OLD | NEW |
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 Loading... |
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 Loading... |
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
314 // Tests the text shown for the sink list. | 309 // Tests the text shown for the sink list. |
315 test('initial sink list route text', function(done) { | 310 test('initial sink list route text', function(done) { |
316 container.allSinks = fakeSinkList; | 311 // Sink 1 - no sink description, no route -> no subtext |
317 container.routeList = fakeRouteList; | 312 // Sink 2 - sink description, no route -> subtext = sink description |
| 313 // Sink 3 - no sink description, route -> subtext = route description |
| 314 // Sink 4 - sink description, route -> subtext = route description |
| 315 container.allSinks = [ |
| 316 new media_router.Sink('sink id 1', 'Sink 1', null, |
| 317 media_router.SinkIconType.CAST, |
| 318 media_router.SinkStatus.ACTIVE, [1, 2, 3]), |
| 319 new media_router.Sink('sink id 2', 'Sink 2', 'Sink 2 description', |
| 320 media_router.SinkIconType.CAST, |
| 321 media_router.SinkStatus.ACTIVE, [1, 2, 3]), |
| 322 new media_router.Sink('sink id 3', 'Sink 3', null, |
| 323 media_router.SinkIconType.CAST, |
| 324 media_router.SinkStatus.PENDING, [1, 2, 3]), |
| 325 new media_router.Sink('sink id 4', 'Sink 4', 'Sink 4 description', |
| 326 media_router.SinkIconType.CAST, |
| 327 media_router.SinkStatus.PENDING, [1, 2, 3]) |
| 328 ]; |
| 329 |
| 330 container.routeList = [ |
| 331 new media_router.Route('id 3', 'sink id 3', 'Title 3', 0, true), |
| 332 new media_router.Route('id 4', 'sink id 4', 'Title 4', 1, false), |
| 333 ]; |
318 | 334 |
319 setTimeout(function() { | 335 setTimeout(function() { |
320 var routeList = | 336 var sinkSubtextList = |
321 container.$['sink-list'].querySelectorAll('.route'); | 337 container.$['sink-list'].querySelectorAll('.sink-subtext'); |
322 assertEquals(fakeSinkList.length, routeList.length); | 338 |
323 checkElementText(fakeRouteList[0].description, routeList[0]); | 339 // There will only be 3 sink subtext entries, because Sink 1 does not |
324 checkElementText(fakeRouteList[1].description, routeList[1]); | 340 // have any subtext. |
325 checkElementText('', routeList[2]); | 341 assertEquals(3, sinkSubtextList.length); |
| 342 |
| 343 checkElementText(container.allSinks[1].description, |
| 344 sinkSubtextList[0]); |
| 345 |
| 346 // Route description overrides sink description for subtext. |
| 347 checkElementText(container.routeList[0].description, |
| 348 sinkSubtextList[1]); |
| 349 |
| 350 checkElementText(container.routeList[1].description, |
| 351 sinkSubtextList[2]); |
326 done(); | 352 done(); |
327 }); | 353 }); |
328 }); | 354 }); |
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 | 355 |
346 // Tests the expected view when there is only one local active route and | 356 // Tests the expected view when there is only one local active route and |
347 // media_router_container is created for the first time. | 357 // media_router_container is created for the first time. |
348 test('initial view with one local route', function() { | 358 test('initial view with one local route', function() { |
349 container.allSinks = fakeSinkList; | 359 container.allSinks = fakeSinkList; |
350 container.routeList = fakeRouteList; | 360 container.routeList = fakeRouteList; |
351 | 361 |
352 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); | 362 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); |
353 }); | 363 }); |
354 | 364 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 'sink-list']); | 501 'sink-list']); |
492 done(); | 502 done(); |
493 }); | 503 }); |
494 }); | 504 }); |
495 | 505 |
496 // Tests that the sink list does not contain any sinks that are not | 506 // 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 | 507 // compatible with the current cast mode and are not associated with a |
498 // route. | 508 // route. |
499 test('sink list filtering based on initial cast mode', function(done) { | 509 test('sink list filtering based on initial cast mode', function(done) { |
500 var newSinks = [ | 510 var newSinks = [ |
501 new media_router.Sink('sink id 10', 'Sink 10', | 511 new media_router.Sink('sink id 10', 'Sink 10', null, |
502 media_router.SinkIconType.CAST, | 512 media_router.SinkIconType.CAST, |
503 media_router.SinkStatus.ACTIVE, [2, 3]), | 513 media_router.SinkStatus.ACTIVE, [2, 3]), |
504 new media_router.Sink('sink id 20', 'Sink 20', | 514 new media_router.Sink('sink id 20', 'Sink 20', null, |
505 media_router.SinkIconType.CAST, | 515 media_router.SinkIconType.CAST, |
506 media_router.SinkStatus.ACTIVE, [1, 2, 3]), | 516 media_router.SinkStatus.ACTIVE, [1, 2, 3]), |
507 new media_router.Sink('sink id 30', 'Sink 30', | 517 new media_router.Sink('sink id 30', 'Sink 30', null, |
508 media_router.SinkIconType.CAST, | 518 media_router.SinkIconType.CAST, |
509 media_router.SinkStatus.PENDING, [2, 3]), | 519 media_router.SinkStatus.PENDING, [2, 3]), |
510 ]; | 520 ]; |
511 | 521 |
512 container.allSinks = newSinks; | 522 container.allSinks = newSinks; |
513 container.routeList = [ | 523 container.routeList = [ |
514 new media_router.Route('id 1', 'sink id 30', 'Title 1', 1, false), | 524 new media_router.Route('id 1', 'sink id 30', 'Title 1', 1, false), |
515 ]; | 525 ]; |
516 | 526 |
517 setTimeout(function() { | 527 setTimeout(function() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 assertEquals(3, sinkList.length); | 571 assertEquals(3, sinkList.length); |
562 done(); | 572 done(); |
563 }); | 573 }); |
564 }); | 574 }); |
565 }); | 575 }); |
566 | 576 |
567 // Tests that sinks provided in some random order will be sorted by name | 577 // Tests that sinks provided in some random order will be sorted by name |
568 // when shown to the user. | 578 // when shown to the user. |
569 test('sinks are shown sorted by name', function(done) { | 579 test('sinks are shown sorted by name', function(done) { |
570 var outOfOrderSinks = [ | 580 var outOfOrderSinks = [ |
571 new media_router.Sink('6543', 'Sleepy', | 581 new media_router.Sink('6543', 'Sleepy', null, |
572 media_router.SinkIconType.CAST, | 582 media_router.SinkIconType.CAST, |
573 media_router.SinkStatus.ACTIVE, [1]), | 583 media_router.SinkStatus.ACTIVE, [1]), |
574 new media_router.Sink('543', 'Happy', | 584 new media_router.Sink('543', 'Happy', null, |
575 media_router.SinkIconType.CAST, | 585 media_router.SinkIconType.CAST, |
576 media_router.SinkStatus.ACTIVE, [1]), | 586 media_router.SinkStatus.ACTIVE, [1]), |
577 new media_router.Sink('43', 'Bashful', | 587 new media_router.Sink('43', 'Bashful', null, |
578 media_router.SinkIconType.CAST, | 588 media_router.SinkIconType.CAST, |
579 media_router.SinkStatus.ACTIVE, [1]), | 589 media_router.SinkStatus.ACTIVE, [1]), |
580 new media_router.Sink('2', 'George', | 590 new media_router.Sink('2', 'George', null, |
581 media_router.SinkIconType.CAST_AUDIO, | 591 media_router.SinkIconType.CAST_AUDIO, |
582 media_router.SinkStatus.ACTIVE, [1]), | 592 media_router.SinkStatus.ACTIVE, [1]), |
583 new media_router.Sink('1', 'George', | 593 new media_router.Sink('1', 'George', null, |
584 media_router.SinkIconType.CAST, | 594 media_router.SinkIconType.CAST, |
585 media_router.SinkStatus.ACTIVE, [1]), | 595 media_router.SinkStatus.ACTIVE, [1]), |
586 new media_router.Sink('3', 'George', | 596 new media_router.Sink('3', 'George', null, |
587 media_router.SinkIconType.HANGOUT, | 597 media_router.SinkIconType.HANGOUT, |
588 media_router.SinkStatus.ACTIVE, [1]), | 598 media_router.SinkStatus.ACTIVE, [1]), |
589 ]; | 599 ]; |
590 | 600 |
591 container.allSinks = outOfOrderSinks; | 601 container.allSinks = outOfOrderSinks; |
592 | 602 |
593 setTimeout(function() { | 603 setTimeout(function() { |
594 var sinkList = | 604 var sinkList = |
595 container.$['sink-list'].querySelectorAll('paper-item'); | 605 container.$['sink-list'].querySelectorAll('paper-item'); |
596 | 606 |
(...skipping 21 matching lines...) Expand all Loading... |
618 done(); | 628 done(); |
619 }); | 629 }); |
620 }); | 630 }); |
621 }); | 631 }); |
622 } | 632 } |
623 | 633 |
624 return { | 634 return { |
625 registerTests: registerTests, | 635 registerTests: registerTests, |
626 }; | 636 }; |
627 }); | 637 }); |
OLD | NEW |