Bug 912590 - Part 1: Update base tests to use new Robotium 4.2 APIs for View fetching. r=gbrown
authorChenxia Liu <liuche@mozilla.com>
Tue, 10 Sep 2013 18:10:29 -0700
changeset 146462 3500cc14c4a1d5bbdded4f2342dd8d1b434ad6a8
parent 146461 150bd140c640741103e8806f934e9f7f30702355
child 146463 8bceed557a76fe0af34ebec67588e848ecfda13f
push id2578
push usercliu@mozilla.com
push dateWed, 11 Sep 2013 01:11:05 +0000
treeherderfx-team@8bceed557a76 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs912590
milestone26.0a1
Bug 912590 - Part 1: Update base tests to use new Robotium 4.2 APIs for View fetching. r=gbrown
mobile/android/base/tests/BaseTest.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -191,17 +191,18 @@ abstract class BaseTest extends Activity
         mAsserter.ok(value.matches(regex), name, "Expected /" + regex +"/, got \"" + value + "\"");
     }
 
     /**
      * Click on the URL bar to focus it and enter editing mode.
      */
     protected final void focusUrlBar() {
         // Click on the browser toolbar to enter editing mode
-        mDriver.findElement(mActivity, BROWSER_TOOLBAR_ID).click();
+        final View toolbarView = mSolo.getView(BROWSER_TOOLBAR_ID);
+        mSolo.clickOnView(toolbarView);
 
         // Wait for highlighed text to gain focus
         boolean success = waitForTest(new BooleanTest() {
             @Override
             public boolean test() {
                 EditText urlEditText = mSolo.getEditText(0);
                 if (urlEditText.isInputMethodTarget()) {
                     return true;
@@ -217,17 +218,17 @@ abstract class BaseTest extends Activity
 
     protected final void enterUrl(String url) {
         focusUrlBar();
 
         // Send the keys for the URL we want to enter
         mActions.sendKeys(url);
 
         // Get the URL text from the URL bar EditText view
-        String urlBarText = mDriver.findElement(mActivity, URL_EDIT_TEXT_ID).getText();
+        String urlBarText = ((EditText) mSolo.getView(URL_EDIT_TEXT_ID)).getText().toString();
         mAsserter.is(url, urlBarText, "URL typed properly");
     }
 
     protected final Fragment getBrowserSearch() {
         final FragmentManager fm = ((FragmentActivity) getActivity()).getSupportFragmentManager();
         return fm.findFragmentByTag("browser_search");
     }
 
@@ -267,42 +268,40 @@ abstract class BaseTest extends Activity
             loadUrl.invoke(tabs, new Object[] { url });
         } catch (Exception e) {
             mAsserter.dumpLog("Exception in loadUrl", e);
             throw new RuntimeException(e);
         }
     }
 
     public final void verifyUrl(String url) {
-        Element urlEditText = mDriver.findElement(mActivity, URL_EDIT_TEXT_ID);
+        final EditText urlEditText = (EditText) mSolo.getView(URL_EDIT_TEXT_ID);
         String urlBarText = null;
         if (urlEditText != null) {
             // wait for a short time for the expected text, in case there is a delay
             // in updating the view
-            waitForTest(new VerifyUrlTest(urlEditText, url), VERIFY_URL_TIMEOUT);
-            urlBarText = urlEditText.getText();
+            waitForTest(new VerifyTextViewText(urlEditText, url), VERIFY_URL_TIMEOUT);
+            urlBarText = urlEditText.getText().toString();
+
         }
         mAsserter.is(urlBarText, url, "Browser toolbar URL stayed the same");
     }
 
-    class VerifyUrlTest implements BooleanTest {
-        private Element mUrlEditText;
-        private String mUrl;
-        public VerifyUrlTest(Element urlEditText, String url) {
-            mUrlEditText = urlEditText;
-            mUrl = url;
+    class VerifyTextViewText implements BooleanTest {
+        private TextView mTextView;
+        private String mExpected;
+        public VerifyTextViewText(TextView textView, String expected) {
+            mTextView = textView;
+            mExpected = expected;
         }
 
         @Override
         public boolean test() {
-            String urlbarText = mUrlEditText.getText();
-            if (urlbarText.equals(mUrl)) {
-                return true;
-            }
-            return false;
+            String textValue = mTextView.getText().toString();
+            return mExpected.equals(textValue);
         }
     }
 
     protected final String getAbsoluteUrl(String url) {
         return mBaseUrl + "/" + url.replaceAll("(^/)", "");
     }
 
     protected final String getAbsoluteRawUrl(String url) {
@@ -480,61 +479,42 @@ abstract class BaseTest extends Activity
                 mSolo.clickOnText("(^More$|^Tools$)");
             }
             waitForText(itemName);
             mSolo.clickOnText(itemName);
         }
     }
 
     public final void verifyHomePagerHidden() {
-        final Element homePagerElement = mDriver.findElement(mActivity, "home_pager");
-        final View homePagerView = mActivity.findViewById(homePagerElement.getId());
+        final View homePagerView = mSolo.getView("home_pager");
 
         boolean rc = waitForTest(new BooleanTest() {
             @Override
             public boolean test() {
                 return homePagerView.getVisibility() != View.VISIBLE;
             }
         }, MAX_WAIT_HOME_PAGER_HIDDEN_MS);
 
         if (!rc) {
             mAsserter.ok(rc, "Verify HomePager is hidden", "HomePager is hidden");
         }
     }
 
     public final void verifyPageTitle(String title) {
-        Element urlBarTitle = mDriver.findElement(getActivity(), URL_BAR_TITLE_ID);
+        final TextView urlBarTitle = (TextView) mSolo.getView(URL_BAR_TITLE_ID);
         String pageTitle = null;
         if (urlBarTitle != null) {
             // Wait for the title to make sure it has been displayed in case the view
             // does not update fast enough
-            waitForTest(new VerifyTitle(urlBarTitle, title), MAX_WAIT_MS);
-            pageTitle = urlBarTitle.getText();
+            waitForTest(new VerifyTextViewText(urlBarTitle, title), MAX_WAIT_MS);
+            pageTitle = urlBarTitle.getText().toString();
         }
         mAsserter.is(pageTitle, title, "Page title is correct");
     }
 
-    class VerifyTitle implements BooleanTest {
-        private Element mUrlBarTitle;
-        private String mTitle;
-        public VerifyTitle(Element urlBarTitle, String title) {
-            mUrlBarTitle = urlBarTitle;
-            mTitle = title;
-        }
-
-        @Override
-        public boolean test() {
-            String pageTitle = mUrlBarTitle.getText();
-            if (pageTitle.equals(mTitle)) {
-                return true;
-            }
-            return false;
-        }
-    }
-
     public final void verifyTabCount(int expectedTabCount) {
         Activity activity = getActivity();
         Element tabCount = mDriver.findElement(activity, "tabs_counter");
         String tabCountText = tabCount.getText();
         int tabCountInt = Integer.parseInt(tabCountText);
         mAsserter.is(tabCountInt, expectedTabCount, "The correct number of tabs are opened");
     }
 
@@ -555,36 +535,31 @@ abstract class BaseTest extends Activity
 
     // Used to hide/show the virtual keyboard
     public void toggleVKB() {
         InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
         imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
     }
 
     public void addTab(String url) {
-        Element tabs = null;
-        Element addTab = null;
-        Activity activity = getActivity();
-        tabs = mDriver.findElement(activity, "tabs");
-        addTab = mDriver.findElement(activity, "add_tab");
-        final int addTabId = addTab.getId();
-        mAsserter.ok(tabs.click(), "checking that tabs clicked", "tabs element clicked");
+        mSolo.clickOnView(mSolo.getView("tabs"));
         // wait for addTab to appear (this is usually immediate)
         boolean success = waitForTest(new BooleanTest() {
             @Override
             public boolean test() {
-                View addTabView = getActivity().findViewById(addTabId);
+                View addTabView = mSolo.getView("add_tab");
                 if (addTabView == null) {
                     return false;
                 }
                 return true;
             }
         }, MAX_WAIT_MS);
         mAsserter.ok(success, "waiting for add tab view", "add tab view available");
-        mAsserter.ok(addTab.click(), "checking that add_tab clicked", "add_tab element clicked");
+        final View addTabView = mSolo.getView("add_tab");
+        mSolo.clickOnView(mSolo.getView("add_tab"));
 
         // Adding a new tab opens about:home, so now we just need to load the url in it.
         inputAndLoadUrl(url);
     }
 
     public final void runOnUiThreadSync(Runnable runnable) {
         RobocopUtils.runOnUiThreadSync(mActivity, runnable);
     }