mobile/android/base/tests/testInputUrlBar.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 package org.mozilla.gecko.tests;
     3 import org.mozilla.gecko.Actions;
     4 import org.mozilla.gecko.Element;
     5 import org.mozilla.gecko.R;
     7 import android.widget.EditText;
     9 /**
    10  * Basic test of text editing within the editing mode.
    11  * - Enter some text, move the cursor around, and modifying some text.
    12  * - Check that all edit entry text is selected after switching about:home tabs.
    13  */
    14 public final class testInputUrlBar extends BaseTest {
    15     private Element mUrlBarEditElement;
    16     private EditText mUrlBarEditView;
    18     public void testInputUrlBar() {
    19         blockForGeckoReady();
    21         startEditingMode();
    22         assertUrlBarText("about:home");
    24         // Avoid any auto domain completion by using a prefix that matches
    25         //  nothing, including about: pages
    26         mActions.sendKeys("zy");
    27         assertUrlBarText("zy");
    29         mActions.sendKeys("cd");
    30         assertUrlBarText("zycd");
    32         mActions.sendSpecialKey(Actions.SpecialKey.LEFT);
    33         mActions.sendSpecialKey(Actions.SpecialKey.LEFT);
    35         // Inserting "" should not do anything.
    36         mActions.sendKeys("");
    37         assertUrlBarText("zycd");
    39         mActions.sendKeys("ef");
    40         assertUrlBarText("zyefcd");
    42         mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
    43         mActions.sendKeys("gh");
    44         assertUrlBarText("zyefcghd");
    46         final EditText editText = mUrlBarEditView;
    47         runOnUiThreadSync(new Runnable() {
    48             public void run() {
    49                 // Select "ef"
    50                 editText.setSelection(2);
    51             }
    52         });
    53         mActions.sendKeys("op");
    54         assertUrlBarText("zyopefcghd");
    56         runOnUiThreadSync(new Runnable() {
    57             public void run() {
    58                 // Select "cg"
    59                 editText.setSelection(6, 8);
    60             }
    61         });
    62         mActions.sendKeys("qr");
    63         assertUrlBarText("zyopefqrhd");
    65         runOnUiThreadSync(new Runnable() {
    66             public void run() {
    67                 // Select "op"
    68                 editText.setSelection(4,2);
    69             }
    70         });
    71         mActions.sendKeys("st");
    72         assertUrlBarText("zystefqrhd");
    74         runOnUiThreadSync(new Runnable() {
    75             public void run() {
    76                 editText.selectAll();
    77             }
    78         });
    79         mActions.sendKeys("uv");
    80         assertUrlBarText("uv");
    82         // Dismiss the VKB
    83         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    85         // Dismiss editing mode
    86         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
    88         waitForText("Enter Search or Address");
    90         // URL bar should have forgotten about "uv" text.
    91         startEditingMode();
    92         assertUrlBarText("about:home");
    94         int width = mDriver.getGeckoWidth() / 2;
    95         int y = mDriver.getGeckoHeight() / 2;
    97         // Slide to the right, force URL bar entry to lose input focus
    98         mActions.drag(width, 0, y, y);
   100         // Select text and replace the content
   101         mSolo.clickOnView(mUrlBarEditView);
   102         mActions.sendKeys("yz");
   104         String yz = getUrlBarText();
   105         mAsserter.ok("yz".equals(yz), "Is the URL bar text \"yz\"?", yz);
   106     }
   108     private void startEditingMode() {
   109         focusUrlBar();
   111         mUrlBarEditElement = mDriver.findElement(getActivity(), R.id.url_edit_text);
   112         final int id = mUrlBarEditElement.getId();
   113         mUrlBarEditView = (EditText) getActivity().findViewById(id);
   114     }
   116     private String getUrlBarText() {
   117         final String elementText = mUrlBarEditElement.getText();
   118         final String editText = mUrlBarEditView.getText().toString();
   119         mAsserter.is(editText, elementText, "Does URL bar editText == elementText?");
   121         return editText;
   122     }
   124     private void assertUrlBarText(String expectedText) {
   125         String actualText = getUrlBarText();
   126         mAsserter.is(actualText, expectedText, "Does URL bar actualText == expectedText?");
   127     }
   128 }

mercurial