summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-08-09 13:48:21 -0700
committerJohn Reck <jreck@google.com>2011-08-09 13:48:21 -0700
commit2bc42420fdf7e42cbdcca0a07e73fbefe7edb5bf (patch)
tree51b9a5bacc13aac84cf73a8402444a10d7f0717c /tests
parent37d9f2f4c540131453b692d6cb17468637dcef9e (diff)
downloadpackages_apps_browser-2bc42420fdf7e42cbdcca0a07e73fbefe7edb5bf.zip
packages_apps_browser-2bc42420fdf7e42cbdcca0a07e73fbefe7edb5bf.tar.gz
packages_apps_browser-2bc42420fdf7e42cbdcca0a07e73fbefe7edb5bf.tar.bz2
Fix BP2ProviderTests
Bug: 5142434 For testIsValidParentWithAccount, the test would remove the account* from a bookmark it was inserting with a valid parent. The provider would correctly identify that a parent was set, but no account info and thus used the account info of the parent. This is not what the test was expecting, however, leading to this error. Fix the tests to explicitly check for child account* not matching parent account* (in which case the parent is discarded, and the bookmark is inserted at the root folder of the child's account*), and for testing the lack of a specified account*. Change-Id: I15b318ee1e846b18ffa187720814c3761d19933a
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/browser/tests/BP2ProviderTests.java64
1 files changed, 49 insertions, 15 deletions
diff --git a/tests/src/com/android/browser/tests/BP2ProviderTests.java b/tests/src/com/android/browser/tests/BP2ProviderTests.java
index 6c3c71e..fa1b9ef 100644
--- a/tests/src/com/android/browser/tests/BP2ProviderTests.java
+++ b/tests/src/com/android/browser/tests/BP2ProviderTests.java
@@ -33,6 +33,15 @@ import java.io.ByteArrayOutputStream;
@SmallTest
public class BP2ProviderTests extends BP2TestCaseHelper {
+ static final String[] PROJECTION = new String[] {
+ BrowserContract.Bookmarks.PARENT,
+ BrowserContract.Bookmarks.ACCOUNT_NAME,
+ BrowserContract.Bookmarks.ACCOUNT_TYPE,
+ };
+ static final int INDEX_PARENT = 0;
+ static final int INDEX_ACCOUNT_NAME = 1;
+ static final int INDEX_ACCOUNT_TYPE = 2;
+
public void testUpdateImage() {
String url = "http://stub1.com";
insertBookmark(url, "stub 1");
@@ -56,6 +65,7 @@ public class BP2ProviderTests extends BP2TestCaseHelper {
}
private void doTestIsValidParent(String accountName, String accountType) {
+ // Create the folder
ContentValues values = new ContentValues();
values.put(BrowserContract.Bookmarks.TITLE, "New Folder");
values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
@@ -65,6 +75,7 @@ public class BP2ProviderTests extends BP2TestCaseHelper {
assertNotNull(folderUri);
long folderId = ContentUris.parseId(folderUri);
assertTrue("Failed to parse folder id!", folderId > 0);
+ // Insert a bookmark with the same ACCOUNT_* info as parent
values.put(BrowserContract.Bookmarks.TITLE, "google");
values.put(BrowserContract.Bookmarks.URL, "http://google.com");
values.put(BrowserContract.Bookmarks.IS_FOLDER, 0);
@@ -72,31 +83,54 @@ public class BP2ProviderTests extends BP2TestCaseHelper {
Uri insertedUri = insertBookmark(values);
assertNotNull(insertedUri);
Cursor c = getMockContentResolver().query(insertedUri,
- new String[] { BrowserContract.Bookmarks.PARENT },
- null, null, null);
+ PROJECTION, null, null, null);
try {
assertNotNull(c);
assertTrue(c.moveToFirst());
- long insertedParentId = c.getLong(0);
+ long insertedParentId = c.getLong(INDEX_PARENT);
+ String insertedAccountName = c.getString(INDEX_ACCOUNT_NAME);
+ String insertedAccountType = c.getString(INDEX_ACCOUNT_TYPE);
+ assertEquals(folderId, insertedParentId);
+ assertEquals(accountName, insertedAccountName);
+ assertEquals(accountType, insertedAccountType);
+
+ // Insert a bookmark with no ACCOUNT_* set, BUT with a valid parent
+ // The inserted should end up with the ACCOUNT_* of the parent
+ values.remove(BrowserContract.Bookmarks.ACCOUNT_NAME);
+ values.remove(BrowserContract.Bookmarks.ACCOUNT_TYPE);
+ insertedUri = insertBookmark(values);
+ assertNotNull(insertedUri);
+ c.close();
+ c = getMockContentResolver().query(insertedUri,
+ PROJECTION, null, null, null);
+ assertNotNull(c);
+ assertTrue(c.moveToFirst());
+ insertedParentId = c.getLong(INDEX_PARENT);
+ insertedAccountName = c.getString(INDEX_ACCOUNT_NAME);
+ insertedAccountType = c.getString(INDEX_ACCOUNT_TYPE);
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);
- }
+ assertEquals(accountName, insertedAccountName);
+ assertEquals(accountType, insertedAccountType);
+
+ // Insert a bookmark with a different ACCOUNT_* than it's parent
+ // ACCOUNT_* should override parent
+ accountName = accountName + "@something.else";
+ accountType = "com.google";
+ values.put(BrowserContract.Bookmarks.ACCOUNT_NAME, accountName);
+ values.put(BrowserContract.Bookmarks.ACCOUNT_TYPE, accountType);
insertedUri = insertBookmark(values);
assertNotNull(insertedUri);
c.close();
c = getMockContentResolver().query(insertedUri,
- new String[] { BrowserContract.Bookmarks.PARENT },
- null, null, null);
+ PROJECTION, null, null, null);
assertNotNull(c);
assertTrue(c.moveToFirst());
- insertedParentId = c.getLong(0);
- assertFalse("child has different accounts than parent!",
- folderId == insertedParentId);
+ insertedParentId = c.getLong(INDEX_PARENT);
+ insertedAccountName = c.getString(INDEX_ACCOUNT_NAME);
+ insertedAccountType = c.getString(INDEX_ACCOUNT_TYPE);
+ assertNotSame(folderId, insertedParentId);
+ assertEquals(accountName, insertedAccountName);
+ assertEquals(accountType, insertedAccountType);
} finally {
c.close();
}