|
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://mochi.test:8888/browser/browser/devtools/framework/" + |
|
7 "test/browser_toolbox_options_disable_cache.sjs"; |
|
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", testCacheEnabled); |
|
30 toolbox.selectTool("options"); |
|
31 } |
|
32 |
|
33 function testCacheEnabled() { |
|
34 let prevTimestamp = getGUID(); |
|
35 |
|
36 gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
|
37 gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
|
38 doc = content.document; |
|
39 is(prevTimestamp, getGUID(), "GUID has not changed (page is cached)"); |
|
40 |
|
41 testCacheEnabled2(); |
|
42 }, true); |
|
43 |
|
44 doc.location.reload(false); |
|
45 } |
|
46 |
|
47 function testCacheEnabled2() { |
|
48 let prevTimestamp = getGUID(); |
|
49 |
|
50 gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
|
51 gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
|
52 doc = content.document; |
|
53 is(prevTimestamp, getGUID(), |
|
54 "GUID has not changed after page refresh (page is cached)"); |
|
55 |
|
56 testCacheDisabled(); |
|
57 }, true); |
|
58 |
|
59 doc.location.reload(false); |
|
60 } |
|
61 |
|
62 function testCacheDisabled() { |
|
63 let prevTimestamp = getGUID(); |
|
64 |
|
65 let panel = toolbox.getCurrentPanel(); |
|
66 let cbx = panel.panelDoc.getElementById("devtools-disable-cache"); |
|
67 let browser = gBrowser.selectedBrowser; |
|
68 |
|
69 browser.addEventListener("load", function onLoad(evt) { |
|
70 browser.removeEventListener(evt.type, onLoad, true); |
|
71 doc = content.document; |
|
72 isnot(prevTimestamp, getGUID(), "GUID has changed (page is not cached)"); |
|
73 testCacheDisabled2(); |
|
74 }, true); |
|
75 |
|
76 info("disabling cache"); |
|
77 |
|
78 cbx.scrollIntoView(); |
|
79 |
|
80 // After uising scrollIntoView() we need to use executeSoon() to wait for the |
|
81 // browser to scroll. |
|
82 executeSoon(function() { |
|
83 EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin); |
|
84 }); |
|
85 } |
|
86 |
|
87 function testCacheDisabled2() { |
|
88 let prevTimestamp = getGUID(); |
|
89 |
|
90 let browser = gBrowser.selectedBrowser; |
|
91 |
|
92 browser.addEventListener("load", function onLoad(evt) { |
|
93 browser.removeEventListener(evt.type, onLoad, true); |
|
94 doc = content.document; |
|
95 isnot(prevTimestamp, getGUID(), |
|
96 "GUID has changed after page refresh (page is not cached)"); |
|
97 finishUp(); |
|
98 }, true); |
|
99 |
|
100 doc.location.reload(false); |
|
101 } |
|
102 |
|
103 function getGUID() { |
|
104 return doc.querySelector("h1").textContent; |
|
105 } |
|
106 |
|
107 function finishUp() { |
|
108 toolbox.destroy().then(() => { |
|
109 gBrowser.removeCurrentTab(); |
|
110 toolbox = doc = null; |
|
111 finish(); |
|
112 }).then(null, console.error); |
|
113 } |