Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/test/data/webui/media_router/media_router_container_route_tests.js

Issue 2068593002: [Media Router] Assign each route a current cast mode if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @fileoverview Suite of tests for media-router-container that focus on 5 /** @fileoverview Suite of tests for media-router-container that focus on
6 * routes. 6 * routes.
7 */ 7 */
8 cr.define('media_router_container_route', function() { 8 cr.define('media_router_container_route', function() {
9 function registerTests() { 9 function registerTests() {
10 suite('MediaRouterContainerRoute', function() { 10 suite('MediaRouterContainerRoute', function() {
11 /** 11 /**
12 * Checks whether |view| matches the current view of |container|. 12 * Checks whether |view| matches the current view of |container|.
13 * 13 *
14 * @param {!media_router.MediaRouterView} view Expected view type. 14 * @param {!media_router.MediaRouterView} view Expected view type.
15 */ 15 */
16 var checkCurrentView; 16 var checkCurrentView;
17 17
18 /** 18 /**
19 * Checks whether the elements specified in |elementIdList| are visible. 19 * Checks whether the elements specified in |elementIdList| are visible.
20 * Checks whether all other elements are not visible. Throws an assertion 20 * Checks whether all other elements are not visible. Throws an assertion
21 * error if this is not true. 21 * error if this is not true.
22 * 22 *
23 * @param {!Array<!string>} elementIdList List of id's of elements that 23 * @param {!Array<!string>} elementIdList List of id's of elements that
24 * should be visible. 24 * should be visible.
25 */ 25 */
26 var checkElementsVisibleWithId; 26 var checkElementsVisibleWithId;
27 27
28 /** 28 /**
29 * Checks the visibility of an element. An element is considered visible
30 * if it exists and its |hidden| property is |false|.
31 *
32 * @param {boolean} visible Whether the element should be visible.
33 * @param {?Element} element The element to test.
34 * @param {elementId=} elementId Optional element id to display.
35 */
36 var checkElementVisible;
37
38 /**
29 * Checks whether |expected| and the text in the |element| are equal. 39 * Checks whether |expected| and the text in the |element| are equal.
30 * 40 *
31 * @param {!string} expected Expected text. 41 * @param {!string} expected Expected text.
32 * @param {!Element} element Element whose text will be checked. 42 * @param {!Element} element Element whose text will be checked.
33 */ 43 */
34 var checkElementText; 44 var checkElementText;
35 45
36 /** 46 /**
37 * Media Router Container created before each test. 47 * Media Router Container created before each test.
38 * @type {?MediaRouterContainer} 48 * @type {?MediaRouterContainer}
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 PolymerTest.clearBody(); 90 PolymerTest.clearBody();
81 // Initialize a media-router-container before each test. 91 // Initialize a media-router-container before each test.
82 container = document.createElement('media-router-container'); 92 container = document.createElement('media-router-container');
83 document.body.appendChild(container); 93 document.body.appendChild(container);
84 94
85 // Get common functions and variables. 95 // Get common functions and variables.
86 var test_base = media_router_container_test_base.init(container); 96 var test_base = media_router_container_test_base.init(container);
87 97
88 checkCurrentView = test_base.checkCurrentView; 98 checkCurrentView = test_base.checkCurrentView;
89 checkElementsVisibleWithId = test_base.checkElementsVisibleWithId; 99 checkElementsVisibleWithId = test_base.checkElementsVisibleWithId;
100 checkElementVisible = test_base.checkElementVisible;
90 checkElementText = test_base.checkElementText; 101 checkElementText = test_base.checkElementText;
91 fakeBlockingIssue = test_base.fakeBlockingIssue; 102 fakeBlockingIssue = test_base.fakeBlockingIssue;
92 fakeCastModeList = test_base.fakeCastModeList; 103 fakeCastModeList = test_base.fakeCastModeList;
93 fakeNonBlockingIssue = test_base.fakeNonBlockingIssue; 104 fakeNonBlockingIssue = test_base.fakeNonBlockingIssue;
94 fakeRouteList = test_base.fakeRouteList; 105 fakeRouteList = test_base.fakeRouteList;
95 fakeRouteListWithLocalRoutesOnly = 106 fakeRouteListWithLocalRoutesOnly =
96 test_base.fakeRouteListWithLocalRoutesOnly; 107 test_base.fakeRouteListWithLocalRoutesOnly;
97 fakeSinkList = test_base.fakeSinkList; 108 fakeSinkList = test_base.fakeSinkList;
98 109
99 container.castModeList = test_base.fakeCastModeList; 110 container.castModeList = test_base.fakeCastModeList;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 done(); 344 done();
334 }); 345 });
335 // All sinks are compatible with cast mode 2. 346 // All sinks are compatible with cast mode 2.
336 assertEquals(fakeSinkList.length, sinkList.length); 347 assertEquals(fakeSinkList.length, sinkList.length);
337 // Tap on a sink without a route, which should fire a 348 // Tap on a sink without a route, which should fire a
338 // 'create-route' event. 349 // 'create-route' event.
339 MockInteractions.tap(sinkList[2]); 350 MockInteractions.tap(sinkList[2]);
340 }); 351 });
341 }); 352 });
342 }); 353 });
354
355 // Tests that the route details cast button is not shown when another sink
356 // is launching.
357 test('no cast button when sink launching', function(done) {
358 container.allSinks = fakeSinkList;
359 container.routeList = fakeRouteList;
360 setTimeout(function() {
361 var sinkList =
362 container.$$('#sink-list').querySelectorAll('paper-item');
363 MockInteractions.tap(sinkList[2]);
364 setTimeout(function() {
365 assertTrue(!!container.currentLaunchingSinkId_);
366 MockInteractions.tap(sinkList[0]);
367 setTimeout(function() {
368 checkElementVisible(
369 false, container.$$('#route-details')
370 .$$('#start-casting-to-route-button'),
371 'start-casting-to-route-button');
372 // The other sink stopped launching, due to route failure, so the
373 // cast button should now appear.
374 container.onCreateRouteResponseReceived(fakeSinkList[0].id, null,
375 true);
376 setTimeout(function() {
377 checkElementVisible(
378 true, container.$$('#route-details')
379 .$$('#start-casting-to-route-button'),
380 'start-casting-to-route-button');
381 done();
382 });
383 });
384 });
385 });
386 });
387
388 // Tests that the route details cast button is shown when the current
389 // route has no |currentCastMode| field defined.
390 test('cast button when no current cast mode', function(done) {
391 container.allSinks = fakeSinkList;
392 container.routeList = fakeRouteList;
393 setTimeout(function() {
394 assertTrue(!container.currentLaunchingSinkId_);
395 MockInteractions.tap(
396 container.$$('#sink-list').querySelectorAll('paper-item')[0]);
397 setTimeout(function() {
398 assertEquals(undefined, container.currentRoute_.currentCastMode);
399 checkElementVisible(
400 true, container.$$('#route-details')
401 .$$('#start-casting-to-route-button'),
402 'start-casting-to-route-button');
403 done();
404 });
405 });
406 });
407
408 // Tests that the route details cast button is shown when the user has
409 // selected a cast mode that is different from the current cast mode of
410 // the route.
411 test('cast button when selected cast mode differs', function(done) {
412 container.allSinks = fakeSinkList;
413 container.routeList = fakeRouteList;
414 container.castModeList = fakeCastModeList;
415 for (var i = 0; i < fakeRouteList.length; ++i) {
416 fakeRouteList[i].currentCastMode = 2;
417 }
418 MockInteractions.tap(
419 container.$['container-header'].$['arrow-drop-icon']);
420 setTimeout(function() {
421 MockInteractions.tap(container.$$('#cast-mode-list')
422 .querySelectorAll('paper-item')[2]);
423 setTimeout(function() {
424 assertTrue(container.shownCastModeValue_ != 2);
425 MockInteractions.tap(
426 container.$$('#sink-list').querySelectorAll('paper-item')[0]);
427 setTimeout(function() {
428 checkElementVisible(
429 true, container.$$('#route-details')
430 .$$('#start-casting-to-route-button'),
431 'start-casting-to-route-button');
432 done();
433 });
434 });
435 });
436 });
437
438 // Tests that the route details cast button is not shown when the user has
439 // selected a the same cast mode as the route's current cast mode.
440 test('no cast button when selected cast mode same', function(done) {
441 container.allSinks = fakeSinkList;
442 container.routeList = fakeRouteList;
443 container.castModeList = fakeCastModeList;
444 for (var i = 0; i < fakeRouteList.length; ++i) {
445 fakeRouteList[i].currentCastMode = 2;
446 }
447 MockInteractions.tap(
448 container.$['container-header'].$['arrow-drop-icon']);
449 setTimeout(function() {
450 MockInteractions.tap(container.$$('#cast-mode-list')
451 .querySelectorAll('paper-item')[1]);
452 setTimeout(function() {
453 assertEquals(2, container.shownCastModeValue_);
454 MockInteractions.tap(
455 container.$$('#sink-list').querySelectorAll('paper-item')[0]);
456 setTimeout(function() {
457 checkElementVisible(
458 false, container.$$('#route-details')
459 .$$('#start-casting-to-route-button'),
460 'start-casting-to-route-button');
461 done();
462 });
463 });
464 });
465 });
466
467 // Tests that the route details cast button is not shown when AUTO cast
468 // mode would pick the same cast mode for the route's sink as the route's
469 // current cast mode.
470 test('no cast button when auto cast mode same', function(done) {
471 container.allSinks = fakeSinkList;
472 container.routeList = fakeRouteList;
473 container.castModeList = fakeCastModeList;
474 for (var i = 0; i < fakeRouteList.length; ++i) {
475 // The lowest cast mode value will be used in AUTO mode. We set it on
476 // the route here so AUTO mode matches the route's current cast mode.
477 fakeRouteList[i].currentCastMode = 2;
478 }
479 setTimeout(function() {
480 assertEquals(-1, container.shownCastModeValue_);
481 MockInteractions.tap(
482 container.$$('#sink-list').querySelectorAll('paper-item')[0]);
483 setTimeout(function() {
484 checkElementVisible(
485 false, container.$$('#route-details')
486 .$$('#start-casting-to-route-button'),
487 'start-casting-to-route-button');
488 done();
489 });
490 });
491 });
492
493 // Tests that the route details cast button is not shown when there is no
494 // sink structure in the container that corresponds to the route whose
495 // details are being viewed. This occurs when there is only one local
496 // route, so it is shown upon opening the dialog, and its sink isn't
497 // compatible with any currently available cast modes.
498 test('no cast button when sink missing', function(done) {
499 container.routeList = fakeRouteList;
500 // Simulate opening dialog with a local route for sink that is
501 // unsupported in the current context, and therefore won't be in the
502 // container's sink list.
503 container.showRouteDetails_(fakeRouteList[0]);
504 setTimeout(function() {
505 checkElementVisible(
506 false, container.$$('#route-details')
507 .$$('#start-casting-to-route-button'),
508 'start-casting-to-route-button');
509 done();
510 });
511 });
343 }); 512 });
344 } 513 }
345 514
346 return { 515 return {
347 registerTests: registerTests, 516 registerTests: registerTests,
348 }; 517 };
349 }); 518 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698