Chromium Code Reviews| Index: chrome/test/data/webui/media_router/media_router_container_test_base.js |
| diff --git a/chrome/test/data/webui/media_router/media_router_container_test_base.js b/chrome/test/data/webui/media_router/media_router_container_test_base.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..faa04e3026c4347c7ea644cc192fde43d5191fe0 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/media_router/media_router_container_test_base.js |
| @@ -0,0 +1,194 @@ |
| +// Copyright 2016 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 Provides basic utility functions and variables for |
| + * media-router-container tests. */ |
| + |
| +cr.define('media_router_container_test_base', function() { |
| + function init(container) { |
| + /** |
| + * The blocking issue to show. |
| + * @type {?media_router.Issue} |
| + */ |
| + var fakeBlockingIssue; |
|
apacible
2016/03/09 17:33:15
You can just initialize the variables here instead
btolsch
2016/03/09 20:01:00
Done.
|
| + |
| + /** |
| + * The list of CastModes to show. |
| + * @type {!Array<!media_router.CastMode>} |
| + */ |
| + var fakeCastModeList = []; |
| + |
| + /** |
| + * The list of CastModes to show with non-default modes only. |
| + * @type {!Array<!media_router.CastMode>} |
| + */ |
| + var fakeCastModeListWithNonDefaultModesOnly = []; |
| + |
| + /** |
| + * The blocking issue to show. |
| + * @type {?media_router.Issue} |
| + */ |
| + var fakeNonBlockingIssue; |
| + |
| + /** |
| + * The list of current routes. |
| + * @type {!Array<!media_router.Route>} |
| + */ |
| + var fakeRouteList = []; |
| + |
| + /** |
| + * The list of available sinks. |
| + * @type {!Array<!media_router.Sink>} |
| + */ |
| + var fakeSinkList = []; |
| + |
| + /** |
| + * The list of elements to check for visibility. |
| + * @const {!Array<string>} |
|
apacible
2016/03/09 17:33:15
nit: {!Array<!string>}
btolsch
2016/03/09 20:01:01
Done.
|
| + */ |
| + 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', |
| + ]; |
| + |
| + /** |
| + * Search text that will match all sinks. |
| + * @type {string} |
| + */ |
| + var searchTextAll; |
| + |
| + /** |
| + * Search text that won't match any sink in fakeSinkList. |
| + * @type {string} |
| + */ |
| + var searchTextNone; |
| + |
| + /** |
| + * Search text that will match exactly one sink. |
| + * @type {string} |
| + */ |
| + var searchTextOne; |
| + |
| + // Checks whether |view| matches the current view of |container|. |
| + var checkCurrentView = function(view) { |
| + assertEquals(view, container.currentView_); |
| + }; |
| + |
| + // 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()); |
| + }; |
| + |
| + 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), |
| + ]; |
| + |
| + fakeCastModeListWithNonDefaultModesOnly = [ |
| + new media_router.CastMode(0x2, 'Description 1', null), |
| + new media_router.CastMode(0x4, 'Description 2', null), |
| + new media_router.CastMode(0x8, 'Description 3', null), |
| + ]; |
| + |
| + fakeRouteList = [ |
| + 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, false, true), |
| + ]; |
| + |
| + 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), |
| + ]; |
| + |
| + 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; |
|
apacible
2016/03/09 17:33:15
Remove?
btolsch
2016/03/09 20:01:01
Done.
|
| + |
| + searchTextAll = 'sink'; |
| + searchTextNone = 'abc'; |
| + searchTextOne = 'sink 1'; |
| + |
| + return { |
|
apacible
2016/03/09 17:33:15
nit: alphabetize and remove extra newline.
btolsch
2016/03/09 20:01:01
Done.
|
| + fakeBlockingIssue: fakeBlockingIssue, |
| + fakeCastModeList: fakeCastModeList, |
| + fakeCastModeListWithNonDefaultModesOnly: |
| + fakeCastModeListWithNonDefaultModesOnly, |
| + fakeNonBlockingIssue: fakeNonBlockingIssue, |
| + fakeRouteList: fakeRouteList, |
| + fakeRouteListWithLocalRoutesOnly: fakeRouteListWithLocalRoutesOnly, |
| + fakeSinkList: fakeSinkList, |
| + searchTextAll: searchTextAll, |
| + searchTextNone: searchTextNone, |
| + searchTextOne: searchTextOne, |
| + |
| + checkCurrentView: checkCurrentView, |
| + checkElementsVisibleWithId: checkElementsVisibleWithId, |
| + checkElementVisibleWithId: checkElementVisibleWithId, |
| + checkElementText: checkElementText, |
| + }; |
| + } |
| + return {init: init}; |
| +}); |