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

We currently have tests only for the full IME layout. Expand the IME test...

We currently have tests only for the full IME layout. Expand the IME test framework to test the Compact layout as well.

BUG=372539

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269957 0039d316-1c4b-4281-b951-d872f2087c98
parent a7b64293
......@@ -31,12 +31,15 @@ const base::FilePath::CharType kInputViewTestDir[] =
"chromeos/virtual_keyboard/inputview/";
const base::FilePath::CharType kBaseKeyboardTestFramework[] = "test_base.js";
const char kDefaultLayout[] = "us";
const char kCompactLayout[] = "us.compact";
struct InputViewConfig : public VirtualKeyboardBrowserTestConfig {
explicit InputViewConfig(std::string id) {
explicit InputViewConfig(std::string id, std::string layout) {
base_framework_ = kBaseKeyboardTestFramework;
extension_id_ = id;
test_dir_ = kInputViewTestDir;
url_ = "chrome-extension://" + id + "/inputview.html?id=us-altgr-intl";
url_ = "chrome-extension://" + id + "/inputview.html?id=" + layout;
}
};
......@@ -78,11 +81,27 @@ class InputViewBrowserTest : public VirtualKeyboardBrowserTest {
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, TypingTest) {
std::string id = InstallIMEExtension();
ASSERT_FALSE(id.empty());
RunTest(base::FilePath("typing_test.js"), InputViewConfig(id));
RunTest(base::FilePath("typing_test.js"),
InputViewConfig(id, kDefaultLayout));
}
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, CompactTypingTest) {
std::string id = InstallIMEExtension();
ASSERT_FALSE(id.empty());
RunTest(base::FilePath("typing_test.js"),
InputViewConfig(id, kCompactLayout));
}
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, KeysetTransitionTest) {
std::string id = InstallIMEExtension();
ASSERT_FALSE(id.empty());
RunTest(base::FilePath("keyset_transition_test.js"), InputViewConfig(id));
RunTest(base::FilePath("keyset_transition_test.js"),
InputViewConfig(id, kDefaultLayout));
}
IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, CompactKeysetTransitionTest) {
std::string id = InstallIMEExtension();
ASSERT_FALSE(id.empty());
RunTest(base::FilePath("keyset_transition_test.js"),
InputViewConfig(id, kCompactLayout));
}
......@@ -7,7 +7,7 @@
function testShiftHighlight() {
// Start in lower case.
mockTouchType('l');
var shift = getShiftKey(Alignment.LEFT);
var shift = getKey("leftShift");
generateTouchEvent(shift, 'touchstart', true, true);
generateTouchEvent(shift, 'touchend', true, true);
// Transitioned to upper case.
......@@ -19,11 +19,16 @@ function testShiftHighlight() {
}
function testCapslock() {
// Skip this test for compact layouts since they don't have capslock keys.
var id = getLayoutId();
if (id.indexOf("compact") > 0)
return;
// Start in lower case.
mockTouchType('l');
// To upper case.
// TODO(rsadam@): Only test this for the full layout.
var caps = document.querySelector('#' + CAPSLOCK_ID);
var caps = getKey("capslock")
generateTouchEvent(caps, 'touchstart', true, true);
generateTouchEvent(caps, 'touchend', true, true);
mockTouchType('A');
......
......@@ -9,17 +9,6 @@ var mockTimer;
var setComposition;
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
......@@ -62,16 +51,93 @@ function tearDown() {
}
/**
* Retrieves the key from the current keyset.
* @param {String} char The character of the key.
* @return {Object} The key.
*/
function getKey(char) {
var key = document.querySelector('#Key' + char.toUpperCase());
assertTrue(!!key, "Cannot find key: " + char);
return key;
* Checks whether the element is currently being displayed on screen.
* @param {Object} The object to check.
* @return {boolean}
*/
function isActive(el) {
return window.getComputedStyle(el).display != "none";
}
(function(exports) {
/**
* Map from keys to layout specific key ids. This only contains a small subset
* of the keys which are used in testing. The ids are based on the XKB layouts
* in GoogleKeyboardInput-xkb.crx.
*/
var KEY_IDS = {
'a' : {
'us' : '101kbd-k-29',
'us.compact' : 'compactkbd-k-key-10',
},
'c' : {
'us' : '101kbd-k-44',
'us.compact' : 'compactkbd-k-key-21',
},
'd' : {
'us' : '101kbd-k-31',
'us.compact' : 'compactkbd-k-key-12',
},
'l' : {
'us' : '101kbd-k-37',
'us.compact' : 'compactkbd-k-key-18',
},
'p' : {
'us' : '101kbd-k-24',
'us.compact' : 'compactkbd-k-key-9',
},
'leftshift' : {
'us' : '101kbd-k-41',
'us.compact' : 'compactkbd-k-21',
},
"capslock" : {
'us' : '101kbd-k-28',
}
};
/**
* Gets the key id of the specified character.
* @param {string} layout The current keyboard layout.
* @param {char} char The character to press.
*/
var getKeyId_ = function(layout, char) {
var lower = char.toLowerCase();
assertTrue(!!KEY_IDS[lower], "Cannot find cached key id: " + char);
assertTrue(!!KEY_IDS[lower][layout],
"Cannot find cached key id: " + char + " in " + layout);
return KEY_IDS[lower][layout];
}
/**
* Returns the current layout id.
* @return {string}
*/
var getLayoutId_ = function() {
// TODO(rsadam@): Generalize this.
var id = window.location.search.split("id=")[1];
assertTrue(!!id, "No layout found.");
return id;
}
/**
* Returns the key object corresponding to the character.
* @return {string} char The character.
*/
var getKey_ = function(char) {
var layoutId = getLayoutId();
var key = document.getElementById(getKeyId_(layoutId, char));
assertTrue(!!key, "Key not present in layout: " + char);
return key;
}
exports.getKey = getKey_;
exports.getLayoutId = getLayoutId_;
})(this);
/**
* Generates a mouse event and dispatches it on the target.
* @param target {Object} The target of the event.
......@@ -123,7 +189,7 @@ function generateTouchEvent(target, type) {
/**
* Mocks a character type using touch.
* @param {String} char The character to type.
* @param {String} char The expected character.
*/
function mockTouchType(char) {
var send = chrome.input.ime.commitText;
......@@ -135,26 +201,3 @@ function mockTouchType(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;
}
assertTrue(!!id, "Invalid shift alignment option: " + align);
var shift = document.querySelector('#' + id);
assertTrue(!!shift, "Cannot find shift key with alignment: " + align);
return shift;
}
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