Bug 1594129 - Snippet messages should not be evaluated for trigger actions r=k88hudson
authorAndrei Oprea <andrei.br92@gmail.com>
Tue, 12 Nov 2019 16:20:28 +0000
changeset 501665 2a0648ebfc029c7bc00232a565613eb10ff21e66
parent 501664 5b26b747f3bd5be47e43b07531a88cc292dfdebb
child 501666 7019a4a1fe39964f90b14158e84d05d727d888bd
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk88hudson
bugs1594129
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 1594129 - Snippet messages should not be evaluated for trigger actions r=k88hudson 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
@@ -1632,17 +1632,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
@@ -1095,16 +1095,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();