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