summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebengineprofile
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-04-19 13:55:46 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-04-19 23:11:30 +0000
commit097f0e78e8a26ea1cda8b7d2e14fcf5551a72abd (patch)
treee0e4e8630182d2372cc0dd4f79e6d9184dbafd92 /tests/auto/widgets/qwebengineprofile
parent7023f228b099c410081db5c697e2d69ed57558da (diff)
Fix user-agent override works when setting content
Adds test for user-agent override and fixes the override so that it also works when loading with content instead of URLs. Change-Id: I3f61b1d91b7b0908e35216722054168d1c514a87 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebengineprofile')
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 7cd42335..e89940d7 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -52,6 +52,7 @@ private Q_SLOTS:
void profileConstructors();
void urlSchemeHandlers();
void urlSchemeHandlerFailRequest();
+ void customUserAgent();
};
void tst_QWebEngineProfile::defaultProfile()
@@ -188,5 +189,33 @@ void tst_QWebEngineProfile::urlSchemeHandlerFailRequest()
QCOMPARE(toPlainTextSync(view.page()), QString());
}
+void tst_QWebEngineProfile::customUserAgent()
+{
+ QString defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();
+ QWebEnginePage page;
+ QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setHtml(QStringLiteral("<html><body>Hello world!</body></html>"));
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+
+ // First test the user-agent is default
+ QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.userAgent")).toString(), defaultUserAgent);
+
+ const QString testUserAgent = QStringLiteral("tst_QWebEngineProfile 1.0");
+ QWebEngineProfile testProfile;
+ testProfile.setHttpUserAgent(testUserAgent);
+
+ // Test a new profile with custom user-agent works
+ QWebEnginePage page2(&testProfile);
+ QSignalSpy loadFinishedSpy2(&page2, SIGNAL(loadFinished(bool)));
+ page2.setHtml(QStringLiteral("<html><body>Hello again!</body></html>"));
+ QTRY_COMPARE(loadFinishedSpy2.count(), 1);
+ QCOMPARE(evaluateJavaScriptSync(&page2, QStringLiteral("navigator.userAgent")).toString(), testUserAgent);
+ QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.userAgent")).toString(), defaultUserAgent);
+
+ // Test an existing page and profile with custom user-agent works
+ QWebEngineProfile::defaultProfile()->setHttpUserAgent(testUserAgent);
+ QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.userAgent")).toString(), testUserAgent);
+}
+
QTEST_MAIN(tst_QWebEngineProfile)
#include "tst_qwebengineprofile.moc"