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