Skip to content

Truly independent web browser

Tests/LibWeb: Import WPT test for the encoding of Location URLs

Andreas Klinga71c85f7d25a
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 1658cef4ea3..d6c5e3c865c 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -151,6 +151,9 @@ Text/input/wpt-import/html/browsers/history/the-history-interface/history_replac
Text/input/wpt-import/html/browsers/browsing-the-web/history-traversal/hashchange_event.html
Text/input/wpt-import/html/browsers/browsing-the-web/history-traversal/popstate_event.html
+; Compares the URLs of HTTP documents, which need an HTTP origin.
+Text/input/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.html
+
; Calls reload() on a child window's Location, which requires a shared tuple origin.
Text/input/wpt-import/html/browsers/history/the-location-interface/reload_document_write.html
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txt
new file mode 100644
index 00000000000..01cab1af6aa
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Fail location.replace() should use document encoding (windows-1252)
+Fail location.assign() should use document encoding (windows-1252)
+Pass location.href setter should use document encoding (windows-1252)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.html
new file mode 100644
index 00000000000..5fc20694847
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.html
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<meta charset="windows-1252">
+<title>Location uses encoding-parse a URL</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<body>
+<script>
+// Test for location.replace()
+async_test(t => {
+ const iframe = document.createElement('iframe');
+ iframe.src = 'resources/blank.html';
+
+ iframe.onload = t.step_func(() => {
+ if (!iframe.contentWindow.location.href.includes('test=')) {
+ iframe.contentWindow.location.replace(
+ iframe.contentWindow.location.href + '?test=\u00DF'
+ );
+ } else {
+ assert_equals(
+ iframe.contentWindow.location.search,
+ '?test=%DF',
+ 'URL should use windows-1252 encoding'
+ );
+ t.done();
+ }
+ });
+
+ document.body.appendChild(iframe);
+}, 'location.replace() should use document encoding (windows-1252)');
+
+// Test for location.assign()
+async_test(t => {
+ const iframe = document.createElement('iframe');
+ iframe.src = 'resources/blank.html';
+
+ iframe.onload = t.step_func(() => {
+ if (!iframe.contentWindow.location.href.includes('assign=')) {
+ iframe.contentWindow.location.assign(
+ iframe.contentWindow.location.href + '?assign=\u00DF'
+ );
+ } else {
+ assert_equals(
+ iframe.contentWindow.location.search,
+ '?assign=%DF',
+ 'URL should use windows-1252 encoding'
+ );
+ t.done();
+ }
+ });
+
+ document.body.appendChild(iframe);
+}, 'location.assign() should use document encoding (windows-1252)');
+
+// Test for location.href setter
+async_test(t => {
+ const iframe = document.createElement('iframe');
+ iframe.src = 'resources/blank.html';
+
+ iframe.onload = t.step_func(() => {
+ if (!iframe.contentWindow.location.href.includes('href=')) {
+ iframe.contentWindow.location.href =
+ iframe.contentWindow.location.href + '?href=\u00DF';
+ } else {
+ assert_equals(
+ iframe.contentWindow.location.search,
+ '?href=%DF',
+ 'URL should use windows-1252 encoding'
+ );
+ t.done();
+ }
+ });
+
+ document.body.appendChild(iframe);
+}, 'location.href setter should use document encoding (windows-1252)');
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-location-interface/resources/blank.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-location-interface/resources/blank.html
new file mode 100644
index 00000000000..1de596b3c65
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/history/the-location-interface/resources/blank.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html>
+<meta charset="windows-1252">
+<title>Blank page</title>