summaryrefslogtreecommitdiffstats
path: root/packages/DocumentsUI/tests
diff options
context:
space:
mode:
Diffstat (limited to 'packages/DocumentsUI/tests')
-rw-r--r--packages/DocumentsUI/tests/Android.mk16
-rw-r--r--packages/DocumentsUI/tests/AndroidManifest.xml13
-rw-r--r--packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java123
3 files changed, 152 insertions, 0 deletions
diff --git a/packages/DocumentsUI/tests/Android.mk b/packages/DocumentsUI/tests/Android.mk
new file mode 100644
index 0000000..fdf4fab
--- /dev/null
+++ b/packages/DocumentsUI/tests/Android.mk
@@ -0,0 +1,16 @@
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_PACKAGE_NAME := DocumentsUITests
+LOCAL_INSTRUMENTATION_FOR := DocumentsUI
+
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
diff --git a/packages/DocumentsUI/tests/AndroidManifest.xml b/packages/DocumentsUI/tests/AndroidManifest.xml
new file mode 100644
index 0000000..81a2889
--- /dev/null
+++ b/packages/DocumentsUI/tests/AndroidManifest.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.documentsui.tests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.documentsui"
+ android:label="Tests for DocumentsUI" />
+
+</manifest>
diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java
new file mode 100644
index 0000000..f53e60d
--- /dev/null
+++ b/packages/DocumentsUI/tests/src/com/android/documentsui/RootsCacheTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2013 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.documentsui;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.documentsui.DocumentsActivity.State;
+import com.android.documentsui.model.RootInfo;
+import com.google.android.collect.Lists;
+
+import java.util.List;
+
+@SmallTest
+public class RootsCacheTest extends AndroidTestCase {
+
+ private static RootInfo buildForMimeTypes(String... mimeTypes) {
+ final RootInfo root = new RootInfo();
+ root.mimeTypes = mimeTypes;
+ return root;
+ }
+
+ private RootInfo mNull = new RootInfo();
+ private RootInfo mEmpty = buildForMimeTypes();
+ private RootInfo mWild = buildForMimeTypes("*/*");
+ private RootInfo mImages = buildForMimeTypes("image/*");
+ private RootInfo mAudio = buildForMimeTypes("audio/*", "application/ogg", "application/x-flac");
+ private RootInfo mDocs = buildForMimeTypes("application/msword", "application/vnd.ms-excel");
+ private RootInfo mMalformed1 = buildForMimeTypes("meow");
+ private RootInfo mMalformed2 = buildForMimeTypes("*/meow");
+
+ private List<RootInfo> mRoots = Lists.newArrayList(
+ mNull, mWild, mEmpty, mImages, mAudio, mDocs, mMalformed1, mMalformed2);
+
+ private State mState;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mState = new State();
+ mState.action = State.ACTION_OPEN;
+ mState.showAdvanced = true;
+ mState.localOnly = false;
+ }
+
+ public void testMatchingRootsEverything() throws Exception {
+ mState.acceptMimes = new String[] { "*/*" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mImages, mAudio, mDocs, mMalformed1, mMalformed2),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsPngOrWild() throws Exception {
+ mState.acceptMimes = new String[] { "image/png", "*/*" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mImages, mAudio, mDocs, mMalformed1, mMalformed2),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsAudioWild() throws Exception {
+ mState.acceptMimes = new String[] { "audio/*" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mAudio),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsAudioWildOrImageWild() throws Exception {
+ mState.acceptMimes = new String[] { "audio/*", "image/*" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mAudio, mImages),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsAudioSpecific() throws Exception {
+ mState.acceptMimes = new String[] { "audio/mpeg" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mAudio),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsDocument() throws Exception {
+ mState.acceptMimes = new String[] { "application/msword" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mDocs),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsApplication() throws Exception {
+ mState.acceptMimes = new String[] { "application/*" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mAudio, mDocs),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ public void testMatchingRootsFlacOrPng() throws Exception {
+ mState.acceptMimes = new String[] { "application/x-flac", "image/png" };
+ assertContainsExactly(
+ Lists.newArrayList(mNull, mWild, mAudio, mImages),
+ RootsCache.getMatchingRoots(mRoots, mState));
+ }
+
+ private static void assertContainsExactly(List<?> expected, List<?> actual) {
+ assertEquals(expected.size(), actual.size());
+ for (Object o : expected) {
+ assertTrue(actual.contains(o));
+ }
+ }
+}