From fefc8c4eb2f92f26291464c2a6edfe595bc1de41 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 27 Oct 2016 09:16:19 +0200 Subject: [PATCH] Add more tests for prompts --- qutebrowser/browser/urlmarks.py | 3 +- qutebrowser/mainwindow/prompt.py | 2 +- tests/end2end/data/prompt/jsprompt.html | 9 +- tests/end2end/features/downloads.feature | 12 ++ tests/end2end/features/prompts.feature | 161 +++++++++++++++++++++ tests/end2end/features/test_prompts_bdd.py | 3 +- tests/manual/js/jsprompt.html | 4 +- 7 files changed, 184 insertions(+), 10 deletions(-) diff --git a/qutebrowser/browser/urlmarks.py b/qutebrowser/browser/urlmarks.py index 1a5f66b05..847f49564 100644 --- a/qutebrowser/browser/urlmarks.py +++ b/qutebrowser/browser/urlmarks.py @@ -33,7 +33,7 @@ import collections from PyQt5.QtCore import pyqtSignal, QUrl, QObject from qutebrowser.utils import (message, usertypes, qtutils, urlutils, - standarddir, objreg) + standarddir, objreg, log) from qutebrowser.commands import cmdutils from qutebrowser.misc import lineparser @@ -201,6 +201,7 @@ class QuickmarkManager(UrlMarkManager): self.marks[name] = url self.changed.emit() self.added.emit(name, url) + log.misc.debug("Added quickmark {} for {}".format(name, url)) if name in self.marks: message.confirm_async( diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index fe11e9425..5086e3b41 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -361,7 +361,7 @@ class LineEdit(QLineEdit): if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier: try: text = utils.get_clipboard(selection=True) - except utils.ClipboardError: + except utils.ClipboardError: # pragma: no cover pass else: e.accept() diff --git a/tests/end2end/data/prompt/jsprompt.html b/tests/end2end/data/prompt/jsprompt.html index d8c848553..4279fc075 100644 --- a/tests/end2end/data/prompt/jsprompt.html +++ b/tests/end2end/data/prompt/jsprompt.html @@ -3,13 +3,14 @@ - + + diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 588aa9be8..dd8419671 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -484,3 +484,15 @@ Feature: Downloading things from a website. And I run :click-element id download And I wait until the download is finished Then the downloaded file test.pdf should exist + + Scenario: Answering a question for a cancelled download (#415) + When I set storage -> prompt-download-directory to true + And I run :download http://localhost:(port)/data/downloads/download.bin + And I wait for "Asking question text=None title='Save file to:'>, *" in the log + And I run :download http://localhost:(port)/data/downloads/download2.bin + And I wait for "Asking question text=None title='Save file to:'>, *" in the log + And I run :download-cancel with count 2 + And I run :prompt-accept + And I wait until the download is finished + Then the downloaded file download.bin should exist + And the downloaded file download2.bin should not exist diff --git a/tests/end2end/features/prompts.feature b/tests/end2end/features/prompts.feature index 61db9eb2a..316f45b4c 100644 --- a/tests/end2end/features/prompts.feature +++ b/tests/end2end/features/prompts.feature @@ -49,6 +49,14 @@ Feature: Prompts And I run :prompt-accept Then the javascript message "Prompt reply: prompt test" should be logged + @pyqt>=5.3.1 + Scenario: Javascript prompt with default + When I open data/prompt/jsprompt.html + And I run :click-element id button-default + And I wait for a prompt + And I run :prompt-accept + Then the javascript message "Prompt reply: default" should be logged + @pyqt>=5.3.1 Scenario: Rejected javascript prompt When I open data/prompt/jsprompt.html @@ -58,6 +66,68 @@ Feature: Prompts And I run :leave-mode Then the javascript message "Prompt reply: null" should be logged + # Multiple prompts + + Scenario: Blocking question interrupted by blocking one + When I set content -> ignore-javascript-alert to false + And I open data/prompt/jsalert.html + And I run :click-element id button + And I wait for a prompt + And I open data/prompt/jsconfirm.html in a new tab + And I run :click-element id button + And I wait for a prompt + # JS confirm + And I run :prompt-accept yes + # JS alert + And I run :prompt-accept + Then the javascript message "confirm reply: true" should be logged + And the javascript message "Alert done" should be logged + + Scenario: Blocking question interrupted by async one + When I set content -> ignore-javascript-alert to false + And I set content -> notifications to ask + And I open data/prompt/jsalert.html + And I run :click-element id button + And I wait for a prompt + And I open data/prompt/notifications.html in a new tab + And I run :click-element id button + And I wait for a prompt + # JS alert + And I run :prompt-accept + # notification permission + And I run :prompt-accept yes + Then the javascript message "Alert done" should be logged + And the javascript message "notification permission granted" should be logged + + Scenario: Async question interrupted by async one + When I set content -> notifications to ask + And I open data/prompt/notifications.html in a new tab + And I run :click-element id button + And I wait for a prompt + And I run :quickmark-save + And I wait for a prompt + # notification permission + And I run :prompt-accept yes + # quickmark + And I run :prompt-accept test + Then the javascript message "notification permission granted" should be logged + And "Added quickmark test for *" should be logged + + Scenario: Async question interrupted by blocking one + When I set content -> notifications to ask + And I set content -> ignore-javascript-alert to false + And I open data/prompt/notifications.html in a new tab + And I run :click-element id button + And I wait for a prompt + And I open data/prompt/jsalert.html in a new tab + And I run :click-element id button + And I wait for a prompt + # JS alert + And I run :prompt-accept + # notification permission + And I run :prompt-accept yes + Then the javascript message "Alert done" should be logged + And the javascript message "notification permission granted" should be logged # Shift-Insert with prompt (issue 1299) @@ -72,6 +142,17 @@ Feature: Prompts And I run :prompt-accept Then the javascript message "Prompt reply: insert test" should be logged + @pyqt>=5.3.1 + Scenario: Pasting via shift-insert without it being supported + When selection is not supported + And I put "insert test" into the primary selection + And I open data/prompt/jsprompt.html + And I run :click-element id button + And I wait for a prompt + And I press the keys "" + And I run :prompt-accept + Then the javascript message "Prompt reply: " should be logged + @pyqt>=5.3.1 Scenario: Using content -> ignore-javascript-prompt When I set content -> ignore-javascript-prompt to true @@ -219,6 +300,44 @@ Feature: Prompts "user": "user" } + Scenario: Authentication with :prompt-accept value + When I open about:blank in a new tab + And I open basic-auth/user/password without waiting + And I wait for a prompt + And I run :prompt-accept user:password + And I wait until basic-auth/user/password is loaded + Then the json on the page should be: + { + "authenticated": true, + "user": "user" + } + + Scenario: Authentication with invalid :prompt-accept value + When I open about:blank in a new tab + And I open basic-auth/user/password without waiting + And I wait for a prompt + And I run :prompt-accept foo + And I run :prompt-accept user:password + Then the error "Value needs to be in the format username:password, but foo was given" should be shown + + Scenario: Tabbing between username and password + When I open about:blank in a new tab + And I open basic-auth/user/password without waiting + And I wait for a prompt + And I press the keys "us" + And I run :prompt-item-focus next + And I press the keys "password" + And I run :prompt-item-focus prev + And I press the keys "er" + And I run :prompt-accept + And I run :prompt-accept + And I wait until basic-auth/user/password is loaded + Then the json on the page should be: + { + "authenticated": true, + "user": "user" + } + # :prompt-accept with value argument Scenario: Javascript alert with value @@ -258,3 +377,45 @@ Feature: Prompts 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 + + Scenario: Javascript confirm with deprecated :prompt-yes command + When I open data/prompt/jsconfirm.html + And I run :click-element id button + And I wait for a prompt + And I run :prompt-yes + Then the javascript message "confirm reply: true" should be logged + And the warning "prompt-yes is deprecated - Use :prompt-accept yes instead!" should be shown + + Scenario: Javascript confirm with deprecated :prompt-no command + When I open data/prompt/jsconfirm.html + And I run :click-element id button + And I wait for a prompt + And I run :prompt-no + Then the javascript message "confirm reply: false" should be logged + And the warning "prompt-no is deprecated - Use :prompt-accept no instead!" should be shown + + # Other + + Scenario: Shutting down with a question + When I open data/prompt/jsconfirm.html + And I run :click-element id button + And I wait for a prompt + And I run :quit + Then the javascript message "confirm reply: false" should be logged + And qutebrowser should quit + + Scenario: Using :prompt-open-download with a prompt which does not support it + When I open data/hello.txt + And I run :quickmark-save + And I wait for a prompt + And I run :prompt-open-download + And I run :prompt-accept test-prompt-open-download + Then "Added quickmark test-prompt-open-download for *" should be logged + + Scenario: Using :prompt-item-focus with a prompt which does not support it + When I open data/hello.txt + And I run :quickmark-save + And I wait for a prompt + And I run :prompt-item-focus next + And I run :prompt-accept test-prompt-item-focus + Then "Added quickmark test-prompt-item-focus for *" should be logged diff --git a/tests/end2end/features/test_prompts_bdd.py b/tests/end2end/features/test_prompts_bdd.py index d98acab9a..8a66880b7 100644 --- a/tests/end2end/features/test_prompts_bdd.py +++ b/tests/end2end/features/test_prompts_bdd.py @@ -39,8 +39,7 @@ def wait_ssl_page_finished_loading(quteproc, ssl_server): @bdd.when("I wait for a prompt") def wait_for_prompt(quteproc): - quteproc.wait_for(message='Entering mode KeyMode.* (reason: question ' - 'asked)') + quteproc.wait_for(message='Asking question *') @bdd.then("no prompt should be shown") diff --git a/tests/manual/js/jsprompt.html b/tests/manual/js/jsprompt.html index 782dc1622..b767fdd2f 100644 --- a/tests/manual/js/jsprompt.html +++ b/tests/manual/js/jsprompt.html @@ -1,8 +1,8 @@