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