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

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

Issue 2683613003: MD Settings: Fix timezone autodetect policy indicator. (Closed)
Patch Set: Use getter instead of private state. Created 3 years, 10 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: {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 assertTrue(indicator.isActive());
125 } else { 125 } else {
126 // Indicator should be missing or hidden. 126 // Indicator should be missing dom-ifed out.
127 if (indicator) 127 assertFalse(!!indicator);
128 assertEquals(0, indicator.clientHeight);
129 } 128 }
130 129
131 assertEquals(policy, dateTime.$.timeZoneAutoDetect.disabled); 130 assertEquals(policy, dateTime.$.timeZoneAutoDetect.disabled);
132 } 131 }
133 132
134 function verifyTimeZonesPopulated(populated) { 133 function verifyTimeZonesPopulated(populated) {
135 var dropdown = dateTime.$$('settings-dropdown-menu'); 134 var dropdown = dateTime.$$('settings-dropdown-menu');
136 if (populated) 135 if (populated)
137 assertEquals(fakeTimeZones.length, dropdown.menuOptions.length); 136 assertEquals(fakeTimeZones.length, dropdown.menuOptions.length);
138 else 137 else
(...skipping 19 matching lines...) Expand all
158 setTimeout(function() { 157 setTimeout(function() {
159 verifyTimeZonesPopulated(true); 158 verifyTimeZonesPopulated(true);
160 done(); 159 done();
161 }); 160 });
162 }); 161 });
163 162
164 test('auto-detect off', function(done) { 163 test('auto-detect off', function(done) {
165 var prefs = getFakePrefs(); 164 var prefs = getFakePrefs();
166 prefs.settings.resolve_timezone_by_geolocation.value = false; 165 prefs.settings.resolve_timezone_by_geolocation.value = false;
167 dateTime = initializeDateTime(prefs, false); 166 dateTime = initializeDateTime(prefs, false);
167 cr.webUIListenerCallback('time-zone-auto-detect-policy', false);
168 168
169 assertTrue(dateTimePageReadyCalled); 169 assertTrue(dateTimePageReadyCalled);
170 assertTrue(getTimeZonesCalled); 170 assertTrue(getTimeZonesCalled);
171 171
172 verifyAutoDetectSetting(false); 172 verifyAutoDetectSetting(false);
173 verifyPolicy(false); 173 verifyPolicy(false);
174 174
175 setTimeout(function() { 175 setTimeout(function() {
176 verifyTimeZonesPopulated(true); 176 verifyTimeZonesPopulated(true);
177 177
178 // Enable auto-detect. 178 // Enable auto-detect.
179 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); 179 MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
180 verifyAutoDetectSetting(true); 180 verifyAutoDetectSetting(true);
181 done(); 181 done();
182 }); 182 });
183 }); 183 });
184 184
185 test('auto-detect forced on', function(done) { 185 test('auto-detect forced on', function(done) {
186 var prefs = getFakePrefs(); 186 var prefs = getFakePrefs();
187 prefs.settings.resolve_timezone_by_geolocation.value = false; 187 prefs.settings.resolve_timezone_by_geolocation.value = false;
188 dateTime = initializeDateTime(prefs, true, true); 188 dateTime = initializeDateTime(prefs, true, true);
189 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, true);
189 190
190 assertTrue(dateTimePageReadyCalled); 191 assertTrue(dateTimePageReadyCalled);
191 assertFalse(getTimeZonesCalled); 192 assertFalse(getTimeZonesCalled);
192 193
193 verifyAutoDetectSetting(true); 194 verifyAutoDetectSetting(true);
194 verifyTimeZonesPopulated(false); 195 verifyTimeZonesPopulated(false);
195 verifyPolicy(true); 196 verifyPolicy(true);
196 197
197 // Cannot disable auto-detect. 198 // Cannot disable auto-detect.
198 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); 199 MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
199 verifyAutoDetectSetting(true); 200 verifyAutoDetectSetting(true);
200 assertFalse(getTimeZonesCalled); 201 assertFalse(getTimeZonesCalled);
201 202
202 // Update the policy: force auto-detect off. 203 // Update the policy: force auto-detect off.
203 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false); 204 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false);
204 verifyAutoDetectSetting(false); 205 verifyAutoDetectSetting(false);
205 verifyPolicy(true); 206 verifyPolicy(true);
206 207
207 assertTrue(getTimeZonesCalled); 208 assertTrue(getTimeZonesCalled);
208 setTimeout(function() { 209 setTimeout(function() {
209 verifyTimeZonesPopulated(true); 210 verifyTimeZonesPopulated(true);
210 done(); 211 done();
211 }); 212 });
212 }); 213 });
213 214
214 test('auto-detect forced off', function(done) { 215 test('auto-detect forced off', function(done) {
215 var prefs = getFakePrefs(); 216 var prefs = getFakePrefs();
216 dateTime = initializeDateTime(prefs, true, false); 217 dateTime = initializeDateTime(prefs, true, false);
218 cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false);
217 219
218 assertTrue(dateTimePageReadyCalled); 220 assertTrue(dateTimePageReadyCalled);
219 assertTrue(getTimeZonesCalled); 221 assertTrue(getTimeZonesCalled);
220 222
221 verifyAutoDetectSetting(false); 223 verifyAutoDetectSetting(false);
222 verifyPolicy(true); 224 verifyPolicy(true);
223 225
224 setTimeout(function() { 226 setTimeout(function() {
225 verifyTimeZonesPopulated(true); 227 verifyTimeZonesPopulated(true);
226 228
227 // Remove the policy so user's preference takes effect. 229 // Remove the policy so user's preference takes effect.
228 cr.webUIListenerCallback('time-zone-auto-detect-policy', false); 230 cr.webUIListenerCallback('time-zone-auto-detect-policy', false);
229 verifyAutoDetectSetting(true); 231 verifyAutoDetectSetting(true);
230 verifyPolicy(false); 232 verifyPolicy(false);
231 233
232 // User can disable auto-detect. 234 // User can disable auto-detect.
233 MockInteractions.tap(dateTime.$.timeZoneAutoDetect); 235 MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
234 verifyAutoDetectSetting(false); 236 verifyAutoDetectSetting(false);
235 done(); 237 done();
236 }); 238 });
237 }); 239 });
238 240
239 test('set date and time button', function() { 241 test('set date and time button', function() {
240 dateTime = initializeDateTime(getFakePrefs(), false); 242 dateTime = initializeDateTime(getFakePrefs(), false);
243 cr.webUIListenerCallback('time-zone-auto-detect-policy', false);
241 244
242 var showSetDateTimeUICalled = false; 245 var showSetDateTimeUICalled = false;
243 registerMessageCallback('showSetDateTimeUI', null, function() { 246 registerMessageCallback('showSetDateTimeUI', null, function() {
244 assertFalse(showSetDateTimeUICalled); 247 assertFalse(showSetDateTimeUICalled);
245 showSetDateTimeUICalled = true; 248 showSetDateTimeUICalled = true;
246 }); 249 });
247 250
248 var setDateTimeButton = dateTime.$.setDateTime; 251 var setDateTimeButton = dateTime.$.setDateTime;
249 assertEquals(0, setDateTimeButton.offsetHeight); 252 assertEquals(0, setDateTimeButton.offsetHeight);
250 253
251 // Make the date and time editable. 254 // Make the date and time editable.
252 cr.webUIListenerCallback('can-set-date-time-changed', true); 255 cr.webUIListenerCallback('can-set-date-time-changed', true);
253 assertGT(setDateTimeButton.offsetHeight, 0); 256 assertGT(setDateTimeButton.offsetHeight, 0);
254 257
255 assertFalse(showSetDateTimeUICalled); 258 assertFalse(showSetDateTimeUICalled);
256 MockInteractions.tap(setDateTimeButton); 259 MockInteractions.tap(setDateTimeButton);
257 assertTrue(showSetDateTimeUICalled); 260 assertTrue(showSetDateTimeUICalled);
258 261
259 // Make the date and time not editable. 262 // Make the date and time not editable.
260 cr.webUIListenerCallback('can-set-date-time-changed', false); 263 cr.webUIListenerCallback('can-set-date-time-changed', false);
261 assertEquals(setDateTimeButton.offsetHeight, 0); 264 assertEquals(setDateTimeButton.offsetHeight, 0);
262 }); 265 });
263 }); 266 });
264 })(); 267 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698