Bug 774178: make some changes to provider profile/notification handling to support "logout", r=gavin

--HG--
extra : transplant_source : %9A%EF0%AF%94l%3D%5D3%03%19/%14%E8%CF%8EI%F6%0B%80
This commit is contained in:
Shane Caraveo 2012-07-15 23:18:59 -07:00
parent 4ebd0f42f9
commit e76851b646
2 changed files with 27 additions and 0 deletions

View File

@ -90,11 +90,22 @@ SocialProvider.prototype = {
if (!profile.displayName)
profile.displayName = profile.userName;
// if no userName, consider this a logged out state, emtpy the
// users ambient notifications. notify both profile and ambient
// changes to clear everything
if (!profile.userName) {
this.profile = {};
this.ambientNotificationIcons = {};
Services.obs.notifyObservers(null, "social:ambient-notification-changed", this.origin);
}
Services.obs.notifyObservers(null, "social:profile-changed", this.origin);
},
// Called by the workerAPI to add/update a notification icon.
setAmbientNotification: function(notification) {
if (!this.profile.userName)
throw new Error("unable to set notifications while logged out");
this.ambientNotificationIcons[notification.name] = notification;
Services.obs.notifyObservers(null, "social:ambient-notification-changed", this.origin);

View File

@ -77,5 +77,21 @@ let tests = {
}
Services.obs.addObserver(ob, "social:ambient-notification-changed", false);
provider.workerAPI._port.postMessage({topic: "test-ambient", data: expect});
},
testProfileCleared: function(next) {
let sent = {
userName: ""
};
function ob(aSubject, aTopic, aData) {
Services.obs.removeObserver(ob, "social:profile-changed", false);
is(aData, provider.origin, "update of profile from our provider");
is(Object.keys(provider.profile).length, 0, "profile was cleared by empty username");
is(Object.keys(provider.ambientNotificationIcons).length, 0, "icons were cleared by empty username");
next();
}
Services.obs.addObserver(ob, "social:profile-changed", false);
provider.workerAPI._port.postMessage({topic: "test-profile", data: sent});
}
};