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

Commit

Permalink
Bug 985853 - Amend the test cases. r=timdream
Browse files Browse the repository at this point in the history
  • Loading branch information
RudyLu authored and KevinGrandon committed Oct 29, 2014
1 parent a025586 commit 9a708ba
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 60 deletions.
8 changes: 4 additions & 4 deletions apps/keyboard/js/keyboard/active_targets_manager.js
Expand Up @@ -101,11 +101,11 @@ ActiveTargetsManager.prototype._handlePressStart = function(press, id) {
}

// Notify current targets about the new touch.
this.activeTargets.forEach(function(target, id) {
if (typeof this.onnewtargetwillactivate === 'function') {
if (typeof this.onnewtargetwillactivate === 'function') {
this.activeTargets.forEach(function(target, id) {
this.onnewtargetwillactivate(target);
}
}, this);
}, this);
}

var target = press.target;
this.activeTargets.set(id, target);
Expand Down
16 changes: 7 additions & 9 deletions apps/keyboard/test/unit/keyboard/active_targets_manager_test.js
Expand Up @@ -38,6 +38,7 @@ suite('ActiveTargetsManager', function() {
manager.ontargetcommitted = this.sinon.stub();
manager.ontargetcancelled = this.sinon.stub();
manager.ontargetdoubletapped = this.sinon.stub();
manager.onnewtargetwillactivate = this.sinon.stub();
manager.start();

assert.isTrue(window.UserPressManager.calledWithNew());
Expand Down Expand Up @@ -452,15 +453,12 @@ suite('ActiveTargetsManager', function() {
userPressManagerStub.onpressstart(press1, id1);

assert.isTrue(manager.onnewtargetwillactivate.calledWith(press0.target),
'Determine commit the first press or not' +
' when the second press starts.');
assert.isTrue(alternativesCharMenuManagerStub.hide.calledOnce);
'onnewtargetwillactivate called.');

assert.isTrue(
manager.ontargetactivated.calledWith(press1.target));
assert.isTrue(manager.ontargetactivated.calledWith(press1.target));

assert.equal(window.clearTimeout.callCount, 3);
assert.equal(window.setTimeout.callCount, 3);
assert.equal(window.clearTimeout.callCount, 2);
assert.equal(window.setTimeout.callCount, 1);
});

test('press end second press, and first press', function() {
Expand All @@ -471,10 +469,10 @@ suite('ActiveTargetsManager', function() {
};
userPressManagerStub.onpressend(pressEnd, id1);

assert.isTrue(alternativesCharMenuManagerStub.hide.calledTwice);
assert.isTrue(alternativesCharMenuManagerStub.hide.calledOnce);
assert.isTrue(
manager.ontargetcommitted.calledWith(press1.target));
assert.equal(window.clearTimeout.callCount, 4);
assert.equal(window.clearTimeout.callCount, 3);

var pressEnd2 = {
target: {
Expand Down
25 changes: 24 additions & 1 deletion apps/keyboard/test/unit/keyboard/target_handlers_manager_test.js
Expand Up @@ -99,6 +99,12 @@ suite('TargetHandlersManager', function() {
assert.isTrue(handlerStub.doubleTap.calledOnce);
});

test('New Target activated', function() {
activeTargetsManagerStub.onnewtargetwillactivate(target);

assert.isTrue(handlerStub.newTargetActivate.calledOnce);
});

suite('longPress', function() {
setup(function() {
activeTargetsManagerStub.ontargetlongpressed(target);
Expand Down Expand Up @@ -129,6 +135,12 @@ suite('TargetHandlersManager', function() {

assert.isTrue(handlerStub.doubleTap.calledOnce);
});

test('New target activated', function() {
activeTargetsManagerStub.onnewtargetwillactivate(target);

assert.isTrue(handlerStub.newTargetActivate.calledOnce);
});
});
});

Expand Down Expand Up @@ -175,6 +187,12 @@ suite('TargetHandlersManager', function() {
assert.isTrue(handlerStub.doubleTap.calledOnce);
});

test('New target activated', function() {
activeTargetsManagerStub.onnewtargetwillactivate(target);

assert.isTrue(handlerStub.newTargetActivate.calledOnce);
});

suite('longPress', function() {
setup(function() {
activeTargetsManagerStub.ontargetlongpressed(target);
Expand Down Expand Up @@ -205,6 +223,12 @@ suite('TargetHandlersManager', function() {

assert.isTrue(handlerStub.doubleTap.calledOnce);
});

test('New target activated', function() {
activeTargetsManagerStub.onnewtargetwillactivate(target);

assert.isTrue(handlerStub.newTargetActivate.calledOnce);
});
});
});

Expand Down Expand Up @@ -261,7 +285,6 @@ suite('TargetHandlersManager', function() {
assert.isTrue(handlerStub.activate.calledOnce);
});


test('SpaceKeyTargetHandler', function() {
var target = {
keyCode: KeyEvent.DOM_VK_SPACE
Expand Down
84 changes: 38 additions & 46 deletions apps/keyboard/test/unit/keyboard/target_handlers_test.js
Expand Up @@ -131,6 +131,21 @@ suite('target handlers', function() {
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});

test('new target activated', function() {
handler.newTargetActivate();

assert.isTrue(
app.inputMethodManager.currentIMEngine.click.calledWith(99));
assert.isTrue(app.inputMethodManager.currentIMEngine.click.calledOnce);

assert.isTrue(app.visualHighlightManager.hide.calledWith(target));
assert.isTrue(app.visualHighlightManager.hide.calledOnce);

handler.commit();
// Won't commit again
assert.isTrue(app.inputMethodManager.currentIMEngine.click.calledOnce);
});

suite('longPress', function() {
setup(function() {
handler.longPress();
Expand Down Expand Up @@ -722,59 +737,22 @@ suite('target handlers', function() {
var target;
setup(function() {
target = {};

handler = new CapsLockTargetHandler(target, app);
});

test('activate', function() {
setup(function() {
handler.activate();

assert.isTrue(app.feedbackManager.triggerFeedback.calledWith(target));
assert.isTrue(app.feedbackManager.triggerFeedback.calledOnce);

assert.isTrue(app.visualHighlightManager.show.calledWith(target));
assert.isTrue(app.visualHighlightManager.show.calledOnce);
});

test('commit', function() {
handler.commit();

assert.isTrue(app.upperCaseStateManager.switchUpperCaseState
.calledWith({
isUpperCase: true,
isUpperCaseLocked: false
}));

assert.isTrue(app.visualHighlightManager.hide.calledWith(target));
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});

test('moveOut', function() {
handler.moveOut();

assert.isTrue(app.visualHighlightManager.hide.calledWith(target));
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});

test('cancel', function() {
handler.cancel();

assert.isTrue(app.visualHighlightManager.hide.calledWith(target));
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});
handler.activate();

test('doubleTap', function() {
handler.doubleTap();
assert.isTrue(app.upperCaseStateManager.switchUpperCaseState
.calledWith({
isUpperCaseLocked: true
}));

assert.isTrue(app.upperCaseStateManager.switchUpperCaseState
.calledWith({
isUpperCaseLocked: true
}));
assert.isTrue(app.feedbackManager.triggerFeedback.calledWith(target));
assert.isTrue(app.feedbackManager.triggerFeedback.calledOnce);

assert.isTrue(app.visualHighlightManager.hide.calledWith(target));
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});
assert.isTrue(app.visualHighlightManager.show.calledWith(target));
assert.isTrue(app.visualHighlightManager.show.calledOnce);
});

test('longPress', function() {
Expand Down Expand Up @@ -804,6 +782,20 @@ suite('target handlers', function() {
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});

test('combo key - activate and then with new arget activated', function() {
handler.newTargetActivate();
handler.commit();

assert.isTrue(app.upperCaseStateManager.switchUpperCaseState
.calledWith({
isUpperCase: false,
isUpperCaseLocked: false
}));

assert.isTrue(app.visualHighlightManager.hide.calledWith(target));
assert.isTrue(app.visualHighlightManager.hide.calledOnce);
});

test('cancel', function() {
assert.equal(handler.cancel, DefaultTargetHandler.prototype.cancel,
'function not overwritten');
Expand Down

0 comments on commit 9a708ba

Please sign in to comment.