Index: chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
diff --git a/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
index 248341a7f1f7213bee9fc66d4dd3c5937cfbd8e1..65e1440af8a9c17d4f678912c434ba86e5b46e83 100644 |
--- a/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
+++ b/chrome/test/data/chromeos/virtual_keyboard/inputview/test_base.js |
@@ -7,14 +7,17 @@ |
var mockController; |
var mockTimer; |
var setComposition; |
+var realSetTimeout; |
var DEFAULT_CONTEXT_ID = 1; |
+var LONGPRESS_DELAY = 1100; |
/** |
* Create mocks for the virtualKeyboardPrivate API. Any tests that trigger API |
* calls must set expectations for call signatures. |
*/ |
function setUp() { |
+ realSetTimeout = window.setTimeout; |
mockController = new MockController(); |
mockTimer = new MockTimer(); |
mockTimer.install(); |
@@ -40,6 +43,17 @@ function setUp() { |
// 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. |
*/ |
@@ -64,38 +78,43 @@ function isActive(el) { |
/** |
* 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. |
+ * in GoogleKeyboardInput-xkb.crx. Ids that start with a number are escaped |
+ * so that document.querySelector returns the correct element. |
*/ |
var KEY_IDS = { |
'a' : { |
- 'us' : '101kbd-k-29', |
- 'us.compact' : 'compactkbd-k-key-10', |
+ 'us' : '#\\31 01kbd-k-29', |
+ 'us.compact.qwerty' : '#compactkbd-k-key-11', |
}, |
'c' : { |
- 'us' : '101kbd-k-44', |
- 'us.compact' : 'compactkbd-k-key-21', |
+ 'us' : '#\\31 01kbd-k-44', |
+ 'us.compact.qwerty' : '#compactkbd-k-key-24', |
}, |
'd' : { |
- 'us' : '101kbd-k-31', |
- 'us.compact' : 'compactkbd-k-key-12', |
+ 'us' : '#\\31 01kbd-k-31', |
+ 'us.compact.qwerty' : '#compactkbd-k-key-13', |
}, |
+ 'e' : { |
+ 'us' : '#\\31 01kbd-k-43', |
+ 'us.compact.qwerty': '#compactkbd-k-key-2', |
+ }, |
'l' : { |
- 'us' : '101kbd-k-37', |
- 'us.compact' : 'compactkbd-k-key-18', |
+ 'us' : '#\\31 01kbd-k-37', |
+ 'us.compact.qwerty' : '#compactkbd-k-key-19', |
}, |
'p' : { |
- 'us' : '101kbd-k-24', |
- 'us.compact' : 'compactkbd-k-key-9', |
+ 'us' : '#\\31 01kbd-k-24', |
+ 'us.compact.qwerty' : '#compactkbd-k-key-9', |
}, |
'leftshift' : { |
- 'us' : '101kbd-k-41', |
- 'us.compact' : 'compactkbd-k-21', |
+ 'us' : '#\\31 01kbd-k-41', |
+ 'us.compact.qwerty' : '#compactkbd-k-21', |
}, |
"capslock" : { |
- 'us' : '101kbd-k-28', |
+ 'us' : '#\\31 01kbd-k-28', |
} |
}; |
@@ -124,14 +143,35 @@ function isActive(el) { |
} |
/** |
+ * 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. |
* @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; |
+ var layout = getLayout_(layoutId); |
+ |
+ // 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_; |
@@ -182,8 +222,13 @@ function mockMouseType(char) { |
* @param type {String} The type of the touch event. |
*/ |
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); |
+ var rect = target.getBoundingClientRect(); |
+ e.pageX = rect.left; |
+ e.pageY = rect.top; |
target.dispatchEvent(e); |
} |