summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2021-03-24 14:23:31 +0100
committerSzabolcs David <davidsz@inf.u-szeged.hu>2021-04-21 16:09:49 +0200
commit0b7510efcde8220e55b0cef5fefc1db76a3bd99a (patch)
tree5e1c9399185d2484cd880d8910d237cce4f407ea /tests
parentb29b245fcb9db741d14180ea7e8dcb3ad2d4f49a (diff)
Fix application locales again
Different countries (with the same language) can have different number formatting and navigator.language should report not only the language, but also the country. Locale normalization often falls back by cutting the country off, because we have common .pak files for countries with the same language. This patch: - Uses the locale resolvation only for concatenating .pak file paths and reports the full locale everywhere else. - Properly sets default ICU locale for JS number formats and prevents l10n_util::GetApplicationLocale() to set it sneakily to some resolved one. - Fixes the crashing --lang command line argument and always prefers its value over QLocale. Task-number: QTBUG-91225 Change-Id: I1c09798abdb523b80f0b7a3d69fa8d7a08c7c09a Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/qwebengineview/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp49
2 files changed, 38 insertions, 14 deletions
diff --git a/tests/auto/widgets/qwebengineview/BLACKLIST b/tests/auto/widgets/qwebengineview/BLACKLIST
index 05ebee4ce..c1a46e16d 100644
--- a/tests/auto/widgets/qwebengineview/BLACKLIST
+++ b/tests/auto/widgets/qwebengineview/BLACKLIST
@@ -6,3 +6,6 @@ windows
[horizontalScrollbarTest]
osx
+
+[mixLangLocale:eu_ES]
+*
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index d86810713..4854b3603 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -124,6 +124,7 @@ private Q_SLOTS:
void doNotBreakLayout();
void changeLocale();
+ void mixLangLocale_data();
void mixLangLocale();
void inputMethodsTextFormat_data();
void inputMethodsTextFormat();
@@ -1213,26 +1214,46 @@ void tst_QWebEngineView::changeLocale()
QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("Die Website ist nicht erreichbar"));
}
+void tst_QWebEngineView::mixLangLocale_data()
+{
+ QTest::addColumn<QString>("locale");
+ QTest::addColumn<QByteArray>("formattedNumber");
+ QTest::newRow("en_DK") << "en-DK" << QByteArray("1.234.567.890");
+ QTest::newRow("de") << "de" << QByteArray("1.234.567.890");
+ QTest::newRow("de_CH") << "de-CH" << QByteArray("1’234’567’890");
+ QTest::newRow("eu_ES") << "eu-ES" << QByteArray("1.234.567.890");
+ QTest::newRow("hu_HU") << "hu-HU" << QByteArray("1\xC2\xA0""234\xC2\xA0""567\xC2\xA0""890"); // no-break spaces
+}
+
void tst_QWebEngineView::mixLangLocale()
{
- for (QString locale : { "en_DK", "de_CH", "eu_ES" }) {
- QLocale::setDefault(locale);
- QWebEngineView view;
- QSignalSpy loadSpy(&view, &QWebEngineView::loadFinished);
+ QFETCH(QString, locale);
+ QFETCH(QByteArray, formattedNumber);
- bool terminated = false;
- auto sc = connect(view.page(), &QWebEnginePage::renderProcessTerminated, [&] () { terminated = true; });
+ QLocale::setDefault(locale);
- view.load(QUrl("qrc:///resources/dummy.html"));
- QTRY_VERIFY(terminated || loadSpy.count() == 1);
+ QWebEngineView view;
+ QSignalSpy loadSpy(&view, &QWebEngineView::loadFinished);
- QVERIFY2(!terminated,
- qPrintable(QString("Locale [%1] terminated: %2, loaded: %3").arg(locale).arg(terminated).arg(loadSpy.count())));
- QVERIFY(loadSpy.first().first().toBool());
+ bool terminated = false;
+ auto sc = connect(view.page(), &QWebEnginePage::renderProcessTerminated, [&] () { terminated = true; });
+
+ view.load(QUrl("qrc:///resources/dummy.html"));
+ QTRY_VERIFY(terminated || loadSpy.count() == 1);
+
+ QVERIFY2(!terminated,
+ qPrintable(QString("Locale [%1] terminated: %2, loaded: %3").arg(locale).arg(terminated).arg(loadSpy.count())));
+ QVERIFY(loadSpy.first().first().toBool());
+
+ QString content = toPlainTextSync(view.page());
+ QVERIFY2(!content.isEmpty() && content.contains("test content"), qPrintable(content));
+
+ QCOMPARE(evaluateJavaScriptSync(view.page(), "navigator.language").toString(), QLocale().bcp47Name());
+
+ if (locale == "eu-ES")
+ QEXPECT_FAIL("", "Basque number formatting is somehow dependent on environment", Continue);
+ QCOMPARE(evaluateJavaScriptSync(view.page(), "Number(1234567890).toLocaleString()").toByteArray(), formattedNumber);
- QString content = toPlainTextSync(view.page());
- QVERIFY2(!content.isEmpty() && content.contains("test content"), qPrintable(content));
- }
QLocale::setDefault(QLocale("en"));
}