summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-07-10 10:31:31 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-07-10 10:31:31 +0200
commita4cef2531fc29d874cec9613e2d2ad7ccd5ad937 (patch)
tree5539faab39cbb372a1530b115e9b9dc1e09492ae /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
parent4746bb904bf6841137d5b50357bf79c852bf5d06 (diff)
parentd35cd072c3f56aa285871a151adc30d9d81f3ea3 (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts: .qmake.conf tests/auto/quick/qmltests/BLACKLIST tests/auto/quick/qquickwebengineview/BLACKLIST Change-Id: I29b68dec8692d0369a2dda56350ee62d3ad73e08
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 8ad11ec75..0fa38f9ef 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -206,6 +206,8 @@ private Q_SLOTS:
void editActionsWithInitialFocus();
void editActionsWithFocusOnIframe();
+ void customUserAgentInNewTab();
+
private:
static QPoint elementCenter(QWebEnginePage *page, const QString &id);
@@ -918,6 +920,7 @@ void tst_QWebEnginePage::findText()
QTRY_COMPARE(loadSpy.count(), 1);
// Select whole page contents.
+ QTRY_VERIFY(m_view->page()->action(QWebEnginePage::SelectAll)->isEnabled());
m_view->page()->triggerAction(QWebEnginePage::SelectAll);
QTRY_COMPARE(m_view->hasSelection(), true);
@@ -3492,6 +3495,69 @@ void tst_QWebEnginePage::editActionsWithFocusOnIframe()
QCOMPARE(page->selectedText(), QStringLiteral("inner"));
}
+void tst_QWebEnginePage::customUserAgentInNewTab()
+{
+ HttpServer server;
+ QByteArray lastUserAgent;
+ connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) {
+ QCOMPARE(rr->requestMethod(), "GET");
+ lastUserAgent = rr->requestHeader("user-agent");
+ rr->setResponseBody(QByteArrayLiteral("<html><body>Test</body></html>"));
+ rr->sendResponse();
+ });
+ QVERIFY(server.start());
+
+ class Page : public QWebEnginePage {
+ public:
+ QWebEngineProfile *targetProfile = nullptr;
+ QScopedPointer<QWebEnginePage> newPage;
+ Page(QWebEngineProfile *profile) : QWebEnginePage(profile) {}
+ private:
+ QWebEnginePage *createWindow(WebWindowType) override
+ {
+ newPage.reset(new QWebEnginePage(targetProfile ? targetProfile : profile(), nullptr));
+ return newPage.data();
+ }
+ };
+ QWebEngineProfile profile1, profile2;
+ profile1.setHttpUserAgent(QStringLiteral("custom 1"));
+ profile2.setHttpUserAgent(QStringLiteral("custom 2"));
+ Page page(&profile1);
+ QWebEngineView view;
+ view.resize(500, 500);
+ view.setPage(&page);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QSignalSpy spy(&page, &QWebEnginePage::loadFinished);
+
+ // First check we can get the user-agent passed through normally
+ page.setHtml(QString("<html><body><a id='link' target='_blank' href='") +
+ server.url("/test1").toEncoded() +
+ QString("'>link</a></body></html>"));
+ 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"));
+ QTRY_VERIFY(page.newPage);
+ QTRY_VERIFY(!lastUserAgent.isEmpty());
+ QCOMPARE(lastUserAgent, profile1.httpUserAgent().toUtf8());
+
+ // Now check we can get the new user-agent of the profile
+ page.newPage.reset();
+ page.targetProfile = &profile2;
+ spy.clear();
+ lastUserAgent = { };
+ page.setHtml(QString("<html><body><a id='link' target='_blank' href='") +
+ server.url("/test2").toEncoded() +
+ 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"));
+ QTRY_VERIFY(page.newPage);
+ QTRY_VERIFY(!lastUserAgent.isEmpty());
+ QCOMPARE(lastUserAgent, profile2.httpUserAgent().toUtf8());
+}
+
static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")};
W_QTEST_MAIN(tst_QWebEnginePage, params)