VideoFragmentTest.java revision c22611ecee4fcc5c1ad27f4367c0c2c00368d488
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 */ 16package android.support.v17.leanback.app; 17 18import static org.junit.Assert.assertNotNull; 19 20import android.content.Intent; 21import android.support.test.InstrumentationRegistry; 22import android.support.test.filters.MediumTest; 23import android.support.test.rule.ActivityTestRule; 24import android.support.test.runner.AndroidJUnit4; 25import android.support.v17.leanback.test.R; 26import android.view.SurfaceHolder; 27 28import org.junit.Rule; 29import org.junit.Test; 30import org.junit.runner.RunWith; 31 32@MediumTest 33@RunWith(AndroidJUnit4.class) 34public class VideoFragmentTest { 35 36 @Rule 37 public ActivityTestRule<VideoFragmentTestActivity> activityTestRule = 38 new ActivityTestRule<>(VideoFragmentTestActivity.class, false, false); 39 private VideoFragmentTestActivity mActivity; 40 41 @Test 42 public void setSurfaceViewCallbackBeforeCreate() { 43 Intent intent = new Intent(); 44 mActivity = activityTestRule.launchActivity(intent); 45 46 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { 47 @Override 48 public void run() { 49 mActivity.replaceVideoFragment(); 50 } 51 }); 52 53 VideoFragment fragment = (VideoFragment) mActivity.getFragmentManager().findFragmentById( 54 R.id.video_fragment); 55 assertNotNull(fragment); 56 } 57 58 @Test 59 public void setSurfaceViewCallbackAfterCreate() { 60 Intent intent = new Intent(); 61 mActivity = activityTestRule.launchActivity(intent); 62 63 VideoFragment fragment = (VideoFragment) mActivity.getFragmentManager().findFragmentById( 64 R.id.video_fragment); 65 assertNotNull(fragment); 66 67 fragment.setSurfaceHolderCallback(new SurfaceHolder.Callback() { 68 @Override 69 public void surfaceCreated(SurfaceHolder holder) { 70 } 71 72 @Override 73 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 74 } 75 76 @Override 77 public void surfaceDestroyed(SurfaceHolder holder) { 78 } 79 }); 80 } 81} 82