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

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

Issue 1204943002: Tests for Media Router media-router-container Polymer element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per michaelpg@ and dbeam@'s comments. Created 5 years, 5 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 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 = [];
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 /**
46 * The list of elements to check for visibility.
47 * @type {!Array<string>}
48 * @const
49 */
50 var visibilityCheckElementIdList = [
51 'cast-mode-header-text',
52 'cast-mode-list',
53 'container-header',
54 'issue-banner',
55 'route-details',
56 'sink-list',
57 'sink-list-header-text',
58 ];
59
60 // Checks whether the current icon matches the icon used for the view.
61 var checkArrowDropIcon = function(view) {
62 assertEquals(container.$['arrow-drop-icon'].icon,
Kevin M 2015/07/08 23:02:21 Expected values precede actual values (important t
apacible 2015/07/09 00:02:27 Done.
63 container.computeArrowDropIcon_(view));
64 }
65
66 // Checks whether |view| matches the current view of |container|.
67 var checkCurrentView = function(view) {
68 assertEquals(container.currentView_, view);
69 }
70
71 // Checks whether the elements specified in |elementIdList| are hidden.
72 // Checks whether all other elements are visible.
73 var checkElementsHiddenWithId = function(elementIdList) {
74 for (var i = 0; i < elementIdList.length; i++) {
75 checkElementHidden(true, container.$[elementIdList[i]]);
76 }
77
78 for (var j = 0; j < visibilityCheckElementIdList.length; j++) {
79 if (elementIdList.indexOf(visibilityCheckElementIdList[j]) == -1) {
80 checkElementHidden(false,
81 container.$[visibilityCheckElementIdList[j]]);
82 }
83 }
84 };
85
86 // Checks whether |element| is hidden.
87 var checkElementHidden = function(hidden, element) {
88 assertEquals(hidden, element.hidden);
89 };
90
91 // Checks whether |expected| and the text in the |elementId| element
92 // are equal.
93 var checkElementText = function(expected, element) {
94 assertEquals(expected.trim(), element.textContent.trim());
95 }
96
97 // Checks whether |expected| and the text in the |elementId| element
98 // are equal given an id.
99 var checkElementTextWithId = function(expected, elementId) {
100 checkElementText(expected, container.$[elementId]);
101 };
102
103 // Import media_router_container.html before running suite.
104 suiteSetup(function() {
105 return PolymerTest.importHtml(
106 'chrome://media-router/elements/media_router_container/' +
107 'media_router_container.html');
108 });
109
110 // Initialize an issue-banner before each test.
111 setup(function(done) {
112 PolymerTest.clearBody();
113 container = document.createElement('media-router-container');
114 document.body.appendChild(container);
115
116 // Initialize local variables.
117 fakeCastModeList = [
118 new media_router.CastMode(1, 'Cast Mode 1', 'Description 1'),
119 new media_router.CastMode(2, 'Cast Mode 2', 'Description 2'),
120 new media_router.CastMode(3, 'Cast Mode 3', 'Description 3'),
121 ];
122
123 fakeRouteList = [
124 new media_router.Route('id 1', 'sink id 1', 'Title 1', true),
125 new media_router.Route('id 2', 'sink id 2', 'Title 2', false),
126 ];
127
128 fakeSinkList = [
129 new media_router.Sink('sink id 1', 'Sink 1',
130 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
131 new media_router.Sink('sink id 2', 'Sink 2',
132 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
133 new media_router.Sink('sink id 3', 'Sink 3',
134 media_router.SinkStatus.PENDING, [1, 2, 3]),
135 ];
136
137 fakeBlockingIssue = new media_router.Issue(
138 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1,
139 'route id 1', true, 1234);
140
141 fakeNonBlockingIssue = new media_router.Issue(
142 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1,
143 'route id 2', false, 1234);
144
145 // Allow for the media router container to be created and attached.
146 setTimeout(done);
147 });
148
149 // Tests for 'close-button-click' event firing when the close button
150 // is clicked.
151 test('close button click', function(done) {
152 container.addEventListener('close-button-click', function() {
153 done();
154 });
155 MockInteractions.tap(container.$['close-button']);
156 });
157
158 // Tests for 'create-route' event firing when a sink with no associated
159 // route is clicked.
160 test('select sink without a route', function(done) {
161 container.sinkList = fakeSinkList;
162
163 setTimeout(function() {
164 var sinkList =
165 container.$['sink-list'].querySelectorAll('paper-item');
166
167 container.addEventListener('create-route', function(data) {
168 assertEquals(fakeSinkList[2].id, data.detail.sinkId);
169 assertEquals(container.selectedCastModeValue_,
170 data.detail.selectedCastModeValue);
171 done();
172 });
173
174 // Tap on a sink without a route, which should fire a 'create-route'
175 // event.
176 MockInteractions.tap(sinkList[2]);
177 });
178 });
179
180 // Tests that selecting a sink with an associated route will make the
181 // |container| switch to ROUTE_DETAILS view.
182 test('select sink with a route', function(done) {
183 container.sinkList = fakeSinkList;
184 container.routeList = fakeRouteList;
185
186 setTimeout(function() {
187 var sinkList =
188 container.$['sink-list'].querySelectorAll('paper-item');
189
190 checkCurrentView(container.containerView_.SINK_LIST);
191 MockInteractions.tap(sinkList[0]);
192 checkCurrentView(container.containerView_.ROUTE_DETAILS);
193 done();
194 });
195 });
196
197 // Tests that |container| returns to SINK_LIST view and arrow drop icon
198 // toggles after a cast mode is selected.
199 test('select cast mode', function(done) {
200 container.castModeList = fakeCastModeList;
201
202 MockInteractions.tap(container.$['arrow-drop-icon']);
203 checkArrowDropIcon(container.containerView_.CAST_MODE_LIST);
204 checkCurrentView(container.containerView_.CAST_MODE_LIST);
205
206 setTimeout(function() {
207 var castModeList =
208 container.$['cast-mode-list'].querySelectorAll('paper-item');
209
210 MockInteractions.tap(castModeList[2]);
211 checkArrowDropIcon(container.containerView_.SINK_LIST);
212 checkCurrentView(container.containerView_.SINK_LIST);
213 done();
214 });
215 });
216
217 // Tests that clicking on the drop down icon will toggle |container|
218 // between SINK_LIST and CAST_MODE_LIST views.
219 test('click drop down icon', function() {
220 checkCurrentView(container.containerView_.SINK_LIST);
221
222 MockInteractions.tap(container.$['arrow-drop-icon']);
223 checkArrowDropIcon(container.containerView_.CAST_MODE_LIST);
224 checkCurrentView(container.containerView_.CAST_MODE_LIST);
225
226 MockInteractions.tap(container.$['arrow-drop-icon']);
227 checkArrowDropIcon(container.containerView_.SINK_LIST);
228 checkCurrentView(container.containerView_.SINK_LIST);
229 });
230
231 // Tests the |computeArrowDropIcon_| function.
232 test('compute arrow drop icon', function() {
233 assertEquals('arrow-drop-up',
234 container.computeArrowDropIcon_(
235 container.containerView_.CAST_MODE_LIST));
236 assertEquals('arrow-drop-down',
237 container.computeArrowDropIcon_(
238 container.containerView_.ROUTE_DETAILS));
239 assertEquals('arrow-drop-down',
240 container.computeArrowDropIcon_(
241 container.containerView_.SINK_LIST));
242 });
243
244 // Tests the header text. Choosing a cast mode updates the header text.
245 test('header text', function() {
246 checkElementTextWithId(loadTimeData.getString('selectCastModeHeader'),
247 'cast-mode-header-text');
248
249 var fakeHeaderText = 'fake header text';
250 container.headerText = fakeHeaderText;
251 checkElementTextWithId(fakeHeaderText, 'sink-list-header-text');
252
253 // Set the cast mode list to update the header text when one is
254 // selected.
255 container.castModeList = fakeCastModeList;
256
257 setTimeout(function() {
258 var castModeList =
259 container.$['cast-mode-list'].querySelectorAll('paper-item');
260
261 for (var i = 0; i < fakeCastModeList.length; i++) {
262 MockInteractions.tap(castModeArray[i]);
263 checkElementTextWithId(fakeCastModeList[i].title,
264 'sink-list-header-text');
265 checkElementText(fakeCastModeList[i].description, castModeList[i]);
266 }
267 });
268 });
269
270 // Tests that text shown for each sink matches their names.
271 test('sink list text', function() {
272 container.sinkList = fakeSinkList;
273
274 setTimeout(function() {
275 var sinkList =
276 container.$['sink-list'].querySelectorAll('paper-item');
277
278 for (var i = 0; i < fakeSinkList.length; i++) {
279 checkElementText(fakeSinkList[i].name, sinkList[i]);
280 }
281 });
282 });
283
284 // Tests the text shown for the sink list.
285 test('sink list route text', function() {
286 container.sinkList = fakeSinkList;
287 container.routeList = fakeRouteList;
288
289 setTimeout(function() {
290 var routeList =
291 container.$['sink-list'].querySelectorAll('.route');
292
293 checkElementText(fakeRouteList[0].title, routeList[0]);
294 checkElementText(fakeRouteList[1].title, routeList[1]);
295 checkElementText('', routeList[2]);
296
297 container.addRoute(
298 new media_router.Route('id 3', 'sink id 3', 'Title 3', false));
299 checkElementText(container.routeList[2].title, routeList[3]);
300
301 container.addRoute(
302 new media_router.Route('id 4', 'sink id 1', 'Title 4', false));
303 checkElementText(container.routeList[0].title, routeList[0]);
304 });
305 });
306
307 // Tests the visibility of routes in the sink list.
308 test('route visibility', function() {
309 container.sinkList = fakeSinkList;
310 container.routeList = fakeRouteList;
311
312 setTimeout(function() {
313 var routeList =
314 container.$['sink-list'].querySelectorAll('.route');
315
316 checkElementHidden(false, routeList[0]);
317 checkElementHidden(false, routeList[1]);
318 checkElementHidden(true, routeList[2]);
319
320 container.addRoute(
321 new media_router.Route('id 3', 'sink id 3', 'Title 3', false));
322 checkElementHidden(false, routeList[2]);
323 });
324 });
325
326 // Tests for expected visible UI when the view is CAST_MODE_LIST.
327 test('cast mode list state visibility', function() {
328 container.showCastModeList_();
329 checkElementsHiddenWithId(['issue-banner',
Kevin M 2015/07/08 23:02:21 Might it be easier to express visibility checks in
apacible 2015/07/09 00:02:27 Makes sense, done.
330 'route-details',
331 'sink-list',
332 'sink-list-header-text']);
333
334 // Set a non-blocking issue. The issue should stay hidden.
335 container.issue = fakeNonBlockingIssue;
336 checkElementsHiddenWithId(['issue-banner',
337 'route-details',
338 'sink-list',
339 'sink-list-header-text']);
340
341 // Set a blocking issue. The issue should stay hidden.
342 container.issue = fakeBlockingIssue;
343 checkElementsHiddenWithId(['issue-banner',
344 'route-details',
345 'sink-list',
346 'sink-list-header-text']);
347 });
348
349 // Tests for expected visible UI when the view is ROUTE_DETAILS.
350 test('route details state visibility', function() {
351 container.showRouteDetails_();
352 checkElementsHiddenWithId(['cast-mode-header-text',
353 'cast-mode-list',
354 'container-header',
355 'issue-banner',
356 'sink-list',
357 'sink-list-header-text']);
358
359 // Set a non-blocking issue. The issue should be shown.
360 container.issue = fakeNonBlockingIssue;
361 checkElementsHiddenWithId(['cast-mode-header-text',
362 'cast-mode-list',
363 'container-header',
364 'sink-list',
365 'sink-list-header-text']);
366
367 // Set a blocking issue. The issue should be shown, and everything
368 // else, hidden.
369 container.issue = fakeBlockingIssue;
370 checkElementsHiddenWithId(['cast-mode-header-text',
371 'cast-mode-list',
372 'container-header',
373 'route-details',
374 'sink-list',
375 'sink-list-header-text']);
376 });
377
378 // Tests for expected visible UI when the view is SINK_LIST.
379 test('sink list state visibility', function() {
380 container.showSinkList_();
381
382 checkElementsHiddenWithId(['cast-mode-header-text',
383 'cast-mode-list',
384 'issue-banner',
385 'route-details']);
386
387 // Set a non-blocking issue. The issue should be shown.
388 container.issue = fakeNonBlockingIssue;
389 checkElementsHiddenWithId(['cast-mode-header-text',
390 'cast-mode-list',
391 'route-details']);
392
393 // Set a blocking issue. The issue should be shown, and everything
394 // else, hidden.
395 container.issue = fakeBlockingIssue;
396 checkElementsHiddenWithId(['cast-mode-header-text',
397 'cast-mode-list',
398 'container-header',
399 'route-details',
400 'sink-list',
401 'sink-list-header-text']);
402 });
403 });
404 }
405
406 return {
407 registerTests: registerTests,
408 };
409 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698