summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2019-04-29 15:51:58 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2019-05-07 07:55:32 +0000
commitefee223d7ff6e0e30fb9d9dff1536936922d4a03 (patch)
tree882cc5427a48ff3da37e3ec722ce6678d9ec274b /tests
parentcb265ff630fdf9a6a97d83f9b3fb8ccb554f4b99 (diff)
Q(Quick)WebEngineProfile: Update list of internal schemes
Disallow installing handler for "about" and everything in kStandardURLSchemes of url/url_util.cc. Except for "gopher" which is used in tests. Suppress warning about custom schemes for "gopher" since it's not a custom scheme. Also lowercase the scheme in urlSchemeHandler() and removeUrlSchemeHandler(). Change-Id: I72b06d4fa6433882019405a0d600a593c8971bf1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 2a4e2d533..3fc8fb45a 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -55,6 +55,7 @@ private Q_SLOTS:
void urlSchemeHandlerFailRequest();
void urlSchemeHandlerFailOnRead();
void urlSchemeHandlerStreaming();
+ void urlSchemeHandlerInstallation();
void customUserAgent();
void httpAcceptLanguage();
void downloadItem();
@@ -466,6 +467,46 @@ void tst_QWebEngineProfile::urlSchemeHandlerStreaming()
QCOMPARE(toPlainTextSync(view.page()), QString::fromLatin1(result));
}
+void tst_QWebEngineProfile::urlSchemeHandlerInstallation()
+{
+ FailingUrlSchemeHandler handler;
+ QWebEngineProfile profile;
+
+ // Builtin schemes that *cannot* be overridden.
+ for (auto scheme : { "about", "blob", "data", "javascript", "qrc", "https", "http", "file",
+ "ftp", "wss", "ws", "filesystem", "FileSystem" }) {
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ QRegularExpression("Cannot install a URL scheme handler overriding internal scheme.*"));
+ profile.installUrlSchemeHandler(scheme, &handler);
+ QCOMPARE(profile.urlSchemeHandler(scheme), nullptr);
+ }
+
+ // Builtin schemes that *can* be overridden.
+ for (auto scheme : { "gopher", "GOPHER" }) {
+ profile.installUrlSchemeHandler(scheme, &handler);
+ QCOMPARE(profile.urlSchemeHandler(scheme), &handler);
+ profile.removeUrlScheme(scheme);
+ }
+
+ // Other schemes should be registered with QWebEngineUrlScheme first, but
+ // handler installation still succeeds to preserve backwards compatibility.
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ QRegularExpression("Please register the custom scheme.*"));
+ profile.installUrlSchemeHandler("tst", &handler);
+ QCOMPARE(profile.urlSchemeHandler("tst"), &handler);
+
+ // Existing handler cannot be overridden.
+ FailingUrlSchemeHandler handler2;
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ QRegularExpression("URL scheme handler already installed.*"));
+ profile.installUrlSchemeHandler("tst", &handler2);
+ QCOMPARE(profile.urlSchemeHandler("tst"), &handler);
+ profile.removeUrlScheme("tst");
+}
+
void tst_QWebEngineProfile::customUserAgent()
{
QString defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();