Bug 1381001 - Bump the folder's last modified timestamp when deleting it. r=Grisha
authorjwu <topwu.tw@gmail.com>
Sun, 23 Jul 2017 15:30:10 +0800
changeset 370470 8e12f9e0619f51792f8dd6d1acb2eb355d98acae
parent 370469 46b12a5d51b89a211ea788909ec7e366f8e6ed0b
child 370471 162b4c3253c4d7acfb7251be61fdf5ec52f58a24
push id47031
push userryanvm@gmail.com
push dateSun, 23 Jul 2017 18:16:54 +0000
treeherderautoland@8e12f9e0619f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha
bugs1381001
milestone56.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 1381001 - Bump the folder's last modified timestamp when deleting it. r=Grisha MozReview-Commit-ID: DeBZatIrDVg
mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderBookmarksTest.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -2240,16 +2240,19 @@ public class BrowserProvider extends Sha
         values.putNull(Bookmarks.PARENT);
         values.putNull(Bookmarks.URL);
         values.putNull(Bookmarks.TITLE);
         values.putNull(Bookmarks.DESCRIPTION);
         values.putNull(Bookmarks.KEYWORD);
         values.putNull(Bookmarks.TAGS);
         values.putNull(Bookmarks.FAVICON_ID);
 
+        // Bump the lastModified timestamp for sync to know to update bookmark records.
+        values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis());
+
         // Leave space for variables in values.
         final int maxVariableNumber = DBUtils.SQLITE_MAX_VARIABLE_NUMBER - values.size();
 
         for (int chunk = 0; chunk <= bookmarkGUIDs.size() / maxVariableNumber; chunk++) {
             final int chunkStart = chunk * maxVariableNumber;
             int chunkEnd = (chunk + 1) * maxVariableNumber;
             if (chunkEnd > bookmarkGUIDs.size()) {
                 chunkEnd = bookmarkGUIDs.size();
--- 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
@@ -31,16 +31,17 @@ import static org.junit.Assert.assertTru
 
 /**
  * Testing direct interactions with bookmarks through BrowserProvider
  */
 @RunWith(TestRunner.class)
 public class BrowserProviderBookmarksTest {
 
     private static final long INVALID_ID = -1;
+    private static final long INVALID_TIMESTAMP = -1;
 
     private ContentProviderClient bookmarksClient;
     private Uri bookmarksTestUri;
     private BrowserProvider provider;
 
     @Before
     public void setUp() throws Exception {
         provider = new BrowserProvider();
@@ -137,16 +138,60 @@ public class BrowserProviderBookmarksTes
                 BrowserContract.Bookmarks.GUID + " = ?",
                 new String[] { "parent" });
 
         // 4 = parent, its two children, mobile root.
         assertEquals(4, changed);
     }
 
     @Test
+    public void testBookmarkFolderLastModifiedOnDeletion() throws RemoteException {
+        final long rootId = getBookmarkIdFromGuid(BrowserContract.Bookmarks.MOBILE_FOLDER_GUID);
+
+        // root
+        // -> sibling
+        // -> parent -- timestamp must change
+        // ---> child-1
+        // ---> child-2 -- delete this one
+
+        final Uri parentUri = insertBookmark("parent", null, "parent", rootId,
+                                             BrowserContract.Bookmarks.TYPE_FOLDER);
+        final Uri siblingUri = insertBookmark("sibling", null, "sibling", rootId,
+                                              BrowserContract.Bookmarks.TYPE_FOLDER);
+
+        final long parentId = Long.parseLong(parentUri.getLastPathSegment());
+        final Uri child1Uri = insertBookmark("child-1", null, "child-1", parentId,
+                                             BrowserContract.Bookmarks.TYPE_FOLDER);
+        final Uri child2Uri = insertBookmark("child-2", null, "child-2", parentId,
+                                             BrowserContract.Bookmarks.TYPE_FOLDER);
+
+        final long parentLastModifiedBeforeDeletion = getLastModified(parentUri);
+        final long siblingLastModifiedBeforeDeletion = getLastModified(siblingUri);
+
+        final long child1LastModifiedBeforeDeletion = getLastModified(child1Uri);
+        final long child2LastModifiedBeforeDeletion = getLastModified(child2Uri);
+
+        bookmarksClient.delete(child2Uri, null, null);
+
+        final long parentLastModifiedAfterDeletion = getLastModified(parentUri);
+        final long siblingLastModifiedAfterDeletion = getLastModified(siblingUri);
+
+        final long child1LastModifiedAfterDeletion = getLastModified(child1Uri);
+        final long child2LastModifiedAfterDeletion = getLastModified(withDeleted(child2Uri));
+
+        // Check last modified timestamp of parent and child-2 is increased.
+        assertTrue(parentLastModifiedAfterDeletion > parentLastModifiedBeforeDeletion);
+        assertTrue(child2LastModifiedAfterDeletion > child2LastModifiedBeforeDeletion);
+
+        // Check last modified timestamp of sibling and child-1 is not changed.
+        assertTrue(siblingLastModifiedBeforeDeletion == siblingLastModifiedAfterDeletion);
+        assertTrue(child1LastModifiedBeforeDeletion == child1LastModifiedAfterDeletion);
+    }
+
+    @Test
     public void testDeleteBookmarkFolder() throws RemoteException {
         final long rootId = getBookmarkIdFromGuid(BrowserContract.Bookmarks.MOBILE_FOLDER_GUID);
 
         // Create a folder.
         final Uri parentUri = insertBookmark("parent", null, "parent", rootId,
                                              BrowserContract.Bookmarks.TYPE_FOLDER);
         final long parentId = Long.parseLong(parentUri.getLastPathSegment());
 
@@ -235,16 +280,36 @@ public class BrowserProviderBookmarksTes
     private Uri testUri(Uri baseUri) {
         return baseUri.buildUpon().appendQueryParameter(BrowserContract.PARAM_IS_TEST, "1").build();
     }
 
     private Uri withDeleted(Uri baseUri) {
         return baseUri.buildUpon().appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "true").build();
     }
 
+    private long getLastModified(final Uri uri) throws RemoteException {
+        final Cursor cursor = bookmarksClient.query(uri,
+                                                    new String[] { BrowserContract.Bookmarks.DATE_MODIFIED },
+                                                    null,
+                                                    null,
+                                                    null);
+        assertNotNull(cursor);
+
+        long lastModified = INVALID_TIMESTAMP;
+        try {
+            assertTrue(cursor.moveToFirst());
+            assertEquals(1, cursor.getCount());
+            lastModified = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Bookmarks.DATE_MODIFIED));
+        } finally {
+            cursor.close();
+        }
+        assertNotEquals(lastModified, INVALID_TIMESTAMP);
+        return lastModified;
+    }
+
     private long getBookmarkIdFromGuid(String guid) throws RemoteException {
         Cursor cursor = bookmarksClient.query(BrowserContract.Bookmarks.CONTENT_URI,
                                               new String[] { BrowserContract.Bookmarks._ID },
                                               BrowserContract.Bookmarks.GUID + " = ?",
                                               new String[] { guid },
                                               null);
         assertNotNull(cursor);