summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebengineprofile
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-04-25 11:47:47 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-04-25 12:40:00 +0200
commit658a964cf2593e6da3b1a822124e796bbe354d36 (patch)
tree8c35a964023069a974f1c54cd679490593e485f2 /tests/auto/widgets/qwebengineprofile
parent63cf26268996ae5580c77095a252696fa549b593 (diff)
parenta3318c84b022282a5a4a2babc51d1e3ca634e25b (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Diffstat (limited to 'tests/auto/widgets/qwebengineprofile')
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index e73ab637b..95d5cf16a 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -47,6 +47,8 @@ private Q_SLOTS:
void disableCache();
void urlSchemeHandlers();
void urlSchemeHandlerFailRequest();
+ void customUserAgent();
+ void httpAcceptLanguage();
};
void tst_QWebEngineProfile::defaultProfile()
@@ -253,5 +255,60 @@ 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);
+}
+
+void tst_QWebEngineProfile::httpAcceptLanguage()
+{
+ QWebEnginePage page;
+ QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setHtml(QStringLiteral("<html><body>Hello world!</body></html>"));
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+
+ QStringList defaultLanguages = evaluateJavaScriptSync(&page, QStringLiteral("navigator.languages")).toStringList();
+
+ const QString testLang = QStringLiteral("xx-YY");
+ QWebEngineProfile testProfile;
+ testProfile.setHttpAcceptLanguage(testLang);
+
+ // Test a completely new profile
+ 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.languages")).toStringList(), QStringList(testLang));
+ // Test the old one wasn't affected
+ QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.languages")).toStringList(), defaultLanguages);
+
+ // Test changing an existing page and profile
+ QWebEngineProfile::defaultProfile()->setHttpAcceptLanguage(testLang);
+ QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("navigator.languages")).toStringList(), QStringList(testLang));
+}
+
QTEST_MAIN(tst_QWebEngineProfile)
#include "tst_qwebengineprofile.moc"