From e76851b646b17724b9a57876f2bae1133f496b92 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Sun, 15 Jul 2012 23:18:59 -0700 Subject: [PATCH] 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 --- toolkit/components/social/SocialProvider.jsm | 11 +++++++++++ .../social/test/browser/browser_workerAPI.js | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/toolkit/components/social/SocialProvider.jsm b/toolkit/components/social/SocialProvider.jsm index 20e89c96bc31..d8bfd745a299 100644 --- a/toolkit/components/social/SocialProvider.jsm +++ b/toolkit/components/social/SocialProvider.jsm @@ -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); diff --git a/toolkit/components/social/test/browser/browser_workerAPI.js b/toolkit/components/social/test/browser/browser_workerAPI.js index 8c42086c98fa..935aa3760b6b 100644 --- a/toolkit/components/social/test/browser/browser_workerAPI.js +++ b/toolkit/components/social/test/browser/browser_workerAPI.js @@ -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}); } };