Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Unified Diff: third_party/WebKit/LayoutTests/media/audio-concurrent-supported.html

Issue 2114243002: Convert audio*, media* and video* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/media/audio-concurrent-supported.html
diff --git a/third_party/WebKit/LayoutTests/media/audio-concurrent-supported.html b/third_party/WebKit/LayoutTests/media/audio-concurrent-supported.html
index 5f1aa0809ffa6552ed846a14f05259d993551c0f..ecffca88243a5bb8509988d01a02e50f81349f89 100644
--- a/third_party/WebKit/LayoutTests/media/audio-concurrent-supported.html
+++ b/third_party/WebKit/LayoutTests/media/audio-concurrent-supported.html
@@ -1,72 +1,52 @@
-<html>
- <title>Test of concurrent HTML5 audio</title>
- <body>
-
- <p>Test that multiple audio elements can play concurrently.</p>
-
- <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956
- (Please avoid writing new tests using video-test.js) -->
- <script src=video-test.js></script>
- <script src=media-file.js></script>
- <script>
- var maxPlayers = 2; // Number of concurrent audio elements to test. For larger values a longer media file is needed.
- var audioElementCount = 0;
-
- function errorListener(event)
- {
- logResult(false, "Element " + audioElementCount + " caught 'error' event, audio.error.code = " + this.error.code);
- endTest();
- }
-
- function canplaythroughListener(event)
- {
- consoleWrite("EVENT(" + audioElementCount + ", canplaythrough)");
- testElement = this;
- testExpected(audioElementCount + ", testElement.currentTime", 0);
- this.play();
- }
-
- function playingListener(event)
- {
- consoleWrite("EVENT(" + audioElementCount + ", playing)");
- }
-
- function timeupdateListener(event)
- {
- testElement = this;
- testExpected(audioElementCount + ", testElement.currentTime", 0, '>');
- this.removeEventListener('timeupdate', timeupdateListener);
- if (++audioElementCount >= maxPlayers) {
- // All audio elements have been started playing. Make sure
- // all of them are still playing.
- consoleWrite("Making sure all " + maxPlayers + " audio elements are in playing state:");
+<!DOCTYPE html>
+<title>Test that multiple audio elements can play concurrently.</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="media-file.js"></script>
+<script>
+async_test(function(t) {
+ // Number of concurrent audio elements to test.
+ // For larger values a longer media file is needed.
+ var maxPlayers = 2;
+ var audioElementCount = 0;
+
+ for (var i = 0; i < maxPlayers; i++) {
+ var audio = document.createElement("audio");
+ document.documentElement.appendChild(audio);
+ }
+
+ testAudioElement(0);
+
+ function testAudioElement(count) {
+ var audioElement = document.querySelectorAll("audio")[count];
+ audioElement.onerror = t.unreached_func();
+ audioElement.onplaying = t.step_func(function() {});
+
+ audioElement.oncanplaythrough = t.step_func(function(event) {
+ var currentAudio = event.target;
+ assert_equals(currentAudio.currentTime, 0, "audio element " + (audioElementCount + 1) + " at start of playback");
+ currentAudio.play();
+ });
+
+ audioElement.ontimeupdate = t.step_func(function(event) {
+ var currentAudio = event.target;
+ assert_greater_than(currentAudio.currentTime, 0, "audio element " + (audioElementCount + 1) + " during playback");
+ currentAudio.ontimeupdate = null;
+ if (++audioElementCount == maxPlayers) {
+ // All audio elements have been started playing.
+ // Make sure all of them are still playing.
for (var i = 0; i < maxPlayers; i++) {
- testElement = document.getElementsByTagName('audio')[i];
- testExpected(i + ", testElement.paused", false);
+ currentAudio = document.getElementsByTagName('audio')[i];
+ assert_false(currentAudio.paused, "audio element " + (i + 1) + " during playback");
}
- endTest();
+ t.done();
} else {
- // Start the next audio element
+ // Start the next audio element.
testAudioElement(audioElementCount);
}
- }
-
- function testAudioElement(count)
- {
- var audioElement = document.getElementsByTagName('audio')[count];
- audioElement.addEventListener('error', errorListener);
- audioElement.addEventListener('canplaythrough', canplaythroughListener);
- audioElement.addEventListener('timeupdate', timeupdateListener);
- audioElement.addEventListener('playing', playingListener);
- audioElement.src = findMediaFile("audio", "content/silence");
- }
-
- consoleWrite("Starting a total of " + maxPlayers + " concurrent audio elements.");
- for (var i = 0; i < maxPlayers; i++)
- document.write("<audio controls></audio>");
-
- testAudioElement(0);
- </script>
+ });
- </body>
-</html>
+ audioElement.src = findMediaFile("audio", "content/silence");
+ }
+});
+</script>

Powered by Google App Engine
This is Rietveld 408576698