Bug 1163418 - Remove use of CPOWs in in browser plugin tests. r=felipe, a=test-only
--- a/browser/base/content/test/plugins/browser_pluginnotification.js
+++ b/browser/base/content/test/plugins/browser_pluginnotification.js
@@ -113,17 +113,17 @@ add_task(function* () {
yield promisePopupNotification("click-to-play-plugins");
yield promiseTabLoadEvent(gBrowser.selectedTab, "data:text/html,<html>hi</html>");
// make sure the notification is gone
let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
ok(!notification, "Test 11b, Should not have a click-to-play notification");
- gTestBrowser.contentWindow.history.back();
+ gTestBrowser.webNavigation.goBack();
yield promisePopupNotification("click-to-play-plugins");
});
// Tests that the "Allow Always" permission works for click-to-play plugins
add_task(function* () {
updateAllTestPlugins(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
--- a/browser/base/content/test/plugins/head.js
+++ b/browser/base/content/test/plugins/head.js
@@ -1,14 +1,16 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
+ "resource://gre/modules/PromiseUtils.jsm");
// The blocklist shim running in the content process does not initialize at
// start up, so it's not active until we load content that needs to do a
// check. This helper bypasses the delay to get the svc up and running
// immediately. Note, call this after remote content has loaded.
function promiseInitContentBlocklistSvc(aBrowser)
{
return ContentTask.spawn(aBrowser, {}, function* () {
@@ -66,50 +68,54 @@ function waitForEvent(subject, eventName
/**
* 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 promiseTabLoadEvent(tab, url) {
+ let deferred = PromiseUtils.defer();
+ info("Wait tab event: load");
- 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);
+ function handle(loadedUrl) {
+ if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
+ info(`Skipping spurious load event for ${loadedUrl}`);
+ return false;
}
- let timeout = setTimeout(() => {
- tab.linkedBrowser.removeEventListener(eventType, handle, true);
- reject(new Error("Timed out while waiting for a '" + eventType + "'' event"));
- }, 30000);
+ info("Tab event received: load");
+ return true;
+ }
+
+ // Create two promises: one resolved from the content process when the page
+ // loads and one that is rejected if we take too long to load the url.
+ let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
+
+ let timeout = setTimeout(() => {
+ deferred.reject(new Error("Timed out while waiting for a 'load' event"));
+ }, 30000);
- tab.linkedBrowser.addEventListener(eventType, handle, true, true);
- if (url) {
- tab.linkedBrowser.loadURI(url);
- }
+ loaded.then(() => {
+ clearTimeout(timeout);
+ deferred.resolve()
});
+
+ if (url)
+ BrowserTestUtils.loadURI(tab.linkedBrowser, url);
+
+ // Promise.all rejects if either promise rejects (i.e. if we time out) and
+ // if our loaded promise resolves before the timeout, then we resolve the
+ // timeout promise as well, causing the all promise to resolve.
+ return Promise.all([deferred.promise, loaded]);
}
function waitForCondition(condition, nextTest, errorMsg, aTries, aWait) {
let tries = 0;
let maxTries = aTries || 100; // 100 tries
let maxWait = aWait || 100; // 100 msec x 100 tries = ten seconds
let interval = setInterval(function() {
if (tries >= maxTries) {