From ff0a2bb9dfad60afe69313cb302fb1cd7d6618ee Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Tue, 13 Jul 2021 18:10:02 +0200 Subject: [PATCH 01/11] feat: add camera options --- .../lib/src/types/camera_options.dart | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 packages/camera/camera_web/lib/src/types/camera_options.dart diff --git a/packages/camera/camera_web/lib/src/types/camera_options.dart b/packages/camera/camera_web/lib/src/types/camera_options.dart new file mode 100644 index 000000000000..0f656484571b --- /dev/null +++ b/packages/camera/camera_web/lib/src/types/camera_options.dart @@ -0,0 +1,182 @@ +// 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. + +/// Options used to create a camera with the given +/// [audio] and [video] media constraints. +/// +/// These options represent web `MediaStreamConstraints` +/// and can be used to request the browser for media streams +/// with the requested types of media. +/// +/// https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints +class CameraOptions { + /// Creates a new instance of [CameraOptions] + /// with the given [audio] and [video] constraints. + const CameraOptions({ + AudioConstraints? audio, + VideoConstraints? video, + }) : audio = audio ?? const AudioConstraints(), + video = video ?? const VideoConstraints(); + + /// The audio constraints for the camera. + final AudioConstraints audio; + + /// The video constraints for the camera. + final VideoConstraints video; + + /// Converts the current instance to a Map. + Map toJson() { + return { + 'audio': audio.toJson(), + 'video': video.toJson(), + }; + } +} + +/// Indicates whether the audio track is requested. +/// +/// By default, the audio track is not requested. +class AudioConstraints { + /// Creates a new instance of [AudioConstraints] + /// with the given [enabled] constraint. + const AudioConstraints({this.enabled = false}); + + /// Whether the audio track should be enabled. + final bool enabled; + + /// Converts the current instance to a Map. + Object toJson() => enabled; +} + +/// Defines constraints that the video track must have +/// to be considered acceptable. +class VideoConstraints { + /// Creates a new instance of [VideoConstraints] + /// with the given constraints. + const VideoConstraints({ + this.facingMode, + this.width, + this.height, + this.deviceId, + }); + + /// The facing mode of the video track. + final FacingModeConstraint? facingMode; + + /// The width of the video track. + final VideoSizeConstraint? width; + + /// The height of the video track. + final VideoSizeConstraint? height; + + /// The device id of the video track. + final String? deviceId; + + /// Converts the current instance to a Map. + Object toJson() { + final json = {}; + + if (width != null) json['width'] = width!.toJson(); + if (height != null) json['height'] = height!.toJson(); + if (facingMode != null) json['facingMode'] = facingMode!.toJson(); + if (deviceId != null) json['deviceId'] = deviceId!; + + return json; + } +} + +/// The camera type used in [FacingModeConstraint]. +/// +/// Specifies whether the requested camera should be facing away +/// or toward the user. +class CameraType { + const CameraType._(this._type); + + final String _type; + + @override + String toString() => _type; + + /// The camera is facing away from the user, viewing their environment. + /// This includes the back camera on a smartphone. + static const CameraType environment = CameraType._('environment'); + + /// The camera is facing toward the user. + /// This includes the front camera on a smartphone. + static const CameraType user = CameraType._('user'); +} + +/// Indicates the direction in which the desired camera should be pointing. +class FacingModeConstraint { + /// Creates a new instance of [FacingModeConstraint] + /// with the given [ideal] and [exact] constraints. + const FacingModeConstraint._({this.ideal, this.exact}); + + /// Creates a new instance of [FacingModeConstraint] + /// with [ideal] constraint set to [type]. + factory FacingModeConstraint(CameraType type) => + FacingModeConstraint._(ideal: type); + + /// Creates a new instance of [FacingModeConstraint] + /// with [exact] constraint set to [type]. + factory FacingModeConstraint.exact(CameraType type) => + FacingModeConstraint._(exact: type); + + /// The ideal facing mode constraint. + /// + /// If this constraint is used, then the camera would ideally have + /// the desired facing [type] but it may be considered optional. + final CameraType? ideal; + + /// The exact facing mode constraint. + /// + /// If this constraint is used, then the camera must have + /// the desired facing [type] to be considered acceptable. + final CameraType? exact; + + /// Converts the current instance to a Map. + Object? toJson() { + return { + if (ideal != null) 'ideal': ideal.toString(), + if (exact != null) 'exact': exact.toString(), + }; + } +} + +/// The size of the requested video track used in +/// [VideoConstraints.width] and [VideoConstraints.height]. +/// +/// The obtained video track will have a size between [minimum] and [maximum] +/// with ideally a size of [ideal]. The size is determined by +/// the capabilities of the hardware and the other specified constraints. +class VideoSizeConstraint { + /// Creates a new instance of [VideoSizeConstraint] with the given + /// [minimum], [ideal] and [maximum] constraints. + const VideoSizeConstraint({this.minimum, this.ideal, this.maximum}); + + /// The minimum video size. + final int? minimum; + + /// The ideal video size. + /// + /// The video would ideally have the [ideal] size + /// but it may be considered optional. If not possible + /// to satisfy, the size will be as close as possible + /// to [ideal]. + final int? ideal; + + /// The maximum video size. + final int? maximum; + + /// Converts the current instance to a Map. + Object toJson() { + final json = {}; + + if (ideal != null) json['ideal'] = ideal; + if (minimum != null) json['min'] = minimum; + if (maximum != null) json['max'] = maximum; + + return json; + } +} From c842c3d9ecd877568803ca93251ec68248740ac3 Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Tue, 13 Jul 2021 18:10:08 +0200 Subject: [PATCH 02/11] test: add camera options tests --- .../types/camera_options_test.dart | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 packages/camera/camera_web/example/integration_test/types/camera_options_test.dart diff --git a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart new file mode 100644 index 000000000000..55cae986e015 --- /dev/null +++ b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart @@ -0,0 +1,127 @@ +// 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 'package:camera_web/src/types/camera_options.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('CameraOptions', () { + testWidgets('serializes correctly', (tester) async { + final cameraOptions = CameraOptions( + audio: AudioConstraints(enabled: true), + video: VideoConstraints( + facingMode: FacingModeConstraint.exact(CameraType.user), + ), + ); + + expect( + cameraOptions.toJson(), + equals({ + 'audio': cameraOptions.audio.toJson(), + 'video': cameraOptions.video.toJson(), + }), + ); + }); + }); + + group('AudioConstraints', () { + testWidgets('serializes correctly', (tester) async { + expect( + AudioConstraints(enabled: true).toJson(), + equals(true), + ); + }); + }); + + group('VideoConstraints', () { + testWidgets('serializes correctly', (tester) async { + final videoConstraints = VideoConstraints( + facingMode: FacingModeConstraint.exact(CameraType.user), + width: VideoSizeConstraint(ideal: 100, maximum: 100), + height: VideoSizeConstraint(ideal: 50, maximum: 50), + deviceId: 'deviceId', + ); + + expect( + videoConstraints.toJson(), + equals({ + 'facingMode': videoConstraints.facingMode!.toJson(), + 'width': videoConstraints.width!.toJson(), + 'height': videoConstraints.height!.toJson(), + 'deviceId': 'deviceId', + }), + ); + }); + }); + + group('FacingModeConstraint', () { + group('ideal', () { + testWidgets( + 'serializes correctly ' + 'for environment camera type', (tester) async { + expect( + FacingModeConstraint( + CameraType.environment, + ).toJson(), + equals({'ideal': 'environment'}), + ); + }); + + testWidgets( + 'serializes correctly ' + 'for user camera type', (tester) async { + expect( + FacingModeConstraint( + CameraType.user, + ).toJson(), + equals({'ideal': 'user'}), + ); + }); + }); + + group('exact', () { + testWidgets( + 'serializes correctly ' + 'for environment camera type', (tester) async { + expect( + FacingModeConstraint.exact( + CameraType.environment, + ).toJson(), + equals({'exact': 'environment'}), + ); + }); + + testWidgets( + 'serializes correctly ' + 'for user camera type', (tester) async { + expect( + FacingModeConstraint.exact( + CameraType.user, + ).toJson(), + equals({'exact': 'user'}), + ); + }); + }); + }); + + group('VideoSizeConstraint ', () { + testWidgets('serializes correctly', (tester) async { + expect( + VideoSizeConstraint( + ideal: 400, + minimum: 200, + maximum: 400, + ).toJson(), + equals({ + 'ideal': 400, + 'min': 200, + 'max': 400, + }), + ); + }); + }); +} From 34a1581861496bae70091f129f40c6873f7e80cd Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Thu, 15 Jul 2021 16:26:48 +0200 Subject: [PATCH 03/11] feat: define value equality for camera options --- .../lib/src/types/camera_options.dart | 63 +++++++++++++++++++ .../camera_web/lib/src/types/types.dart | 1 + 2 files changed, 64 insertions(+) create mode 100644 packages/camera/camera_web/lib/src/types/types.dart diff --git a/packages/camera/camera_web/lib/src/types/camera_options.dart b/packages/camera/camera_web/lib/src/types/camera_options.dart index 0f656484571b..351b8079adbc 100644 --- a/packages/camera/camera_web/lib/src/types/camera_options.dart +++ b/packages/camera/camera_web/lib/src/types/camera_options.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:ui' show hashValues; + /// Options used to create a camera with the given /// [audio] and [video] media constraints. /// @@ -32,6 +34,18 @@ class CameraOptions { 'video': video.toJson(), }; } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is CameraOptions && + other.audio == audio && + other.video == video; + } + + @override + int get hashCode => hashValues(audio, video); } /// Indicates whether the audio track is requested. @@ -47,6 +61,16 @@ class AudioConstraints { /// Converts the current instance to a Map. Object toJson() => enabled; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is AudioConstraints && other.enabled == enabled; + } + + @override + int get hashCode => enabled.hashCode; } /// Defines constraints that the video track must have @@ -84,6 +108,20 @@ class VideoConstraints { return json; } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is VideoConstraints && + other.facingMode == facingMode && + other.width == width && + other.height == height && + other.deviceId == deviceId; + } + + @override + int get hashCode => hashValues(facingMode, width, height, deviceId); } /// The camera type used in [FacingModeConstraint]. @@ -142,6 +180,18 @@ class FacingModeConstraint { if (exact != null) 'exact': exact.toString(), }; } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is FacingModeConstraint && + other.ideal == ideal && + other.exact == exact; + } + + @override + int get hashCode => hashValues(ideal, exact); } /// The size of the requested video track used in @@ -179,4 +229,17 @@ class VideoSizeConstraint { return json; } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is VideoSizeConstraint && + other.minimum == minimum && + other.ideal == ideal && + other.maximum == maximum; + } + + @override + int get hashCode => hashValues(minimum, ideal, maximum); } diff --git a/packages/camera/camera_web/lib/src/types/types.dart b/packages/camera/camera_web/lib/src/types/types.dart new file mode 100644 index 000000000000..5f55dd7c996a --- /dev/null +++ b/packages/camera/camera_web/lib/src/types/types.dart @@ -0,0 +1 @@ +export 'camera_options.dart'; From 79241c8af00fec70bacee88bc305a6b35a3aab94 Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Thu, 15 Jul 2021 16:27:23 +0200 Subject: [PATCH 04/11] test: add camera options value equality tests --- .../types/camera_options_test.dart | 102 +++++++++++++++--- 1 file changed, 88 insertions(+), 14 deletions(-) diff --git a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart index 55cae986e015..3f10b22b8393 100644 --- a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart +++ b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart @@ -26,6 +26,31 @@ void main() { }), ); }); + + testWidgets('supports value equality', (tester) async { + expect( + CameraOptions( + audio: AudioConstraints(enabled: false), + video: VideoConstraints( + facingMode: FacingModeConstraint(CameraType.environment), + width: VideoSizeConstraint(minimum: 10, ideal: 15, maximum: 20), + height: VideoSizeConstraint(minimum: 15, ideal: 20, maximum: 25), + deviceId: 'deviceId', + ), + ), + equals( + CameraOptions( + audio: AudioConstraints(enabled: false), + video: VideoConstraints( + facingMode: FacingModeConstraint(CameraType.environment), + width: VideoSizeConstraint(minimum: 10, ideal: 15, maximum: 20), + height: VideoSizeConstraint(minimum: 15, ideal: 20, maximum: 25), + deviceId: 'deviceId', + ), + ), + ), + ); + }); }); group('AudioConstraints', () { @@ -35,6 +60,13 @@ void main() { equals(true), ); }); + + testWidgets('supports value equality', (tester) async { + expect( + AudioConstraints(enabled: true), + equals(AudioConstraints(enabled: true)), + ); + }); }); group('VideoConstraints', () { @@ -56,6 +88,25 @@ void main() { }), ); }); + + testWidgets('supports value equality', (tester) async { + expect( + VideoConstraints( + facingMode: FacingModeConstraint.exact(CameraType.environment), + width: VideoSizeConstraint(minimum: 90, ideal: 100, maximum: 100), + height: VideoSizeConstraint(minimum: 40, ideal: 50, maximum: 50), + deviceId: 'deviceId', + ), + equals( + VideoConstraints( + facingMode: FacingModeConstraint.exact(CameraType.environment), + width: VideoSizeConstraint(minimum: 90, ideal: 100, maximum: 100), + height: VideoSizeConstraint(minimum: 40, ideal: 50, maximum: 50), + deviceId: 'deviceId', + ), + ), + ); + }); }); group('FacingModeConstraint', () { @@ -64,9 +115,7 @@ void main() { 'serializes correctly ' 'for environment camera type', (tester) async { expect( - FacingModeConstraint( - CameraType.environment, - ).toJson(), + FacingModeConstraint(CameraType.environment).toJson(), equals({'ideal': 'environment'}), ); }); @@ -75,12 +124,17 @@ void main() { 'serializes correctly ' 'for user camera type', (tester) async { expect( - FacingModeConstraint( - CameraType.user, - ).toJson(), + FacingModeConstraint(CameraType.user).toJson(), equals({'ideal': 'user'}), ); }); + + testWidgets('supports value equality', (tester) async { + expect( + FacingModeConstraint(CameraType.user), + equals(FacingModeConstraint(CameraType.user)), + ); + }); }); group('exact', () { @@ -88,9 +142,7 @@ void main() { 'serializes correctly ' 'for environment camera type', (tester) async { expect( - FacingModeConstraint.exact( - CameraType.environment, - ).toJson(), + FacingModeConstraint.exact(CameraType.environment).toJson(), equals({'exact': 'environment'}), ); }); @@ -99,12 +151,17 @@ void main() { 'serializes correctly ' 'for user camera type', (tester) async { expect( - FacingModeConstraint.exact( - CameraType.user, - ).toJson(), + FacingModeConstraint.exact(CameraType.user).toJson(), equals({'exact': 'user'}), ); }); + + testWidgets('supports value equality', (tester) async { + expect( + FacingModeConstraint.exact(CameraType.environment), + equals(FacingModeConstraint.exact(CameraType.environment)), + ); + }); }); }); @@ -112,16 +169,33 @@ void main() { testWidgets('serializes correctly', (tester) async { expect( VideoSizeConstraint( - ideal: 400, minimum: 200, + ideal: 400, maximum: 400, ).toJson(), equals({ - 'ideal': 400, 'min': 200, + 'ideal': 400, 'max': 400, }), ); }); + + testWidgets('supports value equality', (tester) async { + expect( + VideoSizeConstraint( + minimum: 100, + ideal: 200, + maximum: 300, + ), + equals( + VideoSizeConstraint( + minimum: 100, + ideal: 200, + maximum: 300, + ), + ), + ); + }); }); } From d6fba4b2bc6bc5f1d17e69bc752c8cde69f75a10 Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Mon, 19 Jul 2021 11:48:13 +0200 Subject: [PATCH 05/11] feat: use exact for device id in video constraints --- .../example/integration_test/types/camera_options_test.dart | 4 +++- packages/camera/camera_web/lib/src/types/camera_options.dart | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart index 3f10b22b8393..03f65793f510 100644 --- a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart +++ b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart @@ -84,7 +84,9 @@ void main() { 'facingMode': videoConstraints.facingMode!.toJson(), 'width': videoConstraints.width!.toJson(), 'height': videoConstraints.height!.toJson(), - 'deviceId': 'deviceId', + 'deviceId': { + 'exact': 'deviceId', + } }), ); }); diff --git a/packages/camera/camera_web/lib/src/types/camera_options.dart b/packages/camera/camera_web/lib/src/types/camera_options.dart index 351b8079adbc..b6891279e812 100644 --- a/packages/camera/camera_web/lib/src/types/camera_options.dart +++ b/packages/camera/camera_web/lib/src/types/camera_options.dart @@ -104,7 +104,7 @@ class VideoConstraints { if (width != null) json['width'] = width!.toJson(); if (height != null) json['height'] = height!.toJson(); if (facingMode != null) json['facingMode'] = facingMode!.toJson(); - if (deviceId != null) json['deviceId'] = deviceId!; + if (deviceId != null) json['deviceId'] = {'exact': deviceId!}; return json; } From 73562bf4aba324b61b8835ebbad3c037e9a2fee7 Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Mon, 19 Jul 2021 12:49:54 +0200 Subject: [PATCH 06/11] chore: update camera_web version --- packages/camera/camera_web/CHANGELOG.md | 4 ++++ packages/camera/camera_web/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/camera/camera_web/CHANGELOG.md b/packages/camera/camera_web/CHANGELOG.md index 1318780830f8..c48495f8ce43 100644 --- a/packages/camera/camera_web/CHANGELOG.md +++ b/packages/camera/camera_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.1 + +* Added CameraOptions used to create a camera with the audio and video constraints. + ## 0.1.0 * Initial release diff --git a/packages/camera/camera_web/pubspec.yaml b/packages/camera/camera_web/pubspec.yaml index a2aa43c22d65..617cfae0b050 100644 --- a/packages/camera/camera_web/pubspec.yaml +++ b/packages/camera/camera_web/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_web description: A Flutter plugin for getting information about and controlling the camera on Web. repository: https://github.com/flutter/plugins/tree/master/packages/camera/camera_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.1.0 +version: 0.1.1 # This plugin is under development and will be published # when the first working web camera implementation is added. From 15aa4c2b85f479d9b9e02dc87c7b9dfe7582df3c Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Mon, 19 Jul 2021 13:09:59 +0200 Subject: [PATCH 07/11] docs: update comments --- packages/camera/camera_web/lib/src/types/camera_options.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_web/lib/src/types/camera_options.dart b/packages/camera/camera_web/lib/src/types/camera_options.dart index b6891279e812..2a4cdbf15348 100644 --- a/packages/camera/camera_web/lib/src/types/camera_options.dart +++ b/packages/camera/camera_web/lib/src/types/camera_options.dart @@ -9,7 +9,7 @@ import 'dart:ui' show hashValues; /// /// These options represent web `MediaStreamConstraints` /// and can be used to request the browser for media streams -/// with the requested types of media. +/// with audio and video tracks containing the requested types of media. /// /// https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints class CameraOptions { From 556e2fc11706661913e3579a1710831fa4fc0951 Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Mon, 19 Jul 2021 13:12:15 +0200 Subject: [PATCH 08/11] docs: update comments --- packages/camera/camera_web/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_web/CHANGELOG.md b/packages/camera/camera_web/CHANGELOG.md index c48495f8ce43..adc4230dc3bf 100644 --- a/packages/camera/camera_web/CHANGELOG.md +++ b/packages/camera/camera_web/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.1.1 -* Added CameraOptions used to create a camera with the audio and video constraints. +* Added CameraOptions used to constrain the camera audio and video. ## 0.1.0 From 50be75ed0ea074b9c4b4f61df1612f0d6be6ea89 Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Mon, 19 Jul 2021 13:17:15 +0200 Subject: [PATCH 09/11] docs: add copyright --- packages/camera/camera_web/lib/src/types/types.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/camera/camera_web/lib/src/types/types.dart b/packages/camera/camera_web/lib/src/types/types.dart index 5f55dd7c996a..deccd32da4c0 100644 --- a/packages/camera/camera_web/lib/src/types/types.dart +++ b/packages/camera/camera_web/lib/src/types/types.dart @@ -1 +1,5 @@ +// 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. + export 'camera_options.dart'; From a07ec9961c6dc09fe4b134824fa39d6f14fc1fcf Mon Sep 17 00:00:00 2001 From: Bartosz Selwesiuk Date: Mon, 19 Jul 2021 18:04:51 +0200 Subject: [PATCH 10/11] refactor: update test imports --- .../example/integration_test/types/camera_options_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart index 03f65793f510..a74ba3088394 100644 --- a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart +++ b/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:camera_web/src/types/camera_options.dart'; +import 'package:camera_web/src/types/types.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; From f243510a480d4979ccc431106caebb9531f017c3 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 19 Jul 2021 11:12:20 -0700 Subject: [PATCH 11/11] Move purely unit tests to test dir. Do not bump versions yet. --- packages/camera/camera_web/CHANGELOG.md | 5 +-- packages/camera/camera_web/pubspec.yaml | 2 +- ...t => more_tests_exist_elsewhere_test.dart} | 4 +- .../types/camera_options_test.dart | 39 +++++++++---------- 4 files changed, 22 insertions(+), 28 deletions(-) rename packages/camera/camera_web/test/{tests_exist_elsewhere_test.dart => more_tests_exist_elsewhere_test.dart} (72%) rename packages/camera/camera_web/{example/integration_test => test}/types/camera_options_test.dart (82%) diff --git a/packages/camera/camera_web/CHANGELOG.md b/packages/camera/camera_web/CHANGELOG.md index adc4230dc3bf..68bc5f4e1a1e 100644 --- a/packages/camera/camera_web/CHANGELOG.md +++ b/packages/camera/camera_web/CHANGELOG.md @@ -1,7 +1,4 @@ -## 0.1.1 - -* Added CameraOptions used to constrain the camera audio and video. - ## 0.1.0 * Initial release + * Added CameraOptions used to constrain the camera audio and video. diff --git a/packages/camera/camera_web/pubspec.yaml b/packages/camera/camera_web/pubspec.yaml index 617cfae0b050..a2aa43c22d65 100644 --- a/packages/camera/camera_web/pubspec.yaml +++ b/packages/camera/camera_web/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_web description: A Flutter plugin for getting information about and controlling the camera on Web. repository: https://github.com/flutter/plugins/tree/master/packages/camera/camera_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.1.1 +version: 0.1.0 # This plugin is under development and will be published # when the first working web camera implementation is added. diff --git a/packages/camera/camera_web/test/tests_exist_elsewhere_test.dart b/packages/camera/camera_web/test/more_tests_exist_elsewhere_test.dart similarity index 72% rename from packages/camera/camera_web/test/tests_exist_elsewhere_test.dart rename to packages/camera/camera_web/test/more_tests_exist_elsewhere_test.dart index 442c50144727..dc2b64c111d7 100644 --- a/packages/camera/camera_web/test/tests_exist_elsewhere_test.dart +++ b/packages/camera/camera_web/test/more_tests_exist_elsewhere_test.dart @@ -5,9 +5,9 @@ import 'package:flutter_test/flutter_test.dart'; void main() { - test('Tell the user where to find the real tests', () { + test('Tell the user where to find more tests', () { print('---'); - print('This package uses integration_test for its tests.'); + print('This package also uses integration_test for its tests.'); print('See `example/README.md` for more info.'); print('---'); }); diff --git a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart b/packages/camera/camera_web/test/types/camera_options_test.dart similarity index 82% rename from packages/camera/camera_web/example/integration_test/types/camera_options_test.dart rename to packages/camera/camera_web/test/types/camera_options_test.dart index a74ba3088394..6f60bfd5aeda 100644 --- a/packages/camera/camera_web/example/integration_test/types/camera_options_test.dart +++ b/packages/camera/camera_web/test/types/camera_options_test.dart @@ -4,13 +4,10 @@ import 'package:camera_web/src/types/types.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:integration_test/integration_test.dart'; void main() { - IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - group('CameraOptions', () { - testWidgets('serializes correctly', (tester) async { + test('serializes correctly', () { final cameraOptions = CameraOptions( audio: AudioConstraints(enabled: true), video: VideoConstraints( @@ -27,7 +24,7 @@ void main() { ); }); - testWidgets('supports value equality', (tester) async { + test('supports value equality', () { expect( CameraOptions( audio: AudioConstraints(enabled: false), @@ -54,14 +51,14 @@ void main() { }); group('AudioConstraints', () { - testWidgets('serializes correctly', (tester) async { + test('serializes correctly', () { expect( AudioConstraints(enabled: true).toJson(), equals(true), ); }); - testWidgets('supports value equality', (tester) async { + test('supports value equality', () { expect( AudioConstraints(enabled: true), equals(AudioConstraints(enabled: true)), @@ -70,7 +67,7 @@ void main() { }); group('VideoConstraints', () { - testWidgets('serializes correctly', (tester) async { + test('serializes correctly', () { final videoConstraints = VideoConstraints( facingMode: FacingModeConstraint.exact(CameraType.user), width: VideoSizeConstraint(ideal: 100, maximum: 100), @@ -91,7 +88,7 @@ void main() { ); }); - testWidgets('supports value equality', (tester) async { + test('supports value equality', () { expect( VideoConstraints( facingMode: FacingModeConstraint.exact(CameraType.environment), @@ -113,25 +110,25 @@ void main() { group('FacingModeConstraint', () { group('ideal', () { - testWidgets( + test( 'serializes correctly ' - 'for environment camera type', (tester) async { + 'for environment camera type', () { expect( FacingModeConstraint(CameraType.environment).toJson(), equals({'ideal': 'environment'}), ); }); - testWidgets( + test( 'serializes correctly ' - 'for user camera type', (tester) async { + 'for user camera type', () { expect( FacingModeConstraint(CameraType.user).toJson(), equals({'ideal': 'user'}), ); }); - testWidgets('supports value equality', (tester) async { + test('supports value equality', () { expect( FacingModeConstraint(CameraType.user), equals(FacingModeConstraint(CameraType.user)), @@ -140,25 +137,25 @@ void main() { }); group('exact', () { - testWidgets( + test( 'serializes correctly ' - 'for environment camera type', (tester) async { + 'for environment camera type', () { expect( FacingModeConstraint.exact(CameraType.environment).toJson(), equals({'exact': 'environment'}), ); }); - testWidgets( + test( 'serializes correctly ' - 'for user camera type', (tester) async { + 'for user camera type', () { expect( FacingModeConstraint.exact(CameraType.user).toJson(), equals({'exact': 'user'}), ); }); - testWidgets('supports value equality', (tester) async { + test('supports value equality', () { expect( FacingModeConstraint.exact(CameraType.environment), equals(FacingModeConstraint.exact(CameraType.environment)), @@ -168,7 +165,7 @@ void main() { }); group('VideoSizeConstraint ', () { - testWidgets('serializes correctly', (tester) async { + test('serializes correctly', () { expect( VideoSizeConstraint( minimum: 200, @@ -183,7 +180,7 @@ void main() { ); }); - testWidgets('supports value equality', (tester) async { + test('supports value equality', () { expect( VideoSizeConstraint( minimum: 100,