Add more tests for prompts

This commit is contained in:
Florian Bruhin 2016-10-27 09:16:19 +02:00
parent 653ca9799d
commit fefc8c4eb2
7 changed files with 184 additions and 10 deletions

View File

@ -33,7 +33,7 @@ import collections
from PyQt5.QtCore import pyqtSignal, QUrl, QObject from PyQt5.QtCore import pyqtSignal, QUrl, QObject
from qutebrowser.utils import (message, usertypes, qtutils, urlutils, from qutebrowser.utils import (message, usertypes, qtutils, urlutils,
standarddir, objreg) standarddir, objreg, log)
from qutebrowser.commands import cmdutils from qutebrowser.commands import cmdutils
from qutebrowser.misc import lineparser from qutebrowser.misc import lineparser
@ -201,6 +201,7 @@ class QuickmarkManager(UrlMarkManager):
self.marks[name] = url self.marks[name] = url
self.changed.emit() self.changed.emit()
self.added.emit(name, url) self.added.emit(name, url)
log.misc.debug("Added quickmark {} for {}".format(name, url))
if name in self.marks: if name in self.marks:
message.confirm_async( message.confirm_async(

View File

@ -361,7 +361,7 @@ class LineEdit(QLineEdit):
if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier: if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier:
try: try:
text = utils.get_clipboard(selection=True) text = utils.get_clipboard(selection=True)
except utils.ClipboardError: except utils.ClipboardError: # pragma: no cover
pass pass
else: else:
e.accept() e.accept()

View File

@ -3,13 +3,14 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<script type="text/javascript"> <script type="text/javascript">
function prompter() { function prompter(defaultval) {
var reply = prompt("js prompt", "") var reply = prompt("js prompt", defaultval);
console.log("Prompt reply: " + reply) console.log("Prompt reply: " + reply);
} }
</script> </script>
</head> </head>
<body> <body>
<input type="button" onclick="prompter()" value="Show prompt" id="button"> <input type="button" onclick="prompter('')" value="Show prompt" id="button">
<input type="button" onclick="prompter('default')" value="Show prompt with default value" id="button-default">
</body> </body>
</html> </html>

View File

@ -484,3 +484,15 @@ Feature: Downloading things from a website.
And I run :click-element id download And I run :click-element id download
And I wait until the download is finished And I wait until the download is finished
Then the downloaded file test.pdf should exist 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 <qutebrowser.utils.usertypes.Question default='*' mode=<PromptMode.download: 5> 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 <qutebrowser.utils.usertypes.Question default='*' mode=<PromptMode.download: 5> 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

View File

@ -49,6 +49,14 @@ Feature: Prompts
And I run :prompt-accept And I run :prompt-accept
Then the javascript message "Prompt reply: prompt test" should be logged 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 @pyqt>=5.3.1
Scenario: Rejected javascript prompt Scenario: Rejected javascript prompt
When I open data/prompt/jsprompt.html When I open data/prompt/jsprompt.html
@ -58,6 +66,68 @@ Feature: Prompts
And I run :leave-mode And I run :leave-mode
Then the javascript message "Prompt reply: null" should be logged 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) # Shift-Insert with prompt (issue 1299)
@ -72,6 +142,17 @@ Feature: Prompts
And I run :prompt-accept And I run :prompt-accept
Then the javascript message "Prompt reply: insert test" should be logged 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 "<Shift-Insert>"
And I run :prompt-accept
Then the javascript message "Prompt reply: " should be logged
@pyqt>=5.3.1 @pyqt>=5.3.1
Scenario: Using content -> ignore-javascript-prompt Scenario: Using content -> ignore-javascript-prompt
When I set content -> ignore-javascript-prompt to true When I set content -> ignore-javascript-prompt to true
@ -219,6 +300,44 @@ Feature: Prompts
"user": "user" "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 # :prompt-accept with value argument
Scenario: Javascript alert with value Scenario: Javascript alert with value
@ -258,3 +377,45 @@ Feature: Prompts
And I run :prompt-accept yes And I run :prompt-accept yes
Then the javascript message "confirm reply: true" should be logged Then the javascript message "confirm reply: true" should be logged
And the error "No default value was set for this question!" should be shown 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

View File

@ -39,8 +39,7 @@ def wait_ssl_page_finished_loading(quteproc, ssl_server):
@bdd.when("I wait for a prompt") @bdd.when("I wait for a prompt")
def wait_for_prompt(quteproc): def wait_for_prompt(quteproc):
quteproc.wait_for(message='Entering mode KeyMode.* (reason: question ' quteproc.wait_for(message='Asking question *')
'asked)')
@bdd.then("no prompt should be shown") @bdd.then("no prompt should be shown")

View File

@ -1,8 +1,8 @@
<head> <head>
<script type="text/javascript"> <script type="text/javascript">
function prompter() { function prompter() {
var reply = prompt("js prompt", "") var reply = prompt("js prompt", "");
alert("JS alert: " + reply + "!") alert("JS alert: " + reply + "!");
} }
</script> </script>
</head> </head>