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.6k
[camera] Update [CameraOrientationTests testOrientationNotifications] unit test to work on Xcode 13 #4426
Merged
Merged
[camera] Update [CameraOrientationTests testOrientationNotifications] unit test to work on Xcode 13 #4426
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
165b15c
Refactored unit test to prevent usage of XCUIDevice.
mvanbeusekom d9292ba
Add changelog description
mvanbeusekom 6083b93
Replace use of ivar with synthesized property
mvanbeusekom 8af03a6
[camera] Add camera test module map
jmagman 30f7c8d
Fixed nits from PR and bump patch number.
mvanbeusekom 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,65 +3,72 @@ | |||||
| // found in the LICENSE file. | ||||||
|
|
||||||
| @import camera; | ||||||
| @import camera.Test; | ||||||
| @import XCTest; | ||||||
|
|
||||||
| #import <Flutter/Flutter.h> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
| #import <OCMock/OCMock.h> | ||||||
|
|
||||||
| @interface CameraOrientationTests : XCTestCase | ||||||
| @property(strong, nonatomic) id mockRegistrar; | ||||||
| @property(strong, nonatomic) id mockMessenger; | ||||||
| @property(strong, nonatomic) CameraPlugin *cameraPlugin; | ||||||
| @end | ||||||
|
|
||||||
| @implementation CameraOrientationTests | ||||||
|
|
||||||
| - (void)setUp { | ||||||
| [super setUp]; | ||||||
| self.mockRegistrar = OCMProtocolMock(@protocol(FlutterPluginRegistrar)); | ||||||
|
|
||||||
| self.mockMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); | ||||||
| OCMStub([self.mockRegistrar messenger]).andReturn(self.mockMessenger); | ||||||
| self.cameraPlugin = [[CameraPlugin alloc] initWithRegistry:nil messenger:self.mockMessenger]; | ||||||
| } | ||||||
|
|
||||||
| - (void)testOrientationNotifications { | ||||||
| id mockMessenger = self.mockMessenger; | ||||||
| [mockMessenger setExpectationOrderMatters:YES]; | ||||||
| XCUIDevice.sharedDevice.orientation = UIDeviceOrientationPortrait; | ||||||
|
|
||||||
| [CameraPlugin registerWithRegistrar:self.mockRegistrar]; | ||||||
|
|
||||||
| [self rotate:UIDeviceOrientationPortraitUpsideDown expectedChannelOrientation:@"portraitDown"]; | ||||||
| [self rotate:UIDeviceOrientationPortrait expectedChannelOrientation:@"portraitUp"]; | ||||||
| [self rotate:UIDeviceOrientationLandscapeRight expectedChannelOrientation:@"landscapeLeft"]; | ||||||
| [self rotate:UIDeviceOrientationLandscapeLeft expectedChannelOrientation:@"landscapeRight"]; | ||||||
|
|
||||||
| OCMReject([mockMessenger sendOnChannel:[OCMArg any] message:[OCMArg any]]); | ||||||
| // No notification when orientation doesn't change. | ||||||
| XCUIDevice.sharedDevice.orientation = UIDeviceOrientationLandscapeLeft; | ||||||
|
|
||||||
| // No notification when flat. | ||||||
| XCUIDevice.sharedDevice.orientation = UIDeviceOrientationFaceUp; | ||||||
| [self.cameraPlugin | ||||||
| orientationChanged:[self createMockNotificationForOrientation:UIDeviceOrientationFaceUp]]; | ||||||
| // No notification when facedown. | ||||||
| XCUIDevice.sharedDevice.orientation = UIDeviceOrientationFaceDown; | ||||||
| [self.cameraPlugin | ||||||
| orientationChanged:[self createMockNotificationForOrientation:UIDeviceOrientationFaceDown]]; | ||||||
|
|
||||||
| OCMVerifyAll(mockMessenger); | ||||||
| } | ||||||
|
|
||||||
| - (void)rotate:(UIDeviceOrientation)deviceOrientation | ||||||
| expectedChannelOrientation:(NSString*)channelOrientation { | ||||||
| expectedChannelOrientation:(NSString *)channelOrientation { | ||||||
| id mockMessenger = self.mockMessenger; | ||||||
| XCTestExpectation* orientationExpectation = [self expectationWithDescription:channelOrientation]; | ||||||
| XCTestExpectation *orientationExpectation = [self expectationWithDescription:channelOrientation]; | ||||||
|
|
||||||
| OCMExpect([mockMessenger | ||||||
| sendOnChannel:[OCMArg any] | ||||||
| message:[OCMArg checkWithBlock:^BOOL(NSData* data) { | ||||||
| NSObject<FlutterMethodCodec>* codec = [FlutterStandardMethodCodec sharedInstance]; | ||||||
| FlutterMethodCall* methodCall = [codec decodeMethodCall:data]; | ||||||
| message:[OCMArg checkWithBlock:^BOOL(NSData *data) { | ||||||
| NSObject<FlutterMethodCodec> *codec = [FlutterStandardMethodCodec sharedInstance]; | ||||||
| FlutterMethodCall *methodCall = [codec decodeMethodCall:data]; | ||||||
| [orientationExpectation fulfill]; | ||||||
| return | ||||||
| [methodCall.method isEqualToString:@"orientation_changed"] && | ||||||
| [methodCall.arguments isEqualToDictionary:@{@"orientation" : channelOrientation}]; | ||||||
| }]]); | ||||||
|
|
||||||
| XCUIDevice.sharedDevice.orientation = deviceOrientation; | ||||||
| [self.cameraPlugin | ||||||
| orientationChanged:[self createMockNotificationForOrientation:deviceOrientation]]; | ||||||
| [self waitForExpectationsWithTimeout:30.0 handler:nil]; | ||||||
| } | ||||||
|
|
||||||
| - (NSNotification *)createMockNotificationForOrientation:(UIDeviceOrientation)deviceOrientation { | ||||||
| UIDevice *mockDevice = OCMClassMock([UIDevice class]); | ||||||
| OCMStub([mockDevice orientation]).andReturn(deviceOrientation); | ||||||
|
|
||||||
| return [[NSNotification alloc] initWithName:@"orientation_test" object:mockDevice userInfo:nil]; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
| } | ||||||
|
|
||||||
| @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
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,10 @@ | ||
| framework module camera { | ||
| umbrella header "camera-umbrella.h" | ||
|
|
||
| export * | ||
| module * { export * } | ||
|
|
||
| explicit module Test { | ||
| header "CameraPlugin_Test.h" | ||
| } | ||
| } |
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,19 @@ | ||
| // 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. | ||
|
|
||
| // This header is available in the Test module. Import via "@import camera.Test;" | ||
|
|
||
| #import <camera/CameraPlugin.h> | ||
|
|
||
| /// Methods exposed for unit testing. | ||
| @interface CameraPlugin () | ||
|
|
||
| - (instancetype)initWithRegistry:(NSObject<FlutterTextureRegistry> *)registry | ||
| messenger:(NSObject<FlutterBinaryMessenger> *)messenger | ||
| NS_DESIGNATED_INITIALIZER; | ||
| - (instancetype)init NS_UNAVAILABLE; | ||
|
|
||
| - (void)orientationChanged:(NSNotification *)notification; | ||
|
|
||
| @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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // 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 <Foundation/Foundation.h> | ||
| #import <camera/CameraPlugin.h> | ||
|
|
||
| FOUNDATION_EXPORT double cameraVersionNumber; | ||
| FOUNDATION_EXPORT const unsigned char cameraVersionString[]; |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the modulemap change deserves a patch version bump since it's a change in the framework, not just the example tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.