OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @fileoverview Suite of tests for media-router-header. */ | 5 /** @fileoverview Suite of tests for media-router-header. */ |
6 cr.define('media_router_header', function() { | 6 cr.define('media_router_header', function() { |
7 function registerTests() { | 7 function registerTests() { |
8 suite('MediaRouterHeader', function() { | 8 suite('MediaRouterHeader', function() { |
9 /** | 9 /** |
10 * Media Router Header created before each test. | 10 * Media Router Header created before each test. |
11 * @type {MediaRouterHeader} | 11 * @type {MediaRouterHeader} |
12 */ | 12 */ |
13 var header; | 13 var header; |
14 | 14 |
15 /** | 15 /** |
16 * The list of elements to check for visibility. | 16 * The list of elements to check for visibility. |
17 * @const {!Array<string>} | 17 * @const {!Array<string>} |
18 */ | 18 */ |
19 var hiddenCheckElementIdList = [ | 19 var hiddenCheckElementIdList = [ |
20 'arrow-drop-icon', | 20 'arrow-drop-icon', |
21 'back-button', | 21 'back-button', |
22 'close-button', | 22 'close-button', |
23 'header-text' | 23 'header-text', |
24 'user-email-container', | |
24 ]; | 25 ]; |
25 | 26 |
26 // Checks whether the current icon matches the icon used for the view. | 27 // Checks whether the current icon matches the icon used for the view. |
27 var checkArrowDropIcon = function(view) { | 28 var checkArrowDropIcon = function(view) { |
28 assertEquals(header.computeArrowDropIcon_(view), | 29 assertEquals(header.computeArrowDropIcon_(view), |
29 header.$['arrow-drop-icon'].icon); | 30 header.$['arrow-drop-icon'].icon); |
30 }; | 31 }; |
31 | 32 |
32 // Checks whether |element| is hidden. | 33 // Checks whether |element| is hidden. |
apacible
2016/02/23 21:51:01
Update comment to mention unstamped elements would
amp
2016/02/24 00:29:23
Done.
| |
33 var checkElementHidden = function(hidden, element) { | 34 var checkElementHidden = function(hidden, element) { |
34 assertEquals(hidden, element.hidden); | 35 assertEquals(hidden, !element || element.hidden); |
35 }; | 36 }; |
36 | 37 |
37 // Checks whether the elements specified in |elementIdList| are visible. | 38 // Checks whether the elements specified in |elementIdList| are visible. |
38 // Checks whether all other elements are hidden. | 39 // Checks whether all other elements are hidden. |
39 var checkElementsVisibleWithId = function(elementIdList) { | 40 var checkElementsVisibleWithId = function(elementIdList) { |
40 for (var i = 0; i < elementIdList.length; i++) | 41 for (var i = 0; i < elementIdList.length; i++) |
41 checkElementHidden(false, header.$[elementIdList[i]]); | 42 checkElementHidden(false, header.$[elementIdList[i]]); |
42 | 43 |
43 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { | 44 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { |
44 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) | 45 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) |
45 checkElementHidden(true, header.$[hiddenCheckElementIdList[j]]); | 46 checkElementHidden(true, header.$[hiddenCheckElementIdList[j]]); |
46 } | 47 } |
47 }; | 48 }; |
48 | 49 |
49 // Import media_router_header.html before running suite. | 50 // Import media_router_header.html before running suite. |
50 suiteSetup(function() { | 51 suiteSetup(function() { |
51 return PolymerTest.importHtml( | 52 return PolymerTest.importHtml( |
52 'chrome://media-router/elements/media_router_header/' + | 53 'chrome://media-router/elements/media_router_container/' + |
53 'media_router_header.html'); | 54 'media_router_container.html'); |
54 }); | 55 }); |
55 | 56 |
56 // Initialize an media-router-header before each test. | 57 // Initialize an media-router-header before each test. |
57 setup(function(done) { | 58 setup(function(done) { |
58 PolymerTest.clearBody(); | 59 PolymerTest.clearBody(); |
59 header = document.createElement('media-router-header'); | 60 container = document.createElement('media-router-container'); |
60 document.body.appendChild(header); | 61 document.body.appendChild(container); |
62 header = container.$['container-header']; | |
63 header.userEmail = 'user@example.com'; | |
apacible
2016/02/23 21:51:01
Set |userEmail| into the tests when relevant since
amp
2016/02/24 00:29:23
Done.
| |
61 | 64 |
62 // Allow for the media router header to be created and attached. | 65 // Allow for the media router header to be created and attached. |
63 setTimeout(done); | 66 setTimeout(done); |
64 }); | 67 }); |
65 | 68 |
66 // Tests for 'close-button-click' event firing when the close button | 69 // Tests for 'close-button-click' event firing when the close button |
67 // is clicked. | 70 // is clicked. |
68 test('close button click', function(done) { | 71 test('close button click', function(done) { |
69 header.addEventListener('close-button-click', function() { | 72 header.addEventListener('close-button-click', function() { |
70 done(); | 73 done(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 133 |
131 header.view = media_router.MediaRouterView.FILTER; | 134 header.view = media_router.MediaRouterView.FILTER; |
132 MockInteractions.tap(header.$['header-text']); | 135 MockInteractions.tap(header.$['header-text']); |
133 header.view = media_router.MediaRouterView.ISSUE; | 136 header.view = media_router.MediaRouterView.ISSUE; |
134 MockInteractions.tap(header.$['header-text']); | 137 MockInteractions.tap(header.$['header-text']); |
135 header.view = media_router.MediaRouterView.ROUTE_DETAILS; | 138 header.view = media_router.MediaRouterView.ROUTE_DETAILS; |
136 MockInteractions.tap(header.$['header-text']); | 139 MockInteractions.tap(header.$['header-text']); |
137 done(); | 140 done(); |
138 }); | 141 }); |
139 | 142 |
143 // Tests for 'header-height-changed' event firing when the header changes | |
144 // if email is shown. | |
145 test('header height changed with email shown', function(done) { | |
146 header.addEventListener('header-height-changed', function() { | |
147 done(); | |
148 }); | |
149 header.showEmail = true; | |
150 }); | |
151 | |
140 // Tests the |computeArrowDropIcon_| function. | 152 // Tests the |computeArrowDropIcon_| function. |
141 test('compute arrow drop icon', function() { | 153 test('compute arrow drop icon', function() { |
142 assertEquals('arrow-drop-up', | 154 assertEquals('arrow-drop-up', |
143 header.computeArrowDropIcon_( | 155 header.computeArrowDropIcon_( |
144 media_router.MediaRouterView.CAST_MODE_LIST)); | 156 media_router.MediaRouterView.CAST_MODE_LIST)); |
145 assertEquals('arrow-drop-down', | 157 assertEquals('arrow-drop-down', |
146 header.computeArrowDropIcon_( | 158 header.computeArrowDropIcon_( |
147 media_router.MediaRouterView.FILTER)); | 159 media_router.MediaRouterView.FILTER)); |
148 assertEquals('arrow-drop-down', | 160 assertEquals('arrow-drop-down', |
149 header.computeArrowDropIcon_( | 161 header.computeArrowDropIcon_( |
(...skipping 24 matching lines...) Expand all Loading... | |
174 header.view = media_router.MediaRouterView.ROUTE_DETAILS; | 186 header.view = media_router.MediaRouterView.ROUTE_DETAILS; |
175 checkElementsVisibleWithId(['back-button', | 187 checkElementsVisibleWithId(['back-button', |
176 'close-button', | 188 'close-button', |
177 'header-text']); | 189 'header-text']); |
178 | 190 |
179 header.view = media_router.MediaRouterView.SINK_LIST; | 191 header.view = media_router.MediaRouterView.SINK_LIST; |
180 checkElementsVisibleWithId(['arrow-drop-icon', | 192 checkElementsVisibleWithId(['arrow-drop-icon', |
181 'close-button', | 193 'close-button', |
182 'header-text']); | 194 'header-text']); |
183 }); | 195 }); |
196 | |
197 // Tests for expected visible UI depending on the email properties. | |
198 test('visibility of UI depending on email', function(done) { | |
apacible
2016/02/23 21:51:01
We should also test if the header doesn't show the
amp
2016/02/24 00:29:23
Done.
| |
199 header.showEmail = true; | |
200 setTimeout(function() { | |
201 assertFalse(header.$$('#user-email-container').hidden); | |
202 done(); | |
203 }); | |
204 }); | |
184 }); | 205 }); |
185 } | 206 } |
186 | 207 |
187 return { | 208 return { |
188 registerTests: registerTests, | 209 registerTests: registerTests, |
189 }; | 210 }; |
190 }); | 211 }); |
OLD | NEW |