Bug 1401590 - Mock FxAccounts#newAccountState in push service tests. r=markh
authorEdouard Oger <eoger@fastmail.com>
Thu, 21 Sep 2017 13:27:46 -0400
changeset 668887 97282b0c985aa1778ced171514d1ae61945c634c
parent 668886 47f15c732421cedfdf82b8799c89942caf57c655
child 668889 0b39d5cbf3d1cf23fc162fb8b4e9261cbb3d6521
child 668897 2498c1b2376eb27a16fc1f9a090a991ea0669bb8
child 668916 5d4a9fa3b788e67f2c2dca7d1ba4859642e1a1f2
child 668918 2bf248c7a4b1f0e8554ff73a65f132a8f3231f6a
child 668923 41ed2fee97d14e6c9dda177f8cef7778527ed39a
child 668963 ca0035f296fe759a1c048036353c710d2bee85fc
child 668979 07b8896a8f3be39706b80c407193aea0c8e2cf4c
child 668987 a2a8d07ec9090e709a3b44fac04fda0b1a0a86a4
child 668996 fb23ec3c896e3d02d8db1ea76487af2c06e39d95
child 669036 3a9d992b9ef2ca7d20f1f1f0dd9177cc758898b5
child 669040 e7e365f05d0cadb5040a9560c81b68f1331622d6
child 669169 ca1f71034d1f1e3b302a961019f43d72783af8f3
child 669188 1ef7299347a6aab3f4efe823ad1605ee7027915a
child 669253 2cc441e17f13a5169a4ac872bea024a6c66009af
child 669258 4cf77ab73dccbf6e832c4c606d260f78aae9f133
child 669277 8c3b356b64f9c331c5778f086b072f56ae9e9f6c
child 669455 1efb1ad2838bca864204caa76c6119905e15afef
child 669672 97fd20e19ed3c7ebe2aadc60deb4e47932f889aa
child 669675 1e0c5acfe28eb93c64b67fb824daf35725c93616
child 669854 95321cd9a93bf0ba8170e93d30d799b4c3d8961f
child 669878 a39a74185feaaa80052b319275de9ca8ec2349d5
child 670126 5f8c2b1b88bfe9c26ac04a791733131ee13cf184
child 670146 ebae77baf4547ba74b5ca20832697e79b620b345
child 670267 4843facf070144a24ecf9436d5263d2a5c766af4
push id81146
push userbmo:topwu.tw@gmail.com
push dateFri, 22 Sep 2017 05:24:51 +0000
reviewersmarkh
bugs1401590
milestone58.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,