diff options
author | John Reck <jreck@google.com> | 2011-03-03 15:30:26 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-03-03 15:53:19 -0800 |
commit | 57e39f9e46091750c8a07895531446a7f0efdb21 (patch) | |
tree | 1c3ab3a9af062201482db8dd7e727c50670be40d /tests/src/com/android | |
parent | b52c0d8be3486e0e2d89a39c521daa5020605ac2 (diff) | |
download | packages_apps_browser-57e39f9e46091750c8a07895531446a7f0efdb21.zip packages_apps_browser-57e39f9e46091750c8a07895531446a7f0efdb21.tar.gz packages_apps_browser-57e39f9e46091750c8a07895531446a7f0efdb21.tar.bz2 |
Fix isValidParent check
Bug: 3506038
Lookup the parent itself, not the children of the parent in
isValidParent check. Also, adds testing to watch for regressions
Change-Id: I59f00094f862f2e9cd4b4f9fd92d370b87e612e5
Diffstat (limited to 'tests/src/com/android')
4 files changed, 88 insertions, 8 deletions
diff --git a/tests/src/com/android/browser/BrowserProviderTests.java b/tests/src/com/android/browser/BrowserProviderTests.java index f4bf942..eb8ba80 100644 --- a/tests/src/com/android/browser/BrowserProviderTests.java +++ b/tests/src/com/android/browser/BrowserProviderTests.java @@ -16,11 +16,14 @@ package com.android.browser; +import com.android.browser.provider.BrowserProvider2; +import com.android.browser.tests.utils.ProviderTestCase3; + import android.app.SearchManager; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; -import android.test.AndroidTestCase; +import android.provider.BrowserContract; import android.test.suitebuilder.annotation.MediumTest; import java.util.ArrayList; @@ -30,10 +33,15 @@ import java.util.Arrays; * Unit tests for {@link BrowserProvider}. */ @MediumTest -public class BrowserProviderTests extends AndroidTestCase { +public class BrowserProviderTests extends ProviderTestCase3<BrowserProvider2> { private ArrayList<Uri> mDeleteUris; + public BrowserProviderTests() { + super(BrowserProvider2.class, + BrowserContract.AUTHORITY, BrowserProvider2.LEGACY_AUTHORITY); + } + @Override protected void setUp() throws Exception { mDeleteUris = new ArrayList<Uri>(); @@ -128,7 +136,7 @@ public class BrowserProviderTests extends AndroidTestCase { private Cursor getBookmarksSuggest(String query) { Uri suggestUri = Uri.parse("content://browser/bookmarks/search_suggest_query"); String[] selectionArgs = { query }; - Cursor c = getContext().getContentResolver().query(suggestUri, null, "url LIKE ?", + Cursor c = getMockContentResolver().query(suggestUri, null, "url LIKE ?", selectionArgs, null); assertNotNull(c); return c; @@ -149,12 +157,12 @@ public class BrowserProviderTests extends AndroidTestCase { values.put("date", 0); values.put("created", 0); values.put("bookmark", 1); - return getContext().getContentResolver().insert(android.provider.Browser.BOOKMARKS_URI, + return getMockContentResolver().insert(android.provider.Browser.BOOKMARKS_URI, values); } private void deleteUri(Uri uri) { - int count = getContext().getContentResolver().delete(uri, null, null); + int count = getMockContentResolver().delete(uri, null, null); assertEquals("Failed to delete " + uri, 1, count); } diff --git a/tests/src/com/android/browser/tests/BP2ProviderTests.java b/tests/src/com/android/browser/tests/BP2ProviderTests.java index a468fcd..6c3c71e 100644 --- a/tests/src/com/android/browser/tests/BP2ProviderTests.java +++ b/tests/src/com/android/browser/tests/BP2ProviderTests.java @@ -18,9 +18,13 @@ package com.android.browser.tests; import com.android.browser.tests.utils.BP2TestCaseHelper; +import android.content.ContentUris; import android.content.ContentValues; +import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; +import android.net.Uri; +import android.provider.BrowserContract; import android.provider.BrowserContract.Images; import android.test.suitebuilder.annotation.SmallTest; @@ -43,4 +47,58 @@ public class BP2ProviderTests extends BP2TestCaseHelper { assertTrue(updateBookmark(Images.CONTENT_URI, values)); } + public void testIsValidParentNullAccount() { + doTestIsValidParent(null, null); + } + + public void testIsValidParentWithAccount() { + doTestIsValidParent("test@gmail.com", "com.google"); + } + + private void doTestIsValidParent(String accountName, String accountType) { + ContentValues values = new ContentValues(); + values.put(BrowserContract.Bookmarks.TITLE, "New Folder"); + values.put(BrowserContract.Bookmarks.IS_FOLDER, 1); + values.put(BrowserContract.Bookmarks.ACCOUNT_NAME, accountName); + values.put(BrowserContract.Bookmarks.ACCOUNT_TYPE, accountType); + Uri folderUri = insertBookmark(values); + assertNotNull(folderUri); + long folderId = ContentUris.parseId(folderUri); + assertTrue("Failed to parse folder id!", folderId > 0); + values.put(BrowserContract.Bookmarks.TITLE, "google"); + values.put(BrowserContract.Bookmarks.URL, "http://google.com"); + values.put(BrowserContract.Bookmarks.IS_FOLDER, 0); + values.put(BrowserContract.Bookmarks.PARENT, folderId); + Uri insertedUri = insertBookmark(values); + assertNotNull(insertedUri); + Cursor c = getMockContentResolver().query(insertedUri, + new String[] { BrowserContract.Bookmarks.PARENT }, + null, null, null); + try { + assertNotNull(c); + assertTrue(c.moveToFirst()); + long insertedParentId = c.getLong(0); + assertEquals(folderId, insertedParentId); + if (accountName == null) { + values.put(BrowserContract.Bookmarks.ACCOUNT_NAME, "test2@gmail.com"); + values.put(BrowserContract.Bookmarks.ACCOUNT_TYPE, "com.google"); + } else { + values.remove(BrowserContract.Bookmarks.ACCOUNT_NAME); + values.remove(BrowserContract.Bookmarks.ACCOUNT_TYPE); + } + insertedUri = insertBookmark(values); + assertNotNull(insertedUri); + c.close(); + c = getMockContentResolver().query(insertedUri, + new String[] { BrowserContract.Bookmarks.PARENT }, + null, null, null); + assertNotNull(c); + assertTrue(c.moveToFirst()); + insertedParentId = c.getLong(0); + assertFalse("child has different accounts than parent!", + folderId == insertedParentId); + } finally { + c.close(); + } + } } diff --git a/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java b/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java index 58e5bbe..18c1c10 100644 --- a/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java +++ b/tests/src/com/android/browser/tests/utils/BP2TestCaseHelper.java @@ -120,9 +120,9 @@ public abstract class BP2TestCaseHelper extends ProviderTestCase3<BrowserProvide } } - Uri mockInsert(Uri url, ContentValues values) { + Uri mockInsert(Uri uri, ContentValues values) { assertObserversTriggered(false, mLegacyObserver, mRootObserver); - Uri ret = getMockContentResolver().insert(url, values); + Uri ret = getMockContentResolver().insert(uri, values); assertObserversTriggered(true, mLegacyObserver, mRootObserver); return ret; } @@ -145,6 +145,10 @@ public abstract class BP2TestCaseHelper extends ProviderTestCase3<BrowserProvide values.put(BrowserContract.Bookmarks.TITLE, title); values.put(BrowserContract.Bookmarks.URL, url); values.put(BrowserContract.Bookmarks.IS_FOLDER, 0); + return insertBookmark(values); + } + + public Uri insertBookmark(ContentValues values) { assertObserversTriggered(false, mBookmarksObserver, mWidgetObserver); Uri ret = mockInsert(Bookmarks.CONTENT_URI, values); assertObserversTriggered(true, mBookmarksObserver, mWidgetObserver); diff --git a/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java b/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java index 5799b0f..c374292 100644 --- a/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java +++ b/tests/src/com/android/browser/tests/utils/ProviderTestCase3.java @@ -18,7 +18,7 @@ package com.android.browser.tests.utils; import android.content.ContentProvider; import android.content.Context; -import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Resources; import android.database.ContentObserver; import android.net.Uri; @@ -56,6 +56,16 @@ public abstract class ProviderTestCase3<T extends ContentProvider> extends Andro } @Override + public String getPackageName() { + return getContext().getPackageName(); + } + + @Override + public SharedPreferences getSharedPreferences(String name, int mode) { + return getContext().getSharedPreferences("mockcontext2_" + name, mode); + } + + @Override public Context getApplicationContext() { return this; } |