blob: 7c79410810afd7b2e0eb59b022f86c5412bd08e3 [file] [log] [blame]
dino@apple.comacaceda2012-11-27 23:45:13 +00001<!DOCTYPE html>
2<html>
3 <head>
4 <title>Selecting from a list of tracks</title>
5 <script src="media-controls.js"></script>
6 <script src="media-file.js"></script>
7 <script src="video-test.js"></script>
dino@apple.comde30ce22012-12-20 20:11:11 +00008 <script src="trackmenu-test.js"></script>
dino@apple.comacaceda2012-11-27 23:45:13 +00009 <script>
dino@apple.comacaceda2012-11-27 23:45:13 +000010 if (window.testRunner)
11 testRunner.dumpAsText();
12
dino@apple.comacaceda2012-11-27 23:45:13 +000013 function startTest()
14 {
calvaris@igalia.com53ca5472014-02-26 09:41:43 +000015 trackListElement = getTrackListElement();
16 if (!trackListElement)
17 return;
18 testExpected("trackListElement.offsetHeight", 0, ">");
19
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000020 consoleWrite("<br>*** Add another text track.");
21 run('video.addTextTrack("captions", "Commentary", "ru")');
jer.noble@apple.com7f2f1162013-08-01 20:34:20 +000022 showTrackMenu()
dino@apple.comde30ce22012-12-20 20:11:11 +000023 window.setTimeout(turnCaptionsOn, 100);
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000024 consoleWrite("");
dino@apple.comacaceda2012-11-27 23:45:13 +000025 }
26
jer.noble@apple.com7ebbbe32014-10-08 20:04:33 +000027 function captionTrackMenuList()
dino@apple.comacaceda2012-11-27 23:45:13 +000028 {
dino@apple.comde30ce22012-12-20 20:11:11 +000029 var trackListElement = getTrackListElement();
30 if (!trackListElement)
dino@apple.comacaceda2012-11-27 23:45:13 +000031 return;
dino@apple.com53a29d42013-02-05 08:03:22 +000032 // Track list should have a <ul> with <li> children (One of them is "Off").
dino@apple.comacaceda2012-11-27 23:45:13 +000033 var trackList = trackListElement.querySelector("ul");
34 if (!trackList) {
35 failTest("Could not find a child ul element in track list menu");
36 return;
37 }
dino@apple.comacaceda2012-11-27 23:45:13 +000038 var trackListItems = trackList.querySelectorAll("li");
39 if (!trackListItems) {
dino@apple.comde30ce22012-12-20 20:11:11 +000040 failTest("Could not find child li elements in track list menu");
dino@apple.comacaceda2012-11-27 23:45:13 +000041 return;
42 }
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000043
44 return trackListItems;
45 }
46
47 function testMenu()
48 {
jer.noble@apple.com7ebbbe32014-10-08 20:04:33 +000049 trackListItems = captionTrackMenuList();
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000050 var expectedItemCount = video.textTracks.length + 2;
dino@apple.comde30ce22012-12-20 20:11:11 +000051 consoleWrite("There should be " + expectedItemCount + " items in the menu.");
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +000052 testExpected("trackListItems.length", expectedItemCount);
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000053 }
54
55 function selectCaptionMenuItem(index, nextStep)
56 {
dino@apple.comacaceda2012-11-27 23:45:13 +000057 // Click on the selected item
jer.noble@apple.com7ebbbe32014-10-08 20:04:33 +000058 var trackListItems = captionTrackMenuList();
dino@apple.comacaceda2012-11-27 23:45:13 +000059 var selectedTrackItem = trackListItems[index];
60 var boundingRect = selectedTrackItem.getBoundingClientRect();
61 var x = boundingRect.left + boundingRect.width / 2;
62 var y = boundingRect.top + boundingRect.height / 2;
63 eventSender.mouseMoveTo(x, y);
64 eventSender.mouseDown();
65 eventSender.mouseUp();
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000066 window.setTimeout(function() { testMenu(); nextStep(); }, 100);
dino@apple.comacaceda2012-11-27 23:45:13 +000067 }
68
69 function turnCaptionsOn()
70 {
71 consoleWrite("*** Turning captions on");
eric.carlson@apple.com44f8c682013-04-04 22:23:47 +000072 // Click on the third item, which is the second track (Off is the first item, Automatic is second)
73 selectCaptionMenuItem(3, testCaptionsVisible);
dino@apple.comacaceda2012-11-27 23:45:13 +000074 }
75
76 function testCaptionsVisible()
77 {
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000078 testExpected("video.textTracks.length", 4);
eric.carlson@apple.com2519a002012-12-20 05:30:25 +000079 consoleWrite("Track 0 should be showing");
dino@apple.com53a29d42013-02-05 08:03:22 +000080 testExpected("video.textTracks[0].mode", "showing");
eric.carlson@apple.com2519a002012-12-20 05:30:25 +000081 consoleWrite("Track 1 should be disabled");
dino@apple.com53a29d42013-02-05 08:03:22 +000082 testExpected("video.textTracks[1].mode", "disabled");
dino@apple.comacaceda2012-11-27 23:45:13 +000083 consoleWrite("Track 2 should be disabled");
84 testExpected("video.textTracks[2].mode", "disabled");
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000085 consoleWrite("Track 3 should be disabled");
86 testExpected("video.textTracks[3].mode", "disabled");
dino@apple.comacaceda2012-11-27 23:45:13 +000087 testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000088
89 consoleWrite("<br>*** Remove a track.");
90 run('video.removeChild(document.querySelectorAll("track")[0])');
91
dino@apple.comacaceda2012-11-27 23:45:13 +000092 clickCCButton();
93 window.setTimeout(turnCaptionsOff, 100);
94 }
95
96 function turnCaptionsOff()
97 {
eric.carlson@apple.com24a0ac42012-12-07 21:30:12 +000098 consoleWrite("*** Turning captions off");
dino@apple.comacaceda2012-11-27 23:45:13 +000099 selectCaptionMenuItem(0, testCaptionsDisabled);
100 }
101
102 function testCaptionsDisabled()
103 {
104 testExpected("video.textTracks.length", 3);
105 consoleWrite("Track 0 should be disabled");
106 testExpected("video.textTracks[0].mode", "disabled");
107 consoleWrite("Track 1 should be disabled");
108 testExpected("video.textTracks[1].mode", "disabled");
109 consoleWrite("Track 2 should be disabled");
110 testExpected("video.textTracks[2].mode", "disabled");
111 testExpected("textTrackDisplayElement(video, 'display').innerText", "Lorem");
dino@apple.comacaceda2012-11-27 23:45:13 +0000112 endTest();
113 }
114
115 function start()
116 {
117 findMediaElement();
dino@apple.comde30ce22012-12-20 20:11:11 +0000118 video.src = findMediaFile('video', 'content/test');
119 waitForEvent('canplaythrough', function () { startTrackMenuTest(startTest); });
dino@apple.comacaceda2012-11-27 23:45:13 +0000120 }
121 </script>
122 </head>
123
124 <body onload="start()">
125 <p>Test that we are able to trigger the list of captions, and select from the list.</p>
126 <video width="500" height="300" controls>
eric.carlson@apple.com62bb7dc2013-03-20 20:13:36 +0000127 <track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="fr">
dino@apple.comacaceda2012-11-27 23:45:13 +0000128 <track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
dino@apple.comacaceda2012-11-27 23:45:13 +0000129 <track kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
130 </video>
131 </body>
132</html>
133