From df5ce12ed86bcb6748d73599e081d800e103b56f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Dec 2016 07:45:03 +0100 Subject: [PATCH] Make it possible to cancel authentication with QtWebEngine Fixes #2156 --- qutebrowser/browser/shared.py | 1 + qutebrowser/browser/webengine/webenginetab.py | 17 +++++++++++++---- tests/end2end/features/prompts.feature | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/shared.py b/qutebrowser/browser/shared.py index 8536ea837..3d171c696 100644 --- a/qutebrowser/browser/shared.py +++ b/qutebrowser/browser/shared.py @@ -66,6 +66,7 @@ def authentication_required(url, authenticator, abort_on): if answer is not None: authenticator.setUser(answer.user) authenticator.setPassword(answer.password) + return answer def javascript_confirm(url, js_msg, abort_on): diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 34423888a..e954edd76 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -37,7 +37,7 @@ from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory, interceptor, webenginequtescheme, webenginedownloads) from qutebrowser.utils import (usertypes, qtutils, log, javascript, utils, - objreg) + objreg, jinja) _qute_scheme_handler = None @@ -604,9 +604,18 @@ class WebEngineTab(browsertab.AbstractTab): @pyqtSlot(QUrl, 'QAuthenticator*') def _on_authentication_required(self, url, authenticator): # FIXME:qtwebengine support .netrc - shared.authentication_required(url, authenticator, - abort_on=[self.shutting_down, - self.load_started]) + answer = shared.authentication_required( + url, authenticator, abort_on=[self.shutting_down, + self.load_started]) + if answer is None: + # WORKAROUND for + # https://www.riverbankcomputing.com/pipermail/pyqt/2016-December/038400.html + url_string = url.toDisplayString() + error_page = jinja.render( + 'error.html', + title="Error loading page: {}".format(url_string), + url=url_string, error="Authentication required", icon='') + self.set_html(error_page) def _connect_signals(self): view = self._widget diff --git a/tests/end2end/features/prompts.feature b/tests/end2end/features/prompts.feature index 00cb93dd9..25ce208c6 100644 --- a/tests/end2end/features/prompts.feature +++ b/tests/end2end/features/prompts.feature @@ -353,6 +353,22 @@ Feature: Prompts "user": "user4" } + # https://github.com/The-Compiler/qutebrowser/issues/2156 + @qtwebkit_skip + Scenario: Cancellling webpage authentification with QtWebEngine + When I open basic-auth/user5/password5 without waiting + And I wait for a prompt + And I run :leave-mode + And I wait for "Changing title for idx * to 'Error loading page: *'" in the log + Then the page should contain the plaintext "Authentication required" + + @qtwebengine_skip + Scenario: Cancellling webpage authentification with QtWebKit + When I open basic-auth/user6/password6 without waiting + And I wait for a prompt + And I run :leave-mode + Then basic-auth/user6/password6 should be loaded + # :prompt-accept with value argument Scenario: Javascript alert with value