| 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 Provides basic utility functions and variables for |
| 6 * media-router-container tests. |
| 7 */ |
| 8 |
| 9 cr.define('media_router_container_test_base', function() { |
| 10 function init(container) { |
| 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 = function(view) { |
| 17 assertEquals(view, container.currentView_); |
| 18 }; |
| 19 |
| 20 /** |
| 21 * Checks whether the elements specified in |elementIdList| are visible. |
| 22 * Checks whether all other elements are not visible. Throws an assertion |
| 23 * error if this is not true. |
| 24 * |
| 25 * @param {!Array<!string>} elementIdList List of id's of elements that |
| 26 * should be visible. |
| 27 */ |
| 28 var checkElementsVisibleWithId = function(elementIdList) { |
| 29 for (var i = 0; i < elementIdList.length; i++) |
| 30 checkElementVisibleWithId(true, elementIdList[i]); |
| 31 |
| 32 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { |
| 33 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) |
| 34 checkElementVisibleWithId(false, hiddenCheckElementIdList[j]); |
| 35 } |
| 36 }; |
| 37 |
| 38 /** |
| 39 * Checks the visibility of an element with |elementId| in |container|. |
| 40 * An element is considered visible if it exists and its |hidden| property |
| 41 * is |false|. |
| 42 * |
| 43 * @param {boolean} visible Whether the element should be visible. |
| 44 * @param {!string} elementId The id of the element to test. |
| 45 */ |
| 46 var checkElementVisibleWithId = function(visible, elementId) { |
| 47 var element = container.$$('#' + elementId); |
| 48 var elementVisible = !!element && !element.hidden && |
| 49 element.style.display != 'none'; |
| 50 assertEquals(visible, elementVisible, elementId); |
| 51 }; |
| 52 |
| 53 /** |
| 54 * Checks whether |expected| and the text in the |element| are equal. |
| 55 * |
| 56 * @param {!string} expected Expected text. |
| 57 * @param {!Element} element Element whose text will be checked. |
| 58 */ |
| 59 var checkElementText = function(expected, element) { |
| 60 assertEquals(expected.trim(), element.textContent.trim()); |
| 61 }; |
| 62 |
| 63 /** |
| 64 * The blocking issue to show. |
| 65 * @type {!media_router.Issue} |
| 66 */ |
| 67 var fakeBlockingIssue = new media_router.Issue( |
| 68 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, |
| 69 'route id 1', true, 1234); |
| 70 |
| 71 /** |
| 72 * The list of CastModes to show. |
| 73 * @type {!Array<!media_router.CastMode>} |
| 74 */ |
| 75 var fakeCastModeList = [ |
| 76 new media_router.CastMode(0x1, 'Description 0', 'google.com'), |
| 77 new media_router.CastMode(0x2, 'Description 1', null), |
| 78 new media_router.CastMode(0x4, 'Description 2', null), |
| 79 ]; |
| 80 |
| 81 /** |
| 82 * The list of CastModes to show with non-default modes only. |
| 83 * @type {!Array<!media_router.CastMode>} |
| 84 */ |
| 85 var fakeCastModeListWithNonDefaultModesOnly = [ |
| 86 new media_router.CastMode(0x2, 'Description 1', null), |
| 87 new media_router.CastMode(0x4, 'Description 2', null), |
| 88 new media_router.CastMode(0x8, 'Description 3', null), |
| 89 ]; |
| 90 |
| 91 /** |
| 92 * The blocking issue to show. |
| 93 * @type {!media_router.Issue} |
| 94 */ |
| 95 var fakeNonBlockingIssue = new media_router.Issue( |
| 96 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, |
| 97 'route id 2', false, 1234); |
| 98 |
| 99 /** |
| 100 * The list of current routes. |
| 101 * @type {!Array<!media_router.Route>} |
| 102 */ |
| 103 var fakeRouteList = [ |
| 104 new media_router.Route('id 1', 'sink id 1', 'Title 1', 0, true, false), |
| 105 new media_router.Route('id 2', 'sink id 2', 'Title 2', 1, false, true), |
| 106 ]; |
| 107 |
| 108 /** |
| 109 * The list of current routes with local routes only. |
| 110 * @type {!Array<!media_router.Route>} |
| 111 */ |
| 112 var fakeRouteListWithLocalRoutesOnly = [ |
| 113 new media_router.Route('id 1', 'sink id 1', 'Title 1', 0, true, false), |
| 114 new media_router.Route('id 2', 'sink id 2', 'Title 2', 1, true, false), |
| 115 ]; |
| 116 |
| 117 // Common cast mode bitset for creating sinks in |fakeSinkList|. |
| 118 var castModeBitset = 0x2 | 0x4 | 0x8; |
| 119 /** |
| 120 * The list of available sinks. |
| 121 * @type {!Array<!media_router.Sink>} |
| 122 */ |
| 123 var fakeSinkList = [ |
| 124 new media_router.Sink('sink id 1', 'Sink 1', null, null, |
| 125 media_router.SinkIconType.CAST, |
| 126 media_router.SinkStatus.ACTIVE, castModeBitset), |
| 127 new media_router.Sink('sink id 2', 'Sink 2', null, null, |
| 128 media_router.SinkIconType.CAST, |
| 129 media_router.SinkStatus.ACTIVE, castModeBitset), |
| 130 new media_router.Sink('sink id 3', 'Sink 3', null, null, |
| 131 media_router.SinkIconType.CAST, |
| 132 media_router.SinkStatus.PENDING, castModeBitset), |
| 133 ]; |
| 134 |
| 135 /** |
| 136 * The list of elements to check for visibility. |
| 137 * @const {!Array<!string>} |
| 138 */ |
| 139 var hiddenCheckElementIdList = [ |
| 140 'cast-mode-list', |
| 141 'container-header', |
| 142 'device-missing', |
| 143 'first-run-flow', |
| 144 'first-run-flow-cloud-pref', |
| 145 'issue-banner', |
| 146 'no-search-matches', |
| 147 'route-details', |
| 148 'search-results', |
| 149 'sink-list', |
| 150 'sink-list-view', |
| 151 ]; |
| 152 |
| 153 /** |
| 154 * Search text that will match all sinks. |
| 155 * @type {!string} |
| 156 */ |
| 157 var searchTextAll = 'sink'; |
| 158 |
| 159 /** |
| 160 * Search text that won't match any sink in fakeSinkList. |
| 161 * @type {!string} |
| 162 */ |
| 163 var searchTextNone = 'abc'; |
| 164 |
| 165 /** |
| 166 * Search text that will match exactly one sink. |
| 167 * @type {!string} |
| 168 */ |
| 169 var searchTextOne = 'sink 1'; |
| 170 |
| 171 return { |
| 172 checkCurrentView: checkCurrentView, |
| 173 checkElementsVisibleWithId: checkElementsVisibleWithId, |
| 174 checkElementVisibleWithId: checkElementVisibleWithId, |
| 175 checkElementText: checkElementText, |
| 176 fakeBlockingIssue: fakeBlockingIssue, |
| 177 fakeCastModeList: fakeCastModeList, |
| 178 fakeCastModeListWithNonDefaultModesOnly: |
| 179 fakeCastModeListWithNonDefaultModesOnly, |
| 180 fakeNonBlockingIssue: fakeNonBlockingIssue, |
| 181 fakeRouteList: fakeRouteList, |
| 182 fakeRouteListWithLocalRoutesOnly: fakeRouteListWithLocalRoutesOnly, |
| 183 fakeSinkList: fakeSinkList, |
| 184 searchTextAll: searchTextAll, |
| 185 searchTextNone: searchTextNone, |
| 186 searchTextOne: searchTextOne, |
| 187 }; |
| 188 } |
| 189 return {init: init}; |
| 190 }); |
| OLD | NEW |