From 3d9bfd7a0a9bff5a3d66366656ae2746f0af97af Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 29 Apr 2019 12:19:57 +0200 Subject: Silence warnings in tst_qwebengineprofile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Register custom schemes Change-Id: I536a27da8f936e4ea6569e39a8ec6e30e23af03a Reviewed-by: Jüri Valdmann --- .../qwebengineprofile/tst_qwebengineprofile.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp') diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index d9505cbfd..e84aacb27 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ class tst_QWebEngineProfile : public QObject Q_OBJECT private Q_SLOTS: + void initTestCase(); void init(); void cleanup(); void privateProfile(); @@ -61,6 +63,23 @@ private Q_SLOTS: void qtbug_72299(); // this should be the last test }; +void tst_QWebEngineProfile::initTestCase() +{ + QWebEngineUrlScheme foo("foo"); + QWebEngineUrlScheme stream("stream"); + QWebEngineUrlScheme letterto("letterto"); + QWebEngineUrlScheme aviancarrier("aviancarrier"); + foo.setSyntax(QWebEngineUrlScheme::Syntax::Host); + stream.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort); + stream.setDefaultPort(8080); + letterto.setSyntax(QWebEngineUrlScheme::Syntax::Path); + aviancarrier.setSyntax(QWebEngineUrlScheme::Syntax::Path); + QWebEngineUrlScheme::registerScheme(foo); + QWebEngineUrlScheme::registerScheme(stream); + QWebEngineUrlScheme::registerScheme(letterto); + QWebEngineUrlScheme::registerScheme(aviancarrier); +} + void tst_QWebEngineProfile::init() { //make sure defualt global profile is 'default' across all the tests @@ -82,6 +101,7 @@ void tst_QWebEngineProfile::cleanup() profile->setCachePath(QString()); profile->setPersistentStoragePath(QString()); profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache); + profile->removeAllUrlSchemeHandlers(); } void tst_QWebEngineProfile::privateProfile() -- cgit v1.2.3 From fc077552673e25c580592047369acbe47f4be46d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 3 May 2019 10:45:54 +0200 Subject: Do not crash on QWebEnginePagePrivate::releaseProfile() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deregistering the widget or deleting the view should be able to handle a now missing d_ptr in the old page. Change-Id: Ic843f7bde12776b6aad4fad865ccf14a25695154 Fixes: QTBUG-75547 Reviewed-by: Jüri Valdmann --- .../qwebengineprofile/tst_qwebengineprofile.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp') diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index e84aacb27..2a4e2d533 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -60,6 +60,7 @@ private Q_SLOTS: void downloadItem(); void changePersistentPath(); void initiator(); + void badDeleteOrder(); void qtbug_72299(); // this should be the last test }; @@ -589,6 +590,24 @@ void tst_QWebEngineProfile::initiator() QCOMPARE(handler.initiator, QUrl()); } +void tst_QWebEngineProfile::badDeleteOrder() +{ + QWebEngineProfile *profile = new QWebEngineProfile(); + QWebEngineView *view = new QWebEngineView(); + view->resize(640, 480); + view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view)); + QWebEnginePage *page = new QWebEnginePage(profile, view); + view->setPage(page); + + QSignalSpy spyLoadFinished(page, SIGNAL(loadFinished(bool))); + page->setHtml(QStringLiteral("

Badly handled page!

")); + QTRY_COMPARE(spyLoadFinished.count(), 1); + + delete profile; + delete view; +} + void tst_QWebEngineProfile::qtbug_72299() { QWebEngineView view; -- cgit v1.2.3 From efee223d7ff6e0e30fb9d9dff1536936922d4a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Mon, 29 Apr 2019 15:51:58 +0200 Subject: 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 --- .../qwebengineprofile/tst_qwebengineprofile.cpp | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp') 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(); -- cgit v1.2.3