• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */
16 package android.appsecurity.cts;
17 
18 import android.platform.test.annotations.AppModeFull;
19 import android.platform.test.annotations.AppModeInstant;
20 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
21 
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 
27 @RunWith(DeviceJUnit4ClassRunner.class)
28 public class IsolatedSplitsTests extends BaseAppSecurityTest {
29     private static final String PKG = "com.android.cts.isolatedsplitapp";
30     private static final String TEST_CLASS = PKG + ".SplitAppTest";
31 
32     /* The feature hierarchy looks like this:
33 
34         APK_BASE <- APK_FEATURE_A <- APK_FEATURE_B
35             ^------ APK_FEATURE_C
36 
37      */
38     private static final String APK_BASE = "CtsIsolatedSplitApp.apk";
39     private static final String APK_BASE_pl = "CtsIsolatedSplitApp_pl.apk";
40     private static final String APK_FEATURE_A = "CtsIsolatedSplitAppFeatureA.apk";
41     private static final String APK_FEATURE_A_pl = "CtsIsolatedSplitAppFeatureA_pl.apk";
42     private static final String APK_FEATURE_B = "CtsIsolatedSplitAppFeatureB.apk";
43     private static final String APK_FEATURE_B_pl = "CtsIsolatedSplitAppFeatureB_pl.apk";
44     private static final String APK_FEATURE_C = "CtsIsolatedSplitAppFeatureC.apk";
45     private static final String APK_FEATURE_C_pl = "CtsIsolatedSplitAppFeatureC_pl.apk";
46 
47     @Before
setUp()48     public void setUp() throws Exception {
49         Utils.prepareSingleUser(getDevice());
50         getDevice().uninstallPackage(PKG);
51     }
52 
53     @After
tearDown()54     public void tearDown() throws Exception {
55         getDevice().uninstallPackage(PKG);
56     }
57 
58     @Test
59     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallBase_full()60     public void testInstallBase_full() throws Exception {
61         testInstallBase(false);
62     }
63     @Test
64     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallBase_instant()65     public void testInstallBase_instant() throws Exception {
66         testInstallBase(true);
67     }
testInstallBase(boolean instant)68     private void testInstallBase(boolean instant) throws Exception {
69         new InstallMultiple(instant).addApk(APK_BASE).run();
70         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
71     }
72 
73     @Test
74     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallBaseAndConfigSplit_full()75     public void testInstallBaseAndConfigSplit_full() throws Exception {
76         testInstallBaseAndConfigSplit(false);
77     }
78     @Test
79     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallBaseAndConfigSplit_instant()80     public void testInstallBaseAndConfigSplit_instant() throws Exception {
81         testInstallBaseAndConfigSplit(true);
82     }
testInstallBaseAndConfigSplit(boolean instant)83     private void testInstallBaseAndConfigSplit(boolean instant) throws Exception {
84         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_BASE_pl).run();
85         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadPolishLocale");
86     }
87 
88     @Test
89     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallMissingDependency_full()90     public void testInstallMissingDependency_full() throws Exception {
91         testInstallMissingDependency(false);
92     }
93     @Test
94     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallMissingDependency_instant()95     public void testInstallMissingDependency_instant() throws Exception {
96         testInstallMissingDependency(true);
97     }
testInstallMissingDependency(boolean instant)98     private void testInstallMissingDependency(boolean instant) throws Exception {
99         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_FEATURE_B).runExpectingFailure();
100     }
101 
102     @Test
103     @AppModeFull(reason = "b/109878606; instant applications can't send broadcasts to manifest receivers")
testInstallOneFeatureSplit_full()104     public void testInstallOneFeatureSplit_full() throws Exception {
105         testInstallOneFeatureSplit(false);
106     }
testInstallOneFeatureSplit(boolean instant)107     private void testInstallOneFeatureSplit(boolean instant) throws Exception {
108         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_FEATURE_A).run();
109         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
110         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureADefault");
111         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureAReceivers");
112     }
113 
114     @Test
115     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallOneFeatureSplitAndConfigSplits_full()116     public void testInstallOneFeatureSplitAndConfigSplits_full() throws Exception {
117         testInstallOneFeatureSplitAndConfigSplits(false);
118     }
119     @Test
120     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallOneFeatureSplitAndConfigSplits_instant()121     public void testInstallOneFeatureSplitAndConfigSplits_instant() throws Exception {
122         testInstallOneFeatureSplitAndConfigSplits(true);
123     }
testInstallOneFeatureSplitAndConfigSplits(boolean instant)124     private void testInstallOneFeatureSplitAndConfigSplits(boolean instant) throws Exception {
125         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_FEATURE_A).addApk(APK_BASE_pl)
126                 .addApk(APK_FEATURE_A_pl).run();
127         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadPolishLocale");
128         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureAPolishLocale");
129     }
130 
131     @Test
132     @AppModeFull(reason = "b/109878606; instant applications can't send broadcasts to manifest receivers")
testInstallDependentFeatureSplits_full()133     public void testInstallDependentFeatureSplits_full() throws Exception {
134         testInstallDependentFeatureSplits(false);
135     }
testInstallDependentFeatureSplits(boolean instant)136     private void testInstallDependentFeatureSplits(boolean instant) throws Exception {
137         new InstallMultiple(instant)
138                 .addApk(APK_BASE).addApk(APK_FEATURE_A).addApk(APK_FEATURE_B).run();
139         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
140         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureADefault");
141         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureBDefault");
142         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureAAndBReceivers");
143     }
144 
145     @Test
146     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallDependentFeatureSplitsAndConfigSplits_full()147     public void testInstallDependentFeatureSplitsAndConfigSplits_full() throws Exception {
148         testInstallDependentFeatureSplitsAndConfigSplits(false);
149     }
150     @Test
151     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallDependentFeatureSplitsAndConfigSplits_instant()152     public void testInstallDependentFeatureSplitsAndConfigSplits_instant() throws Exception {
153         testInstallDependentFeatureSplitsAndConfigSplits(true);
154     }
testInstallDependentFeatureSplitsAndConfigSplits(boolean instant)155     private void testInstallDependentFeatureSplitsAndConfigSplits(boolean instant) throws Exception {
156         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_FEATURE_A).addApk(APK_FEATURE_B)
157                 .addApk(APK_BASE_pl).addApk(APK_FEATURE_A_pl).addApk(APK_FEATURE_B_pl).run();
158         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadPolishLocale");
159         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureAPolishLocale");
160         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureBPolishLocale");
161     }
162 
163     @Test
164     @AppModeFull(reason = "b/109878606; instant applications can't send broadcasts to manifest receivers")
testInstallAllFeatureSplits_full()165     public void testInstallAllFeatureSplits_full() throws Exception {
166         testInstallAllFeatureSplits(false);
167     }
testInstallAllFeatureSplits(boolean instant)168     private void testInstallAllFeatureSplits(boolean instant) throws Exception {
169         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_FEATURE_A).addApk(APK_FEATURE_B)
170                 .addApk(APK_FEATURE_C).run();
171         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
172         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureADefault");
173         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureBDefault");
174         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureCDefault");
175         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureAAndBAndCReceivers");
176     }
177 
178     @Test
179     @AppModeFull(reason = "'full' portion of the hostside test")
testInstallAllFeatureSplitsAndConfigSplits_full()180     public void testInstallAllFeatureSplitsAndConfigSplits_full() throws Exception {
181         testInstallAllFeatureSplitsAndConfigSplits(false);
182     }
183     @Test
184     @AppModeInstant(reason = "'instant' portion of the hostside test")
testInstallAllFeatureSplitsAndConfigSplits_instant()185     public void testInstallAllFeatureSplitsAndConfigSplits_instant() throws Exception {
186         testInstallAllFeatureSplitsAndConfigSplits(true);
187     }
testInstallAllFeatureSplitsAndConfigSplits(boolean instant)188     private void testInstallAllFeatureSplitsAndConfigSplits(boolean instant) throws Exception {
189         new InstallMultiple(instant).addApk(APK_BASE).addApk(APK_FEATURE_A).addApk(APK_FEATURE_B)
190                 .addApk(APK_FEATURE_C).addApk(APK_BASE_pl).addApk(APK_FEATURE_A_pl)
191                 .addApk(APK_FEATURE_C_pl).run();
192         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadDefault");
193         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureADefault");
194         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureBDefault");
195         Utils.runDeviceTests(getDevice(), PKG, TEST_CLASS, "shouldLoadFeatureCDefault");
196     }
197 }
198