Chromium Code Reviews| 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', function() { | |
| 7 function registerTests() { | |
| 8 suite('MediaRouterContainer', 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 blocking issue to show. | |
| 29 * @type {?media_router.Issue} | |
| 30 */ | |
| 31 var fakeNonBlockingIssue; | |
| 32 | |
| 33 /** | |
| 34 * The list of current routes. | |
| 35 * @type {!Array<!media_router.Route>} | |
| 36 */ | |
| 37 var fakeRouteList = []; | |
| 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-header-text', | |
| 51 'cast-mode-list', | |
| 52 'container-header', | |
| 53 'device-missing', | |
| 54 'issue-banner', | |
| 55 'route-details', | |
| 56 'sink-list', | |
| 57 'sink-list-header-text', | |
| 58 'sink-list-view', | |
| 59 ]; | |
| 60 | |
| 61 // Checks whether the current icon matches the icon used for the view. | |
| 62 var checkArrowDropIcon = function(view) { | |
| 63 assertEquals(container.computeArrowDropIcon_(view), | |
| 64 container.$['arrow-drop-icon'].icon); | |
| 65 }; | |
| 66 | |
| 67 // Checks whether |view| matches the current view of |container|. | |
| 68 var checkCurrentView = function(view) { | |
| 69 assertEquals(view, container.currentView_); | |
| 70 }; | |
| 71 | |
| 72 // Checks whether the elements specified in |elementIdList| are visible. | |
| 73 // Checks whether all other elements are hidden. | |
| 74 var checkElementsVisibleWithId = function(elementIdList) { | |
| 75 for (var i = 0; i < elementIdList.length; i++) | |
| 76 checkElementHidden(false, container.$[elementIdList[i]]); | |
| 77 | |
| 78 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { | |
| 79 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) | |
| 80 checkElementHidden(true, container.$[hiddenCheckElementIdList[j]]); | |
| 81 } | |
| 82 }; | |
| 83 | |
| 84 // Checks whether |element| is hidden. | |
| 85 var checkElementHidden = function(hidden, element) { | |
| 86 assertEquals(hidden, element.hidden); | |
| 87 }; | |
| 88 | |
| 89 // Checks whether |expected| and the text in the |elementId| element | |
| 90 // are equal. | |
| 91 var checkElementText = function(expected, element) { | |
| 92 assertEquals(expected.trim(), element.textContent.trim()); | |
| 93 }; | |
| 94 | |
| 95 // Checks whether |expected| and the text in the |elementId| element | |
| 96 // are equal given an id. | |
| 97 var checkElementTextWithId = function(expected, elementId) { | |
| 98 checkElementText(expected, container.$[elementId]); | |
| 99 }; | |
| 100 | |
| 101 // Import media_router_container.html before running suite. | |
| 102 suiteSetup(function() { | |
| 103 return PolymerTest.importHtml( | |
| 104 'chrome://media-router/elements/media_router_container/' + | |
| 105 'media_router_container.html'); | |
| 106 }); | |
| 107 | |
| 108 // Initialize an issue-banner before each test. | |
| 109 setup(function(done) { | |
| 110 PolymerTest.clearBody(); | |
| 111 container = document.createElement('media-router-container'); | |
| 112 document.body.appendChild(container); | |
| 113 | |
| 114 // Initialize local variables. | |
| 115 fakeCastModeList = [ | |
| 116 new media_router.CastMode(1, 'Cast Mode 1', 'Description 1'), | |
| 117 new media_router.CastMode(2, 'Cast Mode 2', 'Description 2'), | |
| 118 new media_router.CastMode(3, 'Cast Mode 3', 'Description 3'), | |
| 119 ]; | |
| 120 | |
| 121 fakeRouteList = [ | |
| 122 new media_router.Route('id 1', 'sink id 1', 'Title 1', true), | |
| 123 new media_router.Route('id 2', 'sink id 2', 'Title 2', false), | |
| 124 ]; | |
| 125 | |
| 126 fakeSinkList = [ | |
| 127 new media_router.Sink('sink id 1', 'Sink 1', | |
| 128 media_router.SinkStatus.ACTIVE, [1, 2, 3]), | |
| 129 new media_router.Sink('sink id 2', 'Sink 2', | |
| 130 media_router.SinkStatus.ACTIVE, [1, 2, 3]), | |
| 131 new media_router.Sink('sink id 3', 'Sink 3', | |
| 132 media_router.SinkStatus.PENDING, [1, 2, 3]), | |
| 133 ]; | |
| 134 | |
| 135 fakeBlockingIssue = new media_router.Issue( | |
| 136 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, | |
| 137 'route id 1', true, 1234); | |
| 138 | |
| 139 fakeNonBlockingIssue = new media_router.Issue( | |
| 140 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, | |
| 141 'route id 2', false, 1234); | |
| 142 | |
| 143 // Allow for the media router container to be created and attached. | |
| 144 setTimeout(done); | |
| 145 }); | |
| 146 | |
| 147 // Tests for 'close-button-click' event firing when the close button | |
| 148 // is clicked. | |
| 149 test('close button click', function(done) { | |
| 150 container.addEventListener('close-button-click', function() { | |
| 151 done(); | |
| 152 }); | |
| 153 MockInteractions.tap(container.$['close-button']); | |
| 154 }); | |
| 155 | |
| 156 // Tests for 'create-route' event firing when a sink with no associated | |
| 157 // route is clicked. | |
| 158 test('select sink without a route', function(done) { | |
| 159 container.sinkList = fakeSinkList; | |
| 160 | |
| 161 setTimeout(function() { | |
| 162 var sinkList = | |
| 163 container.$['sink-list'].querySelectorAll('paper-item'); | |
| 164 | |
| 165 container.addEventListener('create-route', function(data) { | |
| 166 assertEquals(fakeSinkList[2].id, data.detail.sinkId); | |
| 167 assertEquals(container.selectedCastModeValue_, | |
| 168 data.detail.selectedCastModeValue); | |
| 169 done(); | |
| 170 }); | |
| 171 | |
| 172 // Tap on a sink without a route, which should fire a 'create-route' | |
| 173 // event. | |
| 174 MockInteractions.tap(sinkList[2]); | |
| 175 }); | |
| 176 }); | |
| 177 | |
| 178 // Tests that selecting a sink with an associated route will make the | |
| 179 // |container| switch to ROUTE_DETAILS view. | |
| 180 test('select sink with a route', function(done) { | |
| 181 container.sinkList = fakeSinkList; | |
| 182 container.routeList = fakeRouteList; | |
| 183 | |
| 184 setTimeout(function() { | |
| 185 var sinkList = | |
| 186 container.$['sink-list'].querySelectorAll('paper-item'); | |
| 187 | |
| 188 checkCurrentView(container.CONTAINER_VIEW_.SINK_LIST); | |
| 189 MockInteractions.tap(sinkList[0]); | |
| 190 checkCurrentView(container.CONTAINER_VIEW_.ROUTE_DETAILS); | |
| 191 done(); | |
| 192 }); | |
| 193 }); | |
| 194 | |
| 195 // Tests that |container| returns to SINK_LIST view and arrow drop icon | |
| 196 // toggles after a cast mode is selected. | |
| 197 test('select cast mode', function(done) { | |
| 198 container.castModeList = fakeCastModeList; | |
| 199 | |
| 200 MockInteractions.tap(container.$['arrow-drop-icon']); | |
| 201 checkArrowDropIcon(container.CONTAINER_VIEW_.CAST_MODE_LIST); | |
| 202 checkCurrentView(container.CONTAINER_VIEW_.CAST_MODE_LIST); | |
| 203 | |
| 204 setTimeout(function() { | |
| 205 var castModeList = | |
| 206 container.$['cast-mode-list'].querySelectorAll('paper-item'); | |
| 207 | |
| 208 MockInteractions.tap(castModeList[2]); | |
| 209 checkArrowDropIcon(container.CONTAINER_VIEW_.SINK_LIST); | |
| 210 checkCurrentView(container.CONTAINER_VIEW_.SINK_LIST); | |
| 211 done(); | |
| 212 }); | |
| 213 }); | |
| 214 | |
| 215 // Tests that clicking on the drop down icon will toggle |container| | |
| 216 // between SINK_LIST and CAST_MODE_LIST views. | |
| 217 test('click drop down icon', function() { | |
| 218 checkCurrentView(container.CONTAINER_VIEW_.SINK_LIST); | |
| 219 | |
| 220 MockInteractions.tap(container.$['arrow-drop-icon']); | |
| 221 checkArrowDropIcon(container.CONTAINER_VIEW_.CAST_MODE_LIST); | |
| 222 checkCurrentView(container.CONTAINER_VIEW_.CAST_MODE_LIST); | |
| 223 | |
| 224 MockInteractions.tap(container.$['arrow-drop-icon']); | |
| 225 checkArrowDropIcon(container.CONTAINER_VIEW_.SINK_LIST); | |
| 226 checkCurrentView(container.CONTAINER_VIEW_.SINK_LIST); | |
| 227 }); | |
| 228 | |
| 229 // Tests the |computeArrowDropIcon_| function. | |
| 230 test('compute arrow drop icon', function() { | |
| 231 assertEquals('arrow-drop-up', | |
| 232 container.computeArrowDropIcon_( | |
| 233 container.CONTAINER_VIEW_.CAST_MODE_LIST)); | |
| 234 assertEquals('arrow-drop-down', | |
| 235 container.computeArrowDropIcon_( | |
| 236 container.CONTAINER_VIEW_.ROUTE_DETAILS)); | |
| 237 assertEquals('arrow-drop-down', | |
| 238 container.computeArrowDropIcon_( | |
| 239 container.CONTAINER_VIEW_.SINK_LIST)); | |
| 240 }); | |
|
Dan Beam
2015/07/10 22:29:43
so what happens when you don't take a |done| callb
apacible
2015/07/10 23:25:29
It depends on the test. Here are the different typ
Dan Beam
2015/07/10 23:56:13
tl;dr - mocha uses Function.prototype.length to de
apacible
2015/07/11 00:49:58
Acknowledged dark magic.
| |
| 241 | |
| 242 // Tests the header text. Choosing a cast mode updates the header text. | |
| 243 test('header text', function(done) { | |
| 244 checkElementTextWithId(loadTimeData.getString('selectCastModeHeader'), | |
| 245 'cast-mode-header-text'); | |
| 246 | |
| 247 var fakeHeaderText = 'fake header text'; | |
| 248 container.headerText = fakeHeaderText; | |
| 249 checkElementTextWithId(fakeHeaderText, 'sink-list-header-text'); | |
| 250 | |
| 251 // Set the cast mode list to update the header text when one is | |
| 252 // selected. | |
| 253 container.castModeList = fakeCastModeList; | |
| 254 | |
| 255 setTimeout(function() { | |
| 256 var castModeList = | |
| 257 container.$['cast-mode-list'].querySelectorAll('paper-item'); | |
| 258 | |
| 259 for (var i = 0; i < fakeCastModeList.length; i++) { | |
| 260 MockInteractions.tap(castModeList[i]); | |
| 261 checkElementTextWithId(fakeCastModeList[i].title, | |
| 262 'sink-list-header-text'); | |
| 263 checkElementText(fakeCastModeList[i].description, castModeList[i]); | |
| 264 } | |
| 265 done(); | |
| 266 }); | |
| 267 }); | |
| 268 | |
| 269 // Tests that text shown for each sink matches their names. | |
| 270 test('sink list text', function(done) { | |
| 271 container.sinkList = fakeSinkList; | |
| 272 | |
| 273 setTimeout(function() { | |
| 274 var sinkList = | |
| 275 container.$['sink-list'].querySelectorAll('paper-item'); | |
| 276 | |
| 277 for (var i = 0; i < fakeSinkList.length; i++) { | |
| 278 checkElementText(fakeSinkList[i].name, sinkList[i]); | |
| 279 } | |
| 280 done(); | |
| 281 }); | |
| 282 }); | |
| 283 | |
| 284 // Tests the text shown for the sink list. | |
| 285 test('initial sink list route text', function(done) { | |
| 286 container.sinkList = fakeSinkList; | |
| 287 container.routeList = fakeRouteList; | |
| 288 | |
| 289 setTimeout(function() { | |
| 290 var routeList = | |
| 291 container.$['sink-list'].querySelectorAll('.route'); | |
| 292 | |
| 293 checkElementText(fakeRouteList[0].title, routeList[0]); | |
| 294 checkElementText(fakeRouteList[1].title, routeList[1]); | |
| 295 checkElementText('', routeList[2]); | |
| 296 done(); | |
| 297 }); | |
| 298 }); | |
| 299 | |
| 300 // Tests the visibility of routes in the sink list. | |
| 301 test('initial route visibility', function(done) { | |
| 302 container.sinkList = fakeSinkList; | |
| 303 container.routeList = fakeRouteList; | |
| 304 | |
| 305 setTimeout(function() { | |
| 306 var routeList = | |
| 307 container.$['sink-list'].querySelectorAll('.route'); | |
| 308 | |
| 309 checkElementHidden(false, routeList[0]); | |
| 310 checkElementHidden(false, routeList[1]); | |
| 311 checkElementHidden(true, routeList[2]); | |
| 312 done(); | |
| 313 }); | |
| 314 }); | |
| 315 | |
| 316 // Tests for expected visible UI when the view is CAST_MODE_LIST. | |
| 317 test('cast mode list state visibility', function() { | |
| 318 container.showCastModeList_(); | |
| 319 checkElementsVisibleWithId(['cast-mode-header-text', | |
| 320 'cast-mode-list', | |
| 321 'container-header', | |
| 322 'device-missing', | |
| 323 'sink-list']); | |
| 324 | |
| 325 // Set a non-blocking issue. The issue should stay hidden. | |
| 326 container.issue = fakeNonBlockingIssue; | |
| 327 checkElementsVisibleWithId(['cast-mode-header-text', | |
| 328 'cast-mode-list', | |
| 329 'container-header', | |
| 330 'device-missing', | |
| 331 'sink-list']); | |
| 332 | |
| 333 // Set a blocking issue. The issue should stay hidden. | |
| 334 container.issue = fakeBlockingIssue; | |
| 335 checkElementsVisibleWithId(['cast-mode-header-text', | |
| 336 'cast-mode-list', | |
| 337 'container-header', | |
| 338 'device-missing', | |
| 339 'sink-list']); | |
| 340 }); | |
| 341 | |
| 342 // Tests for expected visible UI when the view is ROUTE_DETAILS. | |
| 343 test('route details state visibility', function() { | |
| 344 container.showRouteDetails_(); | |
| 345 checkElementsVisibleWithId(['device-missing', | |
| 346 'route-details', | |
| 347 'sink-list']); | |
| 348 | |
| 349 // Set a non-blocking issue. The issue should be shown. | |
| 350 container.issue = fakeNonBlockingIssue; | |
| 351 checkElementsVisibleWithId(['device-missing', | |
| 352 'issue-banner', | |
| 353 'route-details', | |
| 354 'sink-list']); | |
| 355 | |
| 356 // Set a blocking issue. The issue should be shown, and everything | |
| 357 // else, hidden. | |
| 358 container.issue = fakeBlockingIssue; | |
| 359 checkElementsVisibleWithId(['device-missing', | |
| 360 'issue-banner', | |
| 361 'sink-list']); | |
| 362 }); | |
| 363 | |
| 364 // Tests for expected visible UI when the view is SINK_LIST. | |
| 365 test('sink list state visibility', function() { | |
| 366 container.showSinkList_(); | |
| 367 checkElementsVisibleWithId(['container-header', | |
| 368 'device-missing', | |
| 369 'sink-list', | |
| 370 'sink-list-header-text', | |
| 371 'sink-list-view']); | |
| 372 | |
| 373 // Set an non-empty sink list. | |
| 374 container.sinkList = fakeSinkList; | |
| 375 checkElementsVisibleWithId(['container-header', | |
| 376 'sink-list', | |
| 377 'sink-list-header-text', | |
| 378 'sink-list-view']); | |
| 379 | |
| 380 // Set a non-blocking issue. The issue should be shown. | |
| 381 container.issue = fakeNonBlockingIssue; | |
| 382 checkElementsVisibleWithId(['container-header', | |
| 383 'issue-banner', | |
| 384 'sink-list', | |
| 385 'sink-list-header-text', | |
| 386 'sink-list-view']); | |
| 387 | |
| 388 // Set a blocking issue. The issue should be shown, and everything | |
| 389 // else, hidden. | |
| 390 container.issue = fakeBlockingIssue; | |
| 391 checkElementsVisibleWithId(['issue-banner', | |
| 392 'sink-list']); | |
|
Dan Beam
2015/07/10 22:29:43
probably fits on one line
apacible
2015/07/10 23:25:29
Done.
| |
| 393 }); | |
| 394 }); | |
| 395 } | |
| 396 | |
| 397 return { | |
| 398 registerTests: registerTests, | |
| 399 }; | |
| 400 }); | |
| OLD | NEW |