Bug 897483 - Add waitForListToLoad() to BaseTest (r=margaret)
authorLucas Rocha <lucasr@mozilla.com>
Sat, 17 Aug 2013 14:24:25 +0100
changeset 143557 c67df6233bd1c9cf553fc6ddd5b37aad7219d45b
parent 143556 fbbc87078c3c5375d4f3edb2fe0219bd6bb5dedc
child 143558 c0a78c5c8988c792b34b2259843e5aed7576b3a7
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs897483
milestone26.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 897483 - Add waitForListToLoad() to BaseTest (r=margaret)
mobile/android/base/tests/AboutHomeTest.java.in
--- a/mobile/android/base/tests/AboutHomeTest.java.in
+++ b/mobile/android/base/tests/AboutHomeTest.java.in
@@ -5,16 +5,17 @@ import @ANDROID_PACKAGE_NAME@.*;
 
 import android.content.ContentResolver;
 import android.database.Cursor;
 import android.net.Uri;
 import android.support.v4.view.ViewPager;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.TabWidget;
+import android.widget.ListAdapter;
 import android.widget.ListView;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 
 /**
  * This class is an extension of BaseTest that helps with interaction with about:home
  * This class contains methods that access the different tabs from about:home, methods that get information like history and bookmarks from the database, edit and remove bookmarks and history items
@@ -71,16 +72,41 @@ abstract class AboutHomeTest extends Bas
             mAsserter.ok(false, "The wrong data type has been provided = " + dataType.toString(), "Please provide a BrowserDataType value");
         }
         uri = uri.buildUpon().appendQueryParameter("profile", "default")
                              .appendQueryParameter("sync", "true").build();
         return uri;
     }
 
     /**
+     * Waits for the given ListView to have a non-empty adapter.
+     *
+     * This method will fail if the given ListView or its adapter are null.
+     */
+    protected boolean waitForListToLoad(final ListView listView) {
+        boolean result = waitForTest(new BooleanTest() {
+            @Override
+            public boolean test() {
+                if (listView == null) {
+                    return false;
+                }
+
+                final ListAdapter adapter = listView.getAdapter();
+                if (adapter == null) {
+                    return false;
+                }
+
+                return (adapter.getCount() > 0);
+            }
+        }, MAX_WAIT_MS);
+
+        return result;
+    }
+
+    /**
      * Get an active ListView with the specified tag .
      *
      * This method uses the predefined tags in HomePager.
      */
     protected final ListView findListViewWithTag(String tag) {
         for (ListView listView : mSolo.getCurrentListViews()) {
             final String listTag = (String) listView.getTag();
             if (TextUtils.isEmpty(listTag)) {