Skip to content

Commit

Permalink
Sync few more media tests from Blink / Chromium
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269768

Reviewed by Eric Carlson.

This patch is to sync few `media` tests from Blink / Chromium,
leveraging `testharness` and also potentially de-flake.

Partial Merge: https://source.chromium.org/chromium/chromium/src/+/f0b4140302ed4571ec1c063fcb0a87b7cca67514 ,
https://source.chromium.org/chromium/chromium/src/+/b7181764cf5da42aa606b814291c9a465567461b ,
https://source.chromium.org/chromium/chromium/src/+/2403d8e3ac2673941329a1942091409e4b21bb64 ,
https://source.chromium.org/chromium/chromium/src/+/f2dfca4180ffdf50c2c9d926d8113d61d5886efc

> Test & Test Expectations Update:
* LayoutTests/media/unsupported-tracks.html:
* LayoutTests/media/unsupported-tracks-expected.txt:
* LayoutTests/media/unsupported-rtsp.html:
* LayoutTests/media/unsupported-rtsp-expected.txt:
* LayoutTests/media/invalid-media-url-crash.html:
* LayoutTests/media/invalid-media-url-crash-expected.txt:
* LayoutTests/media/event-attributes.html:
* LayoutTests/media/event-attributes-expected.txt:
* LayoutTests/media/controls-css-overload.html:
* LayoutTests/media/controls-css-overload-expected.txt:
* LayoutTests/media/audio-data-url.html:
* LayoutTests/media/audio-data-url-expected.txt:

> Platform Test Expectations:
* LayoutTests/platform/mac/TestExpectations:
* LayoutTests/platform/ios-device/TestExpectations:
* LayoutTests/platform/glib/TestExpectations:

Canonical link: https://commits.webkit.org/275069@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Feb 20, 2024
1 parent 494280a commit eae264a
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 280 deletions.
10 changes: 1 addition & 9 deletions LayoutTests/media/audio-data-url-expected.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
Test that audio element can use a data: url

EVENT(loadstart)
EVENT(durationchange)
EVENT(loadedmetadata)
EVENT(loadeddata)
EVENT(canplay)
EVENT(canplaythrough)
EXPECTED (mediaElement.duration.toFixed(2) == '0.25') OK
END OF TEST
PASS Test that audio element can use a data: url

51 changes: 16 additions & 35 deletions LayoutTests/media/audio-data-url.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions LayoutTests/media/controls-css-overload-expected.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

I did not crash
END OF TEST

PASS Testing that overloading some controls doesn't crash the browser

42 changes: 19 additions & 23 deletions LayoutTests/media/controls-css-overload.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>Testing that overloading some controls doesn't crash the browser</title>
<style>
.nocontrols::-webkit-media-controls-panel{
display:none;
}
.notimeline::-webkit-media-controls-timeline-container{
display:none;
}
</style>
<script src=video-test.js></script>
</head>
<body>
<video class="nocontrols" width=300 height=200 controls></video>
<video class="notimeline" width=300 height=200 controls></video>
<script>
consoleWrite("I did not crash");
endTest();
</script>
<!DOCTYPE html>
<title>Testing that overloading some controls doesn't crash the browser</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<style>
.nocontrols::-webkit-media-controls-panel {
display:none;
}
.notimeline::-webkit-media-controls-timeline-container {
display:none;
}
</style>
<video class="nocontrols" width=300 height=200 controls></video>
<video class="notimeline" width=300 height=200 controls></video>
<script>
test(function() {
// Test is complete if there is no crash.
});
</script>
</body>
</html>
45 changes: 1 addition & 44 deletions LayoutTests/media/event-attributes-expected.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,4 @@

EVENT(loadstart)
EVENT(durationchange)
EVENT(loadedmetadata)
EVENT(loadeddata)
EVENT(canplay)
EVENT(canplaythrough)

*** starting playback
RUN(video.play())
EVENT(play)
EVENT(playing)

*** changing playback rate
RUN(video.playbackRate = 2)
EVENT(ratechange)

*** setting volume
RUN(video.volume = 0.5)
EVENT(volumechange)

