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 #26765 from mancas/bug1100341_v2.1
Browse files Browse the repository at this point in the history
Bug 1100341 - [Statusbar][Edge gestures] Icons overlay when performing e...
  • Loading branch information
rvandermeulen committed Jan 5, 2015
2 parents 78d6cfa + 0292817 commit b04a8cb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 46 deletions.
14 changes: 5 additions & 9 deletions apps/system/js/edge_swipe_detector.js
Expand Up @@ -12,8 +12,7 @@ var EdgeSwipeDetector = {

init: function esd_init() {
window.addEventListener('homescreenopened', this);
window.addEventListener('appopen', this);
window.addEventListener('launchapp', this);
window.addEventListener('appopened', this);
window.addEventListener('cardviewclosed', this);
window.addEventListener('mozChromeEvent', this);

Expand Down Expand Up @@ -72,18 +71,15 @@ var EdgeSwipeDetector = {
e.preventDefault();
this._touchEnd(e);
break;
case 'appopen':
case 'appopened':
var app = e.detail;
this.lifecycleEnabled = (app.origin !== FtuLauncher.getFtuOrigin());
if (!app.stayBackground) {
this.lifecycleEnabled = (app.origin !== FtuLauncher.getFtuOrigin());
}
break;
case 'homescreenopened':
this.lifecycleEnabled = false;
break;
case 'launchapp':
if (!e.detail.stayBackground) {
this.lifecycleEnabled = true;
}
break;
case 'cardviewclosed':
if (e.detail && e.detail.newStackPosition) {
this.lifecycleEnabled = true;
Expand Down
21 changes: 20 additions & 1 deletion apps/system/js/statusbar.js
Expand Up @@ -143,6 +143,8 @@ var StatusBar = {

_minimizedStatusBarWidth: window.innerWidth,

_pausedForGesture: false,

/**
* Object used for handling the clock UI element, wraps all related timers
*/
Expand Down Expand Up @@ -360,7 +362,10 @@ var StatusBar = {

case 'sheets-gesture-begin':
this.element.classList.add('hidden');
this.pauseUpdate();
if (!this._pausedForGesture) {
this.pauseUpdate();
this._pausedForGesture = true;
}
break;

case 'utilitytraywillshow':
Expand Down Expand Up @@ -539,6 +544,7 @@ var StatusBar = {

case 'sheets-gesture-end':
this.element.classList.remove('hidden');
this._pausedForGesture = false;
this.resumeUpdate();
break;

Expand All @@ -561,8 +567,21 @@ var StatusBar = {
this._updateMinimizedStatusBarWidth();
/* falls through */
case 'apptitlestatechanged':
this.setAppearance(evt.detail);
if (!this.isPaused()) {
this.element.classList.remove('hidden');
}
break;
case 'homescreenopened':
// In some cases, if the user has been switching apps so fast and
// quickly he press the home button, we might miss the
// |sheets-gesture-end| event so we must resume the statusbar
// if needed
this.setAppearance(evt.detail);
if (this._pausedForGesture) {
this.resumeUpdate();
this._pausedForGesture = false;
}
this.element.classList.remove('hidden');
break;
case 'activityterminated':
Expand Down
42 changes: 6 additions & 36 deletions apps/system/test/unit/edge_swipe_detector_test.js
Expand Up @@ -79,12 +79,6 @@ suite('system/EdgeSwipeDetector >', function() {
name: 'FTU'
};

function appLaunch(config) {
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent('launchapp', true, false, config);
window.dispatchEvent(evt);
}

function homescreen() {
window.dispatchEvent(new Event('homescreenopened'));
}
Expand All @@ -99,7 +93,7 @@ suite('system/EdgeSwipeDetector >', function() {
function launchTransitionEnd(config) {
var evt = document.createEvent('CustomEvent');
config || (config = dialer);
evt.initCustomEvent('appopen', true, false, config);
evt.initCustomEvent('appopened', true, false, config);
window.dispatchEvent(evt);
}

Expand Down Expand Up @@ -147,7 +141,7 @@ suite('system/EdgeSwipeDetector >', function() {
});

test('the edges should be enabled', function() {
appLaunch(dialer);
launchTransitionEnd(dialer);
assert.isFalse(EdgeSwipeDetector.previous.classList.contains('disabled'));
assert.isFalse(EdgeSwipeDetector.next.classList.contains('disabled'));
});
Expand All @@ -162,7 +156,7 @@ suite('system/EdgeSwipeDetector >', function() {
});

test('the edges should not be enabled', function() {
appLaunch(dialer);
launchTransitionEnd(dialer);
var previous = EdgeSwipeDetector.previous;
assert.isTrue(previous.classList.contains('disabled'));
assert.isTrue(EdgeSwipeDetector.next.classList.contains('disabled'));
Expand All @@ -180,7 +174,7 @@ suite('system/EdgeSwipeDetector >', function() {
suite('in background', function() {
setup(function() {
dialer.stayBackground = true;
appLaunch(dialer);
launchTransitionEnd(dialer);
});

test('the edges should not be enabled', function() {
Expand All @@ -198,37 +192,13 @@ suite('system/EdgeSwipeDetector >', function() {
});
});

suite('When a wrapper is launched', function() {
var google = {
url: 'http://google.com/index.html',
origin: 'http://google.com'
};

function wrapperLaunch(config) {
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent('launchapp', true, false, config);
window.dispatchEvent(evt);
}

setup(function() {
EdgeSwipeDetector.previous.classList.add('disabled');
EdgeSwipeDetector.next.classList.add('disabled');
});

test('the edges should be enabled', function() {
wrapperLaunch(google);
assert.isFalse(EdgeSwipeDetector.previous.classList.contains('disabled'));
assert.isFalse(EdgeSwipeDetector.next.classList.contains('disabled'));
});
});

suite('When the setting is enabled', function() {
setup(function() {
MockSettingsListener.mCallbacks['edgesgesture.enabled'](false);
EdgeSwipeDetector.previous.classList.add('disabled');
EdgeSwipeDetector.next.classList.add('disabled');

appLaunch(dialer);
launchTransitionEnd(dialer);
});

teardown(function() {
Expand Down Expand Up @@ -259,7 +229,7 @@ suite('system/EdgeSwipeDetector >', function() {
EdgeSwipeDetector.previous.classList.remove('disabled');
EdgeSwipeDetector.next.classList.remove('disabled');

appLaunch(dialer);
launchTransitionEnd(dialer);
});

teardown(function() {
Expand Down
51 changes: 51 additions & 0 deletions apps/system/test/unit/statusbar_test.js
Expand Up @@ -2300,6 +2300,26 @@ suite('system/Statusbar', function() {
assert.isFalse(StatusBar.element.classList.contains('hidden'));
}

function testEventThatNotShowsIfSwipeDetected(event) {
var currentApp = {
getTopMostWindow: function getTopMostWindow() {
return this._topWindow;
}
};
System.currentApp = currentApp;
var evt = new CustomEvent(event, {detail: currentApp});
StatusBar.element.classList.add('hidden');
StatusBar.handleEvent(evt);
assert.isTrue(setAppearanceStub.called);
assert.isTrue(setAppearanceStub.calledWith(currentApp));
assert.isTrue(StatusBar.element.classList.contains('hidden'));
}

function dispatchEdgeSwipeEvent(event) {
var evt = new CustomEvent(event);
StatusBar.handleEvent(evt);
}

function testEventThatPause(event) {
var evt = new CustomEvent(event);
StatusBar.handleEvent(evt);
Expand All @@ -2317,6 +2337,13 @@ suite('system/Statusbar', function() {
assert.isFalse(StatusBar.isPaused());
}

function testEventThatResumeIfNeeded(event) {
var evt = new CustomEvent(event);
StatusBar.handleEvent(evt);
assert.isTrue(resumeUpdateStub.called);
assert.isFalse(StatusBar.element.classList.contains('hidden'));
}

setup(function() {
app = {
getTopMostWindow: function getTopMostWindow() {
Expand All @@ -2327,6 +2354,7 @@ suite('system/Statusbar', function() {
setAppearanceStub = this.sinon.stub(StatusBar, 'setAppearance');
pauseUpdateStub = this.sinon.stub(StatusBar, 'pauseUpdate');
resumeUpdateStub = this.sinon.stub(StatusBar, 'resumeUpdate');
StatusBar._pausedForGesture = false;
});

test('stackchanged', function() {
Expand Down Expand Up @@ -2400,6 +2428,29 @@ suite('system/Statusbar', function() {
test('utility-tray-overlayclosed', function() {
testEventThatResume.bind(this)('utility-tray-overlayclosed');
});

suite('handle events with swipe detected', function() {
setup(function() {
StatusBar.element.classList.add('hidden');
dispatchEdgeSwipeEvent('sheets-gesture-begin');
dispatchEdgeSwipeEvent('sheets-gesture-begin');
this.sinon.stub(StatusBar, 'isPaused', function() {
return true;
});
});

teardown(function() {
StatusBar.element.classList.remove('hidden');
});

test('apptitlestatechanged', function() {
testEventThatNotShowsIfSwipeDetected.bind(this)('apptitlestatechanged');
});

test('homescreenopened', function() {
testEventThatResumeIfNeeded.bind(this)('homescreenopened');
});
});
});

suite('Label icon width', function() {
Expand Down

0 comments on commit b04a8cb

Please sign in to comment.