summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug445004.html
blob: 02fc79f42547f33cac47cf8f1e81cf79b72441dc (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=445004
-->
<head>
  <title>Test for Bug 445004</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=445004">Mozilla Bug 445004</a>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 445004 **/
is(window.location.hostname, "mochi.test", "Unexpected hostname");
is(window.location.port, "8888", "Unexpected port; fix testcase");

SimpleTest.waitForExplicitFinish();

var loads = 1;

function loadStarted() {
  ++loads;
}
function loadEnded() {
  --loads;
  if (loads == 0) {
    doTest();
  }
}

window.onload = loadEnded;

function getMessage(evt) {
  ok(evt.data == "start" || evt.data == "end", "Must have start or end");
  if (evt.data == "start")
    loadStarted();
  else
    loadEnded();
}

window.addEventListener("message", getMessage);

function checkURI(uri, name, type) {
  var host = uri.match(/^http:\/\/([a-z.0-9]*)/)[1];
  var file = uri.match(/([^\/]*).png$/)[1];
  is(host, file, "Unexpected base URI for test " + name +
     " when testing " + type);
}

function checkFrame(num) {
  // Just snarf our data
  var outer = SpecialPowers.wrap(window.frames[num]);
  name = outer.name;

  is(outer.document.baseURI,
     "http://example.org/tests/dom/html/test/bug445004-outer.html",
     "Unexpected base URI for " + name);

  var iswrite = name.match(/write/);

  var inner = outer.frames[0];
  if (iswrite) {
    is(inner.document.baseURI,
       "http://example.org/tests/dom/html/test/bug445004-outer.html",
       "Unexpected inner base URI for " + name);
  } else {
    is(inner.document.baseURI,
       "http://test1.example.org/tests/dom/html/test/bug445004-inner.html",
       "Unexpected inner base URI for " + name);
  }

  var isrel = name.match(/rel/);
  var offsite = name.match(/offsite/);

  if (!iswrite) {
    if ((isrel && !offsite) || (!isrel && offsite)) {
      is(inner.location.hostname, outer.location.hostname,
         "Unexpected hostnames for " + name);
    } else {
      isnot(inner.location.hostname, outer.location.hostname,
            "Unexpected hostnames for " + name);
    }
  }

  checkURI(inner.frames[0].location.href, name, "direct location");
  checkURI(inner.frames[1].document.getElementsByTagName("img")[0].src,
           name, "direct write");
  if (!iswrite) {
    is(inner.frames[1].location.hostname, inner.location.hostname,
       "Incorrect hostname for " + name + " direct write")
  }
  checkURI(inner.frames[2].location.href, name, "indirect location");
  checkURI(inner.frames[3].document.getElementsByTagName("img")[0].src,
           name, "indirect write");
  if (!iswrite) {
    is(inner.frames[3].location.hostname, outer.location.hostname,
       "Incorrect hostname for " + name + " indirect write")
  }
  checkURI(inner.document.getElementsByTagName("img")[0].src,
           name, "direct image load");
}


function doTest() {
  for (var num = 0; num < 5; ++num) {
    checkFrame(num);
  }

  SimpleTest.finish();
}

</script>
</pre>
<p id="display">
  <iframe
     src="http://example.org/tests/dom/html/test/bug445004-outer-rel.html"
     name="bug445004-outer-rel.html"></iframe>
  <iframe
     src="http://test1.example.org/tests/dom/html/test/bug445004-outer-rel.html"
     name="bug445004-outer-rel.html offsite"></iframe>
  <iframe
     src="http://example.org/tests/dom/html/test/bug445004-outer-abs.html"
     name="bug445004-outer-abs.html"></iframe>
  <iframe
     src="http://test1.example.org/tests/dom/html/test/bug445004-outer-abs.html"
     name="bug445004-outer-abs.html offsite"></iframe>
  <iframe
     src="http://example.org/tests/dom/html/test/bug445004-outer-write.html"
     name="bug445004-outer-write.html"></iframe>
</p>
</body>
</html>