summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp45
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp72
2 files changed, 99 insertions, 18 deletions
diff --git a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp
index 4b18f8e7a..9901bcd76 100644
--- a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp
+++ b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp
@@ -32,6 +32,7 @@
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QTextCodec>
+#include <QWebEngineSettings>
#ifndef QT_NO_OPENSSL
#include <qsslerror.h>
#endif
@@ -124,6 +125,7 @@ void tst_QWebEngineFrame::init()
{
m_view = new QWebEngineView();
m_page = m_view->page();
+ m_page->settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
}
void tst_QWebEngineFrame::cleanup()
@@ -347,7 +349,7 @@ void tst_QWebEngineFrame::requestedUrl()
void tst_QWebEngineFrame::requestedUrlAfterSetAndLoadFailures()
{
QWebEnginePage page;
-
+ page.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
const QUrl first("http://abcdef.abcdef/");
@@ -365,7 +367,6 @@ void tst_QWebEngineFrame::requestedUrlAfterSetAndLoadFailures()
::waitForSignal(&page, SIGNAL(loadFinished(bool)));
QCOMPARE(spy.count(), 2);
QCOMPARE(page.url(), first);
- QEXPECT_FAIL("", "Slight change: The requestedUrl() function catches the error page's entry here thus it results the error page's requested url.", Continue);
QCOMPARE(page.requestedUrl(), second);
QVERIFY(!spy.at(1).first().toBool());
}
@@ -1369,15 +1370,19 @@ void tst_QWebEngineFrame::setUrlHistory()
QTRY_COMPARE(spy.count(), expectedLoadFinishedCount);
QCOMPARE(m_page->url(), aboutBlank);
QCOMPARE(m_page->requestedUrl(), QUrl());
- QCOMPARE(collectHistoryUrls(m_page->history()), QStringList());
+ // Chromium stores navigation entry for every successful loads. The load of the empty page is committed and stored as about:blank.
+ QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << aboutBlank.toString());
url = QUrl("http://non.existent/");
m_page->setUrl(url);
expectedLoadFinishedCount++;
QTRY_COMPARE(spy.count(), expectedLoadFinishedCount);
- QCOMPARE(m_page->url(), url);
- QCOMPARE(m_page->requestedUrl(), url);
- QCOMPARE(collectHistoryUrls(m_page->history()), QStringList());
+ // When error page is disabled in case of LoadFail the entry of the unavailable page is not stored.
+ // We expect the url of the previously loaded page here.
+ QCOMPARE(m_page->url(), aboutBlank);
+ QCOMPARE(m_page->requestedUrl(), QUrl());
+ // Since the entry of the unavailable page is not stored it will not available in the history.
+ QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << aboutBlank.toString());
url = QUrl("qrc:/test1.html");
m_page->setUrl(url);
@@ -1385,25 +1390,31 @@ void tst_QWebEngineFrame::setUrlHistory()
QTRY_COMPARE(spy.count(), expectedLoadFinishedCount);
QCOMPARE(m_page->url(), url);
QCOMPARE(m_page->requestedUrl(), url);
- QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << QStringLiteral("qrc:/test1.html"));
+ QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << aboutBlank.toString() << QStringLiteral("qrc:/test1.html"));
m_page->setUrl(QUrl());
expectedLoadFinishedCount++;
QTRY_COMPARE(spy.count(), expectedLoadFinishedCount);
QCOMPARE(m_page->url(), aboutBlank);
QCOMPARE(m_page->requestedUrl(), QUrl());
- QEXPECT_FAIL("", "Slight change: load(QUrl()) currently loads about:blank and nothing prevents it from being added to the history.", Continue);
- QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << QStringLiteral("qrc:/test1.html"));
+ // Chromium stores navigation entry for every successful loads. The load of the empty page is committed and stored as about:blank.
+ QCOMPARE(collectHistoryUrls(m_page->history()), QStringList()
+ << aboutBlank.toString()
+ << QStringLiteral("qrc:/test1.html")
+ << aboutBlank.toString());
- // Loading same page as current in history, so history count doesn't change.
url = QUrl("qrc:/test1.html");
m_page->setUrl(url);
expectedLoadFinishedCount++;
QTRY_COMPARE(spy.count(), expectedLoadFinishedCount);
QCOMPARE(m_page->url(), url);
QCOMPARE(m_page->requestedUrl(), url);
- QEXPECT_FAIL("", "Slight change: load(QUrl()) currently loads about:blank and nothing prevents it from being added to the history.", Continue);
- QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << QStringLiteral("qrc:/test1.html"));
+ // The history count DOES change since the about:blank is in the list.
+ QCOMPARE(collectHistoryUrls(m_page->history()), QStringList()
+ << aboutBlank.toString()
+ << QStringLiteral("qrc:/test1.html")
+ << aboutBlank.toString()
+ << QStringLiteral("qrc:/test1.html"));
url = QUrl("qrc:/test2.html");
m_page->setUrl(url);
@@ -1411,8 +1422,12 @@ void tst_QWebEngineFrame::setUrlHistory()
QTRY_COMPARE(spy.count(), expectedLoadFinishedCount);
QCOMPARE(m_page->url(), url);
QCOMPARE(m_page->requestedUrl(), url);
- QEXPECT_FAIL("", "Slight change: load(QUrl()) currently loads about:blank and nothing prevents it from being added to the history.", Continue);
- QCOMPARE(collectHistoryUrls(m_page->history()), QStringList() << QStringLiteral("qrc:/test1.html") << QStringLiteral("qrc:/test2.html"));
+ QCOMPARE(collectHistoryUrls(m_page->history()), QStringList()
+ << aboutBlank.toString()
+ << QStringLiteral("qrc:/test1.html")
+ << aboutBlank.toString()
+ << QStringLiteral("qrc:/test1.html")
+ << QStringLiteral("qrc:/test2.html"));
}
void tst_QWebEngineFrame::setUrlUsingStateObject()
@@ -1534,7 +1549,6 @@ void tst_QWebEngineFrame::setUrlThenLoads()
// Just after first load. URL didn't changed yet.
m_page->load(urlToLoad1);
- QEXPECT_FAIL("", "Slight change: url() will return the loaded URL immediately.", Continue);
QCOMPARE(m_page->url(), url);
QCOMPARE(m_page->requestedUrl(), urlToLoad1);
// baseUrlSync spins an event loop and this sometimes return the next result.
@@ -1551,7 +1565,6 @@ void tst_QWebEngineFrame::setUrlThenLoads()
// Just after second load. URL didn't changed yet.
m_page->load(urlToLoad2);
- QEXPECT_FAIL("", "Slight change: url() will return the loaded URL immediately.", Continue);
QCOMPARE(m_page->url(), urlToLoad1);
QCOMPARE(m_page->requestedUrl(), urlToLoad2);
QCOMPARE(baseUrlSync(m_page), extractBaseUrl(urlToLoad1));
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index f0a89d9aa..85939a686 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -191,6 +191,8 @@ private Q_SLOTS:
void macCopyUnicodeToClipboard();
#endif
+ void runJavaScript();
+
private:
QWebEngineView* m_view;
QWebEnginePage* m_page;
@@ -3563,14 +3565,14 @@ void tst_QWebEnginePage::getUserMediaRequest()
QVERIFY(evaluateJavaScriptSync(page, QStringLiteral("!!navigator.webkitGetUserMedia")).toBool());
evaluateJavaScriptSync(page, QStringLiteral("navigator.webkitGetUserMedia({audio: true}, function() {}, function(){})"));
- QTRY_VERIFY_WITH_TIMEOUT(page->gotFeatureRequest(QWebEnginePage::MediaAudioDevices), 100);
+ QTRY_VERIFY_WITH_TIMEOUT(page->gotFeatureRequest(QWebEnginePage::MediaAudioCapture), 100);
// Might end up failing due to the lack of physical media devices deeper in the content layer, so the JS callback is not guaranteed to be called,
// but at least we go through that code path, potentially uncovering failing assertions.
page->acceptPendingRequest();
page->runJavaScript(QStringLiteral("errorCallbackCalled = false;"));
evaluateJavaScriptSync(page, QStringLiteral("navigator.webkitGetUserMedia({audio: true, video: true}, function() {}, function(){errorCallbackCalled = true;})"));
- QTRY_VERIFY_WITH_TIMEOUT(page->gotFeatureRequest(QWebEnginePage::MediaAudioVideoDevices), 100);
+ QTRY_VERIFY_WITH_TIMEOUT(page->gotFeatureRequest(QWebEnginePage::MediaAudioVideoCapture), 100);
page->rejectPendingRequest(); // Should always end up calling the error callback in JS.
QTRY_VERIFY_WITH_TIMEOUT(evaluateJavaScriptSync(page, QStringLiteral("errorCallbackCalled;")).toBool(), 100);
delete page;
@@ -3666,5 +3668,71 @@ void tst_QWebEnginePage::cssMediaTypePageSetting()
#endif
}
+class JavaScriptCallback
+{
+public:
+ JavaScriptCallback() { }
+ JavaScriptCallback(const QVariant& _expected) : expected(_expected) { }
+ virtual void operator() (const QVariant& result) {
+ QVERIFY(result.isValid());
+ QCOMPARE(result, expected);
+ }
+private:
+ QVariant expected;
+};
+
+class JavaScriptCallbackNull
+{
+public:
+ virtual void operator() (const QVariant& result) {
+ QVERIFY(result.isNull());
+// FIXME: Returned null values are currently invalid QVariants.
+// QVERIFY(result.isValid());
+ }
+};
+
+class JavaScriptCallbackUndefined
+{
+public:
+ virtual void operator() (const QVariant& result) {
+ QVERIFY(result.isNull());
+ QVERIFY(!result.isValid());
+ }
+};
+
+void tst_QWebEnginePage::runJavaScript()
+{
+ TestPage page;
+
+ 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));
+
+ 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));
+
+ JavaScriptCallbackNull callbackUndefined;
+ page.runJavaScript("undefined", QWebEngineCallback<const QVariant&>(callbackUndefined));
+
+ QTest::qWait(100);
+}
+
QTEST_MAIN(tst_QWebEnginePage)
#include "tst_qwebenginepage.moc"