Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settingslib.applications; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.mockito.Mockito.mock; |
Antony Sargent | 67952e9 | 2017-02-10 11:07:42 -0800 | [diff] [blame] | 22 | import static org.mockito.Mockito.when; |
Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 23 | |
| 24 | import android.content.pm.ApplicationInfo; |
| 25 | |
| 26 | import org.junit.Before; |
| 27 | import org.junit.Test; |
| 28 | import org.junit.runner.RunWith; |
| 29 | import org.junit.runners.JUnit4; |
| 30 | |
| 31 | @RunWith(JUnit4.class) |
| 32 | public class ApplicationsStateTest { |
Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 33 | private ApplicationsState.AppEntry mEntry; |
| 34 | |
| 35 | @Before |
| 36 | public void setUp() { |
Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 37 | 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 Nishi | 7e33682 | 2017-01-19 14:12:56 -0800 | [diff] [blame] | 45 | assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isTrue(); |
Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testGameFilterAcceptsCategorizedGame() { |
| 50 | mEntry.info.category = ApplicationInfo.CATEGORY_GAME; |
| 51 | |
Daniel Nishi | 7e33682 | 2017-01-19 14:12:56 -0800 | [diff] [blame] | 52 | assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isTrue(); |
Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Test |
| 56 | public void testGameFilterAcceptsCategorizedGameAndDeprecatedIsGame() { |
| 57 | mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME; |
| 58 | mEntry.info.category = ApplicationInfo.CATEGORY_GAME; |
| 59 | |
Daniel Nishi | 7e33682 | 2017-01-19 14:12:56 -0800 | [diff] [blame] | 60 | assertThat(ApplicationsState.FILTER_GAMES.filterApp(mEntry)).isTrue(); |
Daniel Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void testGamesFilterRejectsNotGame() { |
| 65 | mEntry.info.category = ApplicationInfo.CATEGORY_UNDEFINED; |
| 66 | |
Daniel Nishi | 7e33682 | 2017-01-19 14:12:56 -0800 | [diff] [blame] | 67 | 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 Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 89 | } |
Daniel Nishi | bd8c665 | 2017-02-08 12:20:12 -0800 | [diff] [blame] | 90 | |
| 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 Sargent | 67952e9 | 2017-02-10 11:07:42 -0800 | [diff] [blame] | 111 | |
| 112 | @Test |
Jesse Evans | 13be12e | 2017-03-30 17:30:00 -0700 | [diff] [blame] | 113 | 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 Nishi | 140ceb1 | 2017-03-31 10:20:08 -0700 | [diff] [blame] | 177 | 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 Sargent | 67952e9 | 2017-02-10 11:07:42 -0800 | [diff] [blame] | 184 | 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 Evans | ad2b775 | 2017-04-12 18:06:50 -0700 | [diff] [blame] | 204 | 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 Sargent | 67952e9 | 2017-02-10 11:07:42 -0800 | [diff] [blame] | 220 | 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 Nishi | 45c23fa | 2017-03-27 13:19:02 -0700 | [diff] [blame] | 226 | |
| 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 Nishi | abb4bd2 | 2017-01-11 17:46:42 -0800 | [diff] [blame] | 240 | } |