Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


* Updated package description.
* Updated package description;
* Refactor unit test on iOS to make it compatible with new restrictions in Xcode 13 which only supports the use of the `XCUIDevice` in Xcode UI tests.

## 0.9.4+1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,72 @@
// found in the LICENSE file.

@import camera;
@import camera.Test;
@import XCTest;

#import <Flutter/Flutter.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#import <Flutter/Flutter.h>
@import Flutter;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return [[NSNotification alloc] initWithName:@"orientation_test" object:mockDevice userInfo:nil];
return [NSNotification notificationWithName:@"orientation_test" object:mockDevice];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

@end
2 changes: 2 additions & 0 deletions packages/camera/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// found in the LICENSE file.

#import "CameraPlugin.h"
#import "CameraPlugin_Test.h"

#import <AVFoundation/AVFoundation.h>
#import <Accelerate/Accelerate.h>
#import <CoreMotion/CoreMotion.h>
Expand Down
10 changes: 10 additions & 0 deletions packages/camera/camera/ios/Classes/CameraPlugin.modulemap
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"
}
}
19 changes: 19 additions & 0 deletions packages/camera/camera/ios/Classes/CameraPlugin_Test.h
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
9 changes: 9 additions & 0 deletions packages/camera/camera/ios/Classes/camera-umbrella.h
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[];
3 changes: 2 additions & 1 deletion packages/camera/camera/ios/camera.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ A Flutter plugin to use the camera from your Flutter app.
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => 'https://github.com/flutter/plugins/tree/master/packages/camera' }
s.documentation_url = 'https://pub.dev/packages/camera'
s.source_files = 'Classes/**/*'
s.source_files = 'Classes/**/*.{h,m}'
s.public_header_files = 'Classes/**/*.h'
s.module_map = 'Classes/CameraPlugin.modulemap'
s.dependency 'Flutter'

s.platform = :ios, '9.0'
Expand Down