Index: third_party/WebKit/LayoutTests/media/video-source-removed.html |
diff --git a/third_party/WebKit/LayoutTests/media/video-source-removed.html b/third_party/WebKit/LayoutTests/media/video-source-removed.html |
index 50485d47e59de86fba20771909b6a8aedd8b3419..9b5350a638a32028a5ec11f4cc3021d1e5ca013e 100644 |
--- a/third_party/WebKit/LayoutTests/media/video-source-removed.html |
+++ b/third_party/WebKit/LayoutTests/media/video-source-removed.html |
@@ -1,94 +1,57 @@ |
-<!doctype HTML> |
-<html> |
- <head> |
- <title>crash after removing <source> test</title> |
- <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 |
- (Please avoid writing new tests using video-test.js) --> |
- <script src=video-test.js></script> |
- <script src=media-file.js></script> |
- <script> |
- |
- var testInfo = |
- { |
- current : -1, |
- tests : [removeChild, innerHTML, replaceChild] |
- }; |
- |
- function removeChild(sources) |
- { |
- consoleWrite("Removing all <source> elements with <i>removeChild()<" + "/i>"); |
- for (var ndx = 0; ndx < sources.length; ++ndx) { |
- consoleWrite(" -> removeChild(" + ndx + ")"); |
- video.removeChild(sources[ndx]); |
- } |
- } |
- |
- function innerHTML() |
- { |
- consoleWrite("Removing all <source> by setting <i>.innerHTML<" + "/i>"); |
- consoleWrite(" -> video.innerHTML = ''"); |
- } |
- |
- function replaceChild(sources) |
- { |
- consoleWrite("Removing all <source> elements with <i>replaceChild()<" + "/i>"); |
- var span = document.createElement("span") |
- span.appendChild(document.createTextNode("Yo")); |
- for (var ndx = 0; ndx < sources.length; ++ndx) { |
- consoleWrite(" -> replaceChild(" + ndx + ")"); |
- video.replaceChild(span, sources[ndx]); |
- } |
- } |
- |
- function runOneTest() |
- { |
- testInfo.tests[testInfo.current](document.querySelectorAll('source')); |
- setTimeout(configureNextTest, 100); |
- } |
- |
- function addSource(index) |
- { |
- source = document.createElement('source'); |
- source.src = findMediaFile("video", index + "-" + Date.now()); |
- source.type = mimeTypeForExtension(source.src.split('.').pop()); |
- video.appendChild(source); |
- } |
- |
- function runNextTest() |
- { |
- consoleWrite(""); |
- if (++testInfo.current >= testInfo.tests.length) { |
- consoleWrite("PASS: A crash did not occur when removing <source> elements.<br>"); |
- endTest(); |
- return; |
- } |
- |
- video = mediaElement = document.createElement('video'); |
- document.body.appendChild(video); |
- video.addEventListener("loadstart", runOneTest); |
- |
- // Add a bunch of source elements with bogus urls because we want to remove elements |
- // after the media engine begins processing sources, and we can't predict the delay |
- // between when the media element fires an 'error' event and our handler is called, |
- // but we need to guarantee that there are <source> elements that haven't been processed |
- // when we run the test. |
- for (var ndx = 1; ndx <= 10; ndx++) |
- addSource(ndx); |
- } |
- |
- function configureNextTest() |
- { |
- var videos = document.querySelectorAll('video'); |
- for (var ndx = 0; ndx < videos.length; ++ndx) |
- videos[ndx].parentNode.removeChild(videos[ndx]); |
- video = mediaElement = null; |
- setTimeout(runNextTest, 100); |
- } |
- </script> |
- </head> |
- |
- <body> |
- Test to make sure removing a media element's <source>(s) does not cause a crash. |
- <script>configureNextTest()</script> |
- </body> |
-</html> |
+<!DOCTYPE html> |
+<title>Test to make sure removing a media element's source(s) does not cause a crash.</title> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="media-file.js"></script> |
+<script> |
+function test_remove_source(testFunction) { |
+ async_test(function(t) { |
+ var video = document.createElement("video"); |
+ |
+ video.onloadstart = t.step_func(function() { |
+ testFunction(video); |
+ setTimeout(t.step_func_done(), 100); |
+ }); |
+ |
+ // Add a bunch of source elements with bogus urls because we want to remove elements |
+ // after the media engine begins processing sources, and we can't predict the delay |
+ // between when the media element fires an "error" event and our handler is called, |
+ // but we need to guarantee that there are <source> elements that haven't been |
+ // processed when we run the test. |
+ for (var index = 1; index <= 10; index++) |
+ addSource(index); |
+ |
+ function addSource(index) { |
+ source = document.createElement("source"); |
+ source.src = findMediaFile("video", index + "-" + Date.now()); |
+ source.type = mimeTypeForExtension(source.src.split(".").pop()); |
+ video.appendChild(source); |
+ } |
+ }, "source elements removed using " + testFunction.name + "()"); |
+} |
+ |
+function removeChild(video) { |
+ // Removing all "source" elements with "removeChild()". |
+ var sources = video.childNodes; |
+ for (var source of sources) |
+ video.removeChild(source); |
+} |
+ |
+function innerHTML(video) { |
+ // Removing all "source" elements by setting "innerHTML". |
+ video.innerHTML = ""; |
+} |
+ |
+function replaceChild(video) { |
+ // Removing all "source" elements with "replaceChild()". |
+ var sources = video.childNodes; |
+ var span = document.createElement("span"); |
+ span.appendChild(document.createTextNode("Yo")); |
+ for (var source of sources) |
+ video.replaceChild(span, source); |
+} |
+ |
+test_remove_source(removeChild); |
+test_remove_source(innerHTML); |
+test_remove_source(replaceChild); |
+</script> |