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

Unified Diff: third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source.html

Issue 2031783002: Convert media-cont* and media-element* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source.html
diff --git a/third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source.html b/third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source.html
index f1ede32c8a8e869e6ba5708578ab654ca03db083..fb9aaed8c717672e3ec64d96abf8e878e392cd7e 100644
--- a/third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source.html
+++ b/third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source.html
@@ -1,111 +1,51 @@
-<html>
- <title>Test media source replacement</title>
- <body>
-
- <p>Test that media keeps playing when the source element is replaced.</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 src=../resources/gc.js></script>
- <script>
- var timeupdateEventCount = 0;
- var skippedCount = 0;
- var sourceReplaced = false;
-
- function swapAudio() {
- v = document.getElementsByTagName('audio')[0];
- v.removeChild(v.childNodes[0]);
- var s = document.createElement('source');
- s.src = findMediaFile("audio", "content/test");
- v.appendChild(s);
- }
-
- function errorListener(event)
- {
- logResult(false, "Caught 'error' event, audio.error.code = " + this.error.code);
- endTest();
- }
-
- function canplaythroughListener(event)
- {
- consoleWrite("EVENT(canplaythrough)");
- testElement = this;
- testExpected("testElement.currentTime", 0);
- this.play();
- }
-
- function playingListener(event)
- {
- consoleWrite("EVENT(playing)");
- }
-
- function timeupdateListener(event)
- {
- ++timeupdateEventCount;
-
- if (timeupdateEventCount-skippedCount == 1) {
- // If the media play has started it should continue even if
- // source was replaced. Wait for two timeupdate events to
- // make sure the same source keeps playing.
- if (sourceReplaced) {
- if (skippedCount >= 1 || this.currentTime > 0) {
- testElement = this;
- testExpected("testElement.currentTime", 0, '>');
- } else {
- // The time is not 0 as expected. Make sure same
- // source keeps playing by waiting for one more event.
- ++skippedCount;
- }
- }
- } else if (timeupdateEventCount-skippedCount >= 2) {
- // We wait 2 timeupdate events so we are sure the media engine
- // is playing the media, and make sure time is advancing.
- testElement = this;
- testExpected("testElement.currentTime", 0, '>');
- if (!sourceReplaced) {
- consoleWrite("Replacing the media's source element:");
- sourceReplaced = true;
- timeupdateEventCount = 0;
- skippedCount = 0;
- // The ports are not consistent in regards to whether
- // the canplaythrough and playing events are triggered
- // a second time, so stop listening for them. This was
- // done to help the cr-linux test pass, and does not
- // necessarily indicate a problem.
- this.removeEventListener('playing', playingListener);
- this.removeEventListener('canplaythrough', canplaythroughListener);
- swapAudio();
- } else {
- this.removeEventListener('timeupdate', timeupdateListener);
- this.pause();
- endTest();
- }
+<!DOCTYPE html>
+<title>Test that media keeps playing when the source element is replaced.</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="media-file.js"></script>
+<audio></audio>
+<script>
+async_test(function(t) {
+ // TODO(srirama.m): Improve the test for better understanding
+ var timeupdateEventCount = 0;
+ var sourceReplaced = false;
+
+ var audio = document.querySelector("audio");
+ var source = document.createElement("source");
+ source.src = findMediaFile("audio", "content/silence");
+ audio.appendChild(source);
+
+ audio.onerror = t.unreached_func();
+
+ audio.ontimeupdate = t.step_func(function() {
+ ++timeupdateEventCount;
+
+ if (timeupdateEventCount == 1) {
+ // If the media play has started it should continue even if
+ // source was replaced. Wait for two timeupdate events to
+ // make sure the same source keeps playing.
+ if (sourceReplaced)
+ assert_greater_than(audio.currentTime, 0);
+ } else if (timeupdateEventCount == 2) {
+ // We wait 2 timeupdate events so we are sure the media engine
+ // is playing the media, and make sure time is advancing.
+ assert_greater_than(audio.currentTime, 0);
+ if (!sourceReplaced) {
+ // Replacing the media's source element.
+ sourceReplaced = true;
+ timeupdateEventCount = 0;
+
+ audio.removeChild(source);
+ var newSource = document.createElement("source");
+ newSource.src = findMediaFile("audio", "content/test");
+ audio.appendChild(newSource);
+ } else {
+ t.done();
}
}
+ });
- function testAudioElement(count)
- {
- timeupdateEventCount = 0;
- skippedCount = 0;
- var audioElement = document.getElementsByTagName('audio')[count];
- //audioElement.removeChild(audioElement.childNodes[0]);
- audioElement.addEventListener('error', errorListener);
- audioElement.addEventListener('canplaythrough', canplaythroughListener);
- audioElement.addEventListener('timeupdate', timeupdateListener);
- audioElement.addEventListener('playing', playingListener);
-
- var s = document.createElement('source');
- s.src = findMediaFile("audio", "content/silence");
- audioElement.appendChild(s);
-
- }
-
- document.write("<audio controls></audio>");
- testAudioElement(0);
- gc();
- </script>
-
- </body>
-</html>
+ assert_equals(audio.currentTime, 0);
+ audio.play();
+});
+</script>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/media-continues-playing-after-replace-source-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698