This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera] Add Android & iOS implementations for pausing the camera preview #4258
Merged
fluttergithubbot
merged 7 commits into
flutter:master
from
Baseflow:camera/preview-pause-impl-2
Aug 27, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
826f953
[camera] Add Android & iOS implementations for pausing the camera pre…
BeMacized 007ca56
Fixed punctuation
BeMacized 902637d
Added several missing tests
BeMacized 200be9d
Add more missing tests
BeMacized f96649b
Added iOS tests
BeMacized 28b2078
Merge remote-tracking branch 'upstream/master' into camera/preview-pa…
BeMacized 2fdaf5d
Merge branch 'master' into camera/preview-pause-impl-2
BeMacized File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...era/camera/android/src/test/java/io/flutter/plugins/camera/MethodCallHandlerImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.plugins.camera; | ||
|
|
||
| import static org.mockito.Mockito.doThrow; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| import android.app.Activity; | ||
| import android.hardware.camera2.CameraAccessException; | ||
| import io.flutter.plugin.common.BinaryMessenger; | ||
| import io.flutter.plugin.common.MethodCall; | ||
| import io.flutter.plugin.common.MethodChannel; | ||
| import io.flutter.plugins.camera.utils.TestUtils; | ||
| import io.flutter.view.TextureRegistry; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class MethodCallHandlerImplTest { | ||
|
|
||
| MethodChannel.MethodCallHandler handler; | ||
| MethodChannel.Result mockResult; | ||
| Camera mockCamera; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| handler = | ||
| new MethodCallHandlerImpl( | ||
| mock(Activity.class), | ||
| mock(BinaryMessenger.class), | ||
| mock(CameraPermissions.class), | ||
| mock(CameraPermissions.PermissionsRegistry.class), | ||
| mock(TextureRegistry.class), | ||
| null); | ||
| mockResult = mock(MethodChannel.Result.class); | ||
| mockCamera = mock(Camera.class); | ||
| TestUtils.setPrivateField(handler, "camera", mockCamera); | ||
| } | ||
|
|
||
| @Test | ||
| public void onMethodCall_pausePreview_shouldPausePreviewAndSendSuccessResult() | ||
| throws CameraAccessException { | ||
| handler.onMethodCall(new MethodCall("pausePreview", null), mockResult); | ||
|
|
||
| verify(mockCamera, times(1)).pausePreview(); | ||
| verify(mockResult, times(1)).success(null); | ||
| } | ||
|
|
||
| @Test | ||
| public void onMethodCall_pausePreview_shouldSendErrorResultOnCameraAccessException() | ||
| throws CameraAccessException { | ||
| doThrow(new CameraAccessException(0)).when(mockCamera).pausePreview(); | ||
|
|
||
| handler.onMethodCall(new MethodCall("pausePreview", null), mockResult); | ||
|
|
||
| verify(mockResult, times(1)).error("CameraAccess", null, null); | ||
| } | ||
|
|
||
| @Test | ||
| public void onMethodCall_resumePreview_shouldResumePreviewAndSendSuccessResult() { | ||
| handler.onMethodCall(new MethodCall("resumePreview", null), mockResult); | ||
|
|
||
| verify(mockCamera, times(1)).resumePreview(); | ||
| verify(mockResult, times(1)).success(null); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/camera/camera/example/ios/RunnerTests/CameraPreviewPauseTests.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| @import camera; | ||
| @import XCTest; | ||
| @import AVFoundation; | ||
| #import <OCMock/OCMock.h> | ||
|
|
||
| @interface FLTCam : NSObject <FlutterTexture, | ||
| AVCaptureVideoDataOutputSampleBufferDelegate, | ||
| AVCaptureAudioDataOutputSampleBufferDelegate> | ||
| @property(assign, nonatomic) BOOL isPreviewPaused; | ||
| - (void)pausePreviewWithResult:(FlutterResult)result; | ||
| - (void)resumePreviewWithResult:(FlutterResult)result; | ||
| @end | ||
|
|
||
| @interface CameraPreviewPauseTests : XCTestCase | ||
| @property(readonly, nonatomic) FLTCam* camera; | ||
| @end | ||
|
|
||
| @implementation CameraPreviewPauseTests | ||
|
|
||
| - (void)setUp { | ||
| _camera = [[FLTCam alloc] init]; | ||
| } | ||
|
|
||
| - (void)testPausePreviewWithResult_shouldPausePreview { | ||
| XCTestExpectation* resultExpectation = | ||
| [self expectationWithDescription:@"Succeeding result with nil value"]; | ||
| [_camera pausePreviewWithResult:^void(id _Nullable result) { | ||
| XCTAssertNil(result); | ||
| [resultExpectation fulfill]; | ||
| }]; | ||
| [self waitForExpectationsWithTimeout:2.0 handler:nil]; | ||
| XCTAssertTrue(_camera.isPreviewPaused); | ||
| } | ||
|
|
||
| - (void)testResumePreviewWithResult_shouldResumePreview { | ||
| XCTestExpectation* resultExpectation = | ||
| [self expectationWithDescription:@"Succeeding result with nil value"]; | ||
| [_camera resumePreviewWithResult:^void(id _Nullable result) { | ||
| XCTAssertNil(result); | ||
| [resultExpectation fulfill]; | ||
| }]; | ||
| [self waitForExpectationsWithTimeout:2.0 handler:nil]; | ||
| XCTAssertFalse(_camera.isPreviewPaused); | ||
| } | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.