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