no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / caps / tests / mochitest / test_disallowInheritPrincipal.html
blob308ee61320a595b032ad9f7b388a13d3ff045a23
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=732413
5 -->
6 <head>
7 <title>Test for Bug 732413</title>
8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 </head>
11 <body>
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=732413">Mozilla Bug 732413</a>
13 <p id="display"></p>
14 <div id="content" style="display: none">
16 </div>
17 <pre id="test">
18 <script type="application/javascript">
20 /** Test for Bug 732413
21 Passing DISALLOW_INHERIT_PRINCIPAL flag should be effective even if
22 aPrincipal is the system principal.
25 const nsIScriptSecurityManager = SpecialPowers.Ci.nsIScriptSecurityManager;
26 var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
27 .getService(nsIScriptSecurityManager);
28 var sysPrincipal = secMan.getSystemPrincipal();
29 isnot(sysPrincipal, undefined, "Should have a principal");
30 isnot(sysPrincipal, null, "Should have a non-null principal");
31 is(sysPrincipal.isSystemPrincipal, true,
32 "Should have system principal here");
35 var inheritingURI = SpecialPowers.Services.io.newURI("javascript:1+1");
37 // First try a normal call to checkLoadURIWithPrincipal
38 try {
39 secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
40 nsIScriptSecurityManager.STANDARD);
41 ok(true, "checkLoadURI allowed the load");
42 } catch (e) {
43 ok(false, "checkLoadURI failed unexpectedly: " + e);
46 // Now call checkLoadURIWithPrincipal with DISALLOW_INHERIT_PRINCIPAL
47 try {
48 secMan.checkLoadURIWithPrincipal(sysPrincipal, inheritingURI,
49 nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
50 ok(false, "checkLoadURI allowed the load unexpectedly");
51 } catch (e) {
52 ok(true, "checkLoadURI prevented load of principal-inheriting URI");
55 </script>
56 </pre>
57 </body>
58 </html>