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