Home | History | Annotate | Download | only in wm
      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.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
     20 import static android.server.am.StateLogger.log;
     21 import static android.server.wm.DialogFrameTestActivity.EXTRA_TEST_CASE;
     22 
     23 import android.app.Activity;
     24 import android.content.ComponentName;
     25 import android.content.Intent;
     26 import android.server.am.ActivityManagerTestBase;
     27 import android.server.am.WindowManagerState.WindowState;
     28 import android.support.test.rule.ActivityTestRule;
     29 
     30 abstract class ParentChildTestBase<T extends Activity> extends ActivityManagerTestBase {
     31 
     32     interface ParentChildTest {
     33         void doTest(WindowState parent, WindowState child);
     34     }
     35 
     36     private void startTestCase(String testCase) throws Exception {
     37         final Intent intent = new Intent()
     38                 .putExtra(EXTRA_TEST_CASE, testCase);
     39         activityRule().launchActivity(intent);
     40     }
     41 
     42     private void startTestCaseDocked(String testCase) throws Exception {
     43         startTestCase(testCase);
     44         setActivityTaskWindowingMode(activityName(), WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
     45     }
     46 
     47     abstract ComponentName activityName();
     48     abstract ActivityTestRule<T> activityRule();
     49 
     50     abstract void doSingleTest(ParentChildTest t) throws Exception;
     51 
     52     void doFullscreenTest(String testCase, ParentChildTest t) throws Exception {
     53         log("Running test fullscreen");
     54         startTestCase(testCase);
     55         doSingleTest(t);
     56         activityRule().finishActivity();
     57     }
     58 
     59     private void doDockedTest(String testCase, ParentChildTest t) throws Exception {
     60         log("Running test docked");
     61         if (!supportsSplitScreenMultiWindow()) {
     62             log("Skipping test: no split multi-window support");
     63             return;
     64         }
     65         startTestCaseDocked(testCase);
     66         doSingleTest(t);
     67         activityRule().finishActivity();
     68     }
     69 
     70     void doParentChildTest(String testCase, ParentChildTest t) throws Exception {
     71         doFullscreenTest(testCase, t);
     72         doDockedTest(testCase, t);
     73     }
     74 }
     75