2 <?xml-stylesheet type=
"text/css" href=
"chrome://global/skin"?>
3 <?xml-stylesheet type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css"?>
5 https://bugzilla.mozilla.org/show_bug.cgi?id=758415
7 <window title=
"Mozilla Bug 758415"
8 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
11 <!-- test results are displayed in the html:body -->
12 <body xmlns=
"http://www.w3.org/1999/xhtml">
13 <a href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=758415"
14 target=
"_blank">Mozilla Bug
758415</a>
17 <!-- test code goes here -->
18 <script type=
"application/javascript">
21 /** Test for Cross-Origin Xray Expando Sharing. **/
22 SimpleTest.waitForExplicitFinish();
24 // Import our test JSM. We first strip the filename off
25 // the chrome url, then append the jsm filename.
26 var base = /.*\//.exec(window.location.href)[
0];
27 const {checkFromJSM} = ChromeUtils.import(base +
"file_expandosharing.jsm");
29 // Wait for all child frames to load.
31 function frameLoaded() {
32 if (++gLoadCount == window.frames.length)
38 // Empower the content windows with some functions.
39 var wins = document.getElementsByTagName('iframe');
40 for (var i =
0; i < wins.length; ++i) {
41 var win = wins[i].contentWindow.wrappedJSObject;
46 // Grab references to the content windows. We abbreviate the origins as follows:
47 // A: test1.example.org
48 // B: test2.example.org
49 // C: sub1.test1.example.org
50 window.gWinA1 = document.getElementById('frameA1').contentWindow;
51 window.gWinA2 = document.getElementById('frameA2').contentWindow;
52 window.gWinA3 = document.getElementById('frameA3').contentWindow;
53 window.gWinB = document.getElementById('frameB').contentWindow;
54 window.gWinC = document.getElementById('frameC').contentWindow;
56 /* globals gWinA1, gWinA2, gWinA3, gWinB, gWinC */
58 // Test expando sharing with a JSM for different types of Xrays.
59 testJSM(Cu.unwaiveXrays(gWinC.wrappedJSObject.targetWN));
60 testJSM(Cu.unwaiveXrays(gWinC.wrappedJSObject.targetDOM));
61 testJSM(Cu.unwaiveXrays(gWinC.wrappedJSObject.targetJS));
63 // Make sure sandboxes never share expandos with anyone else.
64 testSandbox(Cu.unwaiveXrays(gWinB.wrappedJSObject.targetWN));
65 testSandbox(Cu.unwaiveXrays(gWinB.wrappedJSObject.targetDOM));
66 testSandbox(Cu.unwaiveXrays(gWinB.wrappedJSObject.targetJS));
68 // Test Content Xrays.
74 // Make sure that expandos are shared between us and a JSM.
75 function testJSM(target) {
77 target.strProp =
"foo";
78 target.objProp = { bar:
"baz" };
79 checkFromJSM(target, is);
82 function testSandbox(target) {
84 // This gets both run in this scope and the sandbox scope.
86 function placeExpando() {
90 // Set up the sandboxes. Use an expanded principal to get xrays with
91 // exclusive expandos.
92 let sb1 = Cu.Sandbox([
"https://test1.example.org",
"https://test2.example.org"]);
93 let sb2 = Cu.Sandbox([
"https://test1.example.org",
"https://test2.example.org"]);
96 sb1.name =
"sandbox1";
97 sb2.name =
"sandbox2";
99 Cu.evalInSandbox(placeExpando.toSource() +
"placeExpando();", sb1);
100 Cu.evalInSandbox(placeExpando.toSource() +
"placeExpando();", sb2);
102 // Make sure everyone sees a different value.
103 is(target.prop,
"harness",
"Harness sees its own value");
104 is(Cu.evalInSandbox(
"target.prop", sb1),
"sandbox1",
"Sandbox 1 sees its own value");
105 is(Cu.evalInSandbox(
"target.prop", sb2),
"sandbox2",
"Sandbox 2 sees its own value");
108 // Make sure that the origin tagging machinery works correctly and that we don't
109 // mix up chrome and content expandos.
110 function testContentXrays() {
112 // Give A1 and A3 xrays to (same-origin) A2.
113 Cu.setWantXrays(gWinA1);
114 Cu.setWantXrays(gWinA3);
116 gWinA1.wrappedJSObject.placeExpando('A1_expando',
11, gWinA2.document);
117 gWinA3.wrappedJSObject.placeExpando('A3_expando',
33, gWinA2.document);
118 gWinA2.document.Chrome_expando =
33;
120 is(gWinA2.document.Chrome_expando,
33,
"Read chrome expando properly");
121 is(typeof gWinA2.document.A1_expando, 'undefined',
"Chrome doesn't see content expandos");
122 is(typeof gWinA2.document.A3_expando, 'undefined',
"Chrome doesn't see content expandos");
123 gWinA1.wrappedJSObject.checkExpando('A1_expando',
11, gWinA2.document,
"Content sees proper expandos");
124 gWinA3.wrappedJSObject.checkExpando('A1_expando',
11, gWinA2.document,
"Content sees proper expandos");
125 gWinA1.wrappedJSObject.checkExpando('A3_expando',
33, gWinA2.document,
"Content sees proper expandos");
126 gWinA3.wrappedJSObject.checkExpando('A3_expando',
33, gWinA2.document,
"Content sees proper expandos");
127 gWinA1.wrappedJSObject.checkExpando('Chrome_expando', null, gWinA2.document,
"Content doesn't see chrome expandos");
128 gWinA3.wrappedJSObject.checkExpando('Chrome_expando', null, gWinA2.document,
"Content doesn't see chrome expandos");
130 // We very explicitly do not support expando sharing via document.domain.
131 // A comment in the implementation explains why.
132 gWinA1.document.domain = 'test1.example.org';
133 gWinA2.document.domain = 'test1.example.org';
134 gWinA3.document.domain = 'test1.example.org';
135 gWinC.document.domain = 'test1.example.org';
136 gWinC.wrappedJSObject.checkExpando('A1_expando', null, gWinA2.document,
"document.domain should have no effect here");
137 gWinC.wrappedJSObject.checkExpando('A3_expando', null, gWinA2.document,
"document.domain should have no effect here");
142 <iframe id=
"frameA1" onload=
"frameLoaded();" type=
"content" src=
"https://test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
143 <iframe id=
"frameA2" onload=
"frameLoaded();" type=
"content" src=
"https://test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
144 <iframe id=
"frameA3" onload=
"frameLoaded();" type=
"content" src=
"https://test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
145 <iframe id=
"frameB" onload=
"frameLoaded();" type=
"content" src=
"https://test2.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />
146 <iframe id=
"frameC" onload=
"frameLoaded();" type=
"content" src=
"https://sub1.test1.example.org/tests/js/xpconnect/tests/mochitest/file_expandosharing.html" />