1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testInputUrlBar.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import org.mozilla.gecko.Actions; 1.7 +import org.mozilla.gecko.Element; 1.8 +import org.mozilla.gecko.R; 1.9 + 1.10 +import android.widget.EditText; 1.11 + 1.12 +/** 1.13 + * Basic test of text editing within the editing mode. 1.14 + * - Enter some text, move the cursor around, and modifying some text. 1.15 + * - Check that all edit entry text is selected after switching about:home tabs. 1.16 + */ 1.17 +public final class testInputUrlBar extends BaseTest { 1.18 + private Element mUrlBarEditElement; 1.19 + private EditText mUrlBarEditView; 1.20 + 1.21 + public void testInputUrlBar() { 1.22 + blockForGeckoReady(); 1.23 + 1.24 + startEditingMode(); 1.25 + assertUrlBarText("about:home"); 1.26 + 1.27 + // Avoid any auto domain completion by using a prefix that matches 1.28 + // nothing, including about: pages 1.29 + mActions.sendKeys("zy"); 1.30 + assertUrlBarText("zy"); 1.31 + 1.32 + mActions.sendKeys("cd"); 1.33 + assertUrlBarText("zycd"); 1.34 + 1.35 + mActions.sendSpecialKey(Actions.SpecialKey.LEFT); 1.36 + mActions.sendSpecialKey(Actions.SpecialKey.LEFT); 1.37 + 1.38 + // Inserting "" should not do anything. 1.39 + mActions.sendKeys(""); 1.40 + assertUrlBarText("zycd"); 1.41 + 1.42 + mActions.sendKeys("ef"); 1.43 + assertUrlBarText("zyefcd"); 1.44 + 1.45 + mActions.sendSpecialKey(Actions.SpecialKey.RIGHT); 1.46 + mActions.sendKeys("gh"); 1.47 + assertUrlBarText("zyefcghd"); 1.48 + 1.49 + final EditText editText = mUrlBarEditView; 1.50 + runOnUiThreadSync(new Runnable() { 1.51 + public void run() { 1.52 + // Select "ef" 1.53 + editText.setSelection(2); 1.54 + } 1.55 + }); 1.56 + mActions.sendKeys("op"); 1.57 + assertUrlBarText("zyopefcghd"); 1.58 + 1.59 + runOnUiThreadSync(new Runnable() { 1.60 + public void run() { 1.61 + // Select "cg" 1.62 + editText.setSelection(6, 8); 1.63 + } 1.64 + }); 1.65 + mActions.sendKeys("qr"); 1.66 + assertUrlBarText("zyopefqrhd"); 1.67 + 1.68 + runOnUiThreadSync(new Runnable() { 1.69 + public void run() { 1.70 + // Select "op" 1.71 + editText.setSelection(4,2); 1.72 + } 1.73 + }); 1.74 + mActions.sendKeys("st"); 1.75 + assertUrlBarText("zystefqrhd"); 1.76 + 1.77 + runOnUiThreadSync(new Runnable() { 1.78 + public void run() { 1.79 + editText.selectAll(); 1.80 + } 1.81 + }); 1.82 + mActions.sendKeys("uv"); 1.83 + assertUrlBarText("uv"); 1.84 + 1.85 + // Dismiss the VKB 1.86 + mActions.sendSpecialKey(Actions.SpecialKey.BACK); 1.87 + 1.88 + // Dismiss editing mode 1.89 + mActions.sendSpecialKey(Actions.SpecialKey.BACK); 1.90 + 1.91 + waitForText("Enter Search or Address"); 1.92 + 1.93 + // URL bar should have forgotten about "uv" text. 1.94 + startEditingMode(); 1.95 + assertUrlBarText("about:home"); 1.96 + 1.97 + int width = mDriver.getGeckoWidth() / 2; 1.98 + int y = mDriver.getGeckoHeight() / 2; 1.99 + 1.100 + // Slide to the right, force URL bar entry to lose input focus 1.101 + mActions.drag(width, 0, y, y); 1.102 + 1.103 + // Select text and replace the content 1.104 + mSolo.clickOnView(mUrlBarEditView); 1.105 + mActions.sendKeys("yz"); 1.106 + 1.107 + String yz = getUrlBarText(); 1.108 + mAsserter.ok("yz".equals(yz), "Is the URL bar text \"yz\"?", yz); 1.109 + } 1.110 + 1.111 + private void startEditingMode() { 1.112 + focusUrlBar(); 1.113 + 1.114 + mUrlBarEditElement = mDriver.findElement(getActivity(), R.id.url_edit_text); 1.115 + final int id = mUrlBarEditElement.getId(); 1.116 + mUrlBarEditView = (EditText) getActivity().findViewById(id); 1.117 + } 1.118 + 1.119 + private String getUrlBarText() { 1.120 + final String elementText = mUrlBarEditElement.getText(); 1.121 + final String editText = mUrlBarEditView.getText().toString(); 1.122 + mAsserter.is(editText, elementText, "Does URL bar editText == elementText?"); 1.123 + 1.124 + return editText; 1.125 + } 1.126 + 1.127 + private void assertUrlBarText(String expectedText) { 1.128 + String actualText = getUrlBarText(); 1.129 + mAsserter.is(actualText, expectedText, "Does URL bar actualText == expectedText?"); 1.130 + } 1.131 +}