docshell/test/browser/browser_loadDisallowInherit.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   waitForExplicitFinish();
     7   let tab = gBrowser.selectedTab = gBrowser.addTab();
     8   registerCleanupFunction(function () {
     9     gBrowser.removeTab(tab);
    10   });
    12   let browser = gBrowser.getBrowserForTab(tab);
    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   }
    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");
    30       // Now load the URL normally
    31       loadURL(url, 0, function () {
    32         ok(browser.contentPrincipal.equals(pagePrincipal), url + " should inherit principal");
    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");
    42           func();
    43         });
    44       });
    45     });
    46   }
    48   let urls = [
    49     "data:text/html,<body>hi",
    50     "javascript:1;"
    51   ];
    53   function nextTest() {
    54     let url = urls.shift();
    55     if (url)
    56       testURL(url, nextTest);
    57     else
    58       finish();
    59   }
    61   nextTest();
    62 }

mercurial