Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Tests that disabling JavaScript for a tab works as it should. |
michael@0 | 5 | |
michael@0 | 6 | const TEST_URI = "http://example.com/browser/browser/devtools/framework/" + |
michael@0 | 7 | "test/browser_toolbox_options_disable_js.html"; |
michael@0 | 8 | |
michael@0 | 9 | let doc; |
michael@0 | 10 | let toolbox; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 16 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 17 | |
michael@0 | 18 | gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
michael@0 | 19 | gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
michael@0 | 20 | doc = content.document; |
michael@0 | 21 | gDevTools.showToolbox(target).then(testSelectTool); |
michael@0 | 22 | }, true); |
michael@0 | 23 | |
michael@0 | 24 | content.location = TEST_URI; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function testSelectTool(aToolbox) { |
michael@0 | 28 | toolbox = aToolbox; |
michael@0 | 29 | toolbox.once("options-selected", testJSEnabled); |
michael@0 | 30 | toolbox.selectTool("options"); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function testJSEnabled(event, tool, secondPass) { |
michael@0 | 34 | ok(true, "Toolbox selected via selectTool method"); |
michael@0 | 35 | info("Testing that JS is enabled"); |
michael@0 | 36 | |
michael@0 | 37 | let logJSEnabled = doc.getElementById("logJSEnabled"); |
michael@0 | 38 | let output = doc.getElementById("output"); |
michael@0 | 39 | |
michael@0 | 40 | // We use executeSoon here because switching docSehll.allowJavascript to true |
michael@0 | 41 | // takes a while to become live. |
michael@0 | 42 | executeSoon(function() { |
michael@0 | 43 | EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, doc.defaultView); |
michael@0 | 44 | is(output.textContent, "JavaScript Enabled", 'Output is "JavaScript Enabled"'); |
michael@0 | 45 | testJSEnabledIframe(secondPass); |
michael@0 | 46 | }); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function testJSEnabledIframe(secondPass) { |
michael@0 | 50 | info("Testing that JS is enabled in the iframe"); |
michael@0 | 51 | |
michael@0 | 52 | let iframe = doc.querySelector("iframe"); |
michael@0 | 53 | let iframeDoc = iframe.contentDocument; |
michael@0 | 54 | let logJSEnabled = iframeDoc.getElementById("logJSEnabled"); |
michael@0 | 55 | let output = iframeDoc.getElementById("output"); |
michael@0 | 56 | |
michael@0 | 57 | EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, iframe.contentWindow); |
michael@0 | 58 | is(output.textContent, "JavaScript Enabled", |
michael@0 | 59 | 'Output is "JavaScript Enabled" in iframe'); |
michael@0 | 60 | if (secondPass) { |
michael@0 | 61 | finishUp(); |
michael@0 | 62 | } else { |
michael@0 | 63 | toggleJS().then(testJSDisabled); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function toggleJS() { |
michael@0 | 68 | let deferred = promise.defer(); |
michael@0 | 69 | let panel = toolbox.getCurrentPanel(); |
michael@0 | 70 | let cbx = panel.panelDoc.getElementById("devtools-disable-javascript"); |
michael@0 | 71 | |
michael@0 | 72 | cbx.scrollIntoView(); |
michael@0 | 73 | |
michael@0 | 74 | if (cbx.checked) { |
michael@0 | 75 | info("Clearing checkbox to re-enable JS"); |
michael@0 | 76 | } else { |
michael@0 | 77 | info("Checking checkbox to disable JS"); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | // After uising scrollIntoView() we need to use executeSoon() to wait for the |
michael@0 | 81 | // browser to scroll. |
michael@0 | 82 | executeSoon(function() { |
michael@0 | 83 | gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
michael@0 | 84 | gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
michael@0 | 85 | doc = content.document; |
michael@0 | 86 | |
michael@0 | 87 | deferred.resolve(); |
michael@0 | 88 | }, true); |
michael@0 | 89 | |
michael@0 | 90 | EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin); |
michael@0 | 91 | }); |
michael@0 | 92 | |
michael@0 | 93 | return deferred.promise; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function testJSDisabled() { |
michael@0 | 97 | info("Testing that JS is disabled"); |
michael@0 | 98 | |
michael@0 | 99 | let logJSDisabled = doc.getElementById("logJSDisabled"); |
michael@0 | 100 | let output = doc.getElementById("output"); |
michael@0 | 101 | |
michael@0 | 102 | EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, doc.defaultView); |
michael@0 | 103 | ok(output.textContent !== "JavaScript Disabled", |
michael@0 | 104 | 'output is not "JavaScript Disabled"'); |
michael@0 | 105 | |
michael@0 | 106 | testJSDisabledIframe(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function testJSDisabledIframe() { |
michael@0 | 110 | info("Testing that JS is disabled in the iframe"); |
michael@0 | 111 | |
michael@0 | 112 | let iframe = doc.querySelector("iframe"); |
michael@0 | 113 | let iframeDoc = iframe.contentDocument; |
michael@0 | 114 | let logJSDisabled = iframeDoc.getElementById("logJSDisabled"); |
michael@0 | 115 | let output = iframeDoc.getElementById("output"); |
michael@0 | 116 | |
michael@0 | 117 | EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, iframe.contentWindow); |
michael@0 | 118 | ok(output.textContent !== "JavaScript Disabled", |
michael@0 | 119 | 'output is not "JavaScript Disabled" in iframe'); |
michael@0 | 120 | toggleJS().then(function() { |
michael@0 | 121 | testJSEnabled(null, null, true); |
michael@0 | 122 | }); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function finishUp() { |
michael@0 | 126 | toolbox.destroy().then(function() { |
michael@0 | 127 | gBrowser.removeCurrentTab(); |
michael@0 | 128 | toolbox = doc = null; |
michael@0 | 129 | finish(); |
michael@0 | 130 | }); |
michael@0 | 131 | } |