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