Bug 1401590 - Mock FxAccounts#newAccountState in push service tests. r?markh draft
authorEdouard Oger <eoger@fastmail.com>
Thu, 21 Sep 2017 13:27:46 -0400
changeset 668444 5701f68b77e0bd575dcc35997dcaff76a9cb48ff
parent 667935 319a34bea9e4f3459886b5b9e835bd338320f1fd
child 732706 257336346953fd961d4022a699f8df179469de41
push id81050
push userbmo:eoger@fastmail.com
push dateThu, 21 Sep 2017 17:31:59 +0000
reviewersmarkh
bugs1401590
milestone57.0a1
Bug 1401590 - Mock FxAccounts#newAccountState in push service tests. r?markh MozReview-Commit-ID: 8kVtWbPKp65
services/fxaccounts/tests/xpcshell/test_push_service.js
--- a/services/fxaccounts/tests/xpcshell/test_push_service.js
+++ b/services/fxaccounts/tests/xpcshell/test_push_service.js
@@ -182,21 +182,30 @@ add_task(async function observePushTopic
         }
       })
     },
     QueryInterface() {
       return this;
     }
   };
 
+  let signoutCalled = false;
   let { FxAccounts } = Cu.import("resource://gre/modules/FxAccounts.jsm", {});
-  const fxAccountsMock = new FxAccounts({});
-  fxAccountsMock.internal.currentAccountState.getUserAccountData = async () => {
-    return { deviceId };
-  };
+  const fxAccountsMock = new FxAccounts({
+    newAccountState() {
+      return {
+        async getUserAccountData() {
+          return { deviceId };
+        }
+      }
+    },
+    signOut() {
+      signoutCalled = true;
+    }
+  });
 
   const deviceDisconnectedNotificationObserved = new Promise(resolve => {
     Services.obs.addObserver(function obs(subject, topic, data) {
       Services.obs.removeObserver(obs, topic);
       equal(data, JSON.stringify({ isLocalDevice: true }));
       resolve();
     }, ON_DEVICE_DISCONNECTED_NOTIFICATION);
   });
@@ -204,16 +213,17 @@ add_task(async function observePushTopic
   let pushService = new FxAccountsPushService({
     pushService: mockPushService,
     fxAccounts: fxAccountsMock,
   });
 
   pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
 
   await deviceDisconnectedNotificationObserved;
+  ok(signoutCalled);
 });
 
 add_task(async function observePushTopicDeviceDisconnected_another_device() {
   const deviceId = "bogusid";
   let msg = {
     data: {
       json: () => ({
         command: ON_DEVICE_DISCONNECTED_NOTIFICATION,
@@ -222,21 +232,30 @@ add_task(async function observePushTopic
         }
       })
     },
     QueryInterface() {
       return this;
     }
   };
 
+  let signoutCalled = false;
   let { FxAccounts } = Cu.import("resource://gre/modules/FxAccounts.jsm", {});
-  const fxAccountsMock = new FxAccounts({});
-  fxAccountsMock.internal.currentAccountState.getUserAccountData = async () => {
-    return { deviceId: "thelocaldevice" };
-  };
+  const fxAccountsMock = new FxAccounts({
+    newAccountState() {
+      return {
+        async getUserAccountData() {
+          return { deviceId: "thelocaldevice" };
+        }
+      }
+    },
+    signOut() {
+      signoutCalled = true;
+    }
+  });
 
   const deviceDisconnectedNotificationObserved = new Promise(resolve => {
     Services.obs.addObserver(function obs(subject, topic, data) {
       Services.obs.removeObserver(obs, topic);
       equal(data, JSON.stringify({ isLocalDevice: false }));
       resolve();
     }, ON_DEVICE_DISCONNECTED_NOTIFICATION);
   });
@@ -244,16 +263,17 @@ add_task(async function observePushTopic
   let pushService = new FxAccountsPushService({
     pushService: mockPushService,
     fxAccounts: fxAccountsMock,
   });
 
   pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
 
   await deviceDisconnectedNotificationObserved;
+  ok(!signoutCalled);
 });
 
 add_test(function observePushTopicAccountDestroyed() {
   const uid = "bogusuid";
   let msg = {
     data: {
       json: () => ({
         command: ON_ACCOUNT_DESTROYED_NOTIFICATION,