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

Commit

Permalink
Merge pull request #20542 from snowmantw/issue1025723
Browse files Browse the repository at this point in the history
Bug 1025723 - [LockScreen][System] Change the old locking events with new window events
  • Loading branch information
snowmantw committed Jun 18, 2014
2 parents b58c6d2 + 4321c4c commit 16bfd49
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
8 changes: 4 additions & 4 deletions apps/system/js/nfc_manager.js
Expand Up @@ -60,8 +60,8 @@ var NfcManager = {
'nfc-manager-tech-lost',
this.handleTechLost.bind(this));
window.addEventListener('screenchange', this);
window.addEventListener('lock', this);
window.addEventListener('unlock', this);
window.addEventListener('lockscreen-appopened', this);
window.addEventListener('lockscreen-appclosed', this);
var self = this;
window.SettingsListener.observe('nfc.enabled', false, function(enabled) {
var state = enabled ?
Expand Down Expand Up @@ -124,8 +124,8 @@ var NfcManager = {
handleEvent: function nm_handleEvent(evt) {
var state;
switch (evt.type) {
case 'lock': // Fall through
case 'unlock':
case 'lockscreen-appopened': // Fall through
case 'lockscreen-appclosed':
case 'screenchange':
if (this.hwState == this.NFC_HW_STATE_OFF) {
return;
Expand Down
3 changes: 2 additions & 1 deletion apps/system/js/notifications.js
Expand Up @@ -82,7 +82,8 @@ var NotificationScreen = {
this.externalNotificationsCount = 0;

window.addEventListener('utilitytrayshow', this);
window.addEventListener('unlock', this.clearLockScreen.bind(this));
window.addEventListener('lockscreen-appclosed',
this.clearLockScreen.bind(this));
window.addEventListener('visibilitychange', this);
window.addEventListener('ftuopen', this);
window.addEventListener('ftudone', this);
Expand Down
6 changes: 3 additions & 3 deletions apps/system/js/screen_manager.js
Expand Up @@ -294,9 +294,9 @@ var ScreenManager = {
this._cpuWakeLock = navigator.requestWakeLock('cpu');
window.addEventListener('userproximity', this);
break;
case 'will-unlock' :
case 'lockscreen-appclosing' :
case 'lockpanelchange' :
window.removeEventListener('will-unlock', this);
window.removeEventListener('lockscreen-appclosing', this);
window.removeEventListener('lockpanelchange', this);
this._setIdleTimeout(this._idleTimeout, false);
break;
Expand Down Expand Up @@ -346,7 +346,7 @@ var ScreenManager = {
if (self._deviceLightEnabled)
window.removeEventListener('devicelight', self);

window.removeEventListener('will-unlock', self);
window.removeEventListener('lockscreen-appclosing', self);
window.removeEventListener('lockpanelchange', self);
self.screenEnabled = false;
self._inTransition = false;
Expand Down
14 changes: 7 additions & 7 deletions apps/system/js/statusbar.js
Expand Up @@ -242,11 +242,11 @@ var StatusBar = {
// Listen to 'moztimechange'
window.addEventListener('moztimechange', this);

// Listen to 'lock', 'unlock', and 'lockpanelchange' from lockscreen.js in
// order to correctly set the visibility of the statusbar clock depending
// on the active lockscreen panel
window.addEventListener('lock', this);
window.addEventListener('unlock', this);
// Listen to 'lockscreen-appopened', 'lockscreen-appclosed', and
// 'lockpanelchange' in order to correctly set the visibility of
// the statusbar clock depending on the active lockscreen panel
window.addEventListener('lockscreen-appopened', this);
window.addEventListener('lockscreen-appclosed', this);
window.addEventListener('lockpanelchange', this);

window.addEventListener('appopened', this);
Expand Down Expand Up @@ -281,7 +281,7 @@ var StatusBar = {
this.setActive(evt.detail.screenEnabled);
break;

case 'lock':
case 'lockscreen-appopened':
// Hide the clock in the statusbar when screen is locked
//
// It seems no need to detect the locked value because
Expand All @@ -290,7 +290,7 @@ var StatusBar = {
this.toggleTimeLabel(false);
break;

case 'unlock':
case 'lockscreen-appclosed':
// Display the clock in the statusbar when screen is unlocked
this.toggleTimeLabel(true);
break;
Expand Down
8 changes: 4 additions & 4 deletions apps/system/js/storage.js
Expand Up @@ -13,8 +13,8 @@
function Storage() {
// Disable ums by default
this.setMode(this.automounterDisable);
window.addEventListener('lock', this);
window.addEventListener('unlock', this);
window.addEventListener('lockscreen-appopened', this);
window.addEventListener('lockscreen-appclosed', this);

SettingsListener.observe(this.umsEnabled, false, function umsChanged(val) {
this._mode = this.modeFromBool(val);
Expand Down Expand Up @@ -102,11 +102,11 @@
*/
handleEvent: function(e) {
switch (e.type) {
case 'lock':
case 'lockscreen-appopened':
// Setting mode due to screen locked
this.setMode(this.automounterDisableWhenUnplugged);
break;
case 'unlock':
case 'lockscreen-appclosed':
if (typeof(this._mode) == 'undefined') {
return;
}
Expand Down
21 changes: 12 additions & 9 deletions apps/system/test/unit/nfc_manager_test.js
Expand Up @@ -64,16 +64,19 @@ suite('Nfc Manager Functions', function() {
assert.isTrue(stubHandleTechLost.calledOnce);
});

test('NfcManager listens on screenchange, lock, unlock events', function() {
test('NfcManager listens on screenchange, and the locking events',
function() {
var stubHandleEvent = this.sinon.stub(NfcManager, 'handleEvent');

window.dispatchEvent(new CustomEvent('lock'));
window.dispatchEvent(new CustomEvent('lockscreen-appopened'));
assert.isTrue(stubHandleEvent.calledOnce);
assert.equal(stubHandleEvent.getCall(0).args[0].type, 'lock');
assert.equal(stubHandleEvent.getCall(0).args[0].type,
'lockscreen-appopened');

window.dispatchEvent(new CustomEvent('unlock'));
window.dispatchEvent(new CustomEvent('lockscreen-appclosed'));
assert.isTrue(stubHandleEvent.calledTwice);
assert.equal(stubHandleEvent.getCall(1).args[0].type, 'unlock');
assert.equal(stubHandleEvent.getCall(1).args[0].type,
'lockscreen-appclosed');

window.dispatchEvent(new CustomEvent('screenchange'));
assert.isTrue(stubHandleEvent.calledThrice);
Expand Down Expand Up @@ -111,7 +114,7 @@ suite('Nfc Manager Functions', function() {
// screen lock when NFC ON
NfcManager.hwState = NfcManager.NFC_HW_STATE_ON;
window.MockLockScreen.lock();
NfcManager.handleEvent(new CustomEvent('lock'));
NfcManager.handleEvent(new CustomEvent('lockscreen-appopened'));
assert.isTrue(stubChangeHardwareState.calledOnce);
assert.equal(stubChangeHardwareState.getCall(0).args[0],
NfcManager.NFC_HW_STATE_DISABLE_DISCOVERY);
Expand All @@ -123,15 +126,15 @@ suite('Nfc Manager Functions', function() {

// screen unlock
window.MockLockScreen.unlock();
NfcManager.handleEvent(new CustomEvent('unlock'));
NfcManager.handleEvent(new CustomEvent('lockscreen-appclosed'));
assert.isTrue(stubChangeHardwareState.calledTwice);
assert.equal(stubChangeHardwareState.getCall(1).args[0],
NfcManager.NFC_HW_STATE_ENABLE_DISCOVERY);

// NFC off
NfcManager.hwState = NfcManager.NFC_HW_STATE_OFF;
NfcManager.handleEvent(new CustomEvent('lock'));
NfcManager.handleEvent(new CustomEvent('unlock'));
NfcManager.handleEvent(new CustomEvent('lockscreen-appopened'));
NfcManager.handleEvent(new CustomEvent('lockscreen-appclosed'));
NfcManager.handleEvent(new CustomEvent('screenchange'));
assert.isTrue(stubChangeHardwareState.calledTwice);
});
Expand Down
4 changes: 2 additions & 2 deletions apps/system/test/unit/statusbar_test.js
Expand Up @@ -208,13 +208,13 @@ suite('system/Statusbar', function() {
});
test('lock', function() {
MockLockScreen.locked = true;
var evt = new CustomEvent('lock');
var evt = new CustomEvent('lockscreen-appopened');
StatusBar.handleEvent(evt);
assert.equal(StatusBar.clock.timeoutID, null);
assert.equal(StatusBar.icons.time.hidden, true);
});
test('unlock', function() {
var evt = new CustomEvent('unlock');
var evt = new CustomEvent('lockscreen-appclosed');
StatusBar.handleEvent(evt);
assert.notEqual(StatusBar.clock.timeoutID, null);
assert.equal(StatusBar.icons.time.hidden, false);
Expand Down
4 changes: 2 additions & 2 deletions apps/system/test/unit/storage_test.js
Expand Up @@ -73,7 +73,7 @@ suite('system/Storage', function() {
test('lock calls setMode', function() {
var setModeStub = this.sinon.stub(Storage.prototype, 'setMode');
subject.handleEvent({
type: 'lock'
type: 'lockscreen-appopened'
});
assert.ok(setModeStub.calledWith(2));
});
Expand All @@ -83,7 +83,7 @@ suite('system/Storage', function() {
subject._mode = 3;
var setModeStub = this.sinon.stub(Storage.prototype, 'setMode');
subject.handleEvent({
type: 'unlock'
type: 'lockscreen-appclosed'
});
assert.ok(setModeStub.calledWith(3));
});
Expand Down

0 comments on commit 16bfd49

Please sign in to comment.