Bug 1401590 - Mock FxAccounts#newAccountState in push service tests. r=markh

MozReview-Commit-ID: 8kVtWbPKp65

--HG--
extra : rebase_source : cb970e68e7be85ea53723207b91c7981b84d41a4
This commit is contained in:
Edouard Oger 2017-09-21 13:27:46 -04:00
parent 4efc440d90
commit 27eb845182

View File

@ -187,11 +187,20 @@ add_task(async function observePushTopicDeviceDisconnected_current_device() {
}
};
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) {
@ -209,6 +218,7 @@ add_task(async function observePushTopicDeviceDisconnected_current_device() {
pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
await deviceDisconnectedNotificationObserved;
ok(signoutCalled);
});
add_task(async function observePushTopicDeviceDisconnected_another_device() {
@ -227,11 +237,20 @@ add_task(async function observePushTopicDeviceDisconnected_another_device() {
}
};
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) {
@ -249,6 +268,7 @@ add_task(async function observePushTopicDeviceDisconnected_another_device() {
pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
await deviceDisconnectedNotificationObserved;
ok(!signoutCalled);
});
add_test(function observePushTopicAccountDestroyed() {