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.

--HG--
extra : amend_source : afc970d620a099e31fd54535b52aff7921b1b786
This commit is contained in:
Richard Newman 2015-01-11 20:49:42 -08:00
parent 424a11dac9
commit d6cc336acf
2 changed files with 31 additions and 21 deletions

View File

@ -1,3 +1,7 @@
/* 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;
@ -127,20 +131,21 @@ class DatabaseHelper {
final ContentResolver resolver = mActivity.getContentResolver();
Cursor cursor = null;
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;
}
try {
if (dataType == BrowserDataType.HISTORY) {
cursor = getProfileDB().getAllVisitedHistory(resolver);
} else if (dataType == BrowserDataType.BOOKMARKS) {
cursor = getProfileDB().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.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;
}
@ -150,13 +155,11 @@ class DatabaseHelper {
browserData.add(cursor.getString(cursor.getColumnIndex("url")));
}
} while (cursor.moveToNext());
} finally {
if (cursor != null) {
cursor.close();
}
}
return browserData;
return browserData;
} finally {
cursor.close();
}
}
protected BrowserDB getProfileDB() {

View File

@ -1,7 +1,14 @@
/* 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;
/**
@ -48,10 +55,10 @@ public class testClearPrivateData extends PixelTest {
}
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");