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