Bug 1260478 - Post: Remove TabsProvider integration tests moved into unit tests. r?mcomella
None of these were run in automation anyway. I elected to hg rm,
rather than try to hg mv, since I reworked the tests a little for
Robolectric, including merging two into one. The history isn't
particularly valuable here.
MozReview-Commit-ID: 47eDYvS3l1y
--- a/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
+++ b/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild
@@ -13,17 +13,16 @@ background_junit3_sources = [
'src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java',
'src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryDataExtender.java',
'src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java',
'src/org/mozilla/gecko/background/db/TestBookmarks.java',
'src/org/mozilla/gecko/background/db/TestCachedSQLiteOpenHelper.java',
'src/org/mozilla/gecko/background/db/TestClientsDatabase.java',
'src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java',
'src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java',
- 'src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java',
'src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java',
'src/org/mozilla/gecko/background/db/TestPasswordsRepository.java',
'src/org/mozilla/gecko/background/db/TestTopSites.java',
'src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java',
'src/org/mozilla/gecko/background/fxa/TestAccountLoader.java',
'src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java',
'src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java',
'src/org/mozilla/gecko/background/helpers/BackgroundServiceTestCase.java',
@@ -61,17 +60,16 @@ background_junit3_sources = [
'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessCreationDelegate.java',
'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFetchDelegate.java',
'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFinishDelegate.java',
'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessStoreDelegate.java',
'src/org/mozilla/gecko/background/sync/TestClientsStage.java',
'src/org/mozilla/gecko/background/sync/TestResetting.java',
'src/org/mozilla/gecko/background/sync/TestStoreTracking.java',
'src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java',
- 'src/org/mozilla/gecko/background/sync/TestTabsRecord.java',
'src/org/mozilla/gecko/background/sync/TestWebURLFinder.java',
'src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java',
'src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java',
'src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java',
'src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java',
'src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java',
'src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java',
'src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java',
--- a/mobile/android/tests/background/junit3/instrumentation.ini
+++ b/mobile/android/tests/background/junit3/instrumentation.ini
@@ -8,20 +8,18 @@ subsuite = background
[src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java]
[src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryDataExtender.java]
[src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java]
[src/org/mozilla/gecko/background/db/TestBookmarks.java]
[src/org/mozilla/gecko/background/db/TestCachedSQLiteOpenHelper.java]
[src/org/mozilla/gecko/background/db/TestClientsDatabase.java]
[src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java]
[src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java]
-[src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java]
[src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java]
[src/org/mozilla/gecko/background/db/TestPasswordsRepository.java]
[src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java]
[src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java]
[src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java]
[src/org/mozilla/gecko/background/sync/TestClientsStage.java]
[src/org/mozilla/gecko/background/sync/TestResetting.java]
[src/org/mozilla/gecko/background/sync/TestStoreTracking.java]
[src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java]
-[src/org/mozilla/gecko/background/sync/TestTabsRecord.java]
[src/org/mozilla/gecko/background/sync/TestWebURLFinder.java]
deleted file mode 100644
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFennecTabsStorage.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.gecko.background.db;
-
-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;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.RemoteException;
-import android.test.ActivityInstrumentationTestCase2;
-
-/**
- * Exercise Fennec's tabs provider.
- *
- * @author rnewman
- *
- */
-public class TestFennecTabsStorage extends ActivityInstrumentationTestCase2<Activity> {
- public static final String TEST_CLIENT_GUID = "test guid"; // Real GUIDs never contain spaces.
- public static final String TEST_CLIENT_NAME = "test client name";
-
- public static final String CLIENTS_GUID_IS = BrowserContract.Clients.GUID + " = ?";
- public static final String TABS_CLIENT_GUID_IS = BrowserContract.Tabs.CLIENT_GUID + " = ?";
-
- protected Tab testTab1;
- protected Tab testTab2;
- protected Tab testTab3;
-
- public TestFennecTabsStorage() {
- super(Activity.class);
- }
-
- protected ContentProviderClient getClientsClient() {
- final ContentResolver cr = getInstrumentation().getTargetContext().getApplicationContext().getContentResolver();
- return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI);
- }
-
- protected ContentProviderClient getTabsClient() {
- final ContentResolver cr = getInstrumentation().getTargetContext().getApplicationContext().getContentResolver();
- return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI);
- }
-
- protected int deleteTestClient(final ContentProviderClient clientsClient) throws RemoteException {
- if (clientsClient == null) {
- return -1;
- }
- return clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, CLIENTS_GUID_IS, new String[] { TEST_CLIENT_GUID });
- }
-
- protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws RemoteException {
- if (tabsClient == null) {
- return -1;
- }
- return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI, TABS_CLIENT_GUID_IS, new String[]{TEST_CLIENT_GUID});
- }
-
- @Override
- protected void tearDown() throws Exception {
- deleteAllTestTabs(getTabsClient());
- }
-
- protected void insertTestClient(final ContentProviderClient clientsClient) throws RemoteException {
- ContentValues cv = new ContentValues();
- cv.put(BrowserContract.Clients.GUID, TEST_CLIENT_GUID);
- cv.put(BrowserContract.Clients.NAME, TEST_CLIENT_NAME);
- clientsClient.insert(BrowserContractHelpers.CLIENTS_CONTENT_URI, cv);
- }
-
- @SuppressWarnings("unchecked")
- protected void insertSomeTestTabs(ContentProviderClient tabsClient) throws RemoteException {
- final JSONArray history1 = new JSONArray();
- history1.add("http://test.com/test1.html");
- testTab1 = new Tab("test title 1", "http://test.com/test1.png", history1, 1000);
-
- final JSONArray history2 = new JSONArray();
- history2.add("http://test.com/test2.html#1");
- history2.add("http://test.com/test2.html#2");
- history2.add("http://test.com/test2.html#3");
- testTab2 = new Tab("test title 2", "http://test.com/test2.png", history2, 2000);
-
- final JSONArray history3 = new JSONArray();
- history3.add("http://test.com/test3.html#1");
- history3.add("http://test.com/test3.html#2");
- testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000);
-
- 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.
- public void testObtainCP() {
- final ContentProviderClient clientsClient = getClientsClient();
- assertNotNull(clientsClient);
- clientsClient.release();
-
- final ContentProviderClient tabsClient = getTabsClient();
- assertNotNull(tabsClient);
- tabsClient.release();
- }
-
- public void testWipeClients() throws RemoteException {
- final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI;
- final ContentProviderClient clientsClient = getClientsClient();
-
- // Have to ensure that it's empty…
- clientsClient.delete(uri, null, null);
-
- int deleted = clientsClient.delete(uri, null, null);
- assertEquals(0, deleted);
- }
-
- public void testWipeTabs() throws RemoteException {
- final ContentProviderClient tabsClient = getTabsClient();
-
- // Have to ensure that it's empty…
- deleteAllTestTabs(tabsClient);
-
- int deleted = deleteAllTestTabs(tabsClient);
- assertEquals(0, deleted);
- }
-
- public void testStoreAndRetrieveClients() throws RemoteException {
- final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI;
- final ContentProviderClient clientsClient = getClientsClient();
-
- // Have to ensure that it's empty…
- clientsClient.delete(uri, null, null);
-
- final long now = System.currentTimeMillis();
- final ContentValues first = new ContentValues();
- final ContentValues second = new ContentValues();
- first.put(BrowserContract.Clients.GUID, "abcdefghijkl");
- first.put(BrowserContract.Clients.NAME, "Frist Psot");
- first.put(BrowserContract.Clients.LAST_MODIFIED, now + 1);
- second.put(BrowserContract.Clients.GUID, "mnopqrstuvwx");
- second.put(BrowserContract.Clients.NAME, "Second!!1!");
- second.put(BrowserContract.Clients.LAST_MODIFIED, now + 2);
-
- ContentValues[] values = new ContentValues[] { first, second };
- final int inserted = clientsClient.bulkInsert(uri, values);
- assertEquals(2, inserted);
-
- final String since = BrowserContract.Clients.LAST_MODIFIED + " >= ?";
- final String[] nowArg = new String[] { String.valueOf(now) };
- final String guidAscending = BrowserContract.Clients.GUID + " ASC";
- Cursor cursor = clientsClient.query(uri, null, since, nowArg, guidAscending);
-
- assertNotNull(cursor);
- try {
- assertTrue(cursor.moveToFirst());
- assertEquals(2, cursor.getCount());
-
- final String g1 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.GUID));
- final String n1 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.NAME));
- final long m1 = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Clients.LAST_MODIFIED));
- assertEquals(first.get(BrowserContract.Clients.GUID), g1);
- assertEquals(first.get(BrowserContract.Clients.NAME), n1);
- assertEquals(now + 1, m1);
-
- assertTrue(cursor.moveToNext());
- final String g2 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.GUID));
- final String n2 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.NAME));
- final long m2 = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Clients.LAST_MODIFIED));
- assertEquals(second.get(BrowserContract.Clients.GUID), g2);
- assertEquals(second.get(BrowserContract.Clients.NAME), n2);
- assertEquals(now + 2, m2);
-
- assertFalse(cursor.moveToNext());
- } finally {
- cursor.close();
- }
-
- int deleted = clientsClient.delete(uri, null, null);
- assertEquals(2, deleted);
- }
-
- public void testTabFromCursor() throws Exception {
- final ContentProviderClient tabsClient = getTabsClient();
- final ContentProviderClient clientsClient = getClientsClient();
-
- deleteAllTestTabs(tabsClient);
- deleteTestClient(clientsClient);
- insertTestClient(clientsClient);
- insertSomeTestTabs(tabsClient);
-
- final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
- Cursor cursor = null;
- try {
- cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending);
- assertEquals(3, cursor.getCount());
-
- cursor.moveToFirst();
- final Tab parsed1 = Tab.fromCursor(cursor);
- assertEquals(testTab1, parsed1);
-
- cursor.moveToNext();
- final Tab parsed2 = Tab.fromCursor(cursor);
- assertEquals(testTab2, parsed2);
-
- cursor.moveToPosition(2);
- final Tab parsed3 = Tab.fromCursor(cursor);
- assertEquals(testTab3, parsed3);
- } finally {
- cursor.close();
- }
- }
-
- public void testDeletingClientDeletesTabs() throws Exception {
- final ContentProviderClient tabsClient = getTabsClient();
- final ContentProviderClient clientsClient = getClientsClient();
-
- deleteAllTestTabs(tabsClient);
- deleteTestClient(clientsClient);
- insertTestClient(clientsClient);
- insertSomeTestTabs(tabsClient);
-
- // Delete just the client...
- clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, CLIENTS_GUID_IS, new String [] { TEST_CLIENT_GUID });
-
- Cursor cursor = null;
- try {
- cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, null);
- // ... and all that client's tabs should be removed.
- assertEquals(0, cursor.getCount());
- } finally {
- cursor.close();
- }
- }
-}
deleted file mode 100644
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestTabsRecord.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.gecko.background.sync;
-
-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;
-
-import android.content.ContentProviderClient;
-import android.database.Cursor;
-
-public class TestTabsRecord extends TestFennecTabsStorage {
- public void testTabsRecordFromCursor() throws Exception {
- final ContentProviderClient tabsClient = getTabsClient();
-
- deleteAllTestTabs(tabsClient);
- insertTestClient(getClientsClient());
- insertSomeTestTabs(tabsClient);
-
- final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
- Cursor cursor = null;
- try {
- 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);
-
- final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME);
-
- // Make sure we clean up after ourselves.
- assertEquals(1, cursor.getPosition());
-
- assertEquals(TEST_CLIENT_GUID, tabsRecord.guid);
- assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName);
-
- assertEquals(3, tabsRecord.tabs.size());
- assertEquals(testTab1, tabsRecord.tabs.get(0));
- assertEquals(testTab2, tabsRecord.tabs.get(1));
- assertEquals(testTab3, tabsRecord.tabs.get(2));
-
- assertEquals(Math.max(Math.max(testTab1.lastUsed, testTab2.lastUsed), testTab3.lastUsed), tabsRecord.lastModified);
- } finally {
- cursor.close();
- }
- }
-
- // Verify that we can fetch a record when there are no local tabs at all.
- public void testEmptyTabsRecordFromCursor() throws Exception {
- final ContentProviderClient tabsClient = getTabsClient();
-
- deleteAllTestTabs(tabsClient);
-
- final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
- Cursor cursor = null;
- try {
- 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);
-
- assertEquals(TEST_CLIENT_GUID, tabsRecord.guid);
- assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName);
-
- assertNotNull(tabsRecord.tabs);
- assertEquals(0, tabsRecord.tabs.size());
-
- assertEquals(0, tabsRecord.lastModified);
- } finally {
- cursor.close();
- }
- }
-
- // Not much of a test, but verifies the tabs record at least agrees with the
- // disk data and doubles as a database inspector.
- public void testLocalTabs() throws Exception {
- final ContentProviderClient tabsClient = getTabsClient();
-
- final String positionAscending = BrowserContract.Tabs.POSITION + " ASC";
- Cursor cursor = null;
- try {
- // Keep this in sync with the Fennec schema.
- 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);
-
- assertEquals(TEST_CLIENT_GUID, tabsRecord.guid);
- assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName);
-
- assertNotNull(tabsRecord.tabs);
- assertEquals(cursor.getCount(), tabsRecord.tabs.size());
- } finally {
- cursor.close();
- }
- }
-}
--- a/mobile/android/tests/browser/junit3/moz.build
+++ b/mobile/android/tests/browser/junit3/moz.build
@@ -16,17 +16,16 @@ jar.sources += [
'src/org/mozilla/tests/browser/junit3/TestDistribution.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoBackgroundThread.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoMenu.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoProfilesProvider.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoSharedPrefs.java',
'src/org/mozilla/tests/browser/junit3/TestImageDownloader.java',
'src/org/mozilla/tests/browser/junit3/TestJarReader.java',
'src/org/mozilla/tests/browser/junit3/TestRawResource.java',
- 'src/org/mozilla/tests/browser/junit3/TestRemoteTabs.java',
'src/org/mozilla/tests/browser/junit3/TestSuggestedSites.java',
]
jar.generated_sources = [] # None yet -- try to keep it this way.
jar.javac_flags += ['-Xlint:all']
jar.extra_jars += [
CONFIG['ANDROID_SUPPORT_V4_AAR_LIB'],
CONFIG['ANDROID_RECYCLERVIEW_V7_AAR_LIB'],
deleted file mode 100644
--- a/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestRemoteTabs.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-package org.mozilla.tests.browser.junit3;
-
-import android.content.ContentProviderClient;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.test.InstrumentationTestCase;
-
-import org.mozilla.gecko.GeckoProfile;
-import org.mozilla.gecko.background.db.CursorDumper;
-import org.mozilla.gecko.db.BrowserContract;
-import org.mozilla.gecko.db.LocalTabsAccessor;
-import org.mozilla.gecko.db.RemoteClient;
-import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers;
-
-import java.util.List;
-
-public class TestRemoteTabs extends InstrumentationTestCase {
- private static final long ONE_DAY_IN_MILLISECONDS = 1000 * 60 * 60 * 24;
- private static final long ONE_WEEK_IN_MILLISECONDS = 7 * ONE_DAY_IN_MILLISECONDS;
- private static final long THREE_WEEKS_IN_MILLISECONDS = 3 * ONE_WEEK_IN_MILLISECONDS;
-
- public void testGetClientsWithoutTabsByRecencyFromCursor() throws Exception {
- final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI;
- final ContentResolver cr = getInstrumentation().getTargetContext().getContentResolver();
- final ContentProviderClient cpc = cr.acquireContentProviderClient(uri);
- final LocalTabsAccessor accessor = new LocalTabsAccessor("test"); // The profile name given doesn't matter.
-
- try {
- // Delete all tabs to begin with.
- cpc.delete(uri, null, null);
- Cursor allClients = cpc.query(uri, null, null, null, null);
- try {
- assertEquals(0, allClients.getCount());
- } finally {
- allClients.close();
- }
-
- // Insert a local and remote1 client record, neither with tabs.
- final long now = System.currentTimeMillis();
- // Local client has GUID = null.
- final ContentValues local = new ContentValues();
- local.put(BrowserContract.Clients.NAME, "local");
- local.put(BrowserContract.Clients.LAST_MODIFIED, now + 1);
- // Remote clients have GUID != null.
- final ContentValues remote1 = new ContentValues();
- remote1.put(BrowserContract.Clients.GUID, "guid1");
- remote1.put(BrowserContract.Clients.NAME, "remote1");
- remote1.put(BrowserContract.Clients.LAST_MODIFIED, now + 2);
-
- final ContentValues remote2 = new ContentValues();
- remote2.put(BrowserContract.Clients.GUID, "guid2");
- remote2.put(BrowserContract.Clients.NAME, "remote2");
- remote2.put(BrowserContract.Clients.LAST_MODIFIED, now + 3);
-
- ContentValues[] values = new ContentValues[]{local, remote1, remote2};
- int inserted = cpc.bulkInsert(uri, values);
- assertEquals(3, inserted);
-
- allClients = cpc.query(BrowserContract.Clients.CONTENT_RECENCY_URI, null, null, null, null);
- try {
- CursorDumper.dumpCursor(allClients);
- // The local client is not ignored.
- assertEquals(3, allClients.getCount());
- final List<RemoteClient> clients = accessor.getClientsWithoutTabsByRecencyFromCursor(allClients);
- assertEquals(3, clients.size());
- for (RemoteClient client : clients) {
- // Each client should not have any tabs.
- assertNotNull(client.tabs);
- assertEquals(0, client.tabs.size());
- }
- // Since there are no tabs, the order should be based on last_modified.
- assertEquals("guid2", clients.get(0).guid);
- assertEquals("guid1", clients.get(1).guid);
- assertEquals(null, clients.get(2).guid);
- } finally {
- allClients.close();
- }
-
- // Now let's add a few tabs to one client. The times are chosen so that one tab's
- // last used is not relevant, and the other tab is the most recent used.
- final ContentValues remoteTab1 = new ContentValues();
- remoteTab1.put(BrowserContract.Tabs.CLIENT_GUID, "guid1");
- remoteTab1.put(BrowserContract.Tabs.TITLE, "title1");
- remoteTab1.put(BrowserContract.Tabs.URL, "http://test.com/test1");
- remoteTab1.put(BrowserContract.Tabs.HISTORY, "[\"http://test.com/test1\"]");
- remoteTab1.put(BrowserContract.Tabs.LAST_USED, now);
- remoteTab1.put(BrowserContract.Tabs.POSITION, 0);
-
- final ContentValues remoteTab2 = new ContentValues();
- remoteTab2.put(BrowserContract.Tabs.CLIENT_GUID, "guid1");
- remoteTab2.put(BrowserContract.Tabs.TITLE, "title2");
- remoteTab2.put(BrowserContract.Tabs.URL, "http://test.com/test2");
- remoteTab2.put(BrowserContract.Tabs.HISTORY, "[\"http://test.com/test2\"]");
- remoteTab2.put(BrowserContract.Tabs.LAST_USED, now + 5);
- remoteTab2.put(BrowserContract.Tabs.POSITION, 1);
-
- values = new ContentValues[]{remoteTab1, remoteTab2};
- inserted = cpc.bulkInsert(BrowserContract.Tabs.CONTENT_URI, values);
- assertEquals(2, inserted);
-
- allClients = cpc.query(BrowserContract.Clients.CONTENT_RECENCY_URI, null, BrowserContract.Clients.GUID + " IS NOT NULL", null, null);
- try {
- CursorDumper.dumpCursor(allClients);
- // The local client is ignored.
- assertEquals(2, allClients.getCount());
- final List<RemoteClient> clients = accessor.getClientsWithoutTabsByRecencyFromCursor(allClients);
- assertEquals(2, clients.size());
- for (RemoteClient client : clients) {
- // Each client should be remote and should not have any tabs.
- assertNotNull(client.guid);
- assertNotNull(client.tabs);
- assertEquals(0, client.tabs.size());
- }
- // Since now there is a tab attached to the remote2 client more recent than the
- // remote1 client modified time, it should be first.
- assertEquals("guid1", clients.get(0).guid);
- assertEquals("guid2", clients.get(1).guid);
- } finally {
- allClients.close();
- }
- } finally {
- cpc.release();
- }
- }
-
- public void testGetRecentRemoteClientsUpToOneWeekOld() throws Exception {
- final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI;
- final Context context = getInstrumentation().getTargetContext();
- final String profileName = GeckoProfile.get(context).getName();
- final ContentResolver cr = context.getContentResolver();
- final ContentProviderClient cpc = cr.acquireContentProviderClient(uri);
- final LocalTabsAccessor accessor = new LocalTabsAccessor(profileName);
-
- try {
- // Start Clean
- cpc.delete(uri, null, null);
- final Cursor allClients = cpc.query(uri, null, null, null, null);
- try {
- assertEquals(0, allClients.getCount());
- } finally {
- allClients.close();
- }
-
- // Insert a local and remote1 client record, neither with tabs.
- final long now = System.currentTimeMillis();
- // Local client has GUID = null.
- final ContentValues local = new ContentValues();
- local.put(BrowserContract.Clients.NAME, "local");
- local.put(BrowserContract.Clients.LAST_MODIFIED, now + 1);
- // Remote clients have GUID != null.
- final ContentValues remote1 = new ContentValues();
- remote1.put(BrowserContract.Clients.GUID, "guid1");
- remote1.put(BrowserContract.Clients.NAME, "remote1");
- remote1.put(BrowserContract.Clients.LAST_MODIFIED, now + 2);
-
- // Insert a Remote Client that is 6 days old.
- final ContentValues remote2 = new ContentValues();
- remote2.put(BrowserContract.Clients.GUID, "guid2");
- remote2.put(BrowserContract.Clients.NAME, "remote2");
- remote2.put(BrowserContract.Clients.LAST_MODIFIED, now - ONE_WEEK_IN_MILLISECONDS + ONE_DAY_IN_MILLISECONDS);
-
- // Insert a Remote Client with the same name as previous but with more than 3 weeks old
- final ContentValues remote3 = new ContentValues();
- remote3.put(BrowserContract.Clients.GUID, "guid21");
- remote3.put(BrowserContract.Clients.NAME, "remote2");
- remote3.put(BrowserContract.Clients.LAST_MODIFIED, now - THREE_WEEKS_IN_MILLISECONDS - ONE_DAY_IN_MILLISECONDS);
-
- // Insert another remote client with the same name as previous but with 3 weeks - 1 day old.
- final ContentValues remote4 = new ContentValues();
- remote4.put(BrowserContract.Clients.GUID, "guid22");
- remote4.put(BrowserContract.Clients.NAME, "remote2");
- remote4.put(BrowserContract.Clients.LAST_MODIFIED, now - THREE_WEEKS_IN_MILLISECONDS + ONE_DAY_IN_MILLISECONDS);
-
- // Insert a Remote Client that is exactly one week old.
- final ContentValues remote5 = new ContentValues();
- remote5.put(BrowserContract.Clients.GUID, "guid3");
- remote5.put(BrowserContract.Clients.NAME, "remote3");
- remote5.put(BrowserContract.Clients.LAST_MODIFIED, now - ONE_WEEK_IN_MILLISECONDS);
-
- ContentValues[] values = new ContentValues[]{local, remote1, remote2, remote3, remote4, remote5};
- int inserted = cpc.bulkInsert(uri, values);
- assertEquals(values.length, inserted);
-
- final Cursor remoteClients =
- accessor.getRemoteClientsByRecencyCursor(context);
-
- try {
- CursorDumper.dumpCursor(remoteClients);
- // Local client is not included.
- // (remote1, guid1), (remote2, guid2), (remote3, guid3) are expected.
- assertEquals(3, remoteClients.getCount());
-
- // Check the inner data, according to recency.
- List<RemoteClient> recentRemoteClientsList =
- accessor.getClientsWithoutTabsByRecencyFromCursor(remoteClients);
- assertEquals(3, recentRemoteClientsList.size());
- assertEquals("remote1", recentRemoteClientsList.get(0).name);
- assertEquals("guid1", recentRemoteClientsList.get(0).guid);
- assertEquals("remote2", recentRemoteClientsList.get(1).name);
- assertEquals("guid2", recentRemoteClientsList.get(1).guid);
- assertEquals("remote3", recentRemoteClientsList.get(2).name);
- assertEquals("guid3", recentRemoteClientsList.get(2).guid);
- } finally {
- remoteClients.close();
- }
- } finally {
- cpc.release();
- }
- }
-}