Bug 1363253 - Ignore events specific to preview window also when decrementing. r=florian, a=test-only
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 11 May 2017 15:07:17 +0200
changeset 393989 4f95bb8a858ddba0c994002467109b70b6344990
parent 393988 a3bc13b60d416ad4a0dd42820ede5c0d69c288a0
child 393990 518c6f7cde3efeb4a1ebb12d1f17b04402f7cace
push id7323
push userryanvm@gmail.com
push dateThu, 18 May 2017 12:36:33 +0000
treeherdermozilla-beta@5a67d4114989 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, test-only
bugs1363253
milestone54.0
Bug 1363253 - Ignore events specific to preview window also when decrementing. r=florian, a=test-only MozReview-Commit-ID: 8pjSBUI7ZkZ
browser/base/content/test/webrtc/get_user_media_content_script.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
@@ -13,29 +13,37 @@ const kObservedTopics = [
   "getUserMedia:revoke",
   "getUserMedia:response:deny",
   "getUserMedia:request",
   "recording-device-events",
   "recording-window-ended"
 ];
 
 var gObservedTopics = {};
-function observer(aSubject, aTopic, aData) {
+
+function ignoreEvent(aSubject, aTopic, aData) {
   // With e10s disabled, our content script receives notifications for the
   // preview displayed in our screen sharing permission prompt; ignore them.
   const kBrowserURL = "chrome://browser/content/browser.xul";
   const nsIPropertyBag = Components.interfaces.nsIPropertyBag;
   if (aTopic == "recording-device-events" &&
       aSubject.QueryInterface(nsIPropertyBag).getProperty("requestURL") == kBrowserURL) {
-    return;
+    return true;
   }
   if (aTopic == "recording-window-ended") {
     let win = Services.wm.getOuterWindowWithId(aData).top;
     if (win.document.documentURI == kBrowserURL)
-      return;
+      return true;
+  }
+  return false;
+}
+
+function observer(aSubject, aTopic, aData) {
+  if (ignoreEvent(aSubject, aTopic, aData)) {
+    return;
   }
 
   if (!(aTopic in gObservedTopics))
     gObservedTopics[aTopic] = 1;
   else
     ++gObservedTopics[aTopic];
 }
 
@@ -85,17 +93,26 @@ function _getMediaCaptureState() {
 }
 
 addMessageListener("Test:GetMediaCaptureState", data => {
   sendAsyncMessage("Test:MediaCaptureState", _getMediaCaptureState());
 });
 
 addMessageListener("Test:WaitForObserverCall", ({data}) => {
   let topic = data;
-  Services.obs.addObserver(function obs() {
+  Services.obs.addObserver(function obs(aSubject, aTopic, aData) {
+    if (aTopic != topic) {
+      is(aTopic, topic, "Wrong topic observed");
+      return;
+    }
+
+    if (ignoreEvent(aSubject, aTopic, aData)) {
+      return;
+    }
+
     sendAsyncMessage("Test:ObserverCalled", topic);
     Services.obs.removeObserver(obs, topic);
 
     if (kObservedTopics.indexOf(topic) != -1) {
       if (!(topic in gObservedTopics))
         gObservedTopics[topic] = -1;
       else
         --gObservedTopics[topic];