blob: fed18fa1bcb0307e8b512ea740714ed57408211c [file] [log] [blame]
Daniel Nishiabb4bd22017-01-11 17:46:42 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settingslib.applications;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.mockito.Mockito.mock;
Antony Sargent67952e92017-02-10 11:07:42 -080022import static org.mockito.Mockito.when;
Daniel Nishiabb4bd22017-01-11 17:46:42 -080023
24import android.content.pm.ApplicationInfo;
25
26import org.junit.Before;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.junit.runners.JUnit4;
30
31@RunWith(JUnit4.class)
32public class ApplicationsStateTest {
Daniel Nishiabb4bd22017-01-11 17:46:42 -080033 private ApplicationsState.AppEntry mEntry;
34
35 @Before
36 public void setUp() {
Daniel Nishiabb4bd22017-01-11 17:46:42 -080037 mEntry = mock(ApplicationsState.AppEntry.class);
38 mEntry.info = mock(ApplicationInfo.class);
39 }
40
41 @Test
42 public void testGamesFilterAcceptsGameDeprecated() {
43 mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME;
44
Daniel Nishi7e336822017-01-19 14:12:56 -080045 assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isTrue();
Daniel Nishiabb4bd22017-01-11 17:46:42 -080046 }
47
48 @Test
49 public void testGameFilterAcceptsCategorizedGame() {
50 mEntry.info.category = ApplicationInfo.CATEGORY_GAME;
51
Daniel Nishi7e336822017-01-19 14:12:56 -080052 assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isTrue();
Daniel Nishiabb4bd22017-01-11 17:46:42 -080053 }
54
55 @Test
56 public void testGameFilterAcceptsCategorizedGameAndDeprecatedIsGame() {
57 mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME;
58 mEntry.info.category = ApplicationInfo.CATEGORY_GAME;
59
Daniel Nishi7e336822017-01-19 14:12:56 -080060 assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isTrue();
Daniel Nishiabb4bd22017-01-11 17:46:42 -080061 }
62
63 @Test
64 public void testGamesFilterRejectsNotGame() {
65 mEntry.info.category = ApplicationInfo.CATEGORY_UNDEFINED;
66
Daniel Nishi7e336822017-01-19 14:12:56 -080067 assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isFalse();
68 }
69
70 @Test
71 public void testAudioFilterAcceptsCategorizedAudio() {
72 mEntry.info.category = ApplicationInfo.CATEGORY_AUDIO;
73
74 assertThat(ApplicationsState.FILTER_AUDIO.filterApp(mEntry)).isTrue();
75 }
76
77 @Test
78 public void testAudiosFilterRejectsNotAudio() {
79 mEntry.info.category = ApplicationInfo.CATEGORY_GAME;
80
81 assertThat(ApplicationsState.FILTER_AUDIO.filterApp(mEntry)).isFalse();
82 }
83
84 @Test
85 public void testAudiosFilterRejectsDefaultCategory() {
86 mEntry.info.category = ApplicationInfo.CATEGORY_UNDEFINED;
87
88 assertThat(ApplicationsState.FILTER_AUDIO.filterApp(mEntry)).isFalse();
Daniel Nishiabb4bd22017-01-11 17:46:42 -080089 }
Daniel Nishibd8c6652017-02-08 12:20:12 -080090
91 @Test
92 public void testOtherAppsRejectsAudio() {
93 mEntry.info.category = ApplicationInfo.CATEGORY_AUDIO;
94
95 assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isFalse();
96 }
97
98 @Test
99 public void testOtherAppsRejectsGame() {
100 mEntry.info.category = ApplicationInfo.CATEGORY_GAME;
101
102 assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isFalse();
103 }
104
105 @Test
106 public void testOtherAppsAcceptsDefaultCategory() {
107 mEntry.info.category = ApplicationInfo.CATEGORY_UNDEFINED;
108
109 assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isTrue();
110 }
Antony Sargent67952e92017-02-10 11:07:42 -0800111
112 @Test
Jesse Evans13be12e2017-03-30 17:30:00 -0700113 public void testDownloadAndLauncherAndInstantAcceptsCorrectApps() {
114 // should include instant apps
115 mEntry.isHomeApp = false;
116 mEntry.hasLauncherEntry = false;
117 when(mEntry.info.isInstantApp()).thenReturn(true);
118 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
119 .isTrue();
120
121 // should included updated system apps
122 when(mEntry.info.isInstantApp()).thenReturn(false);
123 mEntry.info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
124 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
125 .isTrue();
126
127 // should not include system apps other than the home app
128 mEntry.info.flags = ApplicationInfo.FLAG_SYSTEM;
129 mEntry.isHomeApp = false;
130 mEntry.hasLauncherEntry = false;
131 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
132 .isFalse();
133
134 // should include the home app
135 mEntry.isHomeApp = true;
136 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
137 .isTrue();
138
139 // should include any System app with a launcher entry
140 mEntry.isHomeApp = false;
141 mEntry.hasLauncherEntry = true;
142 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER_AND_INSTANT.filterApp(mEntry))
143 .isTrue();
144 }
145
146 @Test
147 public void testDownloadAndLauncherAcceptsCorrectApps() {
148 mEntry.isHomeApp = false;
149 mEntry.hasLauncherEntry = false;
150
151 // should included updated system apps
152 when(mEntry.info.isInstantApp()).thenReturn(false);
153 mEntry.info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
154 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
155 .isTrue();
156
157 // should not include system apps other than the home app
158 mEntry.info.flags = ApplicationInfo.FLAG_SYSTEM;
159 mEntry.isHomeApp = false;
160 mEntry.hasLauncherEntry = false;
161 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
162 .isFalse();
163
164 // should include the home app
165 mEntry.isHomeApp = true;
166 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
167 .isTrue();
168
169 // should include any System app with a launcher entry
170 mEntry.isHomeApp = false;
171 mEntry.hasLauncherEntry = true;
172 assertThat(ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER.filterApp(mEntry))
173 .isTrue();
174 }
175
176 @Test
Daniel Nishi140ceb12017-03-31 10:20:08 -0700177 public void testOtherAppsRejectsLegacyGame() {
178 mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME;
179
180 assertThat(ApplicationsState.FILTER_OTHER_APPS.filterApp(mEntry)).isFalse();
181 }
182
183 @Test
Antony Sargent67952e92017-02-10 11:07:42 -0800184 public void testInstantFilterAcceptsInstantApp() {
185 when(mEntry.info.isInstantApp()).thenReturn(true);
186 assertThat(ApplicationsState.FILTER_INSTANT.filterApp(mEntry)).isTrue();
187 }
188
189 @Test
190 public void testInstantFilterRejectsNonInstantApp() {
191 when(mEntry.info.isInstantApp()).thenReturn(false);
192 assertThat(ApplicationsState.FILTER_INSTANT.filterApp(mEntry)).isFalse();
193 }
194
195 @Test
196 public void testEnabledFilterRejectsInstantApp() {
197 mEntry.info.enabled = true;
198 assertThat(ApplicationsState.FILTER_ALL_ENABLED.filterApp(mEntry)).isTrue();
199 when(mEntry.info.isInstantApp()).thenReturn(true);
200 assertThat(ApplicationsState.FILTER_ALL_ENABLED.filterApp(mEntry)).isFalse();
201 }
202
203 @Test
Jesse Evansad2b7752017-04-12 18:06:50 -0700204 public void testFilterWithDomainUrls() {
205 mEntry.info.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
206 // should included updated system apps
207 when(mEntry.info.isInstantApp()).thenReturn(false);
208 assertThat(ApplicationsState.FILTER_WITH_DOMAIN_URLS.filterApp(mEntry))
209 .isTrue();
210 mEntry.info.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
211 assertThat(ApplicationsState.FILTER_WITH_DOMAIN_URLS.filterApp(mEntry))
212 .isFalse();
213 mEntry.info.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
214 when(mEntry.info.isInstantApp()).thenReturn(true);
215 assertThat(ApplicationsState.FILTER_WITH_DOMAIN_URLS.filterApp(mEntry))
216 .isFalse();
217 }
218
219 @Test
Antony Sargent67952e92017-02-10 11:07:42 -0800220 public void testDisabledFilterRejectsInstantApp() {
221 mEntry.info.enabled = false;
222 assertThat(ApplicationsState.FILTER_DISABLED.filterApp(mEntry)).isTrue();
223 when(mEntry.info.isInstantApp()).thenReturn(true);
224 assertThat(ApplicationsState.FILTER_DISABLED.filterApp(mEntry)).isFalse();
225 }
Daniel Nishi45c23fa2017-03-27 13:19:02 -0700226
227 @Test
228 public void testVideoFilterAcceptsCategorizedVideo() {
229 mEntry.info.category = ApplicationInfo.CATEGORY_VIDEO;
230
231 assertThat(ApplicationsState.FILTER_MOVIES.filterApp(mEntry)).isTrue();
232 }
233
234 @Test
235 public void testVideosFilterRejectsNotVideo() {
236 mEntry.info.category = ApplicationInfo.CATEGORY_GAME;
237
238 assertThat(ApplicationsState.FILTER_MOVIES.filterApp(mEntry)).isFalse();
239 }
Daniel Nishiabb4bd22017-01-11 17:46:42 -0800240}