Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: components/policy/tools/template_writers/writers/doc_writer_unittest.py

Issue 2653823006: Include 'external' policies in grit output (admx, adm, doc etc.) (Closed)
Patch Set: Whitespace fix Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Unit tests for writers.doc_writer''' 6 '''Unit tests for writers.doc_writer'''
7 7
8 8
9 import json 9 import json
10 import os 10 import os
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 '<key>TestPolicyName</key>\n' 586 '<key>TestPolicyName</key>\n'
587 '<dict>\n' 587 '<dict>\n'
588 ' <key>foo</key>\n' 588 ' <key>foo</key>\n'
589 ' <integer>123</integer>\n' 589 ' <integer>123</integer>\n'
590 '</dict>' 590 '</dict>'
591 '</dd>' 591 '</dd>'
592 '</dl>' 592 '</dl>'
593 '</dd>' 593 '</dd>'
594 '</dl></root>') 594 '</dl></root>')
595 595
596 def testAddExternalPolicyDetails(self):
597 # Test if the definition list (<dl>) of policy details is created correctly
598 # for 'external' policies.
599 policy = {
600 'type': 'external',
601 'name': 'TestPolicyName',
602 'caption': 'TestPolicyCaption',
603 'desc': 'TestPolicyDesc',
604 'supported_on': [{
605 'product': 'chrome',
606 'platforms': ['win', 'mac', 'linux'],
607 'since_version': '8',
608 'until_version': '',
609 }],
610 'features': {'dynamic_refresh': False},
611 'example_value': {
612 "url": "https://example.com/avatar.jpg",
613 "hash": "deadbeef",
614 },
615 }
616 self.writer.messages['doc_since_version'] = {'text': '...$6...'}
617 self.writer._AddPolicyDetails(self.doc_root, policy)
618 self.assertEquals(
619 self.doc_root.toxml(),
620 '<root><dl>'
621 '<dt style="style_dt;">_test_data_type</dt>'
622 '<dd>External data reference [Windows:REG_SZ] (_test_complex_policies_wi n)</dd>'
623 '<dt style="style_dt;">_test_win_reg_loc</dt>'
624 '<dd style="style_.monospace;">MockKey\TestPolicyName</dd>'
625 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>'
626 '<dd style="style_.monospace;">TestPolicyName</dd>'
627 '<dt style="style_dt;">_test_supported_on</dt>'
628 '<dd>'
629 '<ul style="style_ul;">'
630 '<li>Chrome (Windows, Mac, Linux) ...8...</li>'
631 '</ul>'
632 '</dd>'
633 '<dt style="style_dt;">_test_supported_features</dt>'
634 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>'
635 '<dt style="style_dt;">_test_description</dt><dd><p>TestPolicyDesc</p></dd >'
636 '<dt style="style_dt;">_test_example_value</dt>'
637 '<dd>'
638 '<dl style="style_dd dl;">'
639 '<dt>_test_example_value_win</dt>'
640 '<dd style="style_.monospace;style_.pre;">'
641 'MockKey\TestPolicyName = {'
642 '&quot;url&quot;: &quot;https://example.com/avatar.jpg&quot;, '
643 '&quot;hash&quot;: &quot;deadbeef&quot;}'
644 '</dd>'
645 '<dt>Android/Linux:</dt>'
646 '<dd style="style_.monospace;">'
647 'TestPolicyName: {'
648 '&quot;url&quot;: &quot;https://example.com/avatar.jpg&quot;, '
649 '&quot;hash&quot;: &quot;deadbeef&quot;}'
650 '</dd>'
651 '<dt>Mac:</dt>'
652 '<dd style="style_.monospace;style_.pre;">'
653 '&lt;key&gt;TestPolicyName&lt;/key&gt;\n'
654 '&lt;dict&gt;\n'
655 ' &lt;key&gt;hash&lt;/key&gt;\n'
656 ' &lt;string&gt;deadbeef&lt;/string&gt;\n'
657 ' &lt;key&gt;url&lt;/key&gt;\n'
658 ' &lt;string&gt;https://example.com/avatar.jpg&lt;/string&gt;\n&l t;'
659 '/dict&gt;'
660 '</dd>'
661 '</dl>'
662 '</dd>'
663 '</dl></root>')
664
596 def testAddPolicyDetailsRecommendedOnly(self): 665 def testAddPolicyDetailsRecommendedOnly(self):
597 policy = { 666 policy = {
598 'type': 'main', 667 'type': 'main',
599 'name': 'TestPolicyName', 668 'name': 'TestPolicyName',
600 'caption': 'TestPolicyCaption', 669 'caption': 'TestPolicyCaption',
601 'desc': 'TestPolicyDesc', 670 'desc': 'TestPolicyDesc',
602 'supported_on': [{ 671 'supported_on': [{
603 'product': 'chrome', 672 'product': 'chrome',
604 'platforms': ['win', 'mac', 'linux'], 673 'platforms': ['win', 'mac', 'linux'],
605 'since_version': '8', 674 'since_version': '8',
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 ' &lt;/array&gt;\n' 1088 ' &lt;/array&gt;\n'
1020 ' &lt;key&gt;ProxyMode&lt;/key&gt;\n' 1089 ' &lt;key&gt;ProxyMode&lt;/key&gt;\n'
1021 ' &lt;string&gt;direct&lt;/string&gt;\n' 1090 ' &lt;string&gt;direct&lt;/string&gt;\n'
1022 ' &lt;key&gt;True&lt;/key&gt;\n' 1091 ' &lt;key&gt;True&lt;/key&gt;\n'
1023 ' &lt;true/&gt;\n' 1092 ' &lt;true/&gt;\n'
1024 '&lt;/dict&gt;' 1093 '&lt;/dict&gt;'
1025 '</dd>' 1094 '</dd>'
1026 '</dl>' 1095 '</dl>'
1027 '</root>') 1096 '</root>')
1028 1097
1098 def testAddExternalExample(self):
1099 policy = {
1100 'name': 'PolicyName',
1101 'caption': 'PolicyCaption',
1102 'desc': 'PolicyDesc',
1103 'type': 'external',
1104 'supported_on': [{
1105 'product': 'chrome',
1106 'platforms': ['win', 'mac', 'linux'],
1107 'since_version': '7',
1108 'until_version': '',
1109 }],
1110 'features': {'dynamic_refresh': False},
1111 'example_value': {
1112 "url": "https://example.com/avatar.jpg",
1113 "hash": "deadbeef",
1114 },
1115 }
1116 self.writer._AddDictionaryExample(self.doc_root, policy)
1117 value = json.dumps(policy['example_value']).replace('"', '&quot;')
1118 self.assertEquals(
1119 self.doc_root.toxml(),
1120 '<root>'
1121 '<dl style="style_dd dl;">'
1122 '<dt>_test_example_value_win</dt>'
1123 '<dd style="style_.monospace;style_.pre;">MockKey\PolicyName = '
1124 + value +
1125 '</dd>'
1126 '<dt>Android/Linux:</dt>'
1127 '<dd style="style_.monospace;">PolicyName: ' + value + '</dd>'
1128 '<dt>Mac:</dt>'
1129 '<dd style="style_.monospace;style_.pre;">'
1130 '&lt;key&gt;PolicyName&lt;/key&gt;\n'
1131 '&lt;dict&gt;\n'
1132 ' &lt;key&gt;hash&lt;/key&gt;\n'
1133 ' &lt;string&gt;deadbeef&lt;/string&gt;\n'
1134 ' &lt;key&gt;url&lt;/key&gt;\n'
1135 ' &lt;string&gt;https://example.com/avatar.jpg&lt;/string&gt;\n'
1136 '&lt;/dict&gt;'
1137 '</dd>'
1138 '</dl>'
1139 '</root>')
1140
1029 def testParagraphs(self): 1141 def testParagraphs(self):
1030 text = 'Paragraph 1\n\nParagraph 2\n\nParagraph 3' 1142 text = 'Paragraph 1\n\nParagraph 2\n\nParagraph 3'
1031 self.writer._AddParagraphs(self.doc_root, text) 1143 self.writer._AddParagraphs(self.doc_root, text)
1032 self.assertEquals( 1144 self.assertEquals(
1033 self.doc_root.toxml(), 1145 self.doc_root.toxml(),
1034 '<root><p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p></root>') 1146 '<root><p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p></root>')
1035 1147
1036 if __name__ == '__main__': 1148 if __name__ == '__main__':
1037 unittest.main() 1149 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698