js/xpconnect/tests/chrome/test_bug792280.xul

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:72f01c001cad
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=792280
6 -->
7 <window title="Mozilla Bug 792280"
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=792280"
14 target="_blank">Mozilla Bug 792280</a>
15 </body>
16
17 <!-- test code goes here -->
18 <script type="application/javascript">
19 <![CDATA[
20 /** Test for Bug 792280 **/
21 const Cu = Components.utils;
22
23 function checkSb(sb, expect) {
24 var target = new Cu.Sandbox('http://www.example.com');
25 Cu.evalInSandbox('function fun() { return arguments.callee.caller; };', target);
26 sb.fun = target.fun;
27 let allowed = false;
28 try {
29 allowed = Cu.evalInSandbox('function doTest() { return fun() == doTest; }; doTest()', sb);
30 isnot(expect, "throw", "Should have thrown");
31 } catch (e) {
32 is(expect, "throw", "Should expect exception");
33 ok(/denied|insecure/.test(e), "Should be a security exception: " + e);
34 }
35 is(allowed, expect == "allow", "should censor appropriately");
36 }
37
38 // Note that COWs are callable, but XOWs are not.
39 checkSb(new Cu.Sandbox('http://www.example.com'), "allow");
40 checkSb(new Cu.Sandbox('http://www.example.org'), "throw");
41 checkSb(new Cu.Sandbox(window), "censor");
42
43 ]]>
44 </script>
45 </window>

mercurial