OLD | NEW |
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.content.ClipData; | 7 import android.content.ClipData; |
8 import android.content.ClipboardManager; | 8 import android.content.ClipboardManager; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.res.Configuration; | 10 import android.content.res.Configuration; |
(...skipping 14 matching lines...) Expand all Loading... |
25 import org.chromium.base.test.util.DisabledTest; | 25 import org.chromium.base.test.util.DisabledTest; |
26 import org.chromium.base.test.util.Feature; | 26 import org.chromium.base.test.util.Feature; |
27 import org.chromium.base.test.util.UrlUtils; | 27 import org.chromium.base.test.util.UrlUtils; |
28 import org.chromium.content.browser.test.ContentJUnit4ClassRunner; | 28 import org.chromium.content.browser.test.ContentJUnit4ClassRunner; |
29 import org.chromium.content.browser.test.util.Criteria; | 29 import org.chromium.content.browser.test.util.Criteria; |
30 import org.chromium.content.browser.test.util.CriteriaHelper; | 30 import org.chromium.content.browser.test.util.CriteriaHelper; |
31 import org.chromium.content.browser.test.util.DOMUtils; | 31 import org.chromium.content.browser.test.util.DOMUtils; |
32 import org.chromium.content.browser.test.util.JavaScriptUtils; | 32 import org.chromium.content.browser.test.util.JavaScriptUtils; |
33 import org.chromium.ui.base.ime.TextInputType; | 33 import org.chromium.ui.base.ime.TextInputType; |
34 | 34 |
| 35 import java.util.ArrayList; |
35 import java.util.concurrent.Callable; | 36 import java.util.concurrent.Callable; |
36 | 37 |
37 /** | 38 /** |
38 * IME (input method editor) and text input tests. | 39 * IME (input method editor) and text input tests. |
39 */ | 40 */ |
40 @RunWith(ContentJUnit4ClassRunner.class) | 41 @RunWith(ContentJUnit4ClassRunner.class) |
41 public class ImeTest { | 42 public class ImeTest { |
42 @Rule | 43 @Rule |
43 public ImeActivityTestRule mRule = new ImeActivityTestRule(); | 44 public ImeActivityTestRule mRule = new ImeActivityTestRule(); |
44 | 45 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 mRule.commitText("hello", 1); | 410 mRule.commitText("hello", 1); |
410 mRule.waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); | 411 mRule.waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); |
411 mRule.restartInput(); | 412 mRule.restartInput(); |
412 DOMUtils.clickNode(mRule.getContentViewCore(), "input_text"); | 413 DOMUtils.clickNode(mRule.getContentViewCore(), "input_text"); |
413 mRule.assertWaitForKeyboardStatus(true); | 414 mRule.assertWaitForKeyboardStatus(true); |
414 | 415 |
415 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); | 416 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); |
416 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); | 417 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); |
417 } | 418 } |
418 | 419 |
| 420 private static int getImeAction(EditorInfo editorInfo) { |
| 421 return editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION; |
| 422 } |
| 423 |
| 424 @Test |
| 425 @SmallTest |
| 426 @Feature({"TextInput", "Main"}) |
| 427 public void testAdvanceFocusNextAndPrevious() throws Exception { |
| 428 mRule.focusElement("textarea"); |
| 429 // Forward direction focus. Excessive focus advance should be ignored. |
| 430 for (int i = 0; i < 10; ++i) { |
| 431 // Forward direction focus. |
| 432 mRule.performEditorAction(EditorInfo.IME_ACTION_NEXT); |
| 433 } |
| 434 mRule.waitForKeyboardStates(7, 0, 7, |
| 435 new Integer[] {TextInputType.TEXT_AREA, TextInputType.TEXT_AREA, |
| 436 TextInputType.NUMBER, TextInputType.NUMBER, TextInputTyp
e.CONTENT_EDITABLE, |
| 437 TextInputType.SEARCH, TextInputType.TEXT}); |
| 438 ArrayList<EditorInfo> editorInfoList = |
| 439 mRule.getInputMethodManagerWrapper().getEditorInfoList(); |
| 440 Assert.assertEquals(7, editorInfoList.size()); |
| 441 // textarea. |
| 442 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(0))); |
| 443 // textarea2. |
| 444 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(1))); |
| 445 // input_number1. |
| 446 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(2))); |
| 447 // input_number2. |
| 448 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(3))); |
| 449 // content_editable1. |
| 450 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(4))); |
| 451 // search1. |
| 452 Assert.assertEquals(EditorInfo.IME_ACTION_SEARCH, getImeAction(editorInf
oList.get(5))); |
| 453 // input_text1. |
| 454 Assert.assertEquals(EditorInfo.IME_ACTION_GO, getImeAction(editorInfoLis
t.get(6))); |
| 455 |
| 456 mRule.resetAllStates(); |
| 457 |
| 458 // Backward direction focus. Excessive focus advance should be ignored. |
| 459 for (int i = 0; i < 10; ++i) { |
| 460 // Backward direction focus. |
| 461 mRule.performEditorAction(EditorInfo.IME_ACTION_PREVIOUS); |
| 462 } |
| 463 mRule.waitForKeyboardStates(6, 0, 6, |
| 464 new Integer[] {TextInputType.SEARCH, TextInputType.CONTENT_EDITA
BLE, |
| 465 TextInputType.NUMBER, TextInputType.NUMBER, TextInputTyp
e.TEXT_AREA, |
| 466 TextInputType.TEXT_AREA}); |
| 467 editorInfoList = mRule.getInputMethodManagerWrapper().getEditorInfoList(
); |
| 468 Assert.assertEquals(6, editorInfoList.size()); |
| 469 // search1. |
| 470 Assert.assertEquals(EditorInfo.IME_ACTION_SEARCH, getImeAction(editorInf
oList.get(0))); |
| 471 // content_editable1. |
| 472 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(1))); |
| 473 // input_number2. |
| 474 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(2))); |
| 475 // input_number1. |
| 476 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(3))); |
| 477 // textarea2. |
| 478 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(4))); |
| 479 // textarea. |
| 480 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(5))); |
| 481 } |
| 482 |
419 @Test | 483 @Test |
420 @SmallTest | 484 @SmallTest |
421 @DisabledTest(message = "crbug.com/694812") | 485 @DisabledTest(message = "crbug.com/694812") |
422 @Feature({"TextInput"}) | 486 @Feature({"TextInput"}) |
423 public void testShowAndHideSoftInput() throws Exception { | 487 public void testShowAndHideSoftInput() throws Exception { |
424 mRule.focusElement("input_radio", false); | 488 mRule.focusElement("input_radio", false); |
425 | 489 |
426 // hideSoftKeyboard(), mRule.restartInput() | 490 // hideSoftKeyboard(), mRule.restartInput() |
427 mRule.waitForKeyboardStates(0, 1, 1, new Integer[] {}); | 491 mRule.waitForKeyboardStates(0, 1, 1, new Integer[] {}); |
428 | 492 |
(...skipping 20 matching lines...) Expand all Loading... |
449 // reset internal states to handle the new input form. | 513 // reset internal states to handle the new input form. |
450 mRule.waitForKeyboardStates( | 514 mRule.waitForKeyboardStates( |
451 2, 1, 3, new Integer[] {TextInputType.NUMBER, TextInputType.NUMB
ER}); | 515 2, 1, 3, new Integer[] {TextInputType.NUMBER, TextInputType.NUMB
ER}); |
452 | 516 |
453 mRule.focusElement("input_text"); | 517 mRule.focusElement("input_text"); |
454 // showSoftInput() on input_text. mRule.restartInput() on input_number1
due to focus change, | 518 // showSoftInput() on input_text. mRule.restartInput() on input_number1
due to focus change, |
455 // and mRule.restartInput() on input_text later. | 519 // and mRule.restartInput() on input_text later. |
456 mRule.waitForKeyboardStates(3, 1, 4, | 520 mRule.waitForKeyboardStates(3, 1, 4, |
457 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT}); | 521 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT}); |
458 | 522 |
459 mRule.resetUpdateSelectionList(); | 523 mRule.resetAllStates(); |
460 mRule.setComposingText("a", 1); | 524 mRule.setComposingText("a", 1); |
461 mRule.waitAndVerifyUpdateSelection(0, 1, 1, 0, 1); | 525 mRule.waitAndVerifyUpdateSelection(0, 1, 1, 0, 1); |
462 mRule.resetUpdateSelectionList(); | 526 mRule.resetAllStates(); |
463 | 527 |
464 // JavaScript changes focus. | 528 // JavaScript changes focus. |
465 String code = "(function() { " | 529 String code = "(function() { " |
466 + "var textarea = document.getElementById('textarea');" | 530 + "var textarea = document.getElementById('textarea');" |
467 + "textarea.focus();" | 531 + "textarea.focus();" |
468 + "})();"; | 532 + "})();"; |
469 JavaScriptUtils.executeJavaScriptAndWaitForResult( | 533 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
470 mRule.getContentViewCore().getWebContents(), code); | 534 mRule.getContentViewCore().getWebContents(), code); |
471 mRule.waitAndVerifyUpdateSelection(0, 0, 0, -1, -1); | 535 mRule.waitAndVerifyUpdateSelection(0, 0, 0, -1, -1); |
472 mRule.resetUpdateSelectionList(); | 536 mRule.resetAllStates(); |
473 | 537 |
474 mRule.waitForKeyboardStates(4, 1, 5, | 538 mRule.waitForKeyboardStates(4, 1, 5, |
475 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT, | 539 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT, |
476 TextInputType.TEXT_AREA}); | 540 TextInputType.TEXT_AREA}); |
477 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); | 541 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); |
478 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); | 542 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); |
479 | 543 |
480 mRule.setComposingText("aa", 1); | 544 mRule.setComposingText("aa", 1); |
481 mRule.waitAndVerifyUpdateSelection(0, 2, 2, 0, 2); | 545 mRule.waitAndVerifyUpdateSelection(0, 2, 2, 0, 2); |
482 | 546 |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 }); | 1553 }); |
1490 Assert.assertEquals("abc", mRule.runBlockingOnImeThread(new Callable<Cha
rSequence>() { | 1554 Assert.assertEquals("abc", mRule.runBlockingOnImeThread(new Callable<Cha
rSequence>() { |
1491 @Override | 1555 @Override |
1492 public CharSequence call() throws Exception { | 1556 public CharSequence call() throws Exception { |
1493 return connection.getTextBeforeCursor(5, 0); | 1557 return connection.getTextBeforeCursor(5, 0); |
1494 } | 1558 } |
1495 })); | 1559 })); |
1496 } | 1560 } |
1497 | 1561 |
1498 } | 1562 } |
OLD | NEW |