upload tizen1.0 source
[framework/web/webkit-efl.git] / LayoutTests / media / video-source-removed.html
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>
8
9             var testInfo = 
10             {
11                 current : -1,
12                 tests : [removeChild, innerHTML, replaceChild]
13             };
14
15             function removeChild(sources)
16             {
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]);
21                }
22             }
23
24             function innerHTML()
25             {
26                 consoleWrite("Removing all &lt;source&gt; by setting <i>.innerHTML<" + "/i>");
27                 consoleWrite(" -> video.innerHTML = ''"); 
28             }
29
30             function replaceChild(sources)
31             {
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]);
38                 }
39             }
40
41             function runOneTest()
42             {
43                 testInfo.tests[testInfo.current](document.querySelectorAll('source'));
44                 setTimeout(configureNextTest, 100);
45             }
46
47             function addSource(index)
48             {
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);
53             }
54             
55             function runNextTest()
56             {
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;
62                 }
63
64                 video = mediaElement = document.createElement('video');
65                 document.body.appendChild(video);
66                 video.addEventListener("loadstart", runOneTest);
67
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);
75             }
76
77             function configureNextTest()
78             {
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);
84             }
85         </script>
86     </head>
87
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>