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

Upload IME Test CRX to latest version.

BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274542 0039d316-1c4b-4281-b951-d872f2087c98
parent f37c1c99
...@@ -33,7 +33,7 @@ const base::FilePath::CharType kInputViewTestDir[] = ...@@ -33,7 +33,7 @@ const base::FilePath::CharType kInputViewTestDir[] =
const base::FilePath::CharType kBaseKeyboardTestFramework[] = "test_base.js"; const base::FilePath::CharType kBaseKeyboardTestFramework[] = "test_base.js";
const char kDefaultLayout[] = "us"; const char kDefaultLayout[] = "us";
const char kCompactLayout[] = "us.compact"; const char kCompactLayout[] = "us.compact.qwerty";
struct InputViewConfig : public VirtualKeyboardBrowserTestConfig { struct InputViewConfig : public VirtualKeyboardBrowserTestConfig {
explicit InputViewConfig(std::string id, std::string layout) { explicit InputViewConfig(std::string id, std::string layout) {
...@@ -70,13 +70,6 @@ class InputViewBrowserTest : public VirtualKeyboardBrowserTest { ...@@ -70,13 +70,6 @@ class InputViewBrowserTest : public VirtualKeyboardBrowserTest {
std::string extensionId = installer->extension()->id(); std::string extensionId = installer->extension()->id();
if (!service->GetExtensionById(extensionId, false)) if (!service->GetExtensionById(extensionId, false))
return ""; return "";
// Register extension with IME.
chromeos::input_method::InputMethodManager* ime =
chromeos::input_method::InputMethodManager::Get();
std::string id = chromeos::extension_ime_util::GetComponentInputMethodID(
extensionId, "xkb:us::eng");
ime->ChangeInputMethod(id);
return extensionId; return extensionId;
} }
}; };
......
...@@ -4,58 +4,65 @@ ...@@ -4,58 +4,65 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
function testShiftHighlight() { function testShiftHighlightAsync(testDoneCallback) {
// Start in lower case. var test = function() {
mockTouchType('l'); // Start in lower case.
var shift = getKey("leftShift"); mockTouchType('l');
generateTouchEvent(shift, 'touchstart', true, true); var shift = getKey("leftShift");
generateTouchEvent(shift, 'touchend', true, true); generateTouchEvent(shift, 'touchstart', true, true);
// Transitioned to upper case. generateTouchEvent(shift, 'touchend', true, true);
mockTouchType('A'); // Transitioned to upper case.
// Should revert to lower case. mockTouchType('A');
mockTouchType('p'); // Should revert to lower case.
// Should remain in lower case. mockTouchType('p');
mockTouchType('c'); // Should remain in lower case.
mockTouchType('c');
}
RunTest(test, testDoneCallback);
} }
function testCapslock() { function testCapslockAsync(testDoneCallback) {
// Skip this test for compact layouts since they don't have capslock keys. // Skip this test for compact layouts since they don't have capslock keys.
var id = getLayoutId(); var id = getLayoutId();
if (id.indexOf("compact") > 0) if (id.indexOf("compact") > 0) {
testDoneCallback(false);
return; return;
}
var test = function() {
// Start in lower case.
mockTouchType('l');
// To upper case.
// TODO(rsadam@): Only test this for the full layout.
var caps = getKey("capslock")
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')
// Start in lower case. // Same test, but using mouse events.
mockTouchType('l'); // Start in lower case.
// To upper case. mockMouseType('l');
// TODO(rsadam@): Only test this for the full layout. // To upper case.
var caps = getKey("capslock") mockMouseTypeOnKey(caps);
generateTouchEvent(caps, 'touchstart', true, true); mockMouseType('A');
generateTouchEvent(caps, 'touchend', true, true); // Should persist upper case.
mockTouchType('A'); mockMouseType('P');
// Should persist upper case. mockMouseType('C');
mockTouchType('P'); // Back to lower case.
mockTouchType('C'); mockMouseTypeOnKey(caps);
// Back to lower case. mockMouseType('p');
generateTouchEvent(caps, 'touchstart', true, true); // Persist lower case.
generateTouchEvent(caps, 'touchend', true, true); mockMouseType('c')
mockTouchType('p'); mockMouseType('d')
// Persist lower case. }
mockTouchType('c') RunTest(test, testDoneCallback);
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')
} }
...@@ -7,14 +7,17 @@ ...@@ -7,14 +7,17 @@
var mockController; var mockController;
var mockTimer; var mockTimer;
var setComposition; var setComposition;
var realSetTimeout;
var DEFAULT_CONTEXT_ID = 1; var DEFAULT_CONTEXT_ID = 1;
var LONGPRESS_DELAY = 1100;
/** /**
* Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API * Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API
* calls must set expectations for call signatures. * calls must set expectations for call signatures.
*/ */
function setUp() { function setUp() {
realSetTimeout = window.setTimeout;
mockController = new MockController(); mockController = new MockController();
mockTimer = new MockTimer(); mockTimer = new MockTimer();
mockTimer.install(); mockTimer.install();
...@@ -40,6 +43,17 @@ function setUp() { ...@@ -40,6 +43,17 @@ function setUp() {
// TODO(rsadam): Mock additional extension API calls as required. // TODO(rsadam): Mock additional extension API calls as required.
} }
function RunTest(testFn, testDoneCallback) {
var pollTillReady = function() {
if (window.isKeyboardReady()) {
testFn();
testDoneCallback();
} else
realSetTimeout(pollTillReady, 100);
}
pollTillReady();
}
/** /**
* Verify that API calls match expectations. * Verify that API calls match expectations.
*/ */
...@@ -64,38 +78,43 @@ function isActive(el) { ...@@ -64,38 +78,43 @@ function isActive(el) {
/** /**
* Map from keys to layout specific key ids. This only contains a small subset * 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 * of the keys which are used in testing. The ids are based on the XKB layouts
* in GoogleKeyboardInput-xkb.crx. * in GoogleKeyboardInput-xkb.crx. Ids that start with a number are escaped
* so that document.querySelector returns the correct element.
*/ */
var KEY_IDS = { var KEY_IDS = {
'a' : { 'a' : {
'us' : '101kbd-k-29', 'us' : '#\\31 01kbd-k-29',
'us.compact' : 'compactkbd-k-key-10', 'us.compact.qwerty' : '#compactkbd-k-key-11',
}, },
'c' : { 'c' : {
'us' : '101kbd-k-44', 'us' : '#\\31 01kbd-k-44',
'us.compact' : 'compactkbd-k-key-21', 'us.compact.qwerty' : '#compactkbd-k-key-24',
}, },
'd' : { 'd' : {
'us' : '101kbd-k-31', 'us' : '#\\31 01kbd-k-31',
'us.compact' : 'compactkbd-k-key-12', 'us.compact.qwerty' : '#compactkbd-k-key-13',
}, },
'e' : {
'us' : '#\\31 01kbd-k-43',
'us.compact.qwerty': '#compactkbd-k-key-2',
},
'l' : { 'l' : {
'us' : '101kbd-k-37', 'us' : '#\\31 01kbd-k-37',
'us.compact' : 'compactkbd-k-key-18', 'us.compact.qwerty' : '#compactkbd-k-key-19',
}, },
'p' : { 'p' : {
'us' : '101kbd-k-24', 'us' : '#\\31 01kbd-k-24',
'us.compact' : 'compactkbd-k-key-9', 'us.compact.qwerty' : '#compactkbd-k-key-9',
}, },
'leftshift' : { 'leftshift' : {
'us' : '101kbd-k-41', 'us' : '#\\31 01kbd-k-41',
'us.compact' : 'compactkbd-k-21', 'us.compact.qwerty' : '#compactkbd-k-21',
}, },
"capslock" : { "capslock" : {
'us' : '101kbd-k-28', 'us' : '#\\31 01kbd-k-28',
} }
}; };
...@@ -123,15 +142,36 @@ function isActive(el) { ...@@ -123,15 +142,36 @@ function isActive(el) {
return id; return id;
} }
/**
* Returns the layout with the id provided. Periods in the id are replaced by
* hyphens.
* @param id {string} id The layout id.
* @return {object}
*/
var getLayout_ = function(id) {
// Escape periods to hyphens.
var layoutId = id.replace(/\./g, '-');
var layout = document.querySelector('#' + layoutId);
assertTrue(!!layout, "Cannot find layout with id: " + layoutId);
return layout;
}
/** /**
* Returns the key object corresponding to the character. * Returns the key object corresponding to the character.
* @return {string} char The character. * @return {string} char The character.
*/ */
var getKey_ = function(char) { var getKey_ = function(char) {
var layoutId = getLayoutId(); var layoutId = getLayoutId();
var key = document.getElementById(getKeyId_(layoutId, char)); var layout = getLayout_(layoutId);
assertTrue(!!key, "Key not present in layout: " + char);
return key; // All keys in the layout that are in the target keys position.
var candidates = layout.querySelectorAll(getKeyId_(layoutId, char));
assertTrue(candidates.length > 0, "Cannot find key: " + char);
var visible = Array.prototype.filter.call(candidates, isActive);
assertEquals(1, visible.length,
"Expect exactly one visible key for char: " + char);
return visible[0];
} }
exports.getKey = getKey_; exports.getKey = getKey_;
...@@ -182,8 +222,13 @@ function mockMouseType(char) { ...@@ -182,8 +222,13 @@ function mockMouseType(char) {
* @param type {String} The type of the touch event. * @param type {String} The type of the touch event.
*/ */
function generateTouchEvent(target, type) { function generateTouchEvent(target, type) {
var e = document.createEvent('UIEvents'); // UIEvent does not allow mocking pageX pageY of the event, so we use the
// parent Event class.
var e = document.createEvent('Event');
e.initEvent(type, true, true); e.initEvent(type, true, true);
var rect = target.getBoundingClientRect();
e.pageX = rect.left;
e.pageY = rect.top;
target.dispatchEvent(e); target.dispatchEvent(e);
} }
......
...@@ -7,12 +7,15 @@ ...@@ -7,12 +7,15 @@
/** /**
* Tests typing in the lowercase keyset. * Tests typing in the lowercase keyset.
*/ */
function testLowercaseKeyset() { function testLowercaseKeysetAsync(testDoneCallback) {
// Mouse events. var test = function() {
mockMouseType('l'); // Mouse events.
mockMouseType('p'); mockMouseType('l');
mockMouseType('p');
// Touch events. // Touch events.
mockTouchType('l'); mockTouchType('l');
mockTouchType('p'); mockTouchType('p');
}
RunTest(test, testDoneCallback);
} }
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