Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: third_party/WebKit/LayoutTests/media/video-source-removed.html

Issue 2116293004: Convert video-source-[load|moved|removed].html tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 &lt;source&gt; 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 &lt;source&gt; 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 &lt;source&gt; by setting <i>.innerHTML<" + "/i>");
- consoleWrite(" -> video.innerHTML = ''");
- }
-
- function replaceChild(sources)
- {
- consoleWrite("Removing all &lt;source&gt; 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 &lt;source&gt; 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 &lt;source&gt;(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>

Powered by Google App Engine
This is Rietveld 408576698