From ad82daf8f597855aefbaa190ab89abb148362c7f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 21 Apr 2016 14:35:28 +0200 Subject: 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 Reviewed-by: Michal Klocek --- .../qwebengineprofile/tst_qwebengineprofile.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto') 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("Hello world!")); + 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("Hello again!")); + 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" -- cgit v1.2.3