AW: fix testDefaultTextEncodingWithTwoViews
No change to production logic. This rewrites
AwSettingsTest.testDefaultTextEncodingWithTwoViews. The test was
originally disabled because it relied on 'document.defaultCharset',
which has since been deprecated and removed. This change fixes the test
to instead use some UTF-8 text and verify it cannot be decoded properly
when the charset is Latin-1.
Fixed: 587484
Test: run_webview_instrumentation_test_apk -f AwSettingsTest.testDefaultTextEncodingWithTwoViews
Change-Id: I74350fe36ced6c63013e28283832d8ca3ad46279
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3294103
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Auto-Submit: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: Shimi Zhang <ctzsm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#943782}
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
index 4c1f61e..30d3e12e 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java
@@ -416,6 +416,10 @@
super(containerView, contentViewClient, true);
}
+ // A string which can be encoded by UTF-8 charset but not by Latin-1 charset. Translates to
+ // "Hello world."
+ private static final String NON_LATIN_TEXT = "你好世界";
+
@Override
protected String getAlteredValue() {
return "Latin-1";
@@ -439,11 +443,21 @@
@Override
protected void doEnsureSettingHasValue(String value) throws Throwable {
loadDataSync(getData());
- Assert.assertEquals(value, getTitleOnUiThread());
+
+ if ("UTF-8".equals(value)) {
+ Assert.assertEquals("Title should be decoded correctly when charset is UTF-8",
+ NON_LATIN_TEXT, getTitleOnUiThread());
+ } else {
+ // The content seems to decode as "ä½ å¥½ä¸–ç•Œ", but it's sufficient to just
+ // enforce the text decodes incorrectly.
+ Assert.assertNotEquals(
+ "Title should be garbled (decoded incorrectly) when charset is Latin-1",
+ NON_LATIN_TEXT, getTitleOnUiThread());
+ }
}
private String getData() {
- return "<html><body onload='document.title=document.defaultCharset'></body></html>";
+ return "<html><body onload='document.title=\"" + NON_LATIN_TEXT + "\"'></body></html>";
}
}
@@ -1740,12 +1754,9 @@
views.getContainer1(), views.getClient1(), new ImagePageGenerator(1, true)));
}
- /*
- * @SmallTest
- * @Feature({"AndroidWebView", "Preferences"})
- */
@Test
- @DisabledTest(message = "Disabled due to document.defaultCharset removal. crbug.com/587484")
+ @SmallTest
+ @Feature({"AndroidWebView", "Preferences"})
public void testDefaultTextEncodingWithTwoViews() throws Throwable {
ViewPair views = createViews();
runPerViewSettingsTest(