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://example.com/browser/browser/devtools/framework/" + michael@0: "test/browser_toolbox_options_disable_js.html"; 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", testJSEnabled); michael@0: toolbox.selectTool("options"); michael@0: } michael@0: michael@0: function testJSEnabled(event, tool, secondPass) { michael@0: ok(true, "Toolbox selected via selectTool method"); michael@0: info("Testing that JS is enabled"); michael@0: michael@0: let logJSEnabled = doc.getElementById("logJSEnabled"); michael@0: let output = doc.getElementById("output"); michael@0: michael@0: // We use executeSoon here because switching docSehll.allowJavascript to true michael@0: // takes a while to become live. michael@0: executeSoon(function() { michael@0: EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, doc.defaultView); michael@0: is(output.textContent, "JavaScript Enabled", 'Output is "JavaScript Enabled"'); michael@0: testJSEnabledIframe(secondPass); michael@0: }); michael@0: } michael@0: michael@0: function testJSEnabledIframe(secondPass) { michael@0: info("Testing that JS is enabled in the iframe"); michael@0: michael@0: let iframe = doc.querySelector("iframe"); michael@0: let iframeDoc = iframe.contentDocument; michael@0: let logJSEnabled = iframeDoc.getElementById("logJSEnabled"); michael@0: let output = iframeDoc.getElementById("output"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, iframe.contentWindow); michael@0: is(output.textContent, "JavaScript Enabled", michael@0: 'Output is "JavaScript Enabled" in iframe'); michael@0: if (secondPass) { michael@0: finishUp(); michael@0: } else { michael@0: toggleJS().then(testJSDisabled); michael@0: } michael@0: } michael@0: michael@0: function toggleJS() { michael@0: let deferred = promise.defer(); michael@0: let panel = toolbox.getCurrentPanel(); michael@0: let cbx = panel.panelDoc.getElementById("devtools-disable-javascript"); michael@0: michael@0: cbx.scrollIntoView(); michael@0: michael@0: if (cbx.checked) { michael@0: info("Clearing checkbox to re-enable JS"); michael@0: } else { michael@0: info("Checking checkbox to disable JS"); michael@0: } 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: gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { michael@0: gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); michael@0: doc = content.document; michael@0: michael@0: deferred.resolve(); michael@0: }, true); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function testJSDisabled() { michael@0: info("Testing that JS is disabled"); michael@0: michael@0: let logJSDisabled = doc.getElementById("logJSDisabled"); michael@0: let output = doc.getElementById("output"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, doc.defaultView); michael@0: ok(output.textContent !== "JavaScript Disabled", michael@0: 'output is not "JavaScript Disabled"'); michael@0: michael@0: testJSDisabledIframe(); michael@0: } michael@0: michael@0: function testJSDisabledIframe() { michael@0: info("Testing that JS is disabled in the iframe"); michael@0: michael@0: let iframe = doc.querySelector("iframe"); michael@0: let iframeDoc = iframe.contentDocument; michael@0: let logJSDisabled = iframeDoc.getElementById("logJSDisabled"); michael@0: let output = iframeDoc.getElementById("output"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, iframe.contentWindow); michael@0: ok(output.textContent !== "JavaScript Disabled", michael@0: 'output is not "JavaScript Disabled" in iframe'); michael@0: toggleJS().then(function() { michael@0: testJSEnabled(null, null, true); michael@0: }); michael@0: } michael@0: michael@0: function finishUp() { michael@0: toolbox.destroy().then(function() { michael@0: gBrowser.removeCurrentTab(); michael@0: toolbox = doc = null; michael@0: finish(); michael@0: }); michael@0: }