Bug 1077590 - Part 3: fix testClearPrivateData by removing a flawed assumption in DatabaseHelper. r=me, Java-only on a CLOSED TREE (a=nigelb)
☠☠ backed out by 08c6d198e650 ☠ ☠
authorRichard Newman <rnewman@mozilla.com>
Sun, 11 Jan 2015 20:49:42 -0800
changeset 249105 cb1e6846d8385f4e3cc13ef9c04abc7c7c15e769
parent 249104 5fbb06da804d31daeea6181264f580f389da94e2
child 249106 a868809113e1fe589621232590403651f93aa46c
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, Java-only, nigelb
bugs1077590
milestone37.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 1077590 - Part 3: fix testClearPrivateData by removing a flawed assumption in DatabaseHelper. r=me, Java-only on a CLOSED TREE (a=nigelb) This helper class assumed that all cursors would allow you to navigate to the first item, and would assert if that's not true. But tests routinely attempted to check that cursors returned zero results! And moveToFirst is documented to return false if the cursor is empty. This patch does some cleanup, and also removes this flawed assumption.
mobile/android/base/tests/DatabaseHelper.java
mobile/android/base/tests/testClearPrivateData.java
--- a/mobile/android/base/tests/DatabaseHelper.java
+++ b/mobile/android/base/tests/DatabaseHelper.java
@@ -1,8 +1,12 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
 package org.mozilla.gecko.tests;
 
 import java.util.ArrayList;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.Assert;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.db.BrowserDB;
@@ -122,44 +126,43 @@ class DatabaseHelper {
      *
      * @return an ArrayList of the urls in the Firefox for Android Bookmarks or History databases.
      */
     protected ArrayList<String> getBrowserDBUrls(BrowserDataType dataType) {
         final ArrayList<String> browserData = new ArrayList<String>();
         final ContentResolver resolver = mActivity.getContentResolver();
 
         Cursor cursor = null;
-        try {
-            if (dataType == BrowserDataType.HISTORY) {
-                cursor = getProfileDB().getAllVisitedHistory(resolver);
-            } else if (dataType == BrowserDataType.BOOKMARKS) {
-                cursor = getProfileDB().getBookmarksInFolder(resolver, getFolderIdFromGuid("mobile"));
-            }
+        final BrowserDB db = getProfileDB();
+        if (dataType == BrowserDataType.HISTORY) {
+            cursor = db.getAllVisitedHistory(resolver);
+        } else if (dataType == BrowserDataType.BOOKMARKS) {
+            cursor = db.getBookmarksInFolder(resolver, getFolderIdFromGuid("mobile"));
+        }
 
-            if (cursor == null) {
-                mAsserter.ok(false, "We could not retrieve any data from the database", "The cursor was null");
-                return browserData;
-            }
+        if (cursor == null) {
+            mAsserter.ok(false, "We could not retrieve any data from the database", "The cursor was null");
+            return browserData;
+        }
 
+        try {
             if (!cursor.moveToFirst()) {
-                mAsserter.ok(false, "We could not move to the first item in the database", "moveToFirst failed");
+                // Nothing here, but that's OK -- maybe there are zero results. The calling test will fail.
                 return browserData;
             }
 
             do {
                 // The URL field may be null for folders in the structure of the Bookmarks table for Firefox. Eliminate those.
                 if (cursor.getString(cursor.getColumnIndex("url")) != null) {
                     browserData.add(cursor.getString(cursor.getColumnIndex("url")));
                 }
             } while (cursor.moveToNext());
+
+            return browserData;
         } finally {
-            if (cursor != null) {
-                cursor.close();
-            }
+            cursor.close();
         }
-
-        return browserData;
     }
 
     protected BrowserDB getProfileDB() {
         return GeckoProfile.get(mActivity).getDB();
     }
 }
--- a/mobile/android/base/tests/testClearPrivateData.java
+++ b/mobile/android/base/tests/testClearPrivateData.java
@@ -1,12 +1,19 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
 package org.mozilla.gecko.tests;
+
 import org.mozilla.gecko.Actions;
 import org.mozilla.gecko.R;
 
+import com.jayway.android.robotium.solo.Condition;
+
 import android.view.View;
 
 /**
  * This patch tests the clear private data options:
  * - clear history option by: adding and checking that clear private
  * data option removes the history items but not the users bookmarks
  * - clear site settings and clear saved password by: checking
  * each option present in the doorhanger and clearing the settings from
@@ -43,20 +50,20 @@ public class testClearPrivateData extend
         // Checking that history list is empty
         verifyHistoryCount(0);
 
         // Checking that the user made bookmark is not removed
         mAsserter.ok(mDatabaseHelper.isBookmark(blank2), "Checking that bookmarks have not been removed", "User made bookmarks were not removed with private data");
     }
 
     private void verifyHistoryCount(final int expectedCount) {
-        boolean match = waitForTest( new BooleanTest() {
+        boolean match = waitForCondition(new Condition() {
             @Override
-            public boolean test() {
-                return (mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size() == expectedCount);
+            public boolean isSatisfied() {
+                return mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size() == expectedCount;
             }
         }, TEST_WAIT_MS);
         mAsserter.ok(match, "Checking that the number of history items is correct", String.valueOf(expectedCount) + " history items present in the database");
     }
 
     public void clearSiteSettings() {
         String shareStrings[] = {"Share your location with", "Share", "Don't share", "There are no settings to clear"};
         String titleGeolocation = StringHelper.ROBOCOP_GEOLOCATION_TITLE;