michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: import org.mozilla.gecko.Element; michael@0: import org.mozilla.gecko.R; michael@0: michael@0: import android.widget.EditText; michael@0: michael@0: /** michael@0: * Basic test of text editing within the editing mode. michael@0: * - Enter some text, move the cursor around, and modifying some text. michael@0: * - Check that all edit entry text is selected after switching about:home tabs. michael@0: */ michael@0: public final class testInputUrlBar extends BaseTest { michael@0: private Element mUrlBarEditElement; michael@0: private EditText mUrlBarEditView; michael@0: michael@0: public void testInputUrlBar() { michael@0: blockForGeckoReady(); michael@0: michael@0: startEditingMode(); michael@0: assertUrlBarText("about:home"); michael@0: michael@0: // Avoid any auto domain completion by using a prefix that matches michael@0: // nothing, including about: pages michael@0: mActions.sendKeys("zy"); michael@0: assertUrlBarText("zy"); michael@0: michael@0: mActions.sendKeys("cd"); michael@0: assertUrlBarText("zycd"); michael@0: michael@0: mActions.sendSpecialKey(Actions.SpecialKey.LEFT); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.LEFT); michael@0: michael@0: // Inserting "" should not do anything. michael@0: mActions.sendKeys(""); michael@0: assertUrlBarText("zycd"); michael@0: michael@0: mActions.sendKeys("ef"); michael@0: assertUrlBarText("zyefcd"); michael@0: michael@0: mActions.sendSpecialKey(Actions.SpecialKey.RIGHT); michael@0: mActions.sendKeys("gh"); michael@0: assertUrlBarText("zyefcghd"); michael@0: michael@0: final EditText editText = mUrlBarEditView; michael@0: runOnUiThreadSync(new Runnable() { michael@0: public void run() { michael@0: // Select "ef" michael@0: editText.setSelection(2); michael@0: } michael@0: }); michael@0: mActions.sendKeys("op"); michael@0: assertUrlBarText("zyopefcghd"); michael@0: michael@0: runOnUiThreadSync(new Runnable() { michael@0: public void run() { michael@0: // Select "cg" michael@0: editText.setSelection(6, 8); michael@0: } michael@0: }); michael@0: mActions.sendKeys("qr"); michael@0: assertUrlBarText("zyopefqrhd"); michael@0: michael@0: runOnUiThreadSync(new Runnable() { michael@0: public void run() { michael@0: // Select "op" michael@0: editText.setSelection(4,2); michael@0: } michael@0: }); michael@0: mActions.sendKeys("st"); michael@0: assertUrlBarText("zystefqrhd"); michael@0: michael@0: runOnUiThreadSync(new Runnable() { michael@0: public void run() { michael@0: editText.selectAll(); michael@0: } michael@0: }); michael@0: mActions.sendKeys("uv"); michael@0: assertUrlBarText("uv"); michael@0: michael@0: // Dismiss the VKB michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: michael@0: // Dismiss editing mode michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: michael@0: waitForText("Enter Search or Address"); michael@0: michael@0: // URL bar should have forgotten about "uv" text. michael@0: startEditingMode(); michael@0: assertUrlBarText("about:home"); michael@0: michael@0: int width = mDriver.getGeckoWidth() / 2; michael@0: int y = mDriver.getGeckoHeight() / 2; michael@0: michael@0: // Slide to the right, force URL bar entry to lose input focus michael@0: mActions.drag(width, 0, y, y); michael@0: michael@0: // Select text and replace the content michael@0: mSolo.clickOnView(mUrlBarEditView); michael@0: mActions.sendKeys("yz"); michael@0: michael@0: String yz = getUrlBarText(); michael@0: mAsserter.ok("yz".equals(yz), "Is the URL bar text \"yz\"?", yz); michael@0: } michael@0: michael@0: private void startEditingMode() { michael@0: focusUrlBar(); michael@0: michael@0: mUrlBarEditElement = mDriver.findElement(getActivity(), R.id.url_edit_text); michael@0: final int id = mUrlBarEditElement.getId(); michael@0: mUrlBarEditView = (EditText) getActivity().findViewById(id); michael@0: } michael@0: michael@0: private String getUrlBarText() { michael@0: final String elementText = mUrlBarEditElement.getText(); michael@0: final String editText = mUrlBarEditView.getText().toString(); michael@0: mAsserter.is(editText, elementText, "Does URL bar editText == elementText?"); michael@0: michael@0: return editText; michael@0: } michael@0: michael@0: private void assertUrlBarText(String expectedText) { michael@0: String actualText = getUrlBarText(); michael@0: mAsserter.is(actualText, expectedText, "Does URL bar actualText == expectedText?"); michael@0: } michael@0: }