Bug 840725: Cleanup robocop tab retrieval functions; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 13 Feb 2013 08:54:44 -0700
changeset 121757 2da3edf254fb39ad77385834a3c1b11333c7d2b2
parent 121756 7ec124ace4cbf38baa0a94643fd8314f0e7acff3
child 121758 5e63610b9072fcc9a52f9a5fd8f866e5b28a49f8
push id24307
push useremorley@mozilla.com
push dateThu, 14 Feb 2013 10:47:46 +0000
treeherdermozilla-central@aceeea086ccb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs840725
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 840725: Cleanup robocop tab retrieval functions; r=jmaher
mobile/android/base/tests/BaseTest.java.in
mobile/android/base/tests/testAllPagesTab.java.in
mobile/android/base/tests/testAwesomebarSwipes.java.in
--- a/mobile/android/base/tests/BaseTest.java.in
+++ b/mobile/android/base/tests/BaseTest.java.in
@@ -1,36 +1,36 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import com.jayway.android.robotium.solo.Solo;
 import @ANDROID_PACKAGE_NAME@.*;
 
 import android.app.Activity;
-import android.content.pm.ActivityInfo;
 import android.app.Instrumentation;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.ContentUris;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.content.res.AssetManager;
 import android.database.Cursor;
 import android.net.Uri;
+import android.os.Build;
 import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
+import android.util.DisplayMetrics;
+import android.view.View;
+import android.widget.ListView;
 import java.io.File;
 import java.io.InputStream;
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
-import android.view.View;
-import android.os.Build;
-import android.util.DisplayMetrics;
-import android.widget.ListView;
-import java.util.ArrayList;
 
 /**
  *  A convenient base class suitable for most Robocop tests.
  */
 abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
     public static final int TEST_MOCHITEST = 0;
     public static final int TEST_TALOS = 1;
 
@@ -44,18 +44,16 @@ abstract class BaseTest extends Activity
     protected Solo mSolo;
     protected Driver mDriver;
     protected Assert mAsserter;
     protected Actions mActions;
     protected String mBaseUrl;
     protected String mRawBaseUrl;
     private String mLogFile;
     protected String mProfile;
