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

Side by Side 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, 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html> 1 <!DOCTYPE html>
2 <title>Test media source replacement</title> 2 <title>Test that media keeps playing when the source element is replaced.</title >
3 <body> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="media-file.js"></script>
6 <audio></audio>
7 <script>
8 async_test(function(t) {
9 // TODO(srirama.m): Improve the test for better understanding
10 var timeupdateEventCount = 0;
11 var sourceReplaced = false;
12
13 var audio = document.querySelector("audio");
14 var source = document.createElement("source");
15 source.src = findMediaFile("audio", "content/silence");
16 audio.appendChild(source);
4 17
5 <p>Test that media keeps playing when the source element is replaced.</p> 18 audio.onerror = t.unreached_func();
6 19
7 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 20 audio.ontimeupdate = t.step_func(function() {
8 (Please avoid writing new tests using video-test.js) --> 21 ++timeupdateEventCount;
9 <script src=video-test.js></script>
10 <script src=media-file.js></script>
11 <script src=../resources/gc.js></script>
12 <script>
13 var timeupdateEventCount = 0;
14 var skippedCount = 0;
15 var sourceReplaced = false;
16 22
17 function swapAudio() { 23 if (timeupdateEventCount == 1) {
18 v = document.getElementsByTagName('audio')[0]; 24 // If the media play has started it should continue even if
19 v.removeChild(v.childNodes[0]); 25 // source was replaced. Wait for two timeupdate events to
20 var s = document.createElement('source'); 26 // make sure the same source keeps playing.
21 s.src = findMediaFile("audio", "content/test"); 27 if (sourceReplaced)
22 v.appendChild(s); 28 assert_greater_than(audio.currentTime, 0);
23 } 29 } else if (timeupdateEventCount == 2) {
24 30 // We wait 2 timeupdate events so we are sure the media engine
25 function errorListener(event) 31 // is playing the media, and make sure time is advancing.
26 { 32 assert_greater_than(audio.currentTime, 0);
27 logResult(false, "Caught 'error' event, audio.error.code = " + this .error.code); 33 if (!sourceReplaced) {
28 endTest(); 34 // Replacing the media's source element.
29 } 35 sourceReplaced = true;
30 36 timeupdateEventCount = 0;
31 function canplaythroughListener(event) 37
32 { 38 audio.removeChild(source);
33 consoleWrite("EVENT(canplaythrough)"); 39 var newSource = document.createElement("source");
34 testElement = this; 40 newSource.src = findMediaFile("audio", "content/test");
35 testExpected("testElement.currentTime", 0); 41 audio.appendChild(newSource);
36 this.play(); 42 } else {
37 } 43 t.done();
38
39 function playingListener(event)
40 {
41 consoleWrite("EVENT(playing)");
42 }
43
44 function timeupdateListener(event)
45 {
46 ++timeupdateEventCount;
47
48 if (timeupdateEventCount-skippedCount == 1) {
49 // If the media play has started it should continue even if
50 // source was replaced. Wait for two timeupdate events to
51 // make sure the same source keeps playing.
52 if (sourceReplaced) {
53 if (skippedCount >= 1 || this.currentTime > 0) {
54 testElement = this;
55 testExpected("testElement.currentTime", 0, '>');
56 } else {
57 // The time is not 0 as expected. Make sure same
58 // source keeps playing by waiting for one more event.
59 ++skippedCount;
60 }
61 }
62 } else if (timeupdateEventCount-skippedCount >= 2) {
63 // We wait 2 timeupdate events so we are sure the media engine
64 // is playing the media, and make sure time is advancing.
65 testElement = this;
66 testExpected("testElement.currentTime", 0, '>');
67 if (!sourceReplaced) {
68 consoleWrite("Replacing the media's source element:");
69 sourceReplaced = true;
70 timeupdateEventCount = 0;
71 skippedCount = 0;
72 // The ports are not consistent in regards to whether
73 // the canplaythrough and playing events are triggered
74 // a second time, so stop listening for them. This was
75 // done to help the cr-linux test pass, and does not
76 // necessarily indicate a problem.
77 this.removeEventListener('playing', playingListener);
78 this.removeEventListener('canplaythrough', canplaythroughLis tener);
79 swapAudio();
80 } else {
81 this.removeEventListener('timeupdate', timeupdateListener);
82 this.pause();
83 endTest();
84 }
85 } 44 }
86 } 45 }
46 });
87 47
88 function testAudioElement(count) 48 assert_equals(audio.currentTime, 0);
89 { 49 audio.play();
90 timeupdateEventCount = 0; 50 });
91 skippedCount = 0; 51 </script>
92 var audioElement = document.getElementsByTagName('audio')[count];
93 //audioElement.removeChild(audioElement.childNodes[0]);
94 audioElement.addEventListener('error', errorListener);
95 audioElement.addEventListener('canplaythrough', canplaythroughListen er);
96 audioElement.addEventListener('timeupdate', timeupdateListener);
97 audioElement.addEventListener('playing', playingListener);
98
99 var s = document.createElement('source');
100 s.src = findMediaFile("audio", "content/silence");
101 audioElement.appendChild(s);
102
103 }
104
105 document.write("<audio controls></audio>");
106 testAudioElement(0);
107 gc();
108 </script>
109
110 </body>
111 </html>
OLDNEW
« 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