aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Chromium Automerger <chromium-automerger@android>2014-08-28 19:42:44 +0000
committerAndroid Chromium Automerger <chromium-automerger@android>2014-08-28 19:42:44 +0000
commit41748a0e502220cfbec1f3ee23c453b1478f3023 (patch)
treedf69fa5d6c229b887eec6ad4064eda26250519ea
parentbfb23dc5883711d6b2b8fc128d2156b757b24e68 (diff)
parent77abf65c1d72af6fb7f9ef6f50cdf29fcf42d0a1 (diff)
downloadgrit-41748a0e502220cfbec1f3ee23c453b1478f3023.tar.gz
Merge tools/grit from https://chromium.googlesource.com/external/grit-i18n.git at 77abf65c1d72af6fb7f9ef6f50cdf29fcf42d0a1
This commit was generated by merge_from_chromium.py. Change-Id: I09759be2fe71bf6517ce0dcd608df113d35dfb6f
-rw-r--r--grit/format/policy_templates/writers/doc_writer.py11
-rw-r--r--grit/format/policy_templates/writers/doc_writer_unittest.py61
2 files changed, 66 insertions, 6 deletions
diff --git a/grit/format/policy_templates/writers/doc_writer.py b/grit/format/policy_templates/writers/doc_writer.py
index e8543c2..62c762f 100644
--- a/grit/format/policy_templates/writers/doc_writer.py
+++ b/grit/format/policy_templates/writers/doc_writer.py
@@ -4,6 +4,7 @@
# found in the LICENSE file.
+import json
from xml.dom import minidom
from grit import lazy_re
from grit.format.policy_templates.writers import xml_formatted_writer
@@ -287,8 +288,8 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
self.AddElement(parent, 'dt', {}, 'Windows:')
win = self._AddStyledElement(parent, 'dd', ['.monospace', '.pre'])
key_name = self.config['win_reg_mandatory_key_name']
- example = str(policy['example_value'])
- self.AddText(win, '%s\\%s = "%s"' % (key_name, policy['name'], example))
+ example = json.dumps(policy['example_value'])
+ self.AddText(win, '%s\\%s = %s' % (key_name, policy['name'], example))
def _AddDictionaryExampleLinux(self, parent, policy):
'''Adds an example value for Linux of a 'dict' policy to a DOM node.
@@ -300,7 +301,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
'''
self.AddElement(parent, 'dt', {}, 'Linux:')
linux = self._AddStyledElement(parent, 'dd', ['.monospace'])
- example = str(policy['example_value'])
+ example = json.dumps(policy['example_value'])
self.AddText(linux, '%s: %s' % (policy['name'], example))
def _AddDictionaryExample(self, parent, policy):
@@ -644,13 +645,15 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
'dict': 'Dictionary',
'external': 'External data reference',
}
+ reg_dict = 'REG_SZ; %s' % self._GetLocalizedMessage(
+ 'complex_policies_on_windows')
self._REG_TYPE_MAP = {
'string': 'REG_SZ',
'int': 'REG_DWORD',
'main': 'REG_DWORD',
'int-enum': 'REG_DWORD',
'string-enum': 'REG_SZ',
- 'dict': 'REG_SZ, encoded as a JSON string',
+ 'dict': reg_dict,
}
# The CSS style-sheet used for the document. It will be used in Google
# Sites, which strips class attributes from HTML tags. To work around this,
diff --git a/grit/format/policy_templates/writers/doc_writer_unittest.py b/grit/format/policy_templates/writers/doc_writer_unittest.py
index 05ea240..1508082 100644
--- a/grit/format/policy_templates/writers/doc_writer_unittest.py
+++ b/grit/format/policy_templates/writers/doc_writer_unittest.py
@@ -6,6 +6,7 @@
'''Unit tests for grit.format.policy_templates.writers.doc_writer'''
+import json
import os
import sys
if __name__ == '__main__':
@@ -40,6 +41,7 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon):
})
self.writer.messages = {
'doc_back_to_top': {'text': '_test_back_to_top'},
+ 'doc_complex_policies_on_windows': {'text': '_test_complex_policies_win'},
'doc_data_type': {'text': '_test_data_type'},
'doc_description': {'text': '_test_description'},
'doc_description_column_title': {
@@ -414,6 +416,61 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
'<dd>0x00000000 (Windows), false (Linux), &lt;false /&gt; (Mac)</dd>'
'</dl></root>')
+ def testAddDictPolicyDetails(self):
+ # Test if the definition list (<dl>) of policy details is created correctly
+ # for 'dict' policies.
+ policy = {
+ 'type': 'dict',
+ 'name': 'TestPolicyName',
+ 'caption': 'TestPolicyCaption',
+ 'desc': 'TestPolicyDesc',
+ 'supported_on': [{
+ 'product': 'chrome',
+ 'platforms': ['win', 'mac', 'linux'],
+ 'since_version': '8',
+ 'until_version': '',
+ }],
+ 'features': {'dynamic_refresh': False},
+ 'example_value': { 'foo': 123 }
+ }
+ self.writer.messages['doc_since_version'] = {'text': '...$6...'}
+ self.writer._AddPolicyDetails(self.doc_root, policy)
+ self.assertEquals(
+ self.doc_root.toxml(),
+ '<root><dl>'
+ '<dt style="style_dt;">_test_data_type</dt><dd>Dictionary (REG_SZ; _test_complex_policies_win)</dd>'
+ '<dt style="style_dt;">_test_win_reg_loc</dt>'
+ '<dd style="style_.monospace;">MockKey\TestPolicyName</dd>'
+ '<dt style="style_dt;">_test_mac_linux_pref_name</dt>'
+ '<dd style="style_.monospace;">TestPolicyName</dd>'
+ '<dt style="style_dt;">_test_supported_on</dt>'
+ '<dd>'
+ '<ul style="style_ul;">'
+ '<li>Chrome (Windows, Mac, Linux) ...8...</li>'
+ '</ul>'
+ '</dd>'
+ '<dt style="style_dt;">_test_supported_features</dt>'
+ '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>'
+ '<dt style="style_dt;">_test_description</dt><dd>TestPolicyDesc</dd>'
+ '<dt style="style_dt;">_test_example_value</dt>'
+ '<dd>'
+ '<dl style="style_dd dl;">'
+ '<dt>Windows:</dt>'
+ '<dd style="style_.monospace;style_.pre;">MockKey\TestPolicyName = {&quot;foo&quot;: 123}</dd>'
+ '<dt>Linux:</dt>'
+ '<dd style="style_.monospace;">TestPolicyName: {&quot;foo&quot;: 123}</dd>'
+ '<dt>Mac:</dt>'
+ '<dd style="style_.monospace;style_.pre;">'
+ '&lt;key&gt;TestPolicyName&lt;/key&gt;\n'
+ '&lt;dict&gt;\n'
+ ' &lt;key&gt;foo&lt;/key&gt;\n'
+ ' &lt;integer&gt;123&lt;/integer&gt;\n'
+ '&lt;/dict&gt;'
+ '</dd>'
+ '</dl>'
+ '</dd>'
+ '</dl></root>')
+
def testAddPolicyNote(self):
# TODO(jkummerow): The functionality tested by this test is currently not
# used for anything and will probably soon be removed.
@@ -688,14 +745,14 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
},
}
self.writer._AddDictionaryExample(self.doc_root, policy)
- value = str(policy['example_value'])
+ value = json.dumps(policy['example_value']).replace('"', '&quot;')
self.assertEquals(
self.doc_root.toxml(),
'<root>'
'<dl style="style_dd dl;">'
'<dt>Windows:</dt>'
'<dd style="style_.monospace;style_.pre;">MockKey\PolicyName = '
- '&quot;' + value + '&quot;'
+ + value +
'</dd>'
'<dt>Linux:</dt>'
'<dd style="style_.monospace;">PolicyName: ' + value + '</dd>'