diff --git a/src/main/java/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpers.java b/src/main/java/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpers.java index 7d4742a73..315b2e8ca 100644 --- a/src/main/java/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpers.java +++ b/src/main/java/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpers.java @@ -38,6 +38,8 @@ protected static Uri withSyncAndProfile(Uri u) { public static final Uri DELETED_PASSWORDS_CONTENT_URI = withSyncAndDeletedAndProfile(DeletedPasswords.CONTENT_URI); public static final Uri FORM_HISTORY_CONTENT_URI = withSyncAndProfile(FormHistory.CONTENT_URI); public static final Uri DELETED_FORM_HISTORY_CONTENT_URI = withSyncAndProfile(DeletedFormHistory.CONTENT_URI); + public static final Uri TABS_CONTENT_URI = withSyncAndProfile(Tabs.CONTENT_URI); + public static final Uri CLIENTS_CONTENT_URI = withSyncAndProfile(Clients.CONTENT_URI); public static final String[] PasswordColumns = new String[] { Passwords.ID, diff --git a/src/main/java/org/mozilla/gecko/sync/repositories/android/FennecTabsRepository.java b/src/main/java/org/mozilla/gecko/sync/repositories/android/FennecTabsRepository.java index 18c0c5642..d4cc48e96 100644 --- a/src/main/java/org/mozilla/gecko/sync/repositories/android/FennecTabsRepository.java +++ b/src/main/java/org/mozilla/gecko/sync/repositories/android/FennecTabsRepository.java @@ -73,9 +73,9 @@ protected void releaseProviders() { public FennecTabsRepositorySession(Repository repository, Context context) throws NoContentProviderException { super(repository); - clientsProvider = getContentProvider(context, BrowserContract.Clients.CONTENT_URI); + clientsProvider = getContentProvider(context, BrowserContractHelpers.CLIENTS_CONTENT_URI); try { - tabsProvider = getContentProvider(context, BrowserContract.Tabs.CONTENT_URI); + tabsProvider = getContentProvider(context, BrowserContractHelpers.TABS_CONTENT_URI); } catch (NoContentProviderException e) { clientsProvider.release(); throw e; @@ -85,7 +85,7 @@ public FennecTabsRepositorySession(Repository repository, Context context) throw throw new RuntimeException(e); } - tabsHelper = new RepoUtils.QueryHelper(context, BrowserContract.Tabs.CONTENT_URI, LOG_TAG); + tabsHelper = new RepoUtils.QueryHelper(context, BrowserContractHelpers.TABS_CONTENT_URI, LOG_TAG); } @Override @@ -225,7 +225,7 @@ public void run() { if (tabsRecord.deleted) { try { Logger.debug(LOG_TAG, "Clearing entry for client " + tabsRecord.guid); - clientsProvider.delete(BrowserContract.Clients.CONTENT_URI, + clientsProvider.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, CLIENT_GUID_IS, selectionArgs); delegate.onRecordStoreSucceeded(record.guid); @@ -239,20 +239,20 @@ public void run() { final ContentValues clientsCV = tabsRecord.getClientsContentValues(); Logger.debug(LOG_TAG, "Updating clients provider."); - final int updated = clientsProvider.update(BrowserContract.Clients.CONTENT_URI, + final int updated = clientsProvider.update(BrowserContractHelpers.CLIENTS_CONTENT_URI, clientsCV, CLIENT_GUID_IS, selectionArgs); if (0 == updated) { - clientsProvider.insert(BrowserContract.Clients.CONTENT_URI, clientsCV); + clientsProvider.insert(BrowserContractHelpers.CLIENTS_CONTENT_URI, clientsCV); } // Now insert tabs. final ContentValues[] tabsArray = tabsRecord.getTabsContentValues(); Logger.debug(LOG_TAG, "Inserting " + tabsArray.length + " tabs for client " + tabsRecord.guid); - tabsProvider.delete(BrowserContract.Tabs.CONTENT_URI, TABS_CLIENT_GUID_IS, selectionArgs); - final int inserted = tabsProvider.bulkInsert(BrowserContract.Tabs.CONTENT_URI, tabsArray); + tabsProvider.delete(BrowserContractHelpers.TABS_CONTENT_URI, TABS_CLIENT_GUID_IS, selectionArgs); + final int inserted = tabsProvider.bulkInsert(BrowserContractHelpers.TABS_CONTENT_URI, tabsArray); Logger.trace(LOG_TAG, "Inserted: " + inserted); delegate.onRecordStoreSucceeded(record.guid); @@ -269,8 +269,8 @@ public void run() { @Override public void wipe(RepositorySessionWipeDelegate delegate) { try { - tabsProvider.delete(BrowserContract.Tabs.CONTENT_URI, null, null); - clientsProvider.delete(BrowserContract.Clients.CONTENT_URI, null, null); + tabsProvider.delete(BrowserContractHelpers.TABS_CONTENT_URI, null, null); + clientsProvider.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, null, null); } catch (RemoteException e) { Logger.warn(LOG_TAG, "Got RemoteException in wipe.", e); delegate.onWipeFailed(e); diff --git a/src/main/java/org/mozilla/gecko/sync/repositories/android/FormHistoryRepositorySession.java b/src/main/java/org/mozilla/gecko/sync/repositories/android/FormHistoryRepositorySession.java index ebf9b7f01..e5ae82bf1 100644 --- a/src/main/java/org/mozilla/gecko/sync/repositories/android/FormHistoryRepositorySession.java +++ b/src/main/java/org/mozilla/gecko/sync/repositories/android/FormHistoryRepositorySession.java @@ -10,6 +10,7 @@ import java.util.concurrent.Callable; import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.db.BrowserContract.DeletedFormHistory; import org.mozilla.gecko.db.BrowserContract.FormHistory; import org.mozilla.gecko.sync.repositories.InactiveSessionException; @@ -75,7 +76,7 @@ public void createSession(RepositorySessionCreationDelegate delegate, */ public static ContentProviderClient acquireContentProvider(final Context context) throws NoContentProviderException { - Uri uri = FormHistory.CONTENT_URI; + Uri uri = BrowserContract.FORM_HISTORY_AUTHORITY_URI; ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(uri); if (client == null) { throw new NoContentProviderException(uri); @@ -123,6 +124,7 @@ public void finish(final RepositorySessionFinishDelegate delegate) @Override public void guidsSince(final long timestamp, final RepositorySessionGuidsSinceDelegate delegate) { Runnable command = new Runnable() { + @Override public void run() { if (!isActive()) { delegate.onGuidsSinceFailed(new InactiveSessionException(null)); @@ -703,6 +705,7 @@ public static void purgeDatabases(ContentProviderClient formsProvider) @Override public void wipe(final RepositorySessionWipeDelegate delegate) { Runnable command = new Runnable() { + @Override public void run() { if (!isActive()) { delegate.onWipeFailed(new InactiveSessionException(null)); diff --git a/test/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java b/test/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java index 10462d5e8..a123dfb69 100644 --- a/test/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java +++ b/test/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java @@ -10,6 +10,7 @@ import org.mozilla.gecko.db.BrowserContract; import org.mozilla.gecko.sync.repositories.NoContentProviderException; import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository; import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository.FennecTabsRepositorySession; import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; @@ -34,13 +35,14 @@ public class TestFennecTabsRepositorySession extends AndroidSyncTestCase { protected ContentProviderClient getTabsClient() { final ContentResolver cr = getApplicationContext().getContentResolver(); - return cr.acquireContentProviderClient(BrowserContract.Tabs.CONTENT_URI); + return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI); } public TestFennecTabsRepositorySession() throws NoContentProviderException { super(); } + @Override public void setUp() { if (tabsClient == null) { tabsClient = getTabsClient(); @@ -51,10 +53,11 @@ protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws R if (tabsClient == null) { return -1; } - return tabsClient.delete(BrowserContract.Tabs.CONTENT_URI, + return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS); } + @Override protected void tearDown() throws Exception { if (tabsClient != null) { deleteAllTestTabs(tabsClient); @@ -148,9 +151,9 @@ private void insertSomeTestTabs(ContentProviderClient tabsClient) throws RemoteE history3.add("http://test.com/test3.html#2"); testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000); - tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0)); - tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1)); - tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2)); } protected TabsRecord insertTestTabsAndExtractTabsRecord() throws RemoteException { @@ -159,7 +162,7 @@ protected TabsRecord insertTestTabsAndExtractTabsRecord() throws RemoteException final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; Cursor cursor = null; try { - cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS, positionAscending); CursorDumper.dumpCursor(cursor); diff --git a/test/src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java b/test/src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java index 5b03e2b4a..abfc2f2ba 100644 --- a/test/src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java +++ b/test/src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java @@ -5,6 +5,7 @@ import org.json.simple.JSONArray; import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import android.app.Activity; import android.content.ContentProviderClient; @@ -37,21 +38,22 @@ public TestFennecTabsStorage() { protected ContentProviderClient getClientsClient() { final ContentResolver cr = getInstrumentation().getTargetContext().getApplicationContext().getContentResolver(); - return cr.acquireContentProviderClient(BrowserContract.Clients.CONTENT_URI); + return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI); } protected ContentProviderClient getTabsClient() { final ContentResolver cr = getInstrumentation().getTargetContext().getApplicationContext().getContentResolver(); - return cr.acquireContentProviderClient(BrowserContract.Tabs.CONTENT_URI); + return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI); } protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws RemoteException { if (tabsClient == null) { return -1; } - return tabsClient.delete(BrowserContract.Tabs.CONTENT_URI, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }); + return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }); } + @Override protected void tearDown() throws Exception { deleteAllTestTabs(getTabsClient()); } @@ -73,9 +75,9 @@ protected void insertSomeTestTabs(ContentProviderClient tabsClient) throws Remot history3.add("http://test.com/test3.html#2"); testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000); - tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0)); - tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1)); - tabsClient.insert(BrowserContract.Tabs.CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2)); } // Sanity. @@ -90,7 +92,7 @@ public void testObtainCP() { } public void testWipeClients() throws RemoteException { - final Uri uri = BrowserContract.Clients.CONTENT_URI; + final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI; final ContentProviderClient clientsClient = getClientsClient(); // Have to ensure that it's empty… @@ -111,7 +113,7 @@ public void testWipeTabs() throws RemoteException { } public void testStoreAndRetrieveClients() throws RemoteException { - final Uri uri = BrowserContract.Clients.CONTENT_URI; + final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI; final ContentProviderClient clientsClient = getClientsClient(); // Have to ensure that it's empty… @@ -174,7 +176,7 @@ public void testTabFromCursor() throws Exception { final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; Cursor cursor = null; try { - cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); assertEquals(3, cursor.getCount()); cursor.moveToFirst(); diff --git a/test/src/org/mozilla/gecko/background/sync/TestTabsRecord.java b/test/src/org/mozilla/gecko/background/sync/TestTabsRecord.java index ced439c71..8e4fe0a12 100644 --- a/test/src/org/mozilla/gecko/background/sync/TestTabsRecord.java +++ b/test/src/org/mozilla/gecko/background/sync/TestTabsRecord.java @@ -6,6 +6,7 @@ import org.mozilla.gecko.background.db.CursorDumper; import org.mozilla.gecko.background.db.TestFennecTabsStorage; import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository; import org.mozilla.gecko.sync.repositories.domain.TabsRecord; @@ -22,7 +23,7 @@ public void testTabsRecordFromCursor() throws Exception { final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; Cursor cursor = null; try { - cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); assertEquals(3, cursor.getCount()); cursor.moveToPosition(1); @@ -55,7 +56,7 @@ public void testEmptyTabsRecordFromCursor() throws Exception { final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; Cursor cursor = null; try { - cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); assertEquals(0, cursor.getCount()); final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME); @@ -81,7 +82,7 @@ public void testLocalTabs() throws Exception { Cursor cursor = null; try { // Keep this in sync with the Fennec schema. - cursor = tabsClient.query(BrowserContract.Tabs.CONTENT_URI, null, BrowserContract.Tabs.CLIENT_GUID + " IS NULL", null, positionAscending); + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, BrowserContract.Tabs.CLIENT_GUID + " IS NULL", null, positionAscending); CursorDumper.dumpCursor(cursor); final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME);