Bug 1277026 - Handle FxA push payloads. r=kitcambridge

MozReview-Commit-ID: Cd6nKHP2VQi

--HG--
extra : rebase_source : 05d6879df14f85f9f60ed78386f21b8c7fd6c575
This commit is contained in:
Edouard Oger 2016-06-02 15:21:08 -07:00
Родитель 1625710c42
Коммит 0c9fbf6f6c
2 изменённых файлов: 46 добавлений и 37 удалений

Просмотреть файл

@ -119,7 +119,8 @@ FxAccountsPushService.prototype = {
switch (topic) {
case this.pushService.pushTopic:
if (data === FXA_PUSH_SCOPE_ACCOUNT_UPDATE) {
this._onPushMessage();
let message = subject.QueryInterface(Ci.nsIPushMessage);
this._onPushMessage(message);
}
break;
case this.pushService.subscriptionChangeTopic:
@ -142,10 +143,18 @@ FxAccountsPushService.prototype = {
*
* @private
*/
_onPushMessage() {
_onPushMessage(message) {
this.log.trace("FxAccountsPushService _onPushMessage");
// Use this signal to check the verification state of the account right away
if (!message.data) {
// Use the empty signal to check the verification state of the account right away
this.fxAccounts.checkVerificationStatus();
return;
}
let payload = message.data.json();
switch (payload.command) {
default:
this.log.warn("FxA Push command unrecognized: " + payload.command);
}
},
/**
* Fired when the Push server drops a subscription, or the subscription identifier changes.

Просмотреть файл

@ -49,7 +49,7 @@ let mockLog = {
add_task(function* initialize() {
let pushService = new FxAccountsPushService();
do_check_eq(pushService.initialize(), false);
equal(pushService.initialize(), false);
});
add_task(function* registerPushEndpointSuccess() {
@ -59,7 +59,7 @@ add_task(function* registerPushEndpointSuccess() {
});
let subscription = yield pushService.registerPushEndpoint();
do_check_eq(subscription.endpoint, MOCK_ENDPOINT);
equal(subscription.endpoint, MOCK_ENDPOINT);
});
add_task(function* registerPushEndpointFailure() {
@ -75,7 +75,7 @@ add_task(function* registerPushEndpointFailure() {
});
let subscription = yield pushService.registerPushEndpoint();
do_check_eq(subscription, null);
equal(subscription, null);
});
add_task(function* unsubscribeSuccess() {
@ -85,7 +85,7 @@ add_task(function* unsubscribeSuccess() {
});
let result = yield pushService.unsubscribe();
do_check_eq(result, true);
equal(result, true);
});
add_task(function* unsubscribeFailure() {
@ -101,7 +101,7 @@ add_task(function* unsubscribeFailure() {
});
let result = yield pushService.unsubscribe();
do_check_eq(result, null);
equal(result, null);
});
add_test(function observeLogout() {
@ -122,10 +122,15 @@ add_test(function observeLogout() {
pushService.observe(null, ONLOGOUT_NOTIFICATION);
});
add_test(function observePushTopic() {
add_test(function observePushTopicVerify() {
let emptyMsg = {
QueryInterface: function() {
return this;
}
};
let customAccounts = Object.assign(mockFxAccounts, {
checkVerificationStatus: function () {
// checking verification status on push messages
// checking verification status on push messages without data
run_next_test();
}
});
@ -135,7 +140,7 @@ add_test(function observePushTopic() {
fxAccounts: customAccounts,
});
pushService.observe(null, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
pushService.observe(emptyMsg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
});
add_test(function observeSubscriptionChangeTopic() {
@ -153,8 +158,3 @@ add_test(function observeSubscriptionChangeTopic() {
pushService.observe(null, mockPushService.subscriptionChangeTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
});
function run_test() {
run_next_test();
}