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 #31226 from snowmantw/bug1189455-rev2
Browse files Browse the repository at this point in the history
Bug 1189455 - fix regression of Bug 1173284 to let passcode timeout  work well. r=timdream
  • Loading branch information
BavarianTomcat committed Aug 6, 2015
2 parents 2a3160f + 389cd0e commit a8d618f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 78 deletions.
31 changes: 25 additions & 6 deletions apps/system/lockscreen/js/lockscreen_state_manager.js
Expand Up @@ -15,7 +15,7 @@
*/

/* global SettingsListener */
/* global LockScreenStateSlideShow, LockScreenStateSlideHide */
/* global LockScreenStateSlideShow */
/* global LockScreenStateKeypadShow */
/* global LockScreenStateKeypadHiding, LockScreenStateKeypadRising */
/* global LockScreenStatePanelHide */
Expand Down Expand Up @@ -108,7 +108,6 @@
this.states = {
slideRestore: (new LockScreenStateSlideRestore()).start(this.lockScreen),
slideShow: (new LockScreenStateSlideShow()).start(this.lockScreen),
slideHide: (new LockScreenStateSlideHide()).start(this.lockScreen),
keypadShow: (new LockScreenStateKeypadShow()).start(this.lockScreen),
keypadHiding: (new LockScreenStateKeypadHiding()).start(this.lockScreen),
keypadRising: (new LockScreenStateKeypadRising()).start(this.lockScreen),
Expand Down Expand Up @@ -187,7 +186,7 @@
screenOn: true,
unlocking: false
},
['panelHide', 'slideHide', 'unlock'],
['panelHide', 'unlock'],
this.states.slideShow,
'Resume from screen off');

Expand All @@ -207,7 +206,7 @@
activateUnlock: true
},
['slideShow'],
this.states.slideHide,
this.states.unlock,
'When it activate to unlock with unexpired passcode, unlock and animates.');

