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..f3b5d8233a972a37aecff53590a2d5419993be61 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/media_router/media_router_container_test_base.js |
| @@ -0,0 +1,168 @@ |
| +// 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) { |
| + // Checks whether |view| matches the current view of |container|. |
| + 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.
|
| + 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()); |
| + }; |
| + |
| + /** |
| + * The blocking issue to show. |
| + * @type {?media_router.Issue} |
| + */ |
| + var fakeBlockingIssue = new media_router.Issue( |
| + 'issue id 1', 'Issue Title 1', 'Issue Message 1', 0, 1, |
| + 'route id 1', true, 1234); |
| + |
| + /** |
| + * The list of CastModes to show. |
| + * @type {!Array<!media_router.CastMode>} |
| + */ |
| + var 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), |
| + ]; |
| + |
| + /** |
| + * The list of CastModes to show with non-default modes only. |
| + * @type {!Array<!media_router.CastMode>} |
| + */ |
| + var 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), |
| + ]; |
| + |
| + /** |
| + * The blocking issue to show. |
| + * @type {?media_router.Issue} |
| + */ |
| + var fakeNonBlockingIssue = new media_router.Issue( |
| + 'issue id 2', 'Issue Title 2', 'Issue Message 2', 0, 1, |
| + 'route id 2', false, 1234); |
| + |
| + /** |
| + * The list of current routes. |
| + * @type {!Array<!media_router.Route>} |
| + */ |
| + var 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), |
| + ]; |
| + |
| + /** |
| + * The list of current routes with local routes only. |
| + * @type {!Array<!media_router.Route>} |
| + */ |
| + fakeRouteListWithLocalRoutesOnly = [ |
|
apacible
2016/03/10 18:11:06
var
btolsch
2016/03/10 19:08:08
Done.
|
| + 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; |
|
apacible
2016/03/10 18:11:06
Add comments?
btolsch
2016/03/10 19:08:08
Done.
|
| + /** |
| + * The list of available sinks. |
| + * @type {!Array<!media_router.Sink>} |
| + */ |
| + var 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), |
| + ]; |
| + |
| + /** |
| + * 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', |
| + ]; |
| + |
| + /** |
| + * Search text that will match all sinks. |
| + * @type {string} |
|
apacible
2016/03/10 18:11:06
!string
Here and elsewhere: if initialized where
btolsch
2016/03/10 19:08:08
Done.
|
| + */ |
| + var searchTextAll = 'sink'; |
| + |
| + /** |
| + * Search text that won't match any sink in fakeSinkList. |
| + * @type {string} |
| + */ |
| + var searchTextNone = 'abc'; |
| + |
| + /** |
| + * Search text that will match exactly one sink. |
| + * @type {string} |
| + */ |
| + var searchTextOne = 'sink 1'; |
| + |
| + return { |
| + checkCurrentView: checkCurrentView, |
| + checkElementsVisibleWithId: checkElementsVisibleWithId, |
| + checkElementVisibleWithId: checkElementVisibleWithId, |
| + checkElementText: checkElementText, |
| + fakeBlockingIssue: fakeBlockingIssue, |
| + fakeCastModeList: fakeCastModeList, |
| + fakeCastModeListWithNonDefaultModesOnly: |
| + fakeCastModeListWithNonDefaultModesOnly, |
| + fakeNonBlockingIssue: fakeNonBlockingIssue, |
| + fakeRouteList: fakeRouteList, |
| + fakeRouteListWithLocalRoutesOnly: fakeRouteListWithLocalRoutesOnly, |
| + fakeSinkList: fakeSinkList, |
| + searchTextAll: searchTextAll, |
| + searchTextNone: searchTextNone, |
| + searchTextOne: searchTextOne, |
| + }; |
| + } |
| + return {init: init}; |
| +}); |