mobile/android/base/tests/testInputConnection.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial