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.

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

mercurial