*** pausing playback
RUN(video.pause())
EVENT(pause)

*** seeking
RUN(video.currentTime = 5.6)
EVENT(seeking)
EVENT(seeked)

*** beginning playback
RUN(video.play())
EVENT(play)
EVENT(playing)
EVENT(pause)
EVENT(ended)

*** played to end, setting 'src' to an invalid movie
RUN(progressEventCount = 0)
EVENT(abort)
EVENT(emptied)
EVENT(ratechange)
EVENT(loadstart)
EVENT(error)
EXPECTED (progressEventCount == '0') OK
END OF TEST
PASS Test event attributes for media element.

183 changes: 86 additions & 97 deletions LayoutTests/media/event-attributes.html
Original file line number Diff line number Diff line change
@@ -1,104 +1,93 @@
<!DOCTYPE html>
<html>
<head>
<script src=media-file.js></script>
<script src=video-test.js></script>
<script>
var ratechangeCount = 0;
var playingCount = 0;
var progressEventCount = 0;
var pauseEventCount = 0;
<title>Test event attributes for media element.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<video controls></video>
<script>
async_test(function(t) {
var ratechangeCount = 0;
var playingCount = 0;
var progressEventCount = 0;
var pauseEventCount = 0;

function eventHandler()
{
// Don't log progress event since the number and order are platform
// specific.
if (event.type != "progress")
consoleWrite("EVENT(" + event.type + ")");
switch (event.type)
{
case "canplaythrough":
consoleWrite("<br>*** starting playback");
run("video.play()");
break;
case "playing":
if (++playingCount == 1) {
consoleWrite("<br>*** changing playback rate");
run("video.playbackRate = 2");
}
break;
case "ratechange":
if (++ratechangeCount == 1) {
consoleWrite("<br>*** setting volume");
run("video.volume = 0.5");
}
break;
case "volumechange":
consoleWrite("<br>*** pausing playback");
run("video.pause()");
break;
case "pause":
if(++pauseEventCount == 1) {
consoleWrite("<br>*** seeking");
run("video.currentTime = 5.6");
}
break;
case "seeked":
consoleWrite("<br>*** beginning playback");
run("video.play()");
break;
case "ended":
var mediaFile = findMediaFile("video", "content/garbage");
consoleWrite("<br>*** played to end, setting 'src' to an invalid movie");
run("progressEventCount = 0");
video.src = mediaFile;
break;
case "progress":
++progressEventCount;
break;
case "error":
testExpected('progressEventCount', 0);
endTest();
break;
default:
break;
}
}
var video = document.querySelector("video");

function start()
{
setSrcByTagName("video", findMediaFile("video", "content/test"));
findMediaElement();
}
var actual_events = [];
var expected_events = ["loadstart", "durationchange", "loadedmetadata",
"loadeddata", "canplay", "canplaythrough", "play", "playing", "ratechange",
"volumechange", "pause", "seeking", "seeked", "play", "playing", "pause",
"ended", "abort", "emptied", "ratechange", "loadstart", "error"];

</script>
</head>
video.oncanplaythrough = t.step_func(function(event) {
actual_events.push(event.type);
video.oncanplaythrough = null;
assert_greater_than_equal(progressEventCount, 1);
video.play();
});

<body onload="start()">
video.oncanplay = t.step_func(function(event) {
actual_events.push(event.type);
video.oncanplay = null;
});

<video controls
onabort="eventHandler()"
oncanplay="eventHandler()"
oncanplaythrough="eventHandler()"
ondurationchange="eventHandler()"
onemptied="eventHandler()"
onended="eventHandler()"
onerror="eventHandler()"
onloadeddata="eventHandler()"
onloadedmetadata="eventHandler()"
onloadstart="eventHandler()"
onpause="eventHandler()"
onplay="eventHandler()"
onplaying="eventHandler()"
onprogress="eventHandler()"
onratechange="eventHandler()"
onseeked="eventHandler()"
onseeking="eventHandler()"
onstalled="eventHandler()"
onvolumechange="eventHandler()"
onwaiting="eventHandler()"
>
</video>
video.onplaying = t.step_func(function(event) {
actual_events.push(event.type);
if (++playingCount == 1)
video.playbackRate = 2;
});

</body>
</html>
video.onratechange = t.step_func(function(event) {
actual_events.push(event.type);
if (++ratechangeCount == 1)
video.volume = 0.5;
});

video.onvolumechange = t.step_func(function(event) {
actual_events.push(event.type);
video.pause();
});

video.onpause = t.step_func(function(event) {
actual_events.push(event.type);
if(++pauseEventCount == 1)
video.currentTime = 5.6;
});

video.onseeked = t.step_func(function(event) {
actual_events.push(event.type);
video.play();
});

video.onended = t.step_func(function(event) {
actual_events.push(event.type);
video.src = "content/garbage.ogv";
progressEventCount = 0;
});

video.onprogress = t.step_func(function() {
// Don't log progress event since the number and order are platform specific.
++progressEventCount;
});

video.onerror = t.step_func_done(function(event) {
actual_events.push(event.type);
assert_equals(progressEventCount, 0);
assert_array_equals(actual_events, expected_events);
});

var defaultEventStepFunction = t.step_func(function() {
actual_events.push(event.type);
});

video.onabort = defaultEventStepFunction;
video.ondurationchange = defaultEventStepFunction;
video.onemptied = defaultEventStepFunction;
video.onloadeddata = defaultEventStepFunction;
video.onloadedmetadata = defaultEventStepFunction;
video.onloadstart = defaultEventStepFunction;
video.onplay = defaultEventStepFunction;
video.onseeking = defaultEventStepFunction;

video.src = "content/test.mp4";
});
</script>
8 changes: 2 additions & 6 deletions LayoutTests/media/invalid-media-url-crash-expected.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
Tests that invalid media src url does not result in crash.

