Bug 1077652 - Update browser_newtab_background_captures.js to work with the new preloader r=adw

This commit is contained in:
Tim Taubert 2014-11-19 16:21:22 +01:00
parent bc4dbcd8a1
commit 8bec2e8b93
2 changed files with 26 additions and 39 deletions

View File

@ -11,7 +11,6 @@ const CAPTURE_PREF = "browser.pagethumbnails.capturing_disabled";
function runTests() {
let imports = {};
Cu.import("resource://gre/modules/PageThumbs.jsm", imports);
Cu.import("resource:///modules/BrowserNewTabPreloader.jsm", imports);
// Disable captures.
let originalDisabledState = Services.prefs.getBoolPref(CAPTURE_PREF);
@ -31,32 +30,15 @@ function runTests() {
yield setLinks("-1");
// We need a handle to a hidden, pre-loaded newtab so we can verify that it
// doesn't allow background captures. Add a newtab, which triggers creation
// of a hidden newtab, and then keep calling BrowserNewTabPreloader.newTab
// until it returns true, meaning that it swapped the passed-in tab's docshell
// for the hidden newtab docshell.
let tab = gWindow.gBrowser.addTab("about:blank");
yield addNewTabPageTab();
// doesn't allow background captures. Ensure we have a preloaded browser.
gBrowser._createPreloadBrowser();
// When newtab is loaded very quickly (which is what happens in 99% of cases)
// there is no need to wait so no tests are run. Because each test requires
// either a pass, fail or todo we run a dummy test here.
ok(true, "Each test requires at least one pass, fail or todo so here is a pass.");
// Wait for the preloaded browser to load.
yield waitForBrowserLoad(gBrowser._preloadedBrowser);
let swapWaitCount = 0;
let swapped = imports.BrowserNewTabPreloader.newTab(tab);
while (!swapped) {
if (++swapWaitCount == 10) {
ok(false, "Timed out waiting for newtab docshell swap.");
return;
}
// Give the hidden newtab some time to finish loading.
yield wait(2000);
info("Checking newtab swap " + swapWaitCount);
swapped = imports.BrowserNewTabPreloader.newTab(tab);
}
// The tab's docshell is now the previously hidden newtab docshell.
// We're now ready to use the preloaded browser.
BrowserOpenTab();
let tab = gBrowser.selectedTab;
let doc = tab.linkedBrowser.contentDocument;
// Enable captures.
@ -67,8 +49,11 @@ function runTests() {
if (data != url)
return;
Services.obs.removeObserver(onCreate, "page-thumbnail:create");
ok(true, "thumbnail created after preloaded tab was shown");
// Test finished!
Services.prefs.setBoolPref(CAPTURE_PREF, originalDisabledState);
gBrowser.removeTab(tab);
file.remove(false);
TestRunner.next();
}, "page-thumbnail:create", false);
@ -76,7 +61,3 @@ function runTests() {
info("Waiting for thumbnail capture");
yield true;
}
function wait(ms) {
setTimeout(TestRunner.next, ms);
}

View File

@ -374,21 +374,27 @@ function addNewTabPageTabPromise() {
}
}
// The new tab page might have been preloaded in the background.
if (browser.contentDocument.readyState == "complete") {
waitForCondition(() => !browser.contentDocument.hidden).then(whenNewTabLoaded);
return deferred.promise;
}
// Wait for the new tab page to be loaded.
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
whenNewTabLoaded();
}, true);
waitForBrowserLoad(browser, function () {
// Wait for the document to become visible in case it was preloaded.
waitForCondition(() => !browser.contentDocument.hidden).then(whenNewTabLoaded);
});
return deferred.promise;
}
function waitForBrowserLoad(browser, callback = TestRunner.next) {
if (browser.contentDocument.readyState == "complete") {
executeSoon(callback);
return;
}
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
executeSoon(callback);
}, true);
}
/**
* Compares the current grid arrangement with the given pattern.
* @param the pattern (see below)