Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into bugfix/camera-thr…
Browse files Browse the repository at this point in the history
…eading
  • Loading branch information
mvanbeusekom committed Oct 14, 2021
2 parents cd48ddd + 176cfb8 commit 98fe08a
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 43 deletions.
8 changes: 6 additions & 2 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.9.4+3

* Fix registerTexture and result being called on background thread on iOS.

## 0.9.4+2

* Fix registerTexture and result being called on background thread on iOS;
* 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,15 +3,12 @@
// found in the LICENSE file.

@import camera;
@import camera.Test;
@import XCTest;
@import AVFoundation;
#import <OCMock/OCMock.h>
#import "MockFLTThreadSafeFlutterResult.h"

@interface CameraPlugin (Test)
- (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FLTThreadSafeFlutterResult *)result;
@end

@interface CameraMethodChannelTests : XCTestCase
@property(readonly, nonatomic) CameraPlugin *camera;
@property(readonly, nonatomic) MockFLTThreadSafeFlutterResult *resultObject;
Expand All @@ -20,7 +17,8 @@ @interface CameraMethodChannelTests : XCTestCase
@implementation CameraMethodChannelTests

- (void)setUp {
_camera = [[CameraPlugin alloc] init];
_camera = [[CameraPlugin alloc] initWithRegistry:nil messenger:nil];

XCTestExpectation *expectation =
[[XCTestExpectation alloc] initWithDescription:@"Result finished"];

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

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

#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 notificationWithName:@"orientation_test" object:mockDevice];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ @implementation CameraPreviewPauseTests
- (void)setUp {
_camera = [[FLTCam alloc] init];

XCTestExpectation *expectation =
[[XCTestExpectation alloc] initWithDescription:@"Result finished"];
_resultObject = [[MockFLTThreadSafeFlutterResult alloc] initWithExpectation:expectation];
_resultObject = [[MockFLTThreadSafeFlutterResult alloc] init];
}

- (void)testPausePreviewWithResult_shouldPausePreview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#ifndef MockFLTThreadSafeFlutterResult_h
#define MockFLTThreadSafeFlutterResult_h

@interface FLTThreadSafeFlutterResult ()
@property(readonly, nonatomic) FlutterResult _Nonnull flutterResult;
@end

/**
* Extends FLTThreadSafeFlutterResult to give tests the ability to wait on the result and
* read the received result.
Expand All @@ -17,7 +13,7 @@
@property(readonly, nonatomic) XCTestExpectation *_Nonnull expectation;
@property(nonatomic, nullable) id receivedResult;

- (id _Nonnull)initWithExpectation:(XCTestExpectation *_Nonnull)expectation;
- (instancetype _Nonnull)initWithExpectation:(XCTestExpectation *_Nonnull)expectation;
@end

#endif /* MockFLTThreadSafeFlutterResult_h */
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@

@implementation MockFLTThreadSafeFlutterResult
/**
* Initializes with a notification center.
* Initializes the MockFLTThreadSafeFlutterResult.
*/
- (id)initWithExpectation:(XCTestExpectation *)expectation {
- (instancetype)init {
self = [super init];
return self;
}

/**
* Initializes the MockFLTThreadSafeFlutterResult with an expectation.
*/
- (instancetype)initWithExpectation:(XCTestExpectation *)expectation {
self = [super init];
_expectation = expectation;
return self;
Expand Down
3 changes: 3 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 Expand Up @@ -1292,6 +1294,7 @@ @interface CameraPlugin ()
@implementation CameraPlugin {
dispatch_queue_t _dispatchQueue;
}

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/camera"
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"
}
}
21 changes: 21 additions & 0 deletions packages/camera/camera/ios/Classes/CameraPlugin_Test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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>
#import <camera/FLTThreadSafeFlutterResult.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)handleMethodCallAsync:(FlutterMethodCall *)call result:(FLTThreadSafeFlutterResult *)result;
- (void)orientationChanged:(NSNotification *)notification;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
@interface FLTThreadSafeFlutterResult : NSObject

/**
* Gets the original FlutterResult object wrapped by this FLTThreadSafeFlutterResult instance.
*/
@property(readonly, nonatomic) FlutterResult _Nonnull flutterResult;

/**
* Initializes with a FlutterResult object.
* @param result The FlutterResult object that the result will be given to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#import "FLTThreadSafeFlutterResult.h"
#import <Foundation/Foundation.h>

@interface FLTThreadSafeFlutterResult ()
@property(readonly, nonatomic) FlutterResult flutterResult;
@end

@implementation FLTThreadSafeFlutterResult {
}

Expand Down
10 changes: 10 additions & 0 deletions packages/camera/camera/ios/Classes/camera-umbrella.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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>
#import <camera/FLTThreadSafeFlutterResult.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' => '[email protected]' }
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
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/plugins/tree/master/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.4+2
version: 0.9.4+3

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
14 changes: 10 additions & 4 deletions packages/integration_test/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# integration_test (deprecated)
# integration_test (moved)

## DEPRECATED
## MOVED

This package has been moved to the Flutter SDK. Starting with Flutter 2.0,
it should be included as:
This package has [moved to the Flutter
SDK](https://github.com/flutter/flutter/tree/master/packages/integration_test),
and the pub.dev version is deprecated.
As of Flutter 2.0, include it in your pubspec's
dev dependencies section, as follows:

```
dev_dependencies:
integration_test:
sdk: flutter
```

For the latest documentation, see [Integration
testing](https://flutter.dev/docs/testing/integration-tests).

## Old instructions

This package enables self-driving testing of Flutter code on devices and emulators.
Expand Down

0 comments on commit 98fe08a

Please sign in to comment.