summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/origin/cross-origin-objects/frame.html
blob: 046e49da73ce7736d2e7df9b98a0360c7978ad32 (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
<!doctype html>
<html>
<head>
<script>
  // Override the |frames| property to test that such overrides are
  // properly ignored cross-origin.
  window.frames = "override";

  // If we get a postMessage, we grab references to everything and set
  // document.domain to trim off our topmost subdomain.
  window.onmessage = function(evt) {
    window.windowReferences = [];
    window.locationReferences = [];
    for (var i = 0; i < parent.length; ++i) {
      windowReferences.push(parent[i]);
      locationReferences.push(parent[i].location);
    }
    try {
      document.domain = document.domain.substring(document.domain.indexOf('.') + 1);
      evt.source.postMessage('PASS', '*');
    } catch (e) {
      evt.source.postMessage('FAIL: cannot trim off document.domain: ' + e, '*');
    }
  }

  function checkWindowReferences() {
    for (var i = 0; i < parent.length; ++i) {
      if (windowReferences[i] != parent[i])
        throw new Error("Window references don't match for " + i + " after document.domain");
      if (locationReferences[i] != parent[i].location)
        throw new Error("Location references don't match for " + i + " after document.domain");
    }
    return true;
  }
</script>
</head>
<body>
</body>
</html>