From 078eda97bb4a47f441cb134d3d34d82b706c6523 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Thu, 25 Feb 2016 17:47:00 -0800 Subject: [PATCH] Bug 1250707 - Add test for UrlAnnotations.insert. r=sebastian MozReview-Commit-ID: LmnxRlcxIi --HG-- extra : rebase_source : 7bad7592d739dfdf1a36e58ca942b75d1ad2746a --- .../gecko/tests/testBrowserProvider.java | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git 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 index bab3cd653081..5d456a16812c 100644 --- 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 @@ -1434,6 +1434,11 @@ public class testBrowserProvider extends ContentProviderTest { private class TestInsertUrlAnnotations extends TestCase { @Override public void test() throws Exception { + testInsertionViaContentProvider(); + testInsertionViaUrlAnnotations(); + } + + private void testInsertionViaContentProvider() throws Exception { final String url = "http://mozilla.org"; final String key = "todo"; final String value = "v"; @@ -1444,21 +1449,45 @@ public class testBrowserProvider extends ContentProviderTest { 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"); + assertKeyValueSync(c, key, value); mAsserter.is(c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_CREATED)), dateCreated, - "Inserted url annotation has correct created"); + "Inserted url annotation has correct date 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 void testInsertionViaUrlAnnotations() throws Exception { + final String url = "http://hello.org"; + final String key = "toTheUniverse"; + final String value = "42a"; + final long timeBeforeCreation = System.currentTimeMillis(); + + getTestProfile().getDB().getUrlAnnotations().insertAnnotation(mResolver, url, key, value); + + final Cursor c = getUrlAnnotationByUrl(url); + try { + mAsserter.is(c.moveToFirst(), true, "Inserted url annotation found"); + assertKeyValueSync(c, key, value); + mAsserter.is(true, c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_CREATED)) >= timeBeforeCreation, + "Inserted url annotation has date created greater than or equal to time saved before insertion"); + mAsserter.is(true, c.getLong(c.getColumnIndex(BrowserContract.UrlAnnotations.DATE_MODIFIED)) >= timeBeforeCreation, + "Inserted url annotation has correct date modified greater than or equal to time saved before insertion"); + } finally { + c.close(); + } + } + + private void assertKeyValueSync(final Cursor c, final String key, final String value) { + 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.getInt(c.getColumnIndex(BrowserContract.UrlAnnotations.SYNC_STATUS)), SyncStatus.NEW.getDBValue(), + "Inserted url annotation has default sync status"); + } } private class TestCombinedView extends TestCase {