-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera_avfoundation] Migrate tests to Swift - part 2 #8613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 24 commits into
flutter:main
from
leancodepl:feature/camera-swift-test-migration-part2
Feb 18, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5de2587
Migrate CameraCaptureSessionQueueRaceConditionTests to Swift
FirentisTFW a7b3c02
Migrate CameraMethodChannelTests to Swift
FirentisTFW c91bbae
Migrate CameraOrientationTests to Swift
FirentisTFW 2608e45
Migrate CameraSettingsTests to Swift
FirentisTFW f261951
Migrate CameraSessionPresetsTests to Swift
FirentisTFW effbaae
Bump version and update changelog
FirentisTFW 145ccd2
Remove redundant "any" keywords
FirentisTFW 0f7eada
Merge branch 'main' into feature/camera-swift-test-migration-part2
FirentisTFW 5464d73
Remove duplicated test file
FirentisTFW 39334e1
Inlcude missing test file
FirentisTFW 6989e86
Bump version and update changelog
FirentisTFW 6725409
Resolve conflicts in bridging-header file
FirentisTFW 0b51e01
Revert "Inlcude missing test file"
FirentisTFW ff8fd05
Migrate SavePhotoDelegateTests to Swift
FirentisTFW 974e728
Clean up - Swift tests migration
FirentisTFW 612c425
Sort imports
FirentisTFW 29870d5
Clean up code
FirentisTFW 828f73e
Remove shared state from CameraOrientationTests
FirentisTFW aa7c223
Merge branch 'main' into feature/camera-swift-test-migration-part2
FirentisTFW 4b74842
Bump version
FirentisTFW 3b2b4a9
Adjust code to the new API after merge
FirentisTFW 75a58a0
Fix a comment
FirentisTFW b5743e7
Merge branch 'main' into feature/camera-swift-test-migration-part2
FirentisTFW 4237804
Adjust code after merge
FirentisTFW 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
51 changes: 28 additions & 23 deletions
51
packages/camera/camera_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 0 additions & 72 deletions
72
...camera_avfoundation/example/ios/RunnerTests/CameraCaptureSessionQueueRaceConditionTests.m
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
...ra_avfoundation/example/ios/RunnerTests/CameraCaptureSessionQueueRaceConditionTests.swift
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,54 @@ | ||
// 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 XCTest | ||
|
||
@testable import camera_avfoundation | ||
|
||
final class CameraCaptureSessionQueueRaceConditionTests: XCTestCase { | ||
private func createCameraPlugin() -> CameraPlugin { | ||
return CameraPlugin( | ||
registry: MockFlutterTextureRegistry(), | ||
messenger: MockFlutterBinaryMessenger(), | ||
globalAPI: MockGlobalEventApi(), | ||
deviceDiscoverer: MockCameraDeviceDiscoverer(), | ||
deviceFactory: { _ in MockCaptureDevice() }, | ||
captureSessionFactory: { MockCaptureSession() }, | ||
captureDeviceInputFactory: MockCaptureDeviceInputFactory() | ||
) | ||
} | ||
|
||
func testFixForCaptureSessionQueueNullPointerCrashDueToRaceCondition() { | ||
let cameraPlugin = createCameraPlugin() | ||
let disposeExpectation = expectation(description: "dispose's result block must be called") | ||
let createExpectation = expectation(description: "create's result block must be called") | ||
|
||
// Mimic a dispose call followed by a create call, which can be triggered by slightly dragging the | ||
// home bar, causing the app to be inactive, and immediately regain active. | ||
cameraPlugin.disposeCamera(0) { error in | ||
disposeExpectation.fulfill() | ||
} | ||
|
||
cameraPlugin.createCameraOnSessionQueue( | ||
withName: "acamera", | ||
settings: FCPPlatformMediaSettings.make( | ||
with: .medium, | ||
framesPerSecond: nil, | ||
videoBitrate: nil, | ||
audioBitrate: nil, | ||
enableAudio: true | ||
) | ||
) { result, error in | ||
createExpectation.fulfill() | ||
} | ||
|
||
waitForExpectations(timeout: 30, handler: nil) | ||
|
||
// `captureSessionQueue` must not be nil after `create` call. Otherwise a nil | ||
// `captureSessionQueue` passed into `AVCaptureVideoDataOutput::setSampleBufferDelegate:queue:` | ||
// API will cause a crash. | ||
XCTAssertNotNil( | ||
cameraPlugin.captureSessionQueue, "captureSessionQueue must not be nil after create method.") | ||
} | ||
} |
81 changes: 0 additions & 81 deletions
81
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraExposureTests.m
This file was deleted.
Oops, something went wrong.
100 changes: 0 additions & 100 deletions
100
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.m
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift
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,78 @@ | ||
// 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 AVFoundation | ||
import XCTest | ||
|
||
@testable import camera_avfoundation | ||
|
||
final class CameraMethodChannelTests: XCTestCase { | ||
private func createCameraPlugin(with session: MockCaptureSession) -> CameraPlugin { | ||
return CameraPlugin( | ||
registry: MockFlutterTextureRegistry(), | ||
messenger: MockFlutterBinaryMessenger(), | ||
globalAPI: MockGlobalEventApi(), | ||
deviceDiscoverer: MockCameraDeviceDiscoverer(), | ||
deviceFactory: { _ in MockCaptureDevice() }, | ||
captureSessionFactory: { session }, | ||
captureDeviceInputFactory: MockCaptureDeviceInputFactory() | ||
) | ||
} | ||
|
||
func testCreate_ShouldCallResultOnMainThread() { | ||
let avCaptureSessionMock = MockCaptureSession() | ||
avCaptureSessionMock.canSetSessionPreset = true | ||
let camera = createCameraPlugin(with: avCaptureSessionMock) | ||
let expectation = self.expectation(description: "Result finished") | ||
|
||
var resultValue: NSNumber? | ||
camera.createCameraOnSessionQueue( | ||
withName: "acamera", | ||
settings: FCPPlatformMediaSettings.make( | ||
with: FCPPlatformResolutionPreset.medium, | ||
framesPerSecond: nil, | ||
videoBitrate: nil, | ||
audioBitrate: nil, | ||
enableAudio: true | ||
) | ||
) { result, error in | ||
resultValue = result | ||
expectation.fulfill() | ||
} | ||
|
||
waitForExpectations(timeout: 30, handler: nil) | ||
XCTAssertNotNil(resultValue) | ||
} | ||
|
||
func testDisposeShouldDeallocCamera() { | ||
let avCaptureSessionMock = MockCaptureSession() | ||
avCaptureSessionMock.canSetSessionPreset = true | ||
let camera = createCameraPlugin(with: avCaptureSessionMock) | ||
let createExpectation = self.expectation(description: "create's result block must be called") | ||
|
||
camera.createCameraOnSessionQueue( | ||
withName: "acamera", | ||
settings: FCPPlatformMediaSettings.make( | ||
with: .medium, | ||
framesPerSecond: nil, | ||
videoBitrate: nil, | ||
audioBitrate: nil, | ||
enableAudio: true | ||
) | ||
) { result, error in | ||
createExpectation.fulfill() | ||
} | ||
|
||
waitForExpectations(timeout: 30, handler: nil) | ||
XCTAssertNotNil(camera.camera) | ||
|
||
let disposeExpectation = self.expectation(description: "dispose's result block must be called") | ||
camera.disposeCamera(0) { error in | ||
disposeExpectation.fulfill() | ||
} | ||
|
||
waitForExpectations(timeout: 30, handler: nil) | ||
XCTAssertNil(camera.camera, "camera should be deallocated after dispose") | ||
} | ||
} |
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.