Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: chrome/test/data/webui/settings/date_time_page_tests.js

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

Powered by Google App Engine
This is Rietveld 408576698