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

Unified Diff: third_party/WebKit/LayoutTests/media/video-controls-captions.html

Issue 2121613002: Convert video-controls-[captions, overlay, track]* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nit 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-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..aea44b909edaa7e03608e7acb4e117a89b9c1ecd 100644
--- a/third_party/WebKit/LayoutTests/media/video-controls-captions.html
+++ b/third_party/WebKit/LayoutTests/media/video-controls-captions.html
@@ -1,126 +1,67 @@
<!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");
+
+ 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_equals(textTrackContainerElement(video), null);
+
+ var track = document.querySelector("track");
+ track.onload = t.step_func(function() {
+ assert_equals(textTrackCueElementByIndex(video, 0).innerText, "Lorem");
+
+ // Captions should not be visible after Off is clicked.
turnClosedCaptionsOff(video);
- checkCaptionsDisplay();
+ assert_equals(textTrackCueDisplayElement(video), null);
- removeHTMLTrackElement();
- testClosedCaptionsButtonVisibility(false);
+ // Remove DOM node representing the track element.
+ track.remove();
+ 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));
+
+ clickTextTrackAtIndex(video, 0);
+ });
+
+ // Captions track should load and captions should become visible after a track is selected.
+ clickTextTrackAtIndex(video, 0);
+ });
+
+ function addUnloadableHTMLTrackElement() {
+ // Add non-default text track through HTML with unloadable URI.
+ var track = document.createElement("track");
+ 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");
+ 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>

Powered by Google App Engine
This is Rietveld 408576698