dom/tests/mochitest/dom-level0/idn_child.html
author jwalden@mit.edu
Tue, 26 Feb 2008 19:48:54 -0800
changeset 12322 293a55a0a16d303d004f79cd1c41e33c39d12e73
parent 11364 e178412af25d5af6d62e6fb7da4afd4403f96141
child 14898 c29d990c4499d37578a6a4c8679a5c9e80f02ccf
permissions -rw-r--r--
Bug 417075 - Update postMessage and MessageEvent to reflect domain/uri being replaced by origin, optional origin argument. r+sr=sicking, a=beltzner

<!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://localhost:8888")
    return;

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

  var domain = document.domain;
  if (/test$/.test(domain))
  {
    // XXX should really be IDN (bug 414090)
    //if (domain !== "sub1.exämple.test")
    //  message += " wrong-initial-domain(" + domain + ")";
    // for now expect the punycode value
    if (domain !== "sub1.xn--exmple-cua.test")
      message += " wrong-initial-domain(" + domain + ")";
  }
  else
  {
    if (domain !== "sub1.παράδειγμα.δοκιμή")
      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("exämple.test");
      break;

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

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

  evt.source.postMessage(message);
}

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;
}

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