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