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 #21881 from cctuan/1035453-v2.0
Browse files Browse the repository at this point in the history
Bug 1035453 - [B2G][Camera] Pressing home does not function in the lockscreen camera with passcode lock enabled
  • Loading branch information
cctuan committed Jul 18, 2014
2 parents 8a8622d + faeef73 commit b60d953
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 78 deletions.
66 changes: 7 additions & 59 deletions apps/system/js/secure_window_manager.js
Expand Up @@ -51,11 +51,10 @@
killAnimation: 'immediate',
listens: ['secure-killapps',
'secure-closeapps',
'secure-modeon',
'secure-modeoff',
'secure-appcreated',
'secure-appterminated',
'secure-apprequestclose'
'secure-apprequestclose',
'home'
]
}
};
Expand All @@ -66,9 +65,6 @@
* @listens secure-closeapps - means to close remain apps. It's similar to
* the event above, but would show the closing
* animation.
* @listens secure-modeon - the system would be in the secure mode by locking
* or other reasons.
* @listens secure-modeoff - the system now is not in the secure mode anymore.
* @listens secure-appcreated - when a secure app got created, it would fire
* this event.
* @listens secure-appterminated - when a secure app got really closed, it
Expand All @@ -93,12 +89,6 @@
this.killApps();
}
break;
case 'secure-modeon':
this.resume();
break;
case 'secure-modeoff':
this.suspend();
break;
case 'secure-appcreated':
app = evt.detail;
if (this.allowed(app.config)) {
Expand Down Expand Up @@ -127,42 +117,14 @@
app.close(this.states.killMode ?
this.configs.killAnimation : null);
break;
case 'home':
if (0 !== Object.keys(this.states.runningApps).length) {
this.killApps();
}
break;
}
};

/**
* Remove event listeners except the resuming (`secure-modeon`)
* event.
*
* @private
* @this {SecureWindowManager}
* @memberof SecureWindowManager
*/
SecureWindowManager.prototype.suspend =
function swm_suspend() {
this.suspendEvents();

// Will suspend all events.
// But we also want to leave a single entry to resume.
self.addEventListener('secure-modeon', this);
};

/**
* Hook event listeners back and don't care the resuming
* (`secure-modeon`) event anymore.
*
* @private
* @this {SecureWindowManager}
* @memberof SecureWindowManager
*/
SecureWindowManager.prototype.resume =
function swm_resume() {
this.initEvents();

// To prevent duplicated init.
self.removeEventListener('secure-modeon', this);
};

/**
* @private
* @this {SecureWindowManager}
Expand Down Expand Up @@ -191,20 +153,6 @@
}).bind(this));
};

/**
* Remove listeners of events this manager interested in.
*
* @private
* @this {SecureWindowManager}
* @memberof SecureWindowManager
*/
SecureWindowManager.prototype.suspendEvents =
function swm_suspendEvents() {
this.configs.listens.forEach((function _unbind(ename) {
self.removeEventListener(ename, this);
}).bind(this));
};

/**
* Close/Kill all manager secure apps, which has been registered
* while they're created and opened.
Expand Down
29 changes: 10 additions & 19 deletions apps/system/test/unit/secure_window_manager_test.js
Expand Up @@ -27,9 +27,6 @@ suite('system/SecureWindowManager', function() {
stubById.returns(document.createElement('div'));
appFake = new window.SecureWindow(configFake);
window.secureWindowManager = new window.SecureWindowManager();
// To prevent the original one has been
// initialized in the bootstrap stage.
window.secureWindowManager.suspendEvents();
});

teardown(function() {
Expand Down Expand Up @@ -144,23 +141,17 @@ suite('system/SecureWindowManager', function() {
stubKill.restore();
});

test('Suspend the secure mode', function() {
window.secureWindowManager.handleEvent({type: 'secure-modeoff'});
window.dispatchEvent(new CustomEvent('secure-appcreated',
{detail: appFake}));
assert.isNull(
window.secureWindowManager.states.activeApp,
'the app was got activated in off mode');
});
test('Pressing home', function() {
var evt = {
type: 'home'
};
var stubKillApps = this.sinon.stub(window.secureWindowManager,
'killApps');
window.secureWindowManager.registerApp(appFake);
window.secureWindowManager.handleEvent(evt);

test('Resume the secure mode', function() {
window.secureWindowManager.handleEvent({type: 'secure-modeoff'});
window.dispatchEvent(new CustomEvent('secure-modeon'));
window.dispatchEvent(new CustomEvent('secure-appcreated',
{detail: appFake}));
assert.isNotNull(
window.secureWindowManager.states.activeApp,
'the app was not got activated when the secure mode is on by event');
assert.isTrue(stubKillApps.called,
'should shut down secure apps after pressing home');
});
});
});
Expand Down

0 comments on commit b60d953

Please sign in to comment.