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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 mRule.commitText("hello", 1); | 416 mRule.commitText("hello", 1); |
416 mRule.waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); | 417 mRule.waitAndVerifyUpdateSelection(0, 5, 5, -1, -1); |
417 mRule.restartInput(); | 418 mRule.restartInput(); |
418 DOMUtils.clickNode(mRule.getContentViewCore(), "input_text"); | 419 DOMUtils.clickNode(mRule.getContentViewCore(), "input_text"); |
419 mRule.assertWaitForKeyboardStatus(true); | 420 mRule.assertWaitForKeyboardStatus(true); |
420 | 421 |
421 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); | 422 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); |
422 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); | 423 Assert.assertEquals(5, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); |
423 } | 424 } |
424 | 425 |
| 426 private static int getImeAction(EditorInfo editorInfo) { |
| 427 return editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION; |
| 428 } |
| 429 |
| 430 @Test |
| 431 @SmallTest |
| 432 @Feature({"TextInput", "Main"}) |
| 433 public void testAdvanceFocusNextAndPrevious() throws Exception { |
| 434 mRule.focusElement("textarea"); |
| 435 // Forward direction focus. Excessive focus advance should be ignored. |
| 436 for (int i = 0; i < 10; ++i) { |
| 437 // Forward direction focus. |
| 438 mRule.performEditorAction(EditorInfo.IME_ACTION_NEXT); |
| 439 } |
| 440 mRule.waitForKeyboardStates(7, 0, 7, |
| 441 new Integer[] {TextInputType.TEXT_AREA, TextInputType.TEXT_AREA, |
| 442 TextInputType.NUMBER, TextInputType.NUMBER, TextInputTyp
e.CONTENT_EDITABLE, |
| 443 TextInputType.SEARCH, TextInputType.TEXT}); |
| 444 ArrayList<EditorInfo> editorInfoList = |
| 445 mRule.getInputMethodManagerWrapper().getEditorInfoList(); |
| 446 Assert.assertEquals(7, editorInfoList.size()); |
| 447 // textarea. |
| 448 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(0))); |
| 449 // textarea2. |
| 450 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(1))); |
| 451 // input_number1. |
| 452 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(2))); |
| 453 // input_number2. |
| 454 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(3))); |
| 455 // content_editable1. |
| 456 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(4))); |
| 457 // search1. |
| 458 Assert.assertEquals(EditorInfo.IME_ACTION_SEARCH, getImeAction(editorInf
oList.get(5))); |
| 459 // input_text1. |
| 460 Assert.assertEquals(EditorInfo.IME_ACTION_GO, getImeAction(editorInfoLis
t.get(6))); |
| 461 |
| 462 mRule.resetAllStates(); |
| 463 |
| 464 // Backward direction focus. Excessive focus advance should be ignored. |
| 465 for (int i = 0; i < 10; ++i) { |
| 466 // Backward direction focus. |
| 467 mRule.performEditorAction(EditorInfo.IME_ACTION_PREVIOUS); |
| 468 } |
| 469 mRule.waitForKeyboardStates(6, 0, 6, |
| 470 new Integer[] {TextInputType.SEARCH, TextInputType.CONTENT_EDITA
BLE, |
| 471 TextInputType.NUMBER, TextInputType.NUMBER, TextInputTyp
e.TEXT_AREA, |
| 472 TextInputType.TEXT_AREA}); |
| 473 editorInfoList = mRule.getInputMethodManagerWrapper().getEditorInfoList(
); |
| 474 Assert.assertEquals(6, editorInfoList.size()); |
| 475 // search1. |
| 476 Assert.assertEquals(EditorInfo.IME_ACTION_SEARCH, getImeAction(editorInf
oList.get(0))); |
| 477 // content_editable1. |
| 478 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(1))); |
| 479 // input_number2. |
| 480 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(2))); |
| 481 // input_number1. |
| 482 Assert.assertEquals(EditorInfo.IME_ACTION_NEXT, getImeAction(editorInfoL
ist.get(3))); |
| 483 // textarea2. |
| 484 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(4))); |
| 485 // textarea. |
| 486 Assert.assertEquals(EditorInfo.IME_ACTION_NONE, getImeAction(editorInfoL
ist.get(5))); |
| 487 } |
| 488 |
425 @Test | 489 @Test |
426 @SmallTest | 490 @SmallTest |
427 @DisabledTest(message = "crbug.com/694812") | 491 @DisabledTest(message = "crbug.com/694812") |
428 @Feature({"TextInput"}) | 492 @Feature({"TextInput"}) |
429 public void testShowAndHideSoftInput() throws Exception { | 493 public void testShowAndHideSoftInput() throws Exception { |
430 mRule.focusElement("input_radio", false); | 494 mRule.focusElement("input_radio", false); |
431 | 495 |
432 // hideSoftKeyboard(), mRule.restartInput() | 496 // hideSoftKeyboard(), mRule.restartInput() |
433 mRule.waitForKeyboardStates(0, 1, 1, new Integer[] {}); | 497 mRule.waitForKeyboardStates(0, 1, 1, new Integer[] {}); |
434 | 498 |
(...skipping 20 matching lines...) Expand all Loading... |
455 // reset internal states to handle the new input form. | 519 // reset internal states to handle the new input form. |
456 mRule.waitForKeyboardStates( | 520 mRule.waitForKeyboardStates( |
457 2, 1, 3, new Integer[] {TextInputType.NUMBER, TextInputType.NUMB
ER}); | 521 2, 1, 3, new Integer[] {TextInputType.NUMBER, TextInputType.NUMB
ER}); |
458 | 522 |
459 mRule.focusElement("input_text"); | 523 mRule.focusElement("input_text"); |
460 // showSoftInput() on input_text. mRule.restartInput() on input_number1
due to focus change, | 524 // showSoftInput() on input_text. mRule.restartInput() on input_number1
due to focus change, |
461 // and mRule.restartInput() on input_text later. | 525 // and mRule.restartInput() on input_text later. |
462 mRule.waitForKeyboardStates(3, 1, 4, | 526 mRule.waitForKeyboardStates(3, 1, 4, |
463 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT}); | 527 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT}); |
464 | 528 |
465 mRule.resetUpdateSelectionList(); | 529 mRule.resetAllStates(); |
466 mRule.setComposingText("a", 1); | 530 mRule.setComposingText("a", 1); |
467 mRule.waitAndVerifyUpdateSelection(0, 1, 1, 0, 1); | 531 mRule.waitAndVerifyUpdateSelection(0, 1, 1, 0, 1); |
468 mRule.resetUpdateSelectionList(); | 532 mRule.resetAllStates(); |
469 | 533 |
470 // JavaScript changes focus. | 534 // JavaScript changes focus. |
471 String code = "(function() { " | 535 String code = "(function() { " |
472 + "var textarea = document.getElementById('textarea');" | 536 + "var textarea = document.getElementById('textarea');" |
473 + "textarea.focus();" | 537 + "textarea.focus();" |
474 + "})();"; | 538 + "})();"; |
475 JavaScriptUtils.executeJavaScriptAndWaitForResult( | 539 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
476 mRule.getContentViewCore().getWebContents(), code); | 540 mRule.getContentViewCore().getWebContents(), code); |
477 mRule.waitAndVerifyUpdateSelection(0, 0, 0, -1, -1); | 541 mRule.waitAndVerifyUpdateSelection(0, 0, 0, -1, -1); |
478 mRule.resetUpdateSelectionList(); | 542 mRule.resetAllStates(); |
479 | 543 |
480 mRule.waitForKeyboardStates(4, 1, 5, | 544 mRule.waitForKeyboardStates(4, 1, 5, |
481 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT, | 545 new Integer[] {TextInputType.NUMBER, TextInputType.NUMBER, TextI
nputType.TEXT, |
482 TextInputType.TEXT_AREA}); | 546 TextInputType.TEXT_AREA}); |
483 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); | 547 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelStart); |
484 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); | 548 Assert.assertEquals(0, mRule.getConnectionFactory().getOutAttrs().initia
lSelEnd); |
485 | 549 |
486 mRule.setComposingText("aa", 1); | 550 mRule.setComposingText("aa", 1); |
487 mRule.waitAndVerifyUpdateSelection(0, 2, 2, 0, 2); | 551 mRule.waitAndVerifyUpdateSelection(0, 2, 2, 0, 2); |
488 | 552 |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 }); | 1566 }); |
1503 Assert.assertEquals("abc", mRule.runBlockingOnImeThread(new Callable<Cha
rSequence>() { | 1567 Assert.assertEquals("abc", mRule.runBlockingOnImeThread(new Callable<Cha
rSequence>() { |
1504 @Override | 1568 @Override |
1505 public CharSequence call() throws Exception { | 1569 public CharSequence call() throws Exception { |
1506 return connection.getTextBeforeCursor(5, 0); | 1570 return connection.getTextBeforeCursor(5, 0); |
1507 } | 1571 } |
1508 })); | 1572 })); |
1509 } | 1573 } |
1510 | 1574 |
1511 } | 1575 } |
OLD | NEW |