browser/devtools/framework/test/browser_toolbox_options_disable_js.js

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

mercurial