Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 1090859 - Fixing race condition between applications.ready and SIM dialog #26671

Merged
merged 1 commit into from
Dec 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/system/js/sim_lock.js
Original file line number Diff line number Diff line change
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
31 changes: 21 additions & 10 deletions apps/system/js/simcard_dialog.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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