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 android.support.test.rule; 18 19 import android.app.Activity; 20 import android.support.annotation.NonNull; 21 import android.support.test.InstrumentationRegistry; 22 import android.support.test.runner.intercepting.SingleActivityFactory; 23 24 /** 25 * An extension of existing {@link ActivityTestRule} that contains a fix for finishActivity() 26 * method (cr/138555678). 27 * 28 * Remove this once we move to Android Test Runner 0.7. 29 */ 30 public class BootlegActivityTestRule<T extends Activity> extends ActivityTestRule { BootlegActivityTestRule(Class activityClass)31 public BootlegActivityTestRule(Class activityClass) { 32 super(activityClass); 33 } 34 BootlegActivityTestRule(Class<T> activityClass, boolean initialTouchMode)35 public BootlegActivityTestRule(Class<T> activityClass, boolean initialTouchMode) { 36 super(activityClass, initialTouchMode); 37 } 38 BootlegActivityTestRule(Class<T> activityClass, boolean initialTouchMode, boolean launchActivity)39 public BootlegActivityTestRule(Class<T> activityClass, boolean initialTouchMode, 40 boolean launchActivity) { 41 super(activityClass, initialTouchMode, launchActivity); 42 } 43 BootlegActivityTestRule( SingleActivityFactory activityFactory, boolean initialTouchMode, boolean launchActivity)44 public BootlegActivityTestRule( 45 SingleActivityFactory activityFactory, 46 boolean initialTouchMode, boolean launchActivity) { 47 super(activityFactory, initialTouchMode, launchActivity); 48 } 49 BootlegActivityTestRule(Class<T> activityClass, @NonNull String targetPackage, int launchFlags, boolean initialTouchMode, boolean launchActivity)50 public BootlegActivityTestRule(Class<T> activityClass, 51 @NonNull String targetPackage, int launchFlags, 52 boolean initialTouchMode, boolean launchActivity) { 53 super(activityClass, targetPackage, launchFlags, initialTouchMode, launchActivity); 54 } 55 56 @Override finishActivity()57 public void finishActivity() { 58 super.finishActivity(); 59 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); 60 } 61 62 @Override getActivity()63 public T getActivity() { 64 return (T) super.getActivity(); 65 } 66 } 67