Bug 721731 - Tests for new combined view. r=lucasr
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 23 Mar 2012 15:53:03 -0700
changeset 92032 a2ba1894d61bb3f0365c34d95b071e8cacc2108e
parent 92031 074de1a022db13b52ca309e36b3a59afa10f0cf2
child 92033 2940c6c8ef6620583789b4752c96cb068d3891d8
push idunknown
push userunknown
push dateunknown
reviewerslucasr
bugs721731
milestone13.0a2
Bug 721731 - Tests for new combined view. r=lucasr
mobile/android/base/tests/testBrowserProvider.java.in
--- a/mobile/android/base/tests/testBrowserProvider.java.in
+++ b/mobile/android/base/tests/testBrowserProvider.java.in
@@ -26,16 +26,17 @@ public class testBrowserProvider extends
     private String MENU_FOLDER_GUID;
     private String TAGS_FOLDER_GUID;
     private String TOOLBAR_FOLDER_GUID;
     private String UNFILED_FOLDER_GUID;
 
     private Uri mBookmarksUri;
     private Uri mHistoryUri;
     private Uri mImagesUri;
+    private Uri mCombinedUri;
 
     private String mBookmarksIdCol;
     private String mBookmarksTitleCol;
     private String mBookmarksUrlCol;
     private String mBookmarksFaviconCol;
     private String mBookmarksThumbnailCol;
     private String mBookmarksParentCol;
     private String mBookmarksTypeCol;
@@ -62,20 +63,31 @@ public class testBrowserProvider extends
     private String mHistoryIsDeletedCol;
     private String mHistoryDateCreatedCol;
     private String mHistoryDateModifiedCol;
 
     private String mImagesThumbnailCol;
     private String mImagesFaviconCol;
     private String mImagesUrlCol;
 
+    private String mCombinedIdCol;
+    private String mCombinedBookmarkIdCol;
+    private String mCombinedHistoryIdCol;
+    private String mCombinedUrlCol;
+    private String mCombinedTitleCol;
+    private String mCombinedVisitsCol;
+    private String mCombinedLastVisitedCol;
+    private String mCombinedFaviconCol;
+    private String mCombinedThumbnailCol;
+
     private void loadContractInfo() throws Exception {
         mBookmarksUri = getContentUri("Bookmarks");
         mHistoryUri = getContentUri("History");
         mImagesUri = getContentUri("Images");
+        mCombinedUri = getContentUri("Combined");
 
         PLACES_FOLDER_GUID = getStringColumn("Bookmarks", "PLACES_FOLDER_GUID");
         MOBILE_FOLDER_GUID = getStringColumn("Bookmarks", "MOBILE_FOLDER_GUID");
         MENU_FOLDER_GUID = getStringColumn("Bookmarks", "MENU_FOLDER_GUID");
         TAGS_FOLDER_GUID = getStringColumn("Bookmarks", "TAGS_FOLDER_GUID");
         TOOLBAR_FOLDER_GUID = getStringColumn("Bookmarks", "TOOLBAR_FOLDER_GUID");
         UNFILED_FOLDER_GUID = getStringColumn("Bookmarks", "UNFILED_FOLDER_GUID");
 
@@ -108,16 +120,26 @@ public class testBrowserProvider extends
         mHistoryGuidCol = getStringColumn("History", "GUID");
         mHistoryIsDeletedCol = getStringColumn("History", "IS_DELETED");
         mHistoryDateCreatedCol = getStringColumn("History", "DATE_CREATED");
         mHistoryDateModifiedCol = getStringColumn("History", "DATE_MODIFIED");
 
         mImagesUrlCol = getStringColumn("Images", "URL");
         mImagesFaviconCol = getStringColumn("Images", "FAVICON");
         mImagesThumbnailCol = getStringColumn("Images", "THUMBNAIL");
+
+        mCombinedIdCol = getStringColumn("Combined", "_ID");
+        mCombinedBookmarkIdCol = getStringColumn("Combined", "BOOKMARK_ID");
+        mCombinedHistoryIdCol = getStringColumn("Combined", "HISTORY_ID");
+        mCombinedUrlCol = getStringColumn("Combined", "URL");
+        mCombinedTitleCol = getStringColumn("Combined", "TITLE");
+        mCombinedVisitsCol = getStringColumn("Combined", "VISITS");
+        mCombinedLastVisitedCol = getStringColumn("Combined", "DATE_LAST_VISITED");
+        mCombinedFaviconCol = getStringColumn("Combined", "FAVICON");
+        mCombinedThumbnailCol = getStringColumn("Combined", "THUMBNAIL");
     }
 
     private void loadMobileFolderId() throws Exception {
         Cursor c = getBookmarkByGuid(MOBILE_FOLDER_GUID);
         mAsserter.is(c.moveToFirst(), true, "Mobile bookmarks folder is present");
 
         mMobileFolderId = c.getLong(c.getColumnIndex(mBookmarksIdCol));
     }
