Bug 1401590 - Mock FxAccounts#newAccountState in push service tests. r?markh
MozReview-Commit-ID: 8kVtWbPKp65
--- 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,