Bug 1254797 - Post: assert that pinned position matches physical position in top sites r?mcomella draft
authorAndrzej Hunt <andrzej@ahunt.org>
Tue, 15 Mar 2016 14:44:43 -0700
changeset 341677 9a16c88b7508fc515d6ec899e9deefe6f4a88563
parent 341676 3ccbb1aa2950e35c4b47a62a92dc671c2301ad50
child 516441 8dd2b54f33dbb037f0ca96e88a9cff44d62f7637
push id13267
push userbmo:ahunt@mozilla.com
push dateThu, 17 Mar 2016 16:52:32 +0000
reviewersmcomella
bugs1254797
milestone47.0a1
Bug 1254797 - Post: assert that pinned position matches physical position in top sites r?mcomella MozReview-Commit-ID: JFkKlRvlwh1
mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TopSitesPanel.java
@@ -16,16 +16,18 @@ import java.util.Map;
 
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Restrictions;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.db.BrowserContract;
+import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserContract.Thumbnails;
 import org.mozilla.gecko.db.BrowserContract.TopSites;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
@@ -252,16 +254,28 @@ public class TopSitesPanel extends HomeF
              * @param  info    context menu info object to be updated
              * @param  cursor  used to update the context menu info object
              */
             private void updateContextMenuFromCursor(TopSitesGridContextMenuInfo info, Cursor cursor) {
                 info.url = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.URL));
                 info.title = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.TITLE));
                 info.type = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.TYPE));
                 info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.HISTORY_ID));
+
+                // Our unpinning code expects the onscreen position to be equal to the DB position
+                // for pinned items. Hence we need to assert that these are equal - otherwise
+                // deleting/editing pinned items won't work because we use the physical ID for
+                // pinning related operations. See Bug 1254797 for more context.
+                final int positionIndex = cursor.getColumnIndex(Bookmarks.POSITION);
+                if (positionIndex != -1) {
+                    final int dbPosition = cursor.getInt(positionIndex);
+                    if (dbPosition != info.position) {
+                        throw new IllegalStateException("Physical/onscreen site position doesn't correspond to db pinned position: expected=" + dbPosition + ", actual=" + info.position);
+                    }
+                }
             }
         });
 
         registerForContextMenu(mList);
         registerForContextMenu(mGrid);
     }
 
     @Override