Bug 1590442 - make ASRouter trigger.params support bitwise values; r=k88hudson
authorLiang-Heng Chen <xeonchen@gmail.com>
Mon, 28 Oct 2019 18:13:16 +0000
changeset 499470 aec2718b33a4cfad83c95c66310e50dc60298292
parent 499469 c65ef27b6fc78ec5140068913209bad3b55f1139
child 499471 9fbcda0c9722386650a78ec1ee3d2427946fa9a2
push id114161
push userncsoregi@mozilla.com
push dateTue, 29 Oct 2019 21:34:24 +0000
treeherdermozilla-inbound@25bf8e097e60 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk88hudson
bugs1590442
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1590442 - make ASRouter trigger.params support bitwise values; r=k88hudson Differential Revision: https://phabricator.services.mozilla.com/D50081
browser/components/newtab/lib/ASRouterTargeting.jsm
browser/components/newtab/lib/ASRouterTriggerListeners.jsm
browser/components/newtab/test/browser/browser_asrouter_trigger_listeners.js
--- a/browser/components/newtab/lib/ASRouterTargeting.jsm
+++ b/browser/components/newtab/lib/ASRouterTargeting.jsm
@@ -523,17 +523,19 @@ this.ASRouterTargeting = {
     }
 
     return (
       (candidateMessageTrigger.params &&
         trigger.param.host &&
         candidateMessageTrigger.params.includes(trigger.param.host)) ||
       (candidateMessageTrigger.params &&
         trigger.param.type &&
-        candidateMessageTrigger.params.includes(trigger.param.type)) ||
+        candidateMessageTrigger.params.filter(
+          t => (t & trigger.param.type) === t
+        ).length) ||
       (candidateMessageTrigger.patterns &&
         trigger.param.url &&
         new MatchPatternSet(candidateMessageTrigger.patterns).matches(
           trigger.param.url
         ))
     );
   },
 
--- a/browser/components/newtab/lib/ASRouterTriggerListeners.jsm
+++ b/browser/components/newtab/lib/ASRouterTriggerListeners.jsm
@@ -509,25 +509,22 @@ this.ASRouterTriggerListeners = new Map(
         this._events = [];
         this._sessionPageLoad = 0;
       },
 
       observe(aSubject, aTopic, aData) {
         switch (aTopic) {
           case "SiteProtection:ContentBlockingEvent":
             const { browser, host, event } = aSubject.wrappedJSObject;
-            for (let ev of this._events) {
-              if ((ev & event) !== ev) {
-                continue;
-              }
+            if (this._events.filter(e => (e & event) === e).length) {
               this._triggerHandler(browser, {
                 id: "trackingProtection",
                 param: {
                   host,
-                  type: ev,
+                  type: event,
                 },
                 context: {
                   pageLoad: this._sessionPageLoad,
                 },
               });
             }
             break;
           case "SiteProtection:ContentBlockingMilestone":
@@ -536,17 +533,17 @@ this.ASRouterTriggerListeners = new Map(
                 Services.wm.getMostRecentBrowserWindow().gBrowser
                   .selectedBrowser,
                 {
                   id: "trackingProtection",
                   context: {
                     pageLoad: this._sessionPageLoad,
                   },
                   param: {
-                    type: aSubject.wrappedJSObject.event,
+                    host: aSubject.wrappedJSObject.event,
                   },
                 }
               );
             }
             break;
         }
       },
 
--- a/browser/components/newtab/test/browser/browser_asrouter_trigger_listeners.js
+++ b/browser/components/newtab/test/browser/browser_asrouter_trigger_listeners.js
@@ -322,20 +322,20 @@ add_task(async function check_trackingPr
 add_task(async function check_trackingProtectionMilestone_listener() {
   const TEST_URL =
     "https://example.com/browser/browser/components/newtab/test/browser/red_page.html";
 
   let observerEvent = 0;
   const triggerHandler = (target, trigger) => {
     const {
       id,
-      param: { type },
+      param: { host },
     } = trigger;
     is(id, "trackingProtection", "should match event name");
-    is(type, "ContentBlockingMilestone", "Should be the correct event type");
+    is(host, "ContentBlockingMilestone", "Should be the correct event type");
     observerEvent += 1;
   };
   const trackingProtectionListener = ASRouterTriggerListeners.get(
     "trackingProtection"
   );
 
   // Previously initialized by the Router
   trackingProtectionListener.uninit();