Commit b9d8e2f6 authored by rsadam@chromium.org's avatar rsadam@chromium.org

Adds shift and capslock tests to IME Keyboard tests.

To be landed after: https://codereview.chromium.org/247883002/ and https://codereview.chromium.org/259603002/

BUG=353857

Review URL: https://codereview.chromium.org/255823004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269521 0039d316-1c4b-4281-b951-d872f2087c98
parent 5c098782
...@@ -80,3 +80,9 @@ IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, TypingTest) { ...@@ -80,3 +80,9 @@ IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, TypingTest) {
ASSERT_FALSE(id.empty()); ASSERT_FALSE(id.empty());
RunTest(base::FilePath("typing_test.js"), InputViewConfig(id)); RunTest(base::FilePath("typing_test.js"), InputViewConfig(id));
} }
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, KeysetTransitionTest) {
std::string id = InstallIMEExtension();
ASSERT_FALSE(id.empty());
RunTest(base::FilePath("keyset_transition_test.js"), InputViewConfig(id));
}
/*
* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
function testShiftHighlight() {
// Start in lower case.
mockTouchType('l');
var shift = getShiftKey(Alignment.LEFT);
generateTouchEvent(shift, 'touchstart', true, true);
generateTouchEvent(shift, 'touchend', true, true);
// Transitioned to upper case.
mockTouchType('A');
// Should revert to lower case.
mockTouchType('p');
// Should remain in lower case.
mockTouchType('c');
}
function testCapslock() {
// Start in lower case.
mockTouchType('l');
// To upper case.
// TODO(rsadam@): Only test this for the full layout.
var caps = document.querySelector('#' + CAPSLOCK_ID);
generateTouchEvent(caps, 'touchstart', true, true);
generateTouchEvent(caps, 'touchend', true, true);
mockTouchType('A');
// Should persist upper case.
mockTouchType('P');
mockTouchType('C');
// Back to lower case.
generateTouchEvent(caps, 'touchstart', true, true);
generateTouchEvent(caps, 'touchend', true, true);
mockTouchType('p');
// Persist lower case.
mockTouchType('c')
mockTouchType('d')
// Same test, but using mouse events.
// Start in lower case.
mockMouseType('l');
// To upper case.
mockMouseTypeOnKey(caps);
mockMouseType('A');
// Should persist upper case.
mockMouseType('P');
mockMouseType('C');
// Back to lower case.
mockMouseTypeOnKey(caps);
mockMouseType('p');
// Persist lower case.
mockMouseType('c')
mockMouseType('d')
}
...@@ -9,6 +9,17 @@ var mockTimer; ...@@ -9,6 +9,17 @@ var mockTimer;
var setComposition; var setComposition;
var DEFAULT_CONTEXT_ID = 1; var DEFAULT_CONTEXT_ID = 1;
var CAPSLOCK_ID = "OsLeft";
/**
* Key alignments.
* @enum {string}
*/
var Alignment = {
LEFT: 'left',
RIGHT: 'right',
CENTER: 'center'
};
/** /**
* Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API * Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API
...@@ -17,10 +28,9 @@ var DEFAULT_CONTEXT_ID = 1; ...@@ -17,10 +28,9 @@ var DEFAULT_CONTEXT_ID = 1;
function setUp() { function setUp() {
mockController = new MockController(); mockController = new MockController();
mockTimer = new MockTimer(); mockTimer = new MockTimer();
mockTimer.install(); mockTimer.install();
mockController.createFunctionMock(chrome.input.ime, 'commitText');
mockController.createFunctionMock(chrome.input.ime, 'commitText');
var validateCommit = function(index, expected, observed) { var validateCommit = function(index, expected, observed) {
// Only consider the first argument, the details object. // Only consider the first argument, the details object.
var expectedEvent = expected[0]; var expectedEvent = expected[0];
...@@ -30,6 +40,7 @@ function setUp() { ...@@ -30,6 +40,7 @@ function setUp() {
'Mismatched commit text.'); 'Mismatched commit text.');
}; };
chrome.input.ime.commitText.validateCall = validateCommit; chrome.input.ime.commitText.validateCall = validateCommit;
setComposition = chrome.input.ime.setComposition; setComposition = chrome.input.ime.setComposition;
// Mocks setComposition manually to immediately callback. The mock controller // Mocks setComposition manually to immediately callback. The mock controller
// does not support callback functions. // does not support callback functions.
...@@ -56,7 +67,9 @@ function tearDown() { ...@@ -56,7 +67,9 @@ function tearDown() {
* @return {Object} The key. * @return {Object} The key.
*/ */
function getKey(char) { function getKey(char) {
return document.querySelector('#Key' + char.toUpperCase()) var key = document.querySelector('#Key' + char.toUpperCase());
assertTrue(!!key, "Cannot find key: " + char);
return key;
} }
/** /**
...@@ -70,7 +83,21 @@ function generateMouseEvent(target, type) { ...@@ -70,7 +83,21 @@ function generateMouseEvent(target, type) {
} }
/** /**
* Mocks a character type using the mouse. * Mocks a key type using the mouse.
* @param {Object} key The key to click on.
*/
function mockMouseTypeOnKey(key) {
generateMouseEvent(key, 'mouseover');
generateMouseEvent(key, 'mousedown');
generateMouseEvent(key, 'mouseup');
generateMouseEvent(key, 'click');
generateMouseEvent(key, 'mouseover');
generateMouseEvent(key, 'mouseout');
}
/**
* Mocks a character type using the mouse. Expects the character will be
* committed.
* @param {String} char The character to type. * @param {String} char The character to type.
*/ */
function mockMouseType(char) { function mockMouseType(char) {
...@@ -80,14 +107,54 @@ function mockMouseType(char) { ...@@ -80,14 +107,54 @@ function mockMouseType(char) {
text: char, text: char,
}); });
var key = getKey(char); var key = getKey(char);
if (!key) { mockMouseTypeOnKey(key);
console.error("Cannot find key: " + char); }
return;
/**
* Generates a touch event and dispatches it on the target.
* @param target {Object} The target of the event.
* @param type {String} The type of the touch event.
*/
function generateTouchEvent(target, type) {
var e = document.createEvent('UIEvents');
e.initEvent(type, true, true);
target.dispatchEvent(e);
}
/**
* Mocks a character type using touch.
* @param {String} char The character to type.
*/
function mockTouchType(char) {
var send = chrome.input.ime.commitText;
send.addExpectation({
contextId: DEFAULT_CONTEXT_ID,
text: char,
});
var key = getKey(char);
generateTouchEvent(key, 'touchstart');
generateTouchEvent(key, 'touchend');
}
/**
* Retrieves the shift key from the current keyset.
* @param {Alignment} align The alignment of the shift key.
* @return {Object} The key.
*/
function getShiftKey(align) {
var id;
switch(align) {
case Alignment.LEFT:
id = 'ShiftLeft';
break;
case Alignment.RIGHT:
id = 'ShiftRight';
break;
default:
break;
} }
generateMouseEvent(key, 'mouseover'); assertTrue(!!id, "Invalid shift alignment option: " + align);
generateMouseEvent(key, 'mousedown'); var shift = document.querySelector('#' + id);
generateMouseEvent(key, 'mouseup'); assertTrue(!!shift, "Cannot find shift key with alignment: " + align);
generateMouseEvent(key, 'click'); return shift;
generateMouseEvent(key, 'mouseover');
generateMouseEvent(key, 'mouseout');
} }
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
* Tests typing in the lowercase keyset. * Tests typing in the lowercase keyset.
*/ */
function testLowercaseKeyset() { function testLowercaseKeyset() {
// Mouse events.
mockMouseType('l'); mockMouseType('l');
mockMouseType('p'); mockMouseType('p');
mockMouseType('e');
mockMouseType('f'); // Touch events.
mockTouchType('l');
mockTouchType('p');
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment