Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 package org.mozilla.gecko.tests;
3 import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertEquals;
4 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertSelection;
5 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertSelectionAt;
6 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertText;
7 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertTextAndSelection;
8 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertTextAndSelectionAt;
10 import org.mozilla.gecko.tests.components.GeckoViewComponent.InputConnectionTest;
11 import org.mozilla.gecko.tests.helpers.GeckoHelper;
12 import org.mozilla.gecko.tests.helpers.NavigationHelper;
14 import android.view.inputmethod.EditorInfo;
15 import android.view.inputmethod.InputConnection;
17 /**
18 * Tests the proper operation of GeckoInputConnection
19 */
20 public class testInputConnection extends UITest {
22 private static final String INITIAL_TEXT = "foo";
24 public void testInputConnection() throws InterruptedException {
25 GeckoHelper.blockForReady();
27 NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_INPUT_URL + "#" + INITIAL_TEXT);
28 mToolbar.assertTitle(StringHelper.ROBOCOP_INPUT_TITLE);
30 mGeckoView.mTextInput
31 .waitForInputConnection()
32 .testInputConnection(new BasicInputConnectionTest());
33 }
35 private class BasicInputConnectionTest implements InputConnectionTest {
36 @Override
37 public void test(InputConnection ic, EditorInfo info) {
38 // Test initial text provided by the hash in the test page URL
39 assertText("Initial text matches URL hash", ic, INITIAL_TEXT);
41 // Test setSelection
42 ic.setSelection(0, 3);
43 assertSelection("Can set selection to range", ic, 0, 3);
44 ic.setSelection(-3, 6);
45 // Test both forms of assert
46 assertTextAndSelection("Can handle invalid range", ic, INITIAL_TEXT, 0, 3);
47 ic.setSelection(3, 3);
48 assertSelectionAt("Can collapse selection", ic, 3);
49 ic.setSelection(4, 4);
50 assertTextAndSelectionAt("Can handle invalid cursor", ic, INITIAL_TEXT, 3);
52 // Test commitText
53 ic.commitText("", 10); // Selection past end of new text
54 assertTextAndSelectionAt("Can commit empty text", ic, "foo", 3);
55 ic.commitText("bar", 1); // Selection at end of new text
56 assertTextAndSelectionAt("Can commit text (select after)", ic, "foobar", 6);
57 ic.commitText("foo", -1); // Selection at start of new text
58 assertTextAndSelectionAt("Can commit text (select before)", ic, "foobarfoo", 5);
60 // Test deleteSurroundingText
61 ic.deleteSurroundingText(1, 0);
62 assertTextAndSelectionAt("Can delete text before", ic, "foobrfoo", 4);
63 ic.deleteSurroundingText(1, 1);
64 assertTextAndSelectionAt("Can delete text before/after", ic, "foofoo", 3);
65 ic.deleteSurroundingText(0, 10);
66 assertTextAndSelectionAt("Can delete text after", ic, "foo", 3);
67 ic.deleteSurroundingText(0, 0);
68 assertTextAndSelectionAt("Can delete empty text", ic, "foo", 3);
70 // Test setComposingText
71 ic.setComposingText("foo", 1);
72 assertTextAndSelectionAt("Can start composition", ic, "foofoo", 6);
73 ic.setComposingText("", 1);
74 assertTextAndSelectionAt("Can set empty composition", ic, "foo", 3);
75 ic.setComposingText("bar", 1);
76 assertTextAndSelectionAt("Can update composition", ic, "foobar", 6);
78 // Test finishComposingText
79 ic.finishComposingText();
80 assertTextAndSelectionAt("Can finish composition", ic, "foobar", 6);
82 // Test getTextBeforeCursor
83 fAssertEquals("Can retrieve text before cursor", "bar", ic.getTextBeforeCursor(3, 0));
85 // Test getTextAfterCursor
86 fAssertEquals("Can retrieve text after cursor", "", ic.getTextAfterCursor(3, 0));
87 }
88 }
89 }