michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import static org.mozilla.gecko.tests.helpers.AssertionHelper.fAssertEquals; michael@0: import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertSelection; michael@0: import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertSelectionAt; michael@0: import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertText; michael@0: import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertTextAndSelection; michael@0: import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertTextAndSelectionAt; michael@0: michael@0: import org.mozilla.gecko.tests.components.GeckoViewComponent.InputConnectionTest; michael@0: import org.mozilla.gecko.tests.helpers.GeckoHelper; michael@0: import org.mozilla.gecko.tests.helpers.NavigationHelper; michael@0: michael@0: import android.view.inputmethod.EditorInfo; michael@0: import android.view.inputmethod.InputConnection; michael@0: michael@0: /** michael@0: * Tests the proper operation of GeckoInputConnection michael@0: */ michael@0: public class testInputConnection extends UITest { michael@0: michael@0: private static final String INITIAL_TEXT = "foo"; michael@0: michael@0: public void testInputConnection() throws InterruptedException { michael@0: GeckoHelper.blockForReady(); michael@0: michael@0: NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_INPUT_URL + "#" + INITIAL_TEXT); michael@0: mToolbar.assertTitle(StringHelper.ROBOCOP_INPUT_TITLE); michael@0: michael@0: mGeckoView.mTextInput michael@0: .waitForInputConnection() michael@0: .testInputConnection(new BasicInputConnectionTest()); michael@0: } michael@0: michael@0: private class BasicInputConnectionTest implements InputConnectionTest { michael@0: @Override michael@0: public void test(InputConnection ic, EditorInfo info) { michael@0: // Test initial text provided by the hash in the test page URL michael@0: assertText("Initial text matches URL hash", ic, INITIAL_TEXT); michael@0: michael@0: // Test setSelection michael@0: ic.setSelection(0, 3); michael@0: assertSelection("Can set selection to range", ic, 0, 3); michael@0: ic.setSelection(-3, 6); michael@0: // Test both forms of assert michael@0: assertTextAndSelection("Can handle invalid range", ic, INITIAL_TEXT, 0, 3); michael@0: ic.setSelection(3, 3); michael@0: assertSelectionAt("Can collapse selection", ic, 3); michael@0: ic.setSelection(4, 4); michael@0: assertTextAndSelectionAt("Can handle invalid cursor", ic, INITIAL_TEXT, 3); michael@0: michael@0: // Test commitText michael@0: ic.commitText("", 10); // Selection past end of new text michael@0: assertTextAndSelectionAt("Can commit empty text", ic, "foo", 3); michael@0: ic.commitText("bar", 1); // Selection at end of new text michael@0: assertTextAndSelectionAt("Can commit text (select after)", ic, "foobar", 6); michael@0: ic.commitText("foo", -1); // Selection at start of new text michael@0: assertTextAndSelectionAt("Can commit text (select before)", ic, "foobarfoo", 5); michael@0: michael@0: // Test deleteSurroundingText michael@0: ic.deleteSurroundingText(1, 0); michael@0: assertTextAndSelectionAt("Can delete text before", ic, "foobrfoo", 4); michael@0: ic.deleteSurroundingText(1, 1); michael@0: assertTextAndSelectionAt("Can delete text before/after", ic, "foofoo", 3); michael@0: ic.deleteSurroundingText(0, 10); michael@0: assertTextAndSelectionAt("Can delete text after", ic, "foo", 3); michael@0: ic.deleteSurroundingText(0, 0); michael@0: assertTextAndSelectionAt("Can delete empty text", ic, "foo", 3); michael@0: michael@0: // Test setComposingText michael@0: ic.setComposingText("foo", 1); michael@0: assertTextAndSelectionAt("Can start composition", ic, "foofoo", 6); michael@0: ic.setComposingText("", 1); michael@0: assertTextAndSelectionAt("Can set empty composition", ic, "foo", 3); michael@0: ic.setComposingText("bar", 1); michael@0: assertTextAndSelectionAt("Can update composition", ic, "foobar", 6); michael@0: michael@0: // Test finishComposingText michael@0: ic.finishComposingText(); michael@0: assertTextAndSelectionAt("Can finish composition", ic, "foobar", 6); michael@0: michael@0: // Test getTextBeforeCursor michael@0: fAssertEquals("Can retrieve text before cursor", "bar", ic.getTextBeforeCursor(3, 0)); michael@0: michael@0: // Test getTextAfterCursor michael@0: fAssertEquals("Can retrieve text after cursor", "", ic.getTextAfterCursor(3, 0)); michael@0: } michael@0: } michael@0: }