diff options
| author | 2016-11-23 03:38:44 +0000 | |
|---|---|---|
| committer | 2016-11-23 03:38:47 +0000 | |
| commit | 2ca81f45c446774829017b6e0b74474ec8fded7b (patch) | |
| tree | 09cae62e053b7b316d5fd17c0a1008310835bb32 | |
| parent | a1963e422b8020f3db648efacb6cf4e780d175fa (diff) | |
| parent | cdbe1d645becca3db7707885e962d1a0b9612d93 (diff) | |
Merge "Add test for TileUtils."
| -rw-r--r-- | packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java new file mode 100644 index 000000000000..651a7cb69387 --- /dev/null +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2016 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.settingslib.drawer; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Bundle; +import android.os.UserHandle; +import android.util.ArrayMap; +import android.util.Pair; + +import com.android.settingslib.TestConfig; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; + +@RunWith(RobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class TileUtilsTest { + + @Mock + private Context mContext; + @Mock + private PackageManager mPackageManager; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + when(mContext.getPackageManager()).thenReturn(mPackageManager); + } + + @Test + public void getTilesForIntent_shouldParseCategory() { + final String testCategory = "category1"; + Intent intent = new Intent(); + Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>(); + List<Tile> outTiles = new ArrayList<>(); + List<ResolveInfo> info = new ArrayList<>(); + info.add(newInfo(true, testCategory)); + + when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) + .thenReturn(info); + + TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, + null /* defaultCategory */, outTiles, false /* usePriority */, + false /* checkCategory */); + + assertThat(outTiles.size()).isEqualTo(1); + assertThat(outTiles.get(0).category).isEqualTo(testCategory); + } + + @Test + public void getTilesForIntent_shouldSkipNonSystemApp() { + final String testCategory = "category1"; + Intent intent = new Intent(); + Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>(); + List<Tile> outTiles = new ArrayList<>(); + List<ResolveInfo> info = new ArrayList<>(); + info.add(newInfo(false, testCategory)); + + when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) + .thenReturn(info); + + TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, + null /* defaultCategory */, outTiles, false /* usePriority */, + false /* checkCategory */); + + assertThat(outTiles.isEmpty()).isTrue(); + } + + private ResolveInfo newInfo(boolean systemApp, String category) { + ResolveInfo info = new ResolveInfo(); + info.system = systemApp; + info.activityInfo = new ActivityInfo(); + info.activityInfo.packageName = "abc"; + info.activityInfo.name = "123"; + info.activityInfo.metaData = new Bundle(); + info.activityInfo.metaData.putString("com.android.settings.category", category); + info.activityInfo.applicationInfo = new ApplicationInfo(); + return info; + } +} |