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

Side by Side Diff: chrome/test/data/webui/media_router/route_controls_tests.js

Issue 2725503002: [Media Router] Custom Controls 4 - Implement details view WebUI (Closed)
Patch Set: Address Mark's comments Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /** @fileoverview Suite of tests for route-controls. */
6 cr.define('route_controls', function() {
7 function registerTests() {
8 suite('RouteControls', function() {
9 /**
10 * Route Controls created before each test.
11 * @type {RouteControls}
12 */
13 var controls;
14
15 /**
16 * First fake route created before each test.
17 * @type {media_router.Route}
18 */
19 var fakeRouteOne;
20
21 /**
22 * Second fake route created before each test.
23 * @type {media_router.Route}
24 */
25 var fakeRouteTwo;
26
27 var assertElementText = function(expected, elementId) {
28 assertEquals(expected,
29 controls.$[elementId].innerText);
30 };
31
32 var isElementShown = function(elementId) {
33 return !controls.$[elementId].hasAttribute('hidden');
34 };
35
36 var assertElementShown = function(elementId) {
37 assertTrue(isElementShown(elementId));
38 };
39
40 var assertElementHidden = function(elementId) {
41 assertFalse(isElementShown(elementId));
42 };
43
44 // Creates an instance of RouteStatus with the given parameters. If a
45 // parameter is not set, it defaults to an empty string, zero, or false.
46 var createRouteStatus = function(params = {}) {
47 return new media_router.RouteStatus(
48 params.title ? params.title : "",
49 params.status ? params.status : "",
50 !!params.canPlayPause,
51 !!params.canMute,
52 !!params.canSetVolume,
53 !!params.canSeek,
54 !!params.isPaused,
55 !!params.isMuted,
56 params.volume ? params.volume : 0,
57 params.duration ? params.duration : 0,
58 params.currentTime ? params.currentTime : 0
59 );
60 };
61
62 // Import route_controls.html before running suite.
63 suiteSetup(function() {
64 return PolymerTest.importHtml(
65 'chrome://media-router/elements/route_controls/' +
66 'route_controls.html');
67 });
68
69 // Initialize a route-controls before each test.
70 setup(function(done) {
71 PolymerTest.clearBody();
72 controls = document.createElement('route-controls');
73 document.body.appendChild(controls);
74
75 // Initialize routes and sinks.
76 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1',
77 'Video 1', 1, true, false);
78 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2',
79 'Video 2', 2, false, true);
80
81 // Allow for the route controls to be created and attached.
82 setTimeout(done);
83 });
84
85 // Tests the initial expected text.
86 test('initial text setting', function() {
87 // Set |route|.
88 controls.onRouteUpdated(fakeRouteOne);
89 assertElementText(loadTimeData.getStringF('castingActivityStatus',
90 fakeRouteOne.description), 'route-description');
91
92 // Set |route| to a different route.
93 controls.onRouteUpdated(fakeRouteTwo);
94 assertElementText(loadTimeData.getStringF('castingActivityStatus',
95 fakeRouteTwo.description), 'route-description');
96 });
97
98 // Tests that the route title and status are shown when RouteStatus is
99 // updated.
100 test('update route text', function() {
101 var title = "test title";
102 var status = "test status";
103 controls.routeStatus = createRouteStatus({
104 title: title,
105 status: status
106 });
107
108 assertElementText(title, 'route-title');
109 assertElementText(status, 'route-description');
110 });
111
112 // Tests that media controls are shown and hidden when RouteStatus is
113 // updated.
114 test('media controls visibility', function() {
115 // Create a RouteStatus with no controls.
116 controls.routeStatus = createRouteStatus();
117 assertElementHidden('route-play-pause-button');
118 assertElementHidden('route-time-controls');
119 assertElementHidden('route-volume-button');
120 assertElementHidden('route-volume-slider');
121
122 controls.routeStatus = createRouteStatus({
123 canPlayPause: true,
124 canSeek: true
125 });
126
127 assertElementShown('route-play-pause-button');
128 assertElementShown('route-time-controls');
129 assertElementHidden('route-volume-button');
130 assertElementHidden('route-volume-slider');
131
132 controls.routeStatus = createRouteStatus({
133 canMute: true,
134 canSetVolume: true
135 });
136
137 assertElementHidden('route-play-pause-button');
138 assertElementHidden('route-time-controls');
139 assertElementShown('route-volume-button');
140 assertElementShown('route-volume-slider');
141 });
142
143 // Tests that the play button sends a command to the browser API.
144 test('send play command', function(done) {
145 document.addEventListener('mock-play-current-media', function(data) {
146 done();
147 });
148
149 controls.routeStatus = createRouteStatus({
150 canPlayPause: true,
151 isPaused: true
152 });
153 MockInteractions.tap(controls.$['route-play-pause-button']);
154 });
155
156 // Tests that the pause button sends a command to the browser API.
157 test('send pause command', function(done) {
158 document.addEventListener('mock-pause-current-media', function(data) {
159 done();
160 });
161
162 controls.routeStatus = createRouteStatus({
163 canPlayPause: true,
164 isPaused: false
165 });
166 MockInteractions.tap(controls.$['route-play-pause-button']);
167 });
168
169 // Tests that the mute button sends a command to the browser API.
170 test('send mute command', function(done) {
171 function waitForMuteEvent(data) {
172 // Remove the event listener to avoid interfering with other tests.
173 document.removeEventListener('mock-set-current-media-mute',
174 waitForMuteEvent);
175 if (data.detail.mute) {
176 done();
177 } else {
178 done('Expected the "Mute" command but received "Unmute".');
179 }
180 }
181 document.addEventListener('mock-set-current-media-mute',
182 waitForMuteEvent);
183
184 controls.routeStatus = createRouteStatus({
185 canMute: true,
186 isMuted: false
187 });
188 MockInteractions.tap(controls.$['route-volume-button']);
189 });
190
191 // Tests that the unmute button sends a command to the browser API.
192 test('send unmute command', function(done) {
193 function waitForUnuteEvent(data) {
mark a. foltz 2017/05/15 20:43:22 Typo
takumif 2017/05/18 18:01:56 Oh no. Thanks for noticing!
194 // Remove the event listener to avoid interfering with other tests.
195 document.removeEventListener('mock-set-current-media-mute',
196 waitForUnuteEvent);
197 if (data.detail.mute) {
198 done('Expected the "Unmute" command but received "Mute".');
199 } else {
200 done();
201 }
202 }
203 document.addEventListener('mock-set-current-media-mute',
204 waitForUnuteEvent);
205
206 controls.routeStatus = createRouteStatus({
207 canMute: true,
208 isMuted: true
209 });
210 MockInteractions.tap(controls.$['route-volume-button']);
211 });
212
213 // // Tests that the seek slider sends a command to the browser API.
214 test('send seek command', function(done) {
215 var currentTime = 500;
216 var duration = 1200;
217 document.addEventListener('mock-seek-current-media', function(data) {
218 if (data.detail.time == currentTime) {
219 done();
220 } else {
221 done('Expected the time to be ' + currentTime +
222 ' but instead got ' + data.detail.time);
223 }
224 });
225
226 controls.routeStatus = createRouteStatus({
227 canSeek: true,
228 duration: duration
229 });
230
231 // In actual usage, the change event gets fired when the user interacts
232 // with the slider.
233 controls.$['route-time-slider'].value = currentTime;
234 controls.$['route-time-slider'].fire('change');
235 });
236
237 // Tests that the volume slider sends a command to the browser API.
238 test('send set volume command', function(done) {
239 var volume = 0.45;
240 document.addEventListener(
241 'mock-set-current-media-volume', function(data) {
242 if (data.detail.volume == volume) {
243 done();
244 } else {
245 done('Expected the volume to be ' + volume + ' but instead got ' +
246 data.detail.volume);
247 }
248 });
249
250 controls.routeStatus = createRouteStatus({canSetVolume: true});
251
252 // In actual usage, the change event gets fired when the user interacts
253 // with the slider.
254 controls.$['route-volume-slider'].value = volume;
255 controls.$['route-volume-slider'].fire('change');
256 });
257 });
258 }
259
260 return {
261 registerTests: registerTests,
262 };
263 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698