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. |
| 34 // An element is considered hidden if it does not exist (e.g. unstamped) |
| 35 // or its |hidden| property is |false|. |
33 var checkElementHidden = function(hidden, element) { | 36 var checkElementHidden = function(hidden, element) { |
34 assertEquals(hidden, element.hidden); | 37 assertEquals(hidden, !element || element.hidden); |
35 }; | 38 }; |
36 | 39 |
37 // Checks whether the elements specified in |elementIdList| are visible. | 40 // Checks whether the elements specified in |elementIdList| are visible. |
38 // Checks whether all other elements are hidden. | 41 // Checks whether all other elements are hidden. |
39 var checkElementsVisibleWithId = function(elementIdList) { | 42 var checkElementsVisibleWithId = function(elementIdList) { |
40 for (var i = 0; i < elementIdList.length; i++) | 43 for (var i = 0; i < elementIdList.length; i++) |
41 checkElementHidden(false, header.$[elementIdList[i]]); | 44 checkElementHidden(false, header.$[elementIdList[i]]); |
42 | 45 |
43 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { | 46 for (var j = 0; j < hiddenCheckElementIdList.length; j++) { |
44 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) | 47 if (elementIdList.indexOf(hiddenCheckElementIdList[j]) == -1) |
45 checkElementHidden(true, header.$[hiddenCheckElementIdList[j]]); | 48 checkElementHidden(true, header.$[hiddenCheckElementIdList[j]]); |
46 } | 49 } |
47 }; | 50 }; |
48 | 51 |
| 52 // Checks whether |expected| and the text in the |element| are equal. |
| 53 var checkElementText = function(expected, element) { |
| 54 assertEquals(expected.trim(), element.textContent.trim()); |
| 55 }; |
| 56 |
49 // Import media_router_header.html before running suite. | 57 // Import media_router_header.html before running suite. |
50 suiteSetup(function() { | 58 suiteSetup(function() { |
51 return PolymerTest.importHtml( | 59 return PolymerTest.importHtml( |
52 'chrome://media-router/elements/media_router_header/' + | 60 'chrome://media-router/elements/media_router_container/' + |
53 'media_router_header.html'); | 61 'media_router_container.html'); |
54 }); | 62 }); |
55 | 63 |
56 // Initialize an media-router-header before each test. | 64 // Initialize an media-router-header before each test. |
57 setup(function(done) { | 65 setup(function(done) { |
58 PolymerTest.clearBody(); | 66 PolymerTest.clearBody(); |
59 header = document.createElement('media-router-header'); | 67 container = document.createElement('media-router-container'); |
60 document.body.appendChild(header); | 68 document.body.appendChild(container); |
| 69 header = container.$['container-header']; |
61 | 70 |
62 // Allow for the media router header to be created and attached. | 71 // Allow for the media router header to be created and attached. |
63 setTimeout(done); | 72 setTimeout(done); |
64 }); | 73 }); |
65 | 74 |
66 // Tests for 'close-button-click' event firing when the close button | 75 // Tests for 'close-button-click' event firing when the close button |
67 // is clicked. | 76 // is clicked. |
68 test('close button click', function(done) { | 77 test('close button click', function(done) { |
69 header.addEventListener('close-button-click', function() { | 78 header.addEventListener('close-button-click', function() { |
70 done(); | 79 done(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 139 |
131 header.view = media_router.MediaRouterView.FILTER; | 140 header.view = media_router.MediaRouterView.FILTER; |
132 MockInteractions.tap(header.$['header-text']); | 141 MockInteractions.tap(header.$['header-text']); |
133 header.view = media_router.MediaRouterView.ISSUE; | 142 header.view = media_router.MediaRouterView.ISSUE; |
134 MockInteractions.tap(header.$['header-text']); | 143 MockInteractions.tap(header.$['header-text']); |
135 header.view = media_router.MediaRouterView.ROUTE_DETAILS; | 144 header.view = media_router.MediaRouterView.ROUTE_DETAILS; |
136 MockInteractions.tap(header.$['header-text']); | 145 MockInteractions.tap(header.$['header-text']); |
137 done(); | 146 done(); |
138 }); | 147 }); |
139 | 148 |
| 149 // Tests for 'header-height-changed' event firing when the header changes |
| 150 // if email is shown. |
| 151 test('header height changed with email shown', function(done) { |
| 152 header.addEventListener('header-height-changed', function() { |
| 153 done(); |
| 154 }); |
| 155 header.userEmail = 'user@example.com'; |
| 156 header.showEmail = true; |
| 157 }); |
| 158 |
140 // Tests the |computeArrowDropIcon_| function. | 159 // Tests the |computeArrowDropIcon_| function. |
141 test('compute arrow drop icon', function() { | 160 test('compute arrow drop icon', function() { |
142 assertEquals('arrow-drop-up', | 161 assertEquals('arrow-drop-up', |
143 header.computeArrowDropIcon_( | 162 header.computeArrowDropIcon_( |
144 media_router.MediaRouterView.CAST_MODE_LIST)); | 163 media_router.MediaRouterView.CAST_MODE_LIST)); |
145 assertEquals('arrow-drop-down', | 164 assertEquals('arrow-drop-down', |
146 header.computeArrowDropIcon_( | 165 header.computeArrowDropIcon_( |
147 media_router.MediaRouterView.FILTER)); | 166 media_router.MediaRouterView.FILTER)); |
148 assertEquals('arrow-drop-down', | 167 assertEquals('arrow-drop-down', |
149 header.computeArrowDropIcon_( | 168 header.computeArrowDropIcon_( |
(...skipping 24 matching lines...) Expand all Loading... |
174 header.view = media_router.MediaRouterView.ROUTE_DETAILS; | 193 header.view = media_router.MediaRouterView.ROUTE_DETAILS; |
175 checkElementsVisibleWithId(['back-button', | 194 checkElementsVisibleWithId(['back-button', |
176 'close-button', | 195 'close-button', |
177 'header-text']); | 196 'header-text']); |
178 | 197 |
179 header.view = media_router.MediaRouterView.SINK_LIST; | 198 header.view = media_router.MediaRouterView.SINK_LIST; |
180 checkElementsVisibleWithId(['arrow-drop-icon', | 199 checkElementsVisibleWithId(['arrow-drop-icon', |
181 'close-button', | 200 'close-button', |
182 'header-text']); | 201 'header-text']); |
183 }); | 202 }); |
| 203 |
| 204 // Verify email is shown and header updated if showEmail is true. |
| 205 test('visibility and style of UI depending on email', function(done) { |
| 206 header.userEmail = 'user@example.com'; |
| 207 header.showEmail = true; |
| 208 setTimeout(function() { |
| 209 assertEquals(header.headerWithEmailHeight_, header.offsetHeight) |
| 210 |
| 211 assertFalse(header.$$('#user-email-container').hidden); |
| 212 checkElementText( |
| 213 header.userEmail, |
| 214 header.$$('#user-email-container')); |
| 215 done(); |
| 216 }); |
| 217 }); |
| 218 |
| 219 // Verify no email is shown and header is not modified if email is empty. |
| 220 test('visibility and style of UI for empty email', function(done) { |
| 221 header.userEmail = undefined; |
| 222 header.showEmail = true; |
| 223 setTimeout(function() { |
| 224 assertNotEquals(header.headerWithEmailHeight_, header.offsetHeight) |
| 225 checkElementText( |
| 226 '', |
| 227 header.$$('#user-email-container')); |
| 228 done(); |
| 229 }); |
| 230 }); |
184 }); | 231 }); |
185 } | 232 } |
186 | 233 |
187 return { | 234 return { |
188 registerTests: registerTests, | 235 registerTests: registerTests, |
189 }; | 236 }; |
190 }); | 237 }); |
OLD | NEW |