michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that disabling JavaScript for a tab works as it should. michael@0: michael@0: const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" + michael@0: "test/browser_toolbox_options_disable_cache.sjs"; michael@0: michael@0: let doc; michael@0: let toolbox; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { michael@0: gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); michael@0: doc = content.document; michael@0: gDevTools.showToolbox(target).then(testSelectTool); michael@0: }, true); michael@0: michael@0: content.location = TEST_URI; michael@0: } michael@0: michael@0: function testSelectTool(aToolbox) { michael@0: toolbox = aToolbox; michael@0: toolbox.once("options-selected", testCacheEnabled); michael@0: toolbox.selectTool("options"); michael@0: } michael@0: michael@0: function testCacheEnabled() { michael@0: let prevTimestamp = getGUID(); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { michael@0: gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); michael@0: doc = content.document; michael@0: is(prevTimestamp, getGUID(), "GUID has not changed (page is cached)"); michael@0: michael@0: testCacheEnabled2(); michael@0: }, true); michael@0: michael@0: doc.location.reload(false); michael@0: } michael@0: michael@0: function testCacheEnabled2() { michael@0: let prevTimestamp = getGUID(); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { michael@0: gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); michael@0: doc = content.document; michael@0: is(prevTimestamp, getGUID(), michael@0: "GUID has not changed after page refresh (page is cached)"); michael@0: michael@0: testCacheDisabled(); michael@0: }, true); michael@0: michael@0: doc.location.reload(false); michael@0: } michael@0: michael@0: function testCacheDisabled() { michael@0: let prevTimestamp = getGUID(); michael@0: michael@0: let panel = toolbox.getCurrentPanel(); michael@0: let cbx = panel.panelDoc.getElementById("devtools-disable-cache"); michael@0: let browser = gBrowser.selectedBrowser; michael@0: michael@0: browser.addEventListener("load", function onLoad(evt) { michael@0: browser.removeEventListener(evt.type, onLoad, true); michael@0: doc = content.document; michael@0: isnot(prevTimestamp, getGUID(), "GUID has changed (page is not cached)"); michael@0: testCacheDisabled2(); michael@0: }, true); michael@0: michael@0: info("disabling cache"); michael@0: michael@0: cbx.scrollIntoView(); michael@0: michael@0: // After uising scrollIntoView() we need to use executeSoon() to wait for the michael@0: // browser to scroll. michael@0: executeSoon(function() { michael@0: EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin); michael@0: }); michael@0: } michael@0: michael@0: function testCacheDisabled2() { michael@0: let prevTimestamp = getGUID(); michael@0: michael@0: let browser = gBrowser.selectedBrowser; michael@0: michael@0: browser.addEventListener("load", function onLoad(evt) { michael@0: browser.removeEventListener(evt.type, onLoad, true); michael@0: doc = content.document; michael@0: isnot(prevTimestamp, getGUID(), michael@0: "GUID has changed after page refresh (page is not cached)"); michael@0: finishUp(); michael@0: }, true); michael@0: michael@0: doc.location.reload(false); michael@0: } michael@0: michael@0: function getGUID() { michael@0: return doc.querySelector("h1").textContent; michael@0: } michael@0: michael@0: function finishUp() { michael@0: toolbox.destroy().then(() => { michael@0: gBrowser.removeCurrentTab(); michael@0: toolbox = doc = null; michael@0: finish(); michael@0: }).then(null, console.error); michael@0: }