@@ -255,16 +277,18 @@ public class testBrowserProvider extends
         mTests.add(new TestUpdateBookmarksImages());
 
         mTests.add(new TestInsertHistory());
         mTests.add(new TestInsertHistoryImages());
         mTests.add(new TestDeleteHistory());
         mTests.add(new TestDeleteHistoryImages());
         mTests.add(new TestUpdateHistory());
         mTests.add(new TestUpdateHistoryImages());
+
+        mTests.add(new TestCombinedView());
     }
 
     public void testBrowserProvider() throws Exception {
         setTestType("mochitest");
 
         loadMobileFolderId();
 
         for (int i = 0; i < mTests.size(); i++) {
@@ -871,9 +895,130 @@ public class testBrowserProvider extends
 
             c = getImagesByUrl(h.getAsString(mHistoryUrlCol));
             mAsserter.is(c.moveToFirst(), true, "Updated images found");
 
             mAsserter.is(new String(c.getBlob(c.getColumnIndex(mImagesFaviconCol)), "UTF8"),
                          newFavicon, "Updated image has corresponding favicon image");
         }
     }
+
+    class TestCombinedView extends Test {
+        public void test() throws Exception {
+            final String TITLE_1 = "Test Page 1";
+            final String TITLE_2 = "Test Page 2";
+            final String TITLE_3_HISTORY = "Test Page 3 (History Entry)";
+            final String TITLE_3_BOOKMARK = "Test Page 3 (Bookmark Entry)";
+
+            final String URL_1 = "http://example.com";
+            final String URL_2 = "http://example.org";
+            final String URL_3 = "http://examples2.com";
+
+            final String HISTORY_FAVICON = "HISTORY_FAVICON";
+            final String HISTORY_THUMBNAIL = "HISTORY_THUMBNAIL";
+            final String BOOKMARK_FAVICON = "BOOKMARK_FAVICON";
+            final String BOOKMARK_THUMBNAIL = "BOOKMARK_THUMBNAIL";
+
+            final int VISITS = 10;
+            final long LAST_VISITED = System.currentTimeMillis();
+
+            // Create a basic history entry with images
+            ContentValues basicHistory = createHistoryEntry(TITLE_1, URL_1, VISITS, LAST_VISITED);
+            basicHistory.put(mHistoryFaviconCol, HISTORY_FAVICON.getBytes("UTF8"));
+            basicHistory.put(mHistoryThumbnailCol, HISTORY_THUMBNAIL.getBytes("UTF8"));
+            long basicHistoryId = ContentUris.parseId(mProvider.insert(mHistoryUri, basicHistory));
+
+            // Create a basic bookmark entry with images
+            ContentValues basicBookmark = createBookmark(TITLE_2, URL_2, mMobileFolderId,
+                mBookmarksTypeBookmark, 0, "tags", "description", "keyword");
+            basicBookmark.put(mBookmarksFaviconCol, BOOKMARK_FAVICON.getBytes("UTF8"));
+            basicBookmark.put(mBookmarksThumbnailCol, BOOKMARK_THUMBNAIL.getBytes("UTF8"));
+            long basicBookmarkId = ContentUris.parseId(mProvider.insert(mBookmarksUri, basicBookmark));
+
+            // Create a history entry and bookmark entry with the same URL to
+            // represent a visited bookmark
+            ContentValues combinedHistory = createHistoryEntry(TITLE_3_HISTORY, URL_3, VISITS, LAST_VISITED);
+            combinedHistory.put(mHistoryFaviconCol, HISTORY_FAVICON.getBytes("UTF8"));
+            combinedHistory.put(mHistoryThumbnailCol, HISTORY_THUMBNAIL.getBytes("UTF8"));
+            long combinedHistoryId = ContentUris.parseId(mProvider.insert(mHistoryUri, combinedHistory));
+
+            ContentValues combinedBookmark = createBookmark(TITLE_3_BOOKMARK, URL_3, mMobileFolderId,
+                mBookmarksTypeBookmark, 0, "tags", "description", "keyword");
+            combinedBookmark.put(mBookmarksFaviconCol, BOOKMARK_FAVICON.getBytes("UTF8"));
+            combinedBookmark.put(mBookmarksThumbnailCol, BOOKMARK_THUMBNAIL.getBytes("UTF8"));
+            long combinedBookmarkId = ContentUris.parseId(mProvider.insert(mBookmarksUri, combinedBookmark));
+
+            // Create a bookmark folder to make sure it _doesn't_ show up in the results
+            ContentValues folderBookmark = createBookmark("", "", mMobileFolderId,
+                mBookmarksTypeFolder, 0, "tags", "description", "keyword");
+            mProvider.insert(mBookmarksUri, folderBookmark);
+
+            // Sort entries by url so we can check them individually
+            Cursor c = mProvider.query(mCombinedUri, null, "", null, mCombinedUrlCol);
+
+            mAsserter.is(c.getCount(), 3, "3 combined entries found");
+
+            // First combined entry is basic history entry
+            mAsserter.is(c.moveToFirst(), true, "Found basic history entry");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedIdCol))), new Long(0),
+                         "Combined _id column should always be 0");
+            // TODO: Should we change BrowserProvider to make this return -1, not 0?
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedBookmarkIdCol))), new Long(0),
+                         "Bookmark id should be 0 for basic history entry");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedHistoryIdCol))), new Long(basicHistoryId),
+                         "Basic history entry has correct history id");
+            mAsserter.is(c.getString(c.getColumnIndex(mCombinedTitleCol)), TITLE_1,
+                         "Basic history entry has correct title");
+            mAsserter.is(c.getString(c.getColumnIndex(mCombinedUrlCol)), URL_1,
+                         "Basic history entry has correct url");
+            mAsserter.is(c.getInt(c.getColumnIndex(mCombinedVisitsCol)), VISITS,
+                         "Basic history entry has correct number of visits");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedLastVisitedCol))), new Long(LAST_VISITED),
+                         "Basic history entry has correct last visit time");
+            mAsserter.is(new String(c.getBlob(c.getColumnIndex(mCombinedFaviconCol)), "UTF8"),
+                          HISTORY_FAVICON, "Basic history entry has corresponding favicon image");
+            mAsserter.is(new String(c.getBlob(c.getColumnIndex(mCombinedThumbnailCol)), "UTF8"),
+                          HISTORY_THUMBNAIL, "Basic history entry has corresponding thumbnail image");
+
+            // Second combined entry is basic bookmark entry
+            mAsserter.is(c.moveToNext(), true, "Found basic bookmark entry");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedIdCol))), new Long(0),
+                         "Combined _id column should always be 0");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedBookmarkIdCol))), new Long(basicBookmarkId),
+                         "Basic bookmark entry has correct bookmark id");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedHistoryIdCol))), new Long(-1),
+                         "History id should be -1 for basic bookmark entry");
+            mAsserter.is(c.getString(c.getColumnIndex(mCombinedTitleCol)), TITLE_2,
+                         "Basic bookmark entry has correct title");
+            mAsserter.is(c.getString(c.getColumnIndex(mCombinedUrlCol)), URL_2,
+                         "Basic bookmark entry has correct url");
+            mAsserter.is(c.getInt(c.getColumnIndex(mCombinedVisitsCol)), -1,
+                         "Visits should be -1 for basic bookmark entry");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedLastVisitedCol))), new Long(-1),
+                         "Last visited should be -1 for basic bookmark entry");
+            mAsserter.is(new String(c.getBlob(c.getColumnIndex(mCombinedFaviconCol)), "UTF8"),
+                          BOOKMARK_FAVICON, "Basic bookmark entry has corresponding favicon image");
+            mAsserter.is(new String(c.getBlob(c.getColumnIndex(mCombinedThumbnailCol)), "UTF8"),
+                          BOOKMARK_THUMBNAIL, "Basic bookmark entry has corresponding thumbnail image");
+
+            // Third combined entry is a combined history/bookmark entry
+            mAsserter.is(c.moveToNext(), true, "Found third combined entry");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedIdCol))), new Long(0),
+                         "Combined _id column should always be 0");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedBookmarkIdCol))), new Long(combinedBookmarkId),
+                         "Combined entry has correct bookmark id");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedHistoryIdCol))), new Long(combinedHistoryId),
+                         "Combined entry has correct history id");
+            mAsserter.is(c.getString(c.getColumnIndex(mCombinedTitleCol)), TITLE_3_BOOKMARK,
+                         "Combined entry has title corresponding to bookmark entry");
+            mAsserter.is(c.getString(c.getColumnIndex(mCombinedUrlCol)), URL_3,
+                         "Combined entry has correct url");
+            mAsserter.is(c.getInt(c.getColumnIndex(mCombinedVisitsCol)), VISITS,
+                         "Combined entry has correct number of visits");
+            mAsserter.is(new Long(c.getLong(c.getColumnIndex(mCombinedLastVisitedCol))), new Long(LAST_VISITED),
+                         "Combined entry has correct last visit time");
+            mAsserter.is(new String(c.getBlob(c.getColumnIndex(mCombinedFaviconCol)), "UTF8"),
+                          BOOKMARK_FAVICON, "Combined entry has bookmark favicon image");
+            mAsserter.is(new String(c.getBlob(c.getColumnIndex(mCombinedThumbnailCol)), "UTF8"),
+                          BOOKMARK_THUMBNAIL, "Combined entry has bookmark thumbnail image");
+        }
+    }
 }