1 /* 2 * Copyright (C) 2009 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 com.android.camera.power; 18 19 import android.app.Instrumentation; 20 import android.content.Intent; 21 import android.test.ActivityInstrumentationTestCase2; 22 import android.util.Log; 23 import android.view.KeyEvent; 24 25 import androidx.test.filters.LargeTest; 26 27 import com.android.camera.Camera; 28 import com.android.camera.VideoCamera; 29 30 /** 31 * Junit / Instrumentation test case for camera power measurement 32 * 33 * Running the test suite: 34 * 35 * adb shell am instrument \ 36 * -e com.android.camera.power.ImageAndVideoCapture \ 37 * -w com.android.camera.tests/android.test.InstrumentationTestRunner 38 * 39 */ 40 41 public class ImageAndVideoCapture extends ActivityInstrumentationTestCase2 <Camera> { 42 private String TAG = "ImageAndVideoCapture"; 43 private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 5; 44 private static final int TOTAL_NUMBER_OF_VIDEOCAPTURE = 5; 45 private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds 46 private static final long WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN = 10000; //10 seconds 47 private static final long WAIT_FOR_PREVIEW = 1500; //1.5 seconds 48 private static final long WAIT_FOR_STABLE_STATE = 2000; //2 seconds 49 ImageAndVideoCapture()50 public ImageAndVideoCapture() { 51 super(Camera.class); 52 } 53 54 @Override setUp()55 protected void setUp() throws Exception { 56 getActivity(); 57 super.setUp(); 58 } 59 60 @Override tearDown()61 protected void tearDown() throws Exception { 62 super.tearDown(); 63 } 64 65 @LargeTest testLaunchCamera()66 public void testLaunchCamera() { 67 // This test case capture the baseline for the image preview. 68 try { 69 Thread.sleep(WAIT_FOR_STABLE_STATE); 70 } catch (Exception e) { 71 Log.v(TAG, "Got exception", e); 72 assertTrue("testImageCaptureDoNothing", false); 73 } 74 } 75 76 @LargeTest testCapture5Image()77 public void testCapture5Image() { 78 // This test case will use the default camera setting 79 Instrumentation inst = getInstrumentation(); 80 try { 81 for (int i = 0; i < TOTAL_NUMBER_OF_IMAGECAPTURE; i++) { 82 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 83 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP); 84 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 85 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 86 } 87 Thread.sleep(WAIT_FOR_STABLE_STATE); 88 } catch (Exception e) { 89 Log.v(TAG, "Got exception", e); 90 assertTrue("testImageCapture", false); 91 } 92 } 93 94 @LargeTest testCapture5Videos()95 public void testCapture5Videos() { 96 // This test case will use the default camera setting 97 Instrumentation inst = getInstrumentation(); 98 try { 99 // Switch to the video mode 100 Intent intent = new Intent(); 101 intent.setClass(getInstrumentation().getTargetContext(), 102 VideoCamera.class); 103 getActivity().startActivity(intent); 104 for (int i = 0; i < TOTAL_NUMBER_OF_VIDEOCAPTURE; i++) { 105 Thread.sleep(WAIT_FOR_PREVIEW); 106 // record a video 107 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 108 Thread.sleep(WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN); 109 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 110 Thread.sleep(WAIT_FOR_PREVIEW); 111 } 112 Thread.sleep(WAIT_FOR_STABLE_STATE); 113 } catch (Exception e) { 114 Log.v(TAG, "Got exception", e); 115 assertTrue("testVideoCapture", false); 116 } 117 } 118 } 119