Bug 1157712 - Fix multiple OS X notifications when someone joins a Loop room. Ensure we don't attempt to re-initialise twice. r=mikedeboer

This commit is contained in:
Mark Banner 2015-05-22 14:45:13 +01:00
Родитель 2cf8e6853f
Коммит 1307e179d1
4 изменённых файлов: 41 добавлений и 1 удалений

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

@ -218,7 +218,15 @@ let LoopUI;
// Add observer notifications before the service is initialized // Add observer notifications before the service is initialized
Services.obs.addObserver(this, "loop-status-changed", false); Services.obs.addObserver(this, "loop-status-changed", false);
this.MozLoopService.initialize(); // This is a promise for test purposes, but we don't want to be logging
// expected errors to the console, so we catch them here.
this.MozLoopService.initialize().catch(ex => {
if (!ex.message ||
(!ex.message.contains("not enabled") &&
!ex.message.contains("not needed"))) {
console.error(ex);
}
});
this.updateToolbarState(); this.updateToolbarState();
}, },

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

@ -1072,6 +1072,7 @@ let gInitializeTimerFunc = (deferredInitialization) => {
MozLoopServiceInternal.initialRegistrationDelayMilliseconds); MozLoopServiceInternal.initialRegistrationDelayMilliseconds);
}; };
let gServiceInitialized = false;
/** /**
* Public API * Public API
@ -1089,10 +1090,21 @@ this.MozLoopService = {
}; };
}, },
/**
* Used to override the initalize timer function for test purposes.
*/
set initializeTimerFunc(value) { set initializeTimerFunc(value) {
gInitializeTimerFunc = value; gInitializeTimerFunc = value;
}, },
/**
* Used to reset if the service has been initialized or not - for test
* purposes.
*/
resetServiceInitialized: function() {
gServiceInitialized = false;
},
get roomsParticipantsCount() { get roomsParticipantsCount() {
return LoopRooms.participantsCount; return LoopRooms.participantsCount;
}, },
@ -1101,9 +1113,18 @@ this.MozLoopService = {
* Initialized the loop service, and starts registration with the * Initialized the loop service, and starts registration with the
* push and loop servers. * push and loop servers.
* *
* Note: this returns a promise for unit test purposes.
*
* @return {Promise} * @return {Promise}
*/ */
initialize: Task.async(function*() { initialize: Task.async(function*() {
// Ensure we don't setup things like listeners more than once.
if (gServiceInitialized) {
return Promise.resolve();
}
gServiceInitialized = true;
// Do this here, rather than immediately after definition, so that we can // Do this here, rather than immediately after definition, so that we can
// stub out API functions for unit testing // stub out API functions for unit testing
Object.freeze(this); Object.freeze(this);

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

@ -40,11 +40,19 @@ add_task(function test_initialize_no_guest_rooms() {
add_task(function test_initialize_with_guest_rooms() { add_task(function test_initialize_with_guest_rooms() {
Services.prefs.setBoolPref("loop.createdRoom", true); Services.prefs.setBoolPref("loop.createdRoom", true);
startTimerCalled = false; startTimerCalled = false;
MozLoopService.resetServiceInitialized();
MozLoopService.initialize(); MozLoopService.initialize();
Assert.equal(startTimerCalled, true, Assert.equal(startTimerCalled, true,
"should start the timer when guest rooms have been created"); "should start the timer when guest rooms have been created");
startTimerCalled = false;
MozLoopService.initialize();
Assert.equal(startTimerCalled, false,
"should not have initialized a second time");
}); });
function run_test() { function run_test() {

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

@ -39,6 +39,7 @@ add_task(function* test_initialize_with_no_guest_rooms_and_no_auth_token() {
add_task(function* test_initialize_with_created_room_and_no_auth_token() { add_task(function* test_initialize_with_created_room_and_no_auth_token() {
Services.prefs.setBoolPref(LOOP_CREATED_ROOM_PREF, true); Services.prefs.setBoolPref(LOOP_CREATED_ROOM_PREF, true);
Services.prefs.clearUserPref(LOOP_FXA_TOKEN_PREF); Services.prefs.clearUserPref(LOOP_FXA_TOKEN_PREF);
MozLoopService.resetServiceInitialized();
loopServer.registerPathHandler("/registration", (request, response) => { loopServer.registerPathHandler("/registration", (request, response) => {
response.setStatusLine(null, 200, "OK"); response.setStatusLine(null, 200, "OK");
@ -55,6 +56,7 @@ add_task(function* test_initialize_with_created_room_and_no_auth_token() {
add_task(function* test_initialize_with_invalid_fxa_token() { add_task(function* test_initialize_with_invalid_fxa_token() {
Services.prefs.setCharPref(LOOP_FXA_PROFILE_PREF, FAKE_FXA_PROFILE); Services.prefs.setCharPref(LOOP_FXA_PROFILE_PREF, FAKE_FXA_PROFILE);
Services.prefs.setCharPref(LOOP_FXA_TOKEN_PREF, FAKE_FXA_TOKEN_DATA); Services.prefs.setCharPref(LOOP_FXA_TOKEN_PREF, FAKE_FXA_TOKEN_DATA);
MozLoopService.resetServiceInitialized();
// Only need to implement the FxA registration because the previous // Only need to implement the FxA registration because the previous
// test registered as a guest. // test registered as a guest.
@ -88,6 +90,7 @@ add_task(function* test_initialize_with_invalid_fxa_token() {
add_task(function* test_initialize_with_fxa_token() { add_task(function* test_initialize_with_fxa_token() {
Services.prefs.setCharPref(LOOP_FXA_PROFILE_PREF, FAKE_FXA_PROFILE); Services.prefs.setCharPref(LOOP_FXA_PROFILE_PREF, FAKE_FXA_PROFILE);
Services.prefs.setCharPref(LOOP_FXA_TOKEN_PREF, FAKE_FXA_TOKEN_DATA); Services.prefs.setCharPref(LOOP_FXA_TOKEN_PREF, FAKE_FXA_TOKEN_DATA);
MozLoopService.resetServiceInitialized();
MozLoopService.errors.clear(); MozLoopService.errors.clear();