Bug 855146 - Part 3: Add testInputAwesomeBar test for URL text. r=gbrown

This commit is contained in:
Chris Peterson 2013-03-26 17:02:21 -07:00
Родитель cf0f34871f
Коммит 069b8c07d1
2 изменённых файлов: 122 добавлений и 0 удалений

Просмотреть файл

@ -35,6 +35,7 @@
# [testJarReader] # see bug 738890
[testDistribution]
[testFindInPage]
[testInputAwesomeBar]
# Used for Talos, please don't use in mochitest
#[testPan]

Просмотреть файл

@ -0,0 +1,121 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
/**
* Basic test of text editing within the AwesomeBar.
* - Enter some text, move the cursor around, and modifying some text.
* - Check that all AwesomeBar text is selected after switching AwesomeScreen tabs.
*/
public final class testInputAwesomeBar extends BaseTest {
private Activity mAwesomeBarActivity;
private Element mAwesomeBarTextElement;
private EditText mAwesomeBarEditText;
public void testInputAwesomeBar() {
blockForGeckoReady();
openAwesomeScreen();
assertAwesomeBarText("about:home");
mActions.sendKeys("ab");
assertAwesomeBarText("ab");
mActions.sendKeys("cd");
assertAwesomeBarText("abcd");
mActions.sendSpecialKey(Actions.SpecialKey.LEFT);
mActions.sendSpecialKey(Actions.SpecialKey.LEFT);
// Inserting "" should not do anything.
mActions.sendKeys("");
assertAwesomeBarText("abcd");
mActions.sendKeys("ef");
assertAwesomeBarText("abefcd");
mActions.sendSpecialKey(Actions.SpecialKey.RIGHT);
mActions.sendKeys("gh");
assertAwesomeBarText("abefcghd");
final EditText editText = mAwesomeBarEditText;
runOnUiThreadSync(new Runnable() { public void run() {
// Select "ef"
editText.setSelection(2);
}});
mActions.sendKeys("op");
assertAwesomeBarText("abopefcghd");
runOnUiThreadSync(new Runnable() { public void run() {
// Select "cg"
editText.setSelection(6,8);
}});
mActions.sendKeys("qr");
assertAwesomeBarText("abopefqrhd");
runOnUiThreadSync(new Runnable() { public void run() {
// Select "op"
editText.setSelection(4,2);
}});
mActions.sendKeys("st");
assertAwesomeBarText("abstefqrhd");
runOnUiThreadSync(new Runnable() { public void run() {
editText.selectAll();
}});
mActions.sendKeys("uv");
assertAwesomeBarText("uv");
// BACK key should close the VKB, so typing should no longer affect the AwesomeBar text.
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
// Wait for about:home page to load.
waitForText("Add-ons for your");
// AwesomeBar should have forgotten about "uv" text.
openAwesomeScreen();
assertAwesomeBarText("about:home");
// Switch tabs so address bar loses input focus.
mSolo.clickOnText("Top Sites");
mSolo.clickOnText("Bookmarks");
mSolo.clickOnText("History");
mSolo.clickOnView(mAwesomeBarEditText);
mActions.sendKeys("yz");
// FIXME BUG 855134: Clicking back to the AwesomeBar after the VKB has closed should
// select all URL text. Instead it deselects the URL text and positions the cursor.
String yz = getAwesomeBarText();
mAsserter.ok("yz".equals(yz) || "about:homeyz".equals(yz),
"Is AwesomeBar text \"yz\" or \"about:homeyz\"?", yz);
}
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
private void openAwesomeScreen() {
mAwesomeBarActivity = clickOnAwesomeBar();
mAwesomeBarTextElement = mDriver.findElement(mAwesomeBarActivity, "awesomebar_text");
int id = mAwesomeBarTextElement.getId();
mAwesomeBarEditText = (EditText) mAwesomeBarActivity.findViewById(id);
}
private String getAwesomeBarText() {
String elementText = mAwesomeBarTextElement.getText();
String editText = mAwesomeBarEditText.getText().toString();
mAsserter.is(editText, elementText, "Does AwesomeBar editText == elementText?");
return editText;
}
private void assertAwesomeBarText(String expectedText) {
String actualText = getAwesomeBarText();
mAsserter.is(actualText, expectedText, "Does AwesomeBar actualText == expectedText?");
}
}