summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2015-04-23 21:20:59 +0100
committerVictor Chang <vichang@google.com>2015-05-19 17:59:58 +0100
commit9de20f854362b38c5f766791a53c6891980e0ead (patch)
treefbbb728918808981d77f696443944743ea1cbe9f /tests
parent8bb283381b1eab710da6e4e0eeb537f3422235b4 (diff)
downloadandroid_packages_apps_Bluetooth-9de20f854362b38c5f766791a53c6891980e0ead.tar.gz
android_packages_apps_Bluetooth-9de20f854362b38c5f766791a53c6891980e0ead.tar.bz2
android_packages_apps_Bluetooth-9de20f854362b38c5f766791a53c6891980e0ead.zip
Add unit test for bluetooth contacts sharing policy
Bug: 19990980 Change-Id: Iacd7a53f21500cd809759f5498d54ffd87a8c242
Diffstat (limited to 'tests')
-rwxr-xr-xtests/Android.mk2
-rw-r--r--tests/src/com/android/bluetooth/tests/DevicePolicyUtilsTest.java115
2 files changed, 116 insertions, 1 deletions
diff --git a/tests/Android.mk b/tests/Android.mk
index ff848d907..e18a69697 100755
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -6,7 +6,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_JAVA_LIBRARIES := javax.obex android.test.runner telephony-common libprotobuf-java-micro
-LOCAL_STATIC_JAVA_LIBRARIES := com.android.emailcommon
+LOCAL_STATIC_JAVA_LIBRARIES := com.android.emailcommon littlemock dexmaker
# Include all test java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/src/com/android/bluetooth/tests/DevicePolicyUtilsTest.java b/tests/src/com/android/bluetooth/tests/DevicePolicyUtilsTest.java
new file mode 100644
index 000000000..b69fb15fb
--- /dev/null
+++ b/tests/src/com/android/bluetooth/tests/DevicePolicyUtilsTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015 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.bluetooth.tests;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.net.Uri;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.test.AndroidTestCase;
+
+import com.android.bluetooth.util.DevicePolicyUtils;
+import com.google.testing.littlemock.LittleMock;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static com.google.testing.littlemock.LittleMock.mock;
+import static com.google.testing.littlemock.LittleMock.doReturn;
+import static com.google.testing.littlemock.LittleMock.anyInt;
+
+public class DevicePolicyUtilsTest extends AndroidTestCase {
+ private static final String TAG = "DevicePolicyUtilsTest";
+
+ private static final String SYSTEM_PROPERTY_DEXMAKER_DEXCACHE = "dexmaker.dexcache";
+
+ private String mOriginalDexcache;
+
+ @Override
+ protected void setUp() {
+ mOriginalDexcache = System.getProperty(SYSTEM_PROPERTY_DEXMAKER_DEXCACHE);
+ System.setProperty(SYSTEM_PROPERTY_DEXMAKER_DEXCACHE, getContext().getCacheDir().getPath());
+ }
+
+ @Override
+ protected void tearDown() {
+ if (mOriginalDexcache == null) {
+ System.clearProperty(SYSTEM_PROPERTY_DEXMAKER_DEXCACHE);
+ } else {
+ System.setProperty(SYSTEM_PROPERTY_DEXMAKER_DEXCACHE, mOriginalDexcache);
+ }
+ }
+
+ public void testIsBluetoothWorkContactSharingDisabled() {
+ {
+ // normal user only with bluetoothContacts is disabled
+ Context mockContext = getMockContext(false, true);
+ Uri uri = DevicePolicyUtils.getEnterprisePhoneUri(mockContext);
+ assertEquals("expected: " + Phone.CONTENT_URI + " value = " + uri,
+ Phone.CONTENT_URI, uri);
+ }
+ {
+ // normal user only with bluetoothContacts is not disabled
+ Context mockContext = getMockContext(false, false);
+ Uri uri = DevicePolicyUtils.getEnterprisePhoneUri(mockContext);
+ assertEquals("expected: " + Phone.CONTENT_URI + " value = " + uri,
+ Phone.CONTENT_URI, uri);
+ }
+ {
+ // managedProfile with bluetoothContacts is disabled
+ Context mockContext = getMockContext(true, true);
+ Uri uri = DevicePolicyUtils.getEnterprisePhoneUri(mockContext);
+ assertEquals("expected: " + Phone.CONTENT_URI + " value = " + uri,
+ Phone.CONTENT_URI, uri);
+ }
+ {
+ // managedProfile with bluetoothContacts is not disabled
+ Context mockContext = getMockContext(true, false);
+ Uri uri = DevicePolicyUtils.getEnterprisePhoneUri(mockContext);
+ assertEquals("expected: " + Phone.ENTERPRISE_CONTENT_URI + " value = " + uri,
+ Phone.ENTERPRISE_CONTENT_URI, uri);
+ }
+ }
+
+ private static final List<UserInfo> NORMAL_USERINFO_LIST = Arrays.asList(
+ new UserInfo[]{ new UserInfo(0, "user0", 0)});
+
+ private static final List<UserInfo> MANAGED_USERINFO_LIST = Arrays.asList(new UserInfo[]{
+ new UserInfo(0, "user0", 0),
+ new UserInfo(10, "user10", UserInfo.FLAG_MANAGED_PROFILE)});
+
+ private Context getMockContext(boolean managedProfileExists,
+ boolean isBluetoothContactsSharingDisabled) {
+ DevicePolicyManager mockDpm = mock(DevicePolicyManager.class);
+ doReturn(isBluetoothContactsSharingDisabled).when(mockDpm)
+ .getBluetoothContactSharingDisabled(LittleMock.<UserHandle>anyObject());
+
+ UserManager mockUm = mock(UserManager.class);
+ doReturn(managedProfileExists ? MANAGED_USERINFO_LIST : NORMAL_USERINFO_LIST)
+ .when(mockUm).getProfiles(anyInt());
+
+ Context mockContext = mock(Context.class);
+ doReturn(mockDpm).when(mockContext).getSystemService(Context.DEVICE_POLICY_SERVICE);
+ doReturn(mockUm).when(mockContext).getSystemService(Context.USER_SERVICE);
+
+ return mockContext;
+ }
+}
+