Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java

Issue 373523002: Send correct key-codes when doing composition events instead of always 0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser.input; 5 package org.chromium.content.browser.input;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.ClipData; 8 import android.content.ClipData;
9 import android.content.ClipboardManager; 9 import android.content.ClipboardManager;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 finishComposingText(mConnection); 258 finishComposingText(mConnection);
259 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 5, "hllo ", 1 , 1, -1, -1); 259 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 5, "hllo ", 1 , 1, -1, -1);
260 260
261 commitText(mConnection, "\n", 1); 261 commitText(mConnection, "\n", 1);
262 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 6, "h\nllo ", 2, 2, -1, -1); 262 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 6, "h\nllo ", 2, 2, -1, -1);
263 } 263 }
264 264
265 @SmallTest 265 @SmallTest
266 @Feature({"TextInput", "Main"}) 266 @Feature({"TextInput", "Main"})
267 public void testGuessedKeycodeFromTyping() throws Throwable {
268 assertEquals(0, ImeAdapter.getTypedKeycodeGuess(null, ""));
269 assertEquals(KeyEvent.KEYCODE_X, ImeAdapter.getTypedKeycodeGuess(null, " x"));
270 assertEquals(0, ImeAdapter.getTypedKeycodeGuess(null, "xyz"));
271
272 assertEquals(0, ImeAdapter.getTypedKeycodeGuess("abc", "abc"));
273 assertEquals(KeyEvent.KEYCODE_DEL, ImeAdapter.getTypedKeycodeGuess("abc" , ""));
274
275 assertEquals(KeyEvent.KEYCODE_H, ImeAdapter.getTypedKeycodeGuess("", "h" ));
276 assertEquals(KeyEvent.KEYCODE_DEL, ImeAdapter.getTypedKeycodeGuess("h", ""));
277 assertEquals(KeyEvent.KEYCODE_E, ImeAdapter.getTypedKeycodeGuess("h", "h e"));
278 assertEquals(KeyEvent.KEYCODE_L, ImeAdapter.getTypedKeycodeGuess("he", " hel"));
279 assertEquals(KeyEvent.KEYCODE_O, ImeAdapter.getTypedKeycodeGuess("hel", "helo"));
280 assertEquals(KeyEvent.KEYCODE_DEL, ImeAdapter.getTypedKeycodeGuess("helo ", "hel"));
281 assertEquals(KeyEvent.KEYCODE_L, ImeAdapter.getTypedKeycodeGuess("hel", "hell"));
282 assertEquals(KeyEvent.KEYCODE_L, ImeAdapter.getTypedKeycodeGuess("hell", "helll"));
283 assertEquals(KeyEvent.KEYCODE_DEL, ImeAdapter.getTypedKeycodeGuess("hell l", "hell"));
284 assertEquals(KeyEvent.KEYCODE_O, ImeAdapter.getTypedKeycodeGuess("hell", "hello"));
285
286 assertEquals(KeyEvent.KEYCODE_X, ImeAdapter.getTypedKeycodeGuess("xxx", "xxxx"));
287 assertEquals(KeyEvent.KEYCODE_X, ImeAdapter.getTypedKeycodeGuess("xxx", "xxxxx"));
288 assertEquals(KeyEvent.KEYCODE_DEL, ImeAdapter.getTypedKeycodeGuess("xxx" , "xx"));
289 assertEquals(KeyEvent.KEYCODE_DEL, ImeAdapter.getTypedKeycodeGuess("xxx" , "x"));
290
291 assertEquals(KeyEvent.KEYCODE_Y, ImeAdapter.getTypedKeycodeGuess("xxx", "xxxy"));
292 assertEquals(KeyEvent.KEYCODE_Y, ImeAdapter.getTypedKeycodeGuess("xxx", "xxxxy"));
293 assertEquals(0, ImeAdapter.getTypedKeycodeGuess("xxx", "xy"));
294 assertEquals(0, ImeAdapter.getTypedKeycodeGuess("xxx", "y"));
295
296 assertEquals(0, ImeAdapter.getTypedKeycodeGuess("foo", "bar"));
297 assertEquals(0, ImeAdapter.getTypedKeycodeGuess("foo", "bars"));
298 assertEquals(0, ImeAdapter.getTypedKeycodeGuess("foo", "ba"));
299 }
300
301 @SmallTest
302 @Feature({"TextInput", "Main"})
303 public void testKeyCodesWhileComposingText() throws Throwable {
304 DOMUtils.focusNode(mContentViewCore, "input_radio");
305 assertWaitForKeyboardStatus(false);
306 DOMUtils.focusNode(mContentViewCore, "textarea");
307 assertWaitForKeyboardStatus(true);
308
309 // The calls below are a reflection of what the stock Google Keyboard (A ndroid 4.4) sends
310 // when the noted key is touched on screen. Exercise care when altering to make sure
311 // that the test reflects reality.
312 mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
313 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);
314
315 // H
316 setComposingText(mConnection, "h", 1);
317 assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode);
318 assertEquals("h", mConnection.getTextBeforeCursor(9, 0));
319
320 // O
321 setComposingText(mConnection, "ho", 1);
322 assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode);
323 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0));
324
325 // DEL
326 setComposingText(mConnection, "h", 1);
327 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
328 assertEquals("h", mConnection.getTextBeforeCursor(9, 0));
329
330 // I
331 setComposingText(mConnection, "hi", 1);
332 assertEquals(KeyEvent.KEYCODE_I, mImeAdapter.mLastSyntheticKeyCode);
333 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));
334
335 // SPACE
336 commitText(mConnection, "hi",1);
337 assertEquals(0, mImeAdapter.mLastSyntheticKeyCode);
338 commitText(mConnection, " ", 1);
339 assertEquals(KeyEvent.KEYCODE_SPACE, mImeAdapter.mLastSyntheticKeyCode);
340 assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0));
341
342 // DEL
343 deleteSurroundingText(mConnection, 1, 0);
344 //assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
345 setComposingRegion(mConnection, 0, 2);
346 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));
347
348 // DEL
349 setComposingText(mConnection, "h", 1);
350 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
351 assertEquals("h", mConnection.getTextBeforeCursor(9, 0));
352
353 // DEL
354 setComposingText(mConnection, "", 1);
355 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
356 assertEquals("", mConnection.getTextBeforeCursor(9, 0));
357 }
358
359 @SmallTest
360 @Feature({"TextInput", "Main"})
267 public void testEnterKeyEventWhileComposingText() throws Throwable { 361 public void testEnterKeyEventWhileComposingText() throws Throwable {
268 DOMUtils.focusNode(mContentViewCore, "input_radio"); 362 DOMUtils.focusNode(mContentViewCore, "input_radio");
269 assertWaitForKeyboardStatus(false); 363 assertWaitForKeyboardStatus(false);
270 DOMUtils.focusNode(mContentViewCore, "textarea"); 364 DOMUtils.focusNode(mContentViewCore, "textarea");
271 assertWaitForKeyboardStatus(true); 365 assertWaitForKeyboardStatus(true);
272 366
273 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); 367 mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
274 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1); 368 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);
275 369
276 setComposingText(mConnection, "hello", 1); 370 setComposingText(mConnection, "hello", 1);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 536
443 private void finishComposingText(final AdapterInputConnection connection) { 537 private void finishComposingText(final AdapterInputConnection connection) {
444 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 538 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
445 @Override 539 @Override
446 public void run() { 540 public void run() {
447 connection.finishComposingText(); 541 connection.finishComposingText();
448 } 542 }
449 }); 543 });
450 } 544 }
451 545
546 private void deleteSurroundingText(final AdapterInputConnection connection, final int before,
547 final int after) {
548 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
549 @Override
550 public void run() {
551 connection.deleteSurroundingText(before, after);
552 }
553 });
554 }
555
452 private static class TestAdapterInputConnectionFactory extends 556 private static class TestAdapterInputConnectionFactory extends
453 ImeAdapter.AdapterInputConnectionFactory { 557 ImeAdapter.AdapterInputConnectionFactory {
454 @Override 558 @Override
455 public AdapterInputConnection get(View view, ImeAdapter imeAdapter, 559 public AdapterInputConnection get(View view, ImeAdapter imeAdapter,
456 Editable editable, EditorInfo outAttrs) { 560 Editable editable, EditorInfo outAttrs) {
457 return new TestAdapterInputConnection(view, imeAdapter, editable, ou tAttrs); 561 return new TestAdapterInputConnection(view, imeAdapter, editable, ou tAttrs);
458 } 562 }
459 } 563 }
460 564
461 private static class TestAdapterInputConnection extends AdapterInputConnecti on { 565 private static class TestAdapterInputConnection extends AdapterInputConnecti on {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 public void assertEqualState(String text, int selectionStart, int select ionEnd, 599 public void assertEqualState(String text, int selectionStart, int select ionEnd,
496 int compositionStart, int compositionEnd) { 600 int compositionStart, int compositionEnd) {
497 assertEquals("Text did not match", text, mText); 601 assertEquals("Text did not match", text, mText);
498 assertEquals("Selection start did not match", selectionStart, mSelec tionStart); 602 assertEquals("Selection start did not match", selectionStart, mSelec tionStart);
499 assertEquals("Selection end did not match", selectionEnd, mSelection End); 603 assertEquals("Selection end did not match", selectionEnd, mSelection End);
500 assertEquals("Composition start did not match", compositionStart, mC ompositionStart); 604 assertEquals("Composition start did not match", compositionStart, mC ompositionStart);
501 assertEquals("Composition end did not match", compositionEnd, mCompo sitionEnd); 605 assertEquals("Composition end did not match", compositionEnd, mCompo sitionEnd);
502 } 606 }
503 } 607 }
504 } 608 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698