Bug 1183178: use more robust e10s-friendly tab loading mechanism to fix intermittent test failures. r=Standard8

This commit is contained in:
Mike de Boer 2015-07-21 14:44:37 +02:00
parent bdd69627bc
commit d0cba8aea3
4 changed files with 6 additions and 55 deletions

View File

@ -24,7 +24,6 @@
"promiseOAuthGetRegistration": false,
"promiseOAuthParamsSetup": false,
"promiseObserverNotified": false,
"promiseTabLoadEvent": false,
"promiseWaitForCondition": false,
"resetFxA": true,
// Loop specific items

View File

@ -23,8 +23,7 @@ add_task(function* test_mozLoop_getSelectedTabMetadata() {
Assert.strictEqual(metadata.title, "", "Title should be empty for about:blank");
Assert.deepEqual(metadata.previews, [], "No previews available for about:blank");
let tab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(tab, "about:home");
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home");
metadata = yield promiseGetMetadata();
Assert.strictEqual(metadata.url, null, "URL should be empty for about:home");
@ -34,12 +33,11 @@ add_task(function* test_mozLoop_getSelectedTabMetadata() {
// elements with chrome:// srcs, which show up as null in metadata.previews.
Assert.deepEqual(metadata.previews.filter(e => e), [], "No previews available for about:home");
gBrowser.removeTab(tab);
yield BrowserTestUtils.removeTab(tab);
});
add_task(function* test_mozLoop_getSelectedTabMetadata_defaultIcon() {
let tab = gBrowser.selectedTab = gBrowser.addTab();
yield promiseTabLoadEvent(tab, "http://example.com/");
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
let metadata = yield promiseGetMetadata();
Assert.strictEqual(metadata.url, "http://example.com/", "URL should match");
@ -47,5 +45,5 @@ add_task(function* test_mozLoop_getSelectedTabMetadata_defaultIcon() {
Assert.ok(metadata.title, "Title should be set");
Assert.deepEqual(metadata.previews, [], "No previews available");
gBrowser.removeTab(tab);
yield BrowserTestUtils.removeTab(tab);
});

View File

@ -46,10 +46,10 @@ function promiseWindowIdReceivedNewTab(handlersParam = []) {
}));
});
let createdTab = gBrowser.selectedTab = gBrowser.addTab();
let createdTab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla");
createdTabs.push(createdTab);
promiseHandlers.push(promiseTabLoadEvent(createdTab, "about:mozilla"));
promiseHandlers.push(BrowserTestUtils.browserLoaded(createdTab.linkedBrowser));
return Promise.all(promiseHandlers);
}

View File

@ -207,52 +207,6 @@ function promiseOAuthGetRegistration(baseURL) {
});
}
/**
* Waits for a load (or custom) event to finish in a given tab. If provided
* load an uri into the tab.
*
* @param tab
* The tab to load into.
* @param [optional] url
* The url to load, or the current url.
* @param [optional] event
* The load event type to wait for. Defaults to "load".
* @return {Promise} resolved when the event is handled.
* @resolves to the received event
* @rejects if a valid load event is not received within a meaningful interval
*/
function promiseTabLoadEvent(tab, url, eventType="load") {
return new Promise((resolve, reject) => {
info("Wait tab event: " + eventType);
function handle(event) {
if (event.originalTarget != tab.linkedBrowser.contentDocument ||
event.target.location.href == "about:blank" ||
(url && event.target.location.href != url)) {
info("Skipping spurious '" + eventType + "'' event" +
" for " + event.target.location.href);
return;
}
clearTimeout(timeout);
tab.linkedBrowser.removeEventListener(eventType, handle, true);
info("Tab event received: " + eventType);
resolve(event);
}
let timeout = setTimeout(() => {
if (tab.linkedBrowser) {
tab.linkedBrowser.removeEventListener(eventType, handle, true);
}
reject(new Error("Timed out while waiting for a '" + eventType + "'' event"));
}, 30000);
tab.linkedBrowser.addEventListener(eventType, handle, true, true);
if (url) {
tab.linkedBrowser.loadURI(url);
}
});
}
function getLoopString(stringID) {
return MozLoopServiceInternal.localizedStrings.get(stringID);
}