summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/dom-level0/idn_child.html
blob: 7a44d790ea2eaa510e3290b52ffd5c91178359cd (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Child window on a site whose "base" domain contains IDN</title>
  <script type="application/javascript">
function run()
{
  var target = document.getElementById("location");
  target.textContent = location.hostname + ":" + (location.port || 80);
}

function receiveMessage(evt)
{
  if (evt.origin !== "http://mochi.test:8888")
    return;

  var message = evt.data + "-response";

  var domain = document.domain;
  if (/test$/.test(domain))
  {
    if (domain !== "sub1.xn--exaple-kqf.test")
      message += " wrong-initial-domain(" + domain + ")";
  }
  else
  {
    if (domain !== "sub1.xn--hxajbheg2az3al.xn--jxalpdlp")
      message += " wrong-initial-domain(" + domain + ")";
  }

  switch (location.search)
  {
    case "?idn-whitelist":
      message += idnTest("παράδειγμα.δοκιμή");
      break;

    case "?punycode-whitelist":
      message  += punycodeTest("xn--hxajbheg2az3al.xn--jxalpdlp");
      break;

    case "?idn-nowhitelist":
      message += idnTest("exaмple.test");
      break;

    case "?punycode-nowhitelist":
      message  += punycodeTest("xn--exaple-kqf.test");
      break;

    default:
      message += " unexpected-query(" + location.search + ")";
      break;
  }

  evt.source.postMessage(message, evt.origin);
}

function idnTest(newDomain)
{
  var errors = "";

  try
  {
    document.domain = newDomain;
  }
  catch (e)
  {
    errors += " error-thrown-setting-to-idn(" + String(e).split("").join(",") + ")";
  }

  return errors;
}

function punycodeTest(newDomain)
{
  var errors = "";

  try
  {
    document.domain = newDomain;
  }
  catch (e)
  {
    errors += " error-thrown-setting-to-punycode(" + String(e).split("").join(",") + ")";
  }

  return errors;
}

window.addEventListener("message", receiveMessage);
window.addEventListener("load", run);
  </script>
</head>
<body>
<h1 id="location">Somewhere!</h1>
</body>
</html>