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