OLD | NEW |
1 <!doctype HTML> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Test to make sure removing a media element's source(s) does not cause a c
rash.</title> |
3 <head> | 3 <script src="../resources/testharness.js"></script> |
4 <title>crash after removing <source> test</title> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 5 <script src="media-file.js"></script> |
6 (Please avoid writing new tests using video-test.js) --> | 6 <script> |
7 <script src=video-test.js></script> | 7 function test_remove_source(testFunction) { |
8 <script src=media-file.js></script> | 8 async_test(function(t) { |
9 <script> | 9 var video = document.createElement("video"); |
10 | 10 |
11 var testInfo = | 11 video.onloadstart = t.step_func(function() { |
12 { | 12 testFunction(video); |
13 current : -1, | 13 setTimeout(t.step_func_done(), 100); |
14 tests : [removeChild, innerHTML, replaceChild] | 14 }); |
15 }; | |
16 | 15 |
17 function removeChild(sources) | 16 // Add a bunch of source elements with bogus urls because we want to rem
ove elements |
18 { | 17 // after the media engine begins processing sources, and we can't predic
t the delay |
19 consoleWrite("Removing all <source> elements with <i>remov
eChild()<" + "/i>"); | 18 // between when the media element fires an "error" event and our handler
is called, |
20 for (var ndx = 0; ndx < sources.length; ++ndx) { | 19 // but we need to guarantee that there are <source> elements that haven'
t been |
21 consoleWrite(" -> removeChild(" + ndx + ")"); | 20 // processed when we run the test. |
22 video.removeChild(sources[ndx]); | 21 for (var index = 1; index <= 10; index++) |
23 } | 22 addSource(index); |
24 } | |
25 | 23 |
26 function innerHTML() | 24 function addSource(index) { |
27 { | 25 source = document.createElement("source"); |
28 consoleWrite("Removing all <source> by setting <i>.innerHT
ML<" + "/i>"); | 26 source.src = findMediaFile("video", index + "-" + Date.now()); |
29 consoleWrite(" -> video.innerHTML = ''"); | 27 source.type = mimeTypeForExtension(source.src.split(".").pop()); |
30 } | 28 video.appendChild(source); |
| 29 } |
| 30 }, "source elements removed using " + testFunction.name + "()"); |
| 31 } |
31 | 32 |
32 function replaceChild(sources) | 33 function removeChild(video) { |
33 { | 34 // Removing all "source" elements with "removeChild()". |
34 consoleWrite("Removing all <source> elements with <i>repla
ceChild()<" + "/i>"); | 35 var sources = video.childNodes; |
35 var span = document.createElement("span") | 36 for (var source of sources) |
36 span.appendChild(document.createTextNode("Yo")); | 37 video.removeChild(source); |
37 for (var ndx = 0; ndx < sources.length; ++ndx) { | 38 } |
38 consoleWrite(" -> replaceChild(" + ndx + ")"); | |
39 video.replaceChild(span, sources[ndx]); | |
40 } | |
41 } | |
42 | 39 |
43 function runOneTest() | 40 function innerHTML(video) { |
44 { | 41 // Removing all "source" elements by setting "innerHTML". |
45 testInfo.tests[testInfo.current](document.querySelectorAll('sour
ce')); | 42 video.innerHTML = ""; |
46 setTimeout(configureNextTest, 100); | 43 } |
47 } | |
48 | 44 |
49 function addSource(index) | 45 function replaceChild(video) { |
50 { | 46 // Removing all "source" elements with "replaceChild()". |
51 source = document.createElement('source'); | 47 var sources = video.childNodes; |
52 source.src = findMediaFile("video", index + "-" + Date.now()); | 48 var span = document.createElement("span"); |
53 source.type = mimeTypeForExtension(source.src.split('.').pop()); | 49 span.appendChild(document.createTextNode("Yo")); |
54 video.appendChild(source); | 50 for (var source of sources) |
55 } | 51 video.replaceChild(span, source); |
| 52 } |
56 | 53 |
57 function runNextTest() | 54 test_remove_source(removeChild); |
58 { | 55 test_remove_source(innerHTML); |
59 consoleWrite(""); | 56 test_remove_source(replaceChild); |
60 if (++testInfo.current >= testInfo.tests.length) { | 57 </script> |
61 consoleWrite("PASS: A crash did not occur when removing <
source> elements.<br>"); | |
62 endTest(); | |
63 return; | |
64 } | |
65 | |
66 video = mediaElement = document.createElement('video'); | |
67 document.body.appendChild(video); | |
68 video.addEventListener("loadstart", runOneTest); | |
69 | |
70 // Add a bunch of source elements with bogus urls because we wan
t to remove elements | |
71 // after the media engine begins processing sources, and we can'
t predict the delay | |
72 // between when the media element fires an 'error' event and our
handler is called, | |
73 // but we need to guarantee that there are <source> elements tha
t haven't been processed | |
74 // when we run the test. | |
75 for (var ndx = 1; ndx <= 10; ndx++) | |
76 addSource(ndx); | |
77 } | |
78 | |
79 function configureNextTest() | |
80 { | |
81 var videos = document.querySelectorAll('video'); | |
82 for (var ndx = 0; ndx < videos.length; ++ndx) | |
83 videos[ndx].parentNode.removeChild(videos[ndx]); | |
84 video = mediaElement = null; | |
85 setTimeout(runNextTest, 100); | |
86 } | |
87 </script> | |
88 </head> | |
89 | |
90 <body> | |
91 Test to make sure removing a media element's <source>(s) does not
cause a crash. | |
92 <script>configureNextTest()</script> | |
93 </body> | |
94 </html> | |
OLD | NEW |