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

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 Derek's comments, don't load extensionview unnecessarily 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 checkText = function(expected, elementId) {
mark a. foltz 2017/05/12 21:07:34 assertElementText ?
takumif 2017/05/15 17:13:13 Done.
28 assertEquals(expected,
29 controls.$[elementId].innerText);
30 };
31
32 var isElementShown = function(elementId) {
33 return !controls.$[elementId].hasAttribute('hidden');
34 }
35
36 // Creates an instance of RouteStatus with the given parameters. If a
37 // parameter is not set, it defaults to an empty string, zero, or false.
38 var createRouteStatus = function(params = {}) {
39 return new media_router.RouteStatus(
40 params.title ? params.title : "",
41 params.status ? params.status : "",
42 !!params.canPlayPause,
43 !!params.canMute,
44 !!params.canSetVolume,
45 !!params.canSeek,
46 !!params.isPaused,
47 !!params.isMuted,
48 params.volume ? params.volume : 0,
49 params.duration ? params.duration : 0,
50 params.currentTime ? params.currentTime : 0
51 );
52 }
53
54 // Mock the browser API.
55 var overrideBrowserApi = function() {
56 cr.define('media_router.browserApi', function() {
57 'use strict';
58
59 function pauseCurrentMedia() {
60 controls.fire('mock-pause-current-media');
61 }
62
63 function playCurrentMedia() {
64 controls.fire('mock-play-current-media');
65 }
66
67 function seekCurrentMedia(time) {
68 controls.fire('mock-seek-current-media', {time: time});
69 }
70
71 function setCurrentMediaMute(mute) {
72 controls.fire('mock-set-current-media-mute', {mute: mute});
73 }
74
75 function setCurrentMediaVolume(volume) {
76 controls.fire('mock-set-current-media-volume', {volume: volume});
77 }
78
79 return {
80 pauseCurrentMedia: pauseCurrentMedia,
81 playCurrentMedia: playCurrentMedia,
82 seekCurrentMedia: seekCurrentMedia,
83 setCurrentMediaMute: setCurrentMediaMute,
84 setCurrentMediaVolume: setCurrentMediaVolume,
85 };
86 });
87 }
88
89 // Import route_controls.html before running suite.
90 suiteSetup(function() {
91 return PolymerTest.importHtml(
92 'chrome://media-router/elements/route_controls/' +
93 'route_controls.html');
94 });
95
96 // Initialize a route-controls before each test.
97 setup(function(done) {
98 PolymerTest.clearBody();
99 controls = document.createElement('route-controls');
100 document.body.appendChild(controls);
101 overrideBrowserApi();
102
103 // Initialize routes and sinks.
104 fakeRouteOne = new media_router.Route('route id 1', 'sink id 1',
105 'Video 1', 1, true, false,
106 'chrome-extension://123/custom_view.html');
mark a. foltz 2017/05/12 21:07:35 Nit: It doesn't look like there's any test coverag
takumif 2017/05/15 17:13:13 Done.
107 fakeRouteTwo = new media_router.Route('route id 2', 'sink id 2',
108 'Video 2', 2, false, true);
109
110 // Allow for the route controls to be created and attached.
111 setTimeout(done);
112 });
113
114 // Tests the initial expected text.
115 test('initial text setting', function() {
116 // Set |route|.
117 controls.onRouteUpdated(fakeRouteOne);
118 checkText(loadTimeData.getStringF('castingActivityStatus',
119 fakeRouteOne.description), 'route-description');
120
121 // Set |route| to a different route.
122 controls.onRouteUpdated(fakeRouteTwo);
123 checkText(loadTimeData.getStringF('castingActivityStatus',
124 fakeRouteTwo.description), 'route-description');
125 });
126
127 // Tests that the route title and status are shown when RouteStatus is
128 // updated.
129 test('update route text', function() {
130 var title = "test title";
131 var status = "test status";
132 controls.routeStatus = createRouteStatus({
133 title: title,
134 status: status
135 });
136
137 checkText(title, 'route-title');
138 checkText(status, 'route-description');
139 });
140
141 // Tests that media controls are shown and hidden when RouteStatus is
142 // updated.
143 test('media controls visibility', function() {
144 // Create a RouteStatus with no controls.
145 controls.routeStatus = createRouteStatus();
146 assertFalse(isElementShown('route-play-pause-button'));
mark a. foltz 2017/05/12 21:07:34 Nit: You could have assertElementShown() and asser
takumif 2017/05/15 17:13:13 Done.
147 assertFalse(isElementShown('route-time-controls'));
148 assertFalse(isElementShown('route-volume-button'));
149 assertFalse(isElementShown('route-volume-slider'));
150
151 controls.routeStatus = createRouteStatus({
152 canPlayPause: true,
153 canSeek: true
154 });
155
156 assertTrue(isElementShown('route-play-pause-button'));
157 assertTrue(isElementShown('route-time-controls'));
158 assertFalse(isElementShown('route-volume-button'));
159 assertFalse(isElementShown('route-volume-slider'));
160
161 controls.routeStatus = createRouteStatus({
162 canMute: true,
163 canSetVolume: true
164 });
165
166 assertFalse(isElementShown('route-play-pause-button'));
167 assertFalse(isElementShown('route-time-controls'));
168 assertTrue(isElementShown('route-volume-button'));
169 assertTrue(isElementShown('route-volume-slider'));
170 });
171
172 // Tests that the play button sends a command to the browser API.
173 test('send play command', function(done) {
174 controls.addEventListener('mock-play-current-media', function(data) {
175 done();
176 });
177
178 controls.routeStatus = createRouteStatus({
179 canPlayPause: true,
180 isPaused: true
181 });
182 MockInteractions.tap(controls.$['route-play-pause-button']);
183 });
184
185 // Tests that the pause button sends a command to the browser API.
186 test('send pause command', function(done) {
187 controls.addEventListener('mock-pause-current-media', function(data) {
188 done();
189 });
190
191 controls.routeStatus = createRouteStatus({
192 canPlayPause: true,
193 isPaused: false
194 });
195 MockInteractions.tap(controls.$['route-play-pause-button']);
196 });
197
198 // Tests that the mute button sends a command to the browser API.
199 test('send mute command', function(done) {
200 controls.addEventListener(
201 'mock-set-current-media-mute', function(data) {
202 if (data.detail.mute) {
203 done();
204 } else {
205 done('Expected the "Mute" command but received "Unmute".');
206 }
207 });
208
209 controls.routeStatus = createRouteStatus({
210 canMute: true,
211 isMuted: false
212 });
213 MockInteractions.tap(controls.$['route-volume-button']);
214 });
215
216 // Tests that the unmute button sends a command to the browser API.
217 test('send unmute command', function(done) {
218 controls.addEventListener(
219 'mock-set-current-media-mute', function(data) {
220 if (data.detail.mute) {
221 done('Expected the "Unmute" command but received "Mute".');
222 } else {
223 done();
224 }
225 });
226
227 controls.routeStatus = createRouteStatus({
228 canMute: true,
229 isMuted: true
230 });
231 MockInteractions.tap(controls.$['route-volume-button']);
232 });
233
234 // // Tests that the seek slider sends a command to the browser API.
235 test('send seek command', function(done) {
236 var currentTime = 500;
237 var duration = 1200;
238 controls.addEventListener('mock-seek-current-media', function(data) {
239 if (data.detail.time == currentTime) {
240 done();
241 } else {
242 done('Expected the time to be ' + currentTime +
243 ' but instead got ' + data.detail.time);
244 }
245 });
246
247 controls.routeStatus = createRouteStatus({
248 canSeek: true,
249 duration: duration
250 });
251
252 // In actual usage, the change event gets fired when the user interacts
253 // with the slider.
254 controls.$['route-time-slider'].value = currentTime;
255 controls.$['route-time-slider'].fire('change');
256 });
257
258 // Tests that the volume slider sends a command to the browser API.
259 test('send set volume command', function(done) {
260 var volume = 0.45;
261 controls.addEventListener(
262 'mock-set-current-media-volume', function(data) {
263 if (data.detail.volume == volume) {
264 done();
265 } else {
266 done('Expected the volume to be ' + volume + ' but instead got ' +
267 data.detail.volume);
268 }
269 });
270
271 controls.routeStatus = createRouteStatus({canSetVolume: true});
272
273 // In actual usage, the change event gets fired when the user interacts
274 // with the slider.
275 controls.$['route-volume-slider'].value = volume;
276 controls.$['route-volume-slider'].fire('change');
277 });
278 });
279 }
280
281 return {
282 registerTests: registerTests,
283 };
284 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698