Bug 1250707 - Test insert to url annotations table through BrowserProvider. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 25 Feb 2016 15:34:01 -0800
changeset 334989 4ba3ba783049e0f5664759b83e288813f82d9c3c
parent 334988 5369686567ff03734015ae3e0fd6ab26c57d2f86
child 334990 486d2537493d688dcff21c3c8634cc3ba72eb91d
push id11691
push usermichael.l.comella@gmail.com
push dateFri, 26 Feb 2016 17:31:24 +0000
reviewerssebastian
bugs1250707
milestone47.0a1
Bug 1250707 - Test insert to url annotations table through BrowserProvider. r=sebastian MozReview-Commit-ID: 2UqLgskqAPc
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testBrowserProvider.java
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testBrowserProvider.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testBrowserProvider.java
@@ -4,16 +4,17 @@
 
 package org.mozilla.gecko.tests;
 
 import java.util.ArrayList;
 import java.util.Random;
 
 import org.mozilla.gecko.background.db.CursorDumper;
 import org.mozilla.gecko.db.BrowserContract;
+import org.mozilla.gecko.db.BrowserContract.UrlAnnotations.SyncStatus;
 
 import android.content.ContentProviderOperation;
 import android.content.ContentProviderResult;
 import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.OperationApplicationException;
 import android.database.Cursor;
 import android.net.Uri;
@@ -182,16 +183,27 @@ public class testBrowserProvider extends
         ContentValues thumbnailEntry = new ContentValues();
 
         thumbnailEntry.put(BrowserContract.Thumbnails.URL, pageUrl);
         thumbnailEntry.put(BrowserContract.Thumbnails.DATA, data.getBytes("UTF8"));
 
         return thumbnailEntry;
     }
 
+    private ContentValues createUrlAnnotationEntry(final String url, final String key, final String value,
+                final long dateCreated) {
+        final ContentValues values = new ContentValues();
+        values.put(BrowserContract.UrlAnnotations.URL, url);
+        values.put(BrowserContract.UrlAnnotations.KEY, key);
+        values.put(BrowserContract.UrlAnnotations.VALUE, value);
+        values.put(BrowserContract.UrlAnnotations.DATE_CREATED, dateCreated);
+        values.put(BrowserContract.UrlAnnotations.DATE_MODIFIED, dateCreated);
+        return values;
+    }
+
     private ContentValues createOneHistoryEntry() throws Exception {
         return createHistoryEntry("Example", "http://example.com", 10, System.currentTimeMillis());
     }
 
     private Cursor getHistoryEntryById(long id) throws Exception {
         return getHistoryEntryById(BrowserContract.History.CONTENT_URI, id, null);
     }
 
@@ -219,16 +231,23 @@ public class testBrowserProvider extends
 
     private Cursor getThumbnailByUrl(String url) throws Exception {
         return mProvider.query(BrowserContract.Thumbnails.CONTENT_URI, null,
                                BrowserContract.Thumbnails.URL + " = ?",
                                new String[] { url },
                                null);
     }
 
+    private Cursor getUrlAnnotationByUrl(final String url) throws Exception {
+        return mProvider.query(BrowserContract.UrlAnnotations.CONTENT_URI, null,
+                BrowserContract.UrlAnnotations.URL + " = ?",
+                new String[] { url },
+                null);
+    }
+
     @Override
     public void setUp() throws Exception {
         super.setUp(sBrowserProviderCallable, BrowserContract.AUTHORITY, "browser.db");
 
         mTests.add(new TestSpecialFolders());
 
         mTests.add(new TestInsertBookmarks());
         mTests.add(new TestInsertBookmarksFavicons());
@@ -244,16 +263,18 @@ public class testBrowserProvider extends
         mTests.add(new TestDeleteHistoryFavicons());
         mTests.add(new TestUpdateHistory());
         mTests.add(new TestUpdateHistoryFavicons());
         mTests.add(new TestUpdateOrInsertHistory());
         mTests.add(new TestInsertHistoryThumbnails());
         mTests.add(new TestUpdateHistoryThumbnails());
         mTests.add(new TestDeleteHistoryThumbnails());
 
+        mTests.add(new TestInsertUrlAnnotations());
+
         mTests.add(new TestBatchOperations());
 
         mTests.add(new TestCombinedView());
         mTests.add(new TestCombinedViewDisplay());
         mTests.add(new TestCombinedViewWithDeletedBookmark());
         mTests.add(new TestExpireHistory());
 
         mTests.add(new TestBrowserProviderNotifications());
@@ -1405,16 +1426,46 @@ public class testBrowserProvider extends
             c.close();
 
             c = getThumbnailByUrl(pageUrl);
             mAsserter.is(c.moveToFirst(), false, "Thumbnail is deleted with last reference to it");
             c.close();
         }
     }
 
+    private class TestInsertUrlAnnotations extends TestCase {
+        @Override
+        public void test() throws Exception {
+            final String url = "http://mozilla.org";
+            final String key = "todo";
+            final String value = "v";
+            final long dateCreated = System.currentTimeMillis();
+
+            mProvider.insert(BrowserContract.UrlAnnotations.CONTENT_URI, createUrlAnnotationEntry(url, key, value, dateCreated));
+
+            final Cursor c = getUrlAnnotationByUrl(url);
+            try {
+                mAsserter.is(c.moveToFirst(), true, "Inserted url annotation found");
+
+                mAsserter.is(c.getString(c.getColumnIndex(BrowserContract.UrlAnnotations.KEY)), key,
+                        "Inserted url annotation has correct key");
+                mAsserter.is(c.getString(c.getColumnIndex(BrowserContract.UrlAnnotations.VALUE)), value,
+                        "Inserted url annotation has correct value");
+                mAsserter.is(c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_CREATED)), dateCreated,
+                        "Inserted url annotation has correct created");
+                mAsserter.is(c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_MODIFIED)), dateCreated,
+                        "Inserted url annotation has correct date modified");
+                mAsserter.is(c.getInt(c.getColumnIndex(BrowserContract.UrlAnnotations.SYNC_STATUS)), SyncStatus.NEW.getDBValue(),
+                        "Inserted url annotation has default sync status");
+            } finally {
+                c.close();
+            }
+        }
+    }
+
     private class TestCombinedView extends TestCase {
         @Override
         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 TITLE_3_BOOKMARK2 = "Test Page 3 (Bookmark Entry 2)";