Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / media / video-source-removed.html
blob2133697e26244b65cb6ca011ac1166945b1deace
1 <!doctype HTML>
2 <html>
3 <head>
4 <title>crash after removing &lt;source&gt; test</title>
5 <script src=video-test.js></script>
6 <script src=media-file.js></script>
7 <script>
9 var testInfo =
11 current : -1,
12 tests : [removeChild, innerHTML, replaceChild]
15 function removeChild(sources)
17 consoleWrite("Removing all &lt;source&gt; elements with <i>removeChild()<" + "/i>");
18 for (var ndx = 0; ndx < sources.length; ++ndx) {
19 consoleWrite(" -> removeChild(" + ndx + ")");
20 video.removeChild(sources[ndx]);
24 function innerHTML()
26 consoleWrite("Removing all &lt;source&gt; by setting <i>.innerHTML<" + "/i>");
27 consoleWrite(" -> video.innerHTML = ''");
30 function replaceChild(sources)
32 consoleWrite("Removing all &lt;source&gt; elements with <i>replaceChild()<" + "/i>");
33 var span = document.createElement("span")
34 span.appendChild(document.createTextNode("Yo"));
35 for (var ndx = 0; ndx < sources.length; ++ndx) {
36 consoleWrite(" -> replaceChild(" + ndx + ")");
37 video.replaceChild(span, sources[ndx]);
41 function runOneTest()
43 testInfo.tests[testInfo.current](document.querySelectorAll('source'));
44 setTimeout(configureNextTest, 100);
47 function addSource(index)
49 source = document.createElement('source');
50 source.src = findMediaFile("video", index + "-" + Date.now());
51 source.type = mimeTypeForExtension(source.src.split('.').pop());
52 video.appendChild(source);
55 function runNextTest()
57 consoleWrite("");
58 if (++testInfo.current >= testInfo.tests.length) {
59 consoleWrite("PASS: A crash did not occur when removing &lt;source&gt; elements.<br>");
60 endTest();
61 return;
64 video = mediaElement = document.createElement('video');
65 document.body.appendChild(video);
66 video.addEventListener("loadstart", runOneTest);
68 // Add a bunch of source elements with bogus urls because we want to remove elements
69 // after the media engine begins processing sources, and we can't predict the delay
70 // between when the media element fires an 'error' event and our handler is called,
71 // but we need to guarantee that there are <source> elements that haven't been processed
72 // when we run the test.
73 for (var ndx = 1; ndx <= 10; ndx++)
74 addSource(ndx);
77 function configureNextTest()
79 var videos = document.querySelectorAll('video');
80 for (var ndx = 0; ndx < videos.length; ++ndx)
81 videos[ndx].parentNode.removeChild(videos[ndx]);
82 video = mediaElement = null;
83 setTimeout(runNextTest, 100);
85 </script>
86 </head>
88 <body>
89 Test to make sure removing a media element's &lt;source&gt;(s) does not cause a crash.
90 <script>configureNextTest()</script>
91 </body>
92 </html>