Bug 1151862 - Get the full list of Loop rooms on first notification if we haven't got it previously. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Wed, 06 May 2015 12:47:10 +0100
changeset 273932 44e94627981782a8980e45b4cae7fda82b46328b
parent 273931 90712b6eb7b6a95dba6e6de3a237f73fd82875a9
child 273933 08e566362fc9c84e76c2586a7e843851330aade4
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1151862
milestone40.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 1151862 - Get the full list of Loop rooms on first notification if we haven't got it previously. r=mikedeboer
browser/components/loop/modules/LoopRooms.jsm
browser/components/loop/test/xpcshell/test_looprooms_first_notification.js
browser/components/loop/test/xpcshell/xpcshell.ini
--- a/browser/components/loop/modules/LoopRooms.jsm
+++ b/browser/components/loop/modules/LoopRooms.jsm
@@ -722,18 +722,22 @@ let LoopRoomsInternal = {
   onNotification: function(version, channelID) {
     // See if we received a notification for the channel that's currently active:
     let channelIDs = MozLoopService.channelIDs;
     if ((this.sessionType == LOOP_SESSION_TYPE.GUEST && channelID != channelIDs.roomsGuest) ||
         (this.sessionType == LOOP_SESSION_TYPE.FXA   && channelID != channelIDs.roomsFxA)) {
       return;
     }
 
+    let oldDirty = gDirty;
     gDirty = true;
-    this.getAll(version, () => {});
+    // If we were already dirty, then get the full set of rooms. For example,
+    // we'd already be dirty if we had started up but not got the list of rooms
+    // yet.
+    this.getAll(oldDirty ? null : version, () => {});
   },
 
   /**
    * When a user logs in or out, this method should be invoked to check whether
    * the rooms cache needs to be refreshed.
    *
    * @param {String|null} user The FxA userID or NULL
    */
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/test/xpcshell/test_looprooms_first_notification.js
@@ -0,0 +1,119 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Cu.import("resource://services-common/utils.js");
+Cu.import("resource:///modules/loop/LoopRooms.jsm");
+Cu.import("resource:///modules/Chat.jsm");
+Cu.import("resource://gre/modules/Promise.jsm");
+
+const kGuestKey = "uGIs-kGbYt1hBBwjyW7MLQ";
+const kChannelGuest = MozLoopService.channelIDs.roomsGuest;
+
+const kRoomsResponses = new Map([
+  ["_nxD4V4FflQ", {
+    roomToken: "_nxD4V4FflQ",
+    // Encrypted with roomKey "FliIGLUolW-xkKZVWstqKw".
+    // roomKey is wrapped with kGuestKey.
+    context: {
+      wrappedKey: "F3V27oPB+FgjFbVPML2PupONYqoIZ53XRU4BqG46Lr3eyIGumgCEqgjSe/MXAXiQ//8=",
+      value: "df7B4SNxhOI44eJjQavCevADyCCxz6/DEZbkOkRUMVUxzS42FbzN6C2PqmCKDYUGyCJTwJ0jln8TLw==",
+      alg: "AES-GCM"
+    },
+    roomUrl: "http://localhost:3000/rooms/_nxD4V4FflQ",
+    maxSize: 2,
+    ctime: 1405517546,
+    participants: [{
+      displayName: "Alexis",
+      account: "alexis@example.com",
+      roomConnectionId: "2a1787a6-4a73-43b5-ae3e-906ec1e763cb"
+    }, {
+      displayName: "Adam",
+      roomConnectionId: "781f012b-f1ea-4ce1-9105-7cfc36fb4ec7"
+    }]
+  }],
+  ["QzBbvGmIZWU", {
+    roomToken: "QzBbvGmIZWU",
+    roomName: "Second Room Name",
+    roomUrl: "http://localhost:3000/rooms/QzBbvGmIZWU",
+    maxSize: 2,
+    ctime: 140551741
+  }],
+]);
+
+let gRoomsAdded = [];
+let gRoomsUpdated = [];
+
+const onRoomAdded = function(e, room) {
+  gRoomsAdded.push(room);
+};
+
+const onRoomUpdated = function(e, room) {
+  gRoomsUpdated.push(room);
+};
+
+let gQueryString = null;
+
+add_task(function* setup_server() {
+  loopServer.registerPathHandler("/registration", (req, res) => {
+    res.setStatusLine(null, 200, "OK");
+    res.processAsync();
+    res.finish();
+  });
+
+  loopServer.registerPathHandler("/rooms", (req, res) => {
+    gQueryString = req.queryString;
+
+    res.setStatusLine(null, 200, "OK");
+    // For this simple test, always send all rooms, even though this wouldn't
+    // happen normally.
+    res.write(JSON.stringify([...kRoomsResponses.values()]));
+    res.processAsync();
+    res.finish();
+  });
+
+  mockPushHandler.registrationPushURL = kEndPointUrl;
+
+  yield MozLoopService.promiseRegisteredWithServers();
+});
+
+// Test if notifying from push correctly gets all rooms the first time.
+add_task(function* test_notification_firstTime() {
+  roomsPushNotification("1", kChannelGuest);
+
+  // Wait for the notification to complete before we getAll, otherwise
+  // the getAll may cover up what we're testing.
+  yield waitForCondition(() => gRoomsAdded.length === 2);
+
+  let rooms = yield LoopRooms.promise("getAll");
+  Assert.equal(rooms.length, 2);
+  Assert.equal(gQueryString, "", "Query string should not be set.");
+});
+
+// Test if notifying from push correctly only gets the specific room the second time.
+add_task(function* test_notification_firstTime() {
+  roomsPushNotification("2", kChannelGuest);
+  yield waitForCondition(() => gRoomsUpdated.length === 2);
+
+  let rooms = yield LoopRooms.promise("getAll");
+  Assert.equal(rooms.length, 2);
+  Assert.equal(gQueryString, "version=2", "Query string should be set.");
+});
+
+function run_test() {
+  setupFakeLoopServer();
+
+  Services.prefs.setCharPref("loop.key", kGuestKey);
+  LoopRooms.on("add", onRoomAdded);
+  LoopRooms.on("update", onRoomUpdated);
+
+  do_register_cleanup(function () {
+    Services.prefs.clearUserPref("loop.key");
+
+    LoopRooms.off("add", onRoomAdded);
+    LoopRooms.off("update", onRoomUpdated);
+  });
+
+  run_next_test();
+}
--- a/browser/components/loop/test/xpcshell/xpcshell.ini
+++ b/browser/components/loop/test/xpcshell/xpcshell.ini
@@ -2,16 +2,17 @@
 head = head.js
 tail =
 firefox-appdir = browser
 skip-if = toolkit == 'gonk'
 
 [test_loopapi_hawk_request.js]
 [test_looppush_initialize.js]
 [test_looprooms.js]
+[test_looprooms_first_notification.js]
 [test_loopservice_directcall.js]
 [test_loopservice_dnd.js]
 [test_loopservice_encryptionkey.js]
 [test_loopservice_hawk_errors.js]
 [test_loopservice_hawk_request.js]
 [test_loopservice_loop_prefs.js]
 [test_loopservice_initialize.js]
 [test_loopservice_locales.js]