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

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 kmarshall@'s comments. Rebase. 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}
Dan Beam 2015/07/10 01:42:45 this is not a valid type
apacible 2015/07/10 22:19:33 Done.
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
Dan Beam 2015/07/10 01:42:45 @const {!Array<string>}
apacible 2015/07/10 22:19:32 Done.
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.computeArrowDropIcon_(view),
63 container.$['arrow-drop-icon'].icon);
64 }
Dan Beam 2015/07/10 01:42:45 };
apacible 2015/07/10 22:19:32 Done.
65
66 // Checks whether |view| matches the current view of |container|.
67 var checkCurrentView = function(view) {
68 assertEquals(view, container.currentView_);
69 }
Dan Beam 2015/07/10 01:42:45 };
apacible 2015/07/10 22:19:33 Done.
70
71 // Checks whether the elements specified in |elementIdList| are visible.
72 // Checks whether all other elements are hidden.
73 var checkElementsVisibleWithId = function(elementIdList) {
74 for (var i = 0; i < elementIdList.length; i++) {
75 checkElementHidden(false, container.$[elementIdList[i]]);
76 }
77
78 for (var j = 0; j < hiddenCheckElementIdList.length; j++) {
79 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) {
80 checkElementHidden(true,
81 container.$[hiddenCheckElementIdList[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 }
Dan Beam 2015/07/10 01:42:45 };
apacible 2015/07/10 22:19:33 Done.
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 }
Dan Beam 2015/07/10 01:42:45 done();?
apacible 2015/07/10 22:19:32 Done.
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 }
Dan Beam 2015/07/10 01:42:45 done();?
apacible 2015/07/10 22:19:32 Done.
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 });
Dan Beam 2015/07/10 01:42:45 are any of these actually running? any setTimeout
apacible 2015/07/10 22:19:33 Good call, fixed.
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]);
michaelpg 2015/07/10 01:26:39 add done()
apacible 2015/07/10 22:19:33 Done.
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 checkElementsVisibleWithId(['cast-mode-header-text',
330 'cast-mode-list',
Kevin M 2015/07/09 23:40:12 Fix indents here and elsewhere w/multi line array
apacible 2015/07/10 22:19:32 Done.
331 'container-header']);
332
333 // Set a non-blocking issue. The issue should stay hidden.
334 container.issue = fakeNonBlockingIssue;
335 checkElementsVisibleWithId(['cast-mode-header-text',
336 'cast-mode-list',
337 'container-header']);
338
339 // Set a blocking issue. The issue should stay hidden.
340 container.issue = fakeBlockingIssue;
341 checkElementsVisibleWithId(['cast-mode-header-text',
342 'cast-mode-list',
343 'container-header']);
344 });
345
346 // Tests for expected visible UI when the view is ROUTE_DETAILS.
347 test('route details state visibility', function() {
348 container.showRouteDetails_();
349 checkElementsVisibleWithId(['route-details']);
350
351 // Set a non-blocking issue. The issue should be shown.
352 container.issue = fakeNonBlockingIssue;
353 checkElementsVisibleWithId(['issue-banner',
354 'route-details']);
355
356 // Set a blocking issue. The issue should be shown, and everything
357 // else, hidden.
358 container.issue = fakeBlockingIssue;
359 checkElementsVisibleWithId(['issue-banner']);
360 });
361
362 // Tests for expected visible UI when the view is SINK_LIST.
363 test('sink list state visibility', function() {
364 container.showSinkList_();
365 checkElementsVisibleWithId(['container-header',
366 'sink-list',
367 'sink-list-header-text']);
368
369 // Set a non-blocking issue. The issue should be shown.
370 container.issue = fakeNonBlockingIssue;
371 checkElementsVisibleWithId(['container-header',
372 'issue-banner',
373 'sink-list',
374 'sink-list-header-text']);
375
376 // Set a blocking issue. The issue should be shown, and everything
377 // else, hidden.
378 container.issue = fakeBlockingIssue;
379 checkElementsVisibleWithId(['issue-banner']);
380 });
381 });
382 }
383
384 return {
385 registerTests: registerTests,
386 };
387 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698