From 852baaa8c30b84b0870b235ff69b2d376ba0613f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 18 Sep 2017 09:10:32 +0200 Subject: [PATCH] Drop support for Qt < 5.7.1 See #2742 --- README.asciidoc | 8 +- doc/changelog.asciidoc | 3 +- doc/faq.asciidoc | 20 ---- doc/install.asciidoc | 85 +++++++++-------- doc/qutebrowser.1.asciidoc | 3 - pytest.ini | 1 - qutebrowser/browser/downloadview.py | 35 ++----- qutebrowser/browser/webkit/cache.py | 3 +- .../browser/webkit/certificateerror.py | 8 -- .../browser/webkit/network/networkmanager.py | 40 ++------ qutebrowser/browser/webkit/webkitelem.py | 3 - qutebrowser/browser/webkit/webkitsettings.py | 9 +- qutebrowser/browser/webkit/webkittab.py | 12 +-- qutebrowser/browser/webkit/webpage.py | 49 +++------- qutebrowser/browser/webkit/webview.py | 26 ++---- qutebrowser/mainwindow/statusbar/progress.py | 4 - qutebrowser/mainwindow/tabwidget.py | 24 ++--- qutebrowser/misc/earlyinit.py | 92 ++----------------- qutebrowser/misc/ipc.py | 41 +++------ qutebrowser/qutebrowser.py | 5 +- qutebrowser/utils/log.py | 2 +- qutebrowser/utils/objreg.py | 8 +- qutebrowser/utils/qtutils.py | 10 -- qutebrowser/utils/usertypes.py | 10 +- tests/conftest.py | 10 +- tests/end2end/features/test_yankpaste_bdd.py | 10 +- tests/end2end/test_invocations.py | 4 - tests/helpers/fixtures.py | 4 +- tests/unit/browser/test_tab.py | 5 - tests/unit/browser/webkit/network/test_pac.py | 19 +--- tests/unit/misc/test_earlyinit.py | 77 ---------------- tests/unit/misc/test_ipc.py | 21 +---- tests/unit/utils/test_javascript.py | 57 +----------- .../utils/test_javascript_string_escape.html | 68 -------------- tests/unit/utils/test_qtutils.py | 20 ---- tests/unit/utils/test_standarddir.py | 4 - tests/unit/utils/test_urlutils.py | 10 +- tests/unit/utils/test_version.py | 4 +- tests/unit/utils/usertypes/test_question.py | 11 --- 39 files changed, 142 insertions(+), 683 deletions(-) delete mode 100644 tests/unit/utils/test_javascript_string_escape.html diff --git a/README.asciidoc b/README.asciidoc index 7a1af16e9..1f8de414d 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -102,8 +102,7 @@ The following software and libraries are required to run qutebrowser: * http://www.python.org/[Python] 3.4 or newer (3.6 recommended) - note that support for Python 3.4 https://github.com/qutebrowser/qutebrowser/issues/2742[will be dropped soon]. -* http://qt.io/[Qt] 5.2.0 or newer (5.9 recommended - note that support for Qt - < 5.7.1 will be dropped soon) with the following modules: +* http://qt.io/[Qt] 5.7.1 or newer with the following modules: - QtCore / qtbase - QtQuick (part of qtbase in some distributions) - QtSQL (part of qtbase in some distributions) @@ -111,9 +110,8 @@ The following software and libraries are required to run qutebrowser: - QtWebKit (old or link:https://github.com/annulen/webkit/wiki[reloaded]/NG). Note that support for legacy QtWebKit (before 5.212) will be dropped soon. -* http://www.riverbankcomputing.com/software/pyqt/intro[PyQt] 5.2.0 or newer - (5.9 recommended) for Python 3. Note that support for PyQt < 5.7 will be - dropped soon. +* http://www.riverbankcomputing.com/software/pyqt/intro[PyQt] 5.7.0 or newer + (5.9 recommended) for Python 3. * https://pypi.python.org/pypi/setuptools/[pkg_resources/setuptools] * http://fdik.org/pyPEG/[pyPEG2] * http://jinja.pocoo.org/[jinja2] diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index a1bc8caa3..48226e2e9 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -23,7 +23,7 @@ Breaking changes - (TODO) Support for legacy QtWebKit (before 5.212 which is distributed independently from Qt) is dropped. - (TODO) Support for Python 3.4 is dropped. -- (TODO) Support for Qt before 5.7 is dropped. +- Support for Qt before 5.7.1 and PyQt before 5.7 is dropped. - (TODO) New dependency on ruamel.yaml; dropped PyYAML dependency. - (TODO) The QtWebEngine backend is now used by default if available. - New dependency on the QtSql module and Qt sqlite support. @@ -36,6 +36,7 @@ Breaking changes work properly anymore. - Various documentation files got moved to the doc/ subfolder, `qutebrowser.desktop` got moved to misc/. +- The `--harfbuzz` commandline argument got dropped Major changes ~~~~~~~~~~~~~ diff --git a/doc/faq.asciidoc b/doc/faq.asciidoc index cfc16ec12..c46286950 100644 --- a/doc/faq.asciidoc +++ b/doc/faq.asciidoc @@ -205,26 +205,6 @@ Experiencing freezing on sites like duckduckgo and youtube.:: See https://github.com/qutebrowser/qutebrowser/issues/357[Issue #357] for more details. -Experiencing segfaults (crashes) on Debian systems.:: - For Debian it's highly recommended to install the `gstreamer0.10-plugins-base` package. - This is a workaround for a bug in Qt, it has been fixed upstream in Qt 5.4 - More details can be found - https://bugs.webkit.org/show_bug.cgi?id=119951[here]. - -Segfaults on Facebook, Medium, Amazon, ...:: - If you are on a Debian or Ubuntu based system, you might experience some crashes - visiting these sites. This is caused by various bugs in Qt which have been - fixed in Qt 5.4. However Debian and Ubuntu are slow to adopt or upgrade - some packages. On Debian Jessie, it's recommended to use the experimental - repos as described in https://github.com/qutebrowser/qutebrowser/blob/master/doc/install.asciidoc#on-debian--ubuntu[the documentation]. -+ -Since Ubuntu Trusty (using Qt 5.2.1), -https://bugreports.qt.io/browse/QTBUG-42417?jql=component%20%3D%20WebKit%20and%20resolution%20%3D%20Done%20and%20fixVersion%20in%20(5.3.0%2C%20%225.3.0%20Alpha%22%2C%20%225.3.0%20Beta1%22%2C%20%225.3.0%20RC1%22%2C%205.3.1%2C%205.3.2%2C%205.4.0%2C%20%225.4.0%20Alpha%22%2C%20%225.4.0%20Beta%22%2C%20%225.4.0%20RC%22)%20and%20priority%20in%20(%22P2%3A%20Important%22%2C%20%22P1%3A%20Critical%22%2C%20%22P0%3A%20Blocker%22)[over -70 important bugs] have been fixed in QtWebKit. For Debian Jessie (using Qt 5.3.2) -it's still -https://bugreports.qt.io/browse/QTBUG-42417?jql=component%20%3D%20WebKit%20and%20resolution%20%3D%20Done%20and%20fixVersion%20in%20(5.4.0%2C%20%225.4.0%20Alpha%22%2C%20%225.4.0%20Beta%22%2C%20%225.4.0%20RC%22)%20and%20priority%20in%20(%22P2%3A%20Important%22%2C%20%22P1%3A%20Critical%22%2C%20%22P0%3A%20Blocker%22)[nearly -20 important bugs]. - When using QtWebEngine, qutebrowser reports "Render Process Crashed" and the console prints a traceback on Gentoo Linux or another Source-Based Distro:: As stated in https://gcc.gnu.org/gcc-6/changes.html[GCC's Website] GCC 6 has introduced some optimizations that could break non-conforming codebases, like QtWebEngine. + As a workaround, you can disable the nullpointer check optimization by adding the -fno-delete-null-pointer-checks flag while compiling. + diff --git a/doc/install.asciidoc b/doc/install.asciidoc index e8ce36c48..5af011645 100644 --- a/doc/install.asciidoc +++ b/doc/install.asciidoc @@ -3,39 +3,50 @@ Installing qutebrowser toc::[] +NOTE: qutebrowser recently had some bigger dependency changes for v1.0.0, which +means those instructions might be out of date in some places. +https://github.com/qutebrowser/qutebrowser/blob/master/doc/contributing.asciidoc[Please help] +updating them if you notice something being broken! + On Debian / Ubuntu ------------------ -qutebrowser should run on these systems: +How to install qutebrowser depends a lot on the version of Debian/Ubuntu you're +running. -* Debian jessie or newer -* Ubuntu Trusty (14.04 LTS) or newer -* Any other distribution based on these (e.g. Linux Mint 17+) +Debian Jessie / Ubuntu 14.04 LTS / Linux Mint < 18 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Unfortunately there is no Debian package in the official repos yet, but installing qutebrowser is -still relatively easy! +Those distributions only have Python 3.4 and a too old Qt version available. A +newer Qt isn't easily installable on Python 3.4, unfortunately. -You can use packages that are built for every release or build it yourself from git. +It should be possible to install Python 3.5 e.g. from the +https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa[deadsnakes PPA] or via_ipca +https://github.com/pyenv/pyenv[pyenv], but nobody tried that yet. -On Ubuntu 16.04 and 16.10 it's recommended to <> -instead in order to be able to use the new QtWebEngine backend. Newer versions -have a QtWebEngine package in the repositories. +If you get qutebrowser running on those distributions, please +https://github.com/qutebrowser/qutebrowser/blob/master/doc/contributing.asciidoc[contribute] +to update this documentation! -Using the packages -~~~~~~~~~~~~~~~~~~ +Ubuntu 16.04 LTS / Linux Mint 18 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Ubuntu 16.04 doesn't come with an up-to-date engine (a new enough QtWebKit, or +QtWebEngine). However, it comes with Python 3.5, so you can +<>. + +Debian Stretch / Ubuntu 17.04 and newer +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Those versions come with QtWebEngine in the repositories. This makes it possible +to install qutebrowser via the Debian package. Install the dependencies via apt-get: ---- -# apt-get install python3-lxml python-tox python3-pyqt5 python3-pyqt5.qtwebkit python3-pyqt5.qtquick python3-sip python3-jinja2 python3-pygments python3-yaml python3-pyqt5.qtsql libqt5sql5-sqlite +# apt install python-tox python3-{lxml,pyqt5,sip,jinja2,pygments,yaml} python3-pyqt5.qt{webengine,quick,opengl,sql} libqt5sql5-sqlite ---- -On Debian Stretch or Ubuntu 17.04 or later, it's also recommended to use the -newer QtWebEngine backend. - -To do so, install `python3-pyqt5.qtwebengine` and `python3-pyqt5.qtopengl`, then -start qutebrowser with `--backend webengine`. - Get the qutebrowser package from the https://github.com/qutebrowser/qutebrowser/releases[release page] and download the https://qutebrowser.org/python3-pypeg2_2.15.2-1_all.deb[PyPEG2 package]. @@ -47,35 +58,27 @@ Install the packages: # dpkg -i qutebrowser_*_all.deb ---- -Build it from git -~~~~~~~~~~~~~~~~~ - -Install the dependencies via apt-get: +Some additional hints: +- Alternatively, you can <> to get a newer + QtWebEngine version. +- If running from git, run the following to generate the documentation for the + `:help` command: ++ ---- -# apt-get install python3-pyqt5 python3-pyqt5.qtwebkit python3-pyqt5.qtquick python-tox python3-sip python3-dev python3-pyqt5.qtsql libqt5sql5-sqlite ----- - -On Debian Stretch or Ubuntu 17.04 or later, it's also recommended to install -`python3-pyqt5.qtwebengine` and start qutebrowser with `--backend webengine` in -order to use the new backend. - -To generate the documentation for the `:help` command, when using the git -repository (rather than a release): - ----- -# apt-get install asciidoc source-highlight +# apt-get install --no-install-recommends asciidoc source-highlight $ python3 scripts/asciidoc2html.py ---- -If video or sound don't seem to work, try installing the gstreamer plugins: - +- If you prefer using QtWebKit, there's an up-to-date version available in + Debian experimental, or from http://repo.paretje.be/unstable/[this repository] + for Debian Stretch. +- If video or sound don't work with QtWebKit, try installing the gstreamer plugins: ++ ---- # apt-get install gstreamer1.0-plugins-{bad,base,good,ugly} ---- -Then <>. - On Fedora --------- @@ -116,7 +119,7 @@ $ rm -r qutebrowser-git or you could use an AUR helper, e.g. `yaourt -S qutebrowser-git`. -If video or sound don't seem to work, try installing the gstreamer plugins: +If video or sound don't work with QtWebKit, try installing the gstreamer plugins: ---- # pacman -S gst-plugins-{base,good,bad,ugly} gst-libav @@ -125,6 +128,8 @@ If video or sound don't seem to work, try installing the gstreamer plugins: On Gentoo --------- +WARNING: The Gentoo packages (even the live version) are lagging behind a lot, which means those instructions probably won't work anymore. Until things are looking better, it's recommended to <>. + A version of qutebrowser is available in the main repository and can be installed with: ---- diff --git a/doc/qutebrowser.1.asciidoc b/doc/qutebrowser.1.asciidoc index 58744e75d..fc70427f6 100644 --- a/doc/qutebrowser.1.asciidoc +++ b/doc/qutebrowser.1.asciidoc @@ -84,9 +84,6 @@ show it. *--force-color*:: Force colored logging -*--harfbuzz* '{old,new,system,auto}':: - HarfBuzz engine version to use. Default: auto. - *--relaxed-config*:: Silently remove unknown config options. diff --git a/pytest.ini b/pytest.ini index 5401eaacc..ae9d914e5 100644 --- a/pytest.ini +++ b/pytest.ini @@ -27,7 +27,6 @@ markers = this: Used to mark tests during development no_invalid_lines: Don't fail on unparseable lines in end2end tests issue2478: Tests which are broken on Windows with QtWebEngine, https://github.com/qutebrowser/qutebrowser/issues/2478 - qt55: Tests only running on Qt 5.5 or later qt_log_level_fail = WARNING qt_log_ignore = ^SpellCheck: .* diff --git a/qutebrowser/browser/downloadview.py b/qutebrowser/browser/downloadview.py index ac44d75d9..2417636fe 100644 --- a/qutebrowser/browser/downloadview.py +++ b/qutebrowser/browser/downloadview.py @@ -19,9 +19,6 @@ """The ListView to display downloads in.""" -import functools - -import sip from PyQt5.QtCore import pyqtSlot, QSize, Qt, QTimer from PyQt5.QtWidgets import QListView, QSizePolicy, QMenu, QStyleFactory @@ -30,29 +27,6 @@ from qutebrowser.config import config from qutebrowser.utils import qtutils, utils, objreg -def update_geometry(obj): - """Weird WORKAROUND for some weird PyQt bug (probably). - - This actually should be a method of DownloadView, but for some reason the - rowsInserted/rowsRemoved signals don't get disconnected from this method - when the DownloadView is deleted from Qt (e.g. by closing a window). - - Here we check if obj ("self") was deleted and just ignore the event if so. - - Original bug: https://github.com/qutebrowser/qutebrowser/issues/167 - Workaround bug: https://github.com/qutebrowser/qutebrowser/issues/171 - """ - def _update_geometry(): - """Actually update the geometry if the object still exists.""" - if sip.isdeleted(obj): - return - obj.updateGeometry() - - # If we don't use a singleShot QTimer, the geometry isn't updated correctly - # and won't include the new item. - QTimer.singleShot(0, _update_geometry) - - class DownloadView(QListView): """QListView which shows currently running downloads as a bar. @@ -85,9 +59,12 @@ class DownloadView(QListView): self.setSpacing(1) self._menu = None model = objreg.get('download-model', scope='window', window=win_id) - model.rowsInserted.connect(functools.partial(update_geometry, self)) - model.rowsRemoved.connect(functools.partial(update_geometry, self)) - model.dataChanged.connect(functools.partial(update_geometry, self)) + model.rowsInserted.connect(lambda: + QTimer.singleShot(0, self.updateGeometry)) + model.rowsRemoved.connect(lambda: + QTimer.singleShot(0, self.updateGeometry)) + model.dataChanged.connect(lambda: + QTimer.singleShot(0, self.updateGeometry)) self.setModel(model) self.setWrapping(True) self.setContextMenuPolicy(Qt.CustomContextMenu) diff --git a/qutebrowser/browser/webkit/cache.py b/qutebrowser/browser/webkit/cache.py index 7ed232a49..28ce2f693 100644 --- a/qutebrowser/browser/webkit/cache.py +++ b/qutebrowser/browser/webkit/cache.py @@ -49,7 +49,6 @@ class DiskCache(QNetworkDiskCache): if size is None: size = 1024 * 1024 * 50 # default from QNetworkDiskCachePrivate # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-59909 - if (qtutils.version_check('5.7.1') and - not qtutils.version_check('5.9')): # pragma: no cover + if not qtutils.version_check('5.9'): # pragma: no cover size = 0 self.setMaximumCacheSize(size) diff --git a/qutebrowser/browser/webkit/certificateerror.py b/qutebrowser/browser/webkit/certificateerror.py index 1d2df1562..efc2a9b08 100644 --- a/qutebrowser/browser/webkit/certificateerror.py +++ b/qutebrowser/browser/webkit/certificateerror.py @@ -37,14 +37,6 @@ class CertificateErrorWrapper(usertypes.AbstractCertificateErrorWrapper): self, error=debug.qenum_key(QSslError, self._error.error()), string=str(self)) - def __hash__(self): - try: - # Qt >= 5.4 - return hash(self._error) - except TypeError: - return hash((self._error.certificate().toDer(), - self._error.error())) - def __eq__(self, other): return self._error == other._error # pylint: disable=protected-access diff --git a/qutebrowser/browser/webkit/network/networkmanager.py b/qutebrowser/browser/webkit/network/networkmanager.py index df7b589c3..87fa3a263 100644 --- a/qutebrowser/browser/webkit/network/networkmanager.py +++ b/qutebrowser/browser/webkit/network/networkmanager.py @@ -24,13 +24,12 @@ import collections import netrc import html -from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication, - QUrl, QByteArray) +from PyQt5.QtCore import (pyqtSlot, pyqtSignal, QCoreApplication, QUrl, + QByteArray) from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply, QSslSocket from qutebrowser.config import config -from qutebrowser.utils import (message, log, usertypes, utils, objreg, qtutils, - urlutils) +from qutebrowser.utils import message, log, usertypes, utils, objreg, urlutils from qutebrowser.browser import shared from qutebrowser.browser.webkit import certificateerror from qutebrowser.browser.webkit.network import (webkitqutescheme, networkreply, @@ -88,15 +87,9 @@ def _is_secure_cipher(cipher): def init(): """Disable insecure SSL ciphers on old Qt versions.""" - if qtutils.version_check('5.3.0'): - default_ciphers = QSslSocket.defaultCiphers() - log.init.debug("Default Qt ciphers: {}".format( - ', '.join(c.name() for c in default_ciphers))) - else: - # https://codereview.qt-project.org/#/c/75943/ - default_ciphers = QSslSocket.supportedCiphers() - log.init.debug("Supported Qt ciphers: {}".format( - ', '.join(c.name() for c in default_ciphers))) + default_ciphers = QSslSocket.defaultCiphers() + log.init.debug("Default Qt ciphers: {}".format( + ', '.join(c.name() for c in default_ciphers))) good_ciphers = [] bad_ciphers = [] @@ -409,24 +402,11 @@ class NetworkManager(QNetworkAccessManager): tab = objreg.get('tab', scope='tab', window=self._win_id, tab=self._tab_id) current_url = tab.url() - except (KeyError, RuntimeError, TypeError): + except (KeyError, RuntimeError): # https://github.com/qutebrowser/qutebrowser/issues/889 - # Catching RuntimeError and TypeError because we could be in - # the middle of the webpage shutdown here. + # Catching RuntimeError because we could be in the middle of the + # webpage shutdown here. current_url = QUrl() self.set_referer(req, current_url) - - if PYQT_VERSION < 0x050301: - # WORKAROUND (remove this when we bump the requirements to 5.3.1) - # - # If we don't disable our message handler, we get a freeze if a - # warning is printed due to a PyQt bug, e.g. when clicking a - # currency on http://ch.mouser.com/localsites/ - # - # See http://www.riverbankcomputing.com/pipermail/pyqt/2014-June/034420.html - with log.disable_qt_msghandler(): - reply = super().createRequest(op, req, outgoing_data) - else: - reply = super().createRequest(op, req, outgoing_data) - return reply + return super().createRequest(op, req, outgoing_data) diff --git a/qutebrowser/browser/webkit/webkitelem.py b/qutebrowser/browser/webkit/webkitelem.py index 216da2dd9..54dd6519d 100644 --- a/qutebrowser/browser/webkit/webkitelem.py +++ b/qutebrowser/browser/webkit/webkitelem.py @@ -292,9 +292,6 @@ class WebKitElement(webelem.AbstractWebElement): elem = elem._parent() # pylint: disable=protected-access def _move_text_cursor(self): - if self is None: - # old PyQt versions call the slot after the element is deleted. - return if self.is_text_input() and self.is_editable(): self._tab.caret.move_to_end_of_document() diff --git a/qutebrowser/browser/webkit/webkitsettings.py b/qutebrowser/browser/webkit/webkitsettings.py index 53b26431c..3354a9486 100644 --- a/qutebrowser/browser/webkit/webkitsettings.py +++ b/qutebrowser/browser/webkit/webkitsettings.py @@ -33,7 +33,7 @@ from PyQt5.QtGui import QFont from PyQt5.QtWebKit import QWebSettings from qutebrowser.config import config, websettings -from qutebrowser.utils import standarddir, urlutils, qtutils +from qutebrowser.utils import standarddir, urlutils from qutebrowser.browser import shared @@ -131,13 +131,6 @@ def init(_args): QWebSettings.setOfflineStoragePath( os.path.join(data_path, 'offline-storage')) - if (config.val.content.private_browsing and - not qtutils.version_check('5.4.2')): - # WORKAROUND for https://codereview.qt-project.org/#/c/108936/ - # Won't work when private browsing is not enabled globally, but that's - # the best we can do... - QWebSettings.setIconDatabasePath('') - websettings.init_mappings(MAPPINGS) _set_user_stylesheet() config.instance.changed.connect(_update_settings) diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index b81599e8a..cf2156431 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -55,20 +55,14 @@ class WebKitPrinting(browsertab.AbstractPrinting): """QtWebKit implementations related to printing.""" - def _do_check(self): - if not qtutils.check_print_compat(): - # WORKAROUND (remove this when we bump the requirements to 5.3.0) - raise browsertab.WebTabError( - "Printing on Qt < 5.3.0 on Windows is broken, please upgrade!") - def check_pdf_support(self): - self._do_check() + pass def check_printer_support(self): - self._do_check() + pass def check_preview_support(self): - self._do_check() + pass def to_pdf(self, filename): printer = QPrinter() diff --git a/qutebrowser/browser/webkit/webpage.py b/qutebrowser/browser/webkit/webpage.py index c20952593..7e1d991b9 100644 --- a/qutebrowser/browser/webkit/webpage.py +++ b/qutebrowser/browser/webkit/webpage.py @@ -22,7 +22,7 @@ import html import functools -from PyQt5.QtCore import pyqtSlot, pyqtSignal, PYQT_VERSION, Qt, QUrl, QPoint +from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QPoint from PyQt5.QtGui import QDesktopServices from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest from PyQt5.QtWidgets import QFileDialog @@ -33,8 +33,8 @@ from qutebrowser.config import config from qutebrowser.browser import pdfjs, shared from qutebrowser.browser.webkit import http from qutebrowser.browser.webkit.network import networkmanager -from qutebrowser.utils import (message, usertypes, log, jinja, qtutils, utils, - objreg, debug, urlutils) +from qutebrowser.utils import (message, usertypes, log, jinja, objreg, debug, + urlutils) class BrowserPage(QWebPage): @@ -87,22 +87,16 @@ class BrowserPage(QWebPage): self.restoreFrameStateRequested.connect( self.on_restore_frame_state_requested) - if PYQT_VERSION > 0x050300: - # WORKAROUND (remove this when we bump the requirements to 5.3.1) - # We can't override javaScriptPrompt with older PyQt-versions because - # of a bug in PyQt. - # See http://www.riverbankcomputing.com/pipermail/pyqt/2014-June/034385.html - - def javaScriptPrompt(self, frame, js_msg, default): - """Override javaScriptPrompt to use qutebrowser prompts.""" - if self._is_shutting_down: - return (False, "") - try: - return shared.javascript_prompt(frame.url(), js_msg, default, - abort_on=[self.loadStarted, - self.shutting_down]) - except shared.CallSuper: - return super().javaScriptPrompt(frame, js_msg, default) + def javaScriptPrompt(self, frame, js_msg, default): + """Override javaScriptPrompt to use qutebrowser prompts.""" + if self._is_shutting_down: + return (False, "") + try: + return shared.javascript_prompt(frame.url(), js_msg, default, + abort_on=[self.loadStarted, + self.shutting_down]) + except shared.CallSuper: + return super().javaScriptPrompt(frame, js_msg, default) def _handle_errorpage(self, info, errpage): """Display an error page if needed. @@ -225,10 +219,6 @@ class BrowserPage(QWebPage): def on_print_requested(self, frame): """Handle printing when requested via javascript.""" - if not qtutils.check_print_compat(): - message.error("Printing on Qt < 5.3.0 on Windows is broken, " - "please upgrade!") - return printdiag = QPrintDialog() printdiag.setAttribute(Qt.WA_DeleteOnClose) printdiag.open(lambda: frame.print(printdiag.printer())) @@ -350,15 +340,7 @@ class BrowserPage(QWebPage): frame: The QWebFrame which gets saved. item: The QWebHistoryItem to be saved. """ - try: - if frame != self.mainFrame(): - return - except RuntimeError: - # With Qt 5.2.1 (Ubuntu Trusty) we get this when closing a tab: - # RuntimeError: wrapped C/C++ object of type BrowserPage has - # been deleted - # Since the information here isn't that important for closing web - # views anyways, we ignore this error. + if frame != self.mainFrame(): return data = { 'zoom': frame.zoomFactor(), @@ -401,9 +383,6 @@ class BrowserPage(QWebPage): """ return ext in self._extension_handlers - # WORKAROUND for: - # http://www.riverbankcomputing.com/pipermail/pyqt/2014-August/034722.html - @utils.prevent_exceptions(False, PYQT_VERSION < 0x50302) def extension(self, ext, opt, out): """Override QWebPage::extension to provide error pages. diff --git a/qutebrowser/browser/webkit/webview.py b/qutebrowser/browser/webkit/webview.py index 95e8c14f0..5608995a4 100644 --- a/qutebrowser/browser/webkit/webview.py +++ b/qutebrowser/browser/webkit/webview.py @@ -29,7 +29,7 @@ from PyQt5.QtWebKitWidgets import QWebView, QWebPage from qutebrowser.config import config from qutebrowser.keyinput import modeman -from qutebrowser.utils import log, usertypes, utils, qtutils, objreg, debug +from qutebrowser.utils import log, usertypes, utils, objreg, debug from qutebrowser.browser.webkit import webpage @@ -57,7 +57,7 @@ class WebView(QWebView): def __init__(self, *, win_id, tab_id, tab, private, parent=None): super().__init__(parent) - if sys.platform == 'darwin' and qtutils.version_check('5.4'): + if sys.platform == 'darwin': # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-42948 # See https://github.com/qutebrowser/qutebrowser/issues/462 self.setStyle(QStyleFactory.create('Fusion')) @@ -74,13 +74,9 @@ class WebView(QWebView): page = webpage.BrowserPage(win_id=self.win_id, tab_id=self._tab_id, tabdata=tab.data, private=private, parent=self) - - try: - page.setVisibilityState( - QWebPage.VisibilityStateVisible if self.isVisible() - else QWebPage.VisibilityStateHidden) - except AttributeError: - pass + page.setVisibilityState( + QWebPage.VisibilityStateVisible if self.isVisible() + else QWebPage.VisibilityStateHidden) self.setPage(page) @@ -240,12 +236,8 @@ class WebView(QWebView): Return: The superclass event return value. """ - try: - self.page().setVisibilityState(QWebPage.VisibilityStateVisible) - except AttributeError: - pass - super().showEvent(e) + self.page().setVisibilityState(QWebPage.VisibilityStateVisible) def hideEvent(self, e): """Extend hideEvent to set the page visibility state to hidden. @@ -256,12 +248,8 @@ class WebView(QWebView): Return: The superclass event return value. """ - try: - self.page().setVisibilityState(QWebPage.VisibilityStateHidden) - except AttributeError: - pass - super().hideEvent(e) + self.page().setVisibilityState(QWebPage.VisibilityStateHidden) def mousePressEvent(self, e): """Set the tabdata ClickTarget on a mousepress. diff --git a/qutebrowser/mainwindow/statusbar/progress.py b/qutebrowser/mainwindow/statusbar/progress.py index 7677a796b..c8707e0b1 100644 --- a/qutebrowser/mainwindow/statusbar/progress.py +++ b/qutebrowser/mainwindow/statusbar/progress.py @@ -61,10 +61,6 @@ class Progress(QProgressBar): def on_tab_changed(self, tab): """Set the correct value when the current tab changed.""" - if self is None: # pragma: no branch - # This should never happen, but for some weird reason it does - # sometimes. - return # pragma: no cover self.setValue(tab.progress()) if tab.load_status() == usertypes.LoadStatus.loading: self.show() diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 2e5c0856a..56b3e5953 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -70,9 +70,6 @@ class TabWidget(QTabWidget): @config.change_filter('tabs') def _init_config(self): """Initialize attributes based on the config.""" - if self is None: # pragma: no cover - # WORKAROUND for PyQt 5.2 - return tabbar = self.tabBar() self.setMovable(True) self.setTabsClosable(False) @@ -744,24 +741,17 @@ class TabBarStyle(QCommonStyle): log.misc.warning("Could not get layouts for tab!") return QRect() return layouts.text - elif sr == QStyle.SE_TabWidgetTabBar: + elif sr in [QStyle.SE_TabWidgetTabBar, + QStyle.SE_TabBarScrollLeftButton]: + # Handling SE_TabBarScrollLeftButton so the left scroll button is + # aligned properly. Otherwise, empty space will be shown after the + # last tab even though the button width is set to 0 + # # Need to use super() because we also use super() to render # element in drawControl(); otherwise, we may get bit by # style differences... - rct = super().subElementRect(sr, opt, widget) - return rct + return super().subElementRect(sr, opt, widget) else: - try: - # We need this so the left scroll button is aligned properly. - # Otherwise, empty space will be shown after the last tab even - # though the button width is set to 0 - # - # QStyle.SE_TabBarScrollLeftButton was added in Qt 5.7 - if sr == QStyle.SE_TabBarScrollLeftButton: - return super().subElementRect(sr, opt, widget) - except AttributeError: - pass - return self._style.subElementRect(sr, opt, widget) def _tab_layout(self, opt): diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index a64a2799b..67d4897f0 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -29,7 +29,6 @@ try: except ImportError: hunter = None -import os import sys import faulthandler import traceback @@ -41,8 +40,6 @@ try: except ImportError: tkinter = None -import pkg_resources - # NOTE: No qutebrowser or PyQt import should be done here, as some early # initialization needs to take place before that! @@ -140,73 +137,6 @@ def init_faulthandler(fileobj=sys.__stderr__): faulthandler.register(signal.SIGUSR1) -def _qt_version(): - """Get the running Qt version. - - Needs to be in a function so we can do a local import easily (to not import - from QtCore too early) but can patch this out easily for tests. - """ - from PyQt5.QtCore import qVersion - return pkg_resources.parse_version(qVersion()) - - -def fix_harfbuzz(args): - """Fix harfbuzz issues. - - This switches to the most stable harfbuzz font rendering engine available - on the platform instead of using the system wide one. - - This fixes crashes on various sites. - - - On Qt 5.2 (and probably earlier) the new engine probably has more - crashes and is also experimental. - - e.g. https://bugreports.qt.io/browse/QTBUG-36099 - - - On Qt 5.3.0 there's a bug that affects a lot of websites: - https://bugreports.qt.io/browse/QTBUG-39278 - So the new engine will be more stable. - - - On Qt 5.3.1 this bug is fixed and the old engine will be the more stable - one again. - - - On Qt 5.4 the new engine is the default and most bugs are taken care of. - - IMPORTANT: This needs to be done before QWidgets is imported in any way! - - WORKAROUND (remove this when we bump the requirements to 5.3.1) - - Args: - args: The argparse namespace. - """ - from qutebrowser.utils import log - if 'PyQt5.QtWidgets' in sys.modules: - msg = "Harfbuzz fix attempted but QtWidgets is already imported!" - if getattr(sys, 'frozen', False): - log.init.debug(msg) - else: - log.init.warning(msg) - if sys.platform.startswith('linux') and args.harfbuzz == 'auto': - if _qt_version() == pkg_resources.parse_version('5.3.0'): - log.init.debug("Using new harfbuzz engine (auto)") - os.environ['QT_HARFBUZZ'] = 'new' - elif _qt_version() < pkg_resources.parse_version('5.4.0'): - log.init.debug("Using old harfbuzz engine (auto)") - os.environ['QT_HARFBUZZ'] = 'old' - else: - log.init.debug("Using system harfbuzz engine (auto)") - elif args.harfbuzz in ['old', 'new']: - # forced harfbuzz variant - # FIXME looking at the Qt code, 'new' isn't a valid value, but leaving - # it empty and using new yields different behavior... - # (probably irrelevant when workaround gets removed) - log.init.debug("Using {} harfbuzz engine (forced)".format( - args.harfbuzz)) - os.environ['QT_HARFBUZZ'] = args.harfbuzz - else: - log.init.debug("Using system harfbuzz engine") - - def check_pyqt_core(): """Check if PyQt core is installed.""" try: @@ -268,22 +198,15 @@ def qt_version(qversion=None, qt_version_str=None): return qversion -def check_qt_version(backend): +def check_qt_version(): """Check if the Qt version is recent enough.""" from PyQt5.QtCore import PYQT_VERSION, PYQT_VERSION_STR from qutebrowser.utils import qtutils - if (not qtutils.version_check('5.2.0', strict=True) or + if (not qtutils.version_check('5.7.1', strict=True) or PYQT_VERSION < 0x050200): - text = ("Fatal error: Qt and PyQt >= 5.2.0 are required, but Qt {} / " - "PyQt {} is installed.".format(qt_version(), - PYQT_VERSION_STR)) - _die(text) - elif (backend == 'webengine' and ( - not qtutils.version_check('5.7.1', strict=True) or - PYQT_VERSION < 0x050700)): - text = ("Fatal error: Qt >= 5.7.1 and PyQt >= 5.7 are required for " - "QtWebEngine support, but Qt {} / PyQt {} is installed." - .format(qt_version(), PYQT_VERSION_STR)) + text = ("Fatal error: Qt >= 5.7.1 and PyQt >= 5.7 are required, " + "but Qt {} / PyQt {} is installed.".format(qt_version(), + PYQT_VERSION_STR)) _die(text) @@ -423,13 +346,10 @@ def earlyinit(args): check_pyqt_core() # Init logging as early as possible init_log(args) - # Now the faulthandler is enabled we fix the Qt harfbuzzing library, before - # importing QtWidgets. - fix_harfbuzz(args) # Now we can be sure QtCore is available, so we can print dialogs on # errors, so people only using the GUI notice them as well. backend = get_backend(args) - check_qt_version(backend) + check_qt_version() remove_inputhook() check_libraries(backend) check_ssl_support(backend) diff --git a/qutebrowser/misc/ipc.py b/qutebrowser/misc/ipc.py index 562cc84cc..2e9824211 100644 --- a/qutebrowser/misc/ipc.py +++ b/qutebrowser/misc/ipc.py @@ -139,8 +139,6 @@ class IPCServer(QObject): _server: A QLocalServer to accept new connections. _socket: The QLocalSocket we're currently connected to. _socketname: The socketname to use. - _socketopts_ok: Set if using setSocketOptions is working with this - OS/Qt version. _atime_timer: Timer to update the atime of the socket regularly. Signals: @@ -182,14 +180,6 @@ class IPCServer(QObject): self._socket = None self._old_socket = None - self._socketopts_ok = os.name == 'nt' - if self._socketopts_ok: # pragma: no cover - # If we use setSocketOptions on Unix with Qt < 5.4, we get a - # NameError while listening... - log.ipc.debug("Calling setSocketOptions") - self._server.setSocketOptions(QLocalServer.UserAccessOption) - else: # pragma: no cover - log.ipc.debug("Not calling setSocketOptions") def _remove_server(self): """Remove an existing server.""" @@ -210,22 +200,21 @@ class IPCServer(QObject): raise AddressInUseError(self._server) else: raise ListenError(self._server) - if not self._socketopts_ok: # pragma: no cover - # If we use setSocketOptions on Unix with Qt < 5.4, we get a - # NameError while listening. - # (see b135569d5c6e68c735ea83f42e4baf51f7972281) - # - # Also, we don't get an AddressInUseError with Qt 5.5: - # https://bugreports.qt.io/browse/QTBUG-48635 - # - # This means we only use setSocketOption on Windows... - try: - os.chmod(self._server.fullServerName(), 0o700) - except FileNotFoundError: - # https://github.com/qutebrowser/qutebrowser/issues/1530 - # The server doesn't actually exist even if ok was reported as - # True, so report this as an error. - raise ListenError(self._server) + + # If we use setSocketOptions on Unix with Qt < 5.4, we get a NameError + # while listening. (see b135569d5c6e68c735ea83f42e4baf51f7972281) + # + # Also, we don't get an AddressInUseError with Qt 5.5: + # https://bugreports.qt.io/browse/QTBUG-48635 + # + # This means we don't use it at all. + try: + os.chmod(self._server.fullServerName(), 0o700) + except FileNotFoundError: + # https://github.com/qutebrowser/qutebrowser/issues/1530 + # The server doesn't actually exist even if ok was reported as + # True, so report this as an error. + raise ListenError(self._server) @pyqtSlot('QLocalSocket::LocalSocketError') def on_error(self, err): diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 24cd49914..844898c0a 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -95,9 +95,6 @@ def get_argparser(): action='store_false', dest='color') debug.add_argument('--force-color', help="Force colored logging", action='store_true') - debug.add_argument('--harfbuzz', choices=['old', 'new', 'system', 'auto'], - default='auto', help="HarfBuzz engine version to use. " - "Default: auto.") debug.add_argument('--relaxed-config', action='store_true', help="Silently remove unknown config options.") debug.add_argument('--nowindow', action='store_true', help="Don't show " @@ -172,6 +169,6 @@ def main(): args = argparse.Namespace(**data) earlyinit.earlyinit(args) # We do this imports late as earlyinit needs to be run first (because of - # the harfbuzz fix and version checking). + # version checking and other early initialization) from qutebrowser import app return app.run(args) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 6cdc61f41..3049d5dfe 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -345,7 +345,7 @@ def qt_message_handler(msg_type, context, msg): try: qt_to_logging[QtCore.QtInfoMsg] = logging.INFO except AttributeError: - # Qt < 5.5 + # While we don't support Qt < 5.5 anymore, logging still needs to work pass # Change levels of some well-known messages to debug so they don't get diff --git a/qutebrowser/utils/objreg.py b/qutebrowser/utils/objreg.py index 4df08ba0d..df962a165 100644 --- a/qutebrowser/utils/objreg.py +++ b/qutebrowser/utils/objreg.py @@ -105,13 +105,9 @@ class ObjectRegistry(collections.UserDict): func = partial_objs[name] try: self[name].destroyed.disconnect(func) - except (RuntimeError, TypeError): + except RuntimeError: # If C++ has deleted the object, the slot is already # disconnected. - # - # With older PyQt-versions (5.2.1) we'll get a "TypeError: - # pyqtSignal must be bound to a QObject" instead: - # https://github.com/qutebrowser/qutebrowser/issues/257 pass del partial_objs[name] @@ -145,7 +141,7 @@ class ObjectRegistry(collections.UserDict): for name, obj in self.data.items(): try: obj_repr = repr(obj) - except (RuntimeError, TypeError): + except RuntimeError: # Underlying object deleted probably obj_repr = '' lines.append("{}: {}".format(name, obj_repr)) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 6a3a5e972..72535394e 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -28,7 +28,6 @@ Module attributes: import io -import os import operator import contextlib @@ -137,15 +136,6 @@ def check_overflow(arg, ctype, fatal=True): return arg -def check_print_compat(): - """Check if printing should work in the given Qt version.""" - # WORKAROUND (remove this when we bump the requirements to 5.3.0) - if os.name == 'nt': - return version_check('5.3') - else: - return True - - def ensure_valid(obj): """Ensure a Qt object with an .isValid() method is valid.""" if not obj.isValid(): diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index d57566e57..1bc928697 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -355,14 +355,8 @@ class Question(QObject): log.misc.debug("Question was already aborted") return self.is_aborted = True - try: - self.aborted.emit() - self.completed.emit() - except TypeError: - # WORKAROUND - # We seem to get "pyqtSignal must be bound to a QObject, not - # 'Question' here, which makes no sense at all..." - log.misc.exception("Error while aborting question") + self.aborted.emit() + self.completed.emit() class Timer(QTimer): diff --git a/tests/conftest.py b/tests/conftest.py index 1c26e44d7..302d08864 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -62,7 +62,6 @@ def _apply_platform_markers(config, item): ('no_ci', 'CI' in os.environ, "Skipped on CI."), ('issue2478', os.name == 'nt' and config.webengine, "Broken with QtWebEngine on Windows"), - ('qt55', not qtutils.version_check('5.5'), "Requires Qt 5.5 or newer"), ] for searched_marker, condition, default_reason in markers: @@ -128,12 +127,9 @@ def pytest_collection_modifyitems(config, items): item.add_marker(pytest.mark.xfail(run=False)) if item.get_marker('js_prompt'): if config.webengine: - js_prompt_pyqt_version = 0x050700 - else: - js_prompt_pyqt_version = 0x050300 - item.add_marker(pytest.mark.skipif( - PYQT_VERSION <= js_prompt_pyqt_version, - reason='JS prompts are not supported with this PyQt version')) + item.add_marker(pytest.mark.skipif( + PYQT_VERSION <= 0x050700, + reason='JS prompts are not supported with PyQt 5.7')) if deselected: deselected_items.append(item) diff --git a/tests/end2end/features/test_yankpaste_bdd.py b/tests/end2end/features/test_yankpaste_bdd.py index deabba59f..c891bf7b4 100644 --- a/tests/end2end/features/test_yankpaste_bdd.py +++ b/tests/end2end/features/test_yankpaste_bdd.py @@ -21,8 +21,6 @@ import pytest import pytest_bdd as bdd -from PyQt5.QtCore import PYQT_VERSION - bdd.scenarios('yankpaste.feature') @@ -34,10 +32,6 @@ def init_fake_clipboard(quteproc): @bdd.when(bdd.parsers.parse('I insert "{value}" into the text field')) -def set_text_field(request, quteproc, value): - if request.config.webengine and PYQT_VERSION >= 0x50700: - cmd = ":jseval --world=0 set_text('{}')".format(value) - else: - cmd = ":jseval set_text('{}')".format(value) - quteproc.send_cmd(cmd) +def set_text_field(quteproc, value): + quteproc.send_cmd(":jseval --world=0 set_text('{}')".format(value)) quteproc.wait_for_js('textarea set to: ' + value) diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index a61372450..abc9928c9 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -29,8 +29,6 @@ import pytest from PyQt5.QtCore import QProcess -from qutebrowser.utils import qtutils - def _base_args(config): """Get the arguments to pass with every invocation.""" @@ -188,8 +186,6 @@ def test_version(request): assert re.search(r'^qutebrowser\s+v\d+(\.\d+)', stdout) is not None -@pytest.mark.skipif(not qtutils.version_check('5.3'), - reason="Does not work on Qt 5.2") def test_qt_arg(request, quteproc_new, tmpdir): """Test --qt-arg.""" args = (['--temp-basedir', '--qt-arg', 'stylesheet', diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 6cd038ce0..d8958f235 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -43,7 +43,7 @@ from qutebrowser.browser.webkit import cookies from qutebrowser.misc import savemanager, sql from qutebrowser.keyinput import modeman -from PyQt5.QtCore import PYQT_VERSION, pyqtSignal, QEvent, QSize, Qt, QObject +from PyQt5.QtCore import pyqtSignal, QEvent, QSize, Qt, QObject from PyQt5.QtGui import QKeyEvent from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout from PyQt5.QtNetwork import QNetworkCookieJar @@ -156,8 +156,6 @@ def tab_registry(win_registry): @pytest.fixture def fake_web_tab(stubs, tab_registry, mode_manager, qapp): """Fixture providing the FakeWebTab *class*.""" - if PYQT_VERSION < 0x050600: - pytest.skip('Causes segfaults, see #1638') return stubs.FakeWebTab diff --git a/tests/unit/browser/test_tab.py b/tests/unit/browser/test_tab.py index e6b081f18..a2a34d9ce 100644 --- a/tests/unit/browser/test_tab.py +++ b/tests/unit/browser/test_tab.py @@ -19,8 +19,6 @@ import pytest -from PyQt5.QtCore import PYQT_VERSION - from qutebrowser.browser import browsertab pytestmark = pytest.mark.usefixtures('redirect_webengine_data') @@ -48,9 +46,6 @@ def view(qtbot, config_stub, request): @pytest.fixture(params=['webkit', 'webengine']) def tab(request, qtbot, tab_registry, cookiejar_and_cache, mode_manager): - if PYQT_VERSION < 0x050600: - pytest.skip('Causes segfaults, see #1638') - if request.param == 'webkit': webkittab = pytest.importorskip('qutebrowser.browser.webkit.webkittab') tab_class = webkittab.WebKitTab diff --git a/tests/unit/browser/webkit/network/test_pac.py b/tests/unit/browser/webkit/network/test_pac.py index 1520ff13c..ea8a7acaf 100644 --- a/tests/unit/browser/webkit/network/test_pac.py +++ b/tests/unit/browser/webkit/network/test_pac.py @@ -20,10 +20,9 @@ import http.server import threading import logging -import sys import pytest -from PyQt5.QtCore import QUrl, QT_VERSION_STR +from PyQt5.QtCore import QUrl from PyQt5.QtNetwork import (QNetworkProxy, QNetworkProxyQuery, QHostInfo, QHostAddress) @@ -206,14 +205,6 @@ def test_secret_url(url, has_secret, from_file): res.resolve(QNetworkProxyQuery(QUrl(url)), from_file=from_file) -# See https://github.com/qutebrowser/qutebrowser/pull/1891#issuecomment-259222615 - -try: - from PyQt5 import QtWebEngineWidgets -except ImportError: - QtWebEngineWidgets = None - - def fetcher_test(test_str): class PACHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): @@ -244,10 +235,6 @@ def fetcher_test(test_str): return fetcher -@pytest.mark.skipif(QT_VERSION_STR.startswith('5.7') and - QtWebEngineWidgets is not None and - sys.platform == "linux", - reason="Segfaults when run with QtWebEngine tests on Linux") def test_fetch_success(): test_str = """ function FindProxyForURL(domain, host) { @@ -260,10 +247,6 @@ def test_fetch_success(): assert len(proxies) == 3 -@pytest.mark.skipif(QT_VERSION_STR.startswith('5.7') and - QtWebEngineWidgets is not None and - sys.platform == "linux", - reason="Segfaults when run with QtWebEngine tests on Linux") def test_fetch_evalerror(caplog): test_str = """ function FindProxyForURL(domain, host) { diff --git a/tests/unit/misc/test_earlyinit.py b/tests/unit/misc/test_earlyinit.py index cf67690fd..032a2ccef 100644 --- a/tests/unit/misc/test_earlyinit.py +++ b/tests/unit/misc/test_earlyinit.py @@ -19,11 +19,7 @@ """Test qutebrowser.misc.earlyinit.""" -import os import sys -import types -import logging -import pkg_resources import pytest @@ -37,79 +33,6 @@ def test_init_faulthandler_stderr_none(monkeypatch, attr): earlyinit.init_faulthandler() -class TestFixHarfbuzz: - - @pytest.fixture(autouse=True) - def clear_harfbuzz(self): - """Clear QT_HARFBUZZ before/after tests.""" - old_harfbuzz = os.environ.pop('QT_HARFBUZZ', None) - yield - if old_harfbuzz is None: - os.environ.pop('QT_HARFBUZZ', None) - else: - os.environ['QT_HARFBUZZ'] = old_harfbuzz - - @pytest.fixture - def args(self): - """Get a fake argparse namespace.""" - return types.SimpleNamespace(harfbuzz='auto') - - @pytest.mark.parametrize('harfbuzz, qt_version, platform, expected', [ - ('auto', '5.2.1', 'linux', 'old'), - ('auto', '5.3.0', 'linux', 'new'), - ('auto', '5.3.2', 'linux', 'old'), - ('auto', '5.4.0', 'linux', None), - - ('auto', '5.2.1', 'windows', None), - - ('old', '5.3.0', 'linux', 'old'), - ('old', '5.4.0', 'linux', 'old'), - - ('new', '5.2.1', 'linux', 'new'), - ('new', '5.3.2', 'linux', 'new'), - ('new', '5.4.0', 'linux', 'new'), - ]) - def test_fix_harfbuzz(self, clear_harfbuzz, args, monkeypatch, caplog, - harfbuzz, qt_version, platform, expected): - """Check the QT_HARFBUZZ env var.""" - args.harfbuzz = harfbuzz - monkeypatch.setattr(earlyinit, '_qt_version', - lambda: pkg_resources.parse_version(qt_version)) - monkeypatch.setattr(earlyinit.sys, 'platform', platform) - - with caplog.at_level(logging.WARNING): - # Because QtWidgets is already imported - earlyinit.fix_harfbuzz(args) - - assert os.environ.get('QT_HARFBUZZ', None) == expected - - @pytest.mark.parametrize('frozen, level', [ - (True, logging.DEBUG), - (False, logging.WARNING), - ]) - def test_widgets_warning(self, args, monkeypatch, caplog, frozen, level): - """Make sure fix_harfbuzz warns when QtWidgets is imported.""" - # Make sure QtWidgets is in sys.modules - from PyQt5 import QtWidgets # pylint: disable=unused-variable - if frozen: - monkeypatch.setattr(earlyinit.sys, 'frozen', True, raising=False) - else: - monkeypatch.delattr(earlyinit.sys, 'frozen', raising=False) - - with caplog.at_level(level): - earlyinit.fix_harfbuzz(args) - - record = caplog.records[0] - assert record.levelno == level - msg = "Harfbuzz fix attempted but QtWidgets is already imported!" - assert record.message == msg - - def test_no_warning(self, args, monkeypatch): - """Without QtWidgets in sys.modules, no warning should be shown.""" - monkeypatch.setattr(earlyinit.sys, 'modules', {}) - earlyinit.fix_harfbuzz(args) - - @pytest.mark.parametrize('same', [True, False]) def test_qt_version(same): if same: diff --git a/tests/unit/misc/test_ipc.py b/tests/unit/misc/test_ipc.py index c9e1e3913..a6a663a0d 100644 --- a/tests/unit/misc/test_ipc.py +++ b/tests/unit/misc/test_ipc.py @@ -35,7 +35,7 @@ from PyQt5.QtTest import QSignalSpy import qutebrowser from qutebrowser.misc import ipc -from qutebrowser.utils import objreg, qtutils, standarddir +from qutebrowser.utils import objreg, standarddir from helpers import stubs @@ -778,26 +778,7 @@ def test_connect_inexistent(qlocalsocket): assert qlocalsocket.error() == QLocalSocket.ServerNotFoundError -def test_socket_options_listen_problem(qlocalserver, short_tmpdir): - """In earlier versions of Qt, listening fails when using socketOptions. - - With this test, we verify that this bug exists in the Qt version/OS - combinations we expect it to, and doesn't exist in other versions. - """ - servername = str(short_tmpdir / 'x') - qlocalserver.setSocketOptions(QLocalServer.UserAccessOption) - ok = qlocalserver.listen(servername) - if os.name == 'nt' or qtutils.version_check('5.4'): - assert ok - else: - assert not ok - assert qlocalserver.serverError() == QAbstractSocket.HostNotFoundError - assert qlocalserver.errorString() == 'QLocalServer::listen: Name error' - - @pytest.mark.posix -@pytest.mark.skipif(not qtutils.version_check('5.4'), - reason="setSocketOptions is even more broken on Qt < 5.4.") def test_socket_options_address_in_use_problem(qlocalserver, short_tmpdir): """Qt seems to ignore AddressInUseError when using socketOptions. diff --git a/tests/unit/utils/test_javascript.py b/tests/unit/utils/test_javascript.py index 54c32ee92..82974876f 100644 --- a/tests/unit/utils/test_javascript.py +++ b/tests/unit/utils/test_javascript.py @@ -19,13 +19,9 @@ """Tests for qutebrowser.utils.javascript.""" -import binascii -import os.path - import pytest import hypothesis import hypothesis.strategies -from PyQt5.QtCore import PYQT_VERSION from qutebrowser.utils import javascript @@ -61,65 +57,22 @@ class TestStringEscape: """Test javascript escaping with some expected outcomes.""" assert javascript.string_escape(before) == after - def _test_escape(self, text, qtbot, webframe): - """Helper function for test_real_escape*.""" - try: - self._test_escape_simple(text, webframe) - except AssertionError: - # Try another method if the simple method failed. - # - # See _test_escape_hexlified documentation on why this is - # necessary. - self._test_escape_hexlified(text, qtbot, webframe) - - def _test_escape_hexlified(self, text, qtbot, webframe): - """Test conversion by hexlifying in javascript. - - Since the conversion of QStrings to Python strings is broken in some - older PyQt versions in some corner cases, we load an HTML file which - generates an MD5 of the escaped text and use that for comparisons. - """ - escaped = javascript.string_escape(text) - path = os.path.join(os.path.dirname(__file__), - 'test_javascript_string_escape.html') - with open(path, encoding='utf-8') as f: - html_source = f.read().replace('%INPUT%', escaped) - - with qtbot.waitSignal(webframe.loadFinished) as blocker: - webframe.setHtml(html_source) - assert blocker.args == [True] - - result = webframe.evaluateJavaScript('window.qute_test_result') - assert result is not None - assert '|' in result - result_md5, result_text = result.split('|', maxsplit=1) - text_md5 = binascii.hexlify(text.encode('utf-8')).decode('ascii') - assert result_md5 == text_md5, result_text - - def _test_escape_simple(self, text, webframe): + def _test_escape(self, text, webframe): """Test conversion by using evaluateJavaScript.""" escaped = javascript.string_escape(text) result = webframe.evaluateJavaScript('"{}";'.format(escaped)) assert result == text @pytest.mark.parametrize('text', sorted(TESTS), ids=repr) - def test_real_escape(self, webframe, qtbot, text): + def test_real_escape(self, webframe, text): """Test javascript escaping with a real QWebPage.""" - self._test_escape(text, qtbot, webframe) + self._test_escape(text, webframe) @pytest.mark.qt_log_ignore('^OpenType support missing for script') @hypothesis.given(hypothesis.strategies.text()) - def test_real_escape_hypothesis(self, webframe, qtbot, text): + def test_real_escape_hypothesis(self, webframe, text): """Test javascript escaping with a real QWebPage and hypothesis.""" - # We can't simply use self._test_escape because of this: - # https://github.com/pytest-dev/pytest-qt/issues/69 - - # self._test_escape(text, qtbot, webframe) - try: - self._test_escape_simple(text, webframe) - except AssertionError: - if PYQT_VERSION >= 0x050300: - self._test_escape_hexlified(text, qtbot, webframe) + self._test_escape(text, webframe) @pytest.mark.parametrize('arg, expected', [ diff --git a/tests/unit/utils/test_javascript_string_escape.html b/tests/unit/utils/test_javascript_string_escape.html deleted file mode 100644 index 31bda35ef..000000000 --- a/tests/unit/utils/test_javascript_string_escape.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - -

