1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/browser/browser_loadDisallowInherit.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + waitForExplicitFinish(); 1.9 + 1.10 + let tab = gBrowser.selectedTab = gBrowser.addTab(); 1.11 + registerCleanupFunction(function () { 1.12 + gBrowser.removeTab(tab); 1.13 + }); 1.14 + 1.15 + let browser = gBrowser.getBrowserForTab(tab); 1.16 + 1.17 + function loadURL(url, flags, func) { 1.18 + browser.addEventListener("load", function loadListener(e) { 1.19 + if (browser.currentURI.spec != url) 1.20 + return; 1.21 + browser.removeEventListener(e.type, loadListener, true); 1.22 + func(); 1.23 + }, true); 1.24 + browser.loadURIWithFlags(url, flags, null, null, null); 1.25 + } 1.26 + 1.27 + // Load a normal http URL 1.28 + function testURL(url, func) { 1.29 + loadURL("http://example.com/", 0, function () { 1.30 + let pagePrincipal = browser.contentPrincipal; 1.31 + ok(pagePrincipal, "got principal for http:// page"); 1.32 + 1.33 + // Now load the URL normally 1.34 + loadURL(url, 0, function () { 1.35 + ok(browser.contentPrincipal.equals(pagePrincipal), url + " should inherit principal"); 1.36 + 1.37 + // Now load the URL and disallow inheriting the principal 1.38 + let webNav = Components.interfaces.nsIWebNavigation; 1.39 + loadURL(url, webNav.LOAD_FLAGS_DISALLOW_INHERIT_OWNER, function () { 1.40 + let newPrincipal = browser.contentPrincipal; 1.41 + ok(newPrincipal, "got inner principal"); 1.42 + ok(!newPrincipal.equals(pagePrincipal), 1.43 + url + " should not inherit principal when loaded with DISALLOW_INHERIT_OWNER"); 1.44 + 1.45 + func(); 1.46 + }); 1.47 + }); 1.48 + }); 1.49 + } 1.50 + 1.51 + let urls = [ 1.52 + "data:text/html,<body>hi", 1.53 + "javascript:1;" 1.54 + ]; 1.55 + 1.56 + function nextTest() { 1.57 + let url = urls.shift(); 1.58 + if (url) 1.59 + testURL(url, nextTest); 1.60 + else 1.61 + finish(); 1.62 + } 1.63 + 1.64 + nextTest(); 1.65 +} 1.66 +