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

Unified Diff: chrome/test/data/webui/settings/date_time_page_tests.js

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Try remove g_browser_process check Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/settings/date_time_page_tests.js
diff --git a/chrome/test/data/webui/settings/date_time_page_tests.js b/chrome/test/data/webui/settings/date_time_page_tests.js
index 7a48d13e35637b5028a409a64ec03292b7bd2ba9..5eadd97fbb38fda666302982ff76ec5566acc02c 100644
--- a/chrome/test/data/webui/settings/date_time_page_tests.js
+++ b/chrome/test/data/webui/settings/date_time_page_tests.js
@@ -27,10 +27,39 @@
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: true,
},
+ timezone: {
+ key: 'settings.timezone',
+ type: chrome.settingsPrivate.PrefType.STRING,
+ value: 'Westeros/Kings_Landing',
+ },
},
};
}
+ function updatePrefsWithPolicy(prefs, managed, valueFromPolicy) {
+ var prefsCopy = JSON.parse(JSON.stringify(prefs));
+ if (managed) {
+ prefsCopy.settings.resolve_timezone_by_geolocation.controlledBy =
+ 'USER_POLICY';
+ prefsCopy.settings.resolve_timezone_by_geolocation.enforcement =
+ 'ENFORCED';
+ prefsCopy.settings.resolve_timezone_by_geolocation.value =
+ valueFromPolicy;
+ prefsCopy.settings.timezone.controlledBy = 'USER_POLICY';
+ prefsCopy.settings.timezone.enforcement = 'ENFORCED';
+ } else {
+ prefsCopy.settings.resolve_timezone_by_geolocation.controlledBy =
+ undefined;
+ prefsCopy.settings.resolve_timezone_by_geolocation.enforcement =
+ undefined;
+ // Auto-resolve defaults to true.
+ prefsCopy.settings.resolve_timezone_by_geolocation.value = true;
+ prefsCopy.settings.timezone.controlledBy = undefined;
+ prefsCopy.settings.timezone.enforcement = undefined;
+ }
+ return prefsCopy;
+ }
+
/**
* Sets up fakes and creates the date time element.
* @param {!Object} prefs
@@ -57,10 +86,13 @@
loadTimeData.data = data;
var dateTime = document.createElement('settings-date-time-page');
- dateTime.prefs = prefs;
+ dateTime.prefs =
+ updatePrefsWithPolicy(prefs, hasPolicy, opt_autoDetectPolicyValue);
CrSettingsPrefs.setInitialized();
document.body.appendChild(dateTime);
+ cr.webUIListenerCallback(
+ 'time-zone-auto-detect-policy', hasPolicy, opt_autoDetectPolicyValue);
return dateTime;
}
@@ -110,14 +142,19 @@
PolymerTest.clearBody();
});
- function verifyAutoDetectSetting(autoDetect) {
- assertEquals(autoDetect, dateTime.$$('settings-dropdown-menu').disabled);
- assertEquals(autoDetect, dateTime.$.timeZoneAutoDetect.checked);
+ function verifyAutoDetectSetting(autoDetect, managed) {
+ assertEquals(
+ managed || autoDetect, dateTime.$.userTimeZoneSelector.hidden);
+ if (!managed)
+ assertEquals(autoDetect, dateTime.$.timeZoneAutoDetect.checked);
}
function verifyPolicy(policy) {
Polymer.dom.flush();
- var indicator = dateTime.$$('cr-policy-indicator');
+ var indicator =
+ dateTime.$.timeZoneAutoDetect.$$('cr-policy-pref-indicator');
+ if (indicator && indicator.style.display == 'none')
+ indicator = null;
if (policy) {
assertTrue(!!indicator);
@@ -127,7 +164,7 @@
assertFalse(!!indicator);
}
- assertEquals(policy, dateTime.$.timeZoneAutoDetect.disabled);
+ assertEquals(policy, dateTime.$.timeZoneAutoDetect.$.control.disabled);
}
function verifyTimeZonesPopulated(populated) {
@@ -138,6 +175,14 @@
assertEquals(1, dropdown.menuOptions.length);
}
+ function updatePolicy(dateTime, managed, valueFromPolicy) {
+ dateTime.prefs =
+ updatePrefsWithPolicy(dateTime.prefs, managed, valueFromPolicy);
+ cr.webUIListenerCallback(
+ 'time-zone-auto-detect-policy', managed, valueFromPolicy);
+ Polymer.dom.flush();
+ }
+
test('auto-detect on', function(done) {
var prefs = getFakePrefs();
dateTime = initializeDateTime(prefs, false);
@@ -145,13 +190,13 @@
assertTrue(dateTimePageReadyCalled);
assertFalse(getTimeZonesCalled);
- verifyAutoDetectSetting(true);
+ verifyAutoDetectSetting(true, false);
verifyTimeZonesPopulated(false);
verifyPolicy(false);
// Disable auto-detect.
- MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
- verifyAutoDetectSetting(false);
+ MockInteractions.tap(dateTime.$.timeZoneAutoDetect.$.control);
+ verifyAutoDetectSetting(false, false);
assertTrue(getTimeZonesCalled);
setTimeout(function() {
@@ -161,22 +206,21 @@
});
test('auto-detect off', function(done) {
- var prefs = getFakePrefs();
- prefs.settings.resolve_timezone_by_geolocation.value = false;
- dateTime = initializeDateTime(prefs, false);
- cr.webUIListenerCallback('time-zone-auto-detect-policy', false);
+ dateTime = initializeDateTime(getFakePrefs(), false);
+ dateTime.set(
+ 'prefs.settings.resolve_timezone_by_geolocation.value', false);
assertTrue(dateTimePageReadyCalled);
assertTrue(getTimeZonesCalled);
- verifyAutoDetectSetting(false);
+ verifyAutoDetectSetting(false, false);
verifyPolicy(false);
setTimeout(function() {
verifyTimeZonesPopulated(true);
// Enable auto-detect.
- MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
+ MockInteractions.tap(dateTime.$.timeZoneAutoDetect.$.control);
verifyAutoDetectSetting(true);
done();
});
@@ -184,25 +228,25 @@
test('auto-detect forced on', function(done) {
var prefs = getFakePrefs();
- prefs.settings.resolve_timezone_by_geolocation.value = false;
dateTime = initializeDateTime(prefs, true, true);
- cr.webUIListenerCallback('time-zone-auto-detect-policy', true, true);
+ dateTime.set(
+ 'prefs.settings.resolve_timezone_by_geolocation.value', false);
assertTrue(dateTimePageReadyCalled);
assertFalse(getTimeZonesCalled);
- verifyAutoDetectSetting(true);
+ verifyAutoDetectSetting(true, true);
verifyTimeZonesPopulated(false);
verifyPolicy(true);
// Cannot disable auto-detect.
- MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
- verifyAutoDetectSetting(true);
+ MockInteractions.tap(dateTime.$.timeZoneAutoDetect.$.control);
+ verifyAutoDetectSetting(true, true);
assertFalse(getTimeZonesCalled);
// Update the policy: force auto-detect off.
- cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false);
- verifyAutoDetectSetting(false);
+ updatePolicy(dateTime, true, false);
+ verifyAutoDetectSetting(false, true);
verifyPolicy(true);
assertTrue(getTimeZonesCalled);
@@ -215,32 +259,30 @@
test('auto-detect forced off', function(done) {
var prefs = getFakePrefs();
dateTime = initializeDateTime(prefs, true, false);
- cr.webUIListenerCallback('time-zone-auto-detect-policy', true, false);
assertTrue(dateTimePageReadyCalled);
assertTrue(getTimeZonesCalled);
- verifyAutoDetectSetting(false);
+ verifyAutoDetectSetting(false, true);
verifyPolicy(true);
setTimeout(function() {
verifyTimeZonesPopulated(true);
// Remove the policy so user's preference takes effect.
- cr.webUIListenerCallback('time-zone-auto-detect-policy', false);
- verifyAutoDetectSetting(true);
+ updatePolicy(dateTime, false);
+ verifyAutoDetectSetting(true, false);
verifyPolicy(false);
// User can disable auto-detect.
- MockInteractions.tap(dateTime.$.timeZoneAutoDetect);
- verifyAutoDetectSetting(false);
+ MockInteractions.tap(dateTime.$.timeZoneAutoDetect.$.control);
+ verifyAutoDetectSetting(false, false);
done();
});
});
test('set date and time button', function() {
dateTime = initializeDateTime(getFakePrefs(), false);
- cr.webUIListenerCallback('time-zone-auto-detect-policy', false);
var showSetDateTimeUICalled = false;
registerMessageCallback('showSetDateTimeUI', null, function() {

Powered by Google App Engine
This is Rietveld 408576698