Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
4 type="text/css"?>
5 <!--
6 https://bugzilla.mozilla.org/show_bug.cgi?id=877673
7 -->
8 <window title="Mozilla Bug 877673"
9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10 <script type="application/javascript"
11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
13 <!-- test results are displayed in the html:body -->
14 <body xmlns="http://www.w3.org/1999/xhtml">
15 </body>
17 <!-- test code goes here -->
18 <script type="application/javascript"><![CDATA[
19 SimpleTest.waitForExplicitFinish();
20 const Cu = Components.utils;
21 var sb = new Cu.Sandbox("http://example.org", {wantExportHelpers: true});
22 sb.ok = ok;
24 function executeIn(frame, script, exceptionCb) {
25 sb.frame = frame;
26 sb.exceptionCb = exceptionCb;
27 if (exceptionCb) {
28 return Cu.evalInSandbox("try {evalInWindow('" + script + "',frame); ok(false, 'Exception should have been thrown.')} catch(e) {exceptionCb(e)}", sb);
29 }
31 return Cu.evalInSandbox("evalInWindow('" + script + "',frame)", sb);
32 }
34 function testSameOrigin(frame) {
35 frame.contentWindow.document.wrappedJSObject.str = "foobar";
36 is(executeIn(frame.contentWindow, "document.str"), "foobar",
37 "Same origin string property access.");
39 executeIn(frame.contentWindow, 'document.obj = {prop: "foobar"}');
40 is((executeIn(frame.contentWindow, "document.obj")).prop, "foobar",
41 "Same origin object property access (cloning).");
42 isnot(executeIn(frame.contentWindow, "document.obj"), frame.contentWindow.document.wrappedJSObject.obj,
43 "Ensure cloning for js objects.");
44 is(executeIn(frame.contentWindow, "document"), frame.contentWindow.document,
45 "Xrayables should just pass without cloning.");
46 is( executeIn(frame.contentWindow, "({a:{doc: document}})").a.doc, frame.contentWindow.document,
47 "Deep cloning works.");
49 executeIn(frame.contentWindow, "throw 42", function(e){is(e, 42,
50 "Exception was thrown from script.")});
52 executeIn(frame.contentDocument, "var a = 42;", function(e){ok(e.toString().indexOf("Second argument must be a window") > -1,
53 "Passing non-window to evalInWindow should throw.");});
54 // evalInWindow is also available from Cu:
55 is(Cu.evalInWindow("document.str", frame.contentWindow), "foobar");
56 testDone();
57 }
59 function testCrossOrigin(frame) {
60 executeIn(frame.contentWindow, "var a = 42;", function(e){ok(e.toString().indexOf("Permission denied") > -1,
61 "Executing script in a window from cross origin should throw.");});
62 testDone();
63 }
65 var testsRun = 0;
66 function testDone() {
67 if (++testsRun == 2)
68 SimpleTest.finish();
69 }
70 ]]></script>
71 <iframe src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"
72 onload="testSameOrigin(this)">
73 </iframe>
74 <iframe src="http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_empty.html"
75 onload="testCrossOrigin(this)">
76 </iframe>
77 </window>