Skip to content

Instantly share code, notes, and snippets.

@MikeRatcliffe
Created November 22, 2013 16:06
Show Gist options
  • Save MikeRatcliffe/7602325 to your computer and use it in GitHub Desktop.
Save MikeRatcliffe/7602325 to your computer and use it in GitHub Desktop.
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that disabling JavaScript for a tab works as it should.
const TEST_URI = "http://mochi.test:8888/browser/browser/devtools/framework/" +
"test/browser_toolbox_options_disable_cache.html";
let doc;
let toolbox;
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
let target = TargetFactory.forTab(gBrowser.selectedTab);
gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
doc = content.document;
gDevTools.showToolbox(target).then(testSelectTool);
}, true);
content.location = TEST_URI;
}
function testSelectTool(aToolbox) {
toolbox = aToolbox;
toolbox.once("options-selected", testCacheEnabled);
toolbox.selectTool("options");
}
function testCacheEnabled() {
changeCacheState(true).then(function(pageCached) {
info("Testing that the page cache is enabled");
info("XXXXX: " + pageCached);
//debugger;
changeCacheState(true).then(function(pageCached) {
info("Testing that the page cache is enabled");
info("YYYYY: " + pageCached);
testCacheDisabled();
});
});
}
function testCacheDisabled() {
finishUp();
}
function changeCacheState(state) {
let deferred = promise.defer();
let panel = toolbox.getCurrentPanel();
let cbx = panel.panelDoc.getElementById("devtools-disable-cache");
let browser = gBrowser.selectedBrowser;
browser.addEventListener("pageshow", function onPageShow(pageCached) {
browser.removeEventListener("pageshow", onPageShow, true);
doc = content.document;
deferred.resolve(pageCached.persisted);
}, true);
if (cbx.checked !== state) {
// Disable cache checked and state is false (disabled) or vice-versa.
// Nothing to do so reload page.
doc.location.reload();
} else {
info("Toggling cache " + (state ? "on" : "off"));
cbx.scrollIntoView();
// After uising scrollIntoView() we need to use executeSoon() to wait for the
// browser to scroll.
executeSoon(function() {
EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin);
});
}
return deferred.promise;
}
function finishUp() {
toolbox.destroy().then(function() {
gBrowser.removeCurrentTab();
toolbox = doc = null;
finish();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment