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 #16321 from vingtetun/bug971006-final
Browse files Browse the repository at this point in the history
Bug 971006 - Remove a sync reflow when showing the utility tray. r=etien...
  • Loading branch information
vingtetun committed Feb 14, 2014
2 parents b9859b9 + 35b00f1 commit 19304fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions apps/system/js/utility_tray.js
Expand Up @@ -83,6 +83,7 @@ var UtilityTray = {
break;

case 'touchstart':
evt.preventDefault();
if (LockScreen.locked)
return;
if (evt.target !== this.overlay &&
Expand All @@ -94,10 +95,12 @@ var UtilityTray = {
break;

case 'touchmove':
evt.preventDefault();
this.onTouchMove(evt.touches[0]);
break;

case 'touchend':
evt.preventDefault();
evt.stopImmediatePropagation();
var touch = evt.changedTouches[0];
if (Rocketbar.enabled && !this.shown && !this.active &&
Expand Down
35 changes: 30 additions & 5 deletions apps/system/test/unit/utility_tray_test.js
Expand Up @@ -22,21 +22,26 @@ suite('system/UtilityTray', function() {
var fakeElement;
mocksHelperForUtilityTray.attachTestHelpers();

var FakeEvent = function(y) {
this.pageY = y;
this.preventDefault = function() {};
};

function fakeTouches(start, end) {
UtilityTray.onTouchStart({ pageY: start });
UtilityTray.onTouchStart(new FakeEvent(start));
UtilityTray.screenHeight = 480;

var y = start;
while (y != end) {
UtilityTray.onTouchMove({ pageY: y });
UtilityTray.onTouchMove(new FakeEvent(y));

if (y < end) {
y++;
} else {
y--;
}
}
UtilityTray.onTouchEnd();
UtilityTray.onTouchEnd(new FakeEvent());
}

setup(function(done) {
Expand Down Expand Up @@ -178,11 +183,19 @@ suite('system/UtilityTray', function() {
fakeEvt = {
type: 'touchstart',
target: UtilityTray.overlay,
touches: [0]
touches: [0],
defaultPrevented: false,
preventDefault: function() {
this.defaultPrevented = true;
}
};
UtilityTray.handleEvent(fakeEvt);
});

test('preventDefault() should have been called on touchstart', function() {
assert.isTrue(fakeEvt.defaultPrevented);
});

test('Test UtilityTray.active, should be true', function() {
/* XXX: This is to test UtilityTray.active,
it works in local test but breaks in travis. */
Expand All @@ -195,12 +208,20 @@ suite('system/UtilityTray', function() {
fakeEvt = {
type: 'touchend',
changedTouches: [0],
stopImmediatePropagation: function() {}
stopImmediatePropagation: function() {},
defaultPrevented: false,
preventDefault: function() {
this.defaultPrevented = true;
}
};
UtilityTray.active = true;
UtilityTray.handleEvent(fakeEvt);
});

test('preventDefault() should have been called on touchend', function() {
assert.isTrue(fakeEvt.defaultPrevented);
});

test('Test UtilityTray.active, should be false', function() {
assert.equal(UtilityTray.active, false);
});
Expand Down Expand Up @@ -241,6 +262,7 @@ suite('system/UtilityTray', function() {
test('should display for drag on left half of statusbar', function() {
fakeEvt = {
stopImmediatePropagation: function() {},
preventDefault: function() {},
type: 'touchend',
changedTouches: [{
pageX: 0
Expand All @@ -256,6 +278,7 @@ suite('system/UtilityTray', function() {
test('does not render if utility tray not active', function() {
fakeEvt = {
stopImmediatePropagation: function() {},
preventDefault: function() {},
type: 'touchend',
changedTouches: [{
pageX: 0
Expand All @@ -271,6 +294,7 @@ suite('system/UtilityTray', function() {
test('should not show if we touch to the right', function() {
fakeEvt = {
type: 'touchstart',
preventDefault: function() {},
pageX: 70
};
UtilityTray.onTouchStart(fakeEvt);
Expand All @@ -284,6 +308,7 @@ suite('system/UtilityTray', function() {
assert.equal(UtilityTray.shown, true);
fakeEvt = {
type: 'touchstart',
preventDefault: function() {},
pageX: 0
};
UtilityTray.onTouchStart(fakeEvt);
Expand Down

0 comments on commit 19304fe

Please sign in to comment.