1 /* 2 * Copyright (C) 2016 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; 18 19 import static android.server.wm.DialogFrameTestActivity.EXTRA_TEST_CASE; 20 import static android.server.wm.StateLogger.log; 21 22 import static org.junit.Assert.assertTrue; 23 24 import android.app.Activity; 25 import android.content.ComponentName; 26 import android.content.Intent; 27 import android.server.wm.WindowManagerState.WindowState; 28 29 import androidx.test.rule.ActivityTestRule; 30 31 abstract class ParentChildTestBase<T extends Activity> extends ActivityManagerTestBase { 32 33 interface ParentChildTest { doTest(WindowState parent, WindowState child)34 void doTest(WindowState parent, WindowState child); 35 } 36 startTestCase(String testCase)37 private void startTestCase(String testCase) throws Exception { 38 final Intent intent = new Intent() 39 .putExtra(EXTRA_TEST_CASE, testCase); 40 activityRule().launchActivity(intent); 41 } 42 startTestCaseDocked(String testCase)43 private void startTestCaseDocked(String testCase) throws Exception { 44 startTestCase(testCase); 45 mWmState.computeState(activityName()); 46 putActivityInPrimarySplit(activityName()); 47 } 48 activityName()49 abstract ComponentName activityName(); activityRule()50 abstract ActivityTestRule<T> activityRule(); 51 doSingleTest(ParentChildTest t)52 abstract void doSingleTest(ParentChildTest t) throws Exception; 53 doFullscreenTest(String testCase, ParentChildTest t)54 void doFullscreenTest(String testCase, ParentChildTest t) throws Exception { 55 log("Running test fullscreen"); 56 startTestCase(testCase); 57 doSingleTest(t); 58 activityRule().finishActivity(); 59 } 60 doDockedTest(String testCase, ParentChildTest t)61 private void doDockedTest(String testCase, ParentChildTest t) throws Exception { 62 log("Running test docked"); 63 if (!supportsSplitScreenMultiWindow()) { 64 log("Skipping test: no split multi-window support"); 65 return; 66 } 67 startTestCaseDocked(testCase); 68 doSingleTest(t); 69 activityRule().finishActivity(); 70 71 mWmState.waitFor(wmState -> !wmState.containsActivity(activityName()), 72 "activity must be removed"); 73 assertTrue(mTaskOrganizer.getPrimarySplitTaskCount() == 0); 74 } 75 doParentChildTest(String testCase, ParentChildTest t)76 void doParentChildTest(String testCase, ParentChildTest t) throws Exception { 77 doFullscreenTest(testCase, t); 78 doDockedTest(testCase, t); 79 } 80 } 81