summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/infrastructure/urls/resolving-urls/query-encoding/location.sub.html
blob: 1403cf18cd18360ca9ff6f476383d5274f5fd071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!doctype html>
<meta charset={{GET[encoding]}}> <!-- ends up as <meta charset> by default which is windows-1252 -->
<meta name=variant content="?encoding=windows-1252">
<meta name=variant content="?encoding=x-cp1251">
<meta name=variant content="?encoding=utf8">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
function expected(encoding) {
  return "?" + {
    "UTF-8": "%C3%BF",
    "windows-1251": "%26%23255%3B",
    "windows-1252": "%FF"
  }[encoding];
}

[
  [(win, input) => { win.location = input; }, "location [PutForwards]"],
  [(win, input) => { win.location.assign(input); }, "location.assign()"],
  [(win, input) => { win.location.replace(input); }, "location.replace()"],
  [(win, input) => { win.location.href = input; }, "location.href"]
].forEach(([callback, desc]) => {
  async_test(t => {
    const frame = document.body.appendChild(document.createElement("iframe")),
          actualEncoding = document.characterSet
    callback(frame.contentWindow, "/common/blank.html?\u00FF");
    frame.onload = t.step_func_done(() => {
      assert_equals(frame.contentWindow.location.search, expected(actualEncoding));
    });
  }, desc);
});

async_test(t => {
  const frame = document.body.appendChild(document.createElement("iframe")),
        actualEncoding = document.characterSet;
  frame.src = "/common/blank.html";
  frame.onload = t.step_func(() => {
    frame.contentWindow.location.search = "\u00FF";
    frame.onload = t.step_func_done(() => {
      // location.search always uses UTF-8
      assert_equals(frame.contentWindow.location.search, expected("UTF-8"));
    });
  });
}, "location.search");
</script>