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 #23937 from alivedise/bugzilla/1055299_master/v4
Browse files Browse the repository at this point in the history
Bug 1055299: Ignore continuous app launch request in homescreen side and...r=kgrandon
  • Loading branch information
alivedise committed Sep 15, 2014
2 parents fcc35f5 + 20b9139 commit f5498c1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 26 deletions.
10 changes: 6 additions & 4 deletions apps/system/js/visibility_manager.js
@@ -1,4 +1,4 @@
/* global attentionWindowManager, System */
/* global attentionWindowManager, System, rocketbar */
'use strict';

(function(exports) {
Expand Down Expand Up @@ -88,6 +88,8 @@
this.publish('showwindow', { type: evt.type });
this._resetDeviceLockedTimer();
break;

case 'rocketbar-overlayclosed':
case 'lockscreen-request-unlock':
var detail = evt.detail,
activity = null,
Expand All @@ -98,7 +100,8 @@
notificationId = detail.notificationId;
}

if (!attentionWindowManager.hasActiveWindow()) {
if (!attentionWindowManager.hasActiveWindow() &&
!rocketbar.active) {
this.publish('showwindow', {
activity: activity, // Trigger activity opening in AWM
notificationId: notificationId
Expand All @@ -107,6 +110,7 @@
this._resetDeviceLockedTimer();
break;
case 'lockscreen-appopened':
case 'rocketbar-overlayopened':
// If the audio is active, the app should not set non-visible
// otherwise it will be muted.
// TODO: Remove this hack.
Expand All @@ -124,13 +128,11 @@
this.publish('hidewindow', { type: evt.type });
}
break;
case 'rocketbar-overlayopened':
case 'utility-tray-overlayopened':
case 'cardviewshown':
case 'system-dialog-show':
this.publish('hidewindowforscreenreader');
break;
case 'rocketbar-overlayclosed':
case 'utility-tray-overlayclosed':
case 'cardviewclosed':
case 'system-dialog-hide':
Expand Down
2 changes: 1 addition & 1 deletion apps/system/test/marionette/homescreen_navigation_test.js
Expand Up @@ -64,7 +64,7 @@ marionette('Homescreen navigation >', function() {

goHome();
launchSettings();

client.helper.wait(1000);
reflowHelper.startTracking(System.URL);
client.switchToFrame();

Expand Down
69 changes: 48 additions & 21 deletions apps/system/test/unit/visibility_manager_test.js
@@ -1,4 +1,4 @@
/* globals MocksHelper, VisibilityManager,
/* globals MocksHelper, VisibilityManager, MockRocketbar,
MockAttentionWindowManager, MockTaskManager, MockAppWindow */
'use strict';

Expand All @@ -8,6 +8,7 @@ requireApp('system/shared/test/unit/mocks/mock_manifest_helper.js');
require('/shared/test/unit/mocks/mock_system.js');
requireApp('system/test/unit/mock_attention_window_manager.js');
requireApp('system/test/unit/mock_app_window.js');
requireApp('system/test/unit/mock_rocketbar.js');

var mocksForVisibilityManager = new MocksHelper([
'AttentionWindowManager', 'System', 'AppWindow'
Expand All @@ -19,6 +20,7 @@ suite('system/VisibilityManager', function() {
mocksForVisibilityManager.attachTestHelpers();
setup(function(done) {
window.attentionWindowManager = MockAttentionWindowManager;
window.rocketbar = new MockRocketbar();
this.sinon.useFakeTimers();

stubById = this.sinon.stub(document, 'getElementById');
Expand All @@ -36,6 +38,51 @@ suite('system/VisibilityManager', function() {
});

suite('handle events', function() {
test('rocketbar-overlayopened', function() {
visibilityManager._normalAudioChannelActive = false;
var stubPublish = this.sinon.stub(visibilityManager, 'publish');
visibilityManager.handleEvent({
type: 'rocketbar-overlayopened'
});

assert.isTrue(stubPublish.calledOnce);
assert.equal(stubPublish.getCall(0).args[0], 'hidewindow');

visibilityManager._normalAudioChannelActive = true;
visibilityManager.handleEvent({
type: 'rocketbar-overlayopened'
});

assert.isTrue(stubPublish.calledOnce);

visibilityManager._normalAudioChannelActive = false;
});

test('searchclosed', function() {
this.sinon.stub(MockAttentionWindowManager,
'hasActiveWindow').returns(false);
var stubPublish = this.sinon.stub(visibilityManager, 'publish');

visibilityManager.handleEvent({
type: 'rocketbar-overlayclosed'
});

assert.isTrue(stubPublish.calledOnce);
assert.isTrue(stubPublish.getCall(0).args[0] === 'showwindow');
});

test('searchclosed when there is active attention window', function() {
this.sinon.stub(MockAttentionWindowManager,
'hasActiveWindow').returns(true);
var stubPublish = this.sinon.stub(visibilityManager, 'publish');

visibilityManager.handleEvent({
type: 'searchclosed'
});

assert.isFalse(stubPublish.called);
});

test('lock', function() {
visibilityManager._normalAudioChannelActive = false;
var stubPublish = this.sinon.stub(visibilityManager, 'publish');
Expand Down Expand Up @@ -110,26 +157,6 @@ suite('system/VisibilityManager', function() {
assert.isTrue(stubPublish.calledWith('showlockscreenwindow'));
});

test('rocketbar-overlayopened', function() {
var stubPublish = this.sinon.stub(visibilityManager, 'publish');
visibilityManager.handleEvent({
type: 'rocketbar-overlayopened'
});

assert.isTrue(stubPublish.called);
assert.isTrue(stubPublish.calledWith('hidewindowforscreenreader'));
});

test('rocketbar-overlayclosed', function() {
var stubPublish = this.sinon.stub(visibilityManager, 'publish');
visibilityManager.handleEvent({
type: 'rocketbar-overlayclosed'
});

assert.isTrue(stubPublish.called);
assert.isTrue(stubPublish.calledWith('showwindowforscreenreader'));
});

test('utility-tray-overlayopened', function() {
var stubPublish = this.sinon.stub(visibilityManager, 'publish');
visibilityManager.handleEvent({
Expand Down
30 changes: 30 additions & 0 deletions shared/elements/gaia_grid/js/grid_view.js
Expand Up @@ -29,6 +29,7 @@
this.onTouchEnd = this.onTouchEnd.bind(this);
this.onScroll = this.onScroll.bind(this);
this.onContextMenu = this.onContextMenu.bind(this);
this.onVisibilityChange = this.onVisibilityChange.bind(this);
this.lastScrollTime = 0;

if (config.features.zoom) {
Expand Down Expand Up @@ -73,6 +74,11 @@
this.layout.cols = value;
},

/**
* We are in the state of launching an app.
*/
_launchingApp: false,

/**
* Adds an item into the items array.
* If the item is an icon, add it to icons.
Expand Down Expand Up @@ -144,6 +150,7 @@
this.element.addEventListener('touchend', this.onTouchEnd);
this.element.addEventListener('contextmenu', this.onContextMenu);
window.addEventListener('scroll', this.onScroll, true);
window.addEventListener('visibilitychange', this.onVisibilityChange);
this.lastTouchStart = null;
},

Expand All @@ -152,6 +159,7 @@
this.element.removeEventListener('touchend', this.onTouchEnd);
this.element.removeEventListener('contextmenu', this.onContextMenu);
window.removeEventListener('scroll', this.onScroll, true);
window.removeEventListener('visibilitychange', this.onVisibilityChange);
this.lastTouchStart = null;
},

Expand Down Expand Up @@ -208,6 +216,10 @@
}
},

onVisibilityChange: function() {
this._launchingApp = false;
},

/**
* Launches an app.
*/
Expand Down Expand Up @@ -256,6 +268,24 @@
}, returnTimeout);
}

if ((icon.detail.type === 'app' || icon.detail.type === 'bookmark') &&
this._launchingApp) {
return;
}
if ((icon.detail.type === 'app' && icon.appState === 'ready') ||
icon.detail.type === 'bookmark') {
this._launchingApp = true;
if (this._launchingTimeout) {
window.clearTimeout(this._launchingTimeout);
this._launchingTimeout = null;
}
// This avoids some edge cases if we didn't get visibilitychange anyway.
this._launchingTimeout = window.setTimeout(function() {
this._launchingTimeout = null;
this._launchingApp = false;
}.bind(this), 3000);
}

icon[action]();
},

Expand Down

0 comments on commit f5498c1

Please sign in to comment.