aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org>2014-10-16 12:01:31 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org>2014-10-16 12:01:31 +0000
commit7a723127024fcbd803abd07500fb736f37493187 (patch)
treec599cd94b8c4e51e18d246685e427be9396115f9
parent26b8eddb3579661bb2277c229ebc0ff9e07467b0 (diff)
downloadgrit-7a723127024fcbd803abd07500fb736f37493187.tar.gz
Add a chromium version to policy template files.
CL by cschuet@chromium.org, reviewed at https://codereview.chromium.org/631223003. BUG=108941 TEST=python test_suite_all.py Review URL: https://codereview.chromium.org/642443004 git-svn-id: http://grit-i18n.googlecode.com/svn/trunk@178 7262f16d-afe8-6277-6482-052fa10e57b1
-rw-r--r--grit/format/policy_templates/writer_configuration.py2
-rw-r--r--grit/format/policy_templates/writers/adm_writer.py6
-rw-r--r--grit/format/policy_templates/writers/adm_writer_unittest.py36
-rw-r--r--grit/format/policy_templates/writers/adml_writer.py3
-rw-r--r--grit/format/policy_templates/writers/adml_writer_unittest.py14
-rw-r--r--grit/format/policy_templates/writers/admx_writer.py3
-rw-r--r--grit/format/policy_templates/writers/admx_writer_unittest.py35
-rw-r--r--grit/format/policy_templates/writers/doc_writer.py4
-rw-r--r--grit/format/policy_templates/writers/doc_writer_unittest.py26
-rw-r--r--grit/format/policy_templates/writers/ios_plist_writer.py3
-rw-r--r--grit/format/policy_templates/writers/ios_plist_writer_unittest.py19
-rw-r--r--grit/format/policy_templates/writers/json_writer.py6
-rw-r--r--grit/format/policy_templates/writers/json_writer_unittest.py24
-rw-r--r--grit/format/policy_templates/writers/plist_strings_writer.py6
-rw-r--r--grit/format/policy_templates/writers/plist_strings_writer_unittest.py27
-rw-r--r--grit/format/policy_templates/writers/plist_writer.py4
-rw-r--r--grit/format/policy_templates/writers/plist_writer_unittest.py59
-rw-r--r--grit/format/policy_templates/writers/reg_writer.py11
-rw-r--r--grit/format/policy_templates/writers/reg_writer_unittest.py14
-rw-r--r--grit/format/policy_templates/writers/template_writer.py16
20 files changed, 312 insertions, 6 deletions
diff --git a/grit/format/policy_templates/writer_configuration.py b/grit/format/policy_templates/writer_configuration.py
index 88de6b5..db9613b 100644
--- a/grit/format/policy_templates/writer_configuration.py
+++ b/grit/format/policy_templates/writer_configuration.py
@@ -52,6 +52,8 @@ def GetConfigurationForBuild(defines):
}
else:
raise Exception('Unknown build')
+ if 'version' in defines:
+ config['version'] = defines['version']
config['win_group_policy_class'] = 'Both'
config['win_supported_os'] = 'SUPPORTED_WINXPSP2'
if 'mac_bundle_id' in defines:
diff --git a/grit/format/policy_templates/writers/adm_writer.py b/grit/format/policy_templates/writers/adm_writer.py
index bffbeb5..0413e06 100644
--- a/grit/format/policy_templates/writers/adm_writer.py
+++ b/grit/format/policy_templates/writers/adm_writer.py
@@ -152,6 +152,9 @@ class AdmWriter(template_writer.TemplateWriter):
builder.AddLine('END POLICY', -1)
builder.AddLine()
+ def WriteComment(self, comment):
+ self.lines.AddLine('; ' + comment)
+
def WritePolicy(self, policy):
if self.CanBeMandatory(policy):
self._WritePolicy(policy,
@@ -205,6 +208,9 @@ class AdmWriter(template_writer.TemplateWriter):
return lines
def BeginTemplate(self):
+ if self._GetChromiumVersionString() is not None:
+ self.WriteComment(self.config['build'] + ' version: ' + \
+ self._GetChromiumVersionString())
self._AddGuiString(self.config['win_supported_os'],
self.messages['win_supported_winxpsp2']['text'])
category_path = self.config['win_mandatory_category_path']
diff --git a/grit/format/policy_templates/writers/adm_writer_unittest.py b/grit/format/policy_templates/writers/adm_writer_unittest.py
index 82374bb..27e5314 100644
--- a/grit/format/policy_templates/writers/adm_writer_unittest.py
+++ b/grit/format/policy_templates/writers/adm_writer_unittest.py
@@ -76,6 +76,42 @@ chromium="Chromium"
chromium_recommended="Chromium - Recommended"''')
self.CompareOutputs(output, expected_output)
+ def testVersionAnnotation(self):
+ # Test PListWriter in case of empty polices.
+ grd = self.PrepareTest('''
+ {
+ 'policy_definitions': [],
+ 'placeholders': [],
+ 'messages': {
+ 'win_supported_winxpsp2': {
+ 'text': 'At least "Windows 3.11', 'desc': 'blah'
+ },
+ 'doc_recommended': {
+ 'text': 'Recommended', 'desc': 'bleh'
+ }
+ }
+ }''')
+ output = self.GetOutput(
+ grd, 'fr', {'_chromium': '1', 'version':'39.0.0.0'}, 'adm', 'en')
+ expected_output = '; chromium version: 39.0.0.0\n' + \
+ self.ConstructOutput(['MACHINE', 'USER'], '''
+ CATEGORY !!chromium
+ KEYNAME "Software\\Policies\\Chromium"
+
+ END CATEGORY
+
+ CATEGORY !!chromium_recommended
+ KEYNAME "Software\\Policies\\Chromium\\Recommended"
+
+ END CATEGORY
+
+
+''', '''[Strings]
+SUPPORTED_WINXPSP2="At least "Windows 3.11"
+chromium="Chromium"
+chromium_recommended="Chromium - Recommended"''')
+ self.CompareOutputs(output, expected_output)
+
def testMainPolicy(self):
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest('''
diff --git a/grit/format/policy_templates/writers/adml_writer.py b/grit/format/policy_templates/writers/adml_writer.py
index c525602..5a6e7ee 100644
--- a/grit/format/policy_templates/writers/adml_writer.py
+++ b/grit/format/policy_templates/writers/adml_writer.py
@@ -161,6 +161,9 @@ class ADMLWriter(xml_formatted_writer.XMLFormattedWriter):
dom_impl = minidom.getDOMImplementation('')
self._doc = dom_impl.createDocument(None, 'policyDefinitionResources',
None)
+ if self._GetChromiumVersionString() is not None:
+ self.AddComment(self._doc.documentElement, self.config['build'] + \
+ ' version: ' + self._GetChromiumVersionString())
policy_definitions_resources_elem = self._doc.documentElement
policy_definitions_resources_elem.attributes['revision'] = '1.0'
policy_definitions_resources_elem.attributes['schemaVersion'] = '1.0'
diff --git a/grit/format/policy_templates/writers/adml_writer_unittest.py b/grit/format/policy_templates/writers/adml_writer_unittest.py
index 8a8f4f7..ecafece 100644
--- a/grit/format/policy_templates/writers/adml_writer_unittest.py
+++ b/grit/format/policy_templates/writers/adml_writer_unittest.py
@@ -77,6 +77,20 @@ class AdmlWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest):
'</resources></policyDefinitionResources>')
self.AssertXMLEquals(output, expected_output)
+ def testVersionAnnotation(self):
+ self.writer.config['version'] = '39.0.0.0'
+ self.writer.BeginTemplate()
+ self.writer.EndTemplate()
+ output = self.writer.GetTemplateText()
+ expected_output = (
+ '<?xml version="1.0" ?><policyDefinitionResources'
+ ' revision="1.0" schemaVersion="1.0"><!--test version: 39.0.0.0-->'
+ '<displayName/><description/><resources><stringTable>'
+ '<string id="SUPPORTED_TESTOS">Supported on'
+ ' Test OS or higher</string></stringTable><presentationTable/>'
+ '</resources></policyDefinitionResources>')
+ self.AssertXMLEquals(output, expected_output)
+
def testPolicyGroup(self):
empty_policy_group = {
'name': 'PolicyGroup',
diff --git a/grit/format/policy_templates/writers/admx_writer.py b/grit/format/policy_templates/writers/admx_writer.py
index 0d4394b..5eb4475 100644
--- a/grit/format/policy_templates/writers/admx_writer.py
+++ b/grit/format/policy_templates/writers/admx_writer.py
@@ -349,6 +349,9 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
'''
dom_impl = minidom.getDOMImplementation('')
self._doc = dom_impl.createDocument(None, 'policyDefinitions', None)
+ if self._GetChromiumVersionString() is not None:
+ self.AddComment(self._doc.documentElement, self.config['build'] + \
+ ' version: ' + self._GetChromiumVersionString())
policy_definitions_elem = self._doc.documentElement
policy_definitions_elem.attributes['revision'] = '1.0'
diff --git a/grit/format/policy_templates/writers/admx_writer_unittest.py b/grit/format/policy_templates/writers/admx_writer_unittest.py
index cb3d39e..477a9b6 100644
--- a/grit/format/policy_templates/writers/admx_writer_unittest.py
+++ b/grit/format/policy_templates/writers/admx_writer_unittest.py
@@ -37,7 +37,8 @@ class AdmxWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest):
'win_mandatory_category_path': ['test_category'],
'win_recommended_category_path': ['test_recommended_category'],
'admx_namespace': 'ADMXWriter.Test.Namespace',
- 'admx_prefix': 'test_prefix'
+ 'admx_prefix': 'test_prefix',
+ 'build': 'test_product',
}
self.writer = admx_writer.GetWriter(config)
self.writer.Init()
@@ -82,6 +83,38 @@ class AdmxWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest):
'</policyDefinitions>')
self.AssertXMLEquals(output, expected_output)
+ def testEmptyVersion(self):
+ self.writer.config['version'] = '39.0.0.0'
+ self.writer.BeginTemplate()
+ self.writer.EndTemplate()
+
+ output = self.writer.GetTemplateText()
+ expected_output = (
+ '<?xml version="1.0" ?>\n'
+ '<policyDefinitions revision="1.0" schemaVersion="1.0">\n'
+ ' <!--test_product version: 39.0.0.0-->\n'
+ ' <policyNamespaces>\n'
+ ' <target namespace="ADMXWriter.Test.Namespace"'
+ ' prefix="test_prefix"/>\n'
+ ' <using namespace="Microsoft.Policies.Windows" prefix="windows"/>\n'
+ ' </policyNamespaces>\n'
+ ' <resources minRequiredRevision="1.0"/>\n'
+ ' <supportedOn>\n'
+ ' <definitions>\n'
+ ' <definition displayName="'
+ '$(string.SUPPORTED_TESTOS)" name="SUPPORTED_TESTOS"/>\n'
+ ' </definitions>\n'
+ ' </supportedOn>\n'
+ ' <categories>\n'
+ ' <category displayName="$(string.test_category)"'
+ ' name="test_category"/>\n'
+ ' <category displayName="$(string.test_recommended_category)"'
+ ' name="test_recommended_category"/>\n'
+ ' </categories>\n'
+ ' <policies/>\n'
+ '</policyDefinitions>')
+ self.AssertXMLEquals(output, expected_output)
+
def testEmptyPolicyGroup(self):
empty_policy_group = {
'name': 'PolicyGroup',
diff --git a/grit/format/policy_templates/writers/doc_writer.py b/grit/format/policy_templates/writers/doc_writer.py
index d8f108d..e90e16c 100644
--- a/grit/format/policy_templates/writers/doc_writer.py
+++ b/grit/format/policy_templates/writers/doc_writer.py
@@ -590,6 +590,10 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
def BeginTemplate(self):
# Add a <div> for the summary section.
+ if self._GetChromiumVersionString() is not None:
+ self.AddComment(self._main_div, self.config['build'] + \
+ ' version: ' + self._GetChromiumVersionString())
+
summary_div = self.AddElement(self._main_div, 'div')
self.AddElement(summary_div, 'a', {'name': 'top'})
self.AddElement(summary_div, 'br')
diff --git a/grit/format/policy_templates/writers/doc_writer_unittest.py b/grit/format/policy_templates/writers/doc_writer_unittest.py
index 15d8b85..db03808 100644
--- a/grit/format/policy_templates/writers/doc_writer_unittest.py
+++ b/grit/format/policy_templates/writers/doc_writer_unittest.py
@@ -39,6 +39,7 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'os_name': 'Chrome OS',
'win_reg_mandatory_key_name': 'MockKey',
'win_reg_recommended_key_name': 'MockKeyRec',
+ 'build': 'test_product',
})
self.writer.messages = {
'doc_back_to_top': {'text': '_test_back_to_top'},
@@ -103,6 +104,31 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'<div/>'
'</div>')
+ def testVersionAnnotation(self):
+ # Test if DocWriter creates the skeleton of the document correctly.
+ self.writer.config['version'] = '39.0.0.0'
+ self.writer.BeginTemplate()
+ self.assertEquals(
+ self.writer._main_div.toxml(),
+ '<div>'
+ '<!--test_product version: 39.0.0.0-->'
+ '<div>'
+ '<a name="top"/><br/>_test_intro<br/><br/><br/>'
+ '<table style="style_table;">'
+ '<thead><tr style="style_tr;">'
+ '<td style="style_td;style_td.left;style_thead td;">'
+ '_test_name_column_title'
+ '</td>'
+ '<td style="style_td;style_td.right;style_thead td;">'
+ '_test_description_column_title'
+ '</td>'
+ '</tr></thead>'
+ '<tbody/>'
+ '</table>'
+ '</div>'
+ '<div/>'
+ '</div>')
+
def testGetLocalizedMessage(self):
# Test if localized messages are retrieved correctly.
self.writer.messages = {
diff --git a/grit/format/policy_templates/writers/ios_plist_writer.py b/grit/format/policy_templates/writers/ios_plist_writer.py
index 1da64aa..b726ffa 100644
--- a/grit/format/policy_templates/writers/ios_plist_writer.py
+++ b/grit/format/policy_templates/writers/ios_plist_writer.py
@@ -97,6 +97,9 @@ class IOSPlistWriter(plist_writer.PListWriter):
self._plist.attributes['version'] = '1.0'
self._root_dict = self.AddElement(self._plist, 'dict')
self.AddComment(self._root_dict, CHROME_POLICY_COMMENT)
+ if self._GetChromiumVersionString() is not None:
+ self.AddComment(self._root_dict, ' ' + self.config['build'] + \
+ ' version: ' + self._GetChromiumVersionString() + ' ')
self._dict = self._AddKeyValuePair(self._root_dict, 'ChromePolicy', 'dict')
self._encoded_plist.attributes['version'] = '1.0'
diff --git a/grit/format/policy_templates/writers/ios_plist_writer_unittest.py b/grit/format/policy_templates/writers/ios_plist_writer_unittest.py
index 4743e4e..0fdecb1 100644
--- a/grit/format/policy_templates/writers/ios_plist_writer_unittest.py
+++ b/grit/format/policy_templates/writers/ios_plist_writer_unittest.py
@@ -55,11 +55,17 @@ class IOSPListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
expected_output,
parse,
decode_and_parse):
+
+
+ _defines = { '_chromium': '1',
+ 'mac_bundle_id': 'com.example.Test',
+ 'version': '39.0.0.0' }
+
# Generate the grit output for |templates|.
output = self.GetOutput(
self.PrepareTest(templates),
'fr',
- { '_chromium': '1', 'mac_bundle_id': 'com.example.Test' },
+ _defines,
'ios_plist',
'en')
@@ -124,6 +130,17 @@ class IOSPListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
expected = {}
self._VerifyGeneratedOutput(templates, expected)
+ def testEmptyVersion(self):
+ templates = '''
+ {
+ 'policy_definitions': [],
+ 'placeholders': [],
+ 'messages': {},
+ }
+ '''
+ expected = {}
+ self._VerifyGeneratedOutput(templates, expected)
+
def testBoolean(self):
templates = self._MakeTemplate('BooleanPolicy', 'main', 'True')
expected = {
diff --git a/grit/format/policy_templates/writers/json_writer.py b/grit/format/policy_templates/writers/json_writer.py
index f5af8c1..4dfd282 100644
--- a/grit/format/policy_templates/writers/json_writer.py
+++ b/grit/format/policy_templates/writers/json_writer.py
@@ -39,6 +39,9 @@ class JsonWriter(template_writer.TemplateWriter):
def PreprocessPolicies(self, policy_list):
return self.FlattenGroupsAndSortPolicies(policy_list)
+ def WriteComment(self, comment):
+ self._out.append('// ' + comment)
+
def WritePolicy(self, policy):
if policy['type'] == 'external':
# This type can only be set through cloud policy.
@@ -69,6 +72,9 @@ class JsonWriter(template_writer.TemplateWriter):
self._first_written = False
def BeginTemplate(self):
+ if self._GetChromiumVersionString() is not None:
+ self.WriteComment(self.config['build'] + ''' version: ''' + \
+ self._GetChromiumVersionString())
self._out.append(TEMPLATE_HEADER)
def EndTemplate(self):
diff --git a/grit/format/policy_templates/writers/json_writer_unittest.py b/grit/format/policy_templates/writers/json_writer_unittest.py
index b2ed1ef..8f3c745 100644
--- a/grit/format/policy_templates/writers/json_writer_unittest.py
+++ b/grit/format/policy_templates/writers/json_writer_unittest.py
@@ -24,6 +24,15 @@ TEMPLATE_HEADER="""\
{
"""
+TEMPLATE_HEADER_WITH_VERSION="""\
+// chromium version: 39.0.0.0
+// Policy template for Linux.
+// Uncomment the policies you wish to activate and change their values to
+// something useful for your case. The provided values are for reference only
+// and do not provide meaningful defaults!
+{
+"""
+
HEADER_DELIMETER="""\
//-------------------------------------------------------------------------
@@ -55,10 +64,23 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
' "placeholders": [],'
' "messages": {},'
'}')
- output = self.GetOutput(grd, 'fr', {'_chromium': '1',}, 'json', 'en')
+ output = self.GetOutput(grd, 'fr', {'_chromium': '1'}, 'json', 'en')
expected_output = TEMPLATE_HEADER + '}'
self.CompareOutputs(output, expected_output)
+ def testEmptyWithVersion(self):
+ # Test the handling of an empty policy list.
+ grd = self.PrepareTest(
+ '{'
+ ' "policy_definitions": [],'
+ ' "placeholders": [],'
+ ' "messages": {},'
+ '}')
+ output = self.GetOutput(
+ grd, 'fr', {'_chromium': '1', 'version':'39.0.0.0'}, 'json', 'en')
+ expected_output = TEMPLATE_HEADER_WITH_VERSION + '}'
+ self.CompareOutputs(output, expected_output)
+
def testMainPolicy(self):
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest(
diff --git a/grit/format/policy_templates/writers/plist_strings_writer.py b/grit/format/policy_templates/writers/plist_strings_writer.py
index 966aaf2..4257bf8 100644
--- a/grit/format/policy_templates/writers/plist_strings_writer.py
+++ b/grit/format/policy_templates/writers/plist_strings_writer.py
@@ -22,6 +22,9 @@ class PListStringsWriter(template_writer.TemplateWriter):
[lang].lproj subdirectories of the manifest bundle.
'''
+ def WriteComment(self, comment):
+ self._out.append('/* ' + comment + ' */' )
+
def _AddToStringTable(self, item_name, caption, desc):
'''Add a title and a description of an item to the string table.
@@ -63,6 +66,9 @@ class PListStringsWriter(template_writer.TemplateWriter):
def BeginTemplate(self):
app_name = plist_helper.GetPlistFriendlyName(self.config['app_name'])
+ if self._GetChromiumVersionString() is not None:
+ self.WriteComment(self.config['build'] + ''' version: ''' + \
+ self._GetChromiumVersionString())
self._AddToStringTable(
app_name,
self.config['app_name'],
diff --git a/grit/format/policy_templates/writers/plist_strings_writer_unittest.py b/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
index 17fc85c..efad6f2 100644
--- a/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
+++ b/grit/format/policy_templates/writers/plist_strings_writer_unittest.py
@@ -43,6 +43,33 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'Chromium.pfm_description = "Chromium preferen\\"ces";')
self.assertEquals(output.strip(), expected_output.strip())
+ def testEmptyVersion(self):
+ # Test PListStringsWriter in case of empty polices.
+ grd = self.PrepareTest('''
+ {
+ 'policy_definitions': [],
+ 'placeholders': [],
+ 'messages': {
+ 'mac_chrome_preferences': {
+ 'text': '$1 preferen"ces',
+ 'desc': 'blah'
+ }
+ }
+ }''')
+ output = self.GetOutput(
+ grd,
+ 'fr',
+ {'_chromium': '1',
+ 'mac_bundle_id': 'com.example.Test',
+ 'version': '39.0.0.0'},
+ 'plist_strings',
+ 'en')
+ expected_output = (
+ '/* chromium version: 39.0.0.0 */\n'
+ 'Chromium.pfm_title = "Chromium";\n'
+ 'Chromium.pfm_description = "Chromium preferen\\"ces";')
+ self.assertEquals(output.strip(), expected_output.strip())
+
def testMainPolicy(self):
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest('''
diff --git a/grit/format/policy_templates/writers/plist_writer.py b/grit/format/policy_templates/writers/plist_writer.py
index 6d929d6..cae6844 100644
--- a/grit/format/policy_templates/writers/plist_writer.py
+++ b/grit/format/policy_templates/writers/plist_writer.py
@@ -120,7 +120,9 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter):
def BeginTemplate(self):
self._plist.attributes['version'] = '1'
dict = self.AddElement(self._plist, 'dict')
-
+ if self._GetChromiumVersionString() is not None:
+ self.AddComment(self._plist, self.config['build'] + ' version: ' + \
+ self._GetChromiumVersionString())
app_name = plist_helper.GetPlistFriendlyName(self.config['app_name'])
self._AddStringKeyValuePair(dict, 'pfm_name', app_name)
self._AddStringKeyValuePair(dict, 'pfm_description', '')
diff --git a/grit/format/policy_templates/writers/plist_writer_unittest.py b/grit/format/policy_templates/writers/plist_writer_unittest.py
index ddbdbfe..6186c15 100644
--- a/grit/format/policy_templates/writers/plist_writer_unittest.py
+++ b/grit/format/policy_templates/writers/plist_writer_unittest.py
@@ -52,6 +52,41 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
</dict>
</plist>''' % (product_name, bundle_id, policies)
+ def _GetExpectedOutputsWithVersion(self, product_name, bundle_id, policies,
+ version):
+ '''Substitutes the variable parts into a plist template. The result
+ of this function can be used as an expected result to test the output
+ of PListWriter.
+
+ Args:
+ product_name: The name of the product, normally Chromium or Google Chrome.
+ bundle_id: The mac bundle id of the product.
+ policies: The list of policies.
+
+ Returns:
+ The text of a plist template with the variable parts substituted.
+ '''
+ return '''
+<?xml version="1.0" ?>
+<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
+<plist version="1">
+ <dict>
+ <key>pfm_name</key>
+ <string>%s</string>
+ <key>pfm_description</key>
+ <string/>
+ <key>pfm_title</key>
+ <string/>
+ <key>pfm_version</key>
+ <string>1</string>
+ <key>pfm_domain</key>
+ <string>%s</string>
+ <key>pfm_subkeys</key>
+ %s
+ </dict>
+ <!--%s-->
+</plist>''' % (product_name, bundle_id, policies, version)
+
def testEmpty(self):
# Test PListWriter in case of empty polices.
grd = self.PrepareTest('''
@@ -71,6 +106,30 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'Chromium', 'com.example.Test', '<array/>')
self.assertEquals(output.strip(), expected_output.strip())
+ def testEmptyVersion(self):
+ # Test PListWriter in case of empty polices.
+ grd = self.PrepareTest('''
+ {
+ 'policy_definitions': [],
+ 'placeholders': [],
+ 'messages': {},
+ }''')
+
+ output = self.GetOutput(
+ grd,
+ 'fr',
+ {'_chromium': '1',
+ 'mac_bundle_id': 'com.example.Test',
+ 'version': '39.0.0.0'},
+ 'plist',
+ 'en')
+ expected_output = self._GetExpectedOutputsWithVersion(
+ 'Chromium',
+ 'com.example.Test',
+ '<array/>',
+ 'chromium version: 39.0.0.0')
+ self.assertEquals(output.strip(), expected_output.strip())
+
def testMainPolicy(self):
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest('''
diff --git a/grit/format/policy_templates/writers/reg_writer.py b/grit/format/policy_templates/writers/reg_writer.py
index ad83046..70c87a3 100644
--- a/grit/format/policy_templates/writers/reg_writer.py
+++ b/grit/format/policy_templates/writers/reg_writer.py
@@ -82,6 +82,9 @@ class RegWriter(template_writer.TemplateWriter):
list.append('"%s"=%s' % (policy['name'], example_value_str))
+ def WriteComment(self, comment):
+ self._prefix.append('; ' + comment)
+
def WritePolicy(self, policy):
if self.CanBeMandatory(policy):
self._WritePolicy(policy,
@@ -103,8 +106,12 @@ class RegWriter(template_writer.TemplateWriter):
self._mandatory = []
self._recommended = []
self._last_key = {}
+ self._prefix = []
def GetTemplateText(self):
- prefix = ['Windows Registry Editor Version 5.00']
- all = prefix + self._mandatory + self._recommended
+ self._prefix.append('Windows Registry Editor Version 5.00')
+ if self._GetChromiumVersionString() is not None:
+ self.WriteComment(self.config['build'] + ' version: ' + \
+ self._GetChromiumVersionString())
+ all = self._prefix + self._mandatory + self._recommended
return self.NEWLINE.join(all)
diff --git a/grit/format/policy_templates/writers/reg_writer_unittest.py b/grit/format/policy_templates/writers/reg_writer_unittest.py
index 88fb2e2..2851a8b 100644
--- a/grit/format/policy_templates/writers/reg_writer_unittest.py
+++ b/grit/format/policy_templates/writers/reg_writer_unittest.py
@@ -48,6 +48,20 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
expected_output = 'Windows Registry Editor Version 5.00'
self.CompareOutputs(output, expected_output)
+ def testEmptyVersion(self):
+ # Test the handling of an empty policy list.
+ grd = self.PrepareTest(
+ '{'
+ ' "policy_definitions": [],'
+ ' "placeholders": [],'
+ ' "messages": {}'
+ '}')
+ output = self.GetOutput(
+ grd, 'fr', {'_chromium': '1', 'version': '39.0.0.0' }, 'reg', 'en')
+ expected_output = ('Windows Registry Editor Version 5.00\r\n'
+ '; chromium version: 39.0.0.0\r\n')
+ self.CompareOutputs(output, expected_output)
+
def testMainPolicy(self):
# Tests a policy group with a single policy of type 'main'.
grd = self.PrepareTest(
diff --git a/grit/format/policy_templates/writers/template_writer.py b/grit/format/policy_templates/writers/template_writer.py
index bd48425..d489d64 100644
--- a/grit/format/policy_templates/writers/template_writer.py
+++ b/grit/format/policy_templates/writers/template_writer.py
@@ -102,6 +102,15 @@ class TemplateWriter(object):
is_supported = lambda x: platform in x['platforms']
return any(filter(is_supported, policy['supported_on']))
+ def _GetChromiumVersionString(self):
+ '''Returns the Chromium version string stored in the environment variable
+ version (if it is set).
+
+ Returns: The Chromium version string or None if it has not been set.'''
+
+ if 'version' in self.config:
+ return self.config['version']
+
def _GetPoliciesForWriter(self, group):
'''Filters the list of policies in the passed group that are supported by
the writer.
@@ -191,6 +200,13 @@ class TemplateWriter(object):
'''
raise NotImplementedError()
+ def WriteComment(self, comment):
+ '''Appends the comment to the internal buffer.
+
+ comment: The comment to be added.
+ '''
+ raise NotImplementedError()
+
def WriteRecommendedPolicy(self, policy):
'''Appends the template text corresponding to a recommended policy into the
internal buffer.