OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 that focus on | 5 /** @fileoverview Suite of tests for media-router-container that focus on |
6 * routes. | 6 * routes. |
7 */ | 7 */ |
8 cr.define('media_router_container_route', function() { | 8 cr.define('media_router_container_route', function() { |
9 function registerTests() { | 9 function registerTests() { |
10 suite('MediaRouterContainerRoute', function() { | 10 suite('MediaRouterContainerRoute', function() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 * @type {!Array<!media_router.Route>} | 72 * @type {!Array<!media_router.Route>} |
73 */ | 73 */ |
74 var fakeRouteList = []; | 74 var fakeRouteList = []; |
75 | 75 |
76 /** | 76 /** |
77 * The list of available sinks. | 77 * The list of available sinks. |
78 * @type {!Array<!media_router.Sink>} | 78 * @type {!Array<!media_router.Sink>} |
79 */ | 79 */ |
80 var fakeSinkList = []; | 80 var fakeSinkList = []; |
81 | 81 |
| 82 /** |
| 83 * Sets |container| to use |fakeSinkList| and |fakeRouteList|, and chooses |
| 84 * the sink at the index. |
| 85 * @param {number} index |
| 86 * @return {!Promise<void>} |
| 87 */ |
| 88 var chooseSinkAtIndex = function(index) { |
| 89 container.allSinks = fakeSinkList; |
| 90 container.routeList = fakeRouteList; |
| 91 return new Promise(function(resolve) { |
| 92 setTimeout(function() { |
| 93 var sinkList = container.shadowRoot.getElementById('sink-list') |
| 94 .querySelectorAll('paper-item'); |
| 95 // Start from the SINK_LIST view. |
| 96 container.showSinkList_(); |
| 97 checkCurrentView(media_router.MediaRouterView.SINK_LIST); |
| 98 MockInteractions.tap(sinkList[index]); |
| 99 resolve(); |
| 100 }); |
| 101 }); |
| 102 }; |
| 103 |
82 // Import media_router_container.html before running suite. | 104 // Import media_router_container.html before running suite. |
83 suiteSetup(function() { | 105 suiteSetup(function() { |
84 return PolymerTest.importHtml( | 106 return PolymerTest.importHtml( |
85 'chrome://media-router/elements/media_router_container/' + | 107 'chrome://media-router/elements/media_router_container/' + |
86 'media_router_container.html'); | 108 'media_router_container.html'); |
87 }); | 109 }); |
88 | 110 |
89 setup(function(done) { | 111 setup(function(done) { |
90 PolymerTest.clearBody(); | 112 PolymerTest.clearBody(); |
91 // Initialize a media-router-container before each test. | 113 // Initialize a media-router-container before each test. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Tap on a sink without a route, which should fire a 'create-route' | 160 // Tap on a sink without a route, which should fire a 'create-route' |
139 // event. | 161 // event. |
140 assertEquals(fakeSinkList.length, sinkList.length); | 162 assertEquals(fakeSinkList.length, sinkList.length); |
141 MockInteractions.tap(sinkList[2]); | 163 MockInteractions.tap(sinkList[2]); |
142 }); | 164 }); |
143 }); | 165 }); |
144 | 166 |
145 // Tests that selecting a sink with an associated route will make the | 167 // Tests that selecting a sink with an associated route will make the |
146 // |container| switch to ROUTE_DETAILS view. | 168 // |container| switch to ROUTE_DETAILS view. |
147 test('select sink with a route', function(done) { | 169 test('select sink with a route', function(done) { |
148 container.allSinks = fakeSinkList; | 170 chooseSinkAtIndex(0).then(function() { |
149 container.routeList = fakeRouteList; | |
150 | |
151 setTimeout(function() { | |
152 var sinkList = | |
153 container.shadowRoot.getElementById('sink-list') | |
154 .querySelectorAll('paper-item'); | |
155 | |
156 // Start from the SINK_LIST view. | |
157 container.showSinkList_(); | |
158 checkCurrentView(media_router.MediaRouterView.SINK_LIST); | |
159 MockInteractions.tap(sinkList[0]); | |
160 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); | 171 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); |
161 done(); | 172 done(); |
162 }); | 173 }); |
163 }); | 174 }); |
164 | 175 |
| 176 test('uses WebUI controls when they are available', function(done) { |
| 177 var index = 0; |
| 178 container.webUiRouteControlsAvailable = true; |
| 179 fakeRouteList[index].supportsWebUiController = true; |
| 180 chooseSinkAtIndex(index).then(function() { |
| 181 assertTrue(container.useWebUiRouteControls); |
| 182 done(); |
| 183 }); |
| 184 }); |
| 185 |
| 186 test( |
| 187 'does not use WebUI controls when they are not available', |
| 188 function(done) { |
| 189 var index = 0; |
| 190 container.webUiRouteControlsAvailable = false; |
| 191 fakeRouteList[index].supportsWebUiController = true; |
| 192 chooseSinkAtIndex(index).then(function() { |
| 193 assertFalse(container.useWebUiRouteControls); |
| 194 done(); |
| 195 }); |
| 196 }); |
| 197 |
| 198 test( |
| 199 'does not use WebUI controls when the route does not support them', |
| 200 function(done) { |
| 201 var index = 0; |
| 202 container.webUiRouteControlsAvailable = true; |
| 203 fakeRouteList[index].supportsWebUiController = false; |
| 204 chooseSinkAtIndex(index).then(function() { |
| 205 assertFalse(container.useWebUiRouteControls); |
| 206 done(); |
| 207 }); |
| 208 }); |
| 209 |
165 // Tests the text shown for the sink list. | 210 // Tests the text shown for the sink list. |
166 test('initial sink list route text', function(done) { | 211 test('initial sink list route text', function(done) { |
167 // Sink 1 - no sink description, no route -> no subtext | 212 // Sink 1 - no sink description, no route -> no subtext |
168 // Sink 2 - sink description, no route -> subtext = sink description | 213 // Sink 2 - sink description, no route -> subtext = sink description |
169 // Sink 3 - no sink description, route -> subtext = route description | 214 // Sink 3 - no sink description, route -> subtext = route description |
170 // Sink 4 - sink description, route -> subtext = route description | 215 // Sink 4 - sink description, route -> subtext = route description |
171 container.allSinks = [ | 216 container.allSinks = [ |
172 new media_router.Sink('sink id 1', 'Sink 1', null, null, | 217 new media_router.Sink('sink id 1', 'Sink 1', null, null, |
173 media_router.SinkIconType.CAST, | 218 media_router.SinkIconType.CAST, |
174 media_router.SinkStatus.ACTIVE, [1, 2, 3]), | 219 media_router.SinkStatus.ACTIVE, [1, 2, 3]), |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 done(); | 557 done(); |
513 }); | 558 }); |
514 }); | 559 }); |
515 }); | 560 }); |
516 } | 561 } |
517 | 562 |
518 return { | 563 return { |
519 registerTests: registerTests, | 564 registerTests: registerTests, |
520 }; | 565 }; |
521 }); | 566 }); |
OLD | NEW |