1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_options_disable_cache.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests that disabling JavaScript for a tab works as it should. 1.8 + 1.9 +const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" + 1.10 + "test/browser_toolbox_options_disable_cache.sjs"; 1.11 + 1.12 +let doc; 1.13 +let toolbox; 1.14 + 1.15 +function test() { 1.16 + waitForExplicitFinish(); 1.17 + 1.18 + gBrowser.selectedTab = gBrowser.addTab(); 1.19 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.20 + 1.21 + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { 1.22 + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); 1.23 + doc = content.document; 1.24 + gDevTools.showToolbox(target).then(testSelectTool); 1.25 + }, true); 1.26 + 1.27 + content.location = TEST_URI; 1.28 +} 1.29 + 1.30 +function testSelectTool(aToolbox) { 1.31 + toolbox = aToolbox; 1.32 + toolbox.once("options-selected", testCacheEnabled); 1.33 + toolbox.selectTool("options"); 1.34 +} 1.35 + 1.36 +function testCacheEnabled() { 1.37 + let prevTimestamp = getGUID(); 1.38 + 1.39 + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { 1.40 + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); 1.41 + doc = content.document; 1.42 + is(prevTimestamp, getGUID(), "GUID has not changed (page is cached)"); 1.43 + 1.44 + testCacheEnabled2(); 1.45 + }, true); 1.46 + 1.47 + doc.location.reload(false); 1.48 +} 1.49 + 1.50 +function testCacheEnabled2() { 1.51 + let prevTimestamp = getGUID(); 1.52 + 1.53 + gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { 1.54 + gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); 1.55 + doc = content.document; 1.56 + is(prevTimestamp, getGUID(), 1.57 + "GUID has not changed after page refresh (page is cached)"); 1.58 + 1.59 + testCacheDisabled(); 1.60 + }, true); 1.61 + 1.62 + doc.location.reload(false); 1.63 +} 1.64 + 1.65 +function testCacheDisabled() { 1.66 + let prevTimestamp = getGUID(); 1.67 + 1.68 + let panel = toolbox.getCurrentPanel(); 1.69 + let cbx = panel.panelDoc.getElementById("devtools-disable-cache"); 1.70 + let browser = gBrowser.selectedBrowser; 1.71 + 1.72 + browser.addEventListener("load", function onLoad(evt) { 1.73 + browser.removeEventListener(evt.type, onLoad, true); 1.74 + doc = content.document; 1.75 + isnot(prevTimestamp, getGUID(), "GUID has changed (page is not cached)"); 1.76 + testCacheDisabled2(); 1.77 + }, true); 1.78 + 1.79 + info("disabling cache"); 1.80 + 1.81 + cbx.scrollIntoView(); 1.82 + 1.83 + // After uising scrollIntoView() we need to use executeSoon() to wait for the 1.84 + // browser to scroll. 1.85 + executeSoon(function() { 1.86 + EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin); 1.87 + }); 1.88 +} 1.89 + 1.90 +function testCacheDisabled2() { 1.91 + let prevTimestamp = getGUID(); 1.92 + 1.93 + let browser = gBrowser.selectedBrowser; 1.94 + 1.95 + browser.addEventListener("load", function onLoad(evt) { 1.96 + browser.removeEventListener(evt.type, onLoad, true); 1.97 + doc = content.document; 1.98 + isnot(prevTimestamp, getGUID(), 1.99 + "GUID has changed after page refresh (page is not cached)"); 1.100 + finishUp(); 1.101 + }, true); 1.102 + 1.103 + doc.location.reload(false); 1.104 +} 1.105 + 1.106 +function getGUID() { 1.107 + return doc.querySelector("h1").textContent; 1.108 +} 1.109 + 1.110 +function finishUp() { 1.111 + toolbox.destroy().then(() => { 1.112 + gBrowser.removeCurrentTab(); 1.113 + toolbox = doc = null; 1.114 + finish(); 1.115 + }).then(null, console.error); 1.116 +}