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

Commit

Permalink
Bug 1047645 - Use manual timeout to guard _closed event from not firi…
Browse files Browse the repository at this point in the history
…ng r=alive
  • Loading branch information
KevinGrandon committed Aug 15, 2014
1 parent 7fdb37b commit 295c7f5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/system/js/app_window.js
Expand Up @@ -420,10 +420,18 @@


// If the app is the currently displayed app, switch to the homescreen // If the app is the currently displayed app, switch to the homescreen
if (this.isActive() && !this.isHomescreen) { if (this.isActive() && !this.isHomescreen) {
this.element.addEventListener('_closed', (function onClosed() {
window.removeEventListener('_closed', onClosed); var fallbackTimeout;
var onClosed = function() {
clearTimeout(fallbackTimeout);
this.element.removeEventListener('_closed', onClosed);
this.destroy(); this.destroy();
}).bind(this)); }.bind(this);

this.element.addEventListener('_closed', onClosed);
fallbackTimeout = setTimeout(onClosed,
this.transitionController.CLOSING_TRANSITION_TIMEOUT);

if (this.previousWindow) { if (this.previousWindow) {
this.previousWindow.getBottomMostWindow().open('in-from-left'); this.previousWindow.getBottomMostWindow().open('in-from-left');
this.close('out-to-right'); this.close('out-to-right');
Expand Down
24 changes: 24 additions & 0 deletions apps/system/test/unit/app_window_test.js
Expand Up @@ -1146,6 +1146,11 @@ suite('system/AppWindow', function() {
}); });


suite('Event handlers', function() { suite('Event handlers', function() {
var fakeTransitionController = {
requireOpen: function() {},
requireClose: function() {}
};

test('ActivityDone event', function() { test('ActivityDone event', function() {
var app1 = new AppWindow(fakeAppConfig1); var app1 = new AppWindow(fakeAppConfig1);
var app2 = new AppWindow(fakeAppConfig2); var app2 = new AppWindow(fakeAppConfig2);
Expand Down Expand Up @@ -1303,6 +1308,7 @@ suite('system/AppWindow', function() {
var stubCloseSelf = this.sinon.stub(app1, 'close'); var stubCloseSelf = this.sinon.stub(app1, 'close');
stubIsActive.returns(true); stubIsActive.returns(true);


app1.transitionController = fakeTransitionController;
app1.kill(); app1.kill();
assert.isTrue(stubOpenParent.calledWith('in-from-left')); assert.isTrue(stubOpenParent.calledWith('in-from-left'));
assert.isTrue(stubCloseSelf.calledWith('out-to-right')); assert.isTrue(stubCloseSelf.calledWith('out-to-right'));
Expand All @@ -1315,6 +1321,24 @@ suite('system/AppWindow', function() {
assert.isTrue(stubDestroy.called); assert.isTrue(stubDestroy.called);
}); });


test('kill guards against missed transitions', function() {
var app = new AppWindow(fakeAppConfig1);

// Ensure that the closed event does not trigger the destroy method.
this.sinon.stub(app.element, 'addEventListener');

this.sinon.stub(app, 'isActive').returns(true);
var destroyStub = this.sinon.stub(app, 'destroy');

app.transitionController = fakeTransitionController;
app.kill();
assert.ok(destroyStub.notCalled);

var fallbackTimeout = 1000;
this.sinon.clock.tick(fallbackTimeout);
assert.ok(destroyStub.calledOnce);
});

test('Load event', function() { test('Load event', function() {
var app1 = new AppWindow(fakeAppConfig1); var app1 = new AppWindow(fakeAppConfig1);


Expand Down
4 changes: 4 additions & 0 deletions apps/system/test/unit/lockscreen_window_test.js
Expand Up @@ -77,6 +77,7 @@ suite('system/LockScreenWindow', function() {
// Or the AppWindow would look for it. // Or the AppWindow would look for it.
app.element = document.createElement('div'); app.element = document.createElement('div');
parentElement.appendChild(app.element); parentElement.appendChild(app.element);
app.transitionController = {};
app.kill(); app.kill();
assert.isTrue(stubDispatch.calledWithMatch(sinon.match( assert.isTrue(stubDispatch.calledWithMatch(sinon.match(
function(e) { function(e) {
Expand All @@ -95,6 +96,9 @@ suite('system/LockScreenWindow', function() {
// Or the AppWindow would look for it. // Or the AppWindow would look for it.
app.element = document.createElement('div'); app.element = document.createElement('div');
parentElement.appendChild(app.element); parentElement.appendChild(app.element);
app.transitionController = {
requireClose: function() {}
};
app.kill(); app.kill();
app.close(); app.close();
assert.isTrue(stubDispatch.calledWithMatch(sinon.match( assert.isTrue(stubDispatch.calledWithMatch(sinon.match(
Expand Down
4 changes: 4 additions & 0 deletions apps/system/test/unit/secure_window_test.js
Expand Up @@ -69,6 +69,7 @@ suite('system/SecureWindow', function() {
// Or the AppWindow would look for it. // Or the AppWindow would look for it.
app.element = document.createElement('div'); app.element = document.createElement('div');
parentElement.appendChild(app.element); parentElement.appendChild(app.element);
app.transitionController = {};
app.kill(); app.kill();
assert.isTrue(stubDispatch.calledWithMatch(sinon.match( assert.isTrue(stubDispatch.calledWithMatch(sinon.match(
function(e) { function(e) {
Expand All @@ -89,6 +90,9 @@ suite('system/SecureWindow', function() {
// Or the AppWindow would look for it. // Or the AppWindow would look for it.
app.element = document.createElement('div'); app.element = document.createElement('div');
parentElement.appendChild(app.element); parentElement.appendChild(app.element);
app.transitionController = {
requireClose: function() {}
};
app.kill(); app.kill();
app.close(); app.close();
assert.isTrue(stubDispatch.calledWithMatch(sinon.match( assert.isTrue(stubDispatch.calledWithMatch(sinon.match(
Expand Down

0 comments on commit 295c7f5

Please sign in to comment.