-    private static ListView bookmarkList;
-    private static ListView historyList;
 
     protected void blockForGeckoReady() {
         try {
             Actions.EventExpecter geckoReadyExpector = mActions.expectGeckoEvent("Gecko:Ready");
             ClassLoader classLoader = getActivity().getClassLoader();
             Class appsCls = classLoader.loadClass("org.mozilla.gecko.GeckoThread");
             Class launchStateCls = classLoader.loadClass("org.mozilla.gecko.GeckoThread$LaunchState");
             Method checkLaunchState =  appsCls.getMethod("checkLaunchState", launchStateCls);
@@ -391,56 +389,66 @@ abstract class BaseTest extends Activity
     public final void verifyTabCount(int expectedTabCount) {
         Activity activity = getActivity();
         Element tabCount = mDriver.findElement(activity, "tabs_count");
         String tabCountText = tabCount.getText();
         int tabCountInt = Integer.parseInt(tabCountText);
         mAsserter.is(tabCountInt, expectedTabCount, "The correct number of tabs are opened");
     }
 
-    public ListView getBookmarksList() {
+    /**
+     * Click on the awesome bar, and return the ListView for the 
+     * All Pages ("Top Sites") tab.
+     */
+    protected ListView getAllPagesList(String waitText) {
+        Activity awesomeBarActivity = clickOnAwesomeBar();
+        mSolo.waitForText(waitText);
+
+        ArrayList<ListView> views = mSolo.getCurrentListViews();
+        for (ListView view : views) {
+            if (view.getTag() == "allPages") {
+                return view;
+            }
+        }
+        return null;
+    }
+
+    /** 
+     * Click on the awesome bar, click on the Bookmarks tab, and return
+     * the ListView for the Bookmarks tab.
+     */
+    protected ListView getBookmarksList() {
         Activity awesomeBarActivity = clickOnAwesomeBar();
         mSolo.clickOnText("Bookmarks");
 
-        final ArrayList<ListView> views = mSolo.getCurrentListViews();
-
-        bookmarkList = null;
-        boolean success = waitForTest(new BooleanTest() {
-            public boolean test() {
-               for (ListView view : views) {
-                   if (view.getTag().equals("bookmarks")) {
-                       bookmarkList = view;
-                       return true;
-                   }
-               }
-               return false;
+        ArrayList<ListView> views = mSolo.getCurrentListViews();
+        for (ListView view : views) {
+            if (view.getTag().equals("bookmarks")) {
+                return view;
             }
-        }, MAX_WAIT_MS);
-        return bookmarkList;
+        }
+        return null;
     }
 
-    public ListView getHistoryList() {
+    /**
+     * Click on the awesome bar, click on the History tab, and return
+     * the ListView for the History tab.
+     */
+    protected ListView getHistoryList() {
         Activity awesomeBarActivity = clickOnAwesomeBar();
         mSolo.clickOnText("History");
+        mSolo.waitForText("Today|Yesterday");
 
-        historyList = null;
-        mSolo.waitForText("Today|Yesterday");
-        boolean success = waitForTest(new BooleanTest() {
-            public boolean test() {
-                final ArrayList<ListView> views = mSolo.getCurrentListViews();
-                for (ListView view : views) {
-                    if (view.getTag().equals("history")) {
-                        historyList = view;
-                        return true;
-                    }
-                }
-                return false;
+        ArrayList<ListView> views = mSolo.getCurrentListViews();
+        for (ListView view : views) {
+            if (view.getTag().equals("history")) {
+                return view;
             }
-        }, MAX_WAIT_MS);
-        return historyList;
+        }
+        return null;
     }
 
     public long addOrUpdateBookmark(String title, String url, boolean bookmarklet) {
         ContentResolver resolver = getActivity().getContentResolver();
         Uri bookmarksUri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
         bookmarksUri = bookmarksUri.buildUpon().appendQueryParameter("profile", "default").build();
         long folderId = -1;
         Cursor c = null;
--- a/mobile/android/base/tests/testAllPagesTab.java.in
+++ b/mobile/android/base/tests/testAllPagesTab.java.in
@@ -52,18 +52,17 @@ public class testAllPagesTab extends Bas
         loadUrl(url);
 
         testList(url);
         testClick(url);
         testContextMenu(url);
     }
 
     private void testList(String url) {
-        final ListView list = getAllPagesList(url);
-        mSolo.waitForText(bookmarks[0]);
+        final ListView list = getAllPagesList(bookmarks[0]);
 
         // some basic checks for the tab strip
         TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
         mAsserter.is(tabwidget.getTabCount(), 3, "Three tabs shown");
         mAsserter.is(tabwidget.isStripEnabled(), false, "Strip is hidden");
 
         // check that the right tab is selected
         TabHost host = (TabHost)mSolo.getView(TabHost.class, 0);
@@ -109,64 +108,41 @@ public class testAllPagesTab extends Bas
 
             mAsserter.is(visible, expectedImages, "Correct number of ImageViews visible");
         }
 
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
     }
 
     private void testContextMenu(String url) {
-        ListView list = getAllPagesList(url);
-        mSolo.waitForText(bookmarks[0]);
+        ListView list = getAllPagesList(bookmarks[0]);
 
         View child = list.getChildAt(0);
         mSolo.clickLongOnView(child);
 
         // TODO: Test clicking these does the right thing
         mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has New Tab option", "Open in New Tab");
         mAsserter.ok(mSolo.searchText("Share", true), "Context menu has Share option", "Share");
         mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
         mAsserter.ok(mSolo.searchText("Add to Home Screen", true), "Context menu has Add to Home Screen option", "Add to Home Screen");
 
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
     }
 
     private void testClick(String url) {
-        ListView list = getAllPagesList(url);
-        mSolo.waitForText(bookmarks[0]);
+        ListView list = getAllPagesList(bookmarks[0]);
 
         Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
         View child = list.getChildAt(0);
         mSolo.clickOnView(child);
         contentEventExpecter.blockForEvent();
         verifyUrl(url);
     }
 
-    private ListView getAllPagesList(String url) {
-        Activity awesomeBarActivity = clickOnAwesomeBar();
-        mSolo.waitForText(bookmarks[0]);
-
-        final ArrayList<ListView> views = mSolo.getCurrentListViews();
-
-        listview = null;
-        boolean success = waitForTest(new BooleanTest() {
-            public boolean test() {
-               for (ListView view : views) {
-                   if (view.getTag().equals("allPages")) {
-                       listview = view;
-                       return true;
-                   }
-               }
-               return false;
-            }
-        }, MAX_WAIT_MS);
-        return listview;
-    }
-
     public void tearDown() throws Exception {
         ContentResolver resolver = getActivity().getContentResolver();
         Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/history");
         uri = uri.buildUpon().appendQueryParameter("profile", "default")
                              .appendQueryParameter("sync", "true").build();
         resolver.delete(uri, "url = ?", new String[] {
             "http://mochi.test:8888/tests/robocop/robocop_big_link.html"
         });
--- a/mobile/android/base/tests/testAwesomebarSwipes.java.in
+++ b/mobile/android/base/tests/testAwesomebarSwipes.java.in
@@ -51,21 +51,9 @@ public class testAwesomebarSwipes extend
         mSolo.scrollToSide(Solo.LEFT);
         mAsserter.is(pager.getCurrentItem(), 0, "Dragging left is not allowed when searching");
 
         mSolo.scrollToSide(Solo.RIGHT);
         mAsserter.is(pager.getCurrentItem(), 0, "Dragging right is not allowed when searching");
 
         mActions.sendSpecialKey(Actions.SpecialKey.BACK);
     }
-
-    private ListView getAllPagesList(String url) {
-        Activity awesomeBarActivity = clickOnAwesomeBar();
-        mSolo.waitForText(url);
-
-        ArrayList<ListView> views = mSolo.getCurrentListViews();
-        for (ListView view : views) {
-            if (view.getTag() == "allPages")
-                return view;
-        }
-        return null;
-    }
 }