1// CHECKSTYLE:OFF Generated code 2/* This file is auto-generated from GuidedStepFrgamentTestBase.java. DO NOT MODIFY. */ 3 4/* 5 * Copyright (C) 2016 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19package android.support.v17.leanback.app; 20 21import static org.mockito.Mockito.mock; 22import static org.mockito.Mockito.timeout; 23import static org.mockito.Mockito.verify; 24import static org.mockito.Mockito.when; 25 26import android.content.Intent; 27import android.support.test.InstrumentationRegistry; 28import android.support.test.rule.ActivityTestRule; 29import android.support.v17.leanback.R; 30import android.support.v17.leanback.testutils.PollingCheck; 31import android.view.View; 32 33import org.junit.Before; 34import org.junit.Rule; 35import org.junit.rules.TestName; 36 37/** 38 * @hide from javadoc 39 */ 40public class GuidedStepSupportFragmentTestBase { 41 42 private static final long TIMEOUT = 5000; 43 44 @Rule public TestName mUnitTestName = new TestName(); 45 46 @Rule 47 public ActivityTestRule<GuidedStepSupportFragmentTestActivity> activityTestRule = 48 new ActivityTestRule<>(GuidedStepSupportFragmentTestActivity.class, false, false); 49 50 @Before 51 public void clearTests() { 52 GuidedStepTestSupportFragment.clearTests(); 53 } 54 55 public static class ExpandTransitionFinish extends PollingCheck.PollingCheckCondition { 56 GuidedStepTestSupportFragment.Provider mProvider; 57 58 public ExpandTransitionFinish(GuidedStepTestSupportFragment.Provider provider) { 59 mProvider = provider; 60 } 61 62 @Override 63 public boolean canPreProceed() { 64 return false; 65 } 66 67 @Override 68 public boolean canProceed() { 69 GuidedStepTestSupportFragment fragment = mProvider.getFragment(); 70 if (fragment != null && fragment.getView() != null) { 71 if (!fragment.getGuidedActionsStylist().isInExpandTransition()) { 72 // expand transition finishes 73 return true; 74 } 75 } 76 return false; 77 } 78 } 79 80 public static void waitOnDestroy(GuidedStepTestSupportFragment.Provider provider, 81 int times) { 82 verify(provider, timeout((int)TIMEOUT).times(times)).onDestroy(); 83 } 84 85 public static class EnterTransitionFinish extends PollingCheck.PollingCheckCondition { 86 PollingCheck.ViewScreenPositionDetector mDector = 87 new PollingCheck.ViewScreenPositionDetector(); 88 89 GuidedStepTestSupportFragment.Provider mProvider; 90 91 public EnterTransitionFinish(GuidedStepTestSupportFragment.Provider provider) { 92 mProvider = provider; 93 } 94 @Override 95 public boolean canProceed() { 96 GuidedStepTestSupportFragment fragment = mProvider.getFragment(); 97 if (fragment != null && fragment.getView() != null) { 98 View view = fragment.getView().findViewById(R.id.guidance_title); 99 if (view != null) { 100 if (mDector.isViewStableOnScreen(view)) { 101 return true; 102 } 103 } 104 } 105 return false; 106 } 107 } 108 109 public static void sendKey(int keyCode) { 110 InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(keyCode); 111 } 112 113 public String generateMethodTestName(String testName) { 114 return mUnitTestName.getMethodName() + "_" + testName; 115 } 116 117 public GuidedStepSupportFragmentTestActivity launchTestActivity(String firstTestName) { 118 Intent intent = new Intent(); 119 intent.putExtra(GuidedStepSupportFragmentTestActivity.EXTRA_TEST_NAME, firstTestName); 120 return activityTestRule.launchActivity(intent); 121 } 122 123 public GuidedStepSupportFragmentTestActivity launchTestActivity(String firstTestName, 124 boolean addAsRoot) { 125 Intent intent = new Intent(); 126 intent.putExtra(GuidedStepSupportFragmentTestActivity.EXTRA_TEST_NAME, firstTestName); 127 intent.putExtra(GuidedStepSupportFragmentTestActivity.EXTRA_ADD_AS_ROOT, addAsRoot); 128 return activityTestRule.launchActivity(intent); 129 } 130 131 public GuidedStepSupportFragmentTestActivity launchTestActivity(String firstTestName, 132 boolean addAsRoot, int layoutDirection) { 133 Intent intent = new Intent(); 134 intent.putExtra(GuidedStepSupportFragmentTestActivity.EXTRA_TEST_NAME, firstTestName); 135 intent.putExtra(GuidedStepSupportFragmentTestActivity.EXTRA_ADD_AS_ROOT, addAsRoot); 136 intent.putExtra(GuidedStepSupportFragmentTestActivity.EXTRA_LAYOUT_DIRECTION, layoutDirection); 137 return activityTestRule.launchActivity(intent); 138 } 139 140 public GuidedStepTestSupportFragment.Provider mockProvider(String testName) { 141 GuidedStepTestSupportFragment.Provider test = mock(GuidedStepTestSupportFragment.Provider.class); 142 when(test.getActivity()).thenCallRealMethod(); 143 when(test.getFragmentManager()).thenCallRealMethod(); 144 when(test.getFragment()).thenCallRealMethod(); 145 GuidedStepTestSupportFragment.setupTest(testName, test); 146 return test; 147 } 148} 149 150