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