Chromium Code Reviews| 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 test('visibility and style of UI depending on email', function(done) { | |
|
apacible
2016/02/25 00:16:02
nit: Add comment for test, e.g. "// Tests that the
amp
2016/02/25 03:01:15
Done.
| |
| 205 header.userEmail = 'user@example.com'; | |
| 206 header.showEmail = true; | |
| 207 setTimeout(function() { | |
| 208 assertEquals(header.headerWithEmailHeight_, header.offsetHeight) | |
| 209 | |
| 210 assertFalse(header.$$('#user-email-container').hidden); | |
| 211 checkElementText( | |
| 212 header.userEmail, | |
| 213 header.$$('#user-email-container')); | |
| 214 done(); | |
| 215 }); | |
| 216 }); | |
| 217 | |
| 218 test('visibility and style of UI for empty email', function(done) { | |
| 219 // Verify no email is shown if email is empty | |
|
apacible
2016/02/25 00:16:02
nit: Move this comment right above the previous li
amp
2016/02/25 03:01:15
Done.
| |
| 220 header.userEmail = undefined; | |
| 221 header.showEmail = true; | |
| 222 setTimeout(function() { | |
| 223 assertNotEquals(header.headerWithEmailHeight_, header.offsetHeight) | |
| 224 checkElementText( | |
| 225 '', | |
| 226 header.$$('#user-email-container')); | |
| 227 done(); | |
| 228 }); | |
| 229 }); | |
| 184 }); | 230 }); |
| 185 } | 231 } |
| 186 | 232 |
| 187 return { | 233 return { |
| 188 registerTests: registerTests, | 234 registerTests: registerTests, |
| 189 }; | 235 }; |
| 190 }); | 236 }); |
| OLD | NEW |