diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-03-16 18:21:21 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-03-17 16:33:01 +0800 |
commit | 44294b68bdef9b1a06c070b998e53ce8c5732e5b (patch) | |
tree | 5bee80c200888d4a234d39a96923c73b3dc477ea /tests/src | |
parent | 81cc6353a3451f5c34ddb720a380b0d8d2ede45e (diff) | |
download | LegacyCamera-44294b68bdef9b1a06c070b998e53ce8c5732e5b.zip LegacyCamera-44294b68bdef9b1a06c070b998e53ce8c5732e5b.tar.gz LegacyCamera-44294b68bdef9b1a06c070b998e53ce8c5732e5b.tar.bz2 |
Add more image capture intent tests.
Change-Id: I533c9a2c9101488449331524209a7f202188ec36
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/camera/functional/CameraTest.java | 31 | ||||
-rw-r--r-- | tests/src/com/android/camera/functional/ImageCaptureIntentTest.java | 162 |
2 files changed, 162 insertions, 31 deletions
diff --git a/tests/src/com/android/camera/functional/CameraTest.java b/tests/src/com/android/camera/functional/CameraTest.java index 8f47e70..789310a 100644 --- a/tests/src/com/android/camera/functional/CameraTest.java +++ b/tests/src/com/android/camera/functional/CameraTest.java @@ -5,9 +5,7 @@ import com.android.camera.R; import com.android.camera.VideoCamera; import android.app.Activity; -import android.app.Instrumentation; import android.content.Intent; -import android.graphics.Bitmap; import android.net.Uri; import android.os.Environment; import android.os.Process; @@ -69,33 +67,4 @@ public class CameraTest extends InstrumentationTestCase { // If applications are leaking activity, every reference is reachable. assertTrue(refCount != TEST_COUNT); } - - @LargeTest - public void testImageCaptureIntent() throws Exception { - Instrumentation inst = getInstrumentation(); - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - final Camera activity = (Camera) launchActivityWithIntent( - inst.getTargetContext().getPackageName(), Camera.class, - intent); - - // Take a picture - inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS)); - inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA); - Thread.sleep(4000); - - // Press done button. - inst.runOnMainSync(new Runnable() { - public void run() { - activity.findViewById(R.id.btn_done).performClick(); - } - }); - - assertTrue(activity.isFinishing()); - assertEquals(Activity.RESULT_OK, activity.getResultCode()); - Intent resultData = activity.getResultData(); - Bitmap bitmap = (Bitmap) resultData.getParcelableExtra("data"); - assertNotNull(bitmap); - assertTrue(bitmap.getWidth() > 0); - assertTrue(bitmap.getHeight() > 0); - } } diff --git a/tests/src/com/android/camera/functional/ImageCaptureIntentTest.java b/tests/src/com/android/camera/functional/ImageCaptureIntentTest.java new file mode 100644 index 0000000..1de65d6 --- /dev/null +++ b/tests/src/com/android/camera/functional/ImageCaptureIntentTest.java @@ -0,0 +1,162 @@ +package com.android.camera.functional; + +import com.android.camera.Camera; +import com.android.camera.R; + +import android.app.Activity; +import android.app.Instrumentation; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Environment; +import android.os.Process; +import android.provider.MediaStore; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.UiThreadTest; +import android.util.Log; +import android.view.KeyEvent; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; + +public class ImageCaptureIntentTest extends ActivityInstrumentationTestCase2 <Camera> { + private static final String TAG = "ImageCaptureIntentTest"; + private Intent mIntent; + + public ImageCaptureIntentTest() { + super(Camera.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + } + + @LargeTest + public void testNoExtraOutput() throws Exception { + setActivityIntent(mIntent); + getActivity(); + + takePicture(); + pressDone(); + + assertTrue(getActivity().isFinishing()); + assertEquals(Activity.RESULT_OK, getActivity().getResultCode()); + Intent resultData = getActivity().getResultData(); + Bitmap bitmap = (Bitmap) resultData.getParcelableExtra("data"); + assertNotNull(bitmap); + assertTrue(bitmap.getWidth() > 0); + assertTrue(bitmap.getHeight() > 0); + } + + @LargeTest + public void testExtraOutput() throws Exception { + File file = new File(Environment.getExternalStorageDirectory(), + "test.jpg"); + BufferedInputStream stream = null; + byte[] jpegData; + + try { + mIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); + setActivityIntent(mIntent); + getActivity(); + + takePicture(); + pressDone(); + + assertTrue(getActivity().isFinishing()); + assertEquals(Activity.RESULT_OK, getActivity().getResultCode()); + + // Verify the jpeg file + int fileLength = (int) file.length(); + assertTrue(fileLength > 0); + jpegData = new byte[fileLength]; + stream = new BufferedInputStream(new FileInputStream(file)); + stream.read(jpegData); + } finally { + if (stream != null) stream.close(); + file.delete(); + } + + Bitmap b = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); + assertTrue(b.getWidth() > 0); + assertTrue(b.getHeight() > 0); + } + + @LargeTest + public void testRetake() throws Exception { + setActivityIntent(mIntent); + getActivity(); + + takePicture(); + pressRetake(); + takePicture(); + pressDone(); + + assertTrue(getActivity().isFinishing()); + assertEquals(Activity.RESULT_OK, getActivity().getResultCode()); + Intent resultData = getActivity().getResultData(); + Bitmap bitmap = (Bitmap) resultData.getParcelableExtra("data"); + assertNotNull(bitmap); + assertTrue(bitmap.getWidth() > 0); + assertTrue(bitmap.getHeight() > 0); + } + + @LargeTest + public void testCancel() throws Exception { + setActivityIntent(mIntent); + getActivity(); + + pressCancel(); + + assertTrue(getActivity().isFinishing()); + assertEquals(Activity.RESULT_CANCELED, getActivity().getResultCode()); + } + + @LargeTest + public void testSnapshotCancel() throws Exception { + setActivityIntent(mIntent); + getActivity(); + + takePicture(); + pressCancel(); + + assertTrue(getActivity().isFinishing()); + assertEquals(Activity.RESULT_CANCELED, getActivity().getResultCode()); + } + + private void takePicture() throws Exception { + getInstrumentation().sendKeySync( + new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS)); + getInstrumentation().sendCharacterSync(KeyEvent.KEYCODE_CAMERA); + Thread.sleep(4000); + } + + private void pressDone() { + getInstrumentation().runOnMainSync(new Runnable() { + public void run() { + getActivity().findViewById(R.id.btn_done).performClick(); + } + }); + } + + private void pressRetake() { + getInstrumentation().runOnMainSync(new Runnable() { + public void run() { + getActivity().findViewById(R.id.btn_retake).performClick(); + } + }); + } + + private void pressCancel() { + getInstrumentation().runOnMainSync(new Runnable() { + public void run() { + getActivity().findViewById(R.id.btn_cancel).performClick(); + } + }); + } +} |