OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests that the "kind" attribute is set properly and that cues are only vi sible when "kind" is set to "captions" or "subtitles".</title> |
3 <head> | 3 <video> |
4 <track src="captions-webvtt/metadata.vtt" default> | |
5 </video> | |
6 <script src="../media-file.js"></script> | |
7 <script src="../media-controls.js"></script> | |
8 <script src="../../resources/testharness.js"></script> | |
9 <script src="../../resources/testharnessreport.js"></script> | |
10 <script> | |
11 async_test(function(t) { | |
12 var video = document.querySelector("video"); | |
13 var trackElement = document.querySelector("track"); | |
4 | 14 |
5 <script src=../media-file.js></script> | 15 video.oncanplaythrough = t.step_func(testKind); |
6 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 | 16 trackElement.onload = t.step_func(testKind); |
7 (Please avoid writing new tests using video-test.js) --> | 17 |
8 <script src=../video-test.js></script> | 18 video.src = findMediaFile("video", "../content/counting"); |
9 <script src=../media-controls.js></script> | |
10 <script> | |
11 | 19 |
12 var trackElement; | 20 var eventCount = 0; |
13 function setKind(value) | 21 function testKind() { |
14 { | 22 eventCount++; |
15 consoleWrite("<b>++ '" + value + "'</b>"); | 23 if (eventCount != 2) |
16 consoleWrite("<b> set via DOM</b>"); | 24 return; |
17 run("trackElement.removeAttribute('kind')"); | |
18 run("trackElement.kind = '" + value + "'"); | |
19 testExpected("trackElement.getAttribute('kind')", value); | |
20 testExpected("trackElement.kind", value); | |
21 testExpected("trackElement.track.kind", value); | |
22 consoleWrite("<b> and via attribute</b>"); | |
23 run("trackElement.removeAttribute('kind')"); | |
24 run("trackElement.setAttribute('kind', '" + value + "')"); | |
25 testExpected("trackElement.kind", value); | |
26 testExpected("trackElement.track.kind", value); | |
27 testExpected("trackElement.getAttribute('kind')", value); | |
28 testExpected("textTrackDisplayElement(video, 'display').innerTex t", "Lorem ipsum dolor sit amet, "); | |
29 consoleWrite(""); | |
30 | 25 |
31 } | 26 // Test default attribute value. |
27 assert_equals(trackElement.getAttribute("kind"), null); | |
28 assert_equals(trackElement.kind, "subtitles"); | |
29 assert_equals(video.textTracks[0].kind, "subtitles"); | |
32 | 30 |
33 function testKind() | 31 // Set to bogus value, should return default. |
34 { | 32 |
35 consoleWrite("<b>++ Test default attribute value</b>"); | 33 // Set via DOM. |
36 testExpected("trackElement.getAttribute('kind')", null); | 34 var value = "english-metadata" |
37 testExpected("trackElement.kind", "subtitles"); | 35 trackElement.removeAttribute("kind"); |
38 testExpected("video.textTracks[0].kind", "subtitles"); | 36 trackElement.kind = value; |
39 consoleWrite(""); | 37 assert_equals(trackElement.getAttribute("kind"), value); |
38 assert_equals(trackElement.kind, "subtitles"); | |
39 assert_equals(trackElement.track.kind, "subtitles"); | |
40 | |
41 // Set via attribute. | |
42 trackElement.removeAttribute("kind"); | |
43 trackElement.setAttribute("kind", value); | |
44 assert_equals(trackElement.kind, "subtitles"); | |
45 assert_equals(trackElement.track.kind, "subtitles"); | |
46 assert_equals(trackElement.getAttribute("kind"), value); | |
40 | 47 |
41 consoleWrite("<b>*** Set to bogus value, should return default</ b>"); | 48 // Set to known values. |
42 consoleWrite("<b> set via DOM</b>"); | 49 setKind("subtitles", true); |
43 var value = "english-metadata" | |
44 run("trackElement.removeAttribute('kind')"); | |
45 run("trackElement.kind = '" + value + "'"); | |
46 testExpected("trackElement.getAttribute('kind')", value); | |
47 testExpected("trackElement.kind", "subtitles"); | |
48 testExpected("trackElement.track.kind", "subtitles"); | |
49 consoleWrite("<b> and via attribute</b>"); | |
50 run("trackElement.removeAttribute('kind')"); | |
51 run("trackElement.setAttribute('kind', '" + value + "')"); | |
52 testExpected("trackElement.kind", "subtitles"); | |
53 testExpected("trackElement.track.kind", "subtitles"); | |
54 testExpected("trackElement.getAttribute('kind')", value); | |
55 consoleWrite(""); | |
56 | 50 |
57 consoleWrite("<b>*** Set to known values</b>"); | 51 setKind("captions", true); |
58 setKind("subtitles"); | |
59 | 52 |
60 setKind("captions"); | 53 setKind("descriptions", false); |
61 | 54 |
62 setKind("descriptions"); | 55 setKind("chapters", false); |
63 | 56 |
64 setKind("chapters"); | 57 setKind("metadata", false); |
65 | 58 |
66 setKind("metadata"); | 59 t.done(); |
60 } | |
67 | 61 |
68 endTest(); | 62 function setKind(value, cueIsVisible) { |
mlamouri (slow - plz ping)
2016/05/04 13:59:58
Can you call thisk "setKindAndCheck()"
| |
69 } | 63 // set via DOM. |
64 trackElement.removeAttribute("kind"); | |
65 trackElement.kind = value; | |
66 assert_equals(trackElement.getAttribute("kind"), value); | |
67 assert_equals(trackElement.kind, value); | |
68 assert_equals(trackElement.track.kind, value); | |
69 // Set via attribute. | |
70 trackElement.removeAttribute("kind"); | |
71 trackElement.setAttribute("kind", value); | |
72 assert_equals(trackElement.kind, value); | |
73 assert_equals(trackElement.track.kind, value); | |
74 assert_equals(trackElement.getAttribute("kind"), value); | |
70 | 75 |
71 function loaded() | 76 if (cueIsVisible) { |
72 { | 77 assert_equals(textTrackDisplayElement(video, "display").innerText, " Lorem ipsum dolor sit amet, "); |
73 findMediaElement(); | 78 } else { |
74 trackElement = document.getElementById('track_1'); | 79 assert_throws(null, function() { |
75 | 80 textTrackDisplayElement(video, "display"); |
76 waitForEventsAndCall([[video, 'canplaythrough'], [trackElement, 'load']], testKind); | 81 }); |
77 | 82 } |
78 video.src = findMediaFile('video', '../content/counting'); | 83 } |
79 } | 84 }); |
80 | 85 </script> |
81 </script> | |
82 </head> | |
83 <body onload="loaded()"> | |
84 <p>Tests that the 'kind' attribute is set properly and that cues are onl y visible when 'kind' is set to 'captions' or 'subtitles'.</p> | |
85 <video> | |
86 <track id=track_1 src="captions-webvtt/metadata.vtt" default> | |
87 </video> | |
88 </body> | |
89 </html> | |
OLD | NEW |