From 069b8c07d1e3cd12cd72fc2e9025a3b39d4c972c Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Tue, 26 Mar 2013 17:02:21 -0700 Subject: [PATCH] Bug 855146 - Part 3: Add testInputAwesomeBar test for URL text. r=gbrown --- mobile/android/base/tests/robocop.ini | 1 + .../base/tests/testInputAwesomeBar.java.in | 121 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 mobile/android/base/tests/testInputAwesomeBar.java.in diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index 77148135e92a..eaea025c348b 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -35,6 +35,7 @@ # [testJarReader] # see bug 738890 [testDistribution] [testFindInPage] +[testInputAwesomeBar] # Used for Talos, please don't use in mochitest #[testPan] diff --git a/mobile/android/base/tests/testInputAwesomeBar.java.in b/mobile/android/base/tests/testInputAwesomeBar.java.in new file mode 100644 index 000000000000..e5fe597c588f --- /dev/null +++ b/mobile/android/base/tests/testInputAwesomeBar.java.in @@ -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?"); + } +}