Skip to content

Instantly share code, notes, and snippets.

@bobsilverberg
Created October 29, 2012 14:54
Show Gist options
  • Save bobsilverberg/3973996 to your computer and use it in GitHub Desktop.
Save bobsilverberg/3973996 to your computer and use it in GitHub Desktop.
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Include required modules
var toolbars = require("../../../lib/toolbars");
const TEST_PAGE = "http://www.mozilla.org/en-US/about/contact";
var setupModule = function(module) {
module.controller = mozmill.getBrowserController();
locationBar = new toolbars.locationBar(controller);
}
/**
* Test the stop and reload buttons
*/
var testStopAndReload = function() {
var pageUnloaded = false;
function onBeforeUnload() {
pageUnloaded = true;
controller.window.removeEventListener("beforeunload", onBeforeUnload, false);
dump("*** beforeunload event fired ***");
}
controller.window.addEventListener("beforeunload", onBeforeUnload, false);
// Make sure we have a blank page
controller.open("about:blank");
controller.waitForPageLoad();
// Go to the URL and start loading for some milliseconds
dump("*** before opening test page ***");
controller.open(TEST_PAGE);
dump("*** opened test page ***");
controller.waitFor(function() {
return pageUnloaded;
}, "The page has not been unloaded");
// controller.sleep(100);
var stopButton = locationBar.getElement({type: "stopButton"});
controller.click(stopButton);
// Even an element at the top of a page shouldn't exist when we hit the stop
// button extremely fast
var footer = new elementslib.ID(controller.tabs.activeTab, "footer-right");
controller.assertNodeNotExist(footer);
// Reload, wait for it to completely loading and test again
var reloadButton = locationBar.getElement({type: "reloadButton"});
controller.click(reloadButton);
controller.waitForPageLoad();
footer = new elementslib.ID(controller.tabs.activeTab, "footer-right");
controller.assertNode(footer);
}
/**
* Map test functions to litmus tests
*/
// testStopAndReload.meta = {litmusids : [8030]};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment