Bug 968409 - Add testInputConnection with basic tests; r=cpeterson r=mcomella
authorJim Chen <nchen@mozilla.com>
Thu, 27 Feb 2014 16:17:56 -0500
changeset 171357 ca6fe7cea127b0924e643a88e2a5c887daec8de6
parent 171356 38921bba8197f4f5ce1fd10ef3135ec31f564367
child 171358 b35c78057352cb4c9c1ca4039ca63cab7960775e
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerscpeterson, mcomella
bugs968409
milestone30.0a1
Bug 968409 - Add testInputConnection with basic tests; r=cpeterson r=mcomella
mobile/android/base/tests/StringHelper.java
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/robocop_input.html
mobile/android/base/tests/testInputConnection.java
--- a/mobile/android/base/tests/StringHelper.java
+++ b/mobile/android/base/tests/StringHelper.java
@@ -71,30 +71,32 @@ public class StringHelper {
     public static final String ROBOCOP_BOXES_URL = "/robocop/robocop_boxes.html";
     public static final String ROBOCOP_GEOLOCATION_URL = "/robocop/robocop_geolocation.html";
     public static final String ROBOCOP_LOGIN_URL = "/robocop/robocop_login.html";
     public static final String ROBOCOP_OFFLINE_STORAGE_URL = "/robocop/robocop_offline_storage.html";
     public static final String ROBOCOP_PICTURE_LINK_URL = "/robocop/robocop_picture_link.html";
     public static final String ROBOCOP_SEARCH_URL = "/robocop/robocop_search.html";
     public static final String ROBOCOP_TEXT_PAGE_URL = "/robocop/robocop_text_page.html";
     public static final String ROBOCOP_ADOBE_FLASH_URL = "/robocop/robocop_adobe_flash.html";
+    public static final String ROBOCOP_INPUT_URL = "/robocop/robocop_input.html";
 
     // Robocop page titles
     public static final String ROBOCOP_BIG_LINK_TITLE = "Big Link";
     public static final String ROBOCOP_BIG_MAILTO_TITLE = "Big Mailto";
     public static final String ROBOCOP_BLANK_PAGE_01_TITLE = "Browser Blank Page 01";
     public static final String ROBOCOP_BLANK_PAGE_02_TITLE = "Browser Blank Page 02";
     public static final String ROBOCOP_BLANK_PAGE_03_TITLE = "Browser Blank Page 03";
     public static final String ROBOCOP_BOXES_TITLE = "Browser Box test";
     public static final String ROBOCOP_GEOLOCATION_TITLE = "Geolocation Test Page";
     public static final String ROBOCOP_LOGIN_TITLE = "Robocop Login";
     public static final String ROBOCOP_OFFLINE_STORAGE_TITLE = "Robocop offline storage";
     public static final String ROBOCOP_PICTURE_LINK_TITLE = "Picture Link";
     public static final String ROBOCOP_SEARCH_TITLE = "Robocop Search Engine";
     public static final String ROBOCOP_TEXT_PAGE_TITLE = "Robocop Text Page";
+    public static final String ROBOCOP_INPUT_TITLE = "Robocop Input";
 
     // Settings menu strings
     // Section labels - ordered as found in the settings menu
     public static final String CUSTOMIZE_SECTION_LABEL = "Customize";
     public static final String DISPLAY_SECTION_LABEL = "Display";
     public static final String PRIVACY_SECTION_LABEL = "Privacy";
     public static final String MOZILLA_SECTION_LABEL = "Mozilla";
     public static final String DEVELOPER_TOOLS_SECTION_LABEL = "Developer tools";
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -92,9 +92,10 @@ skip-if = processor == "x86"
 #[testPan]
 #[testCheck]
 #[testCheck2]
 #[testBrowserProviderPerf]
 
 # Using UITest
 [testAboutHomePageNavigation]
 [testAboutHomeVisibility]
+[testInputConnection]
 [testSessionHistory]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/robocop_input.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Robocop Input</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  </head>
+  <body onload="fillInput()">
+    <input id="input">
+    <script>
+      function fillInput() {
+        // fill the input with the URL hash if provided
+        var input = document.getElementById("input");
+        input.value = window.location.hash.slice(1); // remove leading #
+        input.focus();
+      }
+    </script>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testInputConnection.java
@@ -0,0 +1,84 @@
+package org.mozilla.gecko.tests;
+
+import static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
+import static org.mozilla.gecko.tests.helpers.TextInputHelper.*;
+
+import org.mozilla.gecko.tests.components.GeckoViewComponent.InputConnectionTest;
+import org.mozilla.gecko.tests.helpers.*;
+
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+
+/**
+ * Tests the proper operation of GeckoInputConnection
+ */
+public class testInputConnection extends UITest {
+
+    private static final String INITIAL_TEXT = "foo";
+
+    public void testInputConnection() throws InterruptedException {
+        GeckoHelper.blockForReady();
+
+        NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_INPUT_URL + "#" + INITIAL_TEXT);
+        mToolbar.assertTitle(StringHelper.ROBOCOP_INPUT_TITLE);
+
+        mGeckoView.mTextInput
+            .waitForInputConnection()
+            .testInputConnection(new BasicInputConnectionTest());
+    }
+
+    private class BasicInputConnectionTest implements InputConnectionTest {
+        @Override
+        public void test(InputConnection ic, EditorInfo info) {
+            // Test initial text provided by the hash in the test page URL
+            assertText("Initial text matches URL hash", ic, INITIAL_TEXT);
+
+            // Test setSelection
+            ic.setSelection(0, 3);
+            assertSelection("Can set selection to range", ic, 0, 3);
+            ic.setSelection(-3, 6);
+            // Test both forms of assert
+            assertTextAndSelection("Can handle invalid range", ic, INITIAL_TEXT, 0, 3);
+            ic.setSelection(3, 3);
+            assertSelectionAt("Can collapse selection", ic, 3);
+            ic.setSelection(4, 4);
+            assertTextAndSelectionAt("Can handle invalid cursor", ic, INITIAL_TEXT, 3);
+
+            // Test commitText
+            ic.commitText("", 10); // Selection past end of new text
+            assertTextAndSelectionAt("Can commit empty text", ic, "foo", 3);
+            ic.commitText("bar", 1); // Selection at end of new text
+            assertTextAndSelectionAt("Can commit text (select after)", ic, "foobar", 6);
+            ic.commitText("foo", -1); // Selection at start of new text
+            assertTextAndSelectionAt("Can commit text (select before)", ic, "foobarfoo", 5);
+
+            // Test deleteSurroundingText
+            ic.deleteSurroundingText(1, 0);
+            assertTextAndSelectionAt("Can delete text before", ic, "foobrfoo", 4);
+            ic.deleteSurroundingText(1, 1);
+            assertTextAndSelectionAt("Can delete text before/after", ic, "foofoo", 3);
+            ic.deleteSurroundingText(0, 10);
+            assertTextAndSelectionAt("Can delete text after", ic, "foo", 3);
+            ic.deleteSurroundingText(0, 0);
+            assertTextAndSelectionAt("Can delete empty text", ic, "foo", 3);
+
+            // Test setComposingText
+            ic.setComposingText("foo", 1);
+            assertTextAndSelectionAt("Can start composition", ic, "foofoo", 6);
+            ic.setComposingText("", 1);
+            assertTextAndSelectionAt("Can set empty composition", ic, "foo", 3);
+            ic.setComposingText("bar", 1);
+            assertTextAndSelectionAt("Can update composition", ic, "foobar", 6);
+
+            // Test finishComposingText
+            ic.finishComposingText();
+            assertTextAndSelectionAt("Can finish composition", ic, "foobar", 6);
+
+            // Test getTextBeforeCursor
+            assertEquals("Can retrieve text before cursor", "bar", ic.getTextBeforeCursor(3, 0));
+
+            // Test getTextAfterCursor
+            assertEquals("Can retrieve text after cursor", "", ic.getTextAfterCursor(3, 0));
+        }
+    }
+}