summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-13 12:23:06 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-13 12:23:06 +0000
commitf0e63b4b3b44cb5a0f3099a7f3102d4fe7acf3a7 (patch)
treeb0bc10591db36c04c36023a28dd88d10d7f7d50e
parent16c5c87e1296e597b259ad94d8eb7245bd7956a1 (diff)
downloadchromium_src-f0e63b4b3b44cb5a0f3099a7f3102d4fe7acf3a7.zip
chromium_src-f0e63b4b3b44cb5a0f3099a7f3102d4fe7acf3a7.tar.gz
chromium_src-f0e63b4b3b44cb5a0f3099a7f3102d4fe7acf3a7.tar.bz2
Policy: Add ProxyMode and deprecate ProxyServerMode.
- Add support for 'deprecated' attribute in template generator - Add support for both int- and string- based enums in the template generator - Add logic to handle ProxyMode and fall back to ProxyServerMode BUG=68134 TEST=ConfigurationPolicyPrefStore*, new policy template generator tests Review URL: http://codereview.chromium.org/5958014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71315 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/policy/policy_templates.grd42
-rw-r--r--chrome/app/policy/policy_templates.json96
-rw-r--r--chrome/browser/policy/config_dir_policy_provider_unittest.cc5
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc206
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store_unittest.cc75
-rw-r--r--chrome/browser/policy/configuration_policy_provider_mac_unittest.cc5
-rw-r--r--chrome/browser/policy/configuration_policy_provider_win_unittest.cc5
-rw-r--r--chrome/browser/policy/configuration_policy_store_interface.h7
-rw-r--r--chrome/browser/prefs/pref_service_unittest.cc24
-rw-r--r--chrome/browser/prefs/proxy_prefs.cc20
-rw-r--r--chrome/browser/prefs/proxy_prefs.h8
-rw-r--r--chrome/common/policy_constants.cc7
-rw-r--r--chrome/common/policy_constants.h1
-rw-r--r--tools/grit/grit/format/policy_templates/policy_template_generator.py2
-rw-r--r--tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py39
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer.py13
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py71
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adml_writer.py2
-rw-r--r--tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py52
-rw-r--r--tools/grit/grit/format/policy_templates/writers/admx_writer.py15
-rw-r--r--tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py49
-rw-r--r--tools/grit/grit/format/policy_templates/writers/doc_writer.py26
-rw-r--r--tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py47
-rw-r--r--tools/grit/grit/format/policy_templates/writers/json_writer.py6
-rw-r--r--tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py41
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py4
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py56
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_writer.py11
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py70
-rw-r--r--tools/grit/grit/format/policy_templates/writers/reg_writer.py4
-rw-r--r--tools/grit/grit/format/policy_templates/writers/reg_writer_unittest.py42
-rw-r--r--tools/grit/grit/format/policy_templates/writers/template_writer.py16
32 files changed, 847 insertions, 220 deletions
diff --git a/chrome/app/policy/policy_templates.grd b/chrome/app/policy/policy_templates.grd
index b665271..2fa2016 100644
--- a/chrome/app/policy/policy_templates.grd
+++ b/chrome/app/policy/policy_templates.grd
@@ -285,6 +285,24 @@ templates and will be translated for each locale. -->
If you enable this setting, <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> ignores all proxy-related options specified from the command line.
</message>
+ <message name="IDS_POLICY_PROXYMODE_CAPTION" desc="Text describing the dropdown menu for selecting proxy server mode in the 'proxy' policy settings page.">
+ Choose how to specify proxy server settings
+ </message>
+ <message name="IDS_POLICY_ENUM_PROXYDISABLED_CAPTION" desc="Label in the 'proxy server mode' dropdown menu for selecting no proxy server.">
+ Never use a proxy
+ </message>
+ <message name="IDS_POLICY_ENUM_PROXYAUTODETECT_CAPTION" desc="Label in the 'proxy server mode' dropdown menu for selecting to auto-detect proxy settings.">
+ Auto detect proxy settings
+ </message>
+ <message name="IDS_POLICY_ENUM_PROXYPACSCRIPT_CAPTION" desc="Label in the 'proxy server mode' dropdown menu for selecting pac script proxy settings.">
+ Use a .pac proxy script
+ </message>
+ <message name="IDS_POLICY_ENUM_PROXYFIXEDSERVERS_CAPTION" desc="Label in the 'proxy server mode' dropdown menu for selecting fixed server proxy settings.">
+ Use fixed proxy servers
+ </message>
+ <message name="IDS_POLICY_ENUM_PROXYUSESYSTEM_CAPTION" desc="Label in the 'proxy server mode' dropdown menu for selecting to use system proxy settings.">
+ Use system proxy settings
+ </message>
<message name="IDS_POLICY_PROXYSERVERMODE_CAPTION" desc="Text describing the dropdown menu for selecting proxy server mode in the 'proxy' policy settings page.">
Choose how to specify proxy server settings
</message>
@@ -312,7 +330,25 @@ templates and will be translated for each locale. -->
<message name="IDS_POLICY_PROXYPACURL_CAPTION" desc="The label of the 'proxy pac URL' text field in the 'proxy' policy settings page.">
URL to a proxy .pac file
</message>
- <message name="IDS_POLICY_PROXYSERVERMODE_DESC" desc="The description of the 'proxy bypass rules' policy when displayed in OSX Workgroup Manager.">
+ <message name="IDS_POLICY_PROXYMODE_DESC" desc="The description of the 'proxy mode' policy when displayed in OSX Workgroup Manager.">
+ Allows you to specify the proxy server used by <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> and prevents users from changing proxy settings.
+
+ If you choose to never use a proxy server and always connect directly, all other options are ignored.
+
+ If you choose to use system proxy settings or auto detect the proxy server, all other options are ignored.
+
+ If you choose fixed server proxy mode, you can specify further options in 'Address or URL of proxy server' and 'Comma-separated list of proxy bypass rules'.
+
+ If you choose to use a .pac proxy script, you must specify the URL to the script in 'URL to a proxy .pac file'.
+
+ For detailed examples, visit:
+ <ph name="PROXY_HELP_URL">$2<ex>http://www.chromium.org/developers/design-documents/network-settings#TOC-Command-line-options-for-proxy-sett</ex></ph>
+
+ If you enable this setting, <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> ignores all proxy-related options specified from the command line.
+ </message>
+ <message name="IDS_POLICY_PROXYSERVERMODE_DESC" desc="The description of the 'proxy server mode'">
+ This policy is deprecated, use ProxyMode instead.
+
Allows you to specify the proxy server used by <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> and prevents users from changing proxy settings.
If you choose to never use a proxy server and always connect directly, all other options are ignored.
@@ -867,6 +903,10 @@ templates and will be translated for each locale. -->
desc="Text of a link in the generated policy documentation, that takes the user to the top of the page">
Back to top
</message>
+ <message name="IDS_POLICY_DOC_DEPRECATED"
+ desc="Text appended in parentheses to the policy name to indicate that it has been deprecated">
+ deprecated
+ </message>
<message name="IDS_POLICY_DOC_SUPPORTED"
desc="Appears next to the name of each supported feature in the 'list of supported policy features' in the generated policy documentation">
Yes
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 274e00a..2b7d4b3 100644
--- a/chrome/app/policy/policy_templates.json
+++ b/chrome/app/policy/policy_templates.json
@@ -21,7 +21,10 @@
# 'group': - not a real policy, contains a list of policies
# NOTE: Currently nesting groups inside other groups is not supported.
# 'string' - a string value
-# 'enum' - the user can select its value from a collection of items
+# 'int-enum' - the user can select an integer value from a collection of
+# items
+# 'string-enum' - the user can select a string value from a collection of
+# items
# 'main' - a boolean value
# 'list' - a list of string values
#
@@ -72,8 +75,8 @@
# Currently supported product names:
# 'chrome_frame', 'chrome_os'
# 'chrome.win', 'chrome.linux', 'chrome.mac', 'chrome.*'
-# For example if 'chrome.*:5-10' is specified for a policy, then it should
-# be read as:
+# For example if 'chrome.*:5-10' is specified for a policy, then it should
+# be read as:
# 'chrome.linux:5-10,chrome.mac:5-10,chrome.win:5-10'
# The product name also affects in which templates will the policy be included.
# chrome.*, chrome.win, chrome_frame -> ADM,ADMX,ADML,doc
@@ -250,15 +253,32 @@
'type': 'group',
'policies': [
{
+ 'name': 'ProxyMode',
+ 'type': 'string-enum',
+ 'items': [
+ {'name': 'ProxyDisabled', 'value': 'direct'},
+ {'name': 'ProxyAutoDetect', 'value': 'auto_detect'},
+ {'name': 'ProxyPacScript', 'value': 'pac_script'},
+ {'name': 'ProxyFixedServers', 'value': 'fixed_servers'},
+ {'name': 'ProxyUseSystem', 'value': 'system'},
+ ],
+ 'supported_on': ['chrome.*:10-'],
+ 'annotations': {
+ 'features': {'dynamic_refresh': 1},
+ 'example_value': 'direct'
+ }
+ },
+ {
'name': 'ProxyServerMode',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'ProxyServerDisabled', 'value': '0'},
- {'name': 'ProxyServerAutoDetect', 'value': '1'},
- {'name': 'ProxyServerManual', 'value': '2'},
- {'name': 'ProxyServerUseSystem', 'value': '3'},
+ {'name': 'ProxyServerDisabled', 'value': 0},
+ {'name': 'ProxyServerAutoDetect', 'value': 1},
+ {'name': 'ProxyServerManual', 'value': 2},
+ {'name': 'ProxyServerUseSystem', 'value': 3},
],
'supported_on': ['chrome.*:8-'],
+ 'deprecated' : True,
'annotations': {
'features': {'dynamic_refresh': 1},
'example_value': 2,
@@ -412,11 +432,11 @@
'type': 'group',
'policies': [{
'name': 'RestoreOnStartup',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'RestoreOnStartupIsNone', 'value': '0'},
- {'name': 'RestoreOnStartupIsLastSession', 'value': '1'},
- {'name': 'RestoreOnStartupIsURLs', 'value': '4'},
+ {'name': 'RestoreOnStartupIsNone', 'value': 0},
+ {'name': 'RestoreOnStartupIsLastSession', 'value': 1},
+ {'name': 'RestoreOnStartupIsURLs', 'value': 4},
],
'supported_on': ['chrome.*:8-'],
'annotations': {
@@ -517,10 +537,10 @@
'policies': [
{
'name': 'DefaultCookiesSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowCookies', 'value': '0'},
- {'name': 'BlockCookies', 'value': '1'},
+ {'name': 'AllowCookies', 'value': 0},
+ {'name': 'BlockCookies', 'value': 1},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -530,10 +550,10 @@
},
{
'name': 'DefaultImagesSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowImages', 'value': '0'},
- {'name': 'BlockImages', 'value': '1'},
+ {'name': 'AllowImages', 'value': 0},
+ {'name': 'BlockImages', 'value': 1},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -543,10 +563,10 @@
},
{
'name': 'DefaultJavaScriptSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowJavaScript', 'value': '0'},
- {'name': 'BlockJavaScript', 'value': '1'},
+ {'name': 'AllowJavaScript', 'value': 0},
+ {'name': 'BlockJavaScript', 'value': 1},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -556,10 +576,10 @@
},
{
'name': 'DefaultPluginsSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowPlugins', 'value': '0'},
- {'name': 'BlockPlugins', 'value': '1'},
+ {'name': 'AllowPlugins', 'value': 0},
+ {'name': 'BlockPlugins', 'value': 1},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -569,10 +589,10 @@
},
{
'name': 'DefaultPopupsSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowPopups', 'value': '0'},
- {'name': 'BlockPopups', 'value': '1'},
+ {'name': 'AllowPopups', 'value': 0},
+ {'name': 'BlockPopups', 'value': 1},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -582,11 +602,11 @@
},
{
'name': 'DefaultNotificationSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowNotifications', 'value': '0'},
- {'name': 'BlockNotifications', 'value': '1'},
- {'name': 'AskNotifications', 'value': '2'},
+ {'name': 'AllowNotifications', 'value': 0},
+ {'name': 'BlockNotifications', 'value': 1},
+ {'name': 'AskNotifications', 'value': 2},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -596,11 +616,11 @@
},
{
'name': 'DefaultGeolocationSetting',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'AllowGeolocation', 'value': '0'},
- {'name': 'BlockGeolocation', 'value': '1'},
- {'name': 'AskGeolocation', 'value': '2'},
+ {'name': 'AllowGeolocation', 'value': 0},
+ {'name': 'BlockGeolocation', 'value': 1},
+ {'name': 'AskGeolocation', 'value': 2},
],
'supported_on': ['chrome.*:10-'],
'annotations': {
@@ -625,10 +645,10 @@
'type': 'group',
'policies': [{
'name': 'ChromeFrameRendererSettings',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'RenderInHost', 'value': '0'},
- {'name': 'RenderInChromeFrame', 'value': '1'},
+ {'name': 'RenderInHost', 'value': 0},
+ {'name': 'RenderInChromeFrame', 'value': 1},
],
'supported_on': ['chrome_frame:8-'],
'annotations': {
diff --git a/chrome/browser/policy/config_dir_policy_provider_unittest.cc b/chrome/browser/policy/config_dir_policy_provider_unittest.cc
index 982ac6fe..30c2189 100644
--- a/chrome/browser/policy/config_dir_policy_provider_unittest.cc
+++ b/chrome/browser/policy/config_dir_policy_provider_unittest.cc
@@ -261,9 +261,12 @@ INSTANTIATE_TEST_CASE_P(
ValueTestParams::ForStringPolicy(
kPolicyDefaultSearchProviderEncodings,
key::kDefaultSearchProviderEncodings),
- ValueTestParams::ForIntegerPolicy(
+ ValueTestParams::ForStringPolicy(
kPolicyProxyMode,
key::kProxyMode),
+ ValueTestParams::ForIntegerPolicy(
+ kPolicyProxyServerMode,
+ key::kProxyServerMode),
ValueTestParams::ForStringPolicy(
kPolicyProxyServer,
key::kProxyServer),
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index 1330279..58b5cac 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -106,8 +106,9 @@ class ConfigurationPolicyPrefKeeper
// respective values in |prefs_|.
void FinalizeProxyPolicySettings();
- // Returns true if the policy values stored in proxy_* represent a valid
- // proxy configuration.
+ // Returns true if the policy values stored in proxy_* represent a valid proxy
+ // configuration, including the case in which there is no configuration at
+ // all.
bool CheckProxySettings();
// Assumes CheckProxySettings returns true and applies the values stored
@@ -363,6 +364,7 @@ bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy(
// FinalizeProxyPolicySettings() is called to determine whether the presented
// values were correct and apply them in that case.
if (policy == kPolicyProxyMode ||
+ policy == kPolicyProxyServerMode ||
policy == kPolicyProxyServer ||
policy == kPolicyProxyPacUrl ||
policy == kPolicyProxyBypassList) {
@@ -492,96 +494,151 @@ void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() {
bool ConfigurationPolicyPrefKeeper::CheckProxySettings() {
bool mode = HasProxyPolicy(kPolicyProxyMode);
+ bool server_mode = HasProxyPolicy(kPolicyProxyServerMode); // deprecated
bool server = HasProxyPolicy(kPolicyProxyServer);
bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl);
bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList);
- if ((server || pac_url || bypass_list) && !mode) {
+ if ((server || pac_url || bypass_list) && !(mode || server_mode)) {
LOG(WARNING) << "A centrally-administered policy defines proxy setting"
<< " details without setting a proxy mode.";
return false;
}
- if (!mode)
- return true;
+ // If there's a server mode, convert it into a mode.
+ std::string mode_value;
+ if (mode) {
+ if (server_mode)
+ LOG(WARNING) << "Both ProxyMode and ProxyServerMode policies defined, "
+ << "ignoring ProxyMode.";
+ if (!proxy_policies_[kPolicyProxyMode]->GetAsString(&mode_value)) {
+ LOG(WARNING) << "Invalid ProxyMode value.";
+ return false;
+ }
+ } else if (server_mode) {
+ int server_mode_value;
+ if (!proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(
+ &server_mode_value)) {
+ LOG(WARNING) << "Invalid ProxyServerMode value.";
+ return false;
+ }
- int mode_value;
- if (!proxy_policies_[kPolicyProxyMode]->GetAsInteger(&mode_value)) {
- LOG(WARNING) << "Invalid proxy mode value.";
- return false;
+ switch (server_mode_value) {
+ case kPolicyNoProxyServerMode:
+ mode_value = ProxyPrefs::kDirectProxyModeName;
+ break;
+ case kPolicyAutoDetectProxyServerMode:
+ mode_value = ProxyPrefs::kAutoDetectProxyModeName;
+ break;
+ case kPolicyManuallyConfiguredProxyServerMode:
+ if (server && pac_url) {
+ LOG(WARNING) << "A centrally-administered policy dictates that"
+ << " both fixed proxy servers and a .pac url. should"
+ << " be used for proxy configuration.";
+ return false;
+ }
+ if (!server && !pac_url) {
+ LOG(WARNING) << "A centrally-administered policy dictates that the"
+ << " proxy settings should use either fixed proxy"
+ << " servers or a .pac url, but specifies neither.";
+ return false;
+ }
+ if (pac_url)
+ mode_value = ProxyPrefs::kPacScriptProxyModeName;
+ else
+ mode_value = ProxyPrefs::kFixedServersProxyModeName;
+ break;
+ case kPolicyUseSystemProxyServerMode:
+ mode_value = ProxyPrefs::kSystemProxyModeName;
+ break;
+ default:
+ LOG(WARNING) << "Invalid proxy mode " << server_mode_value;
+ return false;
+ }
}
- switch (mode_value) {
- case kPolicyNoProxyServerMode:
- if (server || pac_url || bypass_list) {
- LOG(WARNING) << "A centrally-administered policy disables the use of"
- << " a proxy but also specifies an explicit proxy"
- << " configuration.";
- return false;
- }
- break;
- case kPolicyAutoDetectProxyMode:
- if (server || bypass_list || pac_url) {
- LOG(WARNING) << "A centrally-administered policy dictates that a proxy"
- << " shall be auto configured but specifies fixed proxy"
- << " servers, a by-pass list or a .pac script URL.";
- return false;
- }
- break;
- case kPolicyManuallyConfiguredProxyMode:
- if (server && pac_url) {
- LOG(WARNING) << "A centrally-administered policy dictates that the"
- << " system proxy settings should use both a fixed"
- << " proxy server and a .pac url.";
- return false;
- }
- if (!server && !pac_url) {
- LOG(WARNING) << "A centrally-administered policy dictates that the"
- << " system proxy settings should use either a fixed"
- << " proxy server or a .pac url, but specifies neither.";
- return false;
- }
- break;
- case kPolicyUseSystemProxyMode:
- if (server || pac_url || bypass_list) {
- LOG(WARNING) << "A centrally-administered policy dictates that the"
- << " system proxy settings should be used but also "
- << " specifies an explicit proxy configuration.";
- return false;
- }
- break;
- default:
- LOG(WARNING) << "Invalid proxy mode " << mode_value;
+ // If neither ProxyMode nor ProxyServerMode are specified, mode_value will be
+ // empty and the proxy shouldn't be configured at all.
+ if (mode_value.empty())
+ return true;
+
+ if (mode_value == ProxyPrefs::kDirectProxyModeName) {
+ if (server || pac_url || bypass_list) {
+ LOG(WARNING) << "A centrally-administered policy disables the use of"
+ << " a proxy but also specifies an explicit proxy"
+ << " configuration.";
+ return false;
+ }
+ } else if (mode_value == ProxyPrefs::kAutoDetectProxyModeName) {
+ if (server || bypass_list || pac_url) {
+ LOG(WARNING) << "A centrally-administered policy dictates that a proxy"
+ << " shall be auto configured but specifies fixed proxy"
+ << " servers, a by-pass list or a .pac script URL.";
return false;
+ }
+ } else if (mode_value == ProxyPrefs::kPacScriptProxyModeName) {
+ if (server || bypass_list) {
+ LOG(WARNING) << "A centrally-administered policy dictates that a .pac"
+ << " script URL should be used for proxy configuration but"
+ << " also specifies policies required only for fixed"
+ << " proxy servers.";
+ return false;
+ }
+ } else if (mode_value == ProxyPrefs::kFixedServersProxyModeName) {
+ if (pac_url) {
+ LOG(WARNING) << "A centrally-administered policy dictates that"
+ << " fixed proxy servers should be used but also"
+ << " specifies a .pac script URL.";
+ return false;
+ }
+ } else if (mode_value == ProxyPrefs::kSystemProxyModeName) {
+ if (server || pac_url || bypass_list) {
+ LOG(WARNING) << "A centrally-administered policy dictates that the"
+ << " system proxy settings should be used but also "
+ << " specifies an explicit proxy configuration.";
+ return false;
+ }
+ } else {
+ LOG(WARNING) << "Invalid proxy mode " << mode_value;
+ return false;
}
return true;
}
void ConfigurationPolicyPrefKeeper::ApplyProxySettings() {
- if (!HasProxyPolicy(kPolicyProxyMode))
- return;
-
- int int_mode;
- CHECK(proxy_policies_[kPolicyProxyMode]->GetAsInteger(&int_mode));
ProxyPrefs::ProxyMode mode;
- switch (int_mode) {
- case kPolicyNoProxyServerMode:
- mode = ProxyPrefs::MODE_DIRECT;
- break;
- case kPolicyAutoDetectProxyMode:
- mode = ProxyPrefs::MODE_AUTO_DETECT;
- break;
- case kPolicyManuallyConfiguredProxyMode:
- mode = ProxyPrefs::MODE_FIXED_SERVERS;
- if (HasProxyPolicy(kPolicyProxyPacUrl))
- mode = ProxyPrefs::MODE_PAC_SCRIPT;
- break;
- case kPolicyUseSystemProxyMode:
- mode = ProxyPrefs::MODE_SYSTEM;
- break;
- default:
- mode = ProxyPrefs::MODE_DIRECT;
- NOTREACHED();
+ if (HasProxyPolicy(kPolicyProxyMode)) {
+ std::string string_mode;
+ CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode));
+ if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) {
+ LOG(WARNING) << "A centrally-administered policy specifies a value for"
+ << "the ProxyMode policy that isn't recognized.";
+ return;
+ }
+ } else if (HasProxyPolicy(kPolicyProxyServerMode)) {
+ int int_mode = 0;
+ CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode));
+ switch (int_mode) {
+ case kPolicyNoProxyServerMode:
+ mode = ProxyPrefs::MODE_DIRECT;
+ break;
+ case kPolicyAutoDetectProxyServerMode:
+ mode = ProxyPrefs::MODE_AUTO_DETECT;
+ break;
+ case kPolicyManuallyConfiguredProxyServerMode:
+ mode = ProxyPrefs::MODE_FIXED_SERVERS;
+ if (HasProxyPolicy(kPolicyProxyPacUrl))
+ mode = ProxyPrefs::MODE_PAC_SCRIPT;
+ break;
+ case kPolicyUseSystemProxyServerMode:
+ mode = ProxyPrefs::MODE_SYSTEM;
+ break;
+ default:
+ mode = ProxyPrefs::MODE_DIRECT;
+ NOTREACHED();
+ }
+ } else {
+ return;
}
prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode));
@@ -710,7 +767,8 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
key::kDefaultSearchProviderIconURL },
{ kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING,
key::kDefaultSearchProviderEncodings },
- { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode },
+ { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode },
+ { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode },
{ kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer },
{ kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl },
{ kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList },
diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
index 9f461c1..d81ff91 100644
--- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
@@ -269,9 +269,9 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
Value::CreateStringValue("http://chromium.org/override"));
provider.AddPolicy(kPolicyProxyServer,
Value::CreateStringValue("chromium.org"));
- provider.AddPolicy(kPolicyProxyMode,
+ provider.AddPolicy(kPolicyProxyServerMode,
Value::CreateIntegerValue(
- kPolicyManuallyConfiguredProxyMode));
+ kPolicyManuallyConfiguredProxyServerMode));
ConfigurationPolicyPrefStore store(&provider);
VerifyProxyPrefs(
@@ -281,9 +281,9 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptions) {
TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptionsReversedApplyOrder) {
MockConfigurationPolicyProvider provider;
- provider.AddPolicy(kPolicyProxyMode,
+ provider.AddPolicy(kPolicyProxyServerMode,
Value::CreateIntegerValue(
- kPolicyManuallyConfiguredProxyMode));
+ kPolicyManuallyConfiguredProxyServerMode));
provider.AddPolicy(kPolicyProxyBypassList,
Value::CreateStringValue("http://chromium.org/override"));
provider.AddPolicy(kPolicyProxyServer,
@@ -295,50 +295,95 @@ TEST_F(ConfigurationPolicyPrefStoreProxyTest, ManualOptionsReversedApplyOrder) {
ProxyPrefs::MODE_FIXED_SERVERS);
}
-TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxy) {
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyServerMode) {
MockConfigurationPolicyProvider provider;
- provider.AddPolicy(kPolicyProxyMode,
+ provider.AddPolicy(kPolicyProxyServerMode,
Value::CreateIntegerValue(kPolicyNoProxyServerMode));
ConfigurationPolicyPrefStore store(&provider);
VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_DIRECT);
}
-TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetect) {
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, NoProxyModeName) {
MockConfigurationPolicyProvider provider;
- provider.AddPolicy(kPolicyProxyMode,
- Value::CreateIntegerValue(kPolicyAutoDetectProxyMode));
+ provider.AddPolicy(
+ kPolicyProxyMode,
+ Value::CreateStringValue(ProxyPrefs::kDirectProxyModeName));
+
+ ConfigurationPolicyPrefStore store(&provider);
+ VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_DIRECT);
+}
+
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetectProxyServerMode) {
+ MockConfigurationPolicyProvider provider;
+ provider.AddPolicy(
+ kPolicyProxyServerMode,
+ Value::CreateIntegerValue(kPolicyAutoDetectProxyServerMode));
ConfigurationPolicyPrefStore store(&provider);
VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_AUTO_DETECT);
}
-TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetectPac) {
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, AutoDetectProxyModeName) {
+ MockConfigurationPolicyProvider provider;
+ provider.AddPolicy(
+ kPolicyProxyMode,
+ Value::CreateStringValue(ProxyPrefs::kAutoDetectProxyModeName));
+
+ ConfigurationPolicyPrefStore store(&provider);
+ VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_AUTO_DETECT);
+}
+
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, PacScriptProxyMode) {
MockConfigurationPolicyProvider provider;
provider.AddPolicy(kPolicyProxyPacUrl,
Value::CreateStringValue("http://short.org/proxy.pac"));
provider.AddPolicy(
kPolicyProxyMode,
- Value::CreateIntegerValue(kPolicyManuallyConfiguredProxyMode));
+ Value::CreateStringValue(ProxyPrefs::kPacScriptProxyModeName));
ConfigurationPolicyPrefStore store(&provider);
VerifyProxyPrefs(
store, "", "http://short.org/proxy.pac", "", ProxyPrefs::MODE_PAC_SCRIPT);
}
-TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystem) {
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemProxyServerMode) {
MockConfigurationPolicyProvider provider;
- provider.AddPolicy(kPolicyProxyMode,
- Value::CreateIntegerValue(kPolicyUseSystemProxyMode));
+ provider.AddPolicy(
+ kPolicyProxyServerMode,
+ Value::CreateIntegerValue(kPolicyUseSystemProxyServerMode));
ConfigurationPolicyPrefStore store(&provider);
VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_SYSTEM);
}
+TEST_F(ConfigurationPolicyPrefStoreProxyTest, UseSystemProxyMode) {
+ MockConfigurationPolicyProvider provider;
+ provider.AddPolicy(
+ kPolicyProxyMode,
+ Value::CreateStringValue(ProxyPrefs::kSystemProxyModeName));
+
+ ConfigurationPolicyPrefStore store(&provider);
+ VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_SYSTEM);
+}
+
+TEST_F(ConfigurationPolicyPrefStoreProxyTest,
+ ProxyModeOverridesProxyServerMode) {
+ MockConfigurationPolicyProvider provider;
+ provider.AddPolicy(kPolicyProxyServerMode,
+ Value::CreateIntegerValue(kPolicyNoProxyServerMode));
+ provider.AddPolicy(
+ kPolicyProxyMode,
+ Value::CreateStringValue(ProxyPrefs::kAutoDetectProxyModeName));
+
+ ConfigurationPolicyPrefStore store(&provider);
+ VerifyProxyPrefs(store, "", "", "", ProxyPrefs::MODE_AUTO_DETECT);
+}
+
TEST_F(ConfigurationPolicyPrefStoreProxyTest, ProxyInvalid) {
for (int i = 0; i < MODE_COUNT; ++i) {
MockConfigurationPolicyProvider provider;
- provider.AddPolicy(kPolicyProxyMode, Value::CreateIntegerValue(i));
+ provider.AddPolicy(kPolicyProxyServerMode, Value::CreateIntegerValue(i));
// No mode expects all three parameters being set.
provider.AddPolicy(kPolicyProxyPacUrl,
Value::CreateStringValue("http://short.org/proxy.pac"));
diff --git a/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc b/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc
index 4203fb0..11d04a7 100644
--- a/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc
@@ -235,9 +235,12 @@ INSTANTIATE_TEST_CASE_P(
PolicyTestParams::ForStringPolicy(
kPolicyDefaultSearchProviderEncodings,
key::kDefaultSearchProviderEncodings),
- PolicyTestParams::ForIntegerPolicy(
+ PolicyTestParams::ForStringPolicy(
kPolicyProxyMode,
key::kProxyMode),
+ PolicyTestParams::ForIntegerPolicy(
+ kPolicyProxyServerMode,
+ key::kProxyServerMode),
PolicyTestParams::ForStringPolicy(
kPolicyProxyServer,
key::kProxyServer),
diff --git a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc
index 6085192..481e1d8 100644
--- a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc
@@ -393,9 +393,12 @@ INSTANTIATE_TEST_CASE_P(
PolicyTestParams::ForStringPolicy(
kPolicyDefaultSearchProviderEncodings,
key::kDefaultSearchProviderEncodings),
- PolicyTestParams::ForIntegerPolicy(
+ PolicyTestParams::ForStringPolicy(
kPolicyProxyMode,
key::kProxyMode),
+ PolicyTestParams::ForIntegerPolicy(
+ kPolicyProxyServerMode,
+ key::kProxyServerMode),
PolicyTestParams::ForStringPolicy(
kPolicyProxyServer,
key::kProxyServer),
diff --git a/chrome/browser/policy/configuration_policy_store_interface.h b/chrome/browser/policy/configuration_policy_store_interface.h
index e690242..b7f2f05 100644
--- a/chrome/browser/policy/configuration_policy_store_interface.h
+++ b/chrome/browser/policy/configuration_policy_store_interface.h
@@ -27,6 +27,7 @@ enum ConfigurationPolicyType {
kPolicyDefaultSearchProviderEncodings,
kPolicyDisableSpdy,
kPolicyProxyMode,
+ kPolicyProxyServerMode,
kPolicyProxyServer,
kPolicyProxyPacUrl,
kPolicyProxyBypassList,
@@ -80,11 +81,11 @@ enum PolicyProxyModeType {
// Disable Proxy, connect directly.
kPolicyNoProxyServerMode = 0,
// Auto detect proxy or use specific PAC script if given.
- kPolicyAutoDetectProxyMode = 1,
+ kPolicyAutoDetectProxyServerMode = 1,
// Use manually configured proxy servers (fixed servers).
- kPolicyManuallyConfiguredProxyMode = 2,
+ kPolicyManuallyConfiguredProxyServerMode = 2,
// Use system proxy server.
- kPolicyUseSystemProxyMode = 3,
+ kPolicyUseSystemProxyServerMode = 3,
MODE_COUNT
};
diff --git a/chrome/browser/prefs/pref_service_unittest.cc b/chrome/browser/prefs/pref_service_unittest.cc
index 1a79708..3ead502 100644
--- a/chrome/browser/prefs/pref_service_unittest.cc
+++ b/chrome/browser/prefs/pref_service_unittest.cc
@@ -154,9 +154,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) {
command_line.AppendSwitchASCII(switches::kProxyServer, "789");
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyManuallyConfiguredProxyMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kFixedServersProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
provider->AddPolicy(policy::kPolicyProxyBypassList,
Value::CreateStringValue("abc"));
provider->AddPolicy(policy::kPolicyProxyServer,
@@ -194,9 +194,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
command_line.AppendSwitchASCII(switches::kProxyServer, "789");
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyAutoDetectProxyMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kAutoDetectProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
// First verify that command-line options are set correctly when
// there is no policy in effect.
@@ -229,9 +229,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
command_line.AppendSwitch(switches::kNoProxyServer);
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyAutoDetectProxyMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kAutoDetectProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
// First verify that command-line options are set correctly when
// there is no policy in effect.
@@ -263,9 +263,9 @@ TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
command_line.AppendSwitch(switches::kProxyAutoDetect);
scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
new policy::MockConfigurationPolicyProvider());
- Value* mode_value = Value::CreateIntegerValue(
- policy::kPolicyNoProxyServerMode);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_value);
+ Value* mode_name = Value::CreateStringValue(
+ ProxyPrefs::kDirectProxyModeName);
+ provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
// First verify that the auto-detect is set if there is no managed
// PrefStore.
diff --git a/chrome/browser/prefs/proxy_prefs.cc b/chrome/browser/prefs/proxy_prefs.cc
index 7eb504c..fadd562 100644
--- a/chrome/browser/prefs/proxy_prefs.cc
+++ b/chrome/browser/prefs/proxy_prefs.cc
@@ -7,15 +7,25 @@
#include "base/basictypes.h"
#include "base/logging.h"
+namespace ProxyPrefs {
+
+const char kDirectProxyModeName[] = "direct";
+const char kAutoDetectProxyModeName[] = "auto_detect";
+const char kPacScriptProxyModeName[] = "pac_script";
+const char kFixedServersProxyModeName[] = "fixed_servers";
+const char kSystemProxyModeName[] = "system";
+
+}
+
namespace {
// These names are exposed to the proxy extension API. They must be in sync
// with the constants of ProxyPrefs.
-const char* kProxyModeNames[] = { "direct",
- "auto_detect",
- "pac_script",
- "fixed_servers",
- "system" };
+const char* kProxyModeNames[] = { ProxyPrefs::kDirectProxyModeName,
+ ProxyPrefs::kAutoDetectProxyModeName,
+ ProxyPrefs::kPacScriptProxyModeName,
+ ProxyPrefs::kFixedServersProxyModeName,
+ ProxyPrefs::kSystemProxyModeName };
} // namespace
diff --git a/chrome/browser/prefs/proxy_prefs.h b/chrome/browser/prefs/proxy_prefs.h
index bbeb44d..da911d4 100644
--- a/chrome/browser/prefs/proxy_prefs.h
+++ b/chrome/browser/prefs/proxy_prefs.h
@@ -36,6 +36,14 @@ enum ProxyMode {
kModeCount
};
+// Constants for string values used to specify the proxy mode through externally
+// visible APIs, e.g. through policy or the proxy extension API.
+extern const char kDirectProxyModeName[];
+extern const char kAutoDetectProxyModeName[];
+extern const char kPacScriptProxyModeName[];
+extern const char kFixedServersProxyModeName[];
+extern const char kSystemProxyModeName[];
+
bool IntToProxyMode(int in_value, ProxyMode* out_value);
bool StringToProxyMode(const std::string& in_value,
ProxyMode* out_value);
diff --git a/chrome/common/policy_constants.cc b/chrome/common/policy_constants.cc
index 848b28b..032c07a 100644
--- a/chrome/common/policy_constants.cc
+++ b/chrome/common/policy_constants.cc
@@ -34,10 +34,9 @@ const char kDefaultSearchProviderIconURL[] =
const char kDefaultSearchProviderEncodings[] =
"DefaultSearchProviderEncodings";
const char kDisableSpdy[] = "DisableSpdy";
-// We consider the name ProxyMode more apt than ProxyServerMode but could
-// not change it after publishing that name for the win registry and policy
-// config files.
-const char kProxyMode[] = "ProxyServerMode";
+const char kProxyMode[] = "ProxyMode";
+// Deprecated name of policy to set proxy server mode
+const char kProxyServerMode[] = "ProxyServerMode";
const char kProxyServer[] = "ProxyServer";
const char kProxyPacUrl[] = "ProxyPacUrl";
const char kProxyBypassList[] = "ProxyBypassList";
diff --git a/chrome/common/policy_constants.h b/chrome/common/policy_constants.h
index 37464e6..fae7c8b 100644
--- a/chrome/common/policy_constants.h
+++ b/chrome/common/policy_constants.h
@@ -32,6 +32,7 @@ extern const char kDefaultSearchProviderIconURL[];
extern const char kDefaultSearchProviderEncodings[];
extern const char kDisableSpdy[];
extern const char kProxyMode[];
+extern const char kProxyServerMode[];
extern const char kProxyServer[];
extern const char kProxyPacUrl[];
extern const char kProxyBypassList[];
diff --git a/tools/grit/grit/format/policy_templates/policy_template_generator.py b/tools/grit/grit/format/policy_templates/policy_template_generator.py
index cce0116..c80bd64 100644
--- a/tools/grit/grit/format/policy_templates/policy_template_generator.py
+++ b/tools/grit/grit/format/policy_templates/policy_template_generator.py
@@ -129,7 +129,7 @@ class PolicyTemplateGenerator:
policy['supported_on'])
if policy['type'] == 'group':
self._ProcessPolicyList(policy['policies'])
- elif policy['type'] == 'enum':
+ elif policy['type'] in ('string-enum', 'int-enum'):
# Iterate through all the items of an enum-type policy, and add captions.
for item in policy['items']:
self._AddMessageToItem('ENUM_' + item['name'], item, 'caption')
diff --git a/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py b/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py
index d51c0a5..fe27216 100644
--- a/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py
+++ b/tools/grit/grit/format/policy_templates/policy_template_generator_unittest.py
@@ -211,7 +211,7 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
self.tester.fail()
self.do_test(messages_mock, policy_defs_mock, LocalMockWriter())
- def testEnumTexts(self):
+ def testIntEnumTexts(self):
# Test that GUI messages are assigned correctly to enums
# (aka dropdown menus).
messages_mock = {
@@ -224,12 +224,41 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
}
policy_defs_mock = [{
'name': 'Policy1',
- 'type': 'enum',
+ 'type': 'int-enum',
'supported_on': [],
'items': [
- {'name': 'item1', 'value': '0'},
- {'name': 'item2', 'value': '1'},
- {'name': 'item3', 'value': '3'},
+ {'name': 'item1', 'value': 0},
+ {'name': 'item2', 'value': 1},
+ {'name': 'item3', 'value': 3},
+ ]
+ }]
+
+ class LocalMockWriter(mock_writer.MockWriter):
+ def WritePolicy(self, policy):
+ self.tester.assertEquals(policy['items'][0]['caption'], 'string1')
+ self.tester.assertEquals(policy['items'][1]['caption'], 'string2')
+ self.tester.assertEquals(policy['items'][2]['caption'], 'string3')
+ self.do_test(messages_mock, policy_defs_mock, LocalMockWriter())
+
+ def testStringEnumTexts(self):
+ # Test that GUI messages are assigned correctly to enums
+ # (aka dropdown menus).
+ messages_mock = {
+ 'IDS_POLICY_ENUM_ITEM1_CAPTION': 'string1',
+ 'IDS_POLICY_ENUM_ITEM2_CAPTION': 'string2',
+ 'IDS_POLICY_ENUM_ITEM3_CAPTION': 'string3',
+ 'IDS_POLICY_POLICY1_CAPTION': '',
+ 'IDS_POLICY_POLICY1_DESC': '',
+
+ }
+ policy_defs_mock = [{
+ 'name': 'Policy1',
+ 'type': 'string-enum',
+ 'supported_on': [],
+ 'items': [
+ {'name': 'item1', 'value': 'one'},
+ {'name': 'item2', 'value': 'two'},
+ {'name': 'item3', 'value': 'three'},
]
}]
diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer.py b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
index 23df695..3067282 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer.py
@@ -21,7 +21,8 @@ class AdmWriter(template_writer.TemplateWriter):
TYPE_TO_INPUT = {
'string': 'EDITTEXT',
- 'enum': 'DROPDOWNLIST',
+ 'string-enum': 'DROPDOWNLIST',
+ 'int-enum': 'DROPDOWNLIST',
'list': 'LISTBOX'}
NEWLINE = '\r\n'
@@ -76,11 +77,15 @@ class AdmWriter(template_writer.TemplateWriter):
self._PrintLine('VALUEPREFIX ""')
else:
self._PrintLine('VALUENAME "%s"' % policy['name'])
- if policy['type'] == 'enum':
+ if policy['type'] in ('int-enum', 'string-enum'):
self._PrintLine('ITEMLIST', 1)
for item in policy['items']:
- self._PrintLine('NAME !!%s_DropDown VALUE NUMERIC %s' %
- (item['name'], item['value']))
+ if policy['type'] == 'int-enum':
+ value_text = 'NUMERIC ' + str(item['value'])
+ else:
+ value_text = '"' + item['value'] + '"'
+ self._PrintLine('NAME !!%s_DropDown VALUE %s' %
+ (item['name'], value_text))
self._AddGuiString(item['name'] + '_DropDown', item['caption'])
self._PrintLine('END ITEMLIST', -1)
self._PrintLine('END PART', -1)
diff --git a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py
index b823aae..91d71b8d 100644
--- a/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/adm_writer_unittest.py
@@ -154,17 +154,17 @@ StringPolicy_Part="Caption of policy."
'''
self.CompareOutputs(output, expected_output)
- def testEnumPolicy(self):
- # Tests a policy group with a single policy of type 'enum'.
+ def testIntEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'int-enum'.
grd = self.PrepareTest('''
{
'policy_definitions': [
{
'name': 'EnumPolicy',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'ProxyServerDisabled', 'value': '0'},
- {'name': 'ProxyServerAutoDetect', 'value': '1'},
+ {'name': 'ProxyServerDisabled', 'value': 0},
+ {'name': 'ProxyServerAutoDetect', 'value': 1},
],
'supported_on': ['chrome.win:8-']
},
@@ -215,6 +215,67 @@ ProxyServerAutoDetect_DropDown="Option2"
'''
self.CompareOutputs(output, expected_output)
+ def testStringEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'int-enum'.
+ grd = self.PrepareTest('''
+ {
+ 'policy_definitions': [
+ {
+ 'name': 'EnumPolicy',
+ 'type': 'string-enum',
+ 'items': [
+ {'name': 'ProxyServerDisabled', 'value': 'one'},
+ {'name': 'ProxyServerAutoDetect', 'value': 'two'},
+ ],
+ 'supported_on': ['chrome.win:8-']
+ },
+ ],
+ 'placeholders': [],
+ }''', '''
+ <messages>
+ <message name="IDS_POLICY_ENUMPOLICY_CAPTION">Caption of policy.</message>
+ <message name="IDS_POLICY_ENUMPOLICY_DESC">Description of policy.</message>
+ <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">Option1</message>
+ <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">Option2</message>
+ <message name="IDS_POLICY_WIN_SUPPORTED_WINXPSP2">At least Windows 3.14</message>
+ </messages>
+ ''' )
+ output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
+ expected_output = '''CLASS MACHINE
+ CATEGORY !!google
+ CATEGORY !!googlechrome
+ KEYNAME "Software\\Policies\\Google\\Chrome"
+
+ POLICY !!EnumPolicy_Policy
+ #if version >= 4
+ SUPPORTED !!SUPPORTED_WINXPSP2
+ #endif
+ EXPLAIN !!EnumPolicy_Explain
+
+ PART !!EnumPolicy_Part DROPDOWNLIST
+ VALUENAME "EnumPolicy"
+ ITEMLIST
+ NAME !!ProxyServerDisabled_DropDown VALUE "one"
+ NAME !!ProxyServerAutoDetect_DropDown VALUE "two"
+ END ITEMLIST
+ END PART
+ END POLICY
+
+ END CATEGORY
+ END CATEGORY
+
+[Strings]
+SUPPORTED_WINXPSP2="At least Windows 3.14"
+google="Google"
+googlechrome="Google Chrome"
+EnumPolicy_Policy="Caption of policy."
+EnumPolicy_Explain="Description of policy."
+EnumPolicy_Part="Caption of policy."
+ProxyServerDisabled_DropDown="Option1"
+ProxyServerAutoDetect_DropDown="Option2"
+'''
+ self.CompareOutputs(output, expected_output)
+
def testListPolicy(self):
# Tests a policy group with a single policy of type 'list'.
grd = self.PrepareTest('''
diff --git a/tools/grit/grit/format/policy_templates/writers/adml_writer.py b/tools/grit/grit/format/policy_templates/writers/adml_writer.py
index e656dfd..99f9895 100644
--- a/tools/grit/grit/format/policy_templates/writers/adml_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/adml_writer.py
@@ -87,7 +87,7 @@ class ADMLWriter(xml_formatted_writer.XMLFormattedWriter):
{'refId': policy_name})
label_elem = self.AddElement(textbox_elem, 'label')
label_elem.appendChild(self._doc.createTextNode(policy_label))
- elif policy_type == 'enum':
+ elif policy_type in ('int-enum', 'string-enum'):
for item in policy['items']:
self._AddString(self._string_table_elem, item['name'], item['caption'])
dropdownlist_elem = self.AddElement(presentation_elem, 'dropdownList',
diff --git a/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py
index dd4d42e..03a4399 100644
--- a/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/adml_writer_unittest.py
@@ -158,10 +158,58 @@ class AdmlWriterTest(xml_writer_base_unittest.XmlWriterBaseTest):
'</presentation>')
self.AssertXMLEquals(output, expected_output)
- def testEnumPolicy(self):
+ def testIntEnumPolicy(self):
enum_policy = {
'name': 'EnumPolicyStub',
- 'type': 'enum',
+ 'type': 'int-enum',
+ 'caption': 'Enum policy caption',
+ 'label': 'Enum policy label',
+ 'desc': 'This is a test description.',
+ 'items': [
+ {
+ 'name': 'item 1',
+ 'value': 1,
+ 'caption': 'Caption Item 1',
+ },
+ {
+ 'name': 'item 2',
+ 'value': 2,
+ 'caption': 'Caption Item 2',
+ },
+ ],
+ }
+ self. _InitWriterForAddingPolicies(self.writer, enum_policy)
+ self.writer.WritePolicy(enum_policy)
+ # Assert generated string elements.
+ output = self.GetXMLOfChildren(self.writer._string_table_elem)
+ expected_output = (
+ '<string id="EnumPolicyStub">\n'
+ ' Enum policy caption\n'
+ '</string>\n'
+ '<string id="EnumPolicyStub_Explain">\n'
+ ' This is a test description.\n'
+ '</string>\n'
+ '<string id="item 1">\n'
+ ' Caption Item 1\n'
+ '</string>\n'
+ '<string id="item 2">\n'
+ ' Caption Item 2\n'
+ '</string>')
+ self.AssertXMLEquals(output, expected_output)
+ # Assert generated presentation elements.
+ output = self.GetXMLOfChildren(self.writer._presentation_table_elem)
+ expected_output = (
+ '<presentation id="EnumPolicyStub">\n'
+ ' <dropdownList refId="EnumPolicyStub">\n'
+ ' Enum policy label\n'
+ ' </dropdownList>\n'
+ '</presentation>')
+ self.AssertXMLEquals(output, expected_output)
+
+ def testStringEnumPolicy(self):
+ enum_policy = {
+ 'name': 'EnumPolicyStub',
+ 'type': 'string-enum',
'caption': 'Enum policy caption',
'label': 'Enum policy label',
'desc': 'This is a test description.',
diff --git a/tools/grit/grit/format/policy_templates/writers/admx_writer.py b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
index 164175b..1573d78 100644
--- a/tools/grit/grit/format/policy_templates/writers/admx_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
@@ -157,11 +157,12 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
'valueName': name,
}
self.AddElement(parent, 'text', attributes)
-
- def _AddEnumPolicy(self, parent, name, items):
+ def _AddEnumPolicy(self, parent, policy):
'''Generates ADMX elements for an Enum-Policy and adds them to the
passed parent element.
'''
+ name = policy['name']
+ items = policy['items']
attributes = {
'id': name,
'valueName': name,
@@ -172,7 +173,11 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
item_elem = self.AddElement(enum_elem, 'item', attributes)
value_elem = self.AddElement(item_elem, 'value')
attributes = {'value': str(item['value'])}
- self.AddElement(value_elem, 'decimal', attributes)
+ if policy['type'] == 'int-enum':
+ element_type = 'decimal'
+ else:
+ element_type = 'string'
+ self.AddElement(value_elem, element_type, attributes)
def _AddListPolicy(self, parent, name):
'''Generates ADMX XML elements for a List-Policy and adds them to the
@@ -249,9 +254,9 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
elif policy_type == 'string':
parent = self._GetElements(policy_elem)
self._AddStringPolicy(parent, policy_name)
- elif policy_type == 'enum':
+ elif policy_type in ('int-enum', 'string-enum'):
parent = self._GetElements(policy_elem)
- self._AddEnumPolicy(parent, policy_name, policy['items'])
+ self._AddEnumPolicy(parent, policy)
elif policy_type == 'list':
parent = self._GetElements(policy_elem)
self._AddListPolicy(parent, policy_name)
diff --git a/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py
index c645be0..f8b3fa0 100644
--- a/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py
@@ -201,13 +201,13 @@ class AdmxWriterTest(xml_writer_base_unittest.XmlWriterBaseTest):
'</policy>')
self.AssertXMLEquals(output, expected_output)
- def testEnumPolicy(self):
+ def testIntEnumPolicy(self):
enum_policy = {
'name': 'SampleEnumPolicy',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'item 1', 'value': '0'},
- {'name': 'item 2', 'value': '1'},
+ {'name': 'item_1', 'value': 0},
+ {'name': 'item_2', 'value': 1},
]
}
@@ -223,12 +223,12 @@ class AdmxWriterTest(xml_writer_base_unittest.XmlWriterBaseTest):
' <supportedOn ref="SUPPORTED_TESTOS"/>\n'
' <elements>\n'
' <enum id="SampleEnumPolicy" valueName="SampleEnumPolicy">\n'
- ' <item displayName="$(string.item 1)">\n'
+ ' <item displayName="$(string.item_1)">\n'
' <value>\n'
' <decimal value="0"/>\n'
' </value>\n'
' </item>\n'
- ' <item displayName="$(string.item 2)">\n'
+ ' <item displayName="$(string.item_2)">\n'
' <value>\n'
' <decimal value="1"/>\n'
' </value>\n'
@@ -238,6 +238,43 @@ class AdmxWriterTest(xml_writer_base_unittest.XmlWriterBaseTest):
'</policy>')
self.AssertXMLEquals(output, expected_output)
+ def testStringEnumPolicy(self):
+ enum_policy = {
+ 'name': 'SampleEnumPolicy',
+ 'type': 'string-enum',
+ 'items': [
+ {'name': 'item_1', 'value': 'one'},
+ {'name': 'item_2', 'value': 'two'},
+ ]
+ }
+
+ self._initWriterForPolicy(self.writer, enum_policy)
+ self.writer.WritePolicy(enum_policy)
+ output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc))
+ expected_output = (
+ '<policy class="TestClass" displayName="$(string.SampleEnumPolicy)"'
+ ' explainText="$(string.SampleEnumPolicy_Explain)"'
+ ' key="Software\\Policies\\Test" name="SampleEnumPolicy"'
+ ' presentation="$(presentation.SampleEnumPolicy)">\n'
+ ' <parentCategory ref="PolicyGroup"/>\n'
+ ' <supportedOn ref="SUPPORTED_TESTOS"/>\n'
+ ' <elements>\n'
+ ' <enum id="SampleEnumPolicy" valueName="SampleEnumPolicy">\n'
+ ' <item displayName="$(string.item_1)">\n'
+ ' <value>\n'
+ ' <string value="one"/>\n'
+ ' </value>\n'
+ ' </item>\n'
+ ' <item displayName="$(string.item_2)">\n'
+ ' <value>\n'
+ ' <string value="two"/>\n'
+ ' </value>\n'
+ ' </item>\n'
+ ' </enum>\n'
+ ' </elements>\n'
+ '</policy>')
+ self.AssertXMLEquals(output, expected_output)
+
def testListPolicy(self):
list_policy = {
'name': 'SampleListPolicy',
diff --git a/tools/grit/grit/format/policy_templates/writers/doc_writer.py b/tools/grit/grit/format/policy_templates/writers/doc_writer.py
index 320e79d..7e410bc 100644
--- a/tools/grit/grit/format/policy_templates/writers/doc_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/doc_writer.py
@@ -107,7 +107,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
def _AddDescription(self, parent, policy):
'''Adds a string containing the description of the policy. URLs are
replaced with links and the possible choices are enumerated in case
- of 'enum' type policies.
+ of 'string-enum' and 'int-enum' type policies.
Args:
parent: The DOM node for which the feature list will be added.
@@ -116,11 +116,15 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
# Replace URLs with links in the description.
self._AddTextWithLinks(parent, policy['desc'])
# Add list of enum items.
- if policy['type'] == 'enum':
+ if policy['type'] in ('string-enum', 'int-enum'):
ul = self.AddElement(parent, 'ul')
for item in policy['items']:
+ if policy['type'] == 'int-enum':
+ value_string = str(item['value'])
+ else:
+ value_string = '"%s"' % item['value']
self.AddElement(
- ul, 'li', {}, '%s = %s' % (item['value'], item['caption']))
+ ul, 'li', {}, '%s = %s' % (value_string, item['caption']))
def _AddFeatures(self, parent, policy):
'''Adds a string containing the list of supported features of a policy
@@ -253,10 +257,12 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
raise Exception('Expected boolean value.')
elif policy_type == 'string':
self.AddText(parent, '"%s"' % example_value)
- elif policy_type == 'enum':
+ elif policy_type == 'int-enum':
self.AddText(
parent,
'0x%08x (Windows), %d (Linux/Mac)' % (example_value, example_value))
+ elif policy_type == 'string-enum':
+ self.AddText(parent, '"%s"' % (example_value))
elif policy_type == 'list':
self._AddListExample(parent, policy)
else:
@@ -407,7 +413,11 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
self.AddElement(h2, 'a', {'name': policy['name']})
if policy['type'] != 'group':
# Normal policies get a full description.
- self.AddText(h2, policy['name'])
+ policy_name_text = policy['name']
+ if 'deprecated' in policy and policy['deprecated'] == True:
+ policy_name_text += " ("
+ policy_name_text += self._GetLocalizedMessage('deprecated') + ")"
+ self.AddText(h2, policy_name_text)
self.AddElement(parent2, 'span', {}, policy['caption'])
self._AddPolicyNote(parent2, policy)
self._AddPolicyDetails(parent2, policy)
@@ -424,6 +434,9 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
# Implementation of abstract methods of TemplateWriter:
#
+ def IsDeprecatedPolicySupported(self, policy):
+ return True
+
def WritePolicy(self, policy):
self._AddPolicyRow(self._summary_tbody, policy)
self._AddPolicySection(self._details_div, policy)
@@ -490,7 +503,8 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
self._TYPE_MAP = {
'string': 'String (REG_SZ)',
'main': 'Boolean (REG_DWORD)',
- 'enum': 'Integer (REG_DWORD)',
+ 'int-enum': 'Integer (REG_DWORD)',
+ 'string-enum': 'String (REG_SZ)',
'list': 'List of strings',
}
# The CSS style-sheet used for the document. It will be used in Google
diff --git a/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py
index 7d9e1fb0..6a5fd42 100644
--- a/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/doc_writer_unittest.py
@@ -153,11 +153,11 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon):
e3.toxml(),
'<z a="b" style="style1;style2;">text</z>')
- def testAddDescription(self):
- # Test if URLs are replaced and choices of 'enum' policies are listed
+ def testAddDescriptionIntEnum(self):
+ # Test if URLs are replaced and choices of 'int-enum' policies are listed
# correctly.
policy = {
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
{'value': 0, 'caption': 'Disable foo'},
{'value': 2, 'caption': 'Solve your problem'},
@@ -174,6 +174,27 @@ See http://policy-explanation.example.com for more details.
See <a href="http://policy-explanation.example.com">http://policy-explanation.example.com</a> for more details.
<ul><li>0 = Disable foo</li><li>2 = Solve your problem</li><li>5 = Enable bar</li></ul></root>''')
+ def testAddDescriptionStringEnum(self):
+ # Test if URLs are replaced and choices of 'int-enum' policies are listed
+ # correctly.
+ policy = {
+ 'type': 'string-enum',
+ 'items': [
+ {'value': "one", 'caption': 'Disable foo'},
+ {'value': "two", 'caption': 'Solve your problem'},
+ {'value': "three", 'caption': 'Enable bar'},
+ ],
+ 'desc': '''This policy disables foo, except in case of bar.
+See http://policy-explanation.example.com for more details.
+'''
+ }
+ self.writer._AddDescription(self.doc_root, policy)
+ self.assertEquals(
+ self.doc_root.toxml(),
+ '''<root>This policy disables foo, except in case of bar.
+See <a href="http://policy-explanation.example.com">http://policy-explanation.example.com</a> for more details.
+<ul><li>&quot;one&quot; = Disable foo</li><li>&quot;two&quot; = Solve your problem</li><li>&quot;three&quot; = Enable bar</li></ul></root>''')
+
def testAddFeatures(self):
# Test if the list of features of a policy is handled correctly.
policy = {
@@ -252,11 +273,11 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
e2.toxml(),
'<e2>0x00000000 (Windows), false (Linux), &lt;false /&gt; (Mac)</e2>')
- def testEnumExample(self):
- # Test representation of 'enum' example values.
+ def testIntEnumExample(self):
+ # Test representation of 'int-enum' example values.
policy = {
'name': 'PolicyName',
- 'type': 'enum',
+ 'type': 'int-enum',
'annotations': {
'example_value': 16
}
@@ -266,6 +287,20 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
self.doc_root.toxml(),
'<root>0x00000010 (Windows), 16 (Linux/Mac)</root>')
+ def testStringEnumExample(self):
+ # Test representation of 'int-enum' example values.
+ policy = {
+ 'name': 'PolicyName',
+ 'type': 'string-enum',
+ 'annotations': {
+ 'example_value': "wacky"
+ }
+ }
+ self.writer._AddExample(self.doc_root, policy)
+ self.assertEquals(
+ self.doc_root.toxml(),
+ '<root>&quot;wacky&quot;</root>')
+
def testStringExample(self):
# Test representation of 'string' example values.
policy = {
diff --git a/tools/grit/grit/format/policy_templates/writers/json_writer.py b/tools/grit/grit/format/policy_templates/writers/json_writer.py
index 8a6e35f..bc52ed1 100644
--- a/tools/grit/grit/format/policy_templates/writers/json_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/json_writer.py
@@ -39,8 +39,10 @@ class JsonWriter(template_writer.TemplateWriter):
example_value_str = 'true'
else:
example_value_str = 'false'
- elif policy['type'] == 'enum':
- example_value_str = example_value
+ elif policy['type'] == 'string-enum':
+ example_value_str = '"%s"' % example_value;
+ elif policy['type'] == 'int-enum':
+ example_value_str = str(example_value)
else:
raise Exception('unknown policy type %s:' % policy['type'])
diff --git a/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py
index 744eeaa..16ad11b 100644
--- a/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py
@@ -98,14 +98,14 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'}')
self.CompareOutputs(output, expected_output)
- def testEnumPolicy(self):
- # Tests a policy group with a single policy of type 'enum'.
+ def testIntEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'int-enum'.
grd = self.PrepareTest(
'{'
' "policy_definitions": ['
' {'
' "name": "EnumPolicy",'
- ' "type": "enum",'
+ ' "type": "int-enum",'
' "items": ['
' {"name": "ProxyServerDisabled", "value": 0},'
' {"name": "ProxyServerAutoDetect", "value": 1},'
@@ -133,6 +133,41 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'}')
self.CompareOutputs(output, expected_output)
+ def testStringEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'string-enum'.
+ grd = self.PrepareTest(
+ '{'
+ ' "policy_definitions": ['
+ ' {'
+ ' "name": "EnumPolicy",'
+ ' "type": "string-enum",'
+ ' "items": ['
+ ' {"name": "ProxyServerDisabled", "value": "one"},'
+ ' {"name": "ProxyServerAutoDetect", "value": "two"},'
+ ' ],'
+ ' "supported_on": ["chrome.linux:8-"],'
+ ' "annotations": {'
+ ' "example_value": "one"'
+ ' }'
+ ' },'
+ ' ],'
+ ' "placeholders": [],'
+ '}',
+ '<messages>'
+ ' <message name="IDS_POLICY_ENUMPOLICY_CAPTION"></message>'
+ ' <message name="IDS_POLICY_ENUMPOLICY_DESC"></message>'
+ ' <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">'
+ ' </message>'
+ ' <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">'
+ ' </message>'
+ '</messages>')
+ output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en')
+ expected_output = (
+ '{\n'
+ ' "EnumPolicy": "one"\n'
+ '}')
+ self.CompareOutputs(output, expected_output)
+
def testListPolicy(self):
# Tests a policy group with a single policy of type 'list'.
grd = self.PrepareTest(
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py
index 4f699f2..bb1a634 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer.py
@@ -48,11 +48,11 @@ class PListStringsWriter(template_writer.TemplateWriter):
string table.
'''
desc = policy['desc']
- if (policy['type'] == 'enum'):
+ if policy['type'] in ('int-enum','string-enum'):
# Append the captions of enum items to the description string.
item_descs = []
for item in policy['items']:
- item_descs.append(item['value'] + ' - ' + item['caption'])
+ item_descs.append(str(item['value']) + ' - ' + item['caption'])
desc = '\n'.join(item_descs) + '\n' + desc
self._AddToStringTable(policy['name'], policy['label'], desc)
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
index 1fc19c8..f921c16 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
@@ -126,8 +126,8 @@ With a newline.</message>
'"Description of policy.\\nWith a newline.";')
self.assertEquals(output.strip(), expected_output.strip())
- def testEnumPolicy(self):
- # Tests a policy group with a single policy of type 'enum'.
+ def testIntEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'int-enum'.
grd = self.PrepareTest('''
{
'policy_definitions': [
@@ -136,10 +136,10 @@ With a newline.</message>
'type': 'group',
'policies': [{
'name': 'EnumPolicy',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'ProxyServerDisabled', 'value': '0'},
- {'name': 'ProxyServerAutoDetect', 'value': '1'},
+ {'name': 'ProxyServerDisabled', 'value': 0},
+ {'name': 'ProxyServerAutoDetect', 'value': 1},
],
'supported_on': ['chrome.mac:8-'],
}],
@@ -172,6 +172,52 @@ With a newline.</message>
self.assertEquals(output.strip(), expected_output.strip())
+ def testStringEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'string-enum'.
+ grd = self.PrepareTest('''
+ {
+ 'policy_definitions': [
+ {
+ 'name': 'EnumGroup',
+ 'type': 'group',
+ 'policies': [{
+ 'name': 'EnumPolicy',
+ 'type': 'string-enum',
+ 'items': [
+ {'name': 'ProxyServerDisabled', 'value': "one"},
+ {'name': 'ProxyServerAutoDetect', 'value': "two"},
+ ],
+ 'supported_on': ['chrome.mac:8-'],
+ }],
+ },
+ ],
+ 'placeholders': [],
+ }''', '''
+ <messages>
+ <message name="IDS_POLICY_ENUMGROUP_CAPTION">Caption of group.</message>
+ <message name="IDS_POLICY_ENUMGROUP_DESC">Description of group.</message>
+ <message name="IDS_POLICY_ENUMPOLICY_CAPTION">Caption of policy.</message>
+ <message name="IDS_POLICY_ENUMPOLICY_DESC">Description of policy.</message>
+ <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">Option1</message>
+ <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">Option2</message>
+ <message name="IDS_POLICY_MAC_CHROME_PREFERENCES">$1 preferences</message>
+ </messages>
+ ''' )
+ output = self.GetOutput(
+ grd,
+ 'fr',
+ {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
+ 'plist_strings',
+ 'en')
+ expected_output = (
+ 'Google_Chrome.pfm_title = "Google Chrome";\n'
+ 'Google_Chrome.pfm_description = "Google Chrome preferences";\n'
+ 'EnumPolicy.pfm_title = "Caption of policy.";\n'
+ 'EnumPolicy.pfm_description = '
+ '"one - Option1\\ntwo - Option2\\nDescription of policy.";\n')
+
+ self.assertEquals(output.strip(), expected_output.strip())
+
def testNonSupportedPolicy(self):
# Tests a policy that is not supported on Mac, so its strings shouldn't
# be included in the plist string table.
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_writer.py b/tools/grit/grit/format/policy_templates/writers/plist_writer.py
index a0068ac..53461d9 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_writer.py
@@ -24,7 +24,8 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter):
STRING_TABLE = 'Localizable.strings'
TYPE_TO_INPUT = {
'string': 'string',
- 'enum': 'integer',
+ 'int-enum': 'integer',
+ 'string-enum': 'string',
'main': 'boolean',
'list': 'array',
}
@@ -88,10 +89,14 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter):
self._AddTargets(dict)
self._AddStringKeyValuePair(dict, 'pfm_type',
self.TYPE_TO_INPUT[policy_type])
- if (policy_type == 'enum'):
+ if policy_type in ('int-enum', 'string-enum'):
range_list = self._AddKeyValuePair(dict, 'pfm_range_list', 'array')
for item in policy['items']:
- self.AddElement(range_list, 'integer', {}, item['value'])
+ if policy_type == 'int-enum':
+ element_type = 'integer'
+ else:
+ element_type = 'string'
+ self.AddElement(range_list, element_type, {}, str(item['value']))
def BeginTemplate(self):
self._plist.attributes['version'] = '1'
diff --git a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py
index 88240cd..bbb0f52 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_writer_unittest.py
@@ -175,8 +175,8 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
</array>''')
self.assertEquals(output.strip(), expected_output.strip())
- def testEnumPolicy(self):
- # Tests a policy group with a single policy of type 'enum'.
+ def testIntEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'int-enum'.
grd = self.PrepareTest('''
{
'policy_definitions': [
@@ -185,10 +185,10 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'type': 'group',
'policies': [{
'name': 'EnumPolicy',
- 'type': 'enum',
+ 'type': 'int-enum',
'items': [
- {'name': 'ProxyServerDisabled', 'value': '0'},
- {'name': 'ProxyServerAutoDetect', 'value': '1'},
+ {'name': 'ProxyServerDisabled', 'value': 0},
+ {'name': 'ProxyServerAutoDetect', 'value': 1},
],
'supported_on': ['chrome.mac:8-'],
}],
@@ -235,6 +235,66 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
</array>''')
self.assertEquals(output.strip(), expected_output.strip())
+ def testStringEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'string-enum'.
+ grd = self.PrepareTest('''
+ {
+ 'policy_definitions': [
+ {
+ 'name': 'EnumGroup',
+ 'type': 'group',
+ 'policies': [{
+ 'name': 'EnumPolicy',
+ 'type': 'string-enum',
+ 'items': [
+ {'name': 'ProxyServerDisabled', 'value': 'one'},
+ {'name': 'ProxyServerAutoDetect', 'value': 'two'},
+ ],
+ 'supported_on': ['chrome.mac:8-'],
+ }],
+ },
+ ],
+ 'placeholders': [],
+ }''', '''
+ <messages>
+ <message name="IDS_POLICY_ENUMGROUP_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUMGROUP_DESC">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUMPOLICY_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUMPOLICY_DESC">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">This is not tested here.</message>
+ <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">This is not tested here.</message>
+ </messages>
+ ''' )
+ output = self.GetOutput(
+ grd,
+ 'fr',
+ {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
+ 'plist',
+ 'en')
+ expected_output = self._GetExpectedOutputs(
+ 'Google_Chrome', 'com.example.Test2', '''<array>
+ <dict>
+ <key>pfm_name</key>
+ <string>EnumPolicy</string>
+ <key>pfm_description</key>
+ <string/>
+ <key>pfm_title</key>
+ <string/>
+ <key>pfm_targets</key>
+ <array>
+ <string>user-managed</string>
+ </array>
+ <key>pfm_type</key>
+ <string>string</string>
+ <key>pfm_range_list</key>
+ <array>
+ <string>one</string>
+ <string>two</string>
+ </array>
+ </dict>
+ </array>''')
+ self.assertEquals(output.strip(), expected_output.strip())
+
def testNonSupportedPolicy(self):
# Tests a policy that is not supported on Mac, so it shouldn't
# be included in the plist file.
diff --git a/tools/grit/grit/format/policy_templates/writers/reg_writer.py b/tools/grit/grit/format/policy_templates/writers/reg_writer.py
index 92a39c9..5aea50e 100644
--- a/tools/grit/grit/format/policy_templates/writers/reg_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/reg_writer.py
@@ -69,8 +69,10 @@ class RegWriter(template_writer.TemplateWriter):
example_value_str = 'dword:1'
else:
example_value_str = 'dword:0'
- elif policy['type'] == 'enum':
+ elif policy['type'] == 'int-enum':
example_value_str = 'dword:%d' % example_value
+ elif policy['type'] == 'string-enum':
+ example_value_str = '"%s"' % example_value
else:
raise Exception('unknown policy type %s:' % policy['type'])
diff --git a/tools/grit/grit/format/policy_templates/writers/reg_writer_unittest.py b/tools/grit/grit/format/policy_templates/writers/reg_writer_unittest.py
index 9cd614b..2464efd 100644
--- a/tools/grit/grit/format/policy_templates/writers/reg_writer_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/reg_writer_unittest.py
@@ -103,14 +103,14 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'"StringPolicy"="hello, world! \\\" \\\\"'])
self.CompareOutputs(output, expected_output)
- def testEnumPolicy(self):
- # Tests a policy group with a single policy of type 'enum'.
+ def testIntEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'int-enum'.
grd = self.PrepareTest(
'{'
' "policy_definitions": ['
' {'
' "name": "EnumPolicy",'
- ' "type": "enum",'
+ ' "type": "int-enum",'
' "items": ['
' {"name": "ProxyServerDisabled", "value": 0},'
' {"name": "ProxyServerAutoDetect", "value": 1},'
@@ -139,6 +139,42 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'"EnumPolicy"=dword:1'])
self.CompareOutputs(output, expected_output)
+ def testStringEnumPolicy(self):
+ # Tests a policy group with a single policy of type 'string-enum'.
+ grd = self.PrepareTest(
+ '{'
+ ' "policy_definitions": ['
+ ' {'
+ ' "name": "EnumPolicy",'
+ ' "type": "string-enum",'
+ ' "items": ['
+ ' {"name": "ProxyServerDisabled", "value": "one"},'
+ ' {"name": "ProxyServerAutoDetect", "value": "two"},'
+ ' ],'
+ ' "supported_on": ["chrome.win:8-"],'
+ ' "annotations": {'
+ ' "example_value": "two"'
+ ' }'
+ ' },'
+ ' ],'
+ ' "placeholders": [],'
+ '}',
+ '<messages>'
+ ' <message name="IDS_POLICY_ENUMPOLICY_CAPTION"></message>'
+ ' <message name="IDS_POLICY_ENUMPOLICY_DESC"></message>'
+ ' <message name="IDS_POLICY_ENUM_PROXYSERVERDISABLED_CAPTION">'
+ ' </message>'
+ ' <message name="IDS_POLICY_ENUM_PROXYSERVERAUTODETECT_CAPTION">'
+ ' </message>'
+ '</messages>')
+ output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'reg', 'en')
+ expected_output = self.NEWLINE.join([
+ 'Windows Registry Editor Version 5.00',
+ '',
+ '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Google\\Chrome]',
+ '"EnumPolicy"="two"'])
+ self.CompareOutputs(output, expected_output)
+
def testListPolicy(self):
# Tests a policy group with a single policy of type 'list'.
grd = self.PrepareTest(
diff --git a/tools/grit/grit/format/policy_templates/writers/template_writer.py b/tools/grit/grit/format/policy_templates/writers/template_writer.py
index 01c2ef4..ecff851 100644
--- a/tools/grit/grit/format/policy_templates/writers/template_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/template_writer.py
@@ -33,6 +33,18 @@ class TemplateWriter(object):
self.config = config
self.messages = messages
+ def IsDeprecatedPolicySupported(self, policy):
+ '''Checks if the given deprecated policy is supported by the writer.
+
+ Args:
+ policy: The dictionary of the policy.
+
+ Returns:
+ True if the writer chooses to include the deprecated 'policy' in its
+ output.
+ '''
+ return False
+
def IsPolicySupported(self, policy):
'''Checks if the given policy is supported by the writer.
In other words, the set of platforms supported by the writer
@@ -45,6 +57,10 @@ class TemplateWriter(object):
Returns:
True if the writer chooses to include 'policy' in its output.
'''
+ if ('deprecated' in policy and policy['deprecated'] is True and
+ not self.IsDeprecatedPolicySupported(policy)):
+ return False
+
if '*' in self.platforms:
# Currently chrome_os is only catched here.
return True