Bug 968409 - Add testInputConnection with basic tests; r=cpeterson r=mcomella

This commit is contained in:
Jim Chen 2014-02-27 16:17:56 -05:00
Родитель 38effc9415
Коммит 037714007c
4 изменённых файлов: 105 добавлений и 0 удалений

Просмотреть файл

@ -76,6 +76,7 @@ public class StringHelper {
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";
@ -90,6 +91,7 @@ public class StringHelper {
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

Просмотреть файл

@ -97,4 +97,5 @@ skip-if = processor == "x86"
# Using UITest
[testAboutHomePageNavigation]
[testAboutHomeVisibility]
[testInputConnection]
[testSessionHistory]

Просмотреть файл

@ -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>

Просмотреть файл

@ -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));
}
}
}