2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- import 'dart:html ' ;
5
+ import 'dart:js_interop ' ;
6
6
import 'dart:math' ;
7
7
import 'dart:ui' ;
8
8
@@ -13,6 +13,7 @@ import 'package:camera_web/src/types/types.dart';
13
13
import 'package:flutter_test/flutter_test.dart' ;
14
14
import 'package:integration_test/integration_test.dart' ;
15
15
import 'package:mocktail/mocktail.dart' ;
16
+ import 'package:web/web.dart' ;
16
17
17
18
import 'helpers/helpers.dart' ;
18
19
@@ -22,7 +23,7 @@ void main() {
22
23
const Size videoSize = Size (320 , 240 );
23
24
24
25
/// Draw some seconds of random video frames on canvas in realtime.
25
- Future <void > simulateCamera (CanvasElement canvasElement) async {
26
+ Future <void > simulateCamera (HTMLCanvasElement canvasElement) async {
26
27
const int fps = 15 ;
27
28
const int seconds = 3 ;
28
29
const int frameDuration = 1000 ~ / fps;
@@ -34,8 +35,10 @@ void main() {
34
35
final int h = videoSize.height ~ / 20 ;
35
36
for (int y = 0 ; y < videoSize.height; y += h) {
36
37
for (int x = 0 ; x < videoSize.width; x += w) {
37
- canvasElement.context2D.setFillColorRgb (
38
- random.nextInt (255 ), random.nextInt (255 ), random.nextInt (255 ));
38
+ final int r = random.nextInt (255 );
39
+ final int g = random.nextInt (255 );
40
+ final int b = random.nextInt (255 );
41
+ canvasElement.context2D.fillStyle = 'rgba($r , $g , $b , 1)' .toJS;
39
42
canvasElement.context2D.fillRect (x, y, w, h);
40
43
}
41
44
}
@@ -53,19 +56,25 @@ void main() {
53
56
bool isVideoTypeSupported (String type) => type == supportedVideoType;
54
57
55
58
Future <int > recordVideo (int videoBitrate) async {
56
- final Window window = MockWindow ();
57
- final Navigator navigator = MockNavigator ();
58
- final MediaDevices mediaDevices = MockMediaDevices ();
59
+ final MockWindow mockWindow = MockWindow ();
60
+ final MockNavigator mockNavigator = MockNavigator ();
61
+ final MockMediaDevices mockMediaDevices = MockMediaDevices ();
59
62
60
- when (() => window.navigator).thenReturn (navigator);
61
- when (() => navigator.mediaDevices).thenReturn (mediaDevices);
63
+ final Window window = createJSInteropWrapper (mockWindow) as Window ;
64
+ final Navigator navigator =
65
+ createJSInteropWrapper (mockNavigator) as Navigator ;
66
+ final MediaDevices mediaDevices =
67
+ createJSInteropWrapper (mockMediaDevices) as MediaDevices ;
62
68
63
- final CanvasElement canvasElement = CanvasElement (
64
- width: videoSize.width.toInt (),
65
- height: videoSize.height.toInt (),
66
- )..context2D.clearRect (0 , 0 , videoSize.width, videoSize.height);
69
+ mockWindow.navigator = navigator;
70
+ mockNavigator.mediaDevices = mediaDevices;
67
71
68
- final VideoElement videoElement = VideoElement ();
72
+ final HTMLCanvasElement canvasElement = HTMLCanvasElement ()
73
+ ..width = videoSize.width.toInt ()
74
+ ..height = videoSize.height.toInt ()
75
+ ..context2D.clearRect (0 , 0 , videoSize.width, videoSize.height);
76
+
77
+ final HTMLVideoElement videoElement = HTMLVideoElement ();
69
78
70
79
final MockCameraService cameraService = MockCameraService ();
71
80
0 commit comments