Bug 1025128 - Part 2: Fix JUnit 3 tests. r=me,vivek
authorNick Alexander <nalexander@mozilla.com>
Tue, 27 Oct 2015 14:28:20 -0700
changeset 304989 ebc2cde9c8a1974091c95c10cf671fbe095c4791
parent 304988 28bd6fb286b4123945ff571d0371e078148a4206
child 304990 c90d9b61151efd0c4732c5a39f0eca66c15ba78b
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, vivek
bugs1025128
milestone44.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 1025128 - Part 2: Fix JUnit 3 tests. r=me,vivek
mobile/android/tests/background/junit3/src/db/TestFennecTabsRepositorySession.java
mobile/android/tests/background/junit3/src/db/TestFennecTabsStorage.java
mobile/android/tests/background/junit3/src/sync/TestTabsRecord.java
mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java
--- a/mobile/android/tests/background/junit3/src/db/TestFennecTabsRepositorySession.java
+++ b/mobile/android/tests/background/junit3/src/db/TestFennecTabsRepositorySession.java
@@ -36,31 +36,47 @@ public class TestFennecTabsRepositorySes
   // Override these to test against data that is not live.
   public static final String TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION = BrowserContract.Tabs.CLIENT_GUID + " IS ?";
   public static final String[] TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS = new String[] { TEST_CLIENT_GUID };
 
   public static final String TEST_CLIENTS_GUID_IS_LOCAL_SELECTION = BrowserContract.Clients.GUID + " IS ?";
   public static final String[] TEST_CLIENTS_GUID_IS_LOCAL_SELECTION_ARGS = new String[] { TEST_CLIENT_GUID };
 
   protected ContentProviderClient tabsClient = null;
+  protected ContentProviderClient clientsClient = null;
 
   protected ContentProviderClient getTabsClient() {
     final ContentResolver cr = getApplicationContext().getContentResolver();
     return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI);
   }
 
+  protected ContentProviderClient getClientsClient() {
+    final ContentResolver cr = getApplicationContext().getContentResolver();
+    return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI);
+  }
+
   public TestFennecTabsRepositorySession() throws NoContentProviderException {
     super();
   }
 
   @Override
   public void setUp() {
     if (tabsClient == null) {
       tabsClient = getTabsClient();
     }
+    if (clientsClient == null) {
+      clientsClient = getClientsClient();
+    }
+  }
+
+  protected int deleteTestClient(final ContentProviderClient clientsClient) throws RemoteException {
+    if (clientsClient == null) {
+      return -1;
+    }
+    return clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, TEST_CLIENTS_GUID_IS_LOCAL_SELECTION, TEST_CLIENTS_GUID_IS_LOCAL_SELECTION_ARGS);
   }
 
   protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws RemoteException {
     if (tabsClient == null) {
       return -1;
     }
     return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI,
         TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS);
@@ -69,16 +85,23 @@ public class TestFennecTabsRepositorySes
   @Override
   protected void tearDown() throws Exception {
     if (tabsClient != null) {
       deleteAllTestTabs(tabsClient);
 
       tabsClient.release();
       tabsClient = null;
     }
+
+    if (clientsClient != null) {
+      deleteTestClient(clientsClient);
+
+      clientsClient.release();
+      clientsClient = null;
+    }
   }
 
   protected FennecTabsRepository getRepository() {
     /**
      * Override this chain in order to avoid our test code having to create two
      * sessions all the time.
      */
     return new FennecTabsRepository(clientsDataDelegate) {
@@ -224,24 +247,22 @@ public class TestFennecTabsRepositorySes
   }
 
   // Verify that storing a tabs record writes a clients record with the correct
   // device type to the Fennec clients provider.
   public void testStore() throws NoContentProviderException, RemoteException {
     // Get a valid tabsRecord to write.
     final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord();
     deleteAllTestTabs(tabsClient);
+    deleteTestClient(clientsClient);
 
     final ContentResolver cr = getApplicationContext().getContentResolver();
     final ContentProviderClient clientsClient = cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI);
 
     try {
-      // We can't delete only our test clients due to a Fennec CP issue with guid vs. client_guid.
-      clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, null, null);
-
       // This clients DB is not the Fennec DB; it's Sync's own clients DB.
       final ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(getApplicationContext());
       try {
         ClientRecord clientRecord = new ClientRecord(TEST_CLIENT_GUID);
         clientRecord.name = TEST_CLIENT_NAME;
         clientRecord.type = TEST_CLIENT_DEVICE_TYPE;
         db.store(clientRecord);
       } finally {
--- a/mobile/android/tests/background/junit3/src/db/TestFennecTabsStorage.java
+++ b/mobile/android/tests/background/junit3/src/db/TestFennecTabsStorage.java
@@ -21,16 +21,17 @@ import android.test.ActivityInstrumentat
  *
  * @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);
@@ -41,28 +42,42 @@ public class TestFennecTabsStorage exten
     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 });
+    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");
@@ -164,18 +179,21 @@ public class TestFennecTabsStorage exten
     }
 
     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());
 
@@ -189,9 +207,31 @@ public class TestFennecTabsStorage exten
 
       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();
+    }
+  }
 }
--- a/mobile/android/tests/background/junit3/src/sync/TestTabsRecord.java
+++ b/mobile/android/tests/background/junit3/src/sync/TestTabsRecord.java
@@ -13,16 +13,17 @@ import org.mozilla.gecko.sync.repositori
 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());
 
--- a/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java
+++ b/mobile/android/tests/browser/junit3/src/org/mozilla/tests/browser/junit3/TestJarReader.java
@@ -56,17 +56,17 @@ public class TestJarReader extends Instr
         stream = GeckoJarReader.getStream(context, "jar:" + url + "!/chrome/chrome/content/branding/favicon32.png");
         assertNull(stream);
     }
 
     protected void assertExtractStream(String url) throws IOException {
         final File file = GeckoJarReader.extractStream(getInstrumentation().getTargetContext(), url, getInstrumentation().getContext().getCacheDir(), ".test");
         assertNotNull(file);
         try {
-            assertTrue(file.getName().endsWith("temp"));
+            assertTrue(file.getName().endsWith("test"));
             final String contents = FileUtils.getFileContents(file);
             assertNotNull(contents);
             assertTrue(contents.length() > 0);
         } finally {
             file.delete();
         }
     }