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
17package com.android.camera.stress;
18
19import com.android.camera.CameraActivity;
20import com.android.camera.stress.TestUtil;
21
22import android.app.Activity;
23import android.app.Instrumentation;
24import android.content.Intent;
25import android.provider.MediaStore;
26import android.test.ActivityInstrumentationTestCase2;
27import android.test.suitebuilder.annotation.LargeTest;
28import android.view.KeyEvent;
29
30import 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
43public 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
53    public VideoCapture() {
54        super(CameraActivity.class);
55    }
56
57    @Override
58    protected void setUp() throws Exception {
59        testUtil.prepareOutputFile();
60        super.setUp();
61    }
62
63    @Override
64    protected void tearDown() throws Exception {
65        testUtil.closeOutputFile();
66        super.tearDown();
67    }
68
69    public void captureVideos(String reportTag, Instrumentation inst) throws Exception{
70        boolean memoryResult = false;
71        int total_num_of_videos = CameraStressTestRunner.mVideoIterations;
72        int video_duration = CameraStressTestRunner.mVideoDuration;
73        testUtil.writeReportHeader(reportTag, total_num_of_videos);
74
75        for (int i = 0; i < total_num_of_videos; i++) {
76            Thread.sleep(WAIT_FOR_PREVIEW);
77            // record a video
78            inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
79            Thread.sleep(video_duration);
80            inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
81            testUtil.writeResult(i);
82        }
83    }
84
85    public void testBackVideoCapture() throws Exception {
86        Instrumentation inst = getInstrumentation();
87        Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
88
89        intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.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    public void testFrontVideoCapture() throws Exception {
100        Instrumentation inst = getInstrumentation();
101        Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
102
103        intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class);
104        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
105        intent.putExtra(EXTRAS_CAMERA_FACING,
106                android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
107        Activity act = inst.startActivitySync(intent);
108        Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
109        captureVideos("Front Camera Video Capture\n", inst);
110        act.finish();
111    }
112}
113