summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginepage
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/qwebenginepage')
-rw-r--r--tests/auto/widgets/qwebenginepage/BLACKLIST12
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp335
2 files changed, 161 insertions, 186 deletions
diff --git a/tests/auto/widgets/qwebenginepage/BLACKLIST b/tests/auto/widgets/qwebenginepage/BLACKLIST
index 7857ee818..3053876d4 100644
--- a/tests/auto/widgets/qwebenginepage/BLACKLIST
+++ b/tests/auto/widgets/qwebenginepage/BLACKLIST
@@ -3,6 +3,14 @@ osx
[mouseMovementProperties]
windows
+macos # Can't move cursor (QTBUG-76312)
-[fullScreenRequested]
-windows
+# QTBUG-81614
+[setHtmlWithBaseURL]
+*
+
+[devTools]
+msvc-2019
+
+[setLifecycleStateWithDevTools]
+msvc-2019
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 27aa7a1f7..7fdf897ca 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -225,9 +225,14 @@ private Q_SLOTS:
void editActionsWithoutSelection();
void customUserAgentInNewTab();
+ void renderProcessCrashed();
+ void renderProcessPid();
private:
static QPoint elementCenter(QWebEnginePage *page, const QString &id);
+ static bool isFalseJavaScriptResult(QWebEnginePage *page, const QString &javaScript);
+ static bool isTrueJavaScriptResult(QWebEnginePage *page, const QString &javaScript);
+ static bool isEmptyListJavaScriptResult(QWebEnginePage *page, const QString &javaScript);
QWebEngineView* m_view;
QWebEnginePage* m_page;
@@ -754,20 +759,39 @@ void tst_QWebEnginePage::textSelection()
void tst_QWebEnginePage::backActionUpdate()
{
QWebEngineView view;
+ view.resize(640, 480);
+ view.show();
+
QWebEnginePage *page = view.page();
+ QSignalSpy loadSpy(page, &QWebEnginePage::loadFinished);
QAction *action = page->action(QWebEnginePage::Back);
QVERIFY(!action->isEnabled());
- QSignalSpy loadSpy(page, SIGNAL(loadFinished(bool)));
- QUrl url = QUrl("qrc:///resources/framedindex.html");
- page->load(url);
+
+ page->load(QUrl("qrc:///resources/framedindex.html"));
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
QVERIFY(!action->isEnabled());
- QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(10, 10));
- QEXPECT_FAIL("", "Behavior change: Load signals are emitted only for the main frame in QtWebEngine.", Continue);
- QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 2, 100);
- QEXPECT_FAIL("", "FIXME: Mouse events aren't passed from the QWebEngineView down to the RWHVQtDelegateWidget", Continue);
- QVERIFY(action->isEnabled());
+ auto firstAnchorCenterInFrame = [](QWebEnginePage *page, const QString &frameName) {
+ QVariantList rectList = evaluateJavaScriptSync(page,
+ "(function(){"
+ "var frame = document.getElementsByName('" + frameName + "')[0];"
+ "var anchor = frame.contentDocument.getElementsByTagName('a')[0];"
+ "var rect = anchor.getBoundingClientRect();"
+ "return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
+ "})()").toList();
+
+ if (rectList.count() != 2) {
+ qWarning("firstAnchorCenterInFrame failed.");
+ return QPoint();
+ }
+
+ return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
+ };
+
+ QVERIFY(evaluateJavaScriptSync(page, "document.getElementsByName('frame_b')[0].contentDocument == undefined").toBool());
+ QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, firstAnchorCenterInFrame(page, "frame_c"));
+ QTRY_VERIFY(evaluateJavaScriptSync(page, "document.getElementsByName('frame_b')[0].contentDocument != undefined").toBool());
+ QTRY_VERIFY(action->isEnabled());
}
void tst_QWebEnginePage::localStorageVisibility()
@@ -947,7 +971,7 @@ void tst_QWebEnginePage::findText()
{
CallbackSpy<bool> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
- m_view->findText("", 0, callbackSpy.ref());
+ m_view->findText("", {}, callbackSpy.ref());
QVERIFY(callbackSpy.wasCalled());
QCOMPARE(signalSpy.count(), 1);
QTRY_COMPARE(m_view->selectedText(), QString("foo bar"));
@@ -958,7 +982,7 @@ void tst_QWebEnginePage::findText()
{
CallbackSpy<bool> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
- m_view->findText("Will not be found", 0, callbackSpy.ref());
+ m_view->findText("Will not be found", {}, callbackSpy.ref());
QCOMPARE(callbackSpy.waitForResult(), false);
QTRY_COMPARE(signalSpy.count(), 1);
auto result = signalSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
@@ -975,7 +999,7 @@ void tst_QWebEnginePage::findText()
{
CallbackSpy<bool> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
- m_view->findText("foo", 0, callbackSpy.ref());
+ m_view->findText("foo", {}, callbackSpy.ref());
QVERIFY(callbackSpy.waitForResult());
QTRY_COMPARE(signalSpy.count(), 1);
QTRY_VERIFY(m_view->selectedText().isEmpty());
@@ -986,11 +1010,24 @@ void tst_QWebEnginePage::findText()
{
CallbackSpy<bool> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
- m_view->findText("", 0, callbackSpy.ref());
+ m_view->findText("", {}, callbackSpy.ref());
QTRY_VERIFY(callbackSpy.wasCalled());
QTRY_COMPARE(signalSpy.count(), 1);
QTRY_COMPARE(m_view->selectedText(), QString("foo"));
}
+
+ // Invoking startFinding operation for the same text twice. Without any wait, the second one
+ // should interrupt the first one.
+ {
+ QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ m_view->findText("foo", {});
+ m_view->findText("foo", {});
+ QTRY_COMPARE(signalSpy.count(), 2);
+ QTRY_VERIFY(m_view->selectedText().isEmpty());
+
+ QCOMPARE(signalSpy.at(0).value(0).value<QWebEngineFindTextResult>().numberOfMatches(), 0);
+ QCOMPARE(signalSpy.at(1).value(0).value<QWebEngineFindTextResult>().numberOfMatches(), 1);
+ }
}
void tst_QWebEnginePage::findTextResult()
@@ -1039,11 +1076,11 @@ void tst_QWebEnginePage::findTextSuccessiveShouldCallAllCallbacks()
QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
m_view->setHtml(QString("<html><head></head><body><div>abcdefg abcdefg abcdefg abcdefg abcdefg</div></body></html>"));
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
- m_page->findText("abcde", 0, spy1.ref());
- m_page->findText("abcd", 0, spy2.ref());
- m_page->findText("abc", 0, spy3.ref());
- m_page->findText("ab", 0, spy4.ref());
- m_page->findText("a", 0, spy5.ref());
+ m_page->findText("abcde", {}, spy1.ref());
+ m_page->findText("abcd", {}, spy2.ref());
+ m_page->findText("abc", {}, spy3.ref());
+ m_page->findText("ab", {}, spy4.ref());
+ m_page->findText("a", {}, spy5.ref());
spy5.waitForResult();
QVERIFY(spy1.wasCalled());
QVERIFY(spy2.wasCalled());
@@ -1064,10 +1101,10 @@ void tst_QWebEnginePage::findTextCalledOnMatch()
// CALLBACK
bool callbackCalled = false;
- m_view->page()->findText("foo", 0, [this, &callbackCalled](bool found) {
+ m_view->page()->findText("foo", {}, [this, &callbackCalled](bool found) {
QVERIFY(found);
- m_view->page()->findText("bar", 0, [&callbackCalled](bool found) {
+ m_view->page()->findText("bar", {}, [&callbackCalled](bool found) {
QVERIFY(found);
callbackCalled = true;
});
@@ -1101,7 +1138,7 @@ void tst_QWebEnginePage::findTextActiveMatchOrdinal()
// Iterate over all "foo" matches.
for (int i = 1; i <= 3; ++i) {
- m_view->page()->findText("foo", 0);
+ m_view->page()->findText("foo", {});
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 3);
@@ -1109,7 +1146,7 @@ void tst_QWebEnginePage::findTextActiveMatchOrdinal()
}
// The last match is followed by the fist one.
- m_view->page()->findText("foo", 0);
+ m_view->page()->findText("foo", {});
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 3);
@@ -1123,14 +1160,14 @@ void tst_QWebEnginePage::findTextActiveMatchOrdinal()
QCOMPARE(result.activeMatch(), 3);
// Finding another word resets the activeMatch.
- m_view->page()->findText("bar", 0);
+ m_view->page()->findText("bar", {});
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 2);
QCOMPARE(result.activeMatch(), 1);
// If no match activeMatch is 0.
- m_view->page()->findText("bla", 0);
+ m_view->page()->findText("bla", {});
QTRY_COMPARE(findTextSpy.count(), 1);
result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 0);
@@ -1668,156 +1705,51 @@ void tst_QWebEnginePage::openWindowDefaultSize()
QCOMPARE(requestedGeometry.height(), 100);
}
-class JavaScriptCallbackBase
+bool tst_QWebEnginePage::isFalseJavaScriptResult(QWebEnginePage *page, const QString &javaScript)
{
-public:
- JavaScriptCallbackBase()
- {
- if (watcher)
- QMetaObject::invokeMethod(watcher, "add");
- }
-
- void operator() (const QVariant &result)
- {
- check(result);
- if (watcher)
- QMetaObject::invokeMethod(watcher, "notify");
- }
-
-protected:
- virtual void check(const QVariant &result) = 0;
-
-private:
- friend class JavaScriptCallbackWatcher;
- static QPointer<QObject> watcher;
-};
-
-QPointer<QObject> JavaScriptCallbackBase::watcher = 0;
-
-class JavaScriptCallback : public JavaScriptCallbackBase
-{
-public:
- JavaScriptCallback() { }
- JavaScriptCallback(const QVariant& _expected) : expected(_expected) { }
-
- void check(const QVariant& result) override
- {
- QVERIFY(result.isValid());
- QCOMPARE(result, expected);
- }
-
-private:
- QVariant expected;
-};
-
-class JavaScriptCallbackNull : public JavaScriptCallbackBase
-{
-public:
- void check(const QVariant& result) override
- {
- QVERIFY(result.isNull());
-// FIXME: Returned null values are currently invalid QVariants.
-// QVERIFY(result.isValid());
- }
-};
+ QVariant result = evaluateJavaScriptSync(page, javaScript);
+ return !result.isNull() && result.isValid() && result == QVariant(false);
+}
-class JavaScriptCallbackUndefined : public JavaScriptCallbackBase
+bool tst_QWebEnginePage::isTrueJavaScriptResult(QWebEnginePage *page, const QString &javaScript)
{
-public:
- void check(const QVariant& result) override
- {
- QVERIFY(result.isNull());
- QVERIFY(!result.isValid());
- }
-};
+ QVariant result = evaluateJavaScriptSync(page, javaScript);
+ return !result.isNull() && result.isValid() && result == QVariant(true);
+}
-class JavaScriptCallbackWatcher : public QObject
+bool tst_QWebEnginePage::isEmptyListJavaScriptResult(QWebEnginePage *page, const QString &javaScript)
{
- Q_OBJECT
-public:
- JavaScriptCallbackWatcher()
- {
- Q_ASSERT(!JavaScriptCallbackBase::watcher);
- JavaScriptCallbackBase::watcher = this;
- }
-
- Q_INVOKABLE void add()
- {
- available++;
- }
-
- Q_INVOKABLE void notify()
- {
- called++;
- if (called == available)
- emit allCalled();
- }
-
- bool wait(int maxSeconds = 30)
- {
- if (called == available)
- return true;
-
- QTestEventLoop loop;
- connect(this, SIGNAL(allCalled()), &loop, SLOT(exitLoop()));
- loop.enterLoop(maxSeconds);
- return !loop.timeout();
- }
-
-signals:
- void allCalled();
-
-private:
- int available = 0;
- int called = 0;
-};
-
+ QVariant result = evaluateJavaScriptSync(page, javaScript);
+ return !result.isNull() && result.isValid() && result == QList<QVariant>();
+}
void tst_QWebEnginePage::runJavaScript()
{
TestPage page;
- JavaScriptCallbackWatcher watcher;
-
- JavaScriptCallback callbackBool(QVariant(false));
- page.runJavaScript("false", QWebEngineCallback<const QVariant&>(callbackBool));
-
- JavaScriptCallback callbackInt(QVariant(2));
- page.runJavaScript("2", QWebEngineCallback<const QVariant&>(callbackInt));
-
- JavaScriptCallback callbackDouble(QVariant(2.5));
- page.runJavaScript("2.5", QWebEngineCallback<const QVariant&>(callbackDouble));
-
- JavaScriptCallback callbackString(QVariant(QStringLiteral("Test")));
- page.runJavaScript("\"Test\"", QWebEngineCallback<const QVariant&>(callbackString));
-
- QVariantList list;
- JavaScriptCallback callbackList(list);
- page.runJavaScript("[]", QWebEngineCallback<const QVariant&>(callbackList));
-
+ QVariant result;
QVariantMap map;
- map.insert(QStringLiteral("test"), QVariant(2));
- JavaScriptCallback callbackMap(map);
- page.runJavaScript("var el = {\"test\": 2}; el", QWebEngineCallback<const QVariant&>(callbackMap));
- JavaScriptCallbackNull callbackNull;
- page.runJavaScript("null", QWebEngineCallback<const QVariant&>(callbackNull));
+ QVERIFY(isFalseJavaScriptResult(&page, "false"));
+ QCOMPARE(evaluateJavaScriptSync(&page, "2").toInt(), 2);
+ QCOMPARE(evaluateJavaScriptSync(&page, "2.5").toDouble(), 2.5);
+ QCOMPARE(evaluateJavaScriptSync(&page, "\"Test\"").toString(), "Test");
+ QVERIFY(isEmptyListJavaScriptResult(&page, "[]"));
- JavaScriptCallbackUndefined callbackUndefined;
- page.runJavaScript("undefined", QWebEngineCallback<const QVariant&>(callbackUndefined));
+ map.insert(QStringLiteral("test"), QVariant(2));
+ QCOMPARE(evaluateJavaScriptSync(&page, "var el = {\"test\": 2}; el").toMap(), map);
- JavaScriptCallback callbackDate(QVariant(42.0));
- page.runJavaScript("new Date(42000)", QWebEngineCallback<const QVariant&>(callbackDate));
+ QVERIFY(evaluateJavaScriptSync(&page, "null").isNull());
- JavaScriptCallback callbackBlob(QVariant(QByteArray(8, 0)));
- page.runJavaScript("new ArrayBuffer(8)", QWebEngineCallback<const QVariant&>(callbackBlob));
+ result = evaluateJavaScriptSync(&page, "undefined");
+ QVERIFY(result.isNull() && !result.isValid());
- JavaScriptCallbackUndefined callbackFunction;
- page.runJavaScript("(function(){})", QWebEngineCallback<const QVariant&>(callbackFunction));
+ QCOMPARE(evaluateJavaScriptSync(&page, "new Date(42000)").toDate(), QVariant(42.0).toDate());
+ QCOMPARE(evaluateJavaScriptSync(&page, "new ArrayBuffer(8)").toByteArray(), QByteArray(8, 0));
- JavaScriptCallback callbackPromise(QVariant(QVariantMap{}));
- page.runJavaScript("new Promise(function(){})", QWebEngineCallback<const QVariant&>(callbackPromise));
+ result = evaluateJavaScriptSync(&page, "(function(){})");
+ QVERIFY(result.isNull() && !result.isValid());
- QVERIFY(watcher.wait());
+ QCOMPARE(evaluateJavaScriptSync(&page, "new Promise(function(){})"), QVariant(QVariantMap{}));
}
void tst_QWebEnginePage::runJavaScriptDisabled()
@@ -1860,7 +1792,6 @@ void tst_QWebEnginePage::runJavaScriptFromSlot()
void tst_QWebEnginePage::fullScreenRequested()
{
- JavaScriptCallbackWatcher watcher;
QWebEngineView view;
QWebEnginePage* page = view.page();
view.show();
@@ -1871,9 +1802,8 @@ void tst_QWebEnginePage::fullScreenRequested()
page->load(QUrl("qrc:///resources/fullscreen.html"));
QTRY_COMPARE(loadSpy.count(), 1);
- page->runJavaScript("document.webkitFullscreenEnabled", JavaScriptCallback(true));
- page->runJavaScript("document.webkitIsFullScreen", JavaScriptCallback(false));
- QVERIFY(watcher.wait());
+ QTRY_VERIFY(isTrueJavaScriptResult(page, "document.webkitFullscreenEnabled"));
+ QVERIFY(isFalseJavaScriptResult(page, "document.webkitIsFullScreen"));
// FullscreenRequest must be a user gesture
bool acceptRequest = true;
@@ -1883,17 +1813,15 @@ void tst_QWebEnginePage::fullScreenRequested()
});
QTest::keyPress(view.focusProxy(), Qt::Key_Space);
- QTRY_VERIFY(evaluateJavaScriptSync(page, "document.webkitIsFullScreen").toBool());
- page->runJavaScript("document.webkitExitFullscreen()", JavaScriptCallbackUndefined());
- QVERIFY(watcher.wait());
+ QTRY_VERIFY(isTrueJavaScriptResult(page, "document.webkitIsFullScreen"));
+ page->runJavaScript("document.webkitExitFullscreen()");
+ QTRY_VERIFY(isFalseJavaScriptResult(page, "document.webkitIsFullScreen"));
acceptRequest = false;
- page->runJavaScript("document.webkitFullscreenEnabled", JavaScriptCallback(true));
+ QVERIFY(isTrueJavaScriptResult(page, "document.webkitFullscreenEnabled"));
QTest::keyPress(view.focusProxy(), Qt::Key_Space);
- QVERIFY(watcher.wait());
- page->runJavaScript("document.webkitIsFullScreen", JavaScriptCallback(false));
- QVERIFY(watcher.wait());
+ QTRY_VERIFY(isFalseJavaScriptResult(page, "document.webkitIsFullScreen"));
}
void tst_QWebEnginePage::quotaRequested()
@@ -2026,7 +1954,8 @@ void tst_QWebEnginePage::urlChange()
QUrl testUrl("http://test.qt.io/");
m_view->setHtml(QStringLiteral("<h1>Test</h1"), testUrl);
- QTRY_COMPARE(urlSpy.size(), 1);
+ QTRY_COMPARE(urlSpy.size(), 2);
+ QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), QUrl("data:text/html;charset=UTF-8,%3Ch1%3ETest%3C%2Fh1"));
QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), testUrl);
}
@@ -2086,7 +2015,7 @@ private Q_SLOTS:
void continueError()
{
- emit error(this->error());
+ emit error(this->networkError());
emit finished();
}
};
@@ -2767,14 +2696,14 @@ void tst_QWebEnginePage::setUrlUsingStateObject()
evaluateJavaScriptSync(m_page, "window.history.pushState(null, 'push', 'navigate/to/here')");
expectedUrlChangeCount++;
- QCOMPARE(urlChangedSpy.count(), expectedUrlChangeCount);
+ QTRY_COMPARE(urlChangedSpy.count(), expectedUrlChangeCount);
QCOMPARE(m_page->url(), QUrl("qrc:/resources/navigate/to/here"));
QCOMPARE(m_page->history()->count(), 2);
QVERIFY(m_page->history()->canGoBack());
evaluateJavaScriptSync(m_page, "window.history.replaceState(null, 'replace', 'another/location')");
expectedUrlChangeCount++;
- QCOMPARE(urlChangedSpy.count(), expectedUrlChangeCount);
+ QTRY_COMPARE(urlChangedSpy.count(), expectedUrlChangeCount);
QCOMPARE(m_page->url(), QUrl("qrc:/resources/navigate/to/another/location"));
QCOMPARE(m_page->history()->count(), 2);
QVERIFY(!m_page->history()->canGoForward());
@@ -2823,8 +2752,8 @@ void tst_QWebEnginePage::setUrlThenLoads()
const QUrl urlToLoad2("qrc:/resources/test1.html");
m_page->load(urlToLoad1);
- QCOMPARE(m_page->url(), urlToLoad1);
- QCOMPARE(m_page->requestedUrl(), urlToLoad1);
+ QTRY_COMPARE(m_page->url(), urlToLoad1);
+ QTRY_COMPARE(m_page->requestedUrl(), urlToLoad1);
// baseUrlSync spins an event loop and this sometimes return the next result.
// QCOMPARE(baseUrlSync(m_page), baseUrl);
QTRY_COMPARE(startedSpy.count(), 2);
@@ -2838,8 +2767,8 @@ void tst_QWebEnginePage::setUrlThenLoads()
QCOMPARE(baseUrlSync(m_page), extractBaseUrl(urlToLoad1));
m_page->load(urlToLoad2);
- QCOMPARE(m_page->url(), urlToLoad2);
- QCOMPARE(m_page->requestedUrl(), urlToLoad2);
+ QTRY_COMPARE(m_page->url(), urlToLoad2);
+ QTRY_COMPARE(m_page->requestedUrl(), urlToLoad2);
QCOMPARE(baseUrlSync(m_page), extractBaseUrl(urlToLoad1));
QTRY_COMPARE(startedSpy.count(), 3);
@@ -3352,7 +3281,7 @@ void tst_QWebEnginePage::dataURLFragment()
QTRY_COMPARE(loadFinishedSpy.count(), 1);
QSignalSpy urlChangedSpy(m_page, SIGNAL(urlChanged(QUrl)));
- QTest::mouseClick(m_view->focusProxy(), Qt::LeftButton, 0, elementCenter(m_page, "link"));
+ QTest::mouseClick(m_view->focusProxy(), Qt::LeftButton, {}, elementCenter(m_page, "link"));
QVERIFY(urlChangedSpy.wait());
QCOMPARE(m_page->url().fragment(), QStringLiteral("anchor"));
@@ -3362,7 +3291,7 @@ void tst_QWebEnginePage::dataURLFragment()
"</body></html>", QUrl("http://test.qt.io/mytest.html"));
QTRY_COMPARE(loadFinishedSpy.count(), 2);
- QTest::mouseClick(m_view->focusProxy(), Qt::LeftButton, 0, elementCenter(m_page, "link"));
+ QTest::mouseClick(m_view->focusProxy(), Qt::LeftButton, {}, elementCenter(m_page, "link"));
QVERIFY(urlChangedSpy.wait());
QCOMPARE(m_page->url(), QUrl("http://test.qt.io/mytest.html#anchor"));
}
@@ -3384,7 +3313,7 @@ void tst_QWebEnginePage::devTools()
QCOMPARE(devToolsPage.devToolsPage(), nullptr);
QCOMPARE(devToolsPage.inspectedPage(), &inspectedPage1);
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 30000);
QVERIFY(spy.takeFirst().value(0).toBool());
devToolsPage.setInspectedPage(&inspectedPage2);
@@ -3396,7 +3325,7 @@ void tst_QWebEnginePage::devTools()
QCOMPARE(devToolsPage.devToolsPage(), nullptr);
QCOMPARE(devToolsPage.inspectedPage(), &inspectedPage2);
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 30000);
QVERIFY(spy.takeFirst().value(0).toBool());
devToolsPage.setInspectedPage(nullptr);
@@ -3432,7 +3361,7 @@ void tst_QWebEnginePage::openLinkInDifferentProfile()
QTRY_COMPARE(spy1.count(), 1);
QVERIFY(spy1.takeFirst().value(0).toBool());
page1.targetPage = &page2;
- QTest::mouseClick(view.focusProxy(), Qt::MiddleButton, 0, elementCenter(&page1, "link"));
+ QTest::mouseClick(view.focusProxy(), Qt::MiddleButton, {}, elementCenter(&page1, "link"));
QTRY_COMPARE(spy2.count(), 1);
QVERIFY(spy2.takeFirst().value(0).toBool());
}
@@ -3876,9 +3805,9 @@ void tst_QWebEnginePage::setLifecycleStateWithDevTools()
// Ensure pages are initialized
inspectedPage.load(QStringLiteral("about:blank"));
devToolsPage.load(QStringLiteral("about:blank"));
- QTRY_COMPARE(inspectedSpy.count(), 1);
+ QTRY_COMPARE_WITH_TIMEOUT(inspectedSpy.count(), 1, 30000);
QCOMPARE(inspectedSpy.takeFirst().value(0), QVariant(true));
- QTRY_COMPARE(devToolsSpy.count(), 1);
+ QTRY_COMPARE_WITH_TIMEOUT(devToolsSpy.count(), 1, 30000);
QCOMPARE(devToolsSpy.takeFirst().value(0), QVariant(true));
// Open DevTools with Frozen inspectedPage
@@ -4389,7 +4318,7 @@ void tst_QWebEnginePage::customUserAgentInNewTab()
QTRY_COMPARE(spy.count(), 1);
QVERIFY(spy.takeFirst().value(0).toBool());
QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.userAgent")).toString(), profile1.httpUserAgent());
- QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, elementCenter(&page, "link"));
+ QTest::mouseClick(view.focusProxy(), Qt::LeftButton, {}, elementCenter(&page, "link"));
QTRY_VERIFY(page.newPage);
QTRY_VERIFY(!lastUserAgent.isEmpty());
QCOMPARE(lastUserAgent, profile1.httpUserAgent().toUtf8());
@@ -4404,12 +4333,50 @@ void tst_QWebEnginePage::customUserAgentInNewTab()
QString("'>link</a></body></html>"));
QTRY_COMPARE(spy.count(), 1);
QVERIFY(spy.takeFirst().value(0).toBool());
- QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, elementCenter(&page, "link"));
+ QTest::mouseClick(view.focusProxy(), Qt::LeftButton, {}, elementCenter(&page, "link"));
QTRY_VERIFY(page.newPage);
QTRY_VERIFY(!lastUserAgent.isEmpty());
QCOMPARE(lastUserAgent, profile2.httpUserAgent().toUtf8());
}
+void tst_QWebEnginePage::renderProcessCrashed()
+{
+ using Status = QWebEnginePage::RenderProcessTerminationStatus;
+ QWebEngineProfile profile;
+ QWebEnginePage page(&profile);
+ bool done = false;
+ Status status;
+ connect(&page, &QWebEnginePage::renderProcessTerminated, [&](Status newStatus) {
+ status = newStatus;
+ done = true;
+ });
+ page.load(QUrl("chrome://crash"));
+ QTRY_VERIFY_WITH_TIMEOUT(done, 20000);
+ // The status depends on whether stack traces are enabled. With
+ // --disable-in-process-stack-traces we get an AbnormalTerminationStatus,
+ // otherwise a CrashedTerminationStatus.
+ QVERIFY(status == QWebEnginePage::CrashedTerminationStatus ||
+ status == QWebEnginePage::AbnormalTerminationStatus);
+}
+
+void tst_QWebEnginePage::renderProcessPid()
+{
+ QCOMPARE(m_page->renderProcessPid(), 0);
+
+ m_page->load(QUrl("about:blank"));
+ QSignalSpy spyFinished(m_page, &QWebEnginePage::loadFinished);
+ QVERIFY(spyFinished.wait());
+
+ QVERIFY(m_page->renderProcessPid() > 1);
+
+ bool crashed = false;
+ connect(m_page, &QWebEnginePage::renderProcessTerminated, [&]() { crashed = true; });
+ m_page->load(QUrl("chrome://crash"));
+ QTRY_VERIFY_WITH_TIMEOUT(crashed, 20000);
+
+ QCOMPARE(m_page->renderProcessPid(), 0);
+}
+
static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")};
W_QTEST_MAIN(tst_QWebEnginePage, params)