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, ve rsion): | |
Joao da Silva
2014/10/15 13:04:37
break lines longer than 80 columns
cschuet (SLOW)
2014/10/15 15:23:14
Done.
| |
56 '''Substitutes the variable parts into a plist template. The result | |
57 of this function can be used as an expected result to test the output | |
58 of PListWriter. | |
59 | |
60 Args: | |
61 product_name: The name of the product, normally Chromium or Google Chrome. | |
62 bundle_id: The mac bundle id of the product. | |
63 policies: The list of policies. | |
64 | |
65 Returns: | |
66 The text of a plist template with the variable parts substituted. | |
67 ''' | |
68 return ''' | |
69 <?xml version="1.0" ?> | |
70 <!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTD s/PropertyList-1.0.dtd'> | |
71 <plist version="1"> | |
72 <dict> | |
73 <key>pfm_name</key> | |
74 <string>%s</string> | |
75 <key>pfm_description</key> | |
76 <string/> | |
77 <key>pfm_title</key> | |
78 <string/> | |
79 <key>pfm_version</key> | |
80 <string>1</string> | |
81 <key>pfm_domain</key> | |
82 <string>%s</string> | |
83 <key>pfm_subkeys</key> | |
84 %s | |
85 </dict> | |
86 <!--%s--> | |
87 </plist>''' % (product_name, bundle_id, policies, version) | |
88 | |
89 | |
90 | |
Joao da Silva
2014/10/15 13:04:37
one newline is enough
cschuet (SLOW)
2014/10/15 15:23:14
Done.
| |
55 def testEmpty(self): | 91 def testEmpty(self): |
56 # Test PListWriter in case of empty polices. | 92 # Test PListWriter in case of empty polices. |
57 grd = self.PrepareTest(''' | 93 grd = self.PrepareTest(''' |
94 { | |
95 'policy_definitions': [], | |
96 'placeholders': [], | |
97 'messages': {}, | |
Joao da Silva
2014/10/15 13:04:37
keep the indentation that this had before
cschuet (SLOW)
2014/10/15 15:23:14
Done.
| |
98 }''') | |
99 | |
100 output = self.GetOutput( | |
101 grd, | |
102 'fr', | |
103 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, | |
104 'plist', | |
105 'en') | |
106 expected_output = self._GetExpectedOutputs( | |
107 'Chromium', 'com.example.Test', '<array/>') | |
108 self.assertEquals(output.strip(), expected_output.strip()) | |
109 | |
110 def testEmptyVersion(self): | |
111 # Test PListWriter in case of empty polices. | |
112 grd = self.PrepareTest(''' | |
58 { | 113 { |
59 'policy_definitions': [], | 114 'policy_definitions': [], |
60 'placeholders': [], | 115 'placeholders': [], |
61 'messages': {}, | 116 'messages': {}, |
62 }''') | 117 }''') |
63 | 118 |
64 output = self.GetOutput( | 119 output = self.GetOutput( |
65 grd, | 120 grd, |
66 'fr', | 121 'fr', |
67 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, | 122 {'_chromium': '1', |
123 'mac_bundle_id': 'com.example.Test', | |
124 'version': '39.0.0.0'}, | |
68 'plist', | 125 'plist', |
69 'en') | 126 'en') |
70 expected_output = self._GetExpectedOutputs( | 127 expected_output = self._GetExpectedOutputsWithVersion( |
71 'Chromium', 'com.example.Test', '<array/>') | 128 'Chromium', 'com.example.Test', '<array/>', 'chromium version: 39.0.0.0' ) |
Joao da Silva
2014/10/15 13:04:37
seems like this line is longer than 80 columns too
cschuet (SLOW)
2014/10/15 15:23:14
Done.
| |
72 self.assertEquals(output.strip(), expected_output.strip()) | 129 self.assertEquals(output.strip(), expected_output.strip()) |
73 | 130 |
131 | |
132 | |
Joao da Silva
2014/10/15 13:04:37
remove these newlines
cschuet (SLOW)
2014/10/15 15:23:14
Done.
| |
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 |