Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/media/video-source-moved.html |
| diff --git a/third_party/WebKit/LayoutTests/media/video-source-moved.html b/third_party/WebKit/LayoutTests/media/video-source-moved.html |
| index d497015a19b8f7e68d6fb342d611399d48641ec1..f36eb1b80b5f28248fd0a42f2e3f7d836ca1ad15 100644 |
| --- a/third_party/WebKit/LayoutTests/media/video-source-moved.html |
| +++ b/third_party/WebKit/LayoutTests/media/video-source-moved.html |
| @@ -1,207 +1,144 @@ |
| -<!doctype HTML> |
| -<html> |
| - <head> |
| - <title>moving <source> element 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 : |
| - [ |
| - { fcn : moveToEnd, errorCount : 0, moved : null, done : false, iteration : 1}, |
| - { fcn : moveToEnd, errorCount : 0, moved : null, done : false, iteration : 2}, |
| - { fcn : moveToEnd, errorCount : 0, moved : null, done : false, iteration : 3}, |
| - { fcn : moveEarlier, errorCount : 0, moved : null, iteration : 1 }, |
| - { fcn : moveEarlier, errorCount : 0, moved : null, iteration : 2 }, |
| - { fcn : moveEarlier, errorCount : 0, moved : null, iteration : 3 }, |
| - { fcn : moveEarlier, errorCount : 0, moved : null, iteration : 4 } |
| - ] |
| - }; |
| - |
| - function findCurrentSourceElement() |
| - { |
| - var sources = video.getElementsByTagName('source'); |
| - var currentSrc = video.currentSrc; |
| - var ndx; |
| - for (ndx = 0; ndx < sources.length; ++ndx) { |
| - if (sources[ndx].src == currentSrc) |
| - break; |
| - } |
| - if (ndx >= sources.length) { |
| - failTest(currentSrc + " not found in <source> list"); |
| - return null; |
| - } |
| - return sources[ndx]; |
| +<!DOCTYPE html> |
| +<title>Test to make sure a "source" moved after the media element begins processing is handled correctly.</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="media-file.js"></script> |
| +<script> |
| +for(var i = 0; i < 7; i++) { |
| + async_test(function(t) { |
| + var testInfo = [ |
|
fs
2016/07/05 13:33:04
Optionally, this could be written using forEach:
Srirama
2016/07/05 14:55:28
You mean to avoid the for loop above? Problem is t
fs
2016/07/05 15:03:35
It's possible that "this" could be used since we'r
|
| + { func : moveToEnd, errorCount : 0, moved : null, iteration : 1}, |
| + { func : moveToEnd, errorCount : 0, moved : null, iteration : 2}, |
| + { func : moveToEnd, errorCount : 0, moved : null, iteration : 3}, |
| + { func : moveEarlier, errorCount : 0, moved : null, iteration : 1 }, |
| + { func : moveEarlier, errorCount : 0, moved : null, iteration : 2 }, |
| + { func : moveEarlier, errorCount : 0, moved : null, iteration : 3 }, |
| + { func : moveEarlier, errorCount : 0, moved : null, iteration : 4 } |
|
fs
2016/07/05 13:33:04
I wonder if this test would be slighty easier to c
Srirama
2016/07/05 14:55:28
Done. Looks much better now, thanks.
|
| + ]; |
| + |
| + var test = testInfo[i]; |
| + var video = document.createElement("video"); |
| + |
| + // Add a bunch of source elements with bogus urls because we want to rearrange |
| + // 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) { |
| + var source = document.createElement("source"); |
| + source.src = findMediaFile("video", index + "-" + Date.now()); |
| + source.type = mimeTypeForExtension(source.src.split(".").pop()); |
| + video.appendChild(source); |
| + |
| + source.onerror = t.step_func(function(event) { |
| + test.func(event); |
| + }); |
| + } |
| + |
| + function findCurrentSourceElement() { |
| + var sources = video.childNodes; |
| + var currentSrc = video.currentSrc; |
| + var index; |
| + for (index = 0; index < sources.length; ++index) { |
| + if (sources[index].src == currentSrc) |
| + break; |
| } |
| - function moveEarlier(test, event) |
| - { |
| - if (test.done) |
| - return; |
| + assert_less_than(index, sources.length, currentSrc + " not found in <source> list"); |
| + return sources[index]; |
| + } |
| + |
| + function moveEarlier(event) { |
| + switch (++test.errorCount) { |
| + case 1: |
| + // Do nothing on the first error event |
| + break; |
| - switch (++test.errorCount) |
| + case 2: |
| + var current = findCurrentSourceElement(); |
| + switch (test.iteration) |
| { |
| case 1: |
| - // Do nothing on the first error event |
| + // Moving current "source" element to beginning of list, it should not be processed again. |
| + test.moved = video.removeChild(current); |
| break; |
| - |
| case 2: |
| - var current = findCurrentSourceElement(); |
| - switch (test.iteration) |
| - { |
| - case 1: |
| - consoleWrite("Moving <b>current<" + "/b> <source> element to beginning of list, it should not be processed again."); |
| - test.moved = video.removeChild(current); |
| - break; |
| - case 2: |
| - consoleWrite("Moving <b>next<" + "/b> <source> element to beginning of list, it should never processed."); |
| - test.moved = video.removeChild(current.nextSibling); |
| - break; |
| - case 3: |
| - consoleWrite("<span> inserted after <b>current<" + "/b> <source> element before it is removed, processing should proceed normally."); |
| - var span = document.createElement("span") |
| - span.appendChild(document.createTextNode("Your browser doesn't support HTML5 video!")); |
| - video.insertBefore(span, current.nextSibling); |
| - test.moved = video.removeChild(current); |
| - break; |
| - case 4: |
| - consoleWrite("<span> inserted after <b>next<" + "/b> <source> element before it is removed, processing should proceed normally."); |
| - var span = document.createElement("span") |
| - span.appendChild(document.createTextNode("Your browser doesn't support HTML5 video!")); |
| - video.insertBefore(span, current.nextSibling.nextSibling); |
| - test.moved = video.removeChild(current.nextSibling); |
| - break; |
| - default: |
| - failTest("Malformed test data!"); |
| - break; |
| - } |
| - |
| - testExpected(test.moved, null, '!='); |
| - video.insertBefore(test.moved, video.firstChild); |
| + // Moving next "source" element to beginning of list, it should never processed. |
| + test.moved = video.removeChild(current.nextSibling); |
| + break; |
| + case 3: |
| + // span inserted after current "source" element before it is removed, processing should proceed normally. |
| + var span = document.createElement("span") |
| + span.appendChild(document.createTextNode("Your browser doesn't support HTML5 video!")); |
| + video.insertBefore(span, current.nextSibling); |
| + test.moved = video.removeChild(current); |
| + break; |
| + case 4: |
| + // span inserted after next "source" element before it is removed, processing should proceed normally. |
| + var span = document.createElement("span") |
| + span.appendChild(document.createTextNode("Your browser doesn't support HTML5 video!")); |
| + video.insertBefore(span, current.nextSibling.nextSibling); |
| + test.moved = video.removeChild(current.nextSibling); |
| break; |
| - |
| default: |
| - // We should never get an error for the element we moved. |
| - if (event.target == test.moved) { |
| - failTest("Error fired for <source> moved to beginning of list."); |
| - test.done = true; |
| - return; |
| - } else if (!event.target.nextSibling) { |
| - logResult(true, "<source> moved was not processed"); |
| - setTimeout(configureNextTest, 100); |
| - } |
| + assert_unreached("Malformed test data!"); |
| break; |
| } |
| + |
| + assert_not_equals(test.moved, null); |
| + video.insertBefore(test.moved, video.firstChild); |
| + break; |
| + |
| + default: |
| + // We should never get an error for the element we moved. |
| + assert_not_equals(event.target, test.moved); |
| + if (event.target.nextSibling == null) |
| + t.done(); |
| + break; |
| } |
| + } |
| + |
| + function moveToEnd(event) { |
| + switch (++test.errorCount) { |
| + case 1: |
| + // Do nothing on the first error event |
| + break; |
| - function moveToEnd(test, event) |
| - { |
| - switch (++test.errorCount) |
| + case 2: |
| + var current = findCurrentSourceElement(); |
| + switch (test.iteration) |
| { |
| case 1: |
| - // Do nothing on the first error event |
| + // Moving previous "source" element to end of list, it should be processed again. |
| + test.moved = video.removeChild(current.previousSibling); |
| break; |
| - |
| case 2: |
| - var current = findCurrentSourceElement(); |
| - switch (test.iteration) |
| - { |
| - case 1: |
| - consoleWrite("Moving <b>previous<" + "/b> <source> element to end of list, it should be processed again."); |
| - test.moved = video.removeChild(current.previousSibling); |
| - break; |
| - case 2: |
| - consoleWrite("Moving <b>current<" + "/b> <source> element, it should be processed again."); |
| - test.moved = video.removeChild(current); |
| - break; |
| - case 3: |
| - consoleWrite("Moving <b>next<" + "/b> <source> element, it should be processed again."); |
| - test.moved = video.removeChild(current.nextSibling); |
| - break; |
| - default: |
| - failTest("Malformed test data!"); |
| - break; |
| - } |
| - |
| - testExpected(test.moved, null, '!='); |
| - video.appendChild(test.moved); |
| + // Moving current "source" element, it should be processed again. |
| + test.moved = video.removeChild(current); |
| + break; |
| + case 3: |
| + // Moving next "source" element, it should be processed again. |
| + test.moved = video.removeChild(current.nextSibling); |
| break; |
| - |
| default: |
| - if (event.target == test.moved) { |
| - logResult(true, "<source> moved was processed a second time."); |
| - setTimeout(configureNextTest, 100); |
| - } else if (!event.target.nextSibling) { |
| - // We should never reach the end of the source list since the tests stops |
| - // when the error fires for the moved element. |
| - failTest("Error never fired for <source> moved!"); |
| - } |
| + assert_unreached("Malformed test data!"); |
| break; |
| } |
| - } |
| - function runOneTest(evt) |
| - { |
| - var test = testInfo.tests[testInfo.current]; |
| - test.fcn(test, evt); |
| - } |
| + assert_not_equals(test.moved, null); |
| + video.appendChild(test.moved); |
| + break; |
| - function addSource(index) |
| - { |
| - var source = document.createElement('source'); |
| - source.src = findMediaFile("video", index + "-" + Date.now()); |
| - source.type = mimeTypeForExtension(source.src.split('.').pop()); |
| - video.appendChild(source); |
| + default: |
| + assert_true(event.target == test.moved || event.target.nextSibling != null); |
| + if (event.target == test.moved) |
| + t.done(); |
| + break; |
| } |
| - |
| - function runNextTest() |
| - { |
| - consoleWrite(""); |
| - if (++testInfo.current >= testInfo.tests.length) { |
| - consoleWrite("PASS<br>"); |
| - endTest(); |
| - return; |
| - } |
| - |
| - testInfo.errorCount = 0; |
| - video = mediaElement = document.createElement('video'); |
| - document.body.appendChild(video); |
| - |
| - // Add a bunch of source elements with bogus urls because we want to rearrange 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); |
| - } |
| - |
| - function setup() |
| - { |
| - document.addEventListener("error", runOneTest, true); |
| - configureNextTest(); |
| - } |
| - |
| - </script> |
| - </head> |
| - |
| - <body> |
| - <div>Test to make sure a <source> moved after the media element begins processing |
| - is handled correctly.</div> |
| - <script>setup()</script> |
| - </body> |
| -</html> |
| + } |
| + }); |
| +} |
| +</script> |