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