diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-04-21 14:35:28 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-04-21 15:26:12 +0000 |
commit | ad82daf8f597855aefbaa190ab89abb148362c7f (patch) | |
tree | b75476ab40f6132f4df39628d4e73cd7d51ee72b /tests | |
parent | a1eda6b9aa885619a357f5532e584092b8e5bf91 (diff) |
Do not access browser-context to read user-agent or accept language
Switches HttpUserAgentSettingsQt to reading local string that lives on
the IO thread, instead of accessing a pointer that may be deleted.
Also adds a test and fixes updating accept-language of already
initialized WebContents.
Change-Id: Iff4e3bd1ac40482a92bed50c3f703ed8b974b0ad
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index e89940d71..287e2364a 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -53,6 +53,7 @@ private Q_SLOTS: void urlSchemeHandlers(); void urlSchemeHandlerFailRequest(); void customUserAgent(); + void httpAcceptLanguage(); }; void tst_QWebEngineProfile::defaultProfile() @@ -217,5 +218,32 @@ void tst_QWebEngineProfile::customUserAgent() 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" |