| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** @fileoverview Suite of tests for media-router-container. */ |
| 6 cr.define('media_router_container_part2', function() { |
| 7 function registerTests() { |
| 8 suite('MediaRouterContainerPart2', function() { |
| 9 /** |
| 10 * Media Router Container created before each test. |
| 11 * @type {MediaRouterContainer} |
| 12 */ |
| 13 var container; |
| 14 |
| 15 /** |
| 16 * The blocking issue to show. |
| 17 * @type {?media_router.Issue} |
| 18 */ |
| 19 var fakeBlockingIssue; |
| 20 |
| 21 /** |
| 22 * The list of CastModes to show. |
| 23 * @type {!Array<!media_router.CastMode>} |
| 24 */ |
| 25 var fakeCastModeList = []; |
| 26 |
| 27 /** |
| 28 * The list of CastModes to show with non-default modes only. |
| 29 * @type {!Array<!media_router.CastMode>} |
| 30 */ |
| 31 var fakeCastModeListWithNonDefaultModesOnly = []; |
| 32 |
| 33 /** |
| 34 * The blocking issue to show. |
| 35 * @type {?media_router.Issue} |
| 36 */ |
| 37 var fakeNonBlockingIssue; |
| 38 |
| 39 /** |
| 40 * The list of available sinks. |
| 41 * @type {!Array<!media_router.Sink>} |
| 42 */ |
| 43 var fakeSinkList = []; |
| 44 |
| 45 /** |
| 46 * The list of elements to check for visibility. |
| 47 * @const {!Array<string>} |
| 48 */ |
| 49 var hiddenCheckElementIdList = [ |
| 50 'cast-mode-list', |
| 51 'container-header', |
| 52 'device-missing', |
| 53 'first-run-flow', |
| 54 'first-run-flow-cloud-pref', |
| 55 'issue-banner', |
| 56 'no-search-matches', |
| 57 'route-details', |
| 58 'search-results', |
| 59 'sink-list', |
| 60 'sink-list-view', |
| 61 ]; |
| 62 |
| 63 // Checks whether the elements specified in |elementIdList| are visible. |
| 64 // Checks whether all other elements are not visible. |
| 65 var checkElementsVisibleWithId = function(elementIdList) { |
| 66 for (var i = 0; i < elementIdList.length; i++) |
| 67 checkElementVisibleWithId(true, elementIdList[i]); |
| 68 |
| 69 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { |
| 70 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) |
| 71 checkElementVisibleWithId(false, hiddenCheckElementIdList[j]); |
| 72 } |
| 73 }; |
| 74 |
| 75 // Checks the visibility of an element with |elementId| in |container|. |
| 76 // An element is considered visible if it exists and its |hidden| property |
| 77 // is |false|. |
| 78 var checkElementVisibleWithId = function(visible, elementId) { |
| 79 var element = container.$$('#' + elementId); |
| 80 var elementVisible = !!element && !element.hidden && |
| 81 element.style.display != 'none'; |
| 82 assertEquals(visible, elementVisible, elementId); |
| 83 }; |
| 84 |
| 85 // Checks whether |expected| and the text in the |element| are equal. |
| 86 var checkElementText = function(expected, element) { |
| 87 assertEquals(expected.trim(), element.textContent.trim()); |
| 88 }; |
| 89 |
| 90 // Import media_router_container.html before running suite. |
| 91 suiteSetup(function() { |
| 92 return PolymerTest.importHtml( |
| 93 'chrome://media-router/elements/media_router_container/' + |
| 94 'media_router_container.html'); |
| 95 }); |
| 96 |
| 97 // Initialize a media-router-container before each test. |
| 98 setup(function(done) { |
| 99 PolymerTest.clearBody(); |
| 100 container = document.createElement('media-router-container'); |
| 101 document.body.appendChild(container); |
| 102 |
| 103 // Initialize local variables. |
| 104 fakeCastModeList = [ |
| 105 new media_router.CastMode(0x1, 'Description 0', 'google.com'), |
| 106 new media_router.CastMode(0x2, 'Description 1', null), |
| 107 new media_router.CastMode(0x4, 'Description 2', null), |
| 108 ]; |
| 109 |
| 110 fakeCastModeListWithNonDefaultModesOnly = [ |
| 111 new media_router.CastMode(0x2, 'Description 1', null), |
| 112 new media_router.CastMode(0x4, 'Description 2', null), |
| 113 new media_router.CastMode(0x8, 'Description 3', null), |
| 114 ]; |
| 115 |
| 116 fakeRouteListWithLocalRoutesOnly = [ |
| 117 new media_router.Route('id 1', 'sink id 1', |
| 118 'Title 1', 0, true, false), |
| 119 new media_router.Route('id 2', 'sink id 2', |
| 120 'Title 2', 1, true, false), |
| 121 ]; |
| 122 |
| 123 var castModeBitset = 0x2 | 0x4 | 0x8; |
| 124 fakeSinkList = [ |
| 125 new media_router.Sink('sink id 1', 'Sink 1', null, null, |
| 126 media_router.SinkIconType.CAST, |
| 127 media_router.SinkStatus.ACTIVE, castModeBitset), |
| 128 new media_router.Sink('sink id 2', 'Sink 2', null, null, |
| 129 media_router.SinkIconType.CAST, |
| 130 media_router.SinkStatus.ACTIVE, castModeBitset), |
| 131 new media_router.Sink('sink id 3', 'Sink 3', null, null, |
| 132 media_router.SinkIconType.CAST, |
| 133 media_router.SinkStatus.PENDING, castModeBitset), |
| 134 ]; |
| 135 |
| 136 fakeBlockingIssue = new media_router.Issue( |
| 137 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, |
| 138 'route id 1', true, 1234); |
| 139 |
| 140 fakeNonBlockingIssue = new media_router.Issue( |
| 141 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, |
| 142 'route id 2', false, 1234); |
| 143 |
| 144 container.castModeList = fakeCastModeList; |
| 145 |
| 146 // Allow for the media router container to be created and attached. |
| 147 setTimeout(done); |
| 148 }); |
| 149 |
| 150 // Tests the header text. Choosing a cast mode updates the header text. |
| 151 test('header text with no default cast modes', function(done) { |
| 152 assertEquals(loadTimeData.getString('selectCastModeHeader'), |
| 153 container.selectCastModeHeaderText_); |
| 154 |
| 155 // The container is currently in auto cast mode, since we have not |
| 156 // picked a cast mode explicitly, and the sinks is not compatible |
| 157 // with exactly one cast mode. |
| 158 assertEquals(media_router.AUTO_CAST_MODE.description, |
| 159 container.headerText); |
| 160 assertFalse(container.userHasSelectedCastMode_); |
| 161 |
| 162 container.castModeList = fakeCastModeListWithNonDefaultModesOnly; |
| 163 |
| 164 // Switch to cast mode list view. |
| 165 MockInteractions.tap(container.$['container-header']. |
| 166 $['arrow-drop-icon']); |
| 167 setTimeout(function() { |
| 168 var castModeList = |
| 169 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 170 assertEquals(fakeCastModeListWithNonDefaultModesOnly.length, |
| 171 castModeList.length); |
| 172 for (var i = 0; i < castModeList.length; i++) { |
| 173 MockInteractions.tap(castModeList[i]); |
| 174 assertEquals( |
| 175 fakeCastModeListWithNonDefaultModesOnly[i].description, |
| 176 container.headerText); |
| 177 checkElementText( |
| 178 fakeCastModeListWithNonDefaultModesOnly[i].description, |
| 179 castModeList[i]); |
| 180 } |
| 181 |
| 182 done(); |
| 183 }); |
| 184 }); |
| 185 |
| 186 // Tests the header text when updated with a cast mode list with a mix of |
| 187 // default and non-default cast modes. |
| 188 test('cast modes with one default mode', function(done) { |
| 189 container.castModeList = fakeCastModeList; |
| 190 |
| 191 // Switch to cast mode list view. |
| 192 MockInteractions.tap(container.$['container-header']. |
| 193 $['arrow-drop-icon']); |
| 194 setTimeout(function() { |
| 195 var castModeList = |
| 196 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 197 |
| 198 for (var i = 0; i < fakeCastModeList.length; i++) { |
| 199 MockInteractions.tap(castModeList[i]); |
| 200 if (fakeCastModeList[i].type == |
| 201 media_router.CastModeType.DEFAULT) { |
| 202 assertEquals(fakeCastModeList[i].description, |
| 203 container.headerText); |
| 204 |
| 205 checkElementText(fakeCastModeList[i].host, castModeList[i]); |
| 206 } else { |
| 207 assertEquals(fakeCastModeList[i].description, |
| 208 container.headerText); |
| 209 checkElementText(fakeCastModeList[i].description, |
| 210 castModeList[i]); |
| 211 } |
| 212 } |
| 213 |
| 214 done(); |
| 215 }); |
| 216 }); |
| 217 |
| 218 // Tests for expected visible UI when the view is CAST_MODE_LIST. |
| 219 test('cast mode list state visibility', function(done) { |
| 220 container.showCastModeList_(); |
| 221 setTimeout(function() { |
| 222 checkElementsVisibleWithId(['cast-mode-list', |
| 223 'container-header', |
| 224 'device-missing']); |
| 225 |
| 226 // Set a non-blocking issue. The issue should stay hidden. |
| 227 container.issue = fakeNonBlockingIssue; |
| 228 setTimeout(function() { |
| 229 checkElementsVisibleWithId(['cast-mode-list', |
| 230 'container-header', |
| 231 'device-missing']); |
| 232 |
| 233 // Set a blocking issue. The issue should stay hidden. |
| 234 container.issue = fakeBlockingIssue; |
| 235 setTimeout(function() { |
| 236 checkElementsVisibleWithId(['container-header', |
| 237 'device-missing', |
| 238 'issue-banner']); |
| 239 done(); |
| 240 }); |
| 241 }); |
| 242 }); |
| 243 }); |
| 244 |
| 245 // Tests for the expected visible UI when interacting with the first run |
| 246 // flow with cloud services preference. |
| 247 test('first run button visibility', function(done) { |
| 248 container.showFirstRunFlow = true; |
| 249 container.showFirstRunFlowCloudPref = true; |
| 250 |
| 251 setTimeout(function() { |
| 252 checkElementsVisibleWithId(['container-header', |
| 253 'device-missing', |
| 254 'first-run-flow', |
| 255 'first-run-flow-cloud-pref', |
| 256 'sink-list-view']); |
| 257 MockInteractions.tap(container.shadowRoot.getElementById( |
| 258 'first-run-button')); |
| 259 |
| 260 setTimeout(function() { |
| 261 checkElementsVisibleWithId(['container-header', |
| 262 'device-missing', |
| 263 'sink-list-view']); |
| 264 done(); |
| 265 }); |
| 266 }); |
| 267 }); |
| 268 |
| 269 // Tests that the sink list does not contain any sinks that are not |
| 270 // compatible with the selected cast mode and are not associated with a |
| 271 // route. |
| 272 test('sink list in user selected cast mode', function(done) { |
| 273 var newSinks = [ |
| 274 new media_router.Sink('sink id 10', 'Sink 10', null, null, |
| 275 media_router.SinkIconType.CAST, |
| 276 media_router.SinkStatus.ACTIVE, 0x4 | 0x8), |
| 277 new media_router.Sink('sink id 20', 'Sink 20', null, null, |
| 278 media_router.SinkIconType.CAST, |
| 279 media_router.SinkStatus.ACTIVE, 0x2 | 0x4 | 0x8), |
| 280 new media_router.Sink('sink id 30', 'Sink 30', null, null, |
| 281 media_router.SinkIconType.CAST, |
| 282 media_router.SinkStatus.PENDING, 0x4 | 0x8), |
| 283 ]; |
| 284 |
| 285 container.allSinks = newSinks; |
| 286 container.routeList = [ |
| 287 new media_router.Route('id 1', 'sink id 30', |
| 288 'Title 1', 1, false, false), |
| 289 ]; |
| 290 |
| 291 setTimeout(function() { |
| 292 var sinkList = |
| 293 container.$['sink-list'].querySelectorAll('paper-item'); |
| 294 |
| 295 // Since we haven't selected a cast mode, we don't filter sinks. |
| 296 assertEquals(3, sinkList.length); |
| 297 |
| 298 MockInteractions.tap(container.$['container-header']. |
| 299 $['arrow-drop-icon']); |
| 300 setTimeout(function() { |
| 301 // Cast mode 1 is selected, and the sink list is filtered. |
| 302 var castModeList = |
| 303 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 304 MockInteractions.tap(castModeList[1]); |
| 305 assertEquals(fakeCastModeList[1].description, container.headerText); |
| 306 assertEquals(fakeCastModeList[1].type, |
| 307 container.shownCastModeValue_); |
| 308 |
| 309 setTimeout(function() { |
| 310 var sinkList = |
| 311 container.$['sink-list'].querySelectorAll('paper-item'); |
| 312 |
| 313 // newSinks[0] got filtered out since it is not compatible with |
| 314 // cast mode 1. |
| 315 // 'Sink 20' should be on the list because it contains the |
| 316 // selected cast mode. (sinkList[0] = newSinks[1]) |
| 317 // 'Sink 30' should be on the list because it has a route. |
| 318 // (sinkList[1] = newSinks[2]) |
| 319 assertEquals(2, sinkList.length); |
| 320 checkElementText(newSinks[1].name, sinkList[0]); |
| 321 |
| 322 // |sinkList[1]| contains route title in addition to sink name. |
| 323 assertTrue(sinkList[1].textContent.trim().startsWith( |
| 324 newSinks[2].name.trim())); |
| 325 |
| 326 // Cast mode is not switched back even if there are no sinks |
| 327 // compatible with selected cast mode, because we explicitly |
| 328 // selected that cast mode. |
| 329 container.allSinks = []; |
| 330 setTimeout(function() { |
| 331 assertEquals(fakeCastModeList[1].description, |
| 332 container.headerText); |
| 333 assertEquals(fakeCastModeList[1].type, |
| 334 container.shownCastModeValue_); |
| 335 var sinkList = |
| 336 container.$['sink-list'].querySelectorAll('paper-item'); |
| 337 assertEquals(0, sinkList.length); |
| 338 done(); |
| 339 }); |
| 340 }); |
| 341 }); |
| 342 }); |
| 343 }); |
| 344 |
| 345 // If the container is not in auto mode, and the mode it is currently in |
| 346 // no longer exists in the list of cast modes, then switch back to auto |
| 347 // mode. |
| 348 test('cast mode list updated in selected cast mode', function(done) { |
| 349 assertEquals(media_router.AUTO_CAST_MODE.description, |
| 350 container.headerText); |
| 351 assertEquals(media_router.CastModeType.AUTO, |
| 352 container.shownCastModeValue_); |
| 353 assertFalse(container.userHasSelectedCastMode_); |
| 354 |
| 355 MockInteractions.tap(container.$['container-header']. |
| 356 $['arrow-drop-icon']); |
| 357 setTimeout(function() { |
| 358 var castModeList = |
| 359 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 360 MockInteractions.tap(castModeList[0]); |
| 361 setTimeout(function() { |
| 362 assertEquals(fakeCastModeList[0].description, container.headerText); |
| 363 assertEquals(fakeCastModeList[0].type, |
| 364 container.shownCastModeValue_); |
| 365 assertTrue(container.userHasSelectedCastMode_); |
| 366 container.castModeList = fakeCastModeList.slice(1); |
| 367 setTimeout(function() { |
| 368 assertEquals(media_router.AUTO_CAST_MODE.description, |
| 369 container.headerText); |
| 370 assertEquals(media_router.CastModeType.AUTO, |
| 371 container.shownCastModeValue_); |
| 372 assertFalse(container.userHasSelectedCastMode_); |
| 373 done(); |
| 374 }); |
| 375 }); |
| 376 }); |
| 377 }); |
| 378 |
| 379 test('creating route with selected cast mode', function(done) { |
| 380 container.allSinks = fakeSinkList; |
| 381 MockInteractions.tap(container.$['container-header']. |
| 382 $['arrow-drop-icon']); |
| 383 setTimeout(function() { |
| 384 // Select cast mode 2. |
| 385 var castModeList = |
| 386 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 387 MockInteractions.tap(castModeList[1]); |
| 388 assertEquals(fakeCastModeList[1].description, container.headerText); |
| 389 setTimeout(function() { |
| 390 var sinkList = |
| 391 container.$['sink-list'].querySelectorAll('paper-item'); |
| 392 container.addEventListener('create-route', function(data) { |
| 393 assertEquals(fakeSinkList[2].id, data.detail.sinkId); |
| 394 // Cast mode 2 is used, since we selected it explicitly. |
| 395 assertEquals(fakeCastModeList[1].type, |
| 396 data.detail.selectedCastModeValue); |
| 397 done(); |
| 398 }); |
| 399 // All sinks are compatible with cast mode 2. |
| 400 assertEquals(fakeSinkList.length, sinkList.length); |
| 401 // Tap on a sink without a route, which should fire a 'create-route' |
| 402 // event. |
| 403 MockInteractions.tap(sinkList[2]); |
| 404 }); |
| 405 }); |
| 406 }); |
| 407 |
| 408 // Tests that after a different cast mode is selected, the sink list will |
| 409 // change based on the sinks compatibility with the new cast mode. |
| 410 test('changing cast mode changes sink list', function(done) { |
| 411 container.allSinks = fakeSinkList; |
| 412 |
| 413 MockInteractions.tap(container.$['container-header']. |
| 414 $['arrow-drop-icon']); |
| 415 setTimeout(function() { |
| 416 var castModeList = |
| 417 container.$$('#cast-mode-list').querySelectorAll('paper-item'); |
| 418 MockInteractions.tap(castModeList[0]); |
| 419 assertEquals(fakeCastModeList[0].description, container.headerText); |
| 420 |
| 421 setTimeout(function() { |
| 422 var sinkList = |
| 423 container.$['sink-list'].querySelectorAll('paper-item'); |
| 424 |
| 425 // The sink list is empty because none of the sinks in fakeSinkList |
| 426 // is compatible with cast mode 0. |
| 427 assertEquals(0, sinkList.length); |
| 428 MockInteractions.tap(castModeList[2]); |
| 429 assertEquals(fakeCastModeList[2].description, container.headerText); |
| 430 |
| 431 setTimeout(function() { |
| 432 var sinkList = |
| 433 container.$['sink-list'].querySelectorAll('paper-item'); |
| 434 assertEquals(3, sinkList.length); |
| 435 done(); |
| 436 }); |
| 437 }); |
| 438 }); |
| 439 }); |
| 440 }); |
| 441 } |
| 442 |
| 443 return { |
| 444 registerTests: registerTests, |
| 445 }; |
| 446 }); |
| OLD | NEW |