| OLD | NEW |
| 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 Loading... |
| 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 '"url": "https://example.com/avatar.jpg", ' |
| 643 '"hash": "deadbeef"}' |
| 644 '</dd>' |
| 645 '<dt>Android/Linux:</dt>' |
| 646 '<dd style="style_.monospace;">' |
| 647 'TestPolicyName: {' |
| 648 '"url": "https://example.com/avatar.jpg", ' |
| 649 '"hash": "deadbeef"}' |
| 650 '</dd>' |
| 651 '<dt>Mac:</dt>' |
| 652 '<dd style="style_.monospace;style_.pre;">' |
| 653 '<key>TestPolicyName</key>\n' |
| 654 '<dict>\n' |
| 655 ' <key>hash</key>\n' |
| 656 ' <string>deadbeef</string>\n' |
| 657 ' <key>url</key>\n' |
| 658 ' <string>https://example.com/avatar.jpg</string>\n&l
t;' |
| 659 '/dict>' |
| 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 Loading... |
| 1019 ' </array>\n' | 1088 ' </array>\n' |
| 1020 ' <key>ProxyMode</key>\n' | 1089 ' <key>ProxyMode</key>\n' |
| 1021 ' <string>direct</string>\n' | 1090 ' <string>direct</string>\n' |
| 1022 ' <key>True</key>\n' | 1091 ' <key>True</key>\n' |
| 1023 ' <true/>\n' | 1092 ' <true/>\n' |
| 1024 '</dict>' | 1093 '</dict>' |
| 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('"', '"') |
| 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 '<key>PolicyName</key>\n' |
| 1131 '<dict>\n' |
| 1132 ' <key>hash</key>\n' |
| 1133 ' <string>deadbeef</string>\n' |
| 1134 ' <key>url</key>\n' |
| 1135 ' <string>https://example.com/avatar.jpg</string>\n' |
| 1136 '</dict>' |
| 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() |
| OLD | NEW |