diff --git a/.pylintrc b/.pylintrc index b654355c2..445d2adcc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -54,7 +54,7 @@ no-docstring-rgx=(^_|^main$) [FORMAT] max-line-length=79 -ignore-long-lines=(` in the download prompt. - New `qt.process_model` setting which can be used to change Chromium's process model. - New `qt.low_end_device_mode` setting which turns on Chromium's low-end device @@ -68,6 +70,9 @@ Changed patterns instead of globs. - In passthrough mode, Ctrl + Mousewheel now also gets passed through to the page instead of zooming. +- Editing text in an external editor now simulates a JS "input" event, which + improves compatibility with websites reacting via JS to input. +- The `qute://settings` page is now properly sorted on Python 3.5. Fixed ~~~~~ diff --git a/doc/contributing.asciidoc b/doc/contributing.asciidoc index 69aac9a0d..2c2ccbd3d 100644 --- a/doc/contributing.asciidoc +++ b/doc/contributing.asciidoc @@ -88,7 +88,7 @@ git format-patch origin/master <1> Running qutebrowser ------------------- -After link:install.html#tox[installing qutebrowser via tox], you can run +After link:install{outfilesuffix}#tox[installing qutebrowser via tox], you can run `.venv/bin/qutebrowser --debug --temp-basedir` to test your changes with debug logging enabled and without affecting existing running instances. diff --git a/doc/faq.asciidoc b/doc/faq.asciidoc index a5d790508..05314ec6f 100644 --- a/doc/faq.asciidoc +++ b/doc/faq.asciidoc @@ -315,5 +315,5 @@ My issue is not listed.:: https://github.com/qutebrowser/qutebrowser/issues[the issue tracker] or using the `:report` command. If you are reporting a segfault, make sure you read the - link:doc/stacktrace.html[guide] on how to report them with all needed + link:stacktrace{outfilesuffix}[guide] on how to report them with all needed information. diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 51d3b30a9..99d8b1e33 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -758,11 +758,11 @@ This tries to automatically click on typical _Previous Page_ or _Next Page_ link - `up`: Go up a level in the current URL. - `increment`: Increment the last number in the URL. Uses the - link:settings.html#url.incdec_segments[url.incdec_segments] + link:settings{outsuffix}#url.incdec_segments[url.incdec_segments] config option. - `decrement`: Decrement the last number in the URL. Uses the - link:settings.html#url.incdec_segments[url.incdec_segments] + link:settings{outsuffix}#url.incdec_segments[url.incdec_segments] config option. @@ -1666,7 +1666,7 @@ Shift the focus of the prompt file completion menu to another item. [[prompt-open-download]] === prompt-open-download -Syntax: +:prompt-open-download ['cmdline']+ +Syntax: +:prompt-open-download [*--pdfjs*] ['cmdline']+ Immediately open a download. @@ -1678,6 +1678,9 @@ If no specific command is given, this will use the system's default application cmdline. +==== optional arguments +* +*-p*+, +*--pdfjs*+: Open the download via PDF.js. + ==== note * This command does not split arguments after the last argument and handles quotes literally. diff --git a/doc/help/configuring.asciidoc b/doc/help/configuring.asciidoc index e59a565bc..67704cc0b 100644 --- a/doc/help/configuring.asciidoc +++ b/doc/help/configuring.asciidoc @@ -44,7 +44,7 @@ If you want to customize many settings, you can open the link:qute://settings[] page by running `:set` without any arguments, where all settings are listed and customizable. -Using the link:commands.html#set[`:set`] command and command completion, you +Using the link:commands{outfilesuffix}#set[`:set`] command and command completion, you can quickly set settings interactively, for example `:set tabs.position left`. Some settings are also customizable for a given @@ -53,8 +53,8 @@ https://developer.chrome.com/apps/match_patterns[URL pattern] by doing e.g. To get more help about a setting, use e.g. `:help tabs.position`. -To bind and unbind keys, you can use the link:commands.html#bind[`:bind`] and -link:commands.html#unbind[`:unbind`] commands: +To bind and unbind keys, you can use the link:commands{outfilesuffix}#bind[`:bind`] and +link:commands{outfilesuffix}#unbind[`:unbind`] commands: - Binding the key chain `,v` to the `:spawn mpv {url}` command: `:bind ,v spawn mpv {url}` @@ -67,9 +67,9 @@ See the help pages linked above (or `:help :bind`, `:help :unbind`) for more information. Other useful commands for config manipulation are -link:commands.html#config-unset[`:config-unset`] to reset a value to its default, -link:commands.html#config-clear[`:config-clear`] to reset the entire configuration, -and link:commands.html#config-cycle[`:config-cycle`] to cycle a setting between +link:commands{outfilesuffix}#config-unset[`:config-unset`] to reset a value to its default, +link:commands{outfilesuffix}#config-clear[`:config-clear`] to reset the entire configuration, +and link:commands{outfilesuffix}#config-cycle[`:config-cycle`] to cycle a setting between different values. [[configpy]] @@ -111,7 +111,7 @@ Note that qutebrowser does some Python magic so it's able to warn you about mistyped config settings. As an example, if you do `c.tabs.possition = "left"`, you'll get an error when starting. -See the link:settings.html[settings help page] for all available settings. The +See the link:settings{outfilesuffix}[settings help page] for all available settings. The accepted values depend on the type of the option. Commonly used are: - Strings: `c.tabs.position = "left"` @@ -187,7 +187,7 @@ preferred to use the `config.bind` command. Doing so ensures the commands are valid and normalizes different expressions which map to the same key. For details on how to specify keys and the available modes, see the -link:settings.html#bindings.commands[documentation] for the `bindings.commands` +link:settings{outfilesuffix}#bindings.commands[documentation] for the `bindings.commands` setting. To bind a key: diff --git a/doc/help/index.asciidoc b/doc/help/index.asciidoc index e90d472b5..7b6efa490 100644 --- a/doc/help/index.asciidoc +++ b/doc/help/index.asciidoc @@ -6,14 +6,14 @@ Documentation The following help pages are currently available: -* link:../quickstart.html[Quick start guide] -* link:../faq.html[Frequently asked questions] -* link:../changelog.html[Change Log] -* link:commands.html[Documentation of commands] -* link:configuring.html[Configuring qutebrowser] -* link:settings.html[Documentation of settings] -* link:../userscripts.html[How to write userscripts] -* link:../contributing.html[Contributing to qutebrowser] +* link:../quickstart{outfilesuffix}[Quick start guide] +* link:../faq{outfilesuffix}[Frequently asked questions] +* link:../changelog{outfilesuffix}[Change Log] +* link:commands{outfilesuffix}[Documentation of commands] +* link:configuring{outfilesuffix}[Configuring qutebrowser] +* link:settings{outfilesuffix}[Documentation of settings] +* link:../userscripts{outfilesuffix}[How to write userscripts] +* link:../contributing{outfilesuffix}[Contributing to qutebrowser] Getting help ------------ diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 52cde12c2..be3ceae77 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -660,6 +660,7 @@ Default: * +pass:[<Ctrl-F>]+: +pass:[rl-forward-char]+ * +pass:[<Ctrl-H>]+: +pass:[rl-backward-delete-char]+ * +pass:[<Ctrl-K>]+: +pass:[rl-kill-line]+ +* +pass:[<Ctrl-P>]+: +pass:[prompt-open-download --pdfjs]+ * +pass:[<Ctrl-U>]+: +pass:[rl-unix-line-discard]+ * +pass:[<Ctrl-W>]+: +pass:[rl-unix-word-rubout]+ * +pass:[<Ctrl-X>]+: +pass:[prompt-open-download]+ diff --git a/misc/requirements/requirements-tests.txt b/misc/requirements/requirements-tests.txt index b2ab99952..a6d9eada2 100644 --- a/misc/requirements/requirements-tests.txt +++ b/misc/requirements/requirements-tests.txt @@ -31,7 +31,7 @@ pytest-cov==2.6.0 pytest-faulthandler==1.5.0 pytest-instafail==0.4.0 pytest-mock==1.10.0 -pytest-qt==3.1.0 +pytest-qt==3.2.0 pytest-repeat==0.7.0 pytest-rerunfailures==4.1 pytest-travis-fold==1.3.0 diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 51905f74d..6cdbc0246 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -612,11 +612,11 @@ class CommandDispatcher: - `up`: Go up a level in the current URL. - `increment`: Increment the last number in the URL. Uses the - link:settings.html#url.incdec_segments[url.incdec_segments] + link:settings{outsuffix}#url.incdec_segments[url.incdec_segments] config option. - `decrement`: Decrement the last number in the URL. Uses the - link:settings.html#url.incdec_segments[url.incdec_segments] + link:settings{outsuffix}#url.incdec_segments[url.incdec_segments] config option. tab: Open in a new tab. @@ -1659,6 +1659,8 @@ class CommandDispatcher: """ try: elem.set_value(text) + # Kick off js handlers to trick them into thinking there was input. + elem.dispatch_event("input", bubbles=True) except webelem.OrphanedError: message.error('Edited element vanished') ed.backup() diff --git a/qutebrowser/browser/pdfjs.py b/qutebrowser/browser/pdfjs.py index 1363553e2..4f719f11a 100644 --- a/qutebrowser/browser/pdfjs.py +++ b/qutebrowser/browser/pdfjs.py @@ -99,10 +99,10 @@ def _generate_pdfjs_script(filename): } const viewer = window.PDFView || window.PDFViewerApplication; - viewer.open("{{ url }}"); + viewer.open({{ url }}); }); """).render( - url=javascript.string_escape(url.toString(QUrl.FullyEncoded)), + url=javascript.to_js(url.toString(QUrl.FullyEncoded)), # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-70420 disable_create_object_url=( not qtutils.version_check('5.12') and diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index 1d719738b..f1e510581 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -139,6 +139,18 @@ class AbstractWebElement(collections.abc.MutableMapping): """Set the element value.""" raise NotImplementedError + def dispatch_event(self, event, bubbles=False, + cancelable=False, composed=False): + """Dispatch an event to the element. + + Args: + bubbles: Whether this event should bubble. + cancelable: Whether this event can be cancelled. + composed: Whether the event will trigger listeners outside of a + shadow root. + """ + raise NotImplementedError + def insert_text(self, text): """Insert the given text into the element.""" raise NotImplementedError diff --git a/qutebrowser/browser/webengine/webengineelem.py b/qutebrowser/browser/webengine/webengineelem.py index aefa51f5a..4ef20da18 100644 --- a/qutebrowser/browser/webengine/webengineelem.py +++ b/qutebrowser/browser/webengine/webengineelem.py @@ -135,6 +135,10 @@ class WebEngineElement(webelem.AbstractWebElement): def set_value(self, value): self._js_call('set_value', value) + def dispatch_event(self, event, bubbles=False, + cancelable=False, composed=False): + self._js_call('dispatch_event', event, bubbles, cancelable, composed) + def caret_position(self): """Get the text caret position for the current element. diff --git a/qutebrowser/browser/webkit/webkitelem.py b/qutebrowser/browser/webkit/webkitelem.py index 7ec979d09..01a2736dc 100644 --- a/qutebrowser/browser/webkit/webkitelem.py +++ b/qutebrowser/browser/webkit/webkitelem.py @@ -125,8 +125,20 @@ class WebKitElement(webelem.AbstractWebElement): self._elem.setPlainText(value) else: log.webelem.debug("Filling {!r} via javascript.".format(self)) - value = javascript.string_escape(value) - self._elem.evaluateJavaScript("this.value='{}'".format(value)) + value = javascript.to_js(value) + self._elem.evaluateJavaScript("this.value={}".format(value)) + + def dispatch_event(self, event, bubbles=False, + cancelable=False, composed=False): + self._check_vanished() + log.webelem.debug("Firing event on {!r} via javascript.".format(self)) + self._elem.evaluateJavaScript( + "this.dispatchEvent(new Event({}, " + "{{'bubbles': {}, 'cancelable': {}, 'composed': {}}}))" + .format(javascript.to_js(event), + javascript.to_js(bubbles), + javascript.to_js(cancelable), + javascript.to_js(composed))) def caret_position(self): """Get the text caret position for the current element.""" @@ -142,11 +154,11 @@ class WebKitElement(webelem.AbstractWebElement): raise webelem.Error("Element is not editable!") log.webelem.debug("Inserting text into element {!r}".format(self)) self._elem.evaluateJavaScript(""" - var text = "{}"; + var text = {}; var event = document.createEvent("TextEvent"); event.initTextEvent("textInput", true, true, null, text); this.dispatchEvent(event); - """.format(javascript.string_escape(text))) + """.format(javascript.to_js(text))) def _parent(self): """Get the parent element of this element.""" diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 289fd7b41..0a2c1e2c7 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -2627,6 +2627,7 @@ bindings.default: prompt: : prompt-accept : prompt-open-download + : prompt-open-download --pdfjs : prompt-item-focus prev : prompt-item-focus prev : prompt-item-focus next diff --git a/qutebrowser/html/settings.html b/qutebrowser/html/settings.html index d4ff4ce34..44824eeac 100644 --- a/qutebrowser/html/settings.html +++ b/qutebrowser/html/settings.html @@ -34,7 +34,7 @@ input { width: 98%; } Setting Value - {% for option in configdata.DATA.values() if not option.no_autoconfig %} + {% for option in configdata.DATA.values()|sort(attribute='name') if not option.no_autoconfig %} {{ option.name }} (Current: {{ confget(option.name) | string |truncate(100) }}) diff --git a/qutebrowser/javascript/.eslintrc.yaml b/qutebrowser/javascript/.eslintrc.yaml index 9e99b0aa5..cb1bb1fcb 100644 --- a/qutebrowser/javascript/.eslintrc.yaml +++ b/qutebrowser/javascript/.eslintrc.yaml @@ -59,3 +59,4 @@ rules: multiline-ternary: ["error", "always-multiline"] max-lines-per-function: "off" require-unicode-regexp: "off" + max-params: "off" diff --git a/qutebrowser/javascript/caret.js b/qutebrowser/javascript/caret.js index 8f3ec8d72..28ab3fab0 100644 --- a/qutebrowser/javascript/caret.js +++ b/qutebrowser/javascript/caret.js @@ -1,5 +1,5 @@ /* eslint-disable max-len, max-statements, complexity, -max-params, default-case, valid-jsdoc */ +default-case, valid-jsdoc */ // Copyright 2014 The Chromium Authors. All rights reserved. // diff --git a/qutebrowser/javascript/webelem.js b/qutebrowser/javascript/webelem.js index ad18899f6..4b9a8e8cd 100644 --- a/qutebrowser/javascript/webelem.js +++ b/qutebrowser/javascript/webelem.js @@ -362,6 +362,15 @@ window._qutebrowser.webelem = (function() { document.execCommand("insertText", false, text); }; + funcs.dispatch_event = (id, event, bubbles = false, + cancelable = false, composed = false) => { + const elem = elements[id]; + elem.dispatchEvent( + new Event(event, {"bubbles": bubbles, + "cancelable": cancelable, + "composed": composed})); + }; + funcs.set_attribute = (id, name, value) => { elements[id].setAttribute(name, value); }; diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 357f63dd7..5eb76c86e 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -391,7 +391,7 @@ class PromptContainer(QWidget): @cmdutils.register(instance='prompt-container', scope='window', modes=[usertypes.KeyMode.prompt], maxsplit=0) - def prompt_open_download(self, cmdline: str = None): + def prompt_open_download(self, cmdline: str = None, pdfjs=False): """Immediately open a download. If no specific command is given, this will use the system's default @@ -402,9 +402,10 @@ class PromptContainer(QWidget): is expanded to the temporary file name. If no `{}` is present, the filename is automatically appended to the cmdline. + pdfjs: Open the download via PDF.js. """ try: - self._prompt.download_open(cmdline) + self._prompt.download_open(cmdline, pdfjs=pdfjs) except UnsupportedOperationError: pass @@ -537,8 +538,10 @@ class _BasePrompt(QWidget): def accept(self, value=None): raise NotImplementedError - def download_open(self, _cmdline): + def download_open(self, cmdline, pdfjs): """Open the download directly if this is a download prompt.""" + utils.unused(cmdline) + utils.unused(pdfjs) raise UnsupportedOperationError def item_focus(self, _which): @@ -757,8 +760,13 @@ class DownloadFilenamePrompt(FilenamePrompt): self.question.answer = downloads.FileDownloadTarget(answer) return done - def download_open(self, cmdline): - self.question.answer = downloads.OpenFileDownloadTarget(cmdline) + def download_open(self, cmdline, pdfjs): + if pdfjs: + target = downloads.PDFJSDownloadTarget() + else: + target = downloads.OpenFileDownloadTarget(cmdline) + + self.question.answer = target self.question.done() message.global_bridge.prompt_done.emit(self.KEY_MODE) @@ -767,6 +775,7 @@ class DownloadFilenamePrompt(FilenamePrompt): ('prompt-accept', 'Accept'), ('leave-mode', 'Abort'), ('prompt-open-download', "Open download"), + ('prompt-open-download --pdfjs', "Open download via PDF.js"), ('prompt-yank', "Yank URL"), ] return cmds diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index a2de308da..09655a969 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -385,13 +385,14 @@ class TabBar(QTabBar): if option.startswith('colors.tabs.'): self.update() - # Clear _minimum_tab_size_hint_helper cache when appropriate + # Clear tab size caches when appropriate if option in ["tabs.indicator.padding", "tabs.padding", "tabs.indicator.width", "tabs.min_width", "tabs.pinned.shrink"]: self._minimum_tab_size_hint_helper.cache_clear() + self._minimum_tab_height.cache_clear() def _on_show_switching_delay_changed(self): """Set timer interval when tabs.show_switching_delay got changed.""" @@ -468,6 +469,7 @@ class TabBar(QTabBar): self._set_icon_size() # clear tab size cache self._minimum_tab_size_hint_helper.cache_clear() + self._minimum_tab_height.cache_clear() def _set_icon_size(self): """Set the tab bar favicon size.""" @@ -555,8 +557,7 @@ class TabBar(QTabBar): # Only add padding if indicator exists if indicator_width != 0: padding_h += indicator_padding.left + indicator_padding.right - padding_v = padding.top + padding.bottom - height = self.fontMetrics().height() + padding_v + height = self._minimum_tab_height() width = (text_width + icon_width + padding_h + indicator_width) min_width = config.val.tabs.min_width @@ -565,6 +566,11 @@ class TabBar(QTabBar): width = max(min_width, width) return QSize(width, height) + @functools.lru_cache(maxsize=1) + def _minimum_tab_height(self): + padding = config.cache['tabs.padding'] + return self.fontMetrics().height() + padding.top + padding.bottom + def _tab_pinned(self, index: int) -> bool: """Return True if tab is pinned.""" if not 0 <= index < self.count(): @@ -589,8 +595,7 @@ class TabBar(QTabBar): # want to ensure it's valid in this special case. return QSize() - minimum_size = self.minimumTabSizeHint(index) - height = minimum_size.height() + height = self._minimum_tab_height() if self.vertical: confwidth = str(config.cache['tabs.width']) if confwidth.endswith('%'): @@ -600,7 +605,7 @@ class TabBar(QTabBar): width = main_window.width() * perc / 100 else: width = int(confwidth) - size = QSize(max(minimum_size.width(), width), height) + size = QSize(width, height) else: if config.cache['tabs.pinned.shrink'] and self._tab_pinned(index): # Give pinned tabs the minimum size they need to display their @@ -614,8 +619,9 @@ class TabBar(QTabBar): if max_width > 0: width = min(max_width, width) - # If we don't have enough space, we return the minimum size - width = max(width, minimum_size.width()) + # If for some reason (tests, bugs) self.width() gives 0, use a + # sane min of 10 px + width = max(width, 10) size = QSize(width, height) qtutils.ensure_valid(size) return size diff --git a/qutebrowser/utils/javascript.py b/qutebrowser/utils/javascript.py index 21b373dd1..6127804a5 100644 --- a/qutebrowser/utils/javascript.py +++ b/qutebrowser/utils/javascript.py @@ -49,7 +49,7 @@ def string_escape(text): return text -def _convert_js_arg(arg): +def to_js(arg): """Convert the given argument so it's the equivalent in JS.""" if arg is None: return 'undefined' @@ -60,7 +60,7 @@ def _convert_js_arg(arg): elif isinstance(arg, (int, float)): return str(arg) elif isinstance(arg, list): - return '[{}]'.format(', '.join(_convert_js_arg(e) for e in arg)) + return '[{}]'.format(', '.join(to_js(e) for e in arg)) else: raise TypeError("Don't know how to handle {!r} of type {}!".format( arg, type(arg).__name__)) @@ -68,7 +68,7 @@ def _convert_js_arg(arg): def assemble(module, function, *args): """Assemble a javascript file and a function call.""" - js_args = ', '.join(_convert_js_arg(arg) for arg in args) + js_args = ', '.join(to_js(arg) for arg in args) if module == 'window': parts = ['window', function] else: diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 601ccaf97..165a6d4ad 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -315,8 +315,8 @@ def _chromium_version(): Quick reference: Qt 5.7: Chromium 49 - 49.0.2623.111 (2016-03-02) - 5.7.1: Security fixes up to 54.0.2840.87 (2016-10-19) + 49.0.2623.111 (2016-03-31) + 5.7.1: Security fixes up to 54.0.2840.87 (2016-11-01) Qt 5.8: Chromium 53 53.0.2785.148 (2016-08-31) @@ -324,20 +324,21 @@ def _chromium_version(): Qt 5.9: Chromium 56 (LTS) 56.0.2924.122 (2017-01-25) - 5.9.6: Security fixes up to 66.0.3359.170 (2018-04-17) + 5.9.6: Security fixes up to 66.0.3359.170 (2018-05-10) Qt 5.10: Chromium 61 61.0.3163.140 (2017-09-05) - 5.10.1: Security fixes up to 64.0.3282.140 (2018-01-24) + 5.10.1: Security fixes up to 64.0.3282.140 (2018-02-01) Qt 5.11: Chromium 65 65.0.3325.151 (.1: .230) (2018-03-06) - 5.11.1: Security fixes up to 67.0.3396.87 (2018-05-29) + 5.11.2: Security fixes up to 68.0.3440.75 (2018-07-24) Qt 5.12: Chromium 69 current 5.12 branch: 69.0.3497.70 (2018-09-11) Also see https://www.chromium.org/developers/calendar + and https://chromereleases.googleblog.com/ """ if QWebEngineProfile is None: # This should never happen diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index f10c9213f..2a0c77fc4 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -42,7 +42,6 @@ from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout from PyQt5.QtNetwork import QNetworkCookieJar import helpers.stubs as stubsmod -import helpers.utils from qutebrowser.config import (config, configdata, configtypes, configexc, configfiles, configcache) from qutebrowser.utils import objreg, standarddir, utils, usertypes diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index f5350dfee..731103b68 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -27,8 +27,6 @@ import contextlib import pytest -from PyQt5.QtCore import QObject, pyqtSignal - from qutebrowser.utils import qtutils diff --git a/tests/unit/browser/test_caret.py b/tests/unit/browser/test_caret.py index da73ca162..27b421c84 100644 --- a/tests/unit/browser/test_caret.py +++ b/tests/unit/browser/test_caret.py @@ -25,7 +25,6 @@ import pytest from PyQt5.QtCore import QUrl from qutebrowser.utils import usertypes -from helpers import utils @pytest.fixture @@ -298,7 +297,7 @@ class TestSearch: with qtbot.wait_callback() as callback: web_tab.search.search('fiv', result_cb=callback) - assert callback.args == [True] + callback.assert_called_with(True) mode_manager.enter(usertypes.KeyMode.caret) caret.move_to_end_of_line() @@ -312,11 +311,11 @@ class TestSearch: with qtbot.wait_callback() as callback: web_tab.search.search('w', result_cb=callback) - assert callback.args == [True] + callback.assert_called_with(True) with qtbot.wait_callback() as callback: web_tab.search.next_result(result_cb=callback) - assert callback.args == [True] + callback.assert_called_with(True) mode_manager.enter(usertypes.KeyMode.caret) diff --git a/tests/unit/browser/test_pdfjs.py b/tests/unit/browser/test_pdfjs.py index 91536e416..3ccd255ce 100644 --- a/tests/unit/browser/test_pdfjs.py +++ b/tests/unit/browser/test_pdfjs.py @@ -45,8 +45,8 @@ def test_generate_pdfjs_page(available, snippet, monkeypatch): # Note that we got double protection, once because we use QUrl.FullyEncoded and -# because we use qutebrowser.utils.javascript.string_escape. Characters -# like " are already replaced by QUrl. +# because we use qutebrowser.utils.javascript.to_js. Characters like " are +# already replaced by QUrl. @pytest.mark.parametrize('filename, expected', [ ('foo.bar', "foo.bar"), ('foo"bar', "foo%22bar"), diff --git a/tests/unit/browser/webkit/test_webkitelem.py b/tests/unit/browser/webkit/test_webkitelem.py index df3de6310..971900e94 100644 --- a/tests/unit/browser/webkit/test_webkitelem.py +++ b/tests/unit/browser/webkit/test_webkitelem.py @@ -409,8 +409,8 @@ class TestWebKitElement: assert elem.value() == 'js' @pytest.mark.parametrize('editable, value, uses_js, arg', [ - ('false', 'foo', True, "this.value='foo'"), - ('false', "foo'bar", True, r"this.value='foo\'bar'"), + ('false', 'foo', True, 'this.value="foo"'), + ('false', "foo'bar", True, r'this.value="foo\'bar"'), ('true', 'foo', False, 'foo'), ]) def test_set_value(self, editable, value, uses_js, arg): diff --git a/tests/unit/javascript/conftest.py b/tests/unit/javascript/conftest.py index b2a5924da..2078513b4 100644 --- a/tests/unit/javascript/conftest.py +++ b/tests/unit/javascript/conftest.py @@ -27,7 +27,6 @@ import jinja2 from PyQt5.QtCore import QUrl -import helpers.utils from qutebrowser.utils import utils @@ -112,7 +111,7 @@ class JSTester: """ with self.qtbot.wait_callback() as callback: self.tab.run_js_async(source, callback, world=world) - assert callback.args == [expected] + callback.assert_called_with(expected) @pytest.fixture diff --git a/tests/unit/javascript/position_caret/test_position_caret.py b/tests/unit/javascript/position_caret/test_position_caret.py index eb5a05ad4..9aeaca345 100644 --- a/tests/unit/javascript/position_caret/test_position_caret.py +++ b/tests/unit/javascript/position_caret/test_position_caret.py @@ -21,8 +21,6 @@ import pytest -import helpers.utils - QWebSettings = pytest.importorskip("PyQt5.QtWebKit").QWebSettings QWebPage = pytest.importorskip("PyQt5.QtWebKitWidgets").QWebPage @@ -58,7 +56,7 @@ class CaretTester: with self._qtbot.wait_callback() as callback: self.js.tab.caret.selection(lambda text: callback(text.rstrip())) - assert callback.args == ['MARKER'] + callback.assert_called_with('MARKER') def check_scrolled(self): """Check if the page is scrolled down.""" diff --git a/tests/unit/javascript/stylesheet/test_stylesheet.py b/tests/unit/javascript/stylesheet/test_stylesheet.py index 591d2cd73..2b1c7ced5 100644 --- a/tests/unit/javascript/stylesheet/test_stylesheet.py +++ b/tests/unit/javascript/stylesheet/test_stylesheet.py @@ -62,9 +62,9 @@ class StylesheetTester: """Check whether the css in ELEMENT is set to VALUE.""" self.js.run("console.log({document});" "window.getComputedStyle({document}, null)" - ".getPropertyValue('{prop}');".format( + ".getPropertyValue({prop});".format( document=document_element, - prop=javascript.string_escape(css_style)), + prop=javascript.to_js(css_style)), value) def check_eq(self, one, two, true=True): diff --git a/tests/unit/javascript/test_greasemonkey.py b/tests/unit/javascript/test_greasemonkey.py index 9870352d4..03a914878 100644 --- a/tests/unit/javascript/test_greasemonkey.py +++ b/tests/unit/javascript/test_greasemonkey.py @@ -240,7 +240,7 @@ class TestWindowIsolation: with qtbot.wait_callback() as callback: page.runJavaScript(setup.test_script, callback) - assert callback.args == [setup.expected] + callback.assert_called_with(setup.expected) # The JSCore in 602.1 doesn't fully support Proxy. @pytest.mark.qtwebkit6021_skip diff --git a/tests/unit/javascript/test_js_execution.py b/tests/unit/javascript/test_js_execution.py index 4d47e62c5..1a0ac8dc5 100644 --- a/tests/unit/javascript/test_js_execution.py +++ b/tests/unit/javascript/test_js_execution.py @@ -78,4 +78,4 @@ def test_simple_js_webengine(qtbot, webengineview, qapp, with qtbot.wait_callback() as callback: page.runJavaScript('1 + 1', world, callback) - assert callback.args == [expected] + callback.assert_called_with(expected) diff --git a/tests/unit/utils/test_javascript.py b/tests/unit/utils/test_javascript.py index 0a196cfa1..f5a2e6261 100644 --- a/tests/unit/utils/test_javascript.py +++ b/tests/unit/utils/test_javascript.py @@ -86,12 +86,12 @@ class TestStringEscape: (True, 'true'), ([23, True, 'x'], '[23, true, "x"]'), ]) -def test_convert_js_arg(arg, expected): +def test_to_js(arg, expected): if expected is TypeError: with pytest.raises(TypeError): - javascript._convert_js_arg(arg) + javascript.to_js(arg) else: - assert javascript._convert_js_arg(arg) == expected + assert javascript.to_js(arg) == expected @pytest.mark.parametrize('base, expected_base', [