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

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

Issue 1766473002: [Media Router] Further split media_router_container tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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. */
apacible 2016/03/04 01:25:28 How did you decide how to split up tests? Is this
btolsch 2016/03/04 02:14:37 Unfortunately I can't reproduce the timeouts. So t
apacible 2016/03/04 17:21:33 How long does it take to currently execute for eac
btolsch 2016/03/04 20:00:37 It takes about 2-2.2 seconds to run each part on m
6 cr.define('media_router_container', function() { 6 cr.define('media_router_container_part1', function() {
apacible 2016/03/04 01:25:28 nit: spell out the numbers.
btolsch 2016/03/04 02:14:37 Done.
7 function registerTests() { 7 function registerTests() {
8 suite('MediaRouterContainer', function() { 8 suite('MediaRouterContainerPart1', function() {
9 /** 9 /**
10 * Media Router Container created before each test. 10 * Media Router Container created before each test.
11 * @type {MediaRouterContainer} 11 * @type {MediaRouterContainer}
12 */ 12 */
13 var container; 13 var container;
14 14
15 /** 15 /**
16 * The blocking issue to show. 16 * The blocking issue to show.
17 * @type {?media_router.Issue} 17 * @type {?media_router.Issue}
18 */ 18 */
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 var elementVisible = !!element && !element.hidden && 91 var elementVisible = !!element && !element.hidden &&
92 element.style.display != 'none'; 92 element.style.display != 'none';
93 assertEquals(visible, elementVisible, elementId); 93 assertEquals(visible, elementVisible, elementId);
94 }; 94 };
95 95
96 // Checks whether |expected| and the text in the |element| are equal. 96 // Checks whether |expected| and the text in the |element| are equal.
97 var checkElementText = function(expected, element) { 97 var checkElementText = function(expected, element) {
98 assertEquals(expected.trim(), element.textContent.trim()); 98 assertEquals(expected.trim(), element.textContent.trim());
99 }; 99 };
100 100
101 // Checks whether |expected| and the |property| in |container| are equal.
102 var checkPropertyValue = function(expected, property) {
103 assertEquals(expected.trim(), container.property);
104 }
105
106 // Import media_router_container.html before running suite. 101 // Import media_router_container.html before running suite.
107 suiteSetup(function() { 102 suiteSetup(function() {
108 return PolymerTest.importHtml( 103 return PolymerTest.importHtml(
109 'chrome://media-router/elements/media_router_container/' + 104 'chrome://media-router/elements/media_router_container/' +
110 'media_router_container.html'); 105 'media_router_container.html');
111 }); 106 });
112 107
113 // Initialize a media-router-container before each test. 108 // Initialize a media-router-container before each test.
114 setup(function(done) { 109 setup(function(done) {
115 PolymerTest.clearBody(); 110 PolymerTest.clearBody();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 media_router.SinkIconType.CAST, 144 media_router.SinkIconType.CAST,
150 media_router.SinkStatus.ACTIVE, castModeBitset), 145 media_router.SinkStatus.ACTIVE, castModeBitset),
151 new media_router.Sink('sink id 2', 'Sink 2', null, null, 146 new media_router.Sink('sink id 2', 'Sink 2', null, null,
152 media_router.SinkIconType.CAST, 147 media_router.SinkIconType.CAST,
153 media_router.SinkStatus.ACTIVE, castModeBitset), 148 media_router.SinkStatus.ACTIVE, castModeBitset),
154 new media_router.Sink('sink id 3', 'Sink 3', null, null, 149 new media_router.Sink('sink id 3', 'Sink 3', null, null,
155 media_router.SinkIconType.CAST, 150 media_router.SinkIconType.CAST,
156 media_router.SinkStatus.PENDING, castModeBitset), 151 media_router.SinkStatus.PENDING, castModeBitset),
157 ]; 152 ];
158 153
159 searchTextAll = 'sink';
160 searchTextNone = 'abc';
161 searchTextOne = 'sink 1';
162
163 fakeBlockingIssue = new media_router.Issue( 154 fakeBlockingIssue = new media_router.Issue(
164 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, 155 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1,
165 'route id 1', true, 1234); 156 'route id 1', true, 1234);
166 157
167 fakeNonBlockingIssue = new media_router.Issue( 158 fakeNonBlockingIssue = new media_router.Issue(
168 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, 159 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1,
169 'route id 2', false, 1234); 160 'route id 2', false, 1234);
170 161
171 container.castModeList = fakeCastModeList; 162 container.castModeList = fakeCastModeList;
172 163
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 function(done) { 207 function(done) {
217 container.showFirstRunFlow = true; 208 container.showFirstRunFlow = true;
218 container.showFirstRunFlowCloudPref = true; 209 container.showFirstRunFlowCloudPref = true;
219 210
220 setTimeout(function() { 211 setTimeout(function() {
221 container.addEventListener('acknowledge-first-run-flow', 212 container.addEventListener('acknowledge-first-run-flow',
222 function(data) { 213 function(data) {
223 assertFalse(data.detail.optedIntoCloudServices); 214 assertFalse(data.detail.optedIntoCloudServices);
224 done(); 215 done();
225 }); 216 });
217 // Tapping the checkbox doesn't work if the browser window that the
218 // test opens is unfocused, causing this test to fail.
imcheng 2016/03/04 00:26:58 If there is there a tracking bug for this, please
apacible 2016/03/04 01:25:28 In what case does the browser window become unfocu
btolsch 2016/03/04 02:14:37 If I manually switch back to the console to watch
btolsch 2016/03/04 02:14:37 Done.
apacible 2016/03/04 17:21:33 Ah. This is expected behavior. :) Browser tests a
btolsch 2016/03/04 20:00:37 Done.
226 MockInteractions.tap(container.shadowRoot.getElementById( 219 MockInteractions.tap(container.shadowRoot.getElementById(
227 'first-run-cloud-checkbox')); 220 'first-run-cloud-checkbox'));
228 MockInteractions.tap(container.shadowRoot.getElementById( 221 MockInteractions.tap(container.shadowRoot.getElementById(
229 'first-run-button')); 222 'first-run-button'));
230 }); 223 });
231 }); 224 });
232 225
233 // Tests for 'create-route' event firing when a sink with no associated 226 // Tests for 'create-route' event firing when a sink with no associated
234 // route is clicked. 227 // route is clicked.
235 test('select sink without a route', function(done) { 228 test('select sink without a route', function(done) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 295
303 MockInteractions.tap(container.$['container-header']. 296 MockInteractions.tap(container.$['container-header'].
304 $['arrow-drop-icon']); 297 $['arrow-drop-icon']);
305 checkCurrentView(media_router.MediaRouterView.CAST_MODE_LIST); 298 checkCurrentView(media_router.MediaRouterView.CAST_MODE_LIST);
306 299
307 MockInteractions.tap(container.$['container-header']. 300 MockInteractions.tap(container.$['container-header'].
308 $['arrow-drop-icon']); 301 $['arrow-drop-icon']);
309 checkCurrentView(media_router.MediaRouterView.SINK_LIST); 302 checkCurrentView(media_router.MediaRouterView.SINK_LIST);
310 }); 303 });
311 304
312 // Tests the header text. Choosing a cast mode updates the header text.
313 test('header text with no default cast modes', function(done) {
314 assertEquals(loadTimeData.getString('selectCastModeHeader'),
315 container.selectCastModeHeaderText_);
316
317 // The container is currently in auto cast mode, since we have not
318 // picked a cast mode explicitly, and the sinks is not compatible
319 // with exactly one cast mode.
320 assertEquals(media_router.AUTO_CAST_MODE.description,
321 container.headerText);
322 assertFalse(container.userHasSelectedCastMode_);
323
324 container.castModeList = fakeCastModeListWithNonDefaultModesOnly;
325
326 // Switch to cast mode list view.
327 MockInteractions.tap(container.$['container-header'].
328 $['arrow-drop-icon']);
329 setTimeout(function() {
330 var castModeList =
331 container.$$('#cast-mode-list').querySelectorAll('paper-item');
332 assertEquals(fakeCastModeListWithNonDefaultModesOnly.length,
333 castModeList.length);
334 for (var i = 0; i < castModeList.length; i++) {
335 MockInteractions.tap(castModeList[i]);
336 assertEquals(
337 fakeCastModeListWithNonDefaultModesOnly[i].description,
338 container.headerText);
339 checkElementText(
340 fakeCastModeListWithNonDefaultModesOnly[i].description,
341 castModeList[i]);
342 }
343
344 done();
345 });
346 });
347
348 // Tests the header text when updated with a cast mode list with a mix of
349 // default and non-default cast modes.
350 test('cast modes with one default mode', function(done) {
351 container.castModeList = fakeCastModeList;
352
353 // Switch to cast mode list view.
354 MockInteractions.tap(container.$['container-header'].
355 $['arrow-drop-icon']);
356 setTimeout(function() {
357 var castModeList =
358 container.$$('#cast-mode-list').querySelectorAll('paper-item');
359
360 for (var i = 0; i < fakeCastModeList.length; i++) {
361 MockInteractions.tap(castModeList[i]);
362 if (fakeCastModeList[i].type ==
363 media_router.CastModeType.DEFAULT) {
364 assertEquals(fakeCastModeList[i].description,
365 container.headerText);
366
367 checkElementText(fakeCastModeList[i].host, castModeList[i]);
368 } else {
369 assertEquals(fakeCastModeList[i].description,
370 container.headerText);
371 checkElementText(fakeCastModeList[i].description,
372 castModeList[i]);
373 }
374 }
375
376 done();
377 });
378 });
379
380 // Tests that text shown for each sink matches their names. 305 // Tests that text shown for each sink matches their names.
381 test('sink list text', function(done) { 306 test('sink list text', function(done) {
382 container.allSinks = fakeSinkList; 307 container.allSinks = fakeSinkList;
383 308
384 setTimeout(function() { 309 setTimeout(function() {
385 var sinkList = 310 var sinkList =
386 container.$['sink-list'].querySelectorAll('paper-item'); 311 container.$['sink-list'].querySelectorAll('paper-item');
387 assertEquals(fakeSinkList.length, sinkList.length); 312 assertEquals(fakeSinkList.length, sinkList.length);
388 for (var i = 0; i < fakeSinkList.length; i++) { 313 for (var i = 0; i < fakeSinkList.length; i++) {
389 checkElementText(fakeSinkList[i].name, sinkList[i]); 314 checkElementText(fakeSinkList[i].name, sinkList[i]);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 test('view after route is closed remotely', function() { 462 test('view after route is closed remotely', function() {
538 container.allSinks = fakeSinkList; 463 container.allSinks = fakeSinkList;
539 container.routeList = fakeRouteList; 464 container.routeList = fakeRouteList;
540 container.maybeShowRouteDetailsOnOpen(); 465 container.maybeShowRouteDetailsOnOpen();
541 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); 466 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS);
542 467
543 container.routeList = []; 468 container.routeList = [];
544 checkCurrentView(media_router.MediaRouterView.SINK_LIST); 469 checkCurrentView(media_router.MediaRouterView.SINK_LIST);
545 }); 470 });
546 471
547 // Tests for expected visible UI when the view is CAST_MODE_LIST.
548 test('cast mode list state visibility', function(done) {
549 container.showCastModeList_();
550 setTimeout(function() {
551 checkElementsVisibleWithId(['cast-mode-list',
552 'container-header',
553 'device-missing']);
554
555 // Set a non-blocking issue. The issue should stay hidden.
556 container.issue = fakeNonBlockingIssue;
557 setTimeout(function() {
558 checkElementsVisibleWithId(['cast-mode-list',
559 'container-header',
560 'device-missing']);
561
562 // Set a blocking issue. The issue should stay hidden.
563 container.issue = fakeBlockingIssue;
564 setTimeout(function() {
565 checkElementsVisibleWithId(['container-header',
566 'device-missing',
567 'issue-banner']);
568 done();
569 });
570 });
571 });
572 });
573
574 // Tests for the expected visible UI when interacting with the first run 472 // Tests for the expected visible UI when interacting with the first run
575 // flow. 473 // flow.
576 test('first run button visibility', function(done) { 474 test('first run button visibility', function(done) {
577 container.showFirstRunFlow = true; 475 container.showFirstRunFlow = true;
578 476
579 setTimeout(function() { 477 setTimeout(function() {
580 checkElementVisibleWithId(true, 'first-run-flow'); 478 checkElementVisibleWithId(true, 'first-run-flow');
581 MockInteractions.tap(container.shadowRoot.getElementById( 479 MockInteractions.tap(container.shadowRoot.getElementById(
582 'first-run-button')); 480 'first-run-button'));
583 481
584 setTimeout(function() { 482 setTimeout(function() {
585 checkElementVisibleWithId(false, 'first-run-flow'); 483 checkElementVisibleWithId(false, 'first-run-flow');
586 done(); 484 done();
587 }); 485 });
588 }); 486 });
589 }); 487 });
590 488
591 // Tests for the expected visible UI when interacting with the first run
592 // flow with cloud services preference.
593 test('first run button visibility', function(done) {
594 container.showFirstRunFlow = true;
595 container.showFirstRunFlowCloudPref = true;
596
597 setTimeout(function() {
598 checkElementsVisibleWithId(['container-header',
599 'device-missing',
600 'first-run-flow',
601 'first-run-flow-cloud-pref',
602 'sink-list-view']);
603 MockInteractions.tap(container.shadowRoot.getElementById(
604 'first-run-button'));
605
606 setTimeout(function() {
607 checkElementsVisibleWithId(['container-header',
608 'device-missing',
609 'sink-list-view']);
610 done();
611 });
612 });
613 });
614
615 // Tests for expected visible UI when the view is ROUTE_DETAILS. 489 // Tests for expected visible UI when the view is ROUTE_DETAILS.
616 test('route details visibility', function(done) { 490 test('route details visibility', function(done) {
617 container.showRouteDetails_(); 491 container.showRouteDetails_();
618 setTimeout(function() { 492 setTimeout(function() {
619 checkElementsVisibleWithId(['container-header', 493 checkElementsVisibleWithId(['container-header',
620 'device-missing', 494 'device-missing',
621 'route-details']); 495 'route-details']);
622 done(); 496 done();
623 }); 497 });
624 }); 498 });
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 664
791 // All sinks are shown in auto mode. 665 // All sinks are shown in auto mode.
792 assertEquals(3, sinkList.length); 666 assertEquals(3, sinkList.length);
793 667
794 done(); 668 done();
795 }); 669 });
796 }); 670 });
797 }); 671 });
798 }); 672 });
799 673
800 // Tests that the sink list does not contain any sinks that are not
801 // compatible with the selected cast mode and are not associated with a
802 // route.
803 test('sink list in user selected cast mode', function(done) {
804 var newSinks = [
805 new media_router.Sink('sink id 10', 'Sink 10', null, null,
806 media_router.SinkIconType.CAST,
807 media_router.SinkStatus.ACTIVE, 0x4 | 0x8),
808 new media_router.Sink('sink id 20', 'Sink 20', null, null,
809 media_router.SinkIconType.CAST,
810 media_router.SinkStatus.ACTIVE, 0x2 | 0x4 | 0x8),
811 new media_router.Sink('sink id 30', 'Sink 30', null, null,
812 media_router.SinkIconType.CAST,
813 media_router.SinkStatus.PENDING, 0x4 | 0x8),
814 ];
815
816 container.allSinks = newSinks;
817 container.routeList = [
818 new media_router.Route('id 1', 'sink id 30',
819 'Title 1', 1, false, false),
820 ];
821
822 setTimeout(function() {
823 var sinkList =
824 container.$['sink-list'].querySelectorAll('paper-item');
825
826 // Since we haven't selected a cast mode, we don't filter sinks.
827 assertEquals(3, sinkList.length);
828
829 MockInteractions.tap(container.$['container-header'].
830 $['arrow-drop-icon']);
831 setTimeout(function() {
832 // Cast mode 1 is selected, and the sink list is filtered.
833 var castModeList =
834 container.$$('#cast-mode-list').querySelectorAll('paper-item');
835 MockInteractions.tap(castModeList[1]);
836 assertEquals(fakeCastModeList[1].description, container.headerText);
837 assertEquals(fakeCastModeList[1].type,
838 container.shownCastModeValue_);
839
840 setTimeout(function() {
841 var sinkList =
842 container.$['sink-list'].querySelectorAll('paper-item');
843
844 // newSinks[0] got filtered out since it is not compatible with
845 // cast mode 1.
846 // 'Sink 20' should be on the list because it contains the
847 // selected cast mode. (sinkList[0] = newSinks[1])
848 // 'Sink 30' should be on the list because it has a route.
849 // (sinkList[1] = newSinks[2])
850 assertEquals(2, sinkList.length);
851 checkElementText(newSinks[1].name, sinkList[0]);
852
853 // |sinkList[1]| contains route title in addition to sink name.
854 assertTrue(sinkList[1].textContent.trim().startsWith(
855 newSinks[2].name.trim()));
856
857 // Cast mode is not switched back even if there are no sinks
858 // compatible with selected cast mode, because we explicitly
859 // selected that cast mode.
860 container.allSinks = [];
861 setTimeout(function() {
862 assertEquals(fakeCastModeList[1].description,
863 container.headerText);
864 assertEquals(fakeCastModeList[1].type,
865 container.shownCastModeValue_);
866 var sinkList =
867 container.$['sink-list'].querySelectorAll('paper-item');
868 assertEquals(0, sinkList.length);
869 done();
870 });
871 });
872 });
873 });
874 });
875
876 // Container remains in auto mode even if the cast mode list changed. 674 // Container remains in auto mode even if the cast mode list changed.
877 test('cast mode list updated in auto mode', function(done) { 675 test('cast mode list updated in auto mode', function(done) {
878 assertEquals(media_router.AUTO_CAST_MODE.description, 676 assertEquals(media_router.AUTO_CAST_MODE.description,
879 container.headerText); 677 container.headerText);
880 assertEquals(media_router.CastModeType.AUTO, 678 assertEquals(media_router.CastModeType.AUTO,
881 container.shownCastModeValue_); 679 container.shownCastModeValue_);
882 assertFalse(container.userHasSelectedCastMode_); 680 assertFalse(container.userHasSelectedCastMode_);
883 681
884 container.castModeList = fakeCastModeList.slice(1); 682 container.castModeList = fakeCastModeList.slice(1);
885 setTimeout(function() { 683 setTimeout(function() {
886 assertEquals(media_router.AUTO_CAST_MODE.description, 684 assertEquals(media_router.AUTO_CAST_MODE.description,
887 container.headerText); 685 container.headerText);
888 assertEquals(media_router.CastModeType.AUTO, 686 assertEquals(media_router.CastModeType.AUTO,
889 container.shownCastModeValue_); 687 container.shownCastModeValue_);
890 assertFalse(container.userHasSelectedCastMode_); 688 assertFalse(container.userHasSelectedCastMode_);
891 done(); 689 done();
892 }); 690 });
893 }); 691 });
894
895 // If the container is not in auto mode, and the mode it is currently in
896 // no longer exists in the list of cast modes, then switch back to auto
897 // mode.
898 test('cast mode list updated in selected cast mode', function(done) {
899 assertEquals(media_router.AUTO_CAST_MODE.description,
900 container.headerText);
901 assertEquals(media_router.CastModeType.AUTO,
902 container.shownCastModeValue_);
903 assertFalse(container.userHasSelectedCastMode_);
904
905 MockInteractions.tap(container.$['container-header'].
906 $['arrow-drop-icon']);
907 setTimeout(function() {
908 var castModeList =
909 container.$$('#cast-mode-list').querySelectorAll('paper-item');
910 MockInteractions.tap(castModeList[0]);
911 setTimeout(function() {
912 assertEquals(fakeCastModeList[0].description, container.headerText);
913 assertEquals(fakeCastModeList[0].type,
914 container.shownCastModeValue_);
915 assertTrue(container.userHasSelectedCastMode_);
916 container.castModeList = fakeCastModeList.slice(1);
917 setTimeout(function() {
918 assertEquals(media_router.AUTO_CAST_MODE.description,
919 container.headerText);
920 assertEquals(media_router.CastModeType.AUTO,
921 container.shownCastModeValue_);
922 assertFalse(container.userHasSelectedCastMode_);
923 done();
924 });
925 });
926 });
927 });
928
929 test('creating route with selected cast mode', function(done) {
930 container.allSinks = fakeSinkList;
931 MockInteractions.tap(container.$['container-header'].
932 $['arrow-drop-icon']);
933 setTimeout(function() {
934 // Select cast mode 2.
935 var castModeList =
936 container.$$('#cast-mode-list').querySelectorAll('paper-item');
937 MockInteractions.tap(castModeList[1]);
938 assertEquals(fakeCastModeList[1].description, container.headerText);
939 setTimeout(function() {
940 var sinkList =
941 container.$['sink-list'].querySelectorAll('paper-item');
942 container.addEventListener('create-route', function(data) {
943 assertEquals(fakeSinkList[2].id, data.detail.sinkId);
944 // Cast mode 2 is used, since we selected it explicitly.
945 assertEquals(fakeCastModeList[1].type,
946 data.detail.selectedCastModeValue);
947 done();
948 });
949 // All sinks are compatible with cast mode 2.
950 assertEquals(fakeSinkList.length, sinkList.length);
951 // Tap on a sink without a route, which should fire a 'create-route'
952 // event.
953 MockInteractions.tap(sinkList[2]);
954 });
955 });
956 });
957
958 // Tests that after a different cast mode is selected, the sink list will
959 // change based on the sinks compatibility with the new cast mode.
960 test('changing cast mode changes sink list', function(done) {
961 container.allSinks = fakeSinkList;
962
963 MockInteractions.tap(container.$['container-header'].
964 $['arrow-drop-icon']);
965 setTimeout(function() {
966 var castModeList =
967 container.$$('#cast-mode-list').querySelectorAll('paper-item');
968 MockInteractions.tap(castModeList[0]);
969 assertEquals(fakeCastModeList[0].description, container.headerText);
970
971 setTimeout(function() {
972 var sinkList =
973 container.$['sink-list'].querySelectorAll('paper-item');
974
975 // The sink list is empty because none of the sinks in fakeSinkList
976 // is compatible with cast mode 0.
977 assertEquals(0, sinkList.length);
978 MockInteractions.tap(castModeList[2]);
979 assertEquals(fakeCastModeList[2].description, container.headerText);
980
981 setTimeout(function() {
982 var sinkList =
983 container.$['sink-list'].querySelectorAll('paper-item');
984 assertEquals(3, sinkList.length);
985 done();
986 });
987 });
988 });
989 });
990 }); 692 });
991 } 693 }
992 694
993 return { 695 return {
994 registerTests: registerTests, 696 registerTests: registerTests,
995 }; 697 };
996 }); 698 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698