Bug 332195 - part 5: fix test for e10s, r=mconley

--HG--
extra : commitid : 5Cb58g4sU6s
extra : rebase_source : e22ceac2b58b2ad62587c7db0e7e8bc90565da72
This commit is contained in:
Gijs Kruitbosch 2015-10-26 14:16:46 +01:00
parent 85788a7aa9
commit ea934a6d68
2 changed files with 38 additions and 0 deletions

View File

@ -19,8 +19,11 @@ add_task(function*() {
let firstTab = gBrowser.selectedTab;
// load page that opens prompt when page is hidden
let openedTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, pageWithAlert, true);
let openedTabGotAttentionPromise = BrowserTestUtils.waitForAttribute("attention", openedTab, "true");
// switch away from that tab again - this triggers the alert.
yield BrowserTestUtils.switchTab(gBrowser, firstTab);
// ... but that's async on e10s...
yield openedTabGotAttentionPromise;
// check for attention attribute
is(openedTab.getAttribute("attention"), "true", "Tab with alert should have 'attention' attribute.");
ok(!openedTab.selected, "Tab with alert should not be selected");
@ -43,8 +46,15 @@ add_task(function*() {
let ps = Services.perms;
is(ps.ALLOW_ACTION, ps.testPermission(makeURI(pageWithAlert), "focus-tab-by-prompt"),
"Tab switching should now be allowed");
let openedTabSelectedPromise = BrowserTestUtils.waitForAttribute("selected", openedTab, "true");
// switch to other tab again
yield BrowserTestUtils.switchTab(gBrowser, firstTab);
// This is sync in non-e10s, but in e10s we need to wait for this, so yield anyway.
// Note that the switchTab promise doesn't actually guarantee anything about *which*
// tab ends up as selected when its event fires, so using that here wouldn't work.
yield openedTabSelectedPromise;
// should be switched back
ok(openedTab.selected, "Ta-dah, the other tab should now be selected again!");

View File

@ -603,6 +603,34 @@ this.BrowserTestUtils = {
return extra;
}),
/**
* Returns a promise that is resolved when element gains attribute (or,
* optionally, when it is set to value).
* @param {String} attr
* The attribute to wait for
* @param {Element} element
* The element which should gain the attribute
* @param {String} value (optional)
* Optional, the value the attribute should have.
*
* @returns {Promise}
*/
waitForAttribute(attr, element, value) {
let MutationObserver = element.ownerDocument.defaultView.MutationObserver;
return new Promise(resolve => {
let mut = new MutationObserver(mutations => {
if ((!value && element.getAttribute(attr)) ||
(value && element.getAttribute(attr) === value)) {
resolve();
mut.disconnect();
return;
}
});
mut.observe(element, {attributeFilter: [attr]});
});
},
/**
* Version of EventUtils' `sendChar` function; it will synthesize a keypress
* event in a child process and returns a Promise that will result when the