summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-28 14:48:23 +0100
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2016-02-04 05:34:45 +0000
commitaf79ee493dea93737aa0e0d672f0182c403283fd (patch)
treeab39b9dc702da0afd29590e118826de5b02c7687
parent08f056237a65d70c2eea2efb6c26ecb83a0ee584 (diff)
Stabilize tst_QWebEngineProfile::urlSchemeHandlers
Sometimes the emission of loadFinished wasn't caught. Use a QTRY_VERIFY-like function to synchronously load a page. Change-Id: Ib260a126c0cff7f254c97b1cd89f49b806010235 Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index d06fd5e9..89e8da00 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -106,52 +106,60 @@ public:
}
};
+static bool loadSync(QWebEngineView *view, const QUrl &url, int timeout = 5000)
+{
+ // Ripped off QTRY_VERIFY.
+ QSignalSpy loadFinishedSpy(view, SIGNAL(loadFinished(bool)));
+ view->load(url);
+ if (loadFinishedSpy.isEmpty())
+ QTest::qWait(0);
+ for (int i = 0; i < timeout; i += 50) {
+ if (!loadFinishedSpy.isEmpty())
+ return true;
+ QTest::qWait(50);
+ }
+ return false;
+}
+
void tst_QWebEngineProfile::urlSchemeHandlers()
{
RedirectingUrlSchemeHandler lettertoHandler;
QWebEngineProfile profile(QStringLiteral("urlSchemeHandlers"));
profile.installUrlSchemeHandler("letterto", &lettertoHandler);
QWebEngineView view;
- QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool)));
view.setPage(new QWebEnginePage(&profile, &view));
QString emailAddress = QStringLiteral("egon@olsen-banden.dk");
- view.load(QUrl(QStringLiteral("letterto:") + emailAddress));
- QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(loadSync(&view, QUrl(QStringLiteral("letterto:") + emailAddress)));
QCOMPARE(toPlainTextSync(view.page()), emailAddress);
// Install a gopher handler after the view has been fully initialized.
ReplyingUrlSchemeHandler gopherHandler;
profile.installUrlSchemeHandler("gopher", &gopherHandler);
QUrl url = QUrl(QStringLiteral("gopher://olsen-banden.dk/benny"));
- view.load(url);
- QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(loadSync(&view, url));
QCOMPARE(toPlainTextSync(view.page()), url.toString());
// Remove the letterto scheme, and check whether it is not handled anymore.
profile.removeUrlScheme("letterto");
emailAddress = QStringLiteral("kjeld@olsen-banden.dk");
- view.load(QUrl(QStringLiteral("letterto:") + emailAddress));
- QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(loadSync(&view, QUrl(QStringLiteral("letterto:") + emailAddress)));
QVERIFY(toPlainTextSync(view.page()) != emailAddress);
// Check if gopher is still working after removing letterto.
url = QUrl(QStringLiteral("gopher://olsen-banden.dk/yvonne"));
- view.load(url);
- QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(loadSync(&view, url));
QCOMPARE(toPlainTextSync(view.page()), url.toString());
// Does removeAll work?
profile.removeAllUrlSchemeHandlers();
url = QUrl(QStringLiteral("gopher://olsen-banden.dk/harry"));
- view.load(url);
- QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(loadSync(&view, url));
QVERIFY(toPlainTextSync(view.page()) != url.toString());
// Install a handler that is owned by the view. Make sure this doesn't crash on shutdown.
profile.installUrlSchemeHandler("aviancarrier", new ReplyingUrlSchemeHandler(&view));
url = QUrl(QStringLiteral("aviancarrier:inspector.mortensen@politistyrke.dk"));
- view.load(url);
- QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(loadSync(&view, url));
QCOMPARE(toPlainTextSync(view.page()), url.toString());
}