OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 media-router-container. */ | |
6 cr.define('media_router_container', function() { | |
7 function registerTests() { | |
8 suite('MediaRouterContainer', function() { | |
9 /** | |
10 * Media Router Container created before each test. | |
11 * @type {media_router_container} | |
12 */ | |
13 var container; | |
14 | |
15 /** | |
16 * The blocking issue to show. | |
17 * @type {?media_router.Issue} | |
18 */ | |
19 var fakeBlockingIssue; | |
20 | |
21 /** | |
22 * The list of CastModes to show. | |
23 * @type {!Array<!media_router.CastMode>} | |
24 */ | |
25 var fakeCastModeList; | |
michaelpg
2015/07/06 20:55:46
dbeam: technically this starts out as undefined. d
Dan Beam
2015/07/06 21:08:06
it'd be arguably better to start as
var fakeCas
apacible
2015/07/07 18:38:43
Updated to start as
var fakeCastModeList = [];
| |
26 | |
27 /** | |
28 * The blocking issue to show. | |
29 * @type {?media_router.Issue} | |
30 */ | |
31 var fakeNonBlockingIssue; | |
32 | |
33 /** | |
34 * The list of current routes. | |
35 * @type {!Array<!media_router.Route>} | |
36 */ | |
37 var fakeRouteList; | |
38 | |
39 /** | |
40 * The list of available sinks. | |
41 * @type {!Array<!media_router.Sink} | |
42 */ | |
43 var fakeSinkList; | |
44 | |
45 // Checks whether the current icon matches the icon used for the view. | |
46 var checkArrowDropIcon = function(view) { | |
47 assertEquals(container.$['arrow-drop-icon'].icon, | |
48 container.computeArrowDropIcon_(view)); | |
michaelpg
2015/07/06 20:55:46
You should also test the result of computeArrowDro
apacible
2015/07/07 18:38:43
Done.
| |
49 } | |
50 | |
51 // Checks whether |view| matches the current view of |container|. | |
52 var checkCurrentView = function(view) { | |
53 assertEquals(container.currentView_, view); | |
54 } | |
55 // Checks whether element |elementId| is hidden. |expected| is the | |
michaelpg
2015/07/06 20:55:46
nit: linebreak above
apacible
2015/07/07 18:38:43
Done.
| |
56 // expected visibility. | |
michaelpg
2015/07/06 20:55:46
|expected| is true if the item should be hidden, s
apacible
2015/07/07 18:38:43
Done.
| |
57 var checkElementHiddenWithId = function(expected, elementId) { | |
58 checkElementHidden(expected, container.$[elementId]); | |
59 }; | |
60 | |
61 // Checks whether |element| is hidden. |expected| is the expected | |
62 // visibility. | |
63 var checkElementHidden = function(expected, element) { | |
64 assertEquals(expected, element.hidden); | |
65 }; | |
66 | |
67 // Checks whether |expected| and the text in the |elementId| element | |
68 // are equal. | |
69 var checkElementText = function(expected, element) { | |
70 assertEquals(expected.trim(), element.textContent.trim()); | |
71 } | |
72 | |
73 // Checks whether |expected| and the text in the |elementId| element | |
74 // are equal given an id. | |
75 var checkElementTextWithId = function(expected, elementId) { | |
76 checkElementText(expected, container.$[elementId]); | |
77 }; | |
78 | |
79 // Import media_router_container.html before running suite. | |
80 suiteSetup(function() { | |
81 return PolymerTest.importHtml( | |
82 'chrome://media-router/elements/media_router_container/' + | |
83 'media_router_container.html'); | |
84 }); | |
85 | |
86 // Initialize an issue-banner before each test. | |
87 setup(function(done) { | |
88 PolymerTest.clearBody(); | |
89 container = document.createElement('media-router-container'); | |
90 document.body.appendChild(container); | |
91 | |
92 // Initialize local variables. | |
93 fakeCastModeList = [ | |
94 new media_router.CastMode(1, 'Cast Mode 1', 'Description 1'), | |
michaelpg
2015/07/06 20:55:46
nit: 2-space indent inside array/object literals
apacible
2015/07/07 18:38:43
Done.
| |
95 new media_router.CastMode(2, 'Cast Mode 2', 'Description 2'), | |
96 new media_router.CastMode(3, 'Cast Mode 3', 'Description 3'), | |
97 ]; | |
98 | |
99 fakeRouteList = [ | |
100 new media_router.Route('id 1', 'sink id 1', 'Title 1', true), | |
101 new media_router.Route('id 2', 'sink id 2', 'Title 2', false), | |
102 ]; | |
103 | |
104 fakeSinkList = [ | |
105 new media_router.Sink('sink id 1', 'Sink 1', | |
106 media_router.SinkStatus.ACTIVE, [1, 2, 3]), | |
107 new media_router.Sink('sink id 2', 'Sink 2', | |
108 media_router.SinkStatus.ACTIVE, [1, 2, 3]), | |
109 new media_router.Sink('sink id 3', 'Sink 3', | |
110 media_router.SinkStatus.PENDING, [1, 2, 3]), | |
111 ]; | |
112 | |
113 fakeBlockingIssue = new media_router.Issue( | |
114 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, | |
115 'route id 1', true, 1234); | |
116 | |
117 fakeNonBlockingIssue = new media_router.Issue( | |
118 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, | |
119 'route id 2', false, 1234); | |
120 | |
121 // Allow for the media router container to be created and attached. | |
122 setTimeout(done); | |
123 }); | |
124 | |
125 // Tests for 'close-button-click' event firing when the close button | |
126 // is clicked. | |
127 test('close button click', function(done) { | |
128 container.addEventListener('close-button-click', function() { | |
michaelpg
2015/07/06 20:55:46
We should add a PolymerTest.awaitEvent[s] method t
apacible
2015/07/07 18:38:43
Acknowledged.
| |
129 done(); | |
130 }); | |
131 MockInteractions.tap(container.$['close-button']); | |
132 }); | |
133 | |
134 // Tests for 'create-route' event firing when a sink with no associated | |
135 // route is clicked. | |
136 test('select sink without a route', function() { | |
137 container.sinkList = fakeSinkList; | |
138 | |
139 setTimeout(function() { | |
140 var sinkList = | |
141 container.$['sink-list'].querySelectorAll('paper-item'); | |
142 var sinkArray = Array.prototype.slice.call(sinkList); | |
michaelpg
2015/07/06 20:55:46
why slice this if you're not going to use Array me
apacible
2015/07/07 18:38:43
Fixed.
| |
143 | |
144 container.addEventListener('create-route', function(data) { | |
145 assertEquals(fakeSinkList[2].id, data.detail.sinkId); | |
146 assertEquals(container.selectedCastModeValue_, | |
147 data.detail.selectedCastModeValue); | |
michaelpg
2015/07/06 20:55:46
This is asynchronous, so include a `done` callback
apacible
2015/07/07 18:38:43
Done.
| |
148 }); | |
149 | |
150 // Tap on a sink without a route, which should fire a 'create-route' | |
151 // event. | |
152 MockInteractions.tap(sinkArray[2]); | |
153 }); | |
154 }); | |
155 | |
156 // Tests that selecting a sink with an associated route will make the | |
157 // |container| switch to ROUTE_DETAILS view. | |
158 test('select sink with a route', function() { | |
159 container.sinkList = fakeSinkList; | |
160 | |
161 setTimeout(function() { | |
michaelpg
2015/07/06 20:55:46
Same -- call done() at the end of this function, o
apacible
2015/07/07 18:38:43
Done.
| |
162 var sinkList = | |
163 container.$['sink-list'].querySelectorAll('paper-item'); | |
164 sinkArray = Array.prototype.slice.call(sinkList); | |
165 | |
166 checkCurrentView(container.containerView_.SINK_LIST); | |
167 MockInteractions.tap(sinkArray[0]); | |
168 checkCurrentView(container.containerView_.ROUTE_DETAILS); | |
169 }); | |
170 }); | |
171 | |
172 // Tests that |container| returns to SINK_LIST view and arrow drop icon | |
173 // toggles after a cast mode is selected. | |
174 test('select cast mode', function() { | |
175 container.castModeList = fakeCastModeList; | |
176 | |
177 MockInteractions.tap(container.$['arrow-drop-icon']); | |
178 checkArrowDropIcon(container.containerView_.CAST_MODE_LIST); | |
179 checkCurrentView(container.containerView_.CAST_MODE_LIST); | |
180 | |
181 setTimeout(function() { | |
182 var castModeList = | |
183 container.$['cast-mode-list'].querySelectorAll('paper-item'); | |
184 var castModeArray = Array.prototype.slice.call(castModeList); | |
185 | |
186 MockInteractions.tap(castModeArray[2]); | |
187 checkArrowDropIcon(container.containerView_.SINK_LIST); | |
188 checkCurrentView(container.containerView_.SINK_LIST); | |
189 }); | |
190 }); | |
191 | |
192 // Tests that clicking on the drop down icon will toggle |container| | |
193 // between SINK_LIST and CAST_MODE_LIST views. | |
194 test('click drop down icon', function() { | |
195 checkCurrentView(container.containerView_.SINK_LIST); | |
196 | |
197 MockInteractions.tap(container.$['arrow-drop-icon']); | |
198 checkArrowDropIcon(container.containerView_.CAST_MODE_LIST); | |
199 checkCurrentView(container.containerView_.CAST_MODE_LIST); | |
200 | |
201 MockInteractions.tap(container.$['arrow-drop-icon']); | |
202 checkArrowDropIcon(container.containerView_.SINK_LIST); | |
203 checkCurrentView(container.containerView_.SINK_LIST); | |
204 }); | |
205 | |
206 // Tests the header text. Choosing a cast mode updates the header text. | |
207 test('header text', function() { | |
208 checkElementTextWithId(loadTimeData.getString('selectCastModeHeader'), | |
209 'cast-mode-header-text'); | |
210 | |
211 var fakeHeaderText = 'fake header text'; | |
212 container.headerText = fakeHeaderText; | |
213 checkElementTextWithId(fakeHeaderText, 'sink-list-header-text'); | |
214 | |
215 // Set the cast mode list to update the header text when one is | |
216 // selected. | |
217 container.castModeList = fakeCastModeList; | |
218 | |
219 setTimeout(function() { | |
220 var castModeList = | |
221 container.$['cast-mode-list'].querySelectorAll('paper-item'); | |
222 var castModeArray = Array.prototype.slice.call(castModeList); | |
223 | |
224 for (var i = 0; i < fakeCastModeList.length; i++) { | |
225 MockInteractions.tap(castModeArray[i]); | |
226 checkElementTextWithId(fakeCastModeList[i].title, | |
227 'sink-list-header-text'); | |
228 } | |
229 }); | |
230 }); | |
231 | |
232 // Tests that text shown for each cast mode matches their descriptions. | |
233 test('cast mode list text', function() { | |
234 container.castModeList = fakeCastModeList; | |
235 | |
236 setTimeout(function() { | |
237 var castModeList = | |
238 container.$['cast-mode-list'].querySelectorAll('paper-item'); | |
239 var castModeArray = Array.prototype.slice.call(castModeList); | |
240 | |
241 for (var i = 0; i < fakeCastModeList.length; i++) { | |
242 checkElementText(fakeCastModeList[i].description, castModeArray[i]); | |
michaelpg
2015/07/06 20:55:46
can you combine this with the previous test?
apacible
2015/07/07 18:38:43
Done.
| |
243 } | |
244 }); | |
245 }); | |
246 | |
247 // Tests that text shown for each sink matches their names. | |
248 test('sink list text', function() { | |
249 container.sinkList = fakeSinkList; | |
250 | |
251 setTimeout(function() { | |
252 var sinkList = | |
253 container.$['sink-list'].querySelectorAll('paper-item'); | |
254 sinkArray = Array.prototype.slice.call(sinkList); | |
255 | |
256 for (var i = 0; i < fakeSinkList.length; i++) { | |
257 checkElementText(fakeSinkList[i].name, sinkArray[i]); | |
258 } | |
259 }); | |
260 }); | |
261 | |
262 test('sink list route text', function() { | |
263 container.sinkList = fakeSinkList; | |
264 container.routeList = fakeRouteList; | |
265 | |
266 setTimeout(function() { | |
267 var sinkList = | |
268 container.$['sink-list'].querySelectorAll('paper-item'); | |
269 sinkArray = Array.prototype.slice.call(sinkList); | |
270 | |
271 var routeList = | |
272 container.$['sink-list'].querySelectorAll('.route'); | |
273 routeArray = Array.prototype.slice.call(routeList); | |
274 | |
275 checkElementText(fakeRouteList[0].title, routeArray[0]); | |
276 checkElementText(fakeRouteList[1].title, routeArray[1]); | |
277 checkElementText('', routeArray[2]); | |
278 | |
279 container.addRoute( | |
280 new media_router.Route('id 3', 'sink id 3', 'Title 3', false)); | |
281 checkElementText(container.routeList[2].title, routeArray[3]); | |
282 | |
283 container.addRoute( | |
284 new media_router.Route('id 4', 'sink id 1', 'Title 4', false)); | |
285 checkElementText(container.routeList[0].title, routeArray[0]); | |
286 }); | |
287 }); | |
288 | |
289 // Tests for expected visible UI when the view is CAST_MODE_LIST. | |
290 test('cast mode list state visibility', function() { | |
291 container.showCastModeList_(); | |
292 checkElementHiddenWithId(false, 'container-header'); | |
michaelpg
2015/07/06 20:55:46
A thought: could you make a checkElementsHidden fu
apacible
2015/07/07 18:38:43
Done.
| |
293 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
294 checkElementHiddenWithId(false, 'cast-mode-header-text'); | |
295 checkElementHiddenWithId(true, 'issue-banner'); | |
296 checkElementHiddenWithId(false, 'cast-mode-list'); | |
297 checkElementHiddenWithId(true, 'route-details'); | |
298 checkElementHiddenWithId(true, 'sink-list'); | |
299 | |
300 // Set a non-blocking issue. The issue should stay hidden. | |
301 container.issue = fakeNonBlockingIssue; | |
302 checkElementHiddenWithId(false, 'container-header'); | |
303 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
304 checkElementHiddenWithId(false, 'cast-mode-header-text'); | |
305 checkElementHiddenWithId(true, 'issue-banner'); | |
306 checkElementHiddenWithId(false, 'cast-mode-list'); | |
307 checkElementHiddenWithId(true, 'route-details'); | |
308 checkElementHiddenWithId(true, 'sink-list'); | |
309 | |
310 // Set a blocking issue. The issue should stay hidden. | |
311 container.issue = fakeBlockingIssue; | |
312 checkElementHiddenWithId(false, 'container-header'); | |
313 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
314 checkElementHiddenWithId(false, 'cast-mode-header-text'); | |
315 checkElementHiddenWithId(true, 'issue-banner'); | |
316 checkElementHiddenWithId(false, 'cast-mode-list'); | |
317 checkElementHiddenWithId(true, 'route-details'); | |
318 checkElementHiddenWithId(true, 'sink-list'); | |
319 }); | |
320 | |
321 // Tests for expected visible UI when the view is ROUTE_DETAILS. | |
322 test('route details state visibility', function() { | |
323 container.showRouteDetails_(); | |
324 checkElementHiddenWithId(true, 'container-header'); | |
325 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
326 checkElementHiddenWithId(true, 'cast-mode-header-text'); | |
327 checkElementHiddenWithId(true, 'issue-banner'); | |
328 checkElementHiddenWithId(true, 'cast-mode-list'); | |
329 checkElementHiddenWithId(false, 'route-details'); | |
330 checkElementHiddenWithId(true, 'sink-list'); | |
331 | |
332 // Set a non-blocking issue. The issue should be shown. | |
333 container.issue = fakeNonBlockingIssue; | |
334 checkElementHiddenWithId(true, 'container-header'); | |
335 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
336 checkElementHiddenWithId(true, 'cast-mode-header-text'); | |
337 checkElementHiddenWithId(false, 'issue-banner'); | |
338 checkElementHiddenWithId(true, 'cast-mode-list'); | |
339 checkElementHiddenWithId(false, 'route-details'); | |
340 checkElementHiddenWithId(true, 'sink-list'); | |
341 | |
342 // Set a blocking issue. The issue should be shown, and everything | |
343 // else, hidden. | |
344 container.issue = fakeBlockingIssue; | |
345 checkElementHiddenWithId(true, 'container-header'); | |
346 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
347 checkElementHiddenWithId(true, 'cast-mode-header-text'); | |
348 checkElementHiddenWithId(false, 'issue-banner'); | |
349 checkElementHiddenWithId(true, 'cast-mode-list'); | |
350 checkElementHiddenWithId(true, 'route-details'); | |
351 checkElementHiddenWithId(true, 'sink-list'); | |
352 }); | |
353 | |
354 test('route visibility', function() { | |
355 container.sinkList = fakeSinkList; | |
356 container.routeList = fakeRouteList; | |
357 | |
358 setTimeout(function() { | |
359 var sinkList = | |
360 container.$['sink-list'].querySelectorAll('paper-item'); | |
361 sinkArray = Array.prototype.slice.call(sinkList); | |
362 | |
363 var routeList = | |
364 container.$['sink-list'].querySelectorAll('.route'); | |
365 routeArray = Array.prototype.slice.call(routeList); | |
366 | |
367 checkElementHidden(false, routeArray[0]); | |
368 checkElementHidden(false, routeArray[1]); | |
369 checkElementHidden(true, routeArray[2]); | |
370 | |
371 container.addRoute( | |
372 new media_router.Route('id 3', 'sink id 3', 'Title 3', false)); | |
373 checkElementHidden(false, routeArray[2]); | |
374 }); | |
375 }); | |
376 | |
377 // Tests for expected visible UI when the view is SINK_LIST. | |
378 test('sink list state visibility', function() { | |
379 container.showSinkList_(); | |
380 checkElementHiddenWithId(false, 'container-header'); | |
381 checkElementHiddenWithId(false, 'sink-list-header-text'); | |
382 checkElementHiddenWithId(true, 'cast-mode-header-text'); | |
383 checkElementHiddenWithId(true, 'issue-banner'); | |
384 checkElementHiddenWithId(true, 'cast-mode-list'); | |
385 checkElementHiddenWithId(true, 'route-details'); | |
386 checkElementHiddenWithId(false, 'sink-list'); | |
387 | |
388 // Set a non-blocking issue. The issue should be shown. | |
389 container.issue = fakeNonBlockingIssue; | |
390 checkElementHiddenWithId(false, 'container-header'); | |
391 checkElementHiddenWithId(false, 'sink-list-header-text'); | |
392 checkElementHiddenWithId(true, 'cast-mode-header-text'); | |
393 checkElementHiddenWithId(false, 'issue-banner'); | |
394 checkElementHiddenWithId(true, 'cast-mode-list'); | |
395 checkElementHiddenWithId(true, 'route-details'); | |
396 checkElementHiddenWithId(false, 'sink-list'); | |
397 | |
398 // Set a blocking issue. The issue should be shown, and everything | |
399 // else, hidden. | |
400 container.issue = fakeBlockingIssue; | |
401 checkElementHiddenWithId(true, 'container-header'); | |
402 checkElementHiddenWithId(true, 'sink-list-header-text'); | |
403 checkElementHiddenWithId(true, 'cast-mode-header-text'); | |
404 checkElementHiddenWithId(false, 'issue-banner'); | |
405 checkElementHiddenWithId(true, 'cast-mode-list'); | |
406 checkElementHiddenWithId(true, 'route-details'); | |
407 checkElementHiddenWithId(true, 'sink-list'); | |
408 }); | |
409 }); | |
410 } | |
411 | |
412 return { | |
413 registerTests: registerTests, | |
414 }; | |
415 }); | |
OLD | NEW |