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

Unified Diff: chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js

Issue 1766473002: [Media Router] Further split media_router_container tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Logical test file split Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js
diff --git a/chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js b/chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js
new file mode 100644
index 0000000000000000000000000000000000000000..6e9607d0f8b1ea5b6d7db2d8bedddfda063d39b5
--- /dev/null
+++ b/chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js
@@ -0,0 +1,336 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @fileoverview Suite of tests for media-router-container. */
+cr.define('media_router_container_sink_list', function() {
+ function registerTests() {
+ suite('MediaRouterContainerSinkList', function() {
+ /**
+ * Media Router Container created before each test.
+ * @type {MediaRouterContainer}
+ */
+ var container;
+
+ /**
+ * The blocking issue to show.
+ * @type {?media_router.Issue}
+ */
+ var fakeBlockingIssue;
+
+ /**
+ * The list of CastModes to show.
+ * @type {!Array<!media_router.CastMode>}
+ */
+ var fakeCastModeList = [];
+
+ /**
+ * The blocking issue to show.
+ * @type {?media_router.Issue}
+ */
+ var fakeNonBlockingIssue;
+
+ /**
+ * The list of available sinks.
+ * @type {!Array<!media_router.Sink>}
+ */
+ var fakeSinkList = [];
+
+ /**
+ * The list of elements to check for visibility.
+ * @const {!Array<string>}
+ */
+ var hiddenCheckElementIdList = [
+ 'cast-mode-list',
+ 'container-header',
+ 'device-missing',
+ 'first-run-flow',
+ 'first-run-flow-cloud-pref',
+ 'issue-banner',
+ 'no-search-matches',
+ 'route-details',
+ 'search-results',
+ 'sink-list',
+ 'sink-list-view',
+ ];
+
+ // Checks whether the elements specified in |elementIdList| are visible.
+ // Checks whether all other elements are not visible.
+ var checkElementsVisibleWithId = function(elementIdList) {
+ for (var i = 0; i < elementIdList.length; i++)
+ checkElementVisibleWithId(true, elementIdList[i]);
+
+ for (var j = 0; j < hiddenCheckElementIdList.length; j++) {
+ if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1)
+ checkElementVisibleWithId(false, hiddenCheckElementIdList[j]);
+ }
+ };
+
+ // Checks the visibility of an element with |elementId| in |container|.
+ // An element is considered visible if it exists and its |hidden| property
+ // is |false|.
+ var checkElementVisibleWithId = function(visible, elementId) {
+ var element = container.$$('#' + elementId);
+ var elementVisible = !!element && !element.hidden &&
+ element.style.display != 'none';
+ assertEquals(visible, elementVisible, elementId);
+ };
+
+ // Checks whether |expected| and the text in the |element| are equal.
+ var checkElementText = function(expected, element) {
+ assertEquals(expected.trim(), element.textContent.trim());
+ };
+
+ // Import media_router_container.html before running suite.
+ suiteSetup(function() {
+ return PolymerTest.importHtml(
+ 'chrome://media-router/elements/media_router_container/' +
+ 'media_router_container.html');
+ });
+
+ // Initialize a media-router-container before each test.
+ setup(function(done) {
+ PolymerTest.clearBody();
+ container = document.createElement('media-router-container');
+ document.body.appendChild(container);
+
+ // Initialize local variables.
+ fakeCastModeList = [
+ new media_router.CastMode(0x1, 'Description 0', 'google.com'),
+ new media_router.CastMode(0x2, 'Description 1', null),
+ new media_router.CastMode(0x4, 'Description 2', null),
+ ];
+
+ fakeRouteListWithLocalRoutesOnly = [
+ new media_router.Route('id 1', 'sink id 1',
+ 'Title 1', 0, true, false),
+ new media_router.Route('id 2', 'sink id 2',
+ 'Title 2', 1, true, false),
+ ];
+
+ var castModeBitset = 0x2 | 0x4 | 0x8;
+ fakeSinkList = [
+ new media_router.Sink('sink id 1', 'Sink 1', null, null,
+ media_router.SinkIconType.CAST,
+ media_router.SinkStatus.ACTIVE, castModeBitset),
+ new media_router.Sink('sink id 2', 'Sink 2', null, null,
+ media_router.SinkIconType.CAST,
+ media_router.SinkStatus.ACTIVE, castModeBitset),
+ new media_router.Sink('sink id 3', 'Sink 3', null, null,
+ media_router.SinkIconType.CAST,
+ media_router.SinkStatus.PENDING, castModeBitset),
+ ];
+
+ fakeBlockingIssue = new media_router.Issue(
+ 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1,
+ 'route id 1', true, 1234);
+
+ fakeNonBlockingIssue = new media_router.Issue(
+ 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1,
+ 'route id 2', false, 1234);
+
+ container.castModeList = fakeCastModeList;
+
+ // Allow for the media router container to be created and attached.
+ setTimeout(done);
+ });
+
+ // Tests that text shown for each sink matches their names.
+ test('sink list text', function(done) {
+ container.allSinks = fakeSinkList;
+
+ setTimeout(function() {
+ var sinkList =
+ container.$['sink-list'].querySelectorAll('paper-item');
+ assertEquals(fakeSinkList.length, sinkList.length);
+ for (var i = 0; i < fakeSinkList.length; i++) {
+ checkElementText(fakeSinkList[i].name, sinkList[i]);
+ }
+ done();
+ });
+ });
+
+ // Tests that text shown for sink with domain matches the name and domain.
+ test('sink with domain text', function(done) {
+ // Sink 1 - sink, no domain -> text = name
+ // Sink 2 - sink, domain -> text = sink + domain
+ container.allSinks = [
+ new media_router.Sink('sink id 1', 'Sink 1', null, null,
+ media_router.SinkIconType.HANGOUT,
+ media_router.SinkStatus.ACTIVE, [1, 2, 3]),
+ new media_router.Sink('sink id 2', 'Sink 2',
+ null, 'example.com',
+ media_router.SinkIconType.HANGOUT,
+ media_router.SinkStatus.ACTIVE, [1, 2, 3]),
+ ];
+
+ container.showDomain = true;
+
+ setTimeout(function() {
+ var sinkList =
+ container.$['sink-list'].querySelectorAll('paper-item');
+ assertEquals(2, sinkList.length);
+
+ // |sinkList[0]| has sink name only.
+ checkElementText(container.allSinks[0].name, sinkList[0]);
+ // |sinkList[1]| contains sink name and domain.
+ assertTrue(sinkList[1].textContent.trim().startsWith(
+ container.allSinks[1].name.trim()));
+ assertTrue(sinkList[1].textContent.trim().indexOf(
+ container.allSinks[1].domain.trim()) != -1);
+ done();
+ });
+ });
+
+ // Tests that domain text is not shown when |showDomain| is false.
+ test('sink with domain text', function(done) {
+ // Sink 1 - sink, no domain -> text = name
+ // Sink 2 - sink, domain -> text = sink + domain
+ container.allSinks = [
+ new media_router.Sink('sink id 1', 'Sink 1', null, null,
+ media_router.SinkIconType.HANGOUT,
+ media_router.SinkStatus.ACTIVE, [1, 2, 3]),
+ new media_router.Sink('sink id 2', 'Sink 2',
+ null, 'example.com',
+ media_router.SinkIconType.HANGOUT,
+ media_router.SinkStatus.ACTIVE, [1, 2, 3]),
+ ];
+
+ container.showDomain = false;
+
+ setTimeout(function() {
+ var sinkList =
+ container.$['sink-list'].querySelectorAll('paper-item');
+ assertEquals(2, sinkList.length);
+
+ // |sinkList[0]| has sink name only.
+ checkElementText(container.allSinks[0].name, sinkList[0]);
+ // |sinkList[1]| has sink name but domain should be hidden.
+ checkElementText(container.allSinks[1].name, sinkList[1]);
+ assertTrue(sinkList[1].textContent.trim().indexOf(
+ container.allSinks[1].domain.trim()) == -1);
+ done();
+ });
+ });
+
+ // Tests for expected visible UI when the view is SINK_LIST.
+ test('sink list state visibility', function() {
+ container.showSinkList_();
+ checkElementsVisibleWithId(['container-header',
+ 'device-missing',
+ 'sink-list-view']);
+
+ // Set an non-empty sink list.
+ container.allSinks = fakeSinkList;
+ checkElementsVisibleWithId(['container-header',
+ 'sink-list',
+ 'sink-list-view']);
+ });
+
+ // Tests for expected visible UI when the view is SINK_LIST, and there is
+ // a non blocking issue.
+ test('sink list visibility non blocking issue', function(done) {
+ container.showSinkList_();
+
+ // Set an non-empty sink list.
+ container.allSinks = fakeSinkList;
+
+ // Set a non-blocking issue. The issue should be shown.
+ container.issue = fakeNonBlockingIssue;
+ setTimeout(function() {
+ checkElementsVisibleWithId(['container-header',
+ 'issue-banner',
+ 'sink-list',
+ 'sink-list-view']);
+ done();
+ });
+ });
+
+ // Tests for expected visible UI when the view is SINK_LIST, and there is
+ // a blocking issue.
+ test('sink list visibility blocking issue', function(done) {
+ container.showSinkList_();
+
+ // Set an non-empty sink list.
+ container.allSinks = fakeSinkList;
+
+ // Set a blocking issue. The issue should be shown, and everything
+ // else, hidden.
+ container.issue = fakeBlockingIssue;
+ setTimeout(function() {
+ checkElementsVisibleWithId(['container-header',
+ 'issue-banner',
+ 'sink-list']);
+ done();
+ });
+ });
+
+ // Tests all sinks are always shown in auto mode, and that the mode will
+ // switch if the sinks support only 1 cast mode.
+ test('sink list in auto mode', function(done) {
+ container.allSinks = fakeSinkList;
+ setTimeout(function() {
+ // Container is initially in auto mode since a cast mode has not been
+ // selected.
+ assertEquals(media_router.AUTO_CAST_MODE.description,
+ container.headerText);
+ assertEquals(media_router.CastModeType.AUTO,
+ container.shownCastModeValue_);
+ assertFalse(container.userHasSelectedCastMode_);
+ var sinkList =
+ container.$['sink-list'].querySelectorAll('paper-item');
+
+ // All sinks are shown in auto mode.
+ assertEquals(3, sinkList.length);
+
+ // When sink list changes to only 1 compatible cast mode, the mode is
+ // switched, and all sinks are shown.
+ container.allSinks = [
+ new media_router.Sink('sink id 10', 'Sink 10', null, null,
+ media_router.SinkIconType.CAST,
+ media_router.SinkStatus.ACTIVE, 0x4),
+ new media_router.Sink('sink id 20', 'Sink 20', null, null,
+ media_router.SinkIconType.CAST,
+ media_router.SinkStatus.ACTIVE, 0x4),
+ new media_router.Sink('sink id 30', 'Sink 30', null, null,
+ media_router.SinkIconType.CAST,
+ media_router.SinkStatus.PENDING, 0x4),
+ ];
+
+ setTimeout(function() {
+ assertEquals(fakeCastModeList[2].description, container.headerText);
+ assertEquals(fakeCastModeList[2].type,
+ container.shownCastModeValue_);
+ assertFalse(container.userHasSelectedCastMode_);
+
+ var sinkList =
+ container.$['sink-list'].querySelectorAll('paper-item');
+ assertEquals(3, sinkList.length);
+
+ // When compatible cast modes size is no longer exactly 1, switch
+ // back to auto mode, and all sinks are shown.
+ container.allSinks = fakeSinkList;
+ setTimeout(function() {
+ assertEquals(media_router.AUTO_CAST_MODE.description,
+ container.headerText);
+ assertEquals(media_router.CastModeType.AUTO,
+ container.shownCastModeValue_);
+ assertFalse(container.userHasSelectedCastMode_);
+ var sinkList =
+ container.$['sink-list'].querySelectorAll('paper-item');
+
+ // All sinks are shown in auto mode.
+ assertEquals(3, sinkList.length);
+
+ done();
+ });
+ });
+ });
+ });
+ });
+ }
+
+ return {
+ registerTests: registerTests,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698