Bug 1258142 - Stop using a CPOW in promiseMessage for webrtc bc tests, r=Gijs.
authorFlorian Quèze <florian@queze.net>
Wed, 21 Sep 2016 21:20:06 +0200
changeset 314724 6757959dbba2a80fa1f58ea4e677c65cb5cd9e15
parent 314723 9bc9a1bb8ad6a4b26496b262b8104eb1f66f3396
child 314725 e893929f7606287f3359cda18bfb29d492846643
push id20586
push userflorian@queze.net
push dateWed, 21 Sep 2016 19:22:16 +0000
treeherderfx-team@6757959dbba2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1258142
milestone52.0a1
Bug 1258142 - Stop using a CPOW in promiseMessage for webrtc bc tests, r=Gijs.
browser/base/content/test/webrtc/get_user_media_content_script.js
browser/base/content/test/webrtc/head.js
--- a/browser/base/content/test/webrtc/get_user_media_content_script.js
+++ b/browser/base/content/test/webrtc/get_user_media_content_script.js
@@ -79,8 +79,14 @@ addMessageListener("Test:WaitForObserver
     if (kObservedTopics.indexOf(topic) != -1) {
       if (!(topic in gObservedTopics))
         gObservedTopics[topic] = -1;
       else
         --gObservedTopics[topic];
     }
   }, topic, false);
 });
+
+addMessageListener("Test:WaitForMessage", () => {
+  content.addEventListener("message", ({data}) => {
+    sendAsyncMessage("Test:MessageReceived", data);
+  }, {once: true});
+});
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -241,31 +241,33 @@ function promiseTodoObserverNotCalled(aT
       mm.removeMessageListener("Test:TodoObserverNotCalled:Reply", listener);
       resolve(data.count);
     });
     mm.sendAsyncMessage("Test:TodoObserverNotCalled", aTopic);
   });
 }
 
 function promiseMessage(aMessage, aAction) {
-  let deferred = Promise.defer();
-
-  content.addEventListener("message", function messageListener(event) {
-    content.removeEventListener("message", messageListener);
-    is(event.data, aMessage, "received " + aMessage);
-    if (event.data == aMessage)
-      deferred.resolve();
-    else
-      deferred.reject();
+  let promise = new Promise((resolve, reject) => {
+    let mm = _mm();
+    mm.addMessageListener("Test:MessageReceived", function listener({data}) {
+      is(data, aMessage, "received " + aMessage);
+      if (data == aMessage)
+        resolve();
+      else
+        reject();
+      mm.removeMessageListener("Test:MessageReceived", listener);
+    });
+    mm.sendAsyncMessage("Test:WaitForMessage");
   });
 
   if (aAction)
     aAction();
 
-  return deferred.promise;
+  return promise;
 }
 
 function promisePopupNotificationShown(aName, aAction) {
   let deferred = Promise.defer();
 
   PopupNotifications.panel.addEventListener("popupshown", function popupNotifShown() {
     PopupNotifications.panel.removeEventListener("popupshown", popupNotifShown);