| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** @fileoverview Suite of tests for media-router-container that focus on |
| 6 * routes. */ |
| 7 cr.define('media_router_container_route', function() { |
| 8 function registerTests() { |
| 9 suite('MediaRouterContainerRoute', function() { |
| 10 /** |
| 11 * Checks whether |view| matches the current view of |container|. |
| 12 * |
| 13 * @param {media_router.MediaRouterView} view Expected view type. |
| 14 */ |
| 15 var checkCurrentView; |
| 16 |
| 17 /** |
| 18 * Checks whether the elements specified in |elementIdList| are visible. |
| 19 * Checks whether all other elements are not visible. Throws an assertion |
| 20 * error if this is not true. |
| 21 * |
| 22 * @param {!Array<!string>} elementIdList List of id's of elements that |
| 23 * should be visible. |
| 24 */ |
| 25 var checkElementsVisibleWithId; |
| 26 |
| 27 /** |
| 28 * Checks whether |expected| and the text in the |element| are equal. |
| 29 * |
| 30 * @param {!string} expected Expected text. |
| 31 * @param {Element} element Element whose text will be checked. |
| 32 */ |
| 33 var checkElementText; |
| 34 |
| 35 /** |
| 36 * Media Router Container created before each test. |
| 37 * @type {MediaRouterContainer} |
| 38 */ |
| 39 var container; |
| 40 |
| 41 /** |
| 42 * The blocking issue to show. |
| 43 * @type {?media_router.Issue} |
| 44 */ |
| 45 var fakeBlockingIssue; |
| 46 |
| 47 /** |
| 48 * The list of CastModes to show. |
| 49 * @type {!Array<!media_router.CastMode>} |
| 50 */ |
| 51 var fakeCastModeList = []; |
| 52 |
| 53 /** |
| 54 * The blocking issue to show. |
| 55 * @type {?media_router.Issue} |
| 56 */ |
| 57 var fakeNonBlockingIssue; |
| 58 |
| 59 /** |
| 60 * The list of current routes. |
| 61 * @type {!Array<!media_router.Route>} |
| 62 */ |
| 63 var fakeRouteList = []; |
| 64 |
| 65 /** |
| 66 * The list of available sinks. |
| 67 * @type {!Array<!media_router.Sink>} |
| 68 */ |
| 69 var fakeSinkList = []; |
| 70 |
| 71 // Import media_router_container.html before running suite. |
| 72 suiteSetup(function() { |
| 73 return PolymerTest.importHtml( |
| 74 'chrome://media-router/elements/media_router_container/' + |
| 75 'media_router_container.html'); |
| 76 }); |
| 77 |
| 78 setup(function(done) { |
| 79 PolymerTest.clearBody(); |
| 80 // Initialize a media-router-container before each test. |
| 81 container = document.createElement('media-router-container'); |
| 82 document.body.appendChild(container); |
| 83 |
| 84 // Get common functions and variables. |
| 85 var test_base = media_router_container_test_base.init(container); |
| 86 |
| 87 checkCurrentView = test_base.checkCurrentView; |
| 88 checkElementsVisibleWithId = test_base.checkElementsVisibleWithId; |
| 89 checkElementText = test_base.checkElementText; |
| 90 fakeBlockingIssue = test_base.fakeBlockingIssue; |
| 91 fakeCastModeList = test_base.fakeCastModeList; |
| 92 fakeNonBlockingIssue = test_base.fakeNonBlockingIssue; |
| 93 fakeRouteList = test_base.fakeRouteList; |
| 94 fakeRouteListWithLocalRoutesOnly = |
| 95 test_base.fakeRouteListWithLocalRoutesOnly; |
| 96 fakeSinkList = test_base.fakeSinkList; |
| 97 |
| 98 container.castModeList = test_base.fakeCastModeList; |
| 99 |
| 100 // Allow for the media router container to be created and attached. |
| 101 setTimeout(done); |
| 102 }); |
| 103 |
| 104 // Tests for 'create-route' event firing when a sink with no associated |
| 105 // route is clicked. |
| 106 test('select sink without a route', function(done) { |
| 107 container.allSinks = fakeSinkList; |
| 108 |
| 109 setTimeout(function() { |
| 110 var sinkList = |
| 111 container.$['sink-list'].querySelectorAll('paper-item'); |
| 112 container.addEventListener('create-route', function(data) { |
| 113 // Container is initially in auto mode since a cast mode has not |
| 114 // been selected. |
| 115 assertEquals(media_router.CastModeType.AUTO, |
| 116 container.shownCastModeValue_); |
| 117 assertEquals(fakeSinkList[2].id, data.detail.sinkId); |
| 118 |
| 119 // The preferred compatible cast mode on the sink is used, since |
| 120 // the we did not choose a cast mode on the container. |
| 121 assertEquals(0x2, data.detail.selectedCastModeValue); |
| 122 done(); |
| 123 }); |
| 124 // Tap on a sink without a route, which should fire a 'create-route' |
| 125 // event. |
| 126 assertEquals(fakeSinkList.length, sinkList.length); |
| 127 MockInteractions.tap(sinkList[2]); |
| 128 }); |
| 129 }); |
| 130 |
| 131 // Tests that selecting a sink with an associated route will make the |
| 132 // |container| switch to ROUTE_DETAILS view. |
| 133 test('select sink with a route', function(done) { |
| 134 container.allSinks = fakeSinkList; |
| 135 container.routeList = fakeRouteList; |
| 136 |
| 137 setTimeout(function() { |
| 138 var sinkList = |
| 139 container.$['sink-list'].querySelectorAll('paper-item'); |
| 140 |
| 141 // Start from the SINK_LIST view. |
| 142 container.showSinkList_(); |
| 143 checkCurrentView(media_router.MediaRouterView.SINK_LIST); |
| 144 MockInteractions.tap(sinkList[0]); |
| 145 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); |
| 146 done(); |
| 147 }); |
| 148 }); |
| 149 |
| 150 // Tests the text shown for the sink list. |
| 151 test('initial sink list route text', function(done) { |
| 152 // Sink 1 - no sink description, no route -> no subtext |
| 153 // Sink 2 - sink description, no route -> subtext = sink description |
| 154 // Sink 3 - no sink description, route -> subtext = route description |
| 155 // Sink 4 - sink description, route -> subtext = route description |
| 156 container.allSinks = [ |
| 157 new media_router.Sink('sink id 1', 'Sink 1', null, null, |
| 158 media_router.SinkIconType.CAST, |
| 159 media_router.SinkStatus.ACTIVE, [1, 2, 3]), |
| 160 new media_router.Sink('sink id 2', 'Sink 2', |
| 161 'Sink 2 description', null, |
| 162 media_router.SinkIconType.CAST, |
| 163 media_router.SinkStatus.ACTIVE, [1, 2, 3]), |
| 164 new media_router.Sink('sink id 3', 'Sink 3', null, null, |
| 165 media_router.SinkIconType.CAST, |
| 166 media_router.SinkStatus.PENDING, [1, 2, 3]), |
| 167 new media_router.Sink('sink id 4', 'Sink 4', |
| 168 'Sink 4 description', null, |
| 169 media_router.SinkIconType.CAST, |
| 170 media_router.SinkStatus.PENDING, [1, 2, 3]) |
| 171 ]; |
| 172 |
| 173 container.routeList = [ |
| 174 new media_router.Route('id 3', 'sink id 3', 'Title 3', 0, true), |
| 175 new media_router.Route('id 4', 'sink id 4', 'Title 4', 1, false), |
| 176 ]; |
| 177 |
| 178 setTimeout(function() { |
| 179 var sinkSubtextList = |
| 180 container.$['sink-list'].querySelectorAll('.sink-subtext'); |
| 181 |
| 182 // There will only be 3 sink subtext entries, because Sink 1 does not |
| 183 // have any subtext. |
| 184 assertEquals(3, sinkSubtextList.length); |
| 185 |
| 186 checkElementText(container.allSinks[1].description, |
| 187 sinkSubtextList[0]); |
| 188 |
| 189 // Route description overrides sink description for subtext. |
| 190 checkElementText(container.routeList[0].description, |
| 191 sinkSubtextList[1]); |
| 192 |
| 193 checkElementText(container.routeList[1].description, |
| 194 sinkSubtextList[2]); |
| 195 done(); |
| 196 }); |
| 197 }); |
| 198 |
| 199 // Tests the expected view when there is only one local active route and |
| 200 // media_router_container is created for the first time. |
| 201 test('initial view with one local route', function() { |
| 202 container.allSinks = fakeSinkList; |
| 203 container.routeList = fakeRouteList; |
| 204 container.maybeShowRouteDetailsOnOpen(); |
| 205 |
| 206 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); |
| 207 }); |
| 208 |
| 209 // Tests the expected view when there are multiple local active routes |
| 210 // and media_router_container is created for the first time. |
| 211 test('initial view with multiple local routes', function() { |
| 212 container.allSinks = fakeSinkList; |
| 213 container.routeList = fakeRouteListWithLocalRoutesOnly; |
| 214 |
| 215 checkCurrentView(media_router.MediaRouterView.SINK_LIST); |
| 216 }); |
| 217 |
| 218 // Tests the expected view when there are no local active routes and |
| 219 // media_router_container is created for the first time. |
| 220 test('initial view with no local route', function() { |
| 221 container.allSinks = fakeSinkList; |
| 222 container.routeList = []; |
| 223 |
| 224 checkCurrentView(media_router.MediaRouterView.SINK_LIST); |
| 225 }); |
| 226 |
| 227 // Tests the expected view when there are no local active routes and |
| 228 // media_router_container is created for the first time. |
| 229 test('view after route is closed remotely', function() { |
| 230 container.allSinks = fakeSinkList; |
| 231 container.routeList = fakeRouteList; |
| 232 container.maybeShowRouteDetailsOnOpen(); |
| 233 checkCurrentView(media_router.MediaRouterView.ROUTE_DETAILS); |
| 234 |
| 235 container.routeList = []; |
| 236 checkCurrentView(media_router.MediaRouterView.SINK_LIST); |
| 237 }); |
| 238 |
| 239 // Tests for expected visible UI when the view is ROUTE_DETAILS. |
| 240 test('route details visibility', function(done) { |
| 241 container.showRouteDetails_(); |
| 242 setTimeout(function() { |
| 243 checkElementsVisibleWithId(['container-header', |
| 244 'device-missing', |
| 245 'route-details']); |
| 246 done(); |
| 247 }); |
| 248 }); |
| 249 |
| 250 test('updated route in route details', function(done) { |
| 251 container.allSinks = fakeSinkList; |
| 252 var description = 'Title'; |
| 253 var route = new media_router.Route( |
| 254 'id 1', 'sink id 1', description, 0, true, false); |
| 255 container.routeList = [route]; |
| 256 container.showRouteDetails_(route); |
| 257 setTimeout(function() { |
| 258 // Note that sink-list-view is hidden. |
| 259 checkElementsVisibleWithId( |
| 260 ['container-header', 'route-details', 'sink-list']); |
| 261 assertTrue(!!container.currentRoute_); |
| 262 assertEquals(description, container.currentRoute_.description); |
| 263 |
| 264 var newDescription = 'Foo'; |
| 265 route.description = newDescription; |
| 266 container.routeList = [route]; |
| 267 setTimeout(function() { |
| 268 // Note that sink-list-view is hidden. |
| 269 checkElementsVisibleWithId( |
| 270 ['container-header', 'route-details', 'sink-list']); |
| 271 assertTrue(!!container.currentRoute_); |
| 272 assertEquals(newDescription, container.currentRoute_.description); |
| 273 done(); |
| 274 }); |
| 275 }); |
| 276 }); |
| 277 |
| 278 // Tests for expected visible UI when the view is ROUTE_DETAILS, and there |
| 279 // is a non-blocking issue. |
| 280 test('route details visibility non blocking issue', function(done) { |
| 281 container.showRouteDetails_(); |
| 282 |
| 283 // Set a non-blocking issue. The issue should be shown. |
| 284 container.issue = fakeNonBlockingIssue; |
| 285 setTimeout(function() { |
| 286 checkElementsVisibleWithId(['container-header', |
| 287 'device-missing', |
| 288 'route-details']); |
| 289 done(); |
| 290 }); |
| 291 }); |
| 292 |
| 293 // Tests for expected visible UI when the view is ROUTE_DETAILS, and there |
| 294 // is a blocking issue. |
| 295 test('route details visibility with blocking issue', function(done) { |
| 296 container.showRouteDetails_(); |
| 297 |
| 298 // Set a blocking issue. The issue should be shown, and everything |
| 299 // else, hidden. |
| 300 container.issue = fakeBlockingIssue; |
| 301 setTimeout(function() { |
| 302 checkElementsVisibleWithId(['container-header', |
| 303 'device-missing', |
| 304 'issue-banner']); |
| 305 done(); |
| 306 }); |
| 307 }); |
| 308 |
| 309 test('creating route with selected cast mode', function(done) { |
| 310 container.allSinks = fakeSinkList; |
| 311 MockInteractions.tap(container.$['container-header']. |
| 312 $['arrow-drop-icon']); |
| 313 setTimeout(function() { |
| 314 // Select cast mode 2. |
| 315 var castModeList = |
| 316 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 317 MockInteractions.tap(castModeList[1]); |
| 318 assertEquals(fakeCastModeList[1].description, container.headerText); |
| 319 setTimeout(function() { |
| 320 var sinkList = |
| 321 container.$['sink-list'].querySelectorAll('paper-item'); |
| 322 container.addEventListener('create-route', function(data) { |
| 323 assertEquals(fakeSinkList[2].id, data.detail.sinkId); |
| 324 // Cast mode 2 is used, since we selected it explicitly. |
| 325 assertEquals(fakeCastModeList[1].type, |
| 326 data.detail.selectedCastModeValue); |
| 327 done(); |
| 328 }); |
| 329 // All sinks are compatible with cast mode 2. |
| 330 assertEquals(fakeSinkList.length, sinkList.length); |
| 331 // Tap on a sink without a route, which should fire a 'create-route' |
| 332 // event. |
| 333 MockInteractions.tap(sinkList[2]); |
| 334 }); |
| 335 }); |
| 336 }); |
| 337 }); |
| 338 } |
| 339 |
| 340 return { |
| 341 registerTests: registerTests, |
| 342 }; |
| 343 }); |
| OLD | NEW |