this.registerRule({
Expand Down Expand Up @@ -300,12 +299,22 @@

this.registerRule({
unlockingAppActivated: true,
passcodeEnabled: true
passcodeEnabled: true,
passcodeTimeout: true
},
['slideShow'],
this.states.secureAppLaunching,
'When user invoke secure app, move to the mode');

this.registerRule({
unlockingAppActivated: true,
passcodeEnabled: true,
passcodeTimeout: false
},
['slideShow'],
this.states.unlock,
'When user invoke ordinary app without expired timeout, unlock it.');

this.registerRule({
secureAppClose: true
},
Expand Down Expand Up @@ -610,6 +619,9 @@

LockScreenStateManager.prototype.onUnlockingApp =
function lssm_onUnlockingApp() {
// Check if it should launch secure app or not.
this.lockScreenStates.passcodeTimeout =
this.lockScreen.checkPassCodeTimeout();
var inputs = this.extend(this.lockScreenStates, {
unlockingAppActivated: true
});
Expand Down Expand Up @@ -660,7 +672,14 @@
if (this.lockScreenStates.passcodeEnabled instanceof
LockScreenStateManager.Deferred) {
// So those waiting the promise can go on.
this.lockScreenStates.passcodeEnabled.resolve(val);
var resolve = this.lockScreenStates.passcodeEnabled.resolve;
// Remember: inputs of this transition request is NOT what
// the manager keeps. This is due to some request, like pressing homekey,
// is a one-time event, and will not update the inner states table.
// So if an event is changing the inner states table, we need to
// toggle the value here, not in the resolver of postponed request.
this.lockScreenStates.passcodeEnabled = val;
resolve(val);
} else {
this.lockScreenStates.passcodeEnabled = val;
}
Expand Down
44 changes: 0 additions & 44 deletions apps/system/lockscreen/js/lockscreen_state_slidehide.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/system/lockscreen/lockscreen.html
Expand Up @@ -38,7 +38,6 @@
<script defer src="lockscreen/js/lockscreen_state_panelhide.js"></script>
<script defer src="lockscreen/js/lockscreen_state_sliderestore.js"></script>
<script defer src="lockscreen/js/lockscreen_state_slideshow.js"></script>
<script defer src="lockscreen/js/lockscreen_state_slidehide.js"></script>
<script defer src="lockscreen/js/lockscreen_state_unlock.js"></script>
<script defer src="lockscreen/js/lockscreen_state_secure_app_launching.js"></script>
<script defer src="lockscreen/js/lockscreen_state_logger.js"></script>
Expand Down
64 changes: 57 additions & 7 deletions apps/system/test/unit/lockscreen/lockscreen_state_manager_test.js
Expand Up @@ -38,7 +38,6 @@ suite('system/LockScreenStateManager', function() {

window.LockScreenBaseState = genMock('base');
window.LockScreenStateSlideShow = genMock('slideShow');
window.LockScreenStateSlideHide = genMock('slideHide');
window.LockScreenStateUnlock = genMock('slideUnlock');
window.LockScreenStateSlideRestore = genMock('slideRestore');
window.LockScreenStatePanelHide = genMock('panelHide');
Expand Down Expand Up @@ -72,6 +71,27 @@ suite('system/LockScreenStateManager', function() {
});

suite('self-test all methods: ', function() {
test('|onPasscodeEnabledChanged| can handle delay request well',
function(done) {
var method = LockScreenStateManager.prototype.onPasscodeEnabledChanged;
var mockThis = {
lockScreenStates: {
passcodeEnabled: new LockScreenStateManager.Deferred()
}
};
mockThis.lockScreenStates.passcodeEnabled.promise.then((val) => {
assert.equal(false, val,
'The delay request can\'t get the reading value');
done();
}).catch(done);
method.call(mockThis, false);
assert.isFalse(mockThis.lockScreenStates.passcodeEnabled instanceof
LockScreenStateManager.Deferred,
'it doesn\'t replace the delay request with the read value');
assert.equal(false, mockThis.lockScreenStates.passcodeEnabled,
'it doesn\'t replace the delay request with the read value');
});

test('|resolveInnerStates| would wait all states with promises',
function(done) {
var method = LockScreenStateManager.prototype.resolveInnerStates;
Expand Down Expand Up @@ -230,12 +250,12 @@ suite('system/LockScreenStateManager', function() {
test('With passcode enabled but not expired, when it activate to unlock, ' +
'unlock directly',
function(done) {
this.sinon.stub(subject.states.slideHide, 'transferTo',
this.sinon.stub(subject.states.unlock, 'transferTo',
function() {
// This would be the next step of 'transferOut'.
try {
assert.isTrue(transferOutCalled,
'the state wasn\'t transferred from slideShow to slideHide');
'the state wasn\'t transferred from slideShow to unlock');
} catch(e) {
done(e);
}
Expand Down Expand Up @@ -284,14 +304,14 @@ suite('system/LockScreenStateManager', function() {
subject.transfer(states).catch(done);
});

test('Resume from screen off (from slideHide)',
test('Resume from screen off (from panelHide)',
function(done) {
this.sinon.stub(subject.states.slideShow, 'transferTo',
function() {
// This would be the next step of 'transferOut'.
try {
assert.isTrue(transferOutCalled,
'the state wasn\'t transferred from slideHide to slideShow');
'the state wasn\'t transferred from panelHide to slideShow');
} catch(e) {
done(e);
}
Expand All @@ -306,7 +326,7 @@ suite('system/LockScreenStateManager', function() {
transferOut: this.sinon.stub().returns(Promise.resolve().then(() => {
transferOutCalled = true;
})),
type: 'slideHide'
type: 'panelHide'
};
subject.transfer(states).catch(done);
});
Expand Down Expand Up @@ -508,7 +528,37 @@ suite('system/LockScreenStateManager', function() {
});
var states = subject.extend(subject.lockScreenDefaultStates, {
unlockingAppActivated: true,
passcodeEnabled: true
passcodeEnabled: true,
passcodeTimeout: true
});
var transferOutCalled = false;
subject.previousState = {
transferOut: this.sinon.stub().returns(Promise.resolve().then(() => {
transferOutCalled = true;
})),
type: 'slideShow'
};
subject.transfer(states).catch(done);
});

test('When user unlocks to app with an expired timeout, unlock it',
function(done) {
this.sinon.stub(subject.states.unlock, 'transferTo',
function() {
// This would be the next step of 'transferOut'.
try {
assert.isTrue(transferOutCalled,
'the state wasn\'t transferred from ' +
'slideShow to unlock');
} catch(e) {
done(e);
}
done();
});
var states = subject.extend(subject.lockScreenDefaultStates, {
unlockingAppActivated: true,
passcodeEnabled: true,
passcodeTimeout: false
});
var transferOutCalled = false;
subject.previousState = {
Expand Down

This file was deleted.

0 comments on commit a8d618f

Please sign in to comment.