summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRuslan Abdikeev <aruslan@google.com>2012-05-14 08:14:11 -0700
committerRuslan Abdikeev <aruslan@google.com>2012-05-14 08:14:11 -0700
commit60c131771453fcb65e03ae77f8a378bfa48e6498 (patch)
tree4603f6b3bd3f3afb731368b727f8e34f270d8568 /tests
parent6b04cb56970c528aaf379a64c1492af01ce9ef7e (diff)
downloadPartnerBookmarksProvider-60c131771453fcb65e03ae77f8a378bfa48e6498.tar.gz
Default implementation of PartnerBookmarksProvider
A “Default” Partner Bookmark content provider implements the Partner Bookmarks Content Provider API, and uses xml and raw resources to extract the set of bookmarks and corresponding icons. Bug: 6399404 Change-Id: I416e87320b2ba958aa4f260277e4d6de20856c48
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.mk31
-rw-r--r--tests/AndroidManifest.xml37
-rw-r--r--tests/src/com/android/providers/partnerbookmarks/PartnerBookmarksProviderTest.java108
3 files changed, 176 insertions, 0 deletions
diff --git a/tests/Android.mk b/tests/Android.mk
new file mode 100644
index 0000000..7177397
--- /dev/null
+++ b/tests/Android.mk
@@ -0,0 +1,31 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# We only want this apk build for tests.
+LOCAL_MODULE_TAGS := tests
+
+# Include all test java files.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := PartnerBookmarksProviderTest
+
+LOCAL_JAVA_LIBRARIES := ext android.test.runner
+
+LOCAL_INSTRUMENTATION_FOR := PartnerBookmarksProvider
+
+include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
new file mode 100644
index 0000000..6e6ba14
--- /dev/null
+++ b/tests/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- package name must be unique so suffix with "tests" -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.providers.partnerbookmarks.tests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!--
+ The test declared in this instrumentation will be run along with tests
+ declared by all other applications via the command: "adb shell itr".
+ The "itr" command will find all tests declared by all applications.
+ If you want to run just these tests on their own then use the command:
+ "adb shell am instrument -w com.android.providers.partnerbookmarks.tests/android.test.InstrumentationTestRunner"
+ -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.providers.partnerbookmarks"
+ android:label="partner bookmarks provider tests"/>
+
+ <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
+</manifest>
diff --git a/tests/src/com/android/providers/partnerbookmarks/PartnerBookmarksProviderTest.java b/tests/src/com/android/providers/partnerbookmarks/PartnerBookmarksProviderTest.java
new file mode 100644
index 0000000..9014d14
--- /dev/null
+++ b/tests/src/com/android/providers/partnerbookmarks/PartnerBookmarksProviderTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.providers.partnerbookmarks;
+
+import android.content.ContentProviderClient;
+import android.database.Cursor;
+import android.test.InstrumentationTestCase;
+import android.test.mock.MockContext;
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
+import android.util.Log;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class PartnerBookmarksProviderTest extends InstrumentationTestCase {
+ private static final String TAG = "PartnerBookmarksProviderTest";
+ private static final long FIXED_ID_PARTNER_BOOKMARKS_ROOT =
+ PartnerBookmarksContract.Bookmarks.BOOKMARK_PARENT_ROOT_ID + 1;
+ private static final long NO_FOLDER_FILTER = -1;
+
+ @Override
+ public void setUp() {
+ }
+
+ @Override
+ public void tearDown() {
+ }
+
+ private int countBookmarksInFolder(long folderFilter) throws android.os.RemoteException {
+ ContentProviderClient providerClient =
+ getInstrumentation().getTargetContext().
+ getContentResolver().acquireContentProviderClient(
+ PartnerBookmarksContract.Bookmarks.CONTENT_URI);
+ assertNotNull(
+ "Failed to acquire " + PartnerBookmarksContract.Bookmarks.CONTENT_URI,
+ providerClient);
+ Cursor cursor = providerClient.query(PartnerBookmarksContract.Bookmarks.CONTENT_URI,
+ null, null, null, null);
+ assertNotNull("Failed to query for bookmarks", cursor);
+ int bookmarksCount = 0;
+ while (!cursor.isLast() && !cursor.isAfterLast()) {
+ cursor.moveToNext();
+ long id = cursor.getLong(
+ cursor.getColumnIndexOrThrow(PartnerBookmarksContract.Bookmarks.ID));
+ long parent = cursor.getLong(
+ cursor.getColumnIndexOrThrow(PartnerBookmarksContract.Bookmarks.PARENT));
+ if (folderFilter != NO_FOLDER_FILTER && folderFilter != parent)
+ continue;
+ boolean isFolder = cursor.getInt(
+ cursor.getColumnIndexOrThrow(PartnerBookmarksContract.Bookmarks.TYPE))
+ == PartnerBookmarksContract.Bookmarks.BOOKMARK_TYPE_FOLDER;
+ String url = cursor.getString(
+ cursor.getColumnIndexOrThrow(PartnerBookmarksContract.Bookmarks.URL));
+ String title = cursor.getString(
+ cursor.getColumnIndexOrThrow(PartnerBookmarksContract.Bookmarks.TITLE));
+ bookmarksCount++;
+ }
+ return bookmarksCount;
+ }
+
+ @SmallTest
+ public void testExactlyOneRoot() throws android.os.RemoteException {
+ int totalBookmarks = countBookmarksInFolder(NO_FOLDER_FILTER);
+ if (totalBookmarks > 0) {
+ assertEquals("There must be at most one root",
+ countBookmarksInFolder(
+ PartnerBookmarksContract.Bookmarks.BOOKMARK_PARENT_ROOT_ID),
+ 1);
+ }
+ }
+
+ @SmallTest
+ public void testRootMustBeNonEmptyIfPresent() throws android.os.RemoteException {
+ int totalBookmarks = countBookmarksInFolder(NO_FOLDER_FILTER);
+ if (totalBookmarks > 0) {
+ assertTrue("If the root exists, it must be non-empty",
+ countBookmarksInFolder(FIXED_ID_PARTNER_BOOKMARKS_ROOT) > 0);
+ }
+ }
+
+ @SmallTest
+ public void testDefaultPBPSupportsOnlyFlatListOfBookmarks()
+ throws android.os.RemoteException {
+ int totalBookmarks = countBookmarksInFolder(NO_FOLDER_FILTER);
+ if (totalBookmarks > 0) {
+ assertEquals("Default PBP supports only flat list of bookmarks",
+ countBookmarksInFolder(FIXED_ID_PARTNER_BOOKMARKS_ROOT),
+ totalBookmarks - 1);
+ }
+ }
+}