Files
tubestation/toolkit/content/tests/browser/head.js
Iris Hsiao a501d530f1 Backed out 6 changesets (bug 1347758) for eslint failure
Backed out changeset 9becd55242c1 (bug 1347758)
Backed out changeset 2abce19f5001 (bug 1347758)
Backed out changeset 80232d4c85d5 (bug 1347758)
Backed out changeset 1fd084ec34d4 (bug 1347758)
Backed out changeset cafb3c12027b (bug 1347758)
Backed out changeset 85846edfe957 (bug 1347758)
2017-03-24 16:58:08 +08:00

70 lines
2.1 KiB
JavaScript

"use strict";
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
/**
* A wrapper for the findbar's method "close", which is not synchronous
* because of animation.
*/
function closeFindbarAndWait(findbar) {
return new Promise((resolve) => {
if (findbar.hidden) {
resolve();
return;
}
findbar.addEventListener("transitionend", function cont(aEvent) {
if (aEvent.propertyName != "visibility") {
return;
}
findbar.removeEventListener("transitionend", cont);
resolve();
});
findbar.close();
});
}
function pushPrefs(...aPrefs) {
let deferred = Promise.defer();
SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
return deferred.promise;
}
/**
* Used to check whether the audio unblocking icon is in the tab.
*/
function* waitForTabBlockEvent(tab, expectBlocked) {
if (tab.soundBlocked == expectBlocked) {
ok(true, "The tab should " + (expectBlocked ? "" : "not ") + "be blocked");
} else {
info("Block state doens't match, wait for attributes changes.");
yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.indexOf("blocked") >= 0) {
is(tab.soundBlocked, expectBlocked, "The tab should " + (expectBlocked ? "" : "not ") + "be blocked");
return true;
}
return false;
});
}
}
/**
* Used to check whether the tab has soundplaying attribute.
*/
function* waitForTabPlayingEvent(tab, expectPlaying) {
if (tab.soundPlaying == expectPlaying) {
ok(true, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
} else {
info("Playing state doens't match, wait for attributes changes.");
yield BrowserTestUtils.waitForEvent(tab, "TabAttrModified", false, (event) => {
if (event.detail.changed.indexOf("soundplaying") >= 0) {
is(tab.soundPlaying, expectPlaying, "The tab should " + (expectPlaying ? "" : "not ") + "be playing");
return true;
}
return false;
});
}
}