Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 (function() { | 5 (function() { |
| 6 function getFakePrefs() { | 6 function getFakePrefs() { |
| 7 return { | 7 return { |
| 8 cros: { | 8 cros: { |
| 9 system: { | 9 system: { |
| 10 timezone: { | 10 timezone: { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 assertEquals(autoDetect, dateTime.$$('settings-dropdown-menu').disabled); | 114 assertEquals(autoDetect, dateTime.$$('settings-dropdown-menu').disabled); |
| 115 assertEquals(autoDetect, dateTime.$.timeZoneAutoDetect.checked); | 115 assertEquals(autoDetect, dateTime.$.timeZoneAutoDetect.checked); |
| 116 } | 116 } |
| 117 | 117 |
| 118 function verifyPolicy(policy) { | 118 function verifyPolicy(policy) { |
| 119 Polymer.dom.flush(); | 119 Polymer.dom.flush(); |
| 120 var indicator = dateTime.$$('cr-policy-pref-indicator'); | 120 var indicator = dateTime.$$('cr-policy-pref-indicator'); |
| 121 | 121 |
| 122 if (policy) { | 122 if (policy) { |
| 123 assertTrue(!!indicator); | 123 assertTrue(!!indicator); |
| 124 assertGT(indicator.clientHeight, 0); | 124 assertNotEquals('none', indicator.style.display); |
|
michaelpg
2017/02/08 00:07:12
would indicator.$$('iron-icon').clientHeight be su
dpapad
2017/02/08 01:53:50
Actually it is not at all robust. Here is why:
Th
michaelpg
2017/02/08 02:24:25
Jeez. Can't wait to get rid of those iron-flex glo
dpapad
2017/02/08 22:03:40
> Can you add a TODO to replace these checks with
michaelpg
2017/02/09 22:09:02
SGTM.
|
michaelpg
2017/02/08 00:07:12
generally we should check getComputedStyle, becaus
dpapad
2017/02/08 01:53:50
Tried getComputedStyle() and it throws
TypeError
michaelpg
2017/02/08 02:24:25
Yeah I'm at a loss there.
|
| 125 assertTrue(!!indicator.$$('iron-icon')); | |
|
Dan Beam
2017/02/08 02:14:23
why are we looking into indicator itself?
dpapad
2017/02/08 02:26:35
In lack of a better way to verify if the on/off st
dpapad
2017/02/08 19:18:34
@dbeam PTAL: I added an isActive() method on cr-po
| |
| 126 assertFalse(indicator.$$('iron-icon').hidden); | |
| 125 } else { | 127 } else { |
| 126 // Indicator should be missing or hidden. | 128 // Indicator should be missing or hidden. |
| 127 if (indicator) | 129 if (indicator) |
| 128 assertEquals(0, indicator.clientHeight); | 130 assertEquals('none', indicator.style.display); |
| 129 } | 131 } |
| 130 | 132 |
| 131 assertEquals(policy, dateTime.$.timeZoneAutoDetect.disabled); | 133 assertEquals(policy, dateTime.$.timeZoneAutoDetect.disabled); |
| 132 } | 134 } |
| 133 | 135 |
| 134 function verifyTimeZonesPopulated(populated) { | 136 function verifyTimeZonesPopulated(populated) { |
| 135 var dropdown = dateTime.$$('settings-dropdown-menu'); | 137 var dropdown = dateTime.$$('settings-dropdown-menu'); |
| 136 if (populated) | 138 if (populated) |
| 137 assertEquals(fakeTimeZones.length, dropdown.menuOptions.length); | 139 assertEquals(fakeTimeZones.length, dropdown.menuOptions.length); |
| 138 else | 140 else |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 158 setTimeout(function() { | 160 setTimeout(function() { |
| 159 verifyTimeZonesPopulated(true); | 161 verifyTimeZonesPopulated(true); |
| 160 done(); | 162 done(); |
| 161 }); | 163 }); |
| 162 }); | 164 }); |
| 163 | 165 |
| 164 test('auto-detect off', function(done) { | 166 test('auto-detect off', function(done) { |
| 165 var prefs = getFakePrefs(); | 167 var prefs = getFakePrefs(); |
| 166 prefs.settings.resolve_timezone_by_geolocation.value = false; | 168 prefs.settings.resolve_timezone_by_geolocation.value = false; |
| 167 dateTime = initializeDateTime(prefs, false); | 169 dateTime = initializeDateTime(prefs, false); |
| 170 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); | |
| 168 | 171 |
| 169 assertTrue(dateTimePageReadyCalled); | 172 assertTrue(dateTimePageReadyCalled); |
| 170 assertTrue(getTimeZonesCalled); | 173 assertTrue(getTimeZonesCalled); |
| 171 | 174 |
| 172 verifyAutoDetectSetting(false); | 175 verifyAutoDetectSetting(false); |
| 173 verifyPolicy(false); | 176 verifyPolicy(false); |
| 174 | 177 |
| 175 setTimeout(function() { | 178 setTimeout(function() { |
| 176 verifyTimeZonesPopulated(true); | 179 verifyTimeZonesPopulated(true); |
| 177 | 180 |
| 178 // Enable auto-detect. | 181 // Enable auto-detect. |
| 179 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 182 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); |
| 180 verifyAutoDetectSetting(true); | 183 verifyAutoDetectSetting(true); |
| 181 done(); | 184 done(); |
| 182 }); | 185 }); |
| 183 }); | 186 }); |
| 184 | 187 |
| 185 test('auto-detect forced on', function(done) { | 188 test('auto-detect forced on', function(done) { |
| 186 var prefs = getFakePrefs(); | 189 var prefs = getFakePrefs(); |
| 187 prefs.settings.resolve_timezone_by_geolocation.value = false; | 190 prefs.settings.resolve_timezone_by_geolocation.value = false; |
| 188 dateTime = initializeDateTime(prefs, true, true); | 191 dateTime = initializeDateTime(prefs, true, true); |
| 192 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, true); | |
| 189 | 193 |
| 190 assertTrue(dateTimePageReadyCalled); | 194 assertTrue(dateTimePageReadyCalled); |
| 191 assertFalse(getTimeZonesCalled); | 195 assertFalse(getTimeZonesCalled); |
| 192 | 196 |
| 193 verifyAutoDetectSetting(true); | 197 verifyAutoDetectSetting(true); |
| 194 verifyTimeZonesPopulated(false); | 198 verifyTimeZonesPopulated(false); |
| 195 verifyPolicy(true); | 199 verifyPolicy(true); |
| 196 | 200 |
| 197 // Cannot disable auto-detect. | 201 // Cannot disable auto-detect. |
| 198 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 202 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); |
| 199 verifyAutoDetectSetting(true); | 203 verifyAutoDetectSetting(true); |
| 200 assertFalse(getTimeZonesCalled); | 204 assertFalse(getTimeZonesCalled); |
| 201 | 205 |
| 202 // Update the policy: force auto-detect off. | 206 // Update the policy: force auto-detect off. |
| 203 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false); | 207 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false); |
| 204 verifyAutoDetectSetting(false); | 208 verifyAutoDetectSetting(false); |
| 205 verifyPolicy(true); | 209 verifyPolicy(true); |
| 206 | 210 |
| 207 assertTrue(getTimeZonesCalled); | 211 assertTrue(getTimeZonesCalled); |
| 208 setTimeout(function() { | 212 setTimeout(function() { |
| 209 verifyTimeZonesPopulated(true); | 213 verifyTimeZonesPopulated(true); |
| 210 done(); | 214 done(); |
| 211 }); | 215 }); |
| 212 }); | 216 }); |
| 213 | 217 |
| 214 test('auto-detect forced off', function(done) { | 218 test('auto-detect forced off', function(done) { |
| 215 var prefs = getFakePrefs(); | 219 var prefs = getFakePrefs(); |
| 216 dateTime = initializeDateTime(prefs, true, false); | 220 dateTime = initializeDateTime(prefs, true, false); |
| 221 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false); | |
| 217 | 222 |
| 218 assertTrue(dateTimePageReadyCalled); | 223 assertTrue(dateTimePageReadyCalled); |
| 219 assertTrue(getTimeZonesCalled); | 224 assertTrue(getTimeZonesCalled); |
| 220 | 225 |
| 221 verifyAutoDetectSetting(false); | 226 verifyAutoDetectSetting(false); |
| 222 verifyPolicy(true); | 227 verifyPolicy(true); |
| 223 | 228 |
| 224 setTimeout(function() { | 229 setTimeout(function() { |
| 225 verifyTimeZonesPopulated(true); | 230 verifyTimeZonesPopulated(true); |
| 226 | 231 |
| 227 // Remove the policy so user's preference takes effect. | 232 // Remove the policy so user's preference takes effect. |
| 228 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); | 233 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); |
| 229 verifyAutoDetectSetting(true); | 234 verifyAutoDetectSetting(true); |
| 230 verifyPolicy(false); | 235 verifyPolicy(false); |
| 231 | 236 |
| 232 // User can disable auto-detect. | 237 // User can disable auto-detect. |
| 233 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 238 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); |
| 234 verifyAutoDetectSetting(false); | 239 verifyAutoDetectSetting(false); |
| 235 done(); | 240 done(); |
| 236 }); | 241 }); |
| 237 }); | 242 }); |
| 238 | 243 |
| 239 test('set date and time button', function() { | 244 test('set date and time button', function() { |
| 240 dateTime = initializeDateTime(getFakePrefs(), false); | 245 dateTime = initializeDateTime(getFakePrefs(), false); |
| 246 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); | |
| 241 | 247 |
| 242 var showSetDateTimeUICalled = false; | 248 var showSetDateTimeUICalled = false; |
| 243 registerMessageCallback('showSetDateTimeUI', null, function() { | 249 registerMessageCallback('showSetDateTimeUI', null, function() { |
| 244 assertFalse(showSetDateTimeUICalled); | 250 assertFalse(showSetDateTimeUICalled); |
| 245 showSetDateTimeUICalled = true; | 251 showSetDateTimeUICalled = true; |
| 246 }); | 252 }); |
| 247 | 253 |
| 248 var setDateTimeButton = dateTime.$.setDateTime; | 254 var setDateTimeButton = dateTime.$.setDateTime; |
| 249 assertEquals(0, setDateTimeButton.offsetHeight); | 255 assertEquals(0, setDateTimeButton.offsetHeight); |
| 250 | 256 |
| 251 // Make the date and time editable. | 257 // Make the date and time editable. |
| 252 cr.webUIListenerCallback('can-set-date-time-changed', true); | 258 cr.webUIListenerCallback('can-set-date-time-changed', true); |
| 253 assertGT(setDateTimeButton.offsetHeight, 0); | 259 assertGT(setDateTimeButton.offsetHeight, 0); |
| 254 | 260 |
| 255 assertFalse(showSetDateTimeUICalled); | 261 assertFalse(showSetDateTimeUICalled); |
| 256 MockInteractions.tap(setDateTimeButton); | 262 MockInteractions.tap(setDateTimeButton); |
| 257 assertTrue(showSetDateTimeUICalled); | 263 assertTrue(showSetDateTimeUICalled); |
| 258 | 264 |
| 259 // Make the date and time not editable. | 265 // Make the date and time not editable. |
| 260 cr.webUIListenerCallback('can-set-date-time-changed', false); | 266 cr.webUIListenerCallback('can-set-date-time-changed', false); |
| 261 assertEquals(setDateTimeButton.offsetHeight, 0); | 267 assertEquals(setDateTimeButton.offsetHeight, 0); |
| 262 }); | 268 }); |
| 263 }); | 269 }); |
| 264 })(); | 270 })(); |
| OLD | NEW |