1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_options_disable_js.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests that disabling JavaScript for a tab works as it should. 1.8 + 1.9 +const TEST_URI = "http://example.com/browser/browser/devtools/framework/" + 1.10 + "test/browser_toolbox_options_disable_js.html"; 1.11 + 1.12 +let doc; 1.13 +let toolbox; 1.14 + 1.15 +function test() { 1.16 + waitForExplicitFinish(); 1.17 + 1.18 + gBrowser.selectedTab = gBrowser.addTab(); 1.19 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.20 + 1.21 + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { 1.22 + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); 1.23 + doc = content.document; 1.24 + gDevTools.showToolbox(target).then(testSelectTool); 1.25 + }, true); 1.26 + 1.27 + content.location = TEST_URI; 1.28 +} 1.29 + 1.30 +function testSelectTool(aToolbox) { 1.31 + toolbox = aToolbox; 1.32 + toolbox.once("options-selected", testJSEnabled); 1.33 + toolbox.selectTool("options"); 1.34 +} 1.35 + 1.36 +function testJSEnabled(event, tool, secondPass) { 1.37 + ok(true, "Toolbox selected via selectTool method"); 1.38 + info("Testing that JS is enabled"); 1.39 + 1.40 + let logJSEnabled = doc.getElementById("logJSEnabled"); 1.41 + let output = doc.getElementById("output"); 1.42 + 1.43 + // We use executeSoon here because switching docSehll.allowJavascript to true 1.44 + // takes a while to become live. 1.45 + executeSoon(function() { 1.46 + EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, doc.defaultView); 1.47 + is(output.textContent, "JavaScript Enabled", 'Output is "JavaScript Enabled"'); 1.48 + testJSEnabledIframe(secondPass); 1.49 + }); 1.50 +} 1.51 + 1.52 +function testJSEnabledIframe(secondPass) { 1.53 + info("Testing that JS is enabled in the iframe"); 1.54 + 1.55 + let iframe = doc.querySelector("iframe"); 1.56 + let iframeDoc = iframe.contentDocument; 1.57 + let logJSEnabled = iframeDoc.getElementById("logJSEnabled"); 1.58 + let output = iframeDoc.getElementById("output"); 1.59 + 1.60 + EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, iframe.contentWindow); 1.61 + is(output.textContent, "JavaScript Enabled", 1.62 + 'Output is "JavaScript Enabled" in iframe'); 1.63 + if (secondPass) { 1.64 + finishUp(); 1.65 + } else { 1.66 + toggleJS().then(testJSDisabled); 1.67 + } 1.68 +} 1.69 + 1.70 +function toggleJS() { 1.71 + let deferred = promise.defer(); 1.72 + let panel = toolbox.getCurrentPanel(); 1.73 + let cbx = panel.panelDoc.getElementById("devtools-disable-javascript"); 1.74 + 1.75 + cbx.scrollIntoView(); 1.76 + 1.77 + if (cbx.checked) { 1.78 + info("Clearing checkbox to re-enable JS"); 1.79 + } else { 1.80 + info("Checking checkbox to disable JS"); 1.81 + } 1.82 + 1.83 + // After uising scrollIntoView() we need to use executeSoon() to wait for the 1.84 + // browser to scroll. 1.85 + executeSoon(function() { 1.86 + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { 1.87 + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); 1.88 + doc = content.document; 1.89 + 1.90 + deferred.resolve(); 1.91 + }, true); 1.92 + 1.93 + EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin); 1.94 + }); 1.95 + 1.96 + return deferred.promise; 1.97 +} 1.98 + 1.99 +function testJSDisabled() { 1.100 + info("Testing that JS is disabled"); 1.101 + 1.102 + let logJSDisabled = doc.getElementById("logJSDisabled"); 1.103 + let output = doc.getElementById("output"); 1.104 + 1.105 + EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, doc.defaultView); 1.106 + ok(output.textContent !== "JavaScript Disabled", 1.107 + 'output is not "JavaScript Disabled"'); 1.108 + 1.109 + testJSDisabledIframe(); 1.110 +} 1.111 + 1.112 +function testJSDisabledIframe() { 1.113 + info("Testing that JS is disabled in the iframe"); 1.114 + 1.115 + let iframe = doc.querySelector("iframe"); 1.116 + let iframeDoc = iframe.contentDocument; 1.117 + let logJSDisabled = iframeDoc.getElementById("logJSDisabled"); 1.118 + let output = iframeDoc.getElementById("output"); 1.119 + 1.120 + EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, iframe.contentWindow); 1.121 + ok(output.textContent !== "JavaScript Disabled", 1.122 + 'output is not "JavaScript Disabled" in iframe'); 1.123 + toggleJS().then(function() { 1.124 + testJSEnabled(null, null, true); 1.125 + }); 1.126 +} 1.127 + 1.128 +function finishUp() { 1.129 + toolbox.destroy().then(function() { 1.130 + gBrowser.removeCurrentTab(); 1.131 + toolbox = doc = null; 1.132 + finish(); 1.133 + }); 1.134 +}