summaryrefslogtreecommitdiffstats
path: root/tools/grit
diff options
context:
space:
mode:
authorgfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-17 12:31:38 +0000
committergfeher@chromium.org <gfeher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-17 12:31:38 +0000
commit2aaf240cf9afb6522213e15e3199f76cefcb1065 (patch)
tree437d5a507af693b234899d0b0d7b9ddd62cba17c /tools/grit
parentb58c46b866a3b99a2436911fe026d1baae37f371 (diff)
downloadchromium_src-2aaf240cf9afb6522213e15e3199f76cefcb1065.zip
chromium_src-2aaf240cf9afb6522213e15e3199f76cefcb1065.tar.gz
chromium_src-2aaf240cf9afb6522213e15e3199f76cefcb1065.tar.bz2
Fix string-enums in ADMX templates
BUG=86141 TEST=verify that the value of ProxyMode set via the ADMX template is correctly reflected in about:net-internals Review URL: http://codereview.chromium.org/7155025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/grit')
-rw-r--r--tools/grit/grit/format/policy_templates/writers/admx_writer.py9
-rw-r--r--tools/grit/grit/format/policy_templates/writers/admx_writer_unittest.py54
-rw-r--r--tools/grit/grit/format/policy_templates/writers/plist_writer.py27
-rw-r--r--tools/grit/grit/format/policy_templates/writers/xml_formatted_writer.py36
-rw-r--r--tools/grit/grit/format/policy_templates/writers/xml_writer_base_unittest.py4
5 files changed, 73 insertions, 57 deletions
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 06863d8..da4aa64 100644
--- a/tools/grit/grit/format/policy_templates/writers/admx_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/admx_writer.py
@@ -183,12 +183,11 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
attributes = {'displayName': self._AdmlString(item['name'])}
item_elem = self.AddElement(enum_elem, 'item', attributes)
value_elem = self.AddElement(item_elem, 'value')
- attributes = {'value': str(item['value'])}
+ value_string = str(item['value'])
if policy['type'] == 'int-enum':
- element_type = 'decimal'
+ self.AddElement(value_elem, 'decimal', {'value': value_string})
else:
- element_type = 'string'
- self.AddElement(value_elem, element_type, attributes)
+ self.AddElement(value_elem, 'string', {}, value_string)
def _AddListPolicy(self, parent, name):
'''Generates ADMX XML elements for a List-Policy and adds them to the
@@ -325,4 +324,4 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter):
self._active_policy_group_name = self.config['win_category_path'][-1]
def GetTemplateText(self):
- return self._doc.toprettyxml(indent=' ')
+ return self.ToPrettyXml(self._doc)
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 1e82bae..0a7f226 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
@@ -267,31 +267,39 @@ class AdmxWriterTest(xml_writer_base_unittest.XmlWriterBaseTest):
]
}
- self._initWriterForPolicy(self.writer, enum_policy)
+ # This test is different than the others because it also tests that space
+ # usage inside <string> nodes is correct.
+ dom_impl = minidom.getDOMImplementation('')
+ self.writer._doc = dom_impl.createDocument(None, 'policyDefinitions', None)
+ self.writer._active_policies_elem = self.writer._doc.documentElement
+ self.writer._active_policy_group_name = 'PolicyGroup'
self.writer.WritePolicy(enum_policy)
- output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc))
+ output = self.writer.GetTemplateText()
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>')
+ '<?xml version="1.0" ?>\n'
+ '<policyDefinitions>\n'
+ ' <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>one</string>\n'
+ ' </value>\n'
+ ' </item>\n'
+ ' <item displayName="$(string.item_2)">\n'
+ ' <value>\n'
+ ' <string>two</string>\n'
+ ' </value>\n'
+ ' </item>\n'
+ ' </enum>\n'
+ ' </elements>\n'
+ ' </policy>\n'
+ '</policyDefinitions>')
self.AssertXMLEquals(output, expected_output)
def testListPolicy(self):
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 1dc4da0..46ff0a4 100644
--- a/tools/grit/grit/format/policy_templates/writers/plist_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/plist_writer.py
@@ -123,29 +123,4 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter):
self._plist = self._doc.documentElement
def GetTemplateText(self):
- # return self.plist_doc.toprettyxml(indent=' ')
- # The above pretty-printer does not print the doctype and adds spaces
- # around texts, which the OSX Workgroup Manager does not like. So we use
- # the poor man's pretty printer. It assumes that there are no mixed-content
- # nodes.
- # Get all the XML content in a one-line string.
- xml = self._doc.toxml()
- # Determine where the line breaks will be. (They will only be between tags.)
- lines = xml[1:len(xml) - 1].split('><')
- indent = ''
- res = ''
- # Determine indent for each line.
- for i in range(len(lines)):
- line = lines[i]
- if line[0] == '/':
- # If the current line starts with a closing tag, decrease indent before
- # printing.
- indent = indent[2:]
- lines[i] = indent + '<' + line + '>'
- if (line[0] not in ['/', '?', '!'] and '</' not in line and
- line[len(line) - 1] != '/'):
- # If the current line starts with an opening tag and does not conatin a
- # closing tag, increase indent after the line is printed.
- indent += ' '
- # Reconstruct XML text from the lines.
- return '\n'.join(lines)
+ return self.ToPrettyXml(self._doc)
diff --git a/tools/grit/grit/format/policy_templates/writers/xml_formatted_writer.py b/tools/grit/grit/format/policy_templates/writers/xml_formatted_writer.py
index ad415d4..8323c2e 100644
--- a/tools/grit/grit/format/policy_templates/writers/xml_formatted_writer.py
+++ b/tools/grit/grit/format/policy_templates/writers/xml_formatted_writer.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -52,3 +52,37 @@ class XMLFormattedWriter(template_writer.TemplateWriter):
attribute = doc.createAttribute(name)
attribute.value = value
parent.setAttributeNode(attribute)
+
+ def ToPrettyXml(self, doc):
+ # return doc.toprettyxml(indent=' ')
+ # The above pretty-printer does not print the doctype and adds spaces
+ # around texts, e.g.:
+ # <string>
+ # value of the string
+ # </string>
+ # This is problematic both for the OSX Workgroup Manager (plist files) and
+ # the Windows Group Policy Editor (admx files). What they need instead:
+ # <string>value of string</string>
+ # So we use the poor man's pretty printer here. It assumes that there are
+ # no mixed-content nodes.
+ # Get all the XML content in a one-line string.
+ xml = doc.toxml()
+ # Determine where the line breaks will be. (They will only be between tags.)
+ lines = xml[1:len(xml) - 1].split('><')
+ indent = ''
+ res = ''
+ # Determine indent for each line.
+ for i in range(len(lines)):
+ line = lines[i]
+ if line[0] == '/':
+ # If the current line starts with a closing tag, decrease indent before
+ # printing.
+ indent = indent[2:]
+ lines[i] = indent + '<' + line + '>'
+ if (line[0] not in ['/', '?', '!'] and '</' not in line and
+ line[len(line) - 1] != '/'):
+ # If the current line starts with an opening tag and does not conatin a
+ # closing tag, increase indent after the line is printed.
+ indent += ' '
+ # Reconstruct XML text from the lines.
+ return '\n'.join(lines)
diff --git a/tools/grit/grit/format/policy_templates/writers/xml_writer_base_unittest.py b/tools/grit/grit/format/policy_templates/writers/xml_writer_base_unittest.py
index 125856e..91ff6ed 100644
--- a/tools/grit/grit/format/policy_templates/writers/xml_writer_base_unittest.py
+++ b/tools/grit/grit/format/policy_templates/writers/xml_writer_base_unittest.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
-# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -27,7 +27,7 @@ class XmlWriterBaseTest(unittest.TestCase):
Return: XML of the chrildren of the parent node.
'''
return ''.join(
- child.toprettyxml(indent = ' ') for child in parent.childNodes)
+ child.toprettyxml(indent=' ') for child in parent.childNodes)
def AssertXMLEquals(self, output, expected_output):
'''Asserts if the passed XML arguements are equal.