From 4c02d4e050bb47ee03f64512ad233818b9c37638 Mon Sep 17 00:00:00 2001 From: Geoff Brown Date: Wed, 13 Feb 2013 08:54:44 -0700 Subject: [PATCH] Bug 840725: Cleanup robocop tab retrieval functions; r=jmaher --HG-- extra : rebase_source : de92ecbb4812bd8ff62e43403ccc2c35213e0b04 --- mobile/android/base/tests/BaseTest.java.in | 84 ++++++++++--------- .../base/tests/testAllPagesTab.java.in | 30 +------ .../base/tests/testAwesomebarSwipes.java.in | 12 --- 3 files changed, 49 insertions(+), 77 deletions(-) diff --git a/mobile/android/base/tests/BaseTest.java.in b/mobile/android/base/tests/BaseTest.java.in index e60dfed7905..372063c675b 100755 --- a/mobile/android/base/tests/BaseTest.java.in +++ b/mobile/android/base/tests/BaseTest.java.in @@ -5,27 +5,27 @@ 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.HashMap; -import android.view.View; -import android.os.Build; -import android.util.DisplayMetrics; -import android.widget.ListView; import java.util.ArrayList; +import java.util.HashMap; /** * A convenient base class suitable for most Robocop tests. @@ -49,8 +49,6 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2 { protected String mRawBaseUrl; private String mLogFile; protected String mProfile; - private static ListView bookmarkList; - private static ListView historyList; protected void blockForGeckoReady() { try { @@ -396,46 +394,56 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2 { 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 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 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 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"); - - historyList = null; mSolo.waitForText("Today|Yesterday"); - boolean success = waitForTest(new BooleanTest() { - public boolean test() { - final ArrayList views = mSolo.getCurrentListViews(); - for (ListView view : views) { - if (view.getTag().equals("history")) { - historyList = view; - return true; - } - } - return false; + + ArrayList 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) { diff --git a/mobile/android/base/tests/testAllPagesTab.java.in b/mobile/android/base/tests/testAllPagesTab.java.in index 671976fa509..27bcc1a690b 100644 --- a/mobile/android/base/tests/testAllPagesTab.java.in +++ b/mobile/android/base/tests/testAllPagesTab.java.in @@ -57,8 +57,7 @@ public class testAllPagesTab extends BaseTest { } 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); @@ -114,8 +113,7 @@ public class testAllPagesTab extends BaseTest { } 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); @@ -131,8 +129,7 @@ public class testAllPagesTab extends BaseTest { } 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); @@ -141,27 +138,6 @@ public class testAllPagesTab extends BaseTest { verifyUrl(url); } - private ListView getAllPagesList(String url) { - Activity awesomeBarActivity = clickOnAwesomeBar(); - mSolo.waitForText(bookmarks[0]); - - final ArrayList 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"); diff --git a/mobile/android/base/tests/testAwesomebarSwipes.java.in b/mobile/android/base/tests/testAwesomebarSwipes.java.in index 064b923d664..e2166d09909 100644 --- a/mobile/android/base/tests/testAwesomebarSwipes.java.in +++ b/mobile/android/base/tests/testAwesomebarSwipes.java.in @@ -56,16 +56,4 @@ public class testAwesomebarSwipes extends BaseTest { mActions.sendSpecialKey(Actions.SpecialKey.BACK); } - - private ListView getAllPagesList(String url) { - Activity awesomeBarActivity = clickOnAwesomeBar(); - mSolo.waitForText(url); - - ArrayList views = mSolo.getCurrentListViews(); - for (ListView view : views) { - if (view.getTag() == "allPages") - return view; - } - return null; - } }