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