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