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

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

Issue 1475843002: [MR] Add description field to MediaSink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @fileoverview Suite of tests for media-router-container. */ 5 /** @fileoverview Suite of tests for media-router-container. */
6 cr.define('media_router_container', function() { 6 cr.define('media_router_container', function() {
7 function registerTests() { 7 function registerTests() {
8 suite('MediaRouterContainer', function() { 8 suite('MediaRouterContainer', function() {
9 /** 9 /**
10 * Media Router Container created before each test. 10 * Media Router Container created before each test.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // Checks the visibility of an element with |elementId| in |container|. 82 // Checks the visibility of an element with |elementId| in |container|.
83 // An element is considered visible if it exists and its |hidden| property 83 // An element is considered visible if it exists and its |hidden| property
84 // is |false|. 84 // is |false|.
85 var checkElementVisibleWithId = function(visible, elementId) { 85 var checkElementVisibleWithId = function(visible, elementId) {
86 var element = container.$$('#' + elementId); 86 var element = container.$$('#' + elementId);
87 var elementVisible = !!element && !element.hidden; 87 var elementVisible = !!element && !element.hidden;
88 assertEquals(visible, elementVisible); 88 assertEquals(visible, elementVisible);
89 }; 89 };
90 90
91 // Checks whether |element| is hidden.
92 var checkElementHidden = function(hidden, element) {
93 assertEquals(hidden, element.hidden);
94 };
95
96 // Checks whether |expected| and the text in the |element| are equal. 91 // Checks whether |expected| and the text in the |element| are equal.
97 var checkElementText = function(expected, element) { 92 var checkElementText = function(expected, element) {
98 assertEquals(expected.trim(), element.textContent.trim()); 93 assertEquals(expected.trim(), element.textContent.trim());
99 }; 94 };
100 95
101 // Checks whether |expected| and the |property| in |container| are equal. 96 // Checks whether |expected| and the |property| in |container| are equal.
102 var checkPropertyValue = function(expected, property) { 97 var checkPropertyValue = function(expected, property) {
103 assertEquals(expected.trim(), container.property); 98 assertEquals(expected.trim(), container.property);
104 } 99 }
105 100
(...skipping 29 matching lines...) Expand all
135 ]; 130 ];
136 131
137 fakeRouteListWithLocalRoutesOnly = [ 132 fakeRouteListWithLocalRoutesOnly = [
138 new media_router.Route('id 1', 'sink id 1', 'Title 1', 0, true), 133 new media_router.Route('id 1', 'sink id 1', 'Title 1', 0, true),
139 new media_router.Route('id 2', 'sink id 2', 'Title 2', 1, true), 134 new media_router.Route('id 2', 'sink id 2', 'Title 2', 1, true),
140 ]; 135 ];
141 136
142 // Note: These need to be in-order by name to prevent shuffling. 137 // Note: These need to be in-order by name to prevent shuffling.
143 // Sorting of sinks by name is tested separately. 138 // Sorting of sinks by name is tested separately.
144 fakeSinkList = [ 139 fakeSinkList = [
145 new media_router.Sink('sink id 1', 'Sink 1', 140 new media_router.Sink('sink id 1', 'Sink 1', null,
146 media_router.SinkIconType.CAST, 141 media_router.SinkIconType.CAST,
147 media_router.SinkStatus.ACTIVE, [1, 2, 3]), 142 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
148 new media_router.Sink('sink id 2', 'Sink 2', 143 new media_router.Sink('sink id 2', 'Sink 2', null,
149 media_router.SinkIconType.CAST, 144 media_router.SinkIconType.CAST,
150 media_router.SinkStatus.ACTIVE, [1, 2, 3]), 145 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
151 new media_router.Sink('sink id 3', 'Sink 3', 146 new media_router.Sink('sink id 3', 'Sink 3', null,
152 media_router.SinkIconType.CAST, 147 media_router.SinkIconType.CAST,
153 media_router.SinkStatus.PENDING, [1, 2, 3]), 148 media_router.SinkStatus.PENDING, [1, 2, 3]),
154 ]; 149 ];
155 150
156 fakeBlockingIssue = new media_router.Issue( 151 fakeBlockingIssue = new media_router.Issue(
157 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, 152 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1,
158 'route id 1', true, 1234); 153 'route id 1', true, 1234);
159 154
160 fakeNonBlockingIssue = new media_router.Issue( 155 fakeNonBlockingIssue = new media_router.Issue(
161 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, 156 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 var sinkList = 299 var sinkList =
305 container.$['sink-list'].querySelectorAll('paper-item'); 300 container.$['sink-list'].querySelectorAll('paper-item');
306 assertEquals(fakeSinkList.length, sinkList.length); 301 assertEquals(fakeSinkList.length, sinkList.length);
307 for (var i = 0; i < fakeSinkList.length; i++) { 302 for (var i = 0; i < fakeSinkList.length; i++) {
308 checkElementText(fakeSinkList[i].name, sinkList[i]); 303 checkElementText(fakeSinkList[i].name, sinkList[i]);
309 } 304 }
310 done(); 305 done();
311 }); 306 });
312 }); 307 });
313 308
309
apacible 2015/11/25 23:05:41 nit: remove newline.
imcheng 2015/12/01 19:29:27 Done.
314 // Tests the text shown for the sink list. 310 // Tests the text shown for the sink list.
315 test('initial sink list route text', function(done) { 311 test('initial sink list route text', function(done) {
316 container.allSinks = fakeSinkList; 312 container.allSinks = [
apacible 2015/11/25 23:05:41 Could we just update |fakeSinkList| to have some d
imcheng 2015/12/01 19:29:27 Done. In general, I prefer having separate test da
apacible 2015/12/02 23:27:26 Acknowledged.
317 container.routeList = fakeRouteList; 313 new media_router.Sink('sink id 1', 'Sink 1', null,
314 media_router.SinkIconType.CAST,
315 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
316 new media_router.Sink('sink id 2', 'Sink 2', 'Sink 2 description',
317 media_router.SinkIconType.CAST,
318 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
319 new media_router.Sink('sink id 3', 'Sink 3', null,
320 media_router.SinkIconType.CAST,
321 media_router.SinkStatus.PENDING, [1, 2, 3]),
322 new media_router.Sink('sink id 4', 'Sink 4', 'Sink 4 description',
323 media_router.SinkIconType.CAST,
324 media_router.SinkStatus.PENDING, [1, 2, 3])
325 ];
326
327 container.routeList = [
328 new media_router.Route('id 3', 'sink id 3', 'Title 3', 0, true),
329 new media_router.Route('id 4', 'sink id 4', 'Title 4', 1, false),
330 ];
318 331
319 setTimeout(function() { 332 setTimeout(function() {
320 var routeList = 333 var sinkSubtextList =
321 container.$['sink-list'].querySelectorAll('.route'); 334 container.$['sink-list'].querySelectorAll('.sink-subtext');
322 assertEquals(fakeSinkList.length, routeList.length); 335
323 checkElementText(fakeRouteList[0].description, routeList[0]); 336 // There will only be 3 sink subtext entries, because Sink 1 does not
324 checkElementText(fakeRouteList[1].description, routeList[1]); 337 // have any subtext.
325 checkElementText('', routeList[2]); 338 assertEquals(3, sinkSubtextList.length);
339
340 checkElementText(container.allSinks[1].description,
341 sinkSubtextList[0]);
342
343 // Route description overrides sink description for subtext.
344 checkElementText(container.routeList[0].description,
345 sinkSubtextList[1]);
346
347 checkElementText(container.routeList[1].description,
348 sinkSubtextList[2]);
326 done(); 349 done();
327 }); 350 });
328 }); 351 });
329
330 // Tests the visibility of routes in the sink list.
331 test('initial route visibility', function(done) {
332 container.allSinks = fakeSinkList;
333 container.routeList = fakeRouteList;
334
335 setTimeout(function() {
336 var routeList =
337 container.$['sink-list'].querySelectorAll('.route');
338
339 checkElementHidden(false, routeList[0]);
340 checkElementHidden(false, routeList[1]);
341 checkElementHidden(true, routeList[2]);
342 done();
343 });
344 });
345 352
346 // Tests the expected view when there is only one local active route and 353 // Tests the expected view when there is only one local active route and
347 // media_router_container is created for the first time. 354 // media_router_container is created for the first time.
348 test('initial view with one local route', function() { 355 test('initial view with one local route', function() {
349 container.allSinks = fakeSinkList; 356 container.allSinks = fakeSinkList;
350 container.routeList = fakeRouteList; 357 container.routeList = fakeRouteList;
351 358
352 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); 359 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS);
353 }); 360 });
354 361
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 'sink-list']); 498 'sink-list']);
492 done(); 499 done();
493 }); 500 });
494 }); 501 });
495 502
496 // Tests that the sink list does not contain any sinks that are not 503 // Tests that the sink list does not contain any sinks that are not
497 // compatible with the current cast mode and are not associated with a 504 // compatible with the current cast mode and are not associated with a
498 // route. 505 // route.
499 test('sink list filtering based on initial cast mode', function(done) { 506 test('sink list filtering based on initial cast mode', function(done) {
500 var newSinks = [ 507 var newSinks = [
501 new media_router.Sink('sink id 10', 'Sink 10', 508 new media_router.Sink('sink id 10', 'Sink 10', null,
502 media_router.SinkIconType.CAST, 509 media_router.SinkIconType.CAST,
503 media_router.SinkStatus.ACTIVE, [2, 3]), 510 media_router.SinkStatus.ACTIVE, [2, 3]),
504 new media_router.Sink('sink id 20', 'Sink 20', 511 new media_router.Sink('sink id 20', 'Sink 20', null,
505 media_router.SinkIconType.CAST, 512 media_router.SinkIconType.CAST,
506 media_router.SinkStatus.ACTIVE, [1, 2, 3]), 513 media_router.SinkStatus.ACTIVE, [1, 2, 3]),
507 new media_router.Sink('sink id 30', 'Sink 30', 514 new media_router.Sink('sink id 30', 'Sink 30', null,
508 media_router.SinkIconType.CAST, 515 media_router.SinkIconType.CAST,
509 media_router.SinkStatus.PENDING, [2, 3]), 516 media_router.SinkStatus.PENDING, [2, 3]),
510 ]; 517 ];
511 518
512 container.allSinks = newSinks; 519 container.allSinks = newSinks;
513 container.routeList = [ 520 container.routeList = [
514 new media_router.Route('id 1', 'sink id 30', 'Title 1', 1, false), 521 new media_router.Route('id 1', 'sink id 30', 'Title 1', 1, false),
515 ]; 522 ];
516 523
517 setTimeout(function() { 524 setTimeout(function() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 assertEquals(3, sinkList.length); 568 assertEquals(3, sinkList.length);
562 done(); 569 done();
563 }); 570 });
564 }); 571 });
565 }); 572 });
566 573
567 // Tests that sinks provided in some random order will be sorted by name 574 // Tests that sinks provided in some random order will be sorted by name
568 // when shown to the user. 575 // when shown to the user.
569 test('sinks are shown sorted by name', function(done) { 576 test('sinks are shown sorted by name', function(done) {
570 var outOfOrderSinks = [ 577 var outOfOrderSinks = [
571 new media_router.Sink('6543', 'Sleepy', 578 new media_router.Sink('6543', 'Sleepy', null,
572 media_router.SinkIconType.CAST, 579 media_router.SinkIconType.CAST,
573 media_router.SinkStatus.ACTIVE, [1]), 580 media_router.SinkStatus.ACTIVE, [1]),
574 new media_router.Sink('543', 'Happy', 581 new media_router.Sink('543', 'Happy', null,
575 media_router.SinkIconType.CAST, 582 media_router.SinkIconType.CAST,
576 media_router.SinkStatus.ACTIVE, [1]), 583 media_router.SinkStatus.ACTIVE, [1]),
577 new media_router.Sink('43', 'Bashful', 584 new media_router.Sink('43', 'Bashful', null,
578 media_router.SinkIconType.CAST, 585 media_router.SinkIconType.CAST,
579 media_router.SinkStatus.ACTIVE, [1]), 586 media_router.SinkStatus.ACTIVE, [1]),
580 new media_router.Sink('2', 'George', 587 new media_router.Sink('2', 'George', null,
581 media_router.SinkIconType.CAST_AUDIO, 588 media_router.SinkIconType.CAST_AUDIO,
582 media_router.SinkStatus.ACTIVE, [1]), 589 media_router.SinkStatus.ACTIVE, [1]),
583 new media_router.Sink('1', 'George', 590 new media_router.Sink('1', 'George', null,
584 media_router.SinkIconType.CAST, 591 media_router.SinkIconType.CAST,
585 media_router.SinkStatus.ACTIVE, [1]), 592 media_router.SinkStatus.ACTIVE, [1]),
586 new media_router.Sink('3', 'George', 593 new media_router.Sink('3', 'George', null,
587 media_router.SinkIconType.HANGOUT, 594 media_router.SinkIconType.HANGOUT,
588 media_router.SinkStatus.ACTIVE, [1]), 595 media_router.SinkStatus.ACTIVE, [1]),
589 ]; 596 ];
590 597
591 container.allSinks = outOfOrderSinks; 598 container.allSinks = outOfOrderSinks;
592 599
593 setTimeout(function() { 600 setTimeout(function() {
594 var sinkList = 601 var sinkList =
595 container.$['sink-list'].querySelectorAll('paper-item'); 602 container.$['sink-list'].querySelectorAll('paper-item');
596 603
(...skipping 21 matching lines...) Expand all
618 done(); 625 done();
619 }); 626 });
620 }); 627 });
621 }); 628 });
622 } 629 }
623 630
624 return { 631 return {
625 registerTests: registerTests, 632 registerTests: registerTests,
626 }; 633 };
627 }); 634 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698