Skip to content

Commit 983f882

Browse files
srujzscommit-bot@chromium.org
authored andcommitted
[dart:html] Play videos in draw_image_video_element_test
draw_image_video_element_test creates VideoElements, which the current frame is taken from when drawing to a CanvasElement. The test was waiting on the onCanPlay event of the VideoElement before drawing, although this might mean the video won't actually start playing. This fixes that issue by enabling autoplay and then awaiting the play Event. Change-Id: I100a552a1eb8e88b6b368d88e499f62f2db8e831 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143621 Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Commit-Queue: Srujan Gaddam <srujzs@google.com>
1 parent 7f49939 commit 983f882

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

tests/lib/html/canvasrendering/draw_image_video_element_test.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ var webmVideoDataUrl =
7272
Future testWithThreeParams() async {
7373
setupFunc();
7474

75-
var playFuture = video.onCanPlay.first;
7675
video.onError.listen((_) {
7776
throw ('URL failed to load.');
7877
});
@@ -86,7 +85,13 @@ Future testWithThreeParams() async {
8685
window.console.log('Video is not supported on this system.');
8786
}
8887

89-
await playFuture;
88+
// Without user interaction, playing the video requires autoplay to be enabled
89+
// and autoplay can only be enabled if muted. We loop the video so there is
90+
// always an active frame that can be drawn.
91+
video.loop = true;
92+
video.muted = true;
93+
video.autoplay = true;
94+
await video.play();
9095
context.drawImage(video, 50, 50);
9196

9297
expectPixelFilled(50, 50);
@@ -101,7 +106,6 @@ Future testWithThreeParams() async {
101106
Future testWithFiveParams() async {
102107
setupFunc();
103108

104-
var playFuture = video.onCanPlay.first;
105109
video.onError.listen((_) {
106110
throw ('URL failed to load.');
107111
});
@@ -117,7 +121,10 @@ Future testWithFiveParams() async {
117121
window.console.log('Video is not supported on this system.');
118122
}
119123

120-
await playFuture;
124+
video.loop = true;
125+
video.muted = true;
126+
video.autoplay = true;
127+
await video.play();
121128
context.drawImageToRect(video, new Rectangle(50, 50, 20, 20));
122129

123130
expectPixelFilled(50, 50);
@@ -134,7 +141,6 @@ Future testWithFiveParams() async {
134141
Future testWithNineParams() async {
135142
setupFunc();
136143

137-
var playFuture = video.onCanPlay.first;
138144
video.onError.listen((_) {
139145
throw ('URL failed to load.');
140146
});
@@ -150,7 +156,10 @@ Future testWithNineParams() async {
150156
window.console.log('Video is not supported on this system.');
151157
}
152158

153-
await playFuture;
159+
video.loop = true;
160+
video.muted = true;
161+
video.autoplay = true;
162+
await video.play();
154163
context.drawImageToRect(video, new Rectangle(50, 50, 20, 20),
155164
sourceRect: new Rectangle(2, 2, 6, 6));
156165

@@ -171,7 +180,6 @@ Future testDataUrlWithNineParams() async {
171180
video = new VideoElement();
172181
canvas = new CanvasElement();
173182

174-
var playFuture = video.onCanPlay.first;
175183
video.onError.listen((_) {
176184
throw ('URL failed to load.');
177185
});
@@ -187,7 +195,10 @@ Future testDataUrlWithNineParams() async {
187195
window.console.log('Video is not supported on this system.');
188196
}
189197

190-
await playFuture;
198+
video.loop = true;
199+
video.muted = true;
200+
video.autoplay = true;
201+
await video.play();
191202
context.drawImageToRect(video, new Rectangle(50, 50, 20, 20),
192203
sourceRect: new Rectangle(2, 2, 6, 6));
193204

tests/lib_2/html/canvasrendering/draw_image_video_element_test.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ var webmVideoDataUrl =
7272
Future testWithThreeParams() async {
7373
setupFunc();
7474

75-
var playFuture = video.onCanPlay.first;
7675
video.onError.listen((_) {
7776
throw ('URL failed to load.');
7877
});
@@ -86,7 +85,13 @@ Future testWithThreeParams() async {
8685
window.console.log('Video is not supported on this system.');
8786
}
8887

89-
await playFuture;
88+
// Without user interaction, playing the video requires autoplay to be enabled
89+
// and autoplay can only be enabled if muted. We loop the video so there is
90+
// always an active frame that can be drawn.
91+
video.loop = true;
92+
video.muted = true;
93+
video.autoplay = true;
94+
await video.play();
9095
context.drawImage(video, 50, 50);
9196

9297
expectPixelFilled(50, 50);
@@ -101,7 +106,6 @@ Future testWithThreeParams() async {
101106
Future testWithFiveParams() async {
102107
setupFunc();
103108

104-
var playFuture = video.onCanPlay.first;
105109
video.onError.listen((_) {
106110
throw ('URL failed to load.');
107111
});
@@ -117,7 +121,10 @@ Future testWithFiveParams() async {
117121
window.console.log('Video is not supported on this system.');
118122
}
119123

120-
await playFuture;
124+
video.loop = true;
125+
video.muted = true;
126+
video.autoplay = true;
127+
await video.play();
121128
context.drawImageToRect(video, new Rectangle(50, 50, 20, 20));
122129

123130
expectPixelFilled(50, 50);
@@ -134,7 +141,6 @@ Future testWithFiveParams() async {
134141
Future testWithNineParams() async {
135142
setupFunc();
136143

137-
var playFuture = video.onCanPlay.first;
138144
video.onError.listen((_) {
139145
throw ('URL failed to load.');
140146
});
@@ -150,7 +156,10 @@ Future testWithNineParams() async {
150156
window.console.log('Video is not supported on this system.');
151157
}
152158

153-
await playFuture;
159+
video.loop = true;
160+
video.muted = true;
161+
video.autoplay = true;
162+
await video.play();
154163
context.drawImageToRect(video, new Rectangle(50, 50, 20, 20),
155164
sourceRect: new Rectangle(2, 2, 6, 6));
156165

@@ -171,7 +180,6 @@ Future testDataUrlWithNineParams() async {
171180
video = new VideoElement();
172181
canvas = new CanvasElement();
173182

174-
var playFuture = video.onCanPlay.first;
175183
video.onError.listen((_) {
176184
throw ('URL failed to load.');
177185
});
@@ -187,7 +195,10 @@ Future testDataUrlWithNineParams() async {
187195
window.console.log('Video is not supported on this system.');
188196
}
189197

190-
await playFuture;
198+
video.loop = true;
199+
video.muted = true;
200+
video.autoplay = true;
201+
await video.play();
191202
context.drawImageToRect(video, new Rectangle(50, 50, 20, 20),
192203
sourceRect: new Rectangle(2, 2, 6, 6));
193204

0 commit comments

Comments
 (0)