Bug 772676 - Test history visit counts after migration. r=margaret
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Fri, 13 Jul 2012 07:49:37 +0200
changeset 99159 3de0ba7c2eb498184e4c7a861e9e5d1df93c0a39
parent 99158 e2fd625c1e79c85c99e344ee6f980c6223f35556
child 99160 b878869b3d819cf4637fe94499fd5fe2a95a6887
push id23105
push useremorley@mozilla.com
push dateFri, 13 Jul 2012 12:23:43 +0000
treeherdermozilla-central@a2d40b91eea9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs772676
milestone16.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 772676 - Test history visit counts after migration. r=margaret
mobile/android/base/tests/testMigration.java.in
--- a/mobile/android/base/tests/testMigration.java.in
+++ b/mobile/android/base/tests/testMigration.java.in
@@ -154,23 +154,23 @@ public class testMigration extends Conte
             launchPlacesTest.invoke(pm, new File(mProfile));
         } catch (Exception ex) {
             String stackTrace = Log.getStackTraceString(ex);
             mAsserter.is(true, false, "Unable to invoke launchPlacesTest:" + stackTrace);
             return;
         }
 
         // Run the tests to see if that worked
-        testViaContentProvider();
-        testViaBrowserDB();
+        runTestViaContentProvider();
+        runTestViaBrowserDB();
 
         mAsserter.is(oldDbLocation.exists(), false, "OK old file gone now");
     }
 
-    public void clearHistory() {
+    private void clearHistory() {
         Method clearHistory = null;
 
         try {
             Class browserDB =
                 mClassLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
             clearHistory =
                 browserDB.getMethod("clearHistory", ContentResolver.class);
         } catch (java.lang.ClassNotFoundException ex) {
@@ -185,17 +185,17 @@ public class testMigration extends Conte
             clearHistory.invoke(null, mResolver);
         } catch (Exception ex) {
             String stackTrace = Log.getStackTraceString(ex);
             mAsserter.is(true, false, "Exception clearing history:" + stackTrace);
         }
     }
 
     // stolen from testBookmarks
-    public void testViaBrowserDB() {
+    private void runTestViaBrowserDB() {
         Method isBookmarked = null;
         Method getAllVisitedHistory = null;
         Constructor constructor = null;
 
         try {
             Class localBrowserDB =
                 mClassLoader.loadClass("org.mozilla.gecko.db.LocalBrowserDB");
             isBookmarked =
@@ -260,36 +260,50 @@ public class testMigration extends Conte
                          "History count " + historyCount +
                          ", expected was " + PLACES_KNOWN_HISTORY_URLS);
         } catch (Exception ex) {
             mAsserter.is(true, false, "Exception checking history count");
             ex.printStackTrace();
         }
     }
 
-    public void testViaContentProvider() {
+    private void runTestViaContentProvider() {
         String ensureHistory;
         String ensureBookmarks;
+        String urlField;
+        String visitsField;
 
         Uri controlUri;
+        Uri historyUri;
+
         try {
             Class browserContract =
                 mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract");
             Class browserContractControl =
                 mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract$Control");
+            Class browserContractHistory =
+                mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract$History");
+            Class browserContractUrl =
+                mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract$URLColumns");
+            Class browserContractHistoryColumns =
+                mClassLoader.loadClass("org.mozilla.gecko.db.BrowserContract$HistoryColumns");
+
             controlUri = (Uri)browserContractControl.getField("CONTENT_URI").get(null);
+            historyUri = (Uri)browserContractHistory.getField("CONTENT_URI").get(null);
+            urlField = (String)browserContractUrl.getField("URL").get(null);
+            visitsField = (String)browserContractHistoryColumns.getField("VISITS").get(null);
             String profilePath = (String)browserContract.getField("PARAM_PROFILE_PATH").get(null);
             Uri.Builder builder = controlUri.buildUpon();
             controlUri = builder.build();
             ensureHistory =
                 (String)browserContractControl.getField("ENSURE_HISTORY_MIGRATED").get(null);
             ensureBookmarks =
                 (String)browserContractControl.getField("ENSURE_BOOKMARKS_MIGRATED").get(null);
         } catch (Exception ex) {
-            mAsserter.is(true, false, "Reflection error getting Control Uri");
+            mAsserter.is(true, false, "Reflection error getting BrowserContract classes and Uri's");
             ex.printStackTrace();
             return;
         }
 
         Cursor c = mResolver.query(controlUri,
                                    new String[] { ensureHistory,
                                                   ensureBookmarks },
                                    null,
@@ -302,16 +316,30 @@ public class testMigration extends Conte
         if (c.moveToFirst()) {
             historyMigrated = c.getInt(0);
             bookmarksMigrated = c.getInt(1);
         }
         c.close();
 
         mAsserter.is(historyMigrated, 1, "History migrated");
         mAsserter.is(bookmarksMigrated, 1, "Bookmarks migrated");
+
+        // Check whether visit counts are as expected. The test profile
+        // has visited reddit 4 times so we expect to find that in our
+        // own database too now.
+        c = mResolver.query(historyUri,
+                            new String[] { visitsField },
+                            urlField  + " = ?",
+                            new String[] { "http://www.reddit.com/" },
+                            null);
+        mAsserter.is(c.moveToFirst(), true, "Expected URL found");
+        int visits = c.getInt(0);
+        c.close();
+
+        mAsserter.is(visits, 4, "Visit count of " + visits + " equals expected 4");
     }
 
     @Override
     public void setUp() throws Exception {
         super.setUp("@ANDROID_PACKAGE_NAME@.db.BrowserProvider", "AUTHORITY");
     }
 
     public void tearDown() throws Exception {