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: { |
| 11 key: 'cros.system.timezone', | 11 key: 'cros.system.timezone', |
| 12 type: chrome.settingsPrivate.PrefType.STRING, | 12 type: chrome.settingsPrivate.PrefType.STRING, |
| 13 value: 'Westeros/Kings_Landing', | 13 value: 'Westeros/Kings_Landing', |
| 14 }, | 14 }, |
| 15 }, | 15 }, |
| 16 flags: { | |
| 17 per_user_timezone_enabled: { | |
|
michaelpg
2017/05/30 22:21:23
what is this?
Alexander Alekseev
2017/07/06 06:30:29
This flag is generated in chrome/browser/chromeos/
michaelpg
2017/07/10 19:29:37
that's not a bad idea though. add a TODO here to r
Alexander Alekseev
2017/07/14 03:32:46
Done.
| |
| 18 key: 'cros.flags.per_user_timezone_enabled', | |
| 19 type: chrome.settingsPrivate.PrefType.BOOLEAN, | |
| 20 value: true, | |
| 21 }, | |
| 22 }, | |
| 16 }, | 23 }, |
| 17 settings: { | 24 settings: { |
| 18 clock: { | 25 clock: { |
| 19 use_24hour_clock: { | 26 use_24hour_clock: { |
| 20 key: 'settings.clock.use_24hour_clock', | 27 key: 'settings.clock.use_24hour_clock', |
| 21 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 28 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 22 value: false, | 29 value: false, |
| 23 }, | 30 }, |
| 24 }, | 31 }, |
| 25 resolve_timezone_by_geolocation: { | 32 resolve_timezone_by_geolocation: { |
| 26 key: 'settings.resolve_timezone_by_geolocation', | 33 key: 'settings.resolve_timezone_by_geolocation', |
| 27 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 34 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 28 value: true, | 35 value: true, |
| 29 }, | 36 }, |
| 37 timezone: { | |
| 38 key: 'settings.timezone', | |
| 39 type: chrome.settingsPrivate.PrefType.STRING, | |
| 40 value: 'Westeros/Kings_Landing', | |
| 41 }, | |
| 30 }, | 42 }, |
| 31 }; | 43 }; |
| 32 } | 44 } |
| 33 | 45 |
| 46 function updatePrefsWithPolicy(prefs, managed, valueFromPolicy) { | |
| 47 var prefsCopy = JSON.parse(JSON.stringify(prefs)); | |
| 48 if (managed) { | |
| 49 prefsCopy.settings.resolve_timezone_by_geolocation.controlledBy = | |
| 50 'USER_POLICY'; | |
|
michaelpg
2017/05/30 22:21:24
chrome.settingsPrivate.ControlledBy.USER_POLICY, e
Alexander Alekseev
2017/07/06 06:30:29
Done.
| |
| 51 prefsCopy.settings.resolve_timezone_by_geolocation.enforcement = | |
| 52 'ENFORCED'; | |
| 53 prefsCopy.settings.resolve_timezone_by_geolocation.value = | |
| 54 valueFromPolicy; | |
| 55 prefsCopy.settings.timezone.controlledBy = 'USER_POLICY'; | |
| 56 prefsCopy.settings.timezone.enforcement = 'ENFORCED'; | |
| 57 } else { | |
| 58 prefsCopy.settings.resolve_timezone_by_geolocation.controlledBy = | |
| 59 undefined; | |
| 60 prefsCopy.settings.resolve_timezone_by_geolocation.enforcement = | |
| 61 undefined; | |
| 62 // Auto-resolve defaults to true. | |
| 63 prefsCopy.settings.resolve_timezone_by_geolocation.value = true; | |
| 64 prefsCopy.settings.timezone.controlledBy = undefined; | |
| 65 prefsCopy.settings.timezone.enforcement = undefined; | |
| 66 } | |
| 67 return prefsCopy; | |
| 68 } | |
| 69 | |
| 34 /** | 70 /** |
| 35 * Sets up fakes and creates the date time element. | 71 * Sets up fakes and creates the date time element. |
| 36 * @param {!Object} prefs | 72 * @param {!Object} prefs |
| 37 * @param {boolean} hasPolicy | 73 * @param {boolean} hasPolicy |
| 38 * @param {boolean=} opt_autoDetectPolicyValue | 74 * @param {boolean=} opt_autoDetectPolicyValue |
| 39 * @return {!SettingsDateTimePage} | 75 * @return {!SettingsDateTimePage} |
| 40 */ | 76 */ |
| 41 function initializeDateTime(prefs, hasPolicy, opt_autoDetectPolicyValue) { | 77 function initializeDateTime(prefs, hasPolicy, opt_autoDetectPolicyValue) { |
| 42 // Find the desired initial time zone by ID. | 78 // Find the desired initial time zone by ID. |
| 43 var timeZone = assert(fakeTimeZones.find(function(timeZonePair) { | 79 var timeZone = assert(fakeTimeZones.find(function(timeZonePair) { |
| 44 return timeZonePair[0] == prefs.cros.system.timezone.value; | 80 return timeZonePair[0] == prefs.cros.system.timezone.value; |
| 45 })); | 81 })); |
| 46 | 82 |
| 47 var data = { | 83 var data = { |
| 48 timeZoneID: timeZone[0], | 84 timeZoneID: timeZone[0], |
| 49 timeZoneName: timeZone[1], | 85 timeZoneName: timeZone[1], |
| 50 controlledSettingPolicy: 'This setting is enforced by your administrator', | 86 controlledSettingPolicy: 'This setting is enforced by your administrator', |
| 51 }; | 87 }; |
| 52 | 88 |
| 53 if (hasPolicy) | 89 if (hasPolicy) |
| 54 data.timeZoneAutoDetectValueFromPolicy = opt_autoDetectPolicyValue; | 90 data.timeZoneAutoDetectValueFromPolicy = opt_autoDetectPolicyValue; |
| 55 | 91 |
| 56 window.loadTimeData = new LoadTimeData; | 92 window.loadTimeData = new LoadTimeData; |
| 57 loadTimeData.data = data; | 93 loadTimeData.data = data; |
| 58 | 94 |
| 59 var dateTime = document.createElement('settings-date-time-page'); | 95 var dateTime = document.createElement('settings-date-time-page'); |
| 60 dateTime.prefs = prefs; | 96 dateTime.prefs = |
| 97 updatePrefsWithPolicy(prefs, hasPolicy, opt_autoDetectPolicyValue); | |
| 61 CrSettingsPrefs.setInitialized(); | 98 CrSettingsPrefs.setInitialized(); |
| 62 | 99 |
| 63 document.body.appendChild(dateTime); | 100 document.body.appendChild(dateTime); |
| 101 cr.webUIListenerCallback( | |
| 102 'time-zone-auto-detect-policy', hasPolicy, opt_autoDetectPolicyValue); | |
| 64 return dateTime; | 103 return dateTime; |
| 65 } | 104 } |
| 66 | 105 |
| 67 // CrOS sends time zones as [id, friendly name] pairs. | 106 // CrOS sends time zones as [id, friendly name] pairs. |
| 68 var fakeTimeZones = [ | 107 var fakeTimeZones = [ |
| 69 ['Westeros/Highgarden', '(KNG-2:00) The Reach Time (Highgarden)'], | 108 ['Westeros/Highgarden', '(KNG-2:00) The Reach Time (Highgarden)'], |
| 70 ['Westeros/Winterfell', '(KNG-1:00) The North Time (Winterfell)'], | 109 ['Westeros/Winterfell', '(KNG-1:00) The North Time (Winterfell)'], |
| 71 ['Westeros/Kings_Landing', | 110 ['Westeros/Kings_Landing', |
| 72 '(KNG+0:00) Westeros Standard Time (King\'s Landing)'], | 111 '(KNG+0:00) Westeros Standard Time (King\'s Landing)'], |
| 73 ['Westeros/TheEyrie', '(KNG+1:00) The Vale Time (The Eyrie)'], | 112 ['Westeros/TheEyrie', '(KNG+1:00) The Vale Time (The Eyrie)'], |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 103 }); | 142 }); |
| 104 }); | 143 }); |
| 105 | 144 |
| 106 suiteTeardown(function() { | 145 suiteTeardown(function() { |
| 107 // TODO(michaelpg): Removes the element before exiting, because the | 146 // TODO(michaelpg): Removes the element before exiting, because the |
| 108 // <paper-tooltip> in <cr-policy-indicator> somehow causes warnings | 147 // <paper-tooltip> in <cr-policy-indicator> somehow causes warnings |
| 109 // and/or script errors in axs_testing.js. | 148 // and/or script errors in axs_testing.js. |
| 110 PolymerTest.clearBody(); | 149 PolymerTest.clearBody(); |
| 111 }); | 150 }); |
| 112 | 151 |
| 113 function verifyAutoDetectSetting(autoDetect) { | 152 function verifyAutoDetectSetting(autoDetect, managed) { |
| 114 assertEquals(autoDetect, dateTime.$$('settings-dropdown-menu').disabled); | 153 Polymer.dom.flush(); |
| 115 assertEquals(autoDetect, dateTime.$.timeZoneAutoDetect.checked); | 154 var selector = dateTime.$$('#userTimeZoneSelector'); |
| 155 var selectorHidden = selector ? selector.hidden : true; | |
| 156 assertEquals(managed || autoDetect, selectorHidden); | |
| 157 | |
| 158 var checkButton = dateTime.$$('#timeZoneAutoDetect'); | |
| 159 var checkButtonChecked = checkButton ? checkButton.checked : false; | |
| 160 if (!managed) | |
| 161 assertEquals(autoDetect, checkButtonChecked); | |
| 116 } | 162 } |
| 117 | 163 |
| 118 function verifyPolicy(policy) { | 164 function verifyPolicy(policy) { |
| 119 Polymer.dom.flush(); | 165 Polymer.dom.flush(); |
| 120 var indicator = dateTime.$$('cr-policy-indicator'); | 166 var indicator = |
| 167 dateTime.$$('#timeZoneAutoDetect').$$('cr-policy-pref-indicator'); | |
| 168 if (indicator && indicator.style.display == 'none') | |
| 169 indicator = null; | |
| 121 | 170 |
| 122 if (policy) { | 171 if (policy) { |
| 123 assertTrue(!!indicator); | 172 assertTrue(!!indicator); |
| 124 assertTrue(indicator.indicatorVisible); | 173 assertTrue(indicator.indicatorVisible); |
| 125 } else { | 174 } else { |
| 126 // Indicator should be missing dom-ifed out. | 175 // Indicator should be missing dom-ifed out. |
| 127 assertFalse(!!indicator); | 176 assertFalse(!!indicator); |
| 128 } | 177 } |
| 129 | 178 |
| 130 assertEquals(policy, dateTime.$.timeZoneAutoDetect.disabled); | 179 assertEquals( |
| 180 policy, dateTime.$$('#timeZoneAutoDetect').$$('#control').disabled); | |
| 131 } | 181 } |
| 132 | 182 |
| 133 function verifyTimeZonesPopulated(populated) { | 183 function verifyTimeZonesPopulated(populated) { |
| 134 var dropdown = dateTime.$$('settings-dropdown-menu'); | 184 Polymer.dom.flush(); |
| 185 var userTimezoneDropdown = dateTime.$$('#userTimeZoneSelector'); | |
| 186 var systemTimezoneDropdown = dateTime.$$('#systemTimezoneSelector'); | |
| 187 | |
| 188 var dropdown = | |
| 189 userTimezoneDropdown ? userTimezoneDropdown : systemTimezoneDropdown; | |
| 135 if (populated) | 190 if (populated) |
| 136 assertEquals(fakeTimeZones.length, dropdown.menuOptions.length); | 191 assertEquals(fakeTimeZones.length, dropdown.menuOptions.length); |
| 137 else | 192 else |
| 138 assertEquals(1, dropdown.menuOptions.length); | 193 assertEquals(1, dropdown.menuOptions.length); |
| 139 } | 194 } |
| 140 | 195 |
| 196 function updatePolicy(dateTime, managed, valueFromPolicy) { | |
| 197 dateTime.prefs = | |
| 198 updatePrefsWithPolicy(dateTime.prefs, managed, valueFromPolicy); | |
| 199 cr.webUIListenerCallback( | |
| 200 'time-zone-auto-detect-policy', managed, valueFromPolicy); | |
| 201 Polymer.dom.flush(); | |
| 202 } | |
| 203 | |
| 141 test('auto-detect on', function(done) { | 204 test('auto-detect on', function(done) { |
| 142 var prefs = getFakePrefs(); | 205 var prefs = getFakePrefs(); |
| 143 dateTime = initializeDateTime(prefs, false); | 206 dateTime = initializeDateTime(prefs, false); |
| 144 | 207 |
| 145 assertTrue(dateTimePageReadyCalled); | 208 assertTrue(dateTimePageReadyCalled); |
| 146 assertFalse(getTimeZonesCalled); | 209 assertFalse(getTimeZonesCalled); |
| 147 | 210 |
| 148 verifyAutoDetectSetting(true); | 211 verifyAutoDetectSetting(true, false); |
| 149 verifyTimeZonesPopulated(false); | 212 verifyTimeZonesPopulated(false); |
| 150 verifyPolicy(false); | 213 verifyPolicy(false); |
| 151 | 214 |
| 152 // Disable auto-detect. | 215 // Disable auto-detect. |
| 153 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 216 MockInteractions.tap(dateTime.$$('#timeZoneAutoDetect').$$('#control')); |
| 154 verifyAutoDetectSetting(false); | 217 verifyAutoDetectSetting(false, false); |
| 155 assertTrue(getTimeZonesCalled); | 218 assertTrue(getTimeZonesCalled); |
| 156 | 219 |
| 157 setTimeout(function() { | 220 setTimeout(function() { |
| 158 verifyTimeZonesPopulated(true); | 221 verifyTimeZonesPopulated(true); |
| 159 done(); | 222 done(); |
| 160 }); | 223 }); |
| 161 }); | 224 }); |
| 162 | 225 |
| 163 test('auto-detect off', function(done) { | 226 test('auto-detect off', function(done) { |
| 164 var prefs = getFakePrefs(); | 227 dateTime = initializeDateTime(getFakePrefs(), false); |
| 165 prefs.settings.resolve_timezone_by_geolocation.value = false; | 228 dateTime.set( |
| 166 dateTime = initializeDateTime(prefs, false); | 229 'prefs.settings.resolve_timezone_by_geolocation.value', false); |
| 167 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); | |
| 168 | 230 |
| 169 assertTrue(dateTimePageReadyCalled); | 231 assertTrue(dateTimePageReadyCalled); |
| 170 assertTrue(getTimeZonesCalled); | 232 assertTrue(getTimeZonesCalled); |
| 171 | 233 |
| 172 verifyAutoDetectSetting(false); | 234 verifyAutoDetectSetting(false, false); |
| 173 verifyPolicy(false); | 235 verifyPolicy(false); |
| 174 | 236 |
| 175 setTimeout(function() { | 237 setTimeout(function() { |
| 176 verifyTimeZonesPopulated(true); | 238 verifyTimeZonesPopulated(true); |
| 177 | 239 |
| 178 // Enable auto-detect. | 240 // Enable auto-detect. |
| 179 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 241 MockInteractions.tap(dateTime.$$('#timeZoneAutoDetect').$$('#control')); |
| 180 verifyAutoDetectSetting(true); | 242 verifyAutoDetectSetting(true); |
| 181 done(); | 243 done(); |
| 182 }); | 244 }); |
| 183 }); | 245 }); |
| 184 | 246 |
| 185 test('auto-detect forced on', function(done) { | 247 test('auto-detect forced on', function(done) { |
| 186 var prefs = getFakePrefs(); | 248 var prefs = getFakePrefs(); |
| 187 prefs.settings.resolve_timezone_by_geolocation.value = false; | |
| 188 dateTime = initializeDateTime(prefs, true, true); | 249 dateTime = initializeDateTime(prefs, true, true); |
| 189 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, true); | 250 dateTime.set( |
| 251 'prefs.settings.resolve_timezone_by_geolocation.value', false); | |
| 190 | 252 |
| 191 assertTrue(dateTimePageReadyCalled); | 253 assertTrue(dateTimePageReadyCalled); |
| 192 assertFalse(getTimeZonesCalled); | 254 assertFalse(getTimeZonesCalled); |
| 193 | 255 |
| 194 verifyAutoDetectSetting(true); | 256 verifyAutoDetectSetting(true, true); |
| 195 verifyTimeZonesPopulated(false); | 257 verifyTimeZonesPopulated(false); |
| 196 verifyPolicy(true); | 258 verifyPolicy(true); |
| 197 | 259 |
| 198 // Cannot disable auto-detect. | 260 // Cannot disable auto-detect. |
| 199 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 261 MockInteractions.tap(dateTime.$$('#timeZoneAutoDetect').$$('#control')); |
| 200 verifyAutoDetectSetting(true); | 262 verifyAutoDetectSetting(true, true); |
| 201 assertFalse(getTimeZonesCalled); | 263 assertFalse(getTimeZonesCalled); |
| 202 | 264 |
| 203 // Update the policy: force auto-detect off. | 265 // Update the policy: force auto-detect off. |
| 204 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false); | 266 updatePolicy(dateTime, true, false); |
| 205 verifyAutoDetectSetting(false); | 267 verifyAutoDetectSetting(false, true); |
| 206 verifyPolicy(true); | 268 verifyPolicy(true); |
| 207 | 269 |
| 208 assertTrue(getTimeZonesCalled); | 270 assertTrue(getTimeZonesCalled); |
| 209 setTimeout(function() { | 271 setTimeout(function() { |
| 210 verifyTimeZonesPopulated(true); | 272 verifyTimeZonesPopulated(true); |
| 211 done(); | 273 done(); |
| 212 }); | 274 }); |
| 213 }); | 275 }); |
| 214 | 276 |
| 215 test('auto-detect forced off', function(done) { | 277 test('auto-detect forced off', function(done) { |
| 216 var prefs = getFakePrefs(); | 278 var prefs = getFakePrefs(); |
| 217 dateTime = initializeDateTime(prefs, true, false); | 279 dateTime = initializeDateTime(prefs, true, false); |
| 218 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false); | |
| 219 | 280 |
| 220 assertTrue(dateTimePageReadyCalled); | 281 assertTrue(dateTimePageReadyCalled); |
| 221 assertTrue(getTimeZonesCalled); | 282 assertTrue(getTimeZonesCalled); |
| 222 | 283 |
| 223 verifyAutoDetectSetting(false); | 284 verifyAutoDetectSetting(false, true); |
| 224 verifyPolicy(true); | 285 verifyPolicy(true); |
| 225 | 286 |
| 226 setTimeout(function() { | 287 setTimeout(function() { |
| 227 verifyTimeZonesPopulated(true); | 288 verifyTimeZonesPopulated(true); |
| 228 | 289 |
| 229 // Remove the policy so user's preference takes effect. | 290 // Remove the policy so user's preference takes effect. |
| 230 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); | 291 updatePolicy(dateTime, false); |
| 231 verifyAutoDetectSetting(true); | 292 verifyAutoDetectSetting(true, false); |
| 232 verifyPolicy(false); | 293 verifyPolicy(false); |
| 233 | 294 |
| 234 // User can disable auto-detect. | 295 // User can disable auto-detect. |
| 235 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); | 296 MockInteractions.tap(dateTime.$$('#timeZoneAutoDetect').$$('#control')); |
| 236 verifyAutoDetectSetting(false); | 297 verifyAutoDetectSetting(false, false); |
| 237 done(); | 298 done(); |
| 238 }); | 299 }); |
| 239 }); | 300 }); |
| 240 | 301 |
| 241 test('set date and time button', function() { | 302 test('set date and time button', function() { |
| 242 dateTime = initializeDateTime(getFakePrefs(), false); | 303 dateTime = initializeDateTime(getFakePrefs(), false); |
| 243 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); | |
| 244 | 304 |
| 245 var showSetDateTimeUICalled = false; | 305 var showSetDateTimeUICalled = false; |
| 246 registerMessageCallback('showSetDateTimeUI', null, function() { | 306 registerMessageCallback('showSetDateTimeUI', null, function() { |
| 247 assertFalse(showSetDateTimeUICalled); | 307 assertFalse(showSetDateTimeUICalled); |
| 248 showSetDateTimeUICalled = true; | 308 showSetDateTimeUICalled = true; |
| 249 }); | 309 }); |
| 250 | 310 |
| 251 var setDateTimeButton = dateTime.$.setDateTime; | 311 var setDateTimeButton = dateTime.$$('#setDateTime'); |
| 252 assertEquals(0, setDateTimeButton.offsetHeight); | 312 assertEquals(0, setDateTimeButton.offsetHeight); |
| 253 | 313 |
| 254 // Make the date and time editable. | 314 // Make the date and time editable. |
| 255 cr.webUIListenerCallback('can-set-date-time-changed', true); | 315 cr.webUIListenerCallback('can-set-date-time-changed', true); |
| 256 assertGT(setDateTimeButton.offsetHeight, 0); | 316 assertGT(setDateTimeButton.offsetHeight, 0); |
| 257 | 317 |
| 258 assertFalse(showSetDateTimeUICalled); | 318 assertFalse(showSetDateTimeUICalled); |
| 259 MockInteractions.tap(setDateTimeButton); | 319 MockInteractions.tap(setDateTimeButton); |
| 260 assertTrue(showSetDateTimeUICalled); | 320 assertTrue(showSetDateTimeUICalled); |
| 261 | 321 |
| 262 // Make the date and time not editable. | 322 // Make the date and time not editable. |
| 263 cr.webUIListenerCallback('can-set-date-time-changed', false); | 323 cr.webUIListenerCallback('can-set-date-time-changed', false); |
| 264 assertEquals(setDateTimeButton.offsetHeight, 0); | 324 assertEquals(setDateTimeButton.offsetHeight, 0); |
| 265 }); | 325 }); |
| 266 }); | 326 }); |
| 267 })(); | 327 })(); |
| OLD | NEW |