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 grit.format.policy_templates.writers.plist_writer''' | 6 '''Unit tests for grit.format.policy_templates.writers.plist_writer''' |
7 | 7 |
8 | 8 |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 <string/> | 45 <string/> |
46 <key>pfm_version</key> | 46 <key>pfm_version</key> |
47 <string>1</string> | 47 <string>1</string> |
48 <key>pfm_domain</key> | 48 <key>pfm_domain</key> |
49 <string>%s</string> | 49 <string>%s</string> |
50 <key>pfm_subkeys</key> | 50 <key>pfm_subkeys</key> |
51 %s | 51 %s |
52 </dict> | 52 </dict> |
53 </plist>''' % (product_name, bundle_id, policies) | 53 </plist>''' % (product_name, bundle_id, policies) |
54 | 54 |
| 55 def _GetExpectedOutputsWithVersion(self, product_name, bundle_id, policies, |
| 56 version): |
| 57 '''Substitutes the variable parts into a plist template. The result |
| 58 of this function can be used as an expected result to test the output |
| 59 of PListWriter. |
| 60 |
| 61 Args: |
| 62 product_name: The name of the product, normally Chromium or Google Chrome. |
| 63 bundle_id: The mac bundle id of the product. |
| 64 policies: The list of policies. |
| 65 |
| 66 Returns: |
| 67 The text of a plist template with the variable parts substituted. |
| 68 ''' |
| 69 return ''' |
| 70 <?xml version="1.0" ?> |
| 71 <!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTD
s/PropertyList-1.0.dtd'> |
| 72 <plist version="1"> |
| 73 <dict> |
| 74 <key>pfm_name</key> |
| 75 <string>%s</string> |
| 76 <key>pfm_description</key> |
| 77 <string/> |
| 78 <key>pfm_title</key> |
| 79 <string/> |
| 80 <key>pfm_version</key> |
| 81 <string>1</string> |
| 82 <key>pfm_domain</key> |
| 83 <string>%s</string> |
| 84 <key>pfm_subkeys</key> |
| 85 %s |
| 86 </dict> |
| 87 <!--%s--> |
| 88 </plist>''' % (product_name, bundle_id, policies, version) |
| 89 |
55 def testEmpty(self): | 90 def testEmpty(self): |
56 # Test PListWriter in case of empty polices. | 91 # Test PListWriter in case of empty polices. |
57 grd = self.PrepareTest(''' | 92 grd = self.PrepareTest(''' |
58 { | 93 { |
59 'policy_definitions': [], | 94 'policy_definitions': [], |
60 'placeholders': [], | 95 'placeholders': [], |
61 'messages': {}, | 96 'messages': {}, |
62 }''') | 97 }''') |
63 | 98 |
64 output = self.GetOutput( | 99 output = self.GetOutput( |
65 grd, | 100 grd, |
66 'fr', | 101 'fr', |
67 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, | 102 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, |
68 'plist', | 103 'plist', |
69 'en') | 104 'en') |
70 expected_output = self._GetExpectedOutputs( | 105 expected_output = self._GetExpectedOutputs( |
71 'Chromium', 'com.example.Test', '<array/>') | 106 'Chromium', 'com.example.Test', '<array/>') |
72 self.assertEquals(output.strip(), expected_output.strip()) | 107 self.assertEquals(output.strip(), expected_output.strip()) |
73 | 108 |
| 109 def testEmptyVersion(self): |
| 110 # Test PListWriter in case of empty polices. |
| 111 grd = self.PrepareTest(''' |
| 112 { |
| 113 'policy_definitions': [], |
| 114 'placeholders': [], |
| 115 'messages': {}, |
| 116 }''') |
| 117 |
| 118 output = self.GetOutput( |
| 119 grd, |
| 120 'fr', |
| 121 {'_chromium': '1', |
| 122 'mac_bundle_id': 'com.example.Test', |
| 123 'version': '39.0.0.0'}, |
| 124 'plist', |
| 125 'en') |
| 126 expected_output = self._GetExpectedOutputsWithVersion( |
| 127 'Chromium', |
| 128 'com.example.Test', |
| 129 '<array/>', |
| 130 'chromium version: 39.0.0.0') |
| 131 self.assertEquals(output.strip(), expected_output.strip()) |
| 132 |
74 def testMainPolicy(self): | 133 def testMainPolicy(self): |
75 # Tests a policy group with a single policy of type 'main'. | 134 # Tests a policy group with a single policy of type 'main'. |
76 grd = self.PrepareTest(''' | 135 grd = self.PrepareTest(''' |
77 { | 136 { |
78 'policy_definitions': [ | 137 'policy_definitions': [ |
79 { | 138 { |
80 'name': 'MainGroup', | 139 'name': 'MainGroup', |
81 'type': 'group', | 140 'type': 'group', |
82 'policies': [{ | 141 'policies': [{ |
83 'name': 'MainPolicy', | 142 'name': 'MainPolicy', |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, | 682 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, |
624 'plist', | 683 'plist', |
625 'en') | 684 'en') |
626 expected_output = self._GetExpectedOutputs( | 685 expected_output = self._GetExpectedOutputs( |
627 'Google_Chrome', 'com.example.Test2', '''<array/>''') | 686 'Google_Chrome', 'com.example.Test2', '''<array/>''') |
628 self.assertEquals(output.strip(), expected_output.strip()) | 687 self.assertEquals(output.strip(), expected_output.strip()) |
629 | 688 |
630 | 689 |
631 if __name__ == '__main__': | 690 if __name__ == '__main__': |
632 unittest.main() | 691 unittest.main() |
OLD | NEW |