Bug 1227539: allow a single argument to be passed to push message subscribers. r=Standard8
authorMike de Boer <mdeboer@mozilla.com>
Mon, 30 Nov 2015 16:22:30 +0100
changeset 274652 7905f57f7fa120a49fd15097b01680bcd9f2b0a6
parent 274651 2356e43e24b881410bc3991466378ce2db8991b3
child 274653 f47a7466e36bd0cd0425014c5a1c46a63ffbd4f0
push id16459
push usermdeboer@mozilla.com
push dateMon, 30 Nov 2015 15:51:17 +0000
treeherderfx-team@7905f57f7fa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1227539
milestone45.0a1
Bug 1227539: allow a single argument to be passed to push message subscribers. r=Standard8
browser/extensions/loop/content/shared/js/loopapi-client.js
browser/extensions/loop/test/shared/loopapi-client_test.js
--- a/browser/extensions/loop/content/shared/js/loopapi-client.js
+++ b/browser/extensions/loop/content/shared/js/loopapi-client.js
@@ -146,17 +146,21 @@ var loop = loop || {};
   loop.subscribe = function subscribe(name, callback) {
     if (!gListeningForPushMessages) {
       gRootObj.addMessageListener(kPushMessageName, gListeningForPushMessages = function(message) {
         var eventName = message.data[0];
         if (!gSubscriptionsMap[eventName]) {
           return;
         }
         gSubscriptionsMap[eventName].forEach(function(cb) {
-          cb.apply(null, message.data[1]);
+          var data = message.data[1];
+          if (!Array.isArray(data)) {
+            data = [data];
+          }
+          cb.apply(null, data);
         });
       });
     }
 
     if (!gSubscriptionsMap[name]) {
       gSubscriptionsMap[name] = [];
     }
     gSubscriptionsMap[name].push(callback);
--- a/browser/extensions/loop/test/shared/loopapi-client_test.js
+++ b/browser/extensions/loop/test/shared/loopapi-client_test.js
@@ -238,16 +238,26 @@ describe("loopapi-client", function() {
 
       sinon.assert.calledOnce(stub1);
       sinon.assert.calledWithExactly(stub1, "Foo", "Bar");
       sinon.assert.calledOnce(stub2);
       sinon.assert.calledWithExactly(stub2, "Foo", "Bar");
       sinon.assert.calledOnce(stub3);
       sinon.assert.calledWithExactly(stub3, "Foo", "Bar");
     });
+
+    it("should invoke subscription with non-array arguments too", function() {
+      var stub = sinon.stub();
+      loop.subscribe("LoopStatusChanged", stub);
+
+      sendMessage({ data: ["LoopStatusChanged", "Foo"] });
+
+      sinon.assert.calledOnce(stub);
+      sinon.assert.calledWithExactly(stub, "Foo");
+    });
   });
 
   describe("unsubscribe", function() {
     it("should remove subscriptions from the map", function() {
       var handler = function() {};
       loop.subscribe("LoopStatusChanged", handler);
 
       loop.unsubscribe("LoopStatusChanged", handler);