|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 let tab = gBrowser.selectedTab = gBrowser.addTab(); |
|
8 registerCleanupFunction(function () { |
|
9 gBrowser.removeTab(tab); |
|
10 }); |
|
11 |
|
12 let browser = gBrowser.getBrowserForTab(tab); |
|
13 |
|
14 function loadURL(url, flags, func) { |
|
15 browser.addEventListener("load", function loadListener(e) { |
|
16 if (browser.currentURI.spec != url) |
|
17 return; |
|
18 browser.removeEventListener(e.type, loadListener, true); |
|
19 func(); |
|
20 }, true); |
|
21 browser.loadURIWithFlags(url, flags, null, null, null); |
|
22 } |
|
23 |
|
24 // Load a normal http URL |
|
25 function testURL(url, func) { |
|
26 loadURL("http://example.com/", 0, function () { |
|
27 let pagePrincipal = browser.contentPrincipal; |
|
28 ok(pagePrincipal, "got principal for http:// page"); |
|
29 |
|
30 // Now load the URL normally |
|
31 loadURL(url, 0, function () { |
|
32 ok(browser.contentPrincipal.equals(pagePrincipal), url + " should inherit principal"); |
|
33 |
|
34 // Now load the URL and disallow inheriting the principal |
|
35 let webNav = Components.interfaces.nsIWebNavigation; |
|
36 loadURL(url, webNav.LOAD_FLAGS_DISALLOW_INHERIT_OWNER, function () { |
|
37 let newPrincipal = browser.contentPrincipal; |
|
38 ok(newPrincipal, "got inner principal"); |
|
39 ok(!newPrincipal.equals(pagePrincipal), |
|
40 url + " should not inherit principal when loaded with DISALLOW_INHERIT_OWNER"); |
|
41 |
|
42 func(); |
|
43 }); |
|
44 }); |
|
45 }); |
|
46 } |
|
47 |
|
48 let urls = [ |
|
49 "data:text/html,<body>hi", |
|
50 "javascript:1;" |
|
51 ]; |
|
52 |
|
53 function nextTest() { |
|
54 let url = urls.shift(); |
|
55 if (url) |
|
56 testURL(url, nextTest); |
|
57 else |
|
58 finish(); |
|
59 } |
|
60 |
|
61 nextTest(); |
|
62 } |
|
63 |