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.8k
[camera] Introduce camera_web
package
#4151
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
df27092
feat: add camera_web plugin
bselwe 552fd62
test: add camera_web integration tests
bselwe 557b278
chore: rename camera_web integration tests name in pubspec
bselwe e8267b3
chore: migrate camera_web tests to integration tests
bselwe adc0177
Update packages/camera/camera_web/example/web/index.html
bselwe 9fdeafd
chore: bump initial version to 0.1.0
bselwe 8b06877
docs: update integration tests readme
bselwe 9c6088b
chore: remove unnecessary build.yaml used for mockito
bselwe 453df18
build: remove mocktail from direct dependencies of camera_web
bselwe 7474eeb
build: update build_runner version
bselwe 2241795
refactor: make testing MyApp a stateless widget
bselwe 155e08d
feat: add camera_web barrel file
bselwe 1705045
docs: update copyright 2013 to 2021
bselwe 4710036
docs: update camera_web readme
bselwe 7193081
revert: update copyright 2013 to 2021
bselwe 183c0e0
docs: add missing copyright to camera_web
bselwe ca9569c
build: remove unused dependency
bselwe d075c49
Update packages/camera/camera_web/example/integration_test/camera_web…
bselwe 3256909
style: update camera_web_test formatting
bselwe 3ddbec9
chore: add publish_to: none in pubspec
bselwe 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 | ||
|
||
* Initial release |
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,25 @@ | ||
Copyright 2013 The Flutter Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,7 @@ | ||
# Camera Web Plugin | ||
|
||
A Flutter plugin for Web allowing access to the device cameras. | ||
|
||
*Note*: This plugin is under development. | ||
|
||
In order to use this plugin, your app should depend both on `camera` and `camera_web`. This is a temporary solution until a plugin is released. |
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 @@ | ||
# Testing | ||
|
||
This package uses `package:integration_test` to run its tests in a web browser. | ||
|
||
See [Plugin Tests > Web Tests](https://github.com/flutter/flutter/wiki/Plugin-Tests#web-tests) | ||
in the Flutter wiki for instructions to setup and run the tests in this package. | ||
|
||
Check [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests) | ||
for more info. |
314 changes: 314 additions & 0 deletions
314
packages/camera/camera_web/example/integration_test/camera_web_test.dart
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,314 @@ | ||
// 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 'dart:html'; | ||
|
||
import 'package:camera_platform_interface/camera_platform_interface.dart'; | ||
import 'package:camera_web/camera_web.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
import 'helpers/helpers.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('CameraPlugin', () { | ||
const cameraId = 0; | ||
|
||
late Window window; | ||
late Navigator navigator; | ||
late MediaDevices mediaDevices; | ||
late VideoElement videoElement; | ||
|
||
setUp(() async { | ||
window = MockWindow(); | ||
navigator = MockNavigator(); | ||
mediaDevices = MockMediaDevices(); | ||
videoElement = VideoElement() | ||
..src = | ||
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' | ||
..preload = 'true' | ||
..width = 10 | ||
..height = 10; | ||
|
||
when(() => window.navigator).thenReturn(navigator); | ||
when(() => navigator.mediaDevices).thenReturn(mediaDevices); | ||
when( | ||
() => mediaDevices.getUserMedia(any()), | ||
).thenAnswer((_) async => videoElement.captureStream()); | ||
|
||
CameraPlatform.instance = CameraPlugin()..window = window; | ||
}); | ||
|
||
testWidgets('CameraPlugin is the live instance', (tester) async { | ||
expect(CameraPlatform.instance, isA<CameraPlugin>()); | ||
}); | ||
|
||
testWidgets('availableCameras throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.availableCameras(), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('createCamera throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.createCamera( | ||
CameraDescription( | ||
name: 'name', | ||
lensDirection: CameraLensDirection.external, | ||
sensorOrientation: 0, | ||
), | ||
ResolutionPreset.medium, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('initializeCamera throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.initializeCamera(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('lockCaptureOrientation throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.lockCaptureOrientation( | ||
cameraId, | ||
DeviceOrientation.landscapeLeft, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('unlockCaptureOrientation throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.unlockCaptureOrientation(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('takePicture throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.takePicture(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('prepareForVideoRecording throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.prepareForVideoRecording(), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('startVideoRecording throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.startVideoRecording(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('stopVideoRecording throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.stopVideoRecording(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('pauseVideoRecording throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.pauseVideoRecording(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('resumeVideoRecording throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.resumeVideoRecording(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setFlashMode throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setFlashMode( | ||
cameraId, | ||
FlashMode.auto, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setExposureMode throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setExposureMode( | ||
cameraId, | ||
ExposureMode.auto, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setExposurePoint throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setExposurePoint( | ||
cameraId, | ||
const Point(0, 0), | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('getMinExposureOffset throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.getMinExposureOffset(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('getMaxExposureOffset throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.getMaxExposureOffset(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('getExposureOffsetStepSize throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.getExposureOffsetStepSize(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setExposureOffset throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setExposureOffset( | ||
cameraId, | ||
0, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setFocusMode throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setFocusMode( | ||
cameraId, | ||
FocusMode.auto, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setFocusPoint throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setFocusPoint( | ||
cameraId, | ||
const Point(0, 0), | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('getMaxZoomLevel throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.getMaxZoomLevel(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('getMinZoomLevel throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.getMinZoomLevel(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('setZoomLevel throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.setZoomLevel( | ||
cameraId, | ||
1.0, | ||
), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('buildPreview throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.buildPreview(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('dispose throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.dispose(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
group('events', () { | ||
testWidgets('onCameraInitialized throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.onCameraInitialized(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('onCameraResolutionChanged throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.onCameraResolutionChanged(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('onCameraClosing throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.onCameraClosing(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('onCameraError throws UnimplementedError', (tester) async { | ||
expect( | ||
() => CameraPlatform.instance.onCameraError(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('onVideoRecordedEvent throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.onVideoRecordedEvent(cameraId), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
|
||
testWidgets('onDeviceOrientationChanged throws UnimplementedError', | ||
(tester) async { | ||
expect( | ||
() => CameraPlatform.instance.onDeviceOrientationChanged(), | ||
throwsUnimplementedError, | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/camera/camera_web/example/integration_test/helpers/helpers.dart
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,5 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
bselwe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
export 'mocks.dart'; |
23 changes: 23 additions & 0 deletions
23
packages/camera/camera_web/example/integration_test/helpers/mocks.dart
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,23 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
bselwe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:html'; | ||
|
||
import 'package:mocktail/mocktail.dart'; | ||
|
||
class MockWindow extends Mock implements Window {} | ||
|
||
class MockNavigator extends Mock implements Navigator {} | ||
|
||
class MockMediaDevices extends Mock implements MediaDevices {} | ||
|
||
/// A fake [DomException] that returns the provided [errorName]. | ||
class FakeDomException extends Fake implements DomException { | ||
FakeDomException(this.errorName); | ||
|
||
final String errorName; | ||
|
||
@override | ||
String get name => errorName; | ||
} |
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.