summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/dom/self-origin.sub.html
blob: aba2b3016a5d56e29cdf5526b7b7259e402c188d (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
<!DOCTYPE HTML>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<iframe></iframe>
<iframe id="blob-test"></iframe> <!-- will get blob: URI -->
<iframe src="javascript:'javascript'"></iframe>
<iframe srcdoc="srcdoc"></iframe>
<!-- Use the non-default HTTP port so we can make sure it gets included in
     self.origin -->
<iframe src="http://{{domains[www1]}}:{{ports[http][1]}}{{location[path]}}/../resources/self-origin-subframe.html"></iframe>
<!-- Using the Unicode version on purpose, we expect to get back the Punycode
     version in self.origin -->
<iframe src="http://élève.{{domains[]}}:{{ports[http][1]}}{{location[path]}}/../resources/self-origin-subframe.html"></iframe>
<iframe src="resources/self-origin-subframe.html" sandbox="allow-scripts"></iframe>
<script type="application/javascript">
test(function() {
  var blob = new Blob(['blob']);
  var url = URL.createObjectURL(blob);
  document.getElementById("blob-test").src = url;
}, "Assigning blob url");

/* Each message test is a four things: window to send message to, message to
   send, expected response, async test to use. */
var messageTests = [
  [ frames[4], "getOrigin", "http://{{domains[www1]}}:{{ports[http][1]}}",
    async_test("Should have the right origin for cross-origin subframe") ],
  [ frames[4], "setDomainAndGetOrigin", "http://{{domains[www1]}}:{{ports[http][1]}}",
    async_test("Should have the right origin for cross-origin subframe after setting document.domain") ],
  [ frames[5], "getOrigin", "http://xn--lve-6lad.{{domains[]}}:{{ports[http][1]}}",
    async_test("Should have the right origin for IDN subframe") ],
  [ frames[5], "setDomainAndGetOrigin", "http://xn--lve-6lad.{{domains[]}}:{{ports[http][1]}}",
    async_test("Should have the right origin for IDN subframe after setting document.domain") ],
  [ frames[6], "getOrigin", "null",
    async_test("Should have the right origin for sandboxed iframe") ],
];

var curTest = 0;
function nextMessageTest() {
  if (curTest == messageTests.length) {
    return;
  }

  var testData = messageTests[curTest];
  testData[0].postMessage(testData[1], "*");
}

window.onmessage = function(e) {
  var testData = messageTests[curTest++];
  testData[3].step(function() {
    assert_equals(e.data, testData[2])
  });
  testData[3].done();
  nextMessageTest();
}

addEventListener("load", nextMessageTest);

test(function() {
  assert_equals(self.origin, "http://{{location[host]}}");
}, "We should have the right origin for our page");

var t1 = async_test("about:blank subframe origins");
addEventListener("load", t1.step_func_done(function() {
  assert_equals(frames[0].location.origin, "null",
                "Should have the right location origin for about:blank iframe");
  assert_equals(frames[0].origin, "http://{{location[host]}}",
                "Should have the right origin for about:blank iframe");
}));

var t2 = async_test("blob: subframe origins");
addEventListener("load", t2.step_func_done(function() {
  assert_equals(frames[1].location.origin, "http://{{location[host]}}",
                "Should have the right location origin for blob: iframe");
  assert_equals(frames[1].origin, "http://{{location[host]}}",
                "Should have the right origin for blob: iframe");
}));

var t3 = async_test("javascript: subframe origins");
addEventListener("load", t3.step_func_done(function() {
  assert_equals(frames[2].origin, "http://{{location[host]}}",
                "Should have the right origin for javascript: iframe");
}));

var t4 = async_test("srcdoc subframe origins");
addEventListener("load", t4.step_func_done(function() {
  assert_equals(frames[3].location.origin, "null",
                "Should have the right location origin for srcdoc iframe");
  assert_equals(frames[3].origin, "http://{{location[host]}}",
                "Should have the right origin for srcdoc iframe");
}));
</script>