4 https://bugzilla.mozilla.org/show_bug.cgi?id=801576
8 <title>Test for Bug
801576</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=801576">Mozilla Bug
801576</a>
15 <div id=
"content" style=
"display: none">
18 <script type=
"application/javascript">
20 /** Test for the same-origin policy. **/
21 SimpleTest.waitForExplicitFinish();
23 function check(obj, prop, allowed, write) {
31 Object.defineProperty(obj, 'prop', {getter: function() {}, setter: null});
37 is(accessed, allowed, prop +
" is correctly (in)accessible for " + (write ? 'write' : 'read'));
40 var crossOriginReadableWindowProps = ['blur', 'close', 'closed', 'focus',
41 'frames', 'location', 'length',
42 'opener', 'parent', 'postMessage',
43 'self', 'top', 'window',
44 /* indexed and named accessors */
47 function isCrossOriginReadable(obj, prop) {
49 return crossOriginReadableWindowProps.includes(prop);
50 if (obj ==
"Location")
51 return prop == 'replace';
55 function isCrossOriginWritable(obj, prop) {
57 return prop == 'location';
58 if (obj ==
"Location")
59 return prop == 'href';
62 // NB: we don't want to succeed with writes, so we only check them when it should be denied.
63 function testAll(sameOrigin) {
64 var win = document.getElementById('ifr').contentWindow;
66 // Build a list of properties to check from the properties available on our
69 for (var prop in window) { props.push(prop); }
71 // On android, this appears to be on the window but not on the iframe. It's
72 // not really relevant to this test, so just skip it.
73 if (props.includes('crypto'))
74 props.splice(props.indexOf('crypto'),
1);
76 // Add the named grand-child, since that won't appear on our window.
77 props.push('subframe');
79 for (var prop of props) {
80 check(win, prop, sameOrigin || isCrossOriginReadable('Window', prop), /* write = */ false);
81 if (!sameOrigin && !isCrossOriginWritable('Window', prop))
82 check(win, prop, false, /* write = */ true);
84 for (var prop in window.location) {
85 check(win.location, prop, sameOrigin || isCrossOriginReadable('Location', prop));
86 if (!sameOrigin && !isCrossOriginWritable('Location', prop))
87 check(win.location, prop, false, /* write = */ true);
96 document.getElementById('ifr').contentWindow.location = 'http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html';
107 <iframe id=
"ifr" onload=
"go();" src=
"file_empty.html"></iframe>