From 741ecac9efcf300eb36ce8a9b6dca551b17ba2cf Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 26 Oct 2016 21:09:33 +0200 Subject: [PATCH] More improvements for yesno prompt key hints --- qutebrowser/mainwindow/prompt.py | 12 +++++++++--- tests/end2end/features/prompts.feature | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 1c0dbcbfc..ce9542d0a 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -607,6 +607,8 @@ class YesNoPrompt(_BasePrompt): def accept(self, value=None): if value is None: + if self.question.default is None: + raise Error("No default value was set for this question!") self.question.answer = self.question.default elif value == 'yes': self.question.answer = True @@ -617,13 +619,17 @@ class YesNoPrompt(_BasePrompt): return True def _allowed_commands(self): - default = 'yes' if self.question.default else 'no' cmds = [ ('prompt-accept yes', "Yes"), ('prompt-accept no', "No"), - ('prompt-accept', "Use default ({})".format(default)), - ('leave-mode', "Abort"), ] + + if self.question.default is not None: + assert self.question.default in [True, False] + default = 'yes' if self.question.default else 'no' + cmds.append(('prompt-accept', "Use default ({})".format(default))) + + cmds.append(('leave-mode', "Abort")) return cmds diff --git a/tests/end2end/features/prompts.feature b/tests/end2end/features/prompts.feature index 05324061f..61db9eb2a 100644 --- a/tests/end2end/features/prompts.feature +++ b/tests/end2end/features/prompts.feature @@ -249,3 +249,12 @@ Feature: Prompts And I run :prompt-accept yes Then the javascript message "confirm reply: true" should be logged And the error "Invalid value nope - expected yes/no!" should be shown + + Scenario: Javascript confirm with default value + When I open data/prompt/jsconfirm.html + And I run :click-element id button + And I wait for a prompt + And I run :prompt-accept + And I run :prompt-accept yes + Then the javascript message "confirm reply: true" should be logged + And the error "No default value was set for this question!" should be shown