--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderBookmarksTest.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderBookmarksTest.java
@@ -16,16 +16,17 @@ import org.junit.runner.RunWith;
import org.mozilla.gecko.background.db.DelegatingTestContentProvider;
import org.mozilla.gecko.background.testhelpers.TestRunner;
import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
import org.robolectric.shadows.ShadowContentResolver;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -116,35 +117,75 @@ public class BrowserProviderBookmarksTes
rootId, BrowserContract.Bookmarks.TYPE_BOOKMARK);
changed = bookmarksClient.delete(bookmarksTestUri,
BrowserContract.Bookmarks.PARENT + " = ?",
new String[] { String.valueOf(rootId) });
assertEquals(4, changed);
+ final String parentGuid = "parent";
+
// Test that we correctly count affected records during deletions of subtrees.
- final Uri parentUri = insertBookmark("parent", null, "parent", rootId,
+ final Uri parentUri = insertBookmark(parentGuid, null, parentGuid, rootId,
BrowserContract.Bookmarks.TYPE_FOLDER);
final long parentId = Long.parseLong(parentUri.getLastPathSegment());
insertBookmark("bookmark-5", "https://www.mozilla-2.org", "guid-5",
parentId, BrowserContract.Bookmarks.TYPE_BOOKMARK);
insertBookmark("bookmark-6", "https://www.mozilla-3.org", "guid-6",
parentId, BrowserContract.Bookmarks.TYPE_BOOKMARK);
- // Directly under the root.
+
+ // Directly under the root, this shouldn't be deleted.
insertBookmark("bookmark-7", "https://www.mozilla-4.org", "guid-7",
rootId, BrowserContract.Bookmarks.TYPE_BOOKMARK);
+ // Insert a bunch of folders, triggering chunking logic.
+ for (int i = 0; i < 1500; i++) {
+ String guid = UUID.randomUUID().toString();
+ insertBookmark(guid, "https://www.mozilla-3.org", guid,
+ parentId, BrowserContract.Bookmarks.TYPE_FOLDER);
+ }
+
+ // Insert a folder with a lot of children, triggering chunking logic.
+ final Uri parentUri2 = insertBookmark("big folder", null, UUID.randomUUID().toString(), rootId,
+ BrowserContract.Bookmarks.TYPE_FOLDER);
+ final long parentId2 = Long.parseLong(parentUri2.getLastPathSegment());
+ for (int i = 0; i < 2000; i++) {
+ String guid = UUID.randomUUID().toString();
+ insertBookmark(guid, "https://www.mozilla-3.org", guid,
+ parentId2, BrowserContract.Bookmarks.TYPE_BOOKMARK);
+ }
+
changed = bookmarksClient.delete(bookmarksTestUri,
BrowserContract.Bookmarks.GUID + " = ?",
- new String[] { "parent" });
+ new String[] { parentGuid });
+
+ // 3504 = guid=parent, mobile root ('parent's parent), 2 regular folders, 1500 empty folders,
+ // 1 folder with 2000 children
+ assertEquals(3504, changed);
+
+ final String parentGuid2 = "parent-2";
+ final Uri parentUri3 = insertBookmark(parentGuid2, null, parentGuid2, rootId,
+ BrowserContract.Bookmarks.TYPE_FOLDER);
+ final long parentId3 = Long.parseLong(parentUri3.getLastPathSegment());
- // 4 = parent, its two children, mobile root.
- assertEquals(4, changed);
+ // Test that we can correctly delete a lot of bookmarks, triggering our "chunking logic".
+ for (int i = 0; i < 3000; i++) {
+ int id = 8 + i;
+ insertBookmark("bookmark-" + id, "https://www.mozilla-" + id + ".org", "guid-" + id,
+ parentId3, BrowserContract.Bookmarks.TYPE_BOOKMARK);
+ }
+
+ changed = bookmarksClient.delete(bookmarksTestUri,
+ BrowserContract.Bookmarks.GUID + " = ?",
+ new String[] { parentGuid2 });
+
+ // 3002 = parent-2, its 3000 children, mobile root
+ assertEquals(3002, changed);
}
@Test
public void testBookmarkFolderLastModifiedOnDeletion() throws RemoteException {
final long rootId = getBookmarkIdFromGuid(BrowserContract.Bookmarks.MOBILE_FOLDER_GUID);
// root
// -> sibling