browser/components/sessionstore/test/browser_capabilities.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 "use strict";
     6 /**
     7  * These tests ensures that disabling features by flipping nsIDocShell.allow*
     8  * properties are (re)stored as disabled. Disallowed features must be
     9  * re-enabled when the tab is re-used by another tab restoration.
    10  */
    11 add_task(function docshell_capabilities() {
    12   let tab = yield createTab();
    13   let browser = tab.linkedBrowser;
    14   let docShell = browser.docShell;
    16   // Get the list of capabilities for docShells.
    17   let flags = Object.keys(docShell).filter(k => k.startsWith("allow"));
    19   // Check that everything is allowed by default for new tabs.
    20   let state = JSON.parse(ss.getTabState(tab));
    21   ok(!("disallow" in state), "everything allowed by default");
    22   ok(flags.every(f => docShell[f]), "all flags set to true");
    24   // Flip a couple of allow* flags.
    25   docShell.allowImages = false;
    26   docShell.allowMetaRedirects = false;
    28   // Now reload the document to ensure that these capabilities
    29   // are taken into account.
    30   browser.reload();
    31   yield promiseBrowserLoaded(browser);
    33   // Flush to make sure chrome received all data.
    34   SyncHandlers.get(browser).flush();
    36   // Check that we correctly save disallowed features.
    37   let disallowedState = JSON.parse(ss.getTabState(tab));
    38   let disallow = new Set(disallowedState.disallow.split(","));
    39   ok(disallow.has("Images"), "images not allowed");
    40   ok(disallow.has("MetaRedirects"), "meta redirects not allowed");
    41   is(disallow.size, 2, "two capabilities disallowed");
    43   // Reuse the tab to restore a new, clean state into it.
    44   ss.setTabState(tab, JSON.stringify({ entries: [{url: "about:robots"}] }));
    45   yield promiseTabRestored(tab);
    47   // Flush to make sure chrome received all data.
    48   SyncHandlers.get(browser).flush();
    50   // After restoring disallowed features must be available again.
    51   state = JSON.parse(ss.getTabState(tab));
    52   ok(!("disallow" in state), "everything allowed again");
    53   ok(flags.every(f => docShell[f]), "all flags set to true");
    55   // Restore the state with disallowed features.
    56   ss.setTabState(tab, JSON.stringify(disallowedState));
    57   yield promiseTabRestored(tab);
    59   // Check that docShell flags are set.
    60   ok(!docShell.allowImages, "images not allowed");
    61   ok(!docShell.allowMetaRedirects, "meta redirects not allowed");
    63   // Check that we correctly restored features as disabled.
    64   state = JSON.parse(ss.getTabState(tab));
    65   disallow = new Set(state.disallow.split(","));
    66   ok(disallow.has("Images"), "images not allowed anymore");
    67   ok(disallow.has("MetaRedirects"), "meta redirects not allowed anymore");
    68   is(disallow.size, 2, "two capabilities disallowed");
    70   // Clean up after ourselves.
    71   gBrowser.removeTab(tab);
    72 });
    74 function createTab() {
    75   let tab = gBrowser.addTab("about:mozilla");
    76   let browser = tab.linkedBrowser;
    77   return promiseBrowserLoaded(browser).then(() => tab);
    78 }

mercurial