From 65db7ce17474510f9335ad06197d8b8818b34fbf Mon Sep 17 00:00:00 2001 From: Etienne Segonzac Date: Thu, 5 Dec 2013 18:34:22 +0100 Subject: [PATCH] Bug 943236 - Move the current app to the top of the stack if the app opens a window. --- apps/system/js/stack_manager.js | 11 +++++++--- apps/system/test/unit/stack_manager_test.js | 24 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/apps/system/js/stack_manager.js b/apps/system/js/stack_manager.js index 88b1af9683b6..6c57c158cd00 100644 --- a/apps/system/js/stack_manager.js +++ b/apps/system/js/stack_manager.js @@ -53,6 +53,7 @@ var StackManager = { if (app.stayBackground) { this._insertBelow(app); } else { + this._moveToTop(this._current); this._insertOnTop(app); } break; @@ -60,6 +61,8 @@ var StackManager = { case 'launchwrapper': var config = e.detail; if (!config.stayBackground) { + this._moveToTop(this._current); + var idx = this._indexOfURL(config.url); if (idx !== undefined) { this._moveToTop(idx); @@ -67,9 +70,7 @@ var StackManager = { } break; case 'home': - if (this._stack.length > 1) { - this._moveToTop(this._current); - } + this._moveToTop(this._current); break; case 'appterminated': var manifestURL = e.detail.manifestURL; @@ -92,6 +93,10 @@ var StackManager = { }, _moveToTop: function sm_moveToTop(index) { + if (index >= this._stack.length) { + return; + } + var sheet = this._stack.splice(index, 1)[0]; this._current = this._stack.push(sheet) - 1; }, diff --git a/apps/system/test/unit/stack_manager_test.js b/apps/system/test/unit/stack_manager_test.js index 071d95972649..e02f68e7ce9f 100644 --- a/apps/system/test/unit/stack_manager_test.js +++ b/apps/system/test/unit/stack_manager_test.js @@ -175,6 +175,22 @@ suite('system/StackManager >', function() { assert.deepEqual(StackManager.getPrev(), dialer); assert.deepEqual(StackManager.getCurrent(), contact); }); + + suite('then we go back and launch a third app', function() { + setup(function() { + StackManager.goPrev(); + appLaunch(settings); + }); + + test('the current app at the time of the launch should move to the top', + function() { + assert.deepEqual(StackManager.getPrev(), dialer); + }); + + test('the new app should go on the top', function() { + assert.deepEqual(StackManager.getCurrent(), settings); + }); + }); }); suite('if it\'s already in the stack', function() { @@ -185,10 +201,18 @@ suite('system/StackManager >', function() { test('it should go on top of the stack', function() { appLaunch(dialer, true); + assert.deepEqual(StackManager.getCurrent(), dialer); assert.deepEqual(StackManager.getPrev(), settings); }); + test('it should bring the current app on top too', function() { + StackManager.goPrev(); + appLaunch(dialer, true); + + assert.deepEqual(StackManager.getPrev(), contact); + }); + test('it should not be duplicated', function() { appLaunch(dialer, true);