Skip to content

Commit

Permalink
Bug 1090859 - Fixing race condition between applications.ready and SI…
Browse files Browse the repository at this point in the history
…M dialog
  • Loading branch information
albertopq committed Dec 10, 2014
1 parent 5d6dd54 commit a58ab60
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
11 changes: 10 additions & 1 deletion apps/system/js/sim_lock.js
Expand Up @@ -183,6 +183,15 @@ var SimLock = {
},

showIfLocked: function sl_showIfLocked(currentSlotIndex, skipped) {
var self = this;
if (!applications.ready) {
window.addEventListener('applicationready', function onReady() {
window.removeEventListener('applicationready', onReady);
self.showIfLocked(currentSlotIndex, skipped);
});
return false;
}

if (System.locked)
return false;

Expand Down Expand Up @@ -214,7 +223,7 @@ var SimLock = {
}

// Always showing the first slot first.
if (!this._alreadyShown && index > 1) {
if (!this._alreadyShown && index > 0) {
return false;
}

Expand Down
31 changes: 21 additions & 10 deletions apps/system/js/simcard_dialog.js
@@ -1,6 +1,6 @@
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* global SIMSlotManager, SimPinSystemDialog */
/* global SIMSlotManager, SimPinSystemDialog, applications */

'use strict';

Expand Down Expand Up @@ -291,7 +291,7 @@ var SimPinDialog = {
this._currentSlot = slot;
}

window.dispatchEvent(new CustomEvent('simpinshow'));
this._dispatchEvent('simpinshow');

this.simPinSystemDialog.show();
this._visible = true;
Expand All @@ -313,32 +313,32 @@ var SimPinDialog = {
},

requestClose: function spl_requestClose(reason) {
window.dispatchEvent(new CustomEvent('simpinrequestclose', {
this._dispatchEvent('simpinrequestclose', {
detail: {
dialog: this,
reason: reason
}
}));
});
},

close: function spl_close(reason) {
window.dispatchEvent(new CustomEvent('simpinclose', {
this._dispatchEvent('simpinclose', {
detail: this
}));
});
this.simPinSystemDialog.hide(reason);
this._visible = false;
},

skip: function spl_skip() {
window.dispatchEvent(new CustomEvent('simpinskip', {
this._dispatchEvent('simpinskip', {
detail: this
}));
});
},

back: function spl_back() {
window.dispatchEvent(new CustomEvent('simpinback', {
this._dispatchEvent('simpinback', {
detail: this
}));
});
},

// With the keyboard active the inputs, ensure they get scrolled
Expand All @@ -354,6 +354,17 @@ var SimPinDialog = {
});
},

_dispatchEvent: function spl_dispatchEvent(name, detail) {
if (applications.ready) {
window.dispatchEvent(new CustomEvent(name, detail));
} else {
window.addEventListener('applicationready', function onReady() {
window.removeEventListener('applicationready', onReady);
window.dispatchEvent(new CustomEvent(name, detail));
});
}
},

init: function spl_init() {
if (!this.simPinSystemDialog) {
this.simPinSystemDialog = new SimPinSystemDialog({
Expand Down
13 changes: 12 additions & 1 deletion apps/system/test/unit/sim_lock_test.js
@@ -1,13 +1,14 @@
/* global SimLock, MockL10n, MocksHelper, SimPinDialog, System */
/* global MockSIMSlotManager, MockVersionHelper, FtuLauncher */
/* global preInit, VersionHelper:true */
/* global preInit, VersionHelper:true, MockApplications */

'use strict';

requireApp('system/shared/test/unit/mocks/mock_simslot_manager.js');
requireApp('system/test/unit/mock_simcard_dialog.js');
require('/shared/test/unit/mocks/mock_l10n.js');
require('/shared/test/unit/mocks/mock_system.js');
requireApp('system/test/unit/mock_applications.js');
requireApp('system/test/unit/mock_version_helper.js');
requireApp('system/js/ftu_launcher.js');

Expand Down Expand Up @@ -53,6 +54,8 @@ suite('SimLock', function() {
setup(function() {
// inject one instance
addSimSlot();
window.applications = MockApplications;
window.applications.ready = true;
this.sinon.stub(SimPinDialog, 'show', function() {
SimPinDialog.visible = true;
});
Expand Down Expand Up @@ -199,6 +202,14 @@ suite('SimLock', function() {
assert.isTrue(SimLock._alreadyShown);
});


test('should do nothing if !applications.ready', function() {
window.applications.ready = false;
SimLock.showIfLocked();
assert.isFalse(SimPinDialog.show.called);
window.applications.ready = true;
});

test('should not show if locked', function() {
System.locked = true;
SimLock.showIfLocked();
Expand Down
5 changes: 4 additions & 1 deletion apps/system/test/unit/simcard_dialog_test.js
@@ -1,9 +1,10 @@
/* globals MockL10n, MocksHelper, MockSIMSlot, MockSIMSlotManager,
SimPinDialog */
SimPinDialog, MockApplications */
'use strict';

require('/shared/test/unit/mocks/mock_l10n.js');
requireApp('system//shared/test/unit/mocks/mock_simslot.js');
requireApp('system/test/unit/mock_applications.js');
requireApp('system//shared/test/unit/mocks/mock_simslot_manager.js');

var mocksForSIMPINDialog = new MocksHelper([
Expand Down Expand Up @@ -39,6 +40,8 @@ suite('simcard dialog', function() {
stubById = this.sinon.stub(document, 'getElementById');
stubById.returns(document.createElement('div'));
MockSIMSlotManager.mInstances = [new MockSIMSlot(null, 0)];
window.applications = MockApplications;
window.applications.ready = true;
requireApp('system/js/simcard_dialog.js', function() {
SimPinDialog.init();
callback();
Expand Down

0 comments on commit a58ab60

Please sign in to comment.