EXPECTED (audio.error.code == '4') OK
EXPECTED (video.error.code == '4') OK
EXPECTED (audio.networkState == '3') OK
EXPECTED (video.networkState == '3') OK
END OF TEST
PASS Tests that invalid media src url does not result in crash.
PASS Tests that invalid media src url does not result in crash. 1

48 changes: 18 additions & 30 deletions LayoutTests/media/invalid-media-url-crash.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
<html>
<body>
<p>Tests that invalid media src url does not result in crash.</p>
<script src=video-test.js></script>
<script>
var invalid_url = "!:/" + String.fromCharCode(0) + "%aa#aa";
var error_count = 0;
<!DOCTYPE html>
<title>Tests that invalid media src url does not result in crash.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
function check_invalid_media_src(elementName) {
async_test(function(t) {
var mediaElement = document.createElement(elementName);
mediaElement.src = "!:/" + String.fromCharCode(0) + "%aa#aa";

function errorEvent()
{
error_count++;
if (error_count == 2)
{
testExpected("audio.error.code", MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
testExpected("video.error.code", MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
testExpected("audio.networkState", HTMLMediaElement.NETWORK_NO_SOURCE);
testExpected("video.networkState", HTMLMediaElement.NETWORK_NO_SOURCE);
endTest();
}
}
mediaElement.onerror = t.step_func_done(function() {
assert_equals(mediaElement.error.code, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
assert_equals(mediaElement.networkState, HTMLMediaElement.NETWORK_NO_SOURCE);
});
});
}

var audio = document.createElement('audio');
var video = document.createElement('video');
audio.src = invalid_url;
video.src = invalid_url;
audio.onerror = errorEvent;
video.onerror = errorEvent;
document.body.appendChild(audio);
document.body.appendChild(video);
</script>
</body>
</html>
check_invalid_media_src("audio");
check_invalid_media_src("video");
</script>
7 changes: 1 addition & 6 deletions LayoutTests/media/unsupported-rtsp-expected.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

Test that QuickTime file with RTSP URL generates a load error.

EVENT(error)
EXPECTED (video.error != 'null') OK
EXPECTED (video.error.code == '4') OK
EXPECTED (video.networkState == '3') OK
END OF TEST
PASS Test that QuickTime file with RTSP URL generates a load error.

Loading

0 comments on commit eae264a

Please sign in to comment.