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.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Tests that disabling JavaScript for a tab works as it should.
6 const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" +
7 "test/browser_toolbox_options_disable_cache.sjs";
9 let doc;
10 let toolbox;
12 function test() {
13 waitForExplicitFinish();
15 gBrowser.selectedTab = gBrowser.addTab();
16 let target = TargetFactory.forTab(gBrowser.selectedTab);
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);
24 content.location = TEST_URI;
25 }
27 function testSelectTool(aToolbox) {
28 toolbox = aToolbox;
29 toolbox.once("options-selected", testCacheEnabled);
30 toolbox.selectTool("options");
31 }
33 function testCacheEnabled() {
34 let prevTimestamp = getGUID();
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)");
41 testCacheEnabled2();
42 }, true);
44 doc.location.reload(false);
45 }
47 function testCacheEnabled2() {
48 let prevTimestamp = getGUID();
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)");
56 testCacheDisabled();
57 }, true);
59 doc.location.reload(false);
60 }
62 function testCacheDisabled() {
63 let prevTimestamp = getGUID();
65 let panel = toolbox.getCurrentPanel();
66 let cbx = panel.panelDoc.getElementById("devtools-disable-cache");
67 let browser = gBrowser.selectedBrowser;
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);
76 info("disabling cache");
78 cbx.scrollIntoView();
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 }
87 function testCacheDisabled2() {
88 let prevTimestamp = getGUID();
90 let browser = gBrowser.selectedBrowser;
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);
100 doc.location.reload(false);
101 }
103 function getGUID() {
104 return doc.querySelector("h1").textContent;
105 }
107 function finishUp() {
108 toolbox.destroy().then(() => {
109 gBrowser.removeCurrentTab();
110 toolbox = doc = null;
111 finish();
112 }).then(null, console.error);
113 }