2013-04-20 01:05:20 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2013-10-25 03:02:25 -07:00
|
|
|
"use strict";
|
2013-04-20 01:05:20 -07:00
|
|
|
|
|
|
|
/**
|
2013-10-25 03:02:25 -07:00
|
|
|
* These tests ensures that disabling features by flipping nsIDocShell.allow*
|
2013-04-20 01:05:20 -07:00
|
|
|
* properties are (re)stored as disabled. Disallowed features must be
|
|
|
|
* re-enabled when the tab is re-used by another tab restoration.
|
|
|
|
*/
|
2013-10-25 03:02:25 -07:00
|
|
|
add_task(function docshell_capabilities() {
|
|
|
|
let tab = yield createTab();
|
2013-04-20 01:05:20 -07:00
|
|
|
let browser = tab.linkedBrowser;
|
|
|
|
let docShell = browser.docShell;
|
|
|
|
|
|
|
|
// Get the list of capabilities for docShells.
|
|
|
|
let flags = Object.keys(docShell).filter(k => k.startsWith("allow"));
|
|
|
|
|
|
|
|
// Check that everything is allowed by default for new tabs.
|
|
|
|
let state = JSON.parse(ss.getTabState(tab));
|
|
|
|
ok(!("disallow" in state), "everything allowed by default");
|
|
|
|
ok(flags.every(f => docShell[f]), "all flags set to true");
|
|
|
|
|
|
|
|
// Flip a couple of allow* flags.
|
|
|
|
docShell.allowImages = false;
|
|
|
|
docShell.allowMetaRedirects = false;
|
|
|
|
|
2013-07-26 09:15:25 -07:00
|
|
|
// Now reload the document to ensure that these capabilities
|
2013-10-25 03:02:25 -07:00
|
|
|
// are taken into account.
|
2013-07-26 09:15:25 -07:00
|
|
|
browser.reload();
|
2013-10-25 03:02:25 -07:00
|
|
|
yield promiseBrowserLoaded(browser);
|
|
|
|
|
|
|
|
// Flush to make sure chrome received all data.
|
2014-09-23 15:48:53 -07:00
|
|
|
TabState.flush(browser);
|
2013-07-26 09:15:25 -07:00
|
|
|
|
2013-04-20 01:05:20 -07:00
|
|
|
// Check that we correctly save disallowed features.
|
|
|
|
let disallowedState = JSON.parse(ss.getTabState(tab));
|
|
|
|
let disallow = new Set(disallowedState.disallow.split(","));
|
|
|
|
ok(disallow.has("Images"), "images not allowed");
|
|
|
|
ok(disallow.has("MetaRedirects"), "meta redirects not allowed");
|
|
|
|
is(disallow.size, 2, "two capabilities disallowed");
|
|
|
|
|
|
|
|
// Reuse the tab to restore a new, clean state into it.
|
2015-01-29 00:41:57 -08:00
|
|
|
yield promiseTabState(tab, {entries: [{url: "about:robots"}]});
|
2013-10-25 03:02:25 -07:00
|
|
|
|
|
|
|
// Flush to make sure chrome received all data.
|
2014-09-23 15:48:53 -07:00
|
|
|
TabState.flush(browser);
|
2013-04-20 01:05:20 -07:00
|
|
|
|
|
|
|
// After restoring disallowed features must be available again.
|
|
|
|
state = JSON.parse(ss.getTabState(tab));
|
|
|
|
ok(!("disallow" in state), "everything allowed again");
|
|
|
|
ok(flags.every(f => docShell[f]), "all flags set to true");
|
|
|
|
|
|
|
|
// Restore the state with disallowed features.
|
2015-01-29 00:41:57 -08:00
|
|
|
yield promiseTabState(tab, disallowedState);
|
2013-04-20 01:05:20 -07:00
|
|
|
|
|
|
|
// Check that docShell flags are set.
|
|
|
|
ok(!docShell.allowImages, "images not allowed");
|
2013-07-26 09:15:25 -07:00
|
|
|
ok(!docShell.allowMetaRedirects, "meta redirects not allowed");
|
2013-04-20 01:05:20 -07:00
|
|
|
|
|
|
|
// Check that we correctly restored features as disabled.
|
|
|
|
state = JSON.parse(ss.getTabState(tab));
|
|
|
|
disallow = new Set(state.disallow.split(","));
|
|
|
|
ok(disallow.has("Images"), "images not allowed anymore");
|
|
|
|
ok(disallow.has("MetaRedirects"), "meta redirects not allowed anymore");
|
|
|
|
is(disallow.size, 2, "two capabilities disallowed");
|
|
|
|
|
|
|
|
// Clean up after ourselves.
|
|
|
|
gBrowser.removeTab(tab);
|
2013-10-25 03:02:25 -07:00
|
|
|
});
|
2013-04-20 01:05:20 -07:00
|
|
|
|
2013-10-25 03:02:25 -07:00
|
|
|
function createTab() {
|
|
|
|
let tab = gBrowser.addTab("about:mozilla");
|
|
|
|
let browser = tab.linkedBrowser;
|
|
|
|
return promiseBrowserLoaded(browser).then(() => tab);
|
2013-04-20 01:05:20 -07:00
|
|
|
}
|