mobile/android/base/tests/testInputUrlBar.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:a563ed37cc7a
1 package org.mozilla.gecko.tests;
2
3 import org.mozilla.gecko.Actions;
4 import org.mozilla.gecko.Element;
5 import org.mozilla.gecko.R;
6
7 import android.widget.EditText;
8
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;
17
18 public void testInputUrlBar() {
19 blockForGeckoReady();
20
21 startEditingMode();
22 assertUrlBarText("about:home");
23
24 // Avoid any auto domain completion by using a prefix that matches
25 // nothing, including about: pages
26 mActions.sendKeys("zy");
27 assertUrlBarText("zy");
28
29 mActions.sendKeys("cd");
30 assertUrlBarText("zycd");
31
32 mActions.sendSpecialKey(Actions.SpecialKey.LEFT);
33 mActions.sendSpecialKey(Actions.SpecialKey.LEFT);
34
35 // Inserting "" should not do anything.
36 mActions.sendKeys("");
37 assertUrlBarText("zycd");
38
39 mActions.sendKeys("ef");
40 assertUrlBarText("zyefcd");
41
42 mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
43 mActions.sendKeys("gh");
44 assertUrlBarText("zyefcghd");
45
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");
55
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");
64
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");
73
74 runOnUiThreadSync(new Runnable() {
75 public void run() {
76 editText.selectAll();
77 }
78 });
79 mActions.sendKeys("uv");
80 assertUrlBarText("uv");
81
82 // Dismiss the VKB
83 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
84
85 // Dismiss editing mode
86 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
87
88 waitForText("Enter Search or Address");
89
90 // URL bar should have forgotten about "uv" text.
91 startEditingMode();
92 assertUrlBarText("about:home");
93
94 int width = mDriver.getGeckoWidth() / 2;
95 int y = mDriver.getGeckoHeight() / 2;
96
97 // Slide to the right, force URL bar entry to lose input focus
98 mActions.drag(width, 0, y, y);
99
100 // Select text and replace the content
101 mSolo.clickOnView(mUrlBarEditView);
102 mActions.sendKeys("yz");
103
104 String yz = getUrlBarText();
105 mAsserter.ok("yz".equals(yz), "Is the URL bar text \"yz\"?", yz);
106 }
107
108 private void startEditingMode() {
109 focusUrlBar();
110
111 mUrlBarEditElement = mDriver.findElement(getActivity(), R.id.url_edit_text);
112 final int id = mUrlBarEditElement.getId();
113 mUrlBarEditView = (EditText) getActivity().findViewById(id);
114 }
115
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?");
120
121 return editText;
122 }
123
124 private void assertUrlBarText(String expectedText) {
125 String actualText = getUrlBarText();
126 mAsserter.is(actualText, expectedText, "Does URL bar actualText == expectedText?");
127 }
128 }

mercurial