Commit 5d3ecdf9 authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

Add auto generated documentation about atomic policy groups

Bug: 962669
Change-Id: Ie6333108a9bbe06c16eeb3895b17df855b705f4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1612103Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarLutz Justen <ljusten@chromium.org>
Commit-Queue: Yann Dago <ydago@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668579}
parent bca679cd
......@@ -12,6 +12,10 @@ import("//tools/grit/grit_rule.gni")
assert(!is_ios, "Policy should not be referenced on iOS")
# To generate policy documentation for local use, set this to true for the
# links between pages and subpages to work.
gen_policy_templates_local = false
# To test policy generation for platforms different than your OS, override and
# enable these flags (but don't check that in!).
gen_policy_templates_common = true
......@@ -192,11 +196,16 @@ action("policy_templates") {
chrome_version_path,
] + grit_defines
if (gen_policy_templates_local) {
args += [ "--local" ]
}
if (gen_policy_templates_common) {
outputs += policy_templates_common_outputs
args += [
"--doc",
rebase_path(policy_templates_doc_path, root_build_dir),
"--doc_atomic_groups",
rebase_path(policy_templates_doc_atomic_groups_path, root_build_dir),
]
}
if (gen_policy_templates_android) {
......@@ -453,6 +462,8 @@ if (gen_policy_templates_zip) {
"--add",
rebase_path(policy_templates_doc_path, root_build_dir),
"--add",
rebase_path(policy_templates_doc_atomic_groups_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_reg_path, root_build_dir),
"--add",
rebase_path(policy_templates_win_adm_path, root_build_dir),
......
......@@ -152,6 +152,9 @@ policy_templates_android_outputs = [ policy_templates_android_policy_path ]
# Common outputs.
policy_templates_doc_path =
"$policy_templates_base_dir/common/html/\${lang}/chrome_policy_list.html"
policy_templates_doc_atomic_groups_path =
"$policy_templates_base_dir/common/" +
"html/\${lang}/chrome_policy_atomic_groups_list.html"
policy_templates_common_outputs = []
foreach(lang, policy_templates_languages) {
policy_templates_common_outputs += [
......
......@@ -7,6 +7,10 @@ import copy
import re
def IsGroupOrAtomicGroup(policy):
return policy['type'] == 'group' or policy['type'] == 'atomic_group'
class PolicyTemplateGenerator:
'''Generates template text for a particular platform.
......@@ -60,6 +64,14 @@ class PolicyTemplateGenerator:
for key in self._messages.keys():
self._messages[key]['text'] = self._ImportMessage(
self._messages[key]['text'])
self._AddAtomicGroups(self._policy_data['policy_definitions'],
self._policy_data['policy_atomic_group_definitions'])
self._policy_data[
'policy_atomic_group_definitions'] = self._ExpandAtomicGroups(
self._policy_data['policy_definitions'],
self._policy_data['policy_atomic_group_definitions'])
self._ProcessPolicyList(
self._policy_data['policy_atomic_group_definitions'])
self._policy_data['policy_definitions'] = self._ExpandGroups(
self._policy_data['policy_definitions'])
self._policy_definitions = self._policy_data['policy_definitions']
......@@ -125,20 +137,21 @@ class PolicyTemplateGenerator:
policy: The data structure of the policy or group, that will get message
strings here.
'''
policy['desc'] = self._ImportMessage(policy['desc'])
if policy['type'] != 'atomic_group':
policy['desc'] = self._ImportMessage(policy['desc'])
policy['caption'] = self._ImportMessage(policy['caption'])
if 'label' in policy:
policy['label'] = self._ImportMessage(policy['label'])
if 'arc_support' in policy:
policy['arc_support'] = self._ImportMessage(policy['arc_support'])
if policy['type'] == 'group':
if IsGroupOrAtomicGroup(policy):
self._ProcessPolicyList(policy['policies'])
elif policy['type'] in ('string-enum', 'int-enum', 'string-enum-list'):
# Iterate through all the items of an enum-type policy, and add captions.
for item in policy['items']:
item['caption'] = self._ImportMessage(item['caption'])
if policy['type'] != 'group':
if not IsGroupOrAtomicGroup(policy):
if not 'label' in policy:
# If 'label' is not specified, then it defaults to 'caption':
policy['label'] = policy['caption']
......@@ -171,6 +184,43 @@ class PolicyTemplateGenerator:
policy_data_copy = copy.deepcopy(self._policy_data)
return template_writer.WriteTemplate(policy_data_copy)
def _AddAtomicGroups(self, policy_list, policy_atomic_groups):
'''Adds an 'atomic_group' field to the policies that are part of an atomic
group.
Args:
policy_list: A list of policies and groups.
policy_atomic_groups: A list of policy atomic groups
'''
policy_lookup = {
policy['name']: policy
for policy in policy_list
if not IsGroupOrAtomicGroup(policy)
}
for group in policy_atomic_groups:
for policy_name in group['policies']:
policy_lookup[policy_name]['atomic_group'] = group['name']
break
def _ExpandAtomicGroups(self, policy_list, policy_atomic_groups):
'''Replaces policies names inside atomic group definitions for actual
policies definitions.
Args:
policy_list: A list of policies and groups.
Returns:
Modified policy_list
'''
policies = [
policy for policy in policy_list if not IsGroupOrAtomicGroup(policy)
]
for group in policy_atomic_groups:
group['type'] = 'atomic_group'
expanded = self._ExpandGroups(policies + policy_atomic_groups)
expanded = [policy for policy in expanded if IsGroupOrAtomicGroup(policy)]
return copy.deepcopy(expanded)
def _ExpandGroups(self, policy_list):
'''Replaces policies names inside group definitions for actual policies
definitions. If policy does not belong to any group, leave it as is.
......@@ -181,11 +231,11 @@ class PolicyTemplateGenerator:
Returns:
Modified policy_list
'''
groups = [policy for policy in policy_list if policy['type'] == 'group']
groups = [policy for policy in policy_list if IsGroupOrAtomicGroup(policy)]
policies = {
policy['name']: policy
for policy in policy_list
if policy['type'] != 'group'
if not IsGroupOrAtomicGroup(policy)
}
policies_in_groups = set()
result_policies = []
......@@ -200,7 +250,7 @@ class PolicyTemplateGenerator:
result_policies.append(group)
result_policies.extend([
policy for policy in policy_list if policy['type'] != 'group' and
policy for policy in policy_list if not IsGroupOrAtomicGroup(policy) and
policy['name'] not in policies_in_groups
])
return result_policies
......@@ -28,6 +28,7 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase):
'messages': {},
'placeholders': [],
'policy_definitions': [],
'policy_atomic_group_definitions': [],
}
def do_test(self, policy_data, writer):
......
......@@ -20,7 +20,8 @@ from writers import adm_writer, adml_writer, admx_writer, \
chromeos_admx_writer, chromeos_adml_writer, \
google_admx_writer, google_adml_writer, \
android_policy_writer, reg_writer, doc_writer, \
json_writer, plist_writer, plist_strings_writer
doc_atomic_groups_writer , json_writer, plist_writer, \
plist_strings_writer
def MacLanguageMap(lang):
......@@ -59,6 +60,7 @@ _WRITER_DESCS = [
WriterDesc('android_policy', False, 'utf-8', None, False),
WriterDesc('reg', False, 'utf-16', None, False),
WriterDesc('doc', True, 'utf-8', None, False),
WriterDesc('doc_atomic_groups', True, 'utf-8', None, False),
WriterDesc('json', False, 'utf-8', None, False),
WriterDesc('plist', False, 'utf-8', None, False),
WriterDesc('plist_strings', True, 'utf-8', MacLanguageMap, False)
......@@ -148,6 +150,13 @@ def main(argv):
parser.add_option('--google_admx', action='append', dest='google_admx')
parser.add_option('--reg', action='append', dest='reg')
parser.add_option('--doc', action='append', dest='doc')
parser.add_option(
'--doc_atomic_groups', action='append', dest='--doc_atomic_groups')
parser.add_option(
'--local',
action='store_true',
help='If set, the documentation will be built so \
that links work locally in the generated path.')
parser.add_option('--json', action='append', dest='json')
parser.add_option('--plist', action='append', dest='plist')
parser.add_option('--plist_strings', action='append', dest='plist_strings')
......@@ -165,6 +174,7 @@ def main(argv):
config = _GetWriterConfiguration(options.grit_defines)
config['major_version'] = _ParseVersionFile(options.version_path)
config['local'] = options.local
# For each language, load policy data once and run all writers on it.
for lang in languages:
......
......@@ -71,6 +71,7 @@ class AdmWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -101,6 +102,7 @@ chromium_recommended="Chromium - Recommended"''')
policy_json = '''
{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -142,6 +144,7 @@ chromium_recommended="Chromium - Recommended"''')
'desc': 'Description of main.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -210,6 +213,7 @@ Reference: https://www.chromium.org/administrators/policy-list-3#MainPolicy"''')
'desc': 'Description of main.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -266,6 +270,7 @@ With a newline.""",
'caption': 'Caption of policy.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -332,6 +337,7 @@ StringPolicy_Part="Caption of policy."
'supported_on': ['chrome.win:8-']
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -400,6 +406,7 @@ IntPolicy_Part="Caption of policy."
},
],
'placeholders': [],
'policy_atomic_group_definitions': [],
'messages': %s
}''' % MESSAGES
output = self.GetOutput(policy_json, {'_chromium': '1'}, 'adm')
......@@ -477,6 +484,7 @@ IntPolicy_Part="Caption of policy."
'features': { 'can_be_recommended': True },
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -562,6 +570,7 @@ ProxyServerAutoDetect_DropDown="Option2"
'features': { 'can_be_recommended': True },
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -643,6 +652,7 @@ With a newline.""",
'label': 'Label of list policy.'
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s,
}''' % MESSAGES
......@@ -717,6 +727,7 @@ With a newline.""",
'label': 'Label of list policy.'
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -783,6 +794,7 @@ ListPolicy_Part="Label of list policy."
'caption': 'Caption of policy.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -850,6 +862,7 @@ DictionaryPolicy_Part="Caption of policy."
'caption': 'Caption of policy.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -923,6 +936,7 @@ ExternalPolicy_Part="Caption of policy."
'desc': 'Desc of list policy.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -960,6 +974,7 @@ chromium_recommended="Chromium - Recommended"
'desc': 'Description of main.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -1031,6 +1046,7 @@ With a newline."""
With a newline."""
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -1133,6 +1149,7 @@ Policy2_Part="Caption of policy2."
'supported_on': ['chrome.win:39-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......@@ -1215,6 +1232,7 @@ EnumPolicy_B_Part="Caption of policy B."
'desc': """Description of policy1."""
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': %s
}''' % MESSAGES
......
#!/usr/bin/env python
# Copyright 2019 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.
from writers import doc_writer
def GetWriter(config):
'''Factory method for creating DocAtomicGroupsWriter objects.
See the constructor of TemplateWriter for description of
arguments.
'''
return DocAtomicGroupsWriter(['*'], config)
class DocAtomicGroupsWriter(doc_writer.DocWriter):
'''Class for generating atomic policy group templates in HTML format.
The intended use of the generated file is to upload it on
https://www.chromium.org, therefore its format has some limitations:
- No HTML and body tags.
- Restricted set of element attributes: for example no 'class'.
Because of the latter the output is styled using the 'style'
attributes of HTML elements. This is supported by the dictionary
self._STYLES[] and the method self._AddStyledElement(), they try
to mimic the functionality of CSS classes. (But without inheritance.)
This class is invoked by PolicyTemplateGenerator to create the HTML
files.
'''
def _AddPolicyRow(self, parent, policy):
'''Adds a row for the policy in the summary table.
Args:
parent: The DOM node of the summary table.
policy: The data structure of the policy.
'''
tr = self._AddStyledElement(parent, 'tr', ['tr'])
indent = 'padding-left: %dpx;' % (7 + self._indent_level * 14)
if policy['type'] != 'group':
# Normal policies get two columns with name and caption.
name_td = self._AddStyledElement(tr, 'td', ['td', 'td.left'],
{'style': indent})
policy_ref = './'
if self.config.get('local', False):
policy_ref = './chrome_policy_list.html'
self.AddElement(name_td, 'a', {'href': policy_ref + '#' + policy['name']},
policy['name'])
self._AddStyledElement(tr, 'td', ['td', 'td.right'], {},
policy['caption'])
else:
# Groups get one column with caption.
name_td = self._AddStyledElement(tr, 'td', ['td', 'td.left'], {
'style': indent,
'colspan': '2'
})
self.AddElement(name_td, 'a', {'name': policy['name']}, policy['caption'])
#
# Implementation of abstract methods of TemplateWriter:
#
def WritePolicy(self, policy):
self._AddPolicyRow(self._summary_tbody, policy)
def BeginTemplate(self):
self._BeginTemplate('group_intro')
def WriteTemplate(self, template):
'''Writes the given template definition.
Args:
template: Template definition to write.
Returns:
Generated output for the passed template definition.
'''
self.messages = template['messages']
self.Init()
policies = self.PreprocessPolicies(
template['policy_atomic_group_definitions'])
self.BeginTemplate()
for policy in policies:
if policy['type'] != 'atomic_group':
continue
self.BeginPolicyGroup(policy)
for child_policy in policy['policies']:
# Nesting of groups is currently not supported.
self.WritePolicy(child_policy)
self.EndPolicyGroup()
self.EndTemplate()
return self.GetTemplateText()
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Copyright 2019 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.
......@@ -613,6 +613,15 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
# Don't add an example for Google cloud managed ChromeOS policies.
dd = self._AddPolicyAttribute(dl, 'example_value')
self._AddExample(dd, policy)
if 'atomic_group' in policy:
dd = self._AddPolicyAttribute(dl, 'policy_atomic_group')
policy_group_ref = './policy-list-3/atomic_groups'
if 'local' in self.config and self.config['local']:
policy_group_ref = './chrome_policy_atomic_groups_list.html'
self.AddText(dd, self.GetLocalizedMessage('policy_in_atomic_group') + ' ')
self.AddElement(dd, 'a',
{'href': policy_group_ref + '#' + policy['atomic_group']},
policy['atomic_group'])
def _AddPolicyNote(self, parent, policy):
'''If a policy has an additional web page assigned with it, then add
......@@ -696,25 +705,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
return schema['minimum'] != 0
return False
#
# 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)
def BeginPolicyGroup(self, group):
self.WritePolicy(group)
self._indent_level += 1
def EndPolicyGroup(self):
self._indent_level -= 1
def BeginTemplate(self):
def _BeginTemplate(self, intro_message_id):
# Add a <div> for the summary section.
if self._GetChromiumVersionString() is not None:
self.AddComment(self._main_div, self.config['build'] + \
......@@ -723,7 +714,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
summary_div = self.AddElement(self._main_div, 'div')
self.AddElement(summary_div, 'a', {'name': 'top'})
self.AddElement(summary_div, 'br')
self._AddParagraphs(summary_div, self.GetLocalizedMessage('intro'))
self._AddParagraphs(summary_div, self.GetLocalizedMessage(intro_message_id))
self.AddElement(summary_div, 'br')
self.AddElement(summary_div, 'br')
self.AddElement(summary_div, 'br')
......@@ -741,6 +732,27 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter):
# Add a <div> for the detailed policy listing.
self._details_div = self.AddElement(self._main_div, 'div')
#
# 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)
def BeginPolicyGroup(self, group):
self.WritePolicy(group)
self._indent_level += 1
def EndPolicyGroup(self):
self._indent_level -= 1
def BeginTemplate(self):
self._BeginTemplate('intro')
def Init(self):
dom_impl = minidom.getDOMImplementation('')
self._doc = dom_impl.createDocument(None, 'html', None)
......
......@@ -135,6 +135,12 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'doc_bla': {
'text': '_test_bla'
},
'doc_policy_atomic_group': {
'text': '_test_policy_atomic_group'
},
'doc_policy_in_atomic_group': {
'text': '_test_policy_in_atomic_group'
}
}
self.writer.Init()
......@@ -1036,6 +1042,65 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
'</div>'
'</root>')
def testAddPolicySectionWithAtomicGroup(self):
# Test if policy details are correctly added to the document.
policy = {
'name':
'PolicyName',
'caption':
'PolicyCaption',
'desc':
'PolicyDesc',
'type':
'string',
'supported_on': [{
'product': 'chrome',
'platforms': ['win', 'mac', 'chrome_os'],
'since_version': '7',
'until_version': '',
}],
'features': {
'dynamic_refresh': False
},
'example_value':
'False',
'atomic_group':
'PolicyGroup'
}
self.writer._AddPolicySection(self.doc_root, policy)
self.assertEquals(
self.doc_root.toxml(), '<root>'
'<div style="margin-left: 0px">'
'<h3><a name="PolicyName"/>PolicyName</h3>'
'<span>PolicyCaption</span>'
'<dl>'
'<dt style="style_dt;">_test_data_type</dt>'
'<dd>String [Windows:REG_SZ]</dd>'
'<dt style="style_dt;">_test_win_reg_loc</dt>'
'<dd style="style_.monospace;">MockKey\\PolicyName</dd>'
'<dt style="style_dt;">_test_chrome_os_reg_loc</dt>'
'<dd style="style_.monospace;">MockKeyCrOS\\PolicyName</dd>'
'<dt style="style_dt;">_test_mac_linux_pref_name</dt>'
'<dd style="style_.monospace;">PolicyName</dd>'
'<dt style="style_dt;">_test_supported_on</dt>'
'<dd>'
'<ul style="style_ul;">'
'<li>Chrome (Windows, Mac, Chrome OS) ..7..</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><p>PolicyDesc</p></dd>'
'<dt style="style_dt;">_test_example_value</dt>'
'<dd>&quot;False&quot;</dd>'
'<dt style="style_dt;">_test_policy_atomic_group</dt>'
'<dd>_test_policy_in_atomic_group <a href="./policy-list-3/atomic_groups#PolicyGroup">PolicyGroup</a></dd>'
'</dl>'
'<a href="#top">_test_back_to_top</a>'
'</div>'
'</root>')
def testAddPolicySectionForWindowsOnly(self):
policy = {
'name':
......
......@@ -62,6 +62,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
"policy_definitions": [],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -74,6 +75,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
"policy_definitions": [],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -98,6 +100,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": True
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -127,6 +130,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": True
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -156,6 +160,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": "hello, world!"
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -181,6 +186,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": 15
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -210,6 +216,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": 1
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -241,6 +248,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": "one"
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -266,6 +274,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ["foo", "bar"]
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -297,6 +306,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ["one", "two"]
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -332,6 +342,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ''' + str(example) + '''
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": %s,
}''' % MESSAGES
......@@ -364,6 +375,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": %s
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": %s,
}''' % (str(example), MESSAGES)
......@@ -392,6 +404,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ["a"]
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -428,6 +441,7 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": "c"
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......
......@@ -22,6 +22,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -43,6 +44,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -82,6 +84,7 @@ class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'desc': 'Description of main policy.',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -124,6 +127,7 @@ With a newline.""",
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -168,6 +172,7 @@ With a newline.""",
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -224,6 +229,7 @@ With a newline.""",
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -276,6 +282,7 @@ With a newline.""",
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -329,6 +336,7 @@ With a newline.""",
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......@@ -371,6 +379,7 @@ With a newline.""",
'supported_on': ['chrome_os:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {
'mac_chrome_preferences': {
......
......@@ -90,6 +90,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -107,6 +108,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -142,6 +144,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {}
}'''
......@@ -191,6 +194,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {}
}'''
......@@ -242,6 +246,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {}
}'''
......@@ -288,6 +293,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'caption': '',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -338,6 +344,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'caption': '',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -400,6 +407,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'caption': '',
}
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -453,6 +461,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -503,6 +512,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -558,6 +568,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'supported_on': ['chrome.mac:8-'],
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -609,6 +620,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'caption': '',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -655,6 +667,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'caption': '',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......@@ -702,6 +715,7 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon):
'desc': '',
},
],
'policy_atomic_group_definitions': [],
'placeholders': [],
'messages': {},
}'''
......
......@@ -36,6 +36,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
"policy_definitions": [],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {}
}'''
......@@ -50,6 +51,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
policy_json = '''
{
"policy_definitions": [],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {}
}'''
......@@ -76,6 +78,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": True
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -107,6 +110,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": True
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -132,6 +136,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": "hello, world! \\\" \\\\"
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -157,6 +162,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": 26
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -186,6 +192,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": 1
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -215,6 +222,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": "two"
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -240,6 +248,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ["foo", "bar"]
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -268,6 +277,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ["foo", "bar"]
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -302,6 +312,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ''' + str(example) + '''
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -333,6 +344,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": %s
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}''' % str(example)
......@@ -360,6 +372,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": ["a"]
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......@@ -397,6 +410,7 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon):
"example_value": "c"
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {},
}'''
......
......@@ -70,6 +70,7 @@ class PolicyTemplatesJsonUnittest(unittest.TestCase):
'desc': '''This policy does stuff.'''
},
],
"policy_atomic_group_definitions": [],
"placeholders": [],
"messages": {
'message_string_id': {
......@@ -173,6 +174,8 @@ class PolicyTemplatesJsonUnittest(unittest.TestCase):
},
},
],
'policy_atomic_group_definitions': [
],
'messages': {
'message_string_id': {
'text': '''%s'''
......
......@@ -269,6 +269,11 @@ class PolicyJson(skeleton_gatherer.SkeletonGatherer):
self._AddNontranslateableChunk(" 'policy_definitions': [\n")
self._AddItems(self.data['policy_definitions'], 'policy', None, 2)
self._AddNontranslateableChunk(" ],\n")
self._AddNontranslateableChunk(" 'policy_atomic_group_definitions': [\n")
if 'policy_atomic_group_definitions' in self.data:
self._AddItems(self.data['policy_atomic_group_definitions'],
'policy', None, 2)
self._AddNontranslateableChunk(" ],\n")
self._AddMessages()
self._AddNontranslateableChunk('\n}')
......
......@@ -25,7 +25,11 @@ class PolicyJsonUnittest(unittest.TestCase):
return expected
def testEmpty(self):
original = "{'policy_definitions': [], 'messages': {}}"
original = """{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'messages': {}
}"""
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
gatherer.Parse()
self.failUnless(len(gatherer.GetCliques()) == 0)
......@@ -46,6 +50,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" 'label': 'nothing special 3',"
" },"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {"
" 'msg_identifier': {"
" 'text': 'nothing special 3',"
......@@ -73,6 +78,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" ]"
" },"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {}"
"}")
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......@@ -102,6 +108,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" 'caption': 'nothing special',"
" },"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {}"
"}")
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......@@ -124,6 +131,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" },"
" },"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {}"
"}")
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......@@ -146,6 +154,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" },"
" },"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {}"
"}")
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......@@ -169,6 +178,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" ]"
" }"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {}"
"}")
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......@@ -190,6 +200,7 @@ class PolicyJsonUnittest(unittest.TestCase):
" 'caption': 'nothing special',"
" }"
" ],"
" 'policy_atomic_group_definitions': [],"
" 'messages': {}"
"}")
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......@@ -201,6 +212,7 @@ class PolicyJsonUnittest(unittest.TestCase):
def testEscapingAndLineBreaks(self):
original = """{
'policy_definitions': [],
'policy_atomic_group_definitions': [],
'messages': {
'msg1': {
# The following line will contain two backslash characters when it
......@@ -250,6 +262,7 @@ with a newline?''',
<ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>.''',
},
],
'policy_atomic_group_definitions': [],
'messages': {}
}"""
gatherer = policy_json.PolicyJson(StringIO.StringIO(original))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment