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
Родитель bc4dbcd8a1
Коммит 8bec2e8b93
2 изменённых файлов: 26 добавлений и 39 удалений

Просмотреть файл

@ -11,7 +11,6 @@ const CAPTURE_PREF = "browser.pagethumbnails.capturing_disabled";
function runTests() { function runTests() {
let imports = {}; let imports = {};
Cu.import("resource://gre/modules/PageThumbs.jsm", imports); Cu.import("resource://gre/modules/PageThumbs.jsm", imports);
Cu.import("resource:///modules/BrowserNewTabPreloader.jsm", imports);
// Disable captures. // Disable captures.
let originalDisabledState = Services.prefs.getBoolPref(CAPTURE_PREF); let originalDisabledState = Services.prefs.getBoolPref(CAPTURE_PREF);
@ -31,32 +30,15 @@ function runTests() {
yield setLinks("-1"); yield setLinks("-1");
// We need a handle to a hidden, pre-loaded newtab so we can verify that it // 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 // doesn't allow background captures. Ensure we have a preloaded browser.
// of a hidden newtab, and then keep calling BrowserNewTabPreloader.newTab gBrowser._createPreloadBrowser();
// 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();
// When newtab is loaded very quickly (which is what happens in 99% of cases) // Wait for the preloaded browser to load.
// there is no need to wait so no tests are run. Because each test requires yield waitForBrowserLoad(gBrowser._preloadedBrowser);
// 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.");
let swapWaitCount = 0; // We're now ready to use the preloaded browser.
let swapped = imports.BrowserNewTabPreloader.newTab(tab); BrowserOpenTab();
while (!swapped) { let tab = gBrowser.selectedTab;
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.
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
// Enable captures. // Enable captures.
@ -67,8 +49,11 @@ function runTests() {
if (data != url) if (data != url)
return; return;
Services.obs.removeObserver(onCreate, "page-thumbnail:create"); Services.obs.removeObserver(onCreate, "page-thumbnail:create");
ok(true, "thumbnail created after preloaded tab was shown");
// Test finished! // Test finished!
Services.prefs.setBoolPref(CAPTURE_PREF, originalDisabledState); Services.prefs.setBoolPref(CAPTURE_PREF, originalDisabledState);
gBrowser.removeTab(tab);
file.remove(false); file.remove(false);
TestRunner.next(); TestRunner.next();
}, "page-thumbnail:create", false); }, "page-thumbnail:create", false);
@ -76,7 +61,3 @@ function runTests() {
info("Waiting for thumbnail capture"); info("Waiting for thumbnail capture");
yield true; yield true;
} }
function wait(ms) {
setTimeout(TestRunner.next, ms);
}

Просмотреть файл

@ -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. // Wait for the new tab page to be loaded.
browser.addEventListener("load", function onLoad() { waitForBrowserLoad(browser, function () {
browser.removeEventListener("load", onLoad, true); // Wait for the document to become visible in case it was preloaded.
whenNewTabLoaded(); waitForCondition(() => !browser.contentDocument.hidden).then(whenNewTabLoaded);
}, true); });
return deferred.promise; 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. * Compares the current grid arrangement with the given pattern.
* @param the pattern (see below) * @param the pattern (see below)