1 /*
2  * Copyright (C) 2019 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 android.server.wm.intent;
18 
19 import android.content.ComponentName;
20 import android.server.wm.ActivityManagerTestBase;
21 import android.server.wm.intent.Persistence.TestCase;
22 
23 import org.junit.After;
24 
25 import java.util.List;
26 
27 public abstract class IntentTestBase extends ActivityManagerTestBase {
28 
29     /**
30      * This get's called from {@link IntentGenerationTests} because {@link IntentGenerationTests}
31      * run multiple {@link TestCase}-s in a single junit test.
32      *
33      * Normal test classes can just extend this class with manual cleanUp.
34      *
35      * @param activitiesInUsedInTest activities that should be gone after tearDown
36      */
cleanUp(List<ComponentName> activitiesInUsedInTest)37     public void cleanUp(List<ComponentName> activitiesInUsedInTest) throws Exception {
38         launchHomeActivityNoWait();
39         removeRootTasksWithActivityTypes(ALL_ACTIVITY_TYPE_BUT_HOME);
40 
41         this.getWmState().waitForWithAmState(
42                 state -> state.containsNoneOf(activitiesInUsedInTest),
43                 "activity to be removed");
44     }
45 
46     @After
tearDown()47     public void tearDown() throws Exception {
48         cleanUp(activitiesUsedInTest());
49     }
50 
51     /**
52      * @return The activities that are launched in this Test.
53      */
activitiesUsedInTest()54     abstract List<ComponentName> activitiesUsedInTest();
55 }
56