set_text() not called...

- diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py index f0fda7a2e..0b39d9df3 100644 --- a/tests/unit/utils/test_qtutils.py +++ b/tests/unit/utils/test_qtutils.py @@ -118,26 +118,6 @@ class TestCheckOverflow: assert newval == repl -@pytest.mark.parametrize('os_name, qversion, expected', [ - ('linux', '5.2.1', True), # unaffected OS - ('linux', '5.4.1', True), # unaffected OS - ('nt', '5.2.1', False), - ('nt', '5.3.0', True), # unaffected Qt version - ('nt', '5.4.1', True), # unaffected Qt version -]) -def test_check_print_compat(os_name, qversion, expected, monkeypatch): - """Test check_print_compat. - - Args: - os_name: The fake os.name to set. - qversion: The fake qVersion() to set. - expected: The expected return value. - """ - monkeypatch.setattr(qtutils.os, 'name', os_name) - monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion) - assert qtutils.check_print_compat() == expected - - class QtObject: """Fake Qt object for test_ensure.""" diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index b828926e9..d652310d5 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -87,8 +87,6 @@ def test_fake_mac_config(tmpdir, monkeypatch): assert standarddir.config() == expected -# FIXME:conf needs AppDataLocation -@pytest.mark.qt55 @pytest.mark.parametrize('what', ['data', 'config', 'cache']) @pytest.mark.not_mac def test_fake_windows(tmpdir, monkeypatch, what): @@ -354,8 +352,6 @@ class TestSystemData: assert standarddir.data(system=True) == standarddir.data() -# FIXME:conf needs AppDataLocation -@pytest.mark.qt55 class TestMoveWindowsAndMacOS: """Test other invocations of _move_data.""" diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index a6ae9104b..a6b1242d1 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -328,9 +328,8 @@ def test_get_search_url_invalid(url): (False, True, True, 'deadbeef'), (False, True, True, 'hello.'), (False, True, False, 'site:cookies.com oatmeal raisin'), - # no DNS because bogus-IP - (False, True, False, '31c3'), - (False, True, False, 'foo::bar'), # no DNS because of no host + # no DNS because there is no host + (False, True, False, 'foo::bar'), # Valid search term with autosearch (False, False, False, 'test foo'), # autosearch = False @@ -350,11 +349,6 @@ def test_is_url(config_stub, fake_dns, url: The URL to test, as a string. auto_search: With which auto_search setting to test """ - if (url == '31c3' and - auto_search == 'dns' and - qtutils.version_check('5.6.1')): - pytest.xfail("Qt behavior changed") - config_stub.val.url.auto_search = auto_search if auto_search == 'dns': if uses_dns: diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index 8736d875e..17e233d45 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -35,7 +35,7 @@ import pkg_resources import pytest import qutebrowser -from qutebrowser.utils import version, usertypes, qtutils +from qutebrowser.utils import version, usertypes from qutebrowser.browser import pdfjs @@ -946,8 +946,6 @@ def test_version_output(params, stubs, monkeypatch): assert version.version() == expected -@pytest.mark.skipif(not qtutils.version_check('5.4'), - reason="Needs Qt >= 5.4.") def test_opengl_vendor(): """Simply call version.opengl_vendor() and see if it doesn't crash.""" pytest.importorskip("PyQt5.QtOpenGL") diff --git a/tests/unit/utils/usertypes/test_question.py b/tests/unit/utils/usertypes/test_question.py index b11c01b6a..ebb209326 100644 --- a/tests/unit/utils/usertypes/test_question.py +++ b/tests/unit/utils/usertypes/test_question.py @@ -19,8 +19,6 @@ """Tests for usertypes.Question.""" -import logging - import pytest from qutebrowser.utils import usertypes @@ -82,15 +80,6 @@ def test_abort(question, qtbot): assert question.is_aborted -def test_abort_typeerror(question, qtbot, mocker, caplog): - """Test Question.abort() with .emit() raising a TypeError.""" - signal_mock = mocker.patch('qutebrowser.utils.usertypes.Question.aborted') - signal_mock.emit.side_effect = TypeError - with caplog.at_level(logging.ERROR, 'misc'): - question.abort() - assert caplog.records[0].message == 'Error while aborting question' - - def test_abort_twice(question, qtbot): """Abort a question twice.""" with qtbot.wait_signal(question.aborted):