content/html/document/test/test_bug445004.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/html/document/test/test_bug445004.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=445004
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 445004</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=445004">Mozilla Bug 445004</a>
    1.16 +<div id="content" style="display: none">
    1.17 +  
    1.18 +</div>
    1.19 +<pre id="test">
    1.20 +<script type="application/javascript">
    1.21 +
    1.22 +/** Test for Bug 445004 **/
    1.23 +is(window.location.hostname, "mochi.test", "Unexpected hostname");
    1.24 +is(window.location.port, "8888", "Unexpected port; fix testcase");
    1.25 +
    1.26 +SimpleTest.waitForExplicitFinish();
    1.27 +
    1.28 +var loads = 1;
    1.29 +
    1.30 +function loadStarted() {
    1.31 +  ++loads;
    1.32 +}
    1.33 +function loadEnded() {
    1.34 +  --loads;
    1.35 +  if (loads == 0) {
    1.36 +    doTest();
    1.37 +  }
    1.38 +}
    1.39 +
    1.40 +window.onload = loadEnded;
    1.41 +
    1.42 +function getMessage(evt) {
    1.43 +  ok(evt.data == "start" || evt.data == "end", "Must have start or end");
    1.44 +  if (evt.data == "start")
    1.45 +    loadStarted();
    1.46 +  else
    1.47 +    loadEnded();
    1.48 +}
    1.49 +
    1.50 +window.addEventListener("message", getMessage, false);
    1.51 +
    1.52 +function checkURI(uri, name, type) {
    1.53 +  var host = uri.match(/^http:\/\/([a-z.0-9]*)/)[1];
    1.54 +  var file = uri.match(/([^\/]*).png$/)[1];
    1.55 +  is(host, file, "Unexpected base URI for test " + name +
    1.56 +     " when testing " + type);
    1.57 +}
    1.58 +
    1.59 +function checkFrame(num) {
    1.60 +  // Just snarf our data
    1.61 +  var outer = SpecialPowers.wrap(window.frames[num]);
    1.62 +  name = outer.name;
    1.63 +
    1.64 +  is(outer.document.baseURI,
    1.65 +     "http://example.org/tests/content/html/document/test/bug445004-outer.html",
    1.66 +     "Unexpected base URI for " + name);
    1.67 +
    1.68 +  var iswrite = name.match(/write/);
    1.69 +
    1.70 +  var inner = outer.frames[0];
    1.71 +  if (iswrite) {
    1.72 +    is(inner.document.baseURI,
    1.73 +       "http://example.org/tests/content/html/document/test/bug445004-outer.html",
    1.74 +       "Unexpected inner base URI for " + name);
    1.75 +  } else {
    1.76 +    is(inner.document.baseURI,
    1.77 +       "http://test1.example.org/tests/content/html/document/test/bug445004-inner.html",
    1.78 +       "Unexpected inner base URI for " + name);
    1.79 +  }
    1.80 +
    1.81 +  var isrel = name.match(/rel/);
    1.82 +  var offsite = name.match(/offsite/);
    1.83 +
    1.84 +  if (!iswrite) {
    1.85 +    if ((isrel && !offsite) || (!isrel && offsite)) {
    1.86 +      is(inner.location.hostname, outer.location.hostname,
    1.87 +         "Unexpected hostnames for " + name);
    1.88 +    } else {
    1.89 +      isnot(inner.location.hostname, outer.location.hostname,
    1.90 +            "Unexpected hostnames for " + name);
    1.91 +    }
    1.92 +  }
    1.93 +
    1.94 +  checkURI(inner.frames[0].location.href, name, "direct location");
    1.95 +  checkURI(inner.frames[1].document.getElementsByTagName("img")[0].src,
    1.96 +           name, "direct write");
    1.97 +  if (!iswrite) {
    1.98 +    is(inner.frames[1].location.hostname, inner.location.hostname,
    1.99 +       "Incorrect hostname for " + name + " direct write")
   1.100 +  }
   1.101 +  checkURI(inner.frames[2].location.href, name, "indirect location");
   1.102 +  checkURI(inner.frames[3].document.getElementsByTagName("img")[0].src,
   1.103 +           name, "indirect write");
   1.104 +  if (!iswrite) {
   1.105 +    is(inner.frames[3].location.hostname, outer.location.hostname,
   1.106 +       "Incorrect hostname for " + name + " indirect write")
   1.107 +  }
   1.108 +  checkURI(inner.document.getElementsByTagName("img")[0].src,
   1.109 +           name, "direct image load");
   1.110 +}
   1.111 +
   1.112 +
   1.113 +function doTest() {
   1.114 +  for (var num = 0; num < 5; ++num) {
   1.115 +    checkFrame(num);
   1.116 +  }
   1.117 +
   1.118 +  SimpleTest.finish();
   1.119 +}
   1.120 +
   1.121 +</script>
   1.122 +</pre>
   1.123 +<p id="display">
   1.124 +  <iframe
   1.125 +     src="http://example.org/tests/content/html/document/test/bug445004-outer-rel.html"
   1.126 +     name="bug445004-outer-rel.html"></iframe>
   1.127 +  <iframe
   1.128 +     src="http://test1.example.org/tests/content/html/document/test/bug445004-outer-rel.html"
   1.129 +     name="bug445004-outer-rel.html offsite"></iframe>
   1.130 +  <iframe
   1.131 +     src="http://example.org/tests/content/html/document/test/bug445004-outer-abs.html"
   1.132 +     name="bug445004-outer-abs.html"></iframe>
   1.133 +  <iframe
   1.134 +     src="http://test1.example.org/tests/content/html/document/test/bug445004-outer-abs.html"
   1.135 +     name="bug445004-outer-abs.html offsite"></iframe>
   1.136 +  <iframe
   1.137 +     src="http://example.org/tests/content/html/document/test/bug445004-outer-write.html"
   1.138 +     name="bug445004-outer-write.html"></iframe>
   1.139 +</p>
   1.140 +</body>
   1.141 +</html>

mercurial