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