1 /*
2  * Copyright (C) 2010 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.stress;
18 
19 import android.app.Activity;
20 import android.app.Instrumentation;
21 import android.content.Intent;
22 import android.test.ActivityInstrumentationTestCase2;
23 import android.view.KeyEvent;
24 
25 import androidx.test.filters.LargeTest;
26 
27 import com.android.camera.VideoCamera;
28 
29 /**
30  * Junit / Instrumentation test case for camera test
31  *
32  * Running the test suite:
33  *
34  * adb shell am instrument \
35  *    -e class com.android.camera.stress.VideoCapture \
36  *    -w com.google.android.camera.tests/android.test.InstrumentationTestRunner
37  *
38  */
39 
40 public class VideoCapture extends ActivityInstrumentationTestCase2 <VideoCamera> {
41     private String TAG = "VideoCapture";
42     private static final long WAIT_FOR_PREVIEW = 1500; //1.5 seconds
43     private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //2 seconds
44 
45     // Private intent extras which control the camera facing.
46     private final static String EXTRAS_CAMERA_FACING =
47         "android.intent.extras.CAMERA_FACING";
48 
49     private TestUtil testUtil = new TestUtil();
50 
VideoCapture()51     public VideoCapture() {
52         super(VideoCamera.class);
53     }
54 
55     @Override
setUp()56     protected void setUp() throws Exception {
57         testUtil.prepareOutputFile();
58         super.setUp();
59     }
60 
61     @Override
tearDown()62     protected void tearDown() throws Exception {
63         testUtil.closeOutputFile();
64         super.tearDown();
65     }
66 
67     @LargeTest
captureVideos(String reportTag, Instrumentation inst)68     public void captureVideos(String reportTag, Instrumentation inst) throws Exception{
69         boolean memoryResult = false;
70         int total_num_of_videos = CameraStressTestRunner.mVideoIterations;
71         int video_duration = CameraStressTestRunner.mVideoDuration;
72         testUtil.writeReportHeader(reportTag, total_num_of_videos);
73 
74         for (int i = 0; i < total_num_of_videos; i++) {
75             Thread.sleep(WAIT_FOR_PREVIEW);
76             // record a video
77             inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
78             Thread.sleep(video_duration);
79             inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
80             testUtil.writeResult(i);
81         }
82     }
83 
84     @LargeTest
testBackVideoCapture()85     public void testBackVideoCapture() throws Exception {
86         Instrumentation inst = getInstrumentation();
87         Intent intent = new Intent();
88 
89         intent.setClass(getInstrumentation().getTargetContext(), VideoCamera.class);
90         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
91         intent.putExtra(EXTRAS_CAMERA_FACING,
92                 android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
93         Activity act = inst.startActivitySync(intent);
94         Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
95         captureVideos("Back Camera Video Capture\n", inst);
96         act.finish();
97     }
98 
99     @LargeTest
testFrontVideoCapture()100     public void testFrontVideoCapture() throws Exception {
101         Instrumentation inst = getInstrumentation();
102         Intent intent = new Intent();
103 
104         intent.setClass(getInstrumentation().getTargetContext(), VideoCamera.class);
105         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
106         intent.putExtra(EXTRAS_CAMERA_FACING,
107                 android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
108         Activity act = inst.startActivitySync(intent);
109         Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
110         captureVideos("Front Camera Video Capture\n", inst);
111         act.finish();
112     }
113 }
114