Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/media/video-controls-captions.html |
| diff --git a/third_party/WebKit/LayoutTests/media/video-controls-captions.html b/third_party/WebKit/LayoutTests/media/video-controls-captions.html |
| index 9f9dfa58f6b78176f8415b4c3c127d132dbf94e2..b466b09fe456b035e7796b1ae4e812e94f39f809 100644 |
| --- a/third_party/WebKit/LayoutTests/media/video-controls-captions.html |
| +++ b/third_party/WebKit/LayoutTests/media/video-controls-captions.html |
| @@ -1,126 +1,72 @@ |
| <!DOCTYPE html> |
| -<html> |
| -<head> |
| - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| - <title>Test closed caption track selection functionality.</title> |
| - <script src=media-file.js></script> |
| - <script src=media-controls.js></script> |
| - <!-- 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> |
| - var track; |
| - |
| - function addTextTrackThroughJS() |
| - { |
| - consoleWrite(""); |
| - consoleWrite("** Add a text track through JS to the video element **"); |
| - var t = video.addTextTrack('captions', 'English', 'en'); |
| - t.addCue(new VTTCue(0.0, 10.0, 'Some random caption text')); |
| - } |
| - |
| - function addUnloadableHTMLTrackElement() |
| - { |
| - consoleWrite(""); |
| - consoleWrite("** Add non-default text track through HTML with unloadable URI **"); |
| - |
| - track = document.createElement("track"); |
| - track.setAttribute("kind", "captions"); |
| - track.setAttribute("srclang", "en"); |
| - track.setAttribute("src", "invalid.vtt"); |
| - |
| - track.addEventListener("error", trackError); |
| - |
| - video.appendChild(track); |
| - testExpected("track.readyState", HTMLTrackElement.NONE); |
| - testExpected("track.track.mode", "disabled"); |
| - testExpected("video.textTracks.length", 1); |
| - } |
| - |
| - function removeHTMLTrackElement() |
| - { |
| - consoleWrite(""); |
| - consoleWrite("** Remove DOM node representing the track element **"); |
| - var htmlTrack = video.children[0]; |
| - video.removeChild(htmlTrack); |
| - } |
| - |
| - function checkCaptionsDisplay() |
| - { |
| - // When no tracks are loaded, this should report no text track container, |
| - // when tracks are loaded but not visible, should report no cues visible, |
| - // when tracks are loaded and visible, should properly check the text. |
| - testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem"); |
| - } |
| - |
| - function startTest() |
| - { |
| - if (!window.eventSender) { |
| - consoleWrite("No eventSender found."); |
| - failTest(); |
| - } |
| - |
| - findMediaElement(); |
| - testClosedCaptionsButtonVisibility(true); |
| - |
| - consoleWrite(""); |
| - consoleWrite("** The captions track should be listed in textTracks, but not yet loaded. **"); |
| - testExpected("video.textTracks.length", 1); |
| - testExpected("video.textTracks[0].mode", "disabled"); |
| - checkCaptionsDisplay(); |
| - |
| - consoleWrite(""); |
| - consoleWrite("** Captions track should load and captions should become visible after a track is selected **"); |
| - |
| - // Note: the test flow continues with "testCCTrackSelectionFunctionality" when the |
| - // "load" event of the single TextTrack fires up. While the test structure |
| - // might seem weird, this avoids timeouts. |
| - selectTextTrack(video, 0); |
| - } |
| - |
| - function testCCTrackSelectionFunctionality() |
| - { |
| - checkCaptionsDisplay(); |
| - |
| - consoleWrite(""); |
| - consoleWrite("** Captions should not be visible after Off is clicked **"); |
| +<title>Tests that the closed captions button enables track switching.</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="media-file.js"></script> |
| +<script src="media-controls.js"></script> |
| +<video controls> |
| + <track src="track/captions-webvtt/captions-fast.vtt" kind="captions"> |
| +</video> |
| +<script> |
| +async_test(function(t) { |
| + var video = document.querySelector("video"); |
| + var track = document.querySelector("track"); |
|
fs
2016/07/04 08:46:55
We could move this into the relevant scope, right?
Srirama
2016/07/04 13:00:23
Done.
|
| + |
| + video.oncanplaythrough = t.step_func(function() { |
| + assert_true(isClosedCaptionsButtonVisible(video)); |
| + |
| + // The captions track should be listed in textTracks, but not yet loaded. |
| + assert_equals(video.textTracks.length, 1); |
| + assert_equals(video.textTracks[0].mode, "disabled"); |
| + assert_throws(null, function() { |
|
Srirama
2016/07/04 07:56:56
This is for "text track container" error and the o
fs
2016/07/04 08:46:55
I think the easiest way forward is just to add an
foolip
2016/07/04 08:49:31
It's not always clear what checkCaptionsDisplay is
Srirama
2016/07/04 13:00:23
Attempted the first approach. The helpers are a bi
|
| + textTrackDisplayElement(video, "display"); |
| + }); |
| + |
| + track.onload = t.step_func(function() { |
| + assert_equals(textTrackDisplayElement(video, "display").innerText, "Lorem"); |
| + |
| + // Captions should not be visible after Off is clicked. |
| turnClosedCaptionsOff(video); |
| - checkCaptionsDisplay(); |
| + assert_throws(null, function() { |
| + textTrackDisplayElement(video, "display"); |
| + }); |
| - removeHTMLTrackElement(); |
| - testClosedCaptionsButtonVisibility(false); |
| + // Remove DOM node representing the track element. |
| + video.removeChild(track); |
|
foolip
2016/07/04 08:49:32
Just track.remove() works too.
Srirama
2016/07/04 13:00:23
Done.
|
| + assert_false(isClosedCaptionsButtonVisible(video)); |
| addUnloadableHTMLTrackElement(); |
| - testClosedCaptionsButtonVisibility(true); |
| - |
| - consoleWrite(""); |
| - selectTextTrack(video, 0); |
| - } |
| - |
| - function trackError() |
| - { |
| - consoleWrite("** Track failed to load **"); |
| - testClosedCaptionsButtonVisibility(false); |
| - |
| - addTextTrackThroughJS(); |
| - testClosedCaptionsButtonVisibility(true); |
| - |
| - endTest(); |
| - } |
| - |
| - function loaded() |
| - { |
| - findMediaElement(); |
| - waitForEvent('canplaythrough', startTest); |
| - |
| - video.src = findMediaFile('video', 'content/counting'); |
| - } |
| - </script> |
| -</head> |
| -<body onload="loaded()"> |
| - <p>Tests that the closed captions button enables track switching</p> |
| - <video controls> |
| - <track src="track/captions-webvtt/captions-fast.vtt" kind="captions" onload="testCCTrackSelectionFunctionality()"> |
| - </video> |
| -</body> |
| -</html> |
| + assert_true(isClosedCaptionsButtonVisible(video)); |
| + |
| + selectTextTrackAtIndex(video, 0); |
|
foolip
2016/07/04 08:49:31
Since you're renaming it anyway, I think clickText
Srirama
2016/07/04 13:00:23
Done.
|
| + }); |
| + |
| + // Captions track should load and captions should become visible after a track is selected. |
| + selectTextTrackAtIndex(video, 0); |
| + }); |
| + |
| + function addUnloadableHTMLTrackElement() { |
| + // Add non-default text track through HTML with unloadable URI. |
| + track = document.createElement("track"); |
|
fs
2016/07/04 08:46:55
Make 'track' local (per above.)
Srirama
2016/07/04 13:00:23
Done.
|
| + track.setAttribute("kind", "captions"); |
| + track.setAttribute("srclang", "en"); |
| + track.setAttribute("src", "invalid.vtt"); |
| + |
| + track.onerror = t.step_func_done(function() { |
| + // Track failed to load. |
| + assert_false(isClosedCaptionsButtonVisible(video)); |
| + // Add a text track through JS to the video element. |
| + var newTrack = video.addTextTrack("captions", "English", "en"); |
| + newTrack.addCue(new VTTCue(0, 10, "Some random caption text")); |
|
foolip
2016/07/04 08:49:31
Is this line really needed for the test to pass? T
Srirama
2016/07/04 13:00:23
Done.
|
| + assert_true(isClosedCaptionsButtonVisible(video)); |
| + }); |
| + |
| + video.appendChild(track); |
| + assert_equals(track.readyState, HTMLTrackElement.NONE); |
| + assert_equals(track.track.mode, "disabled"); |
| + assert_equals(video.textTracks.length, 1); |
| + } |
| + |
| + video.src = findMediaFile("video", "content/counting"); |
| +}); |
| +</script> |