diff options
Diffstat (limited to 'grit/format/policy_templates/writers/doc_writer_unittest.py')
-rw-r--r-- | grit/format/policy_templates/writers/doc_writer_unittest.py | 119 |
1 files changed, 117 insertions, 2 deletions
diff --git a/grit/format/policy_templates/writers/doc_writer_unittest.py b/grit/format/policy_templates/writers/doc_writer_unittest.py index 05ea240..15d8b85 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__': @@ -37,9 +38,11 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'frame_name': 'Chrome Frame', 'os_name': 'Chrome OS', 'win_reg_mandatory_key_name': 'MockKey', + 'win_reg_recommended_key_name': 'MockKeyRec', }) 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': { @@ -48,6 +51,7 @@ class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon): 'doc_example_value': {'text': '_test_example_value'}, 'doc_feature_dynamic_refresh': {'text': '_test_feature_dynamic_refresh'}, 'doc_feature_can_be_recommended': {'text': '_test_feature_recommended'}, + 'doc_feature_can_be_mandatory': {'text': '_test_feature_mandatory'}, 'doc_intro': {'text': '_test_intro'}, 'doc_mac_linux_pref_name': {'text': '_test_mac_linux_pref_name'}, 'doc_note': {'text': '_test_note'}, @@ -414,6 +418,117 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex '<dd>0x00000000 (Windows), false (Linux), <false /> (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 = {"foo": 123}</dd>' + '<dt>Linux:</dt>' + '<dd style="style_.monospace;">TestPolicyName: {"foo": 123}</dd>' + '<dt>Mac:</dt>' + '<dd style="style_.monospace;style_.pre;">' + '<key>TestPolicyName</key>\n' + '<dict>\n' + ' <key>foo</key>\n' + ' <integer>123</integer>\n' + '</dict>' + '</dd>' + '</dl>' + '</dd>' + '</dl></root>') + + def testAddPolicyDetailsRecommendedOnly(self): + policy = { + 'type': 'main', + 'name': 'TestPolicyName', + 'caption': 'TestPolicyCaption', + 'desc': 'TestPolicyDesc', + 'supported_on': [{ + 'product': 'chrome', + 'platforms': ['win', 'mac', 'linux'], + 'since_version': '8', + 'until_version': '', + }, { + 'product': 'chrome', + 'platforms': ['android'], + 'since_version': '30', + 'until_version': '', + }, { + 'product': 'chrome', + 'platforms': ['ios'], + 'since_version': '34', + 'until_version': '', + }], + 'features': { + 'dynamic_refresh': False, + 'can_be_mandatory': False, + 'can_be_recommended': True + }, + 'example_value': False + } + 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>Boolean (REG_DWORD)</dd>' + '<dt style="style_dt;">_test_win_reg_loc</dt>' + '<dd style="style_.monospace;">MockKeyRec\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>' + '<li>Chrome (Android) ...30...</li>' + '<li>Chrome (iOS) ...34...</li>' + '</ul>' + '</dd>' + '<dt style="style_dt;">_test_supported_features</dt>' + '<dd>_test_feature_mandatory: _test_not_supported,' + ' _test_feature_recommended: _test_supported,' + ' _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>0x00000000 (Windows), false (Linux), <false /> (Mac)</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 +803,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('"', '"') self.assertEquals( self.doc_root.toxml(), '<root>' '<dl style="style_dd dl;">' '<dt>Windows:</dt>' '<dd style="style_.monospace;style_.pre;">MockKey\PolicyName = ' - '"' + value + '"' + + value + '</dd>' '<dt>Linux:</dt>' '<dd style="style_.monospace;">PolicyName: ' + value + '</dd>' |