Bug 1594129 - Snippet messages should not be evaluated for trigger actions r=k88hudson a=pascalc
authorAndrei Oprea <andrei.br92@gmail.com>
Tue, 12 Nov 2019 16:20:28 +0000
changeset 563497 a514ead5cb170c7d66faf354c5d1a403c8938989
parent 563496 c65d4278139f08b1b18e602c3453f62c74bc53c9
child 563498 ee54407d806ffbfd10f2c05f54e729e12a704ccd
push id2203
push userarchaeopteryx@coole-files.de
push dateThu, 28 Nov 2019 22:17:51 +0000
treeherdermozilla-release@ee54407d806f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk88hudson, pascalc
bugs1594129
milestone71.0
Bug 1594129 - Snippet messages should not be evaluated for trigger actions r=k88hudson a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D52056
browser/components/newtab/lib/ASRouter.jsm
browser/components/newtab/test/unit/asrouter/ASRouter.test.js
--- a/browser/components/newtab/lib/ASRouter.jsm
+++ b/browser/components/newtab/lib/ASRouter.jsm
@@ -1621,17 +1621,20 @@ class _ASRouter {
   }) {
     const msgs = this._getUnblockedMessages().filter(m => {
       if (provider && m.provider !== provider) {
         return false;
       }
       if (template && m.template !== template) {
         return false;
       }
-      if (m.trigger && m.trigger.id !== triggerId) {
+      if (triggerId && !m.trigger) {
+        return false;
+      }
+      if (triggerId && m.trigger.id !== triggerId) {
         return false;
       }
 
       return true;
     });
 
     if (returnAll) {
       return this._findAllMessages(
--- a/browser/components/newtab/test/unit/asrouter/ASRouter.test.js
+++ b/browser/components/newtab/test/unit/asrouter/ASRouter.test.js
@@ -1089,16 +1089,41 @@ describe("ASRouter", () => {
 
       assert.calledOnce(stub);
       assert.calledWithExactly(stub, sinon.match.array, {
         id: trigger.triggerId,
         param: trigger.triggerParam,
         context: trigger.triggerContext,
       });
     });
+    it("should filter out messages without a trigger (or different) when a triggerId is defined", async () => {
+      const trigger = { triggerId: "foo" };
+      const message1 = {
+        id: "1",
+        campaign: "foocampaign",
+        trigger: { id: "foo" },
+      };
+      const message2 = {
+        id: "2",
+        campaign: "foocampaign",
+        trigger: { id: "bar" },
+      };
+      const message3 = {
+        id: "3",
+        campaign: "bazcampaign",
+      };
+      await Router.setState({ messages: [message2, message1, message3] });
+      // Just return the first message provided as arg
+      sandbox.stub(Router, "_findMessage").callsFake(args => args);
+
+      const result = Router.handleMessageRequest(trigger);
+
+      assert.lengthOf(result, 1);
+      assert.deepEqual(result[0], message1);
+    });
   });
 
   describe("#uninit", () => {
     it("should remove the message listener on the RemotePageManager", () => {
       const [, listenerAdded] = channel.addMessageListener.firstCall.args;
       assert.isFunction(listenerAdded);
 
       Router.uninit();