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

[camera] Introduce camera_web package #4151

Merged
merged 20 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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: 3 additions & 0 deletions packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release
25 changes: 25 additions & 0 deletions packages/camera/camera_web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright 2013 The Flutter Authors. All rights reserved.
bselwe marked this conversation as resolved.
Show resolved Hide resolved

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.
7 changes: 7 additions & 0 deletions packages/camera/camera_web/README.md
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.
9 changes: 9 additions & 0 deletions packages/camera/camera_web/example/README.md
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.
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,
);
});
});
});
}
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';
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;
}
Loading