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

Side by Side Diff: tools/grit/grit/format/policy_templates/writers/json_writer_unittest.py

Issue 6360002: Remove 'annotations' dictionary in policy_definitions.json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better comments Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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.json_writer''' 6 '''Unit tests for grit.format.policy_templates.writers.json_writer'''
7 7
8 8
9 import os 9 import os
10 import sys 10 import sys
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 # Tests a policy group with a single policy of type 'main'. 49 # Tests a policy group with a single policy of type 'main'.
50 grd = self.PrepareTest( 50 grd = self.PrepareTest(
51 '{' 51 '{'
52 ' "policy_definitions": [' 52 ' "policy_definitions": ['
53 ' {' 53 ' {'
54 ' "name": "MainPolicy",' 54 ' "name": "MainPolicy",'
55 ' "type": "main",' 55 ' "type": "main",'
56 ' "caption": "",' 56 ' "caption": "",'
57 ' "desc": "",' 57 ' "desc": "",'
58 ' "supported_on": ["chrome.linux:8-"],' 58 ' "supported_on": ["chrome.linux:8-"],'
59 ' "annotations": {' 59 ' "example_value": True'
60 ' "example_value": True'
61 ' }'
62 ' },' 60 ' },'
63 ' ],' 61 ' ],'
64 ' "placeholders": [],' 62 ' "placeholders": [],'
65 ' "messages": {},' 63 ' "messages": {},'
66 '}') 64 '}')
67 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'json', 'en') 65 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'json', 'en')
68 expected_output = ( 66 expected_output = (
69 '{\n' 67 '{\n'
70 ' "MainPolicy": true\n' 68 ' "MainPolicy": true\n'
71 '}') 69 '}')
72 self.CompareOutputs(output, expected_output) 70 self.CompareOutputs(output, expected_output)
73 71
74 def testStringPolicy(self): 72 def testStringPolicy(self):
75 # Tests a policy group with a single policy of type 'string'. 73 # Tests a policy group with a single policy of type 'string'.
76 grd = self.PrepareTest( 74 grd = self.PrepareTest(
77 '{' 75 '{'
78 ' "policy_definitions": [' 76 ' "policy_definitions": ['
79 ' {' 77 ' {'
80 ' "name": "StringPolicy",' 78 ' "name": "StringPolicy",'
81 ' "type": "string",' 79 ' "type": "string",'
82 ' "caption": "",' 80 ' "caption": "",'
83 ' "desc": "",' 81 ' "desc": "",'
84 ' "supported_on": ["chrome.linux:8-"],' 82 ' "supported_on": ["chrome.linux:8-"],'
85 ' "annotations": {' 83 ' "example_value": "hello, world!"'
86 ' "example_value": "hello, world!"'
87 ' }'
88 ' },' 84 ' },'
89 ' ],' 85 ' ],'
90 ' "placeholders": [],' 86 ' "placeholders": [],'
91 ' "messages": {},' 87 ' "messages": {},'
92 '}') 88 '}')
93 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') 89 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
94 expected_output = ( 90 expected_output = (
95 '{\n' 91 '{\n'
96 ' "StringPolicy": "hello, world!"\n' 92 ' "StringPolicy": "hello, world!"\n'
97 '}') 93 '}')
98 self.CompareOutputs(output, expected_output) 94 self.CompareOutputs(output, expected_output)
99 95
100 def testIntPolicy(self): 96 def testIntPolicy(self):
101 # Tests a policy group with a single policy of type 'string'. 97 # Tests a policy group with a single policy of type 'string'.
102 grd = self.PrepareTest( 98 grd = self.PrepareTest(
103 '{' 99 '{'
104 ' "policy_definitions": [' 100 ' "policy_definitions": ['
105 ' {' 101 ' {'
106 ' "name": "IntPolicy",' 102 ' "name": "IntPolicy",'
107 ' "type": "int",' 103 ' "type": "int",'
108 ' "caption": "",' 104 ' "caption": "",'
109 ' "desc": "",' 105 ' "desc": "",'
110 ' "supported_on": ["chrome.linux:8-"],' 106 ' "supported_on": ["chrome.linux:8-"],'
111 ' "annotations": {' 107 ' "example_value": 15'
112 ' "example_value": 15'
113 ' }'
114 ' },' 108 ' },'
115 ' ],' 109 ' ],'
116 ' "placeholders": [],' 110 ' "placeholders": [],'
117 ' "messages": {},' 111 ' "messages": {},'
118 '}') 112 '}')
119 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') 113 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
120 expected_output = ( 114 expected_output = (
121 '{\n' 115 '{\n'
122 ' "IntPolicy": 15\n' 116 ' "IntPolicy": 15\n'
123 '}') 117 '}')
124 self.CompareOutputs(output, expected_output) 118 self.CompareOutputs(output, expected_output)
125 119
126 def testIntEnumPolicy(self): 120 def testIntEnumPolicy(self):
127 # Tests a policy group with a single policy of type 'int-enum'. 121 # Tests a policy group with a single policy of type 'int-enum'.
128 grd = self.PrepareTest( 122 grd = self.PrepareTest(
129 '{' 123 '{'
130 ' "policy_definitions": [' 124 ' "policy_definitions": ['
131 ' {' 125 ' {'
132 ' "name": "EnumPolicy",' 126 ' "name": "EnumPolicy",'
133 ' "type": "int-enum",' 127 ' "type": "int-enum",'
134 ' "caption": "",' 128 ' "caption": "",'
135 ' "desc": "",' 129 ' "desc": "",'
136 ' "items": [' 130 ' "items": ['
137 ' {"name": "ProxyServerDisabled", "value": 0, "caption": ""},' 131 ' {"name": "ProxyServerDisabled", "value": 0, "caption": ""},'
138 ' {"name": "ProxyServerAutoDetect", "value": 1, "caption": ""},' 132 ' {"name": "ProxyServerAutoDetect", "value": 1, "caption": ""},'
139 ' ],' 133 ' ],'
140 ' "supported_on": ["chrome.linux:8-"],' 134 ' "supported_on": ["chrome.linux:8-"],'
141 ' "annotations": {' 135 ' "example_value": 1'
142 ' "example_value": 1'
143 ' }'
144 ' },' 136 ' },'
145 ' ],' 137 ' ],'
146 ' "placeholders": [],' 138 ' "placeholders": [],'
147 ' "messages": {},' 139 ' "messages": {},'
148 '}') 140 '}')
149 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en') 141 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en')
150 expected_output = ( 142 expected_output = (
151 '{\n' 143 '{\n'
152 ' "EnumPolicy": 1\n' 144 ' "EnumPolicy": 1\n'
153 '}') 145 '}')
154 self.CompareOutputs(output, expected_output) 146 self.CompareOutputs(output, expected_output)
155 147
156 def testStringEnumPolicy(self): 148 def testStringEnumPolicy(self):
157 # Tests a policy group with a single policy of type 'string-enum'. 149 # Tests a policy group with a single policy of type 'string-enum'.
158 grd = self.PrepareTest( 150 grd = self.PrepareTest(
159 '{' 151 '{'
160 ' "policy_definitions": [' 152 ' "policy_definitions": ['
161 ' {' 153 ' {'
162 ' "name": "EnumPolicy",' 154 ' "name": "EnumPolicy",'
163 ' "type": "string-enum",' 155 ' "type": "string-enum",'
164 ' "caption": "",' 156 ' "caption": "",'
165 ' "desc": "",' 157 ' "desc": "",'
166 ' "items": [' 158 ' "items": ['
167 ' {"name": "ProxyServerDisabled", "value": "one",' 159 ' {"name": "ProxyServerDisabled", "value": "one",'
168 ' "caption": ""},' 160 ' "caption": ""},'
169 ' {"name": "ProxyServerAutoDetect", "value": "two",' 161 ' {"name": "ProxyServerAutoDetect", "value": "two",'
170 ' "caption": ""},' 162 ' "caption": ""},'
171 ' ],' 163 ' ],'
172 ' "supported_on": ["chrome.linux:8-"],' 164 ' "supported_on": ["chrome.linux:8-"],'
173 ' "annotations": {' 165 ' "example_value": "one"'
174 ' "example_value": "one"'
175 ' }'
176 ' },' 166 ' },'
177 ' ],' 167 ' ],'
178 ' "placeholders": [],' 168 ' "placeholders": [],'
179 ' "messages": {},' 169 ' "messages": {},'
180 '}') 170 '}')
181 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en') 171 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'json', 'en')
182 expected_output = ( 172 expected_output = (
183 '{\n' 173 '{\n'
184 ' "EnumPolicy": "one"\n' 174 ' "EnumPolicy": "one"\n'
185 '}') 175 '}')
186 self.CompareOutputs(output, expected_output) 176 self.CompareOutputs(output, expected_output)
187 177
188 def testListPolicy(self): 178 def testListPolicy(self):
189 # Tests a policy group with a single policy of type 'list'. 179 # Tests a policy group with a single policy of type 'list'.
190 grd = self.PrepareTest( 180 grd = self.PrepareTest(
191 '{' 181 '{'
192 ' "policy_definitions": [' 182 ' "policy_definitions": ['
193 ' {' 183 ' {'
194 ' "name": "ListPolicy",' 184 ' "name": "ListPolicy",'
195 ' "type": "list",' 185 ' "type": "list",'
196 ' "caption": "",' 186 ' "caption": "",'
197 ' "desc": "",' 187 ' "desc": "",'
198 ' "supported_on": ["chrome.linux:8-"],' 188 ' "supported_on": ["chrome.linux:8-"],'
199 ' "annotations": {' 189 ' "example_value": ["foo", "bar"]'
200 ' "example_value": ["foo", "bar"]'
201 ' }'
202 ' },' 190 ' },'
203 ' ],' 191 ' ],'
204 ' "placeholders": [],' 192 ' "placeholders": [],'
205 ' "messages": {},' 193 ' "messages": {},'
206 '}') 194 '}')
207 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') 195 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
208 expected_output = ( 196 expected_output = (
209 '{\n' 197 '{\n'
210 ' "ListPolicy": ["foo", "bar"]\n' 198 ' "ListPolicy": ["foo", "bar"]\n'
211 '}') 199 '}')
212 self.CompareOutputs(output, expected_output) 200 self.CompareOutputs(output, expected_output)
213 201
214 def testNonSupportedPolicy(self): 202 def testNonSupportedPolicy(self):
215 # Tests a policy that is not supported on Linux, so it shouldn't 203 # Tests a policy that is not supported on Linux, so it shouldn't
216 # be included in the JSON file. 204 # be included in the JSON file.
217 grd = self.PrepareTest( 205 grd = self.PrepareTest(
218 '{' 206 '{'
219 ' "policy_definitions": [' 207 ' "policy_definitions": ['
220 ' {' 208 ' {'
221 ' "name": "NonLinuxPolicy",' 209 ' "name": "NonLinuxPolicy",'
222 ' "type": "list",' 210 ' "type": "list",'
223 ' "caption": "",' 211 ' "caption": "",'
224 ' "desc": "",' 212 ' "desc": "",'
225 ' "supported_on": ["chrome.mac:8-"],' 213 ' "supported_on": ["chrome.mac:8-"],'
226 ' "annotations": {' 214 ' "example_value": ["a"]'
227 ' "example_value": ["a"]'
228 ' }'
229 ' },' 215 ' },'
230 ' ],' 216 ' ],'
231 ' "placeholders": [],' 217 ' "placeholders": [],'
232 ' "messages": {},' 218 ' "messages": {},'
233 '}') 219 '}')
234 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') 220 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
235 expected_output = '{\n}' 221 expected_output = '{\n}'
236 self.CompareOutputs(output, expected_output) 222 self.CompareOutputs(output, expected_output)
237 223
238 def testPolicyGroup(self): 224 def testPolicyGroup(self):
239 # Tests a policy group that has more than one policies. 225 # Tests a policy group that has more than one policies.
240 grd = self.PrepareTest( 226 grd = self.PrepareTest(
241 '{' 227 '{'
242 ' "policy_definitions": [' 228 ' "policy_definitions": ['
243 ' {' 229 ' {'
244 ' "name": "Group1",' 230 ' "name": "Group1",'
245 ' "type": "group",' 231 ' "type": "group",'
246 ' "caption": "",' 232 ' "caption": "",'
247 ' "desc": "",' 233 ' "desc": "",'
248 ' "policies": [{' 234 ' "policies": [{'
249 ' "name": "Policy1",' 235 ' "name": "Policy1",'
250 ' "type": "list",' 236 ' "type": "list",'
251 ' "caption": "",' 237 ' "caption": "",'
252 ' "desc": "",' 238 ' "desc": "",'
253 ' "supported_on": ["chrome.linux:8-"],' 239 ' "supported_on": ["chrome.linux:8-"],'
254 ' "annotations": {' 240 ' "example_value": ["a", "b"]'
255 ' "example_value": ["a", "b"]'
256 ' }'
257 ' },{' 241 ' },{'
258 ' "name": "Policy2",' 242 ' "name": "Policy2",'
259 ' "type": "string",' 243 ' "type": "string",'
260 ' "caption": "",' 244 ' "caption": "",'
261 ' "desc": "",' 245 ' "desc": "",'
262 ' "supported_on": ["chrome.linux:8-"],' 246 ' "supported_on": ["chrome.linux:8-"],'
263 ' "annotations": {' 247 ' "example_value": "c"'
264 ' "example_value": "c"'
265 ' }'
266 ' }],' 248 ' }],'
267 ' },' 249 ' },'
268 ' ],' 250 ' ],'
269 ' "placeholders": [],' 251 ' "placeholders": [],'
270 ' "messages": {},' 252 ' "messages": {},'
271 '}') 253 '}')
272 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') 254 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en')
273 expected_output = ( 255 expected_output = (
274 '{\n' 256 '{\n'
275 ' "Policy1": ["a", "b"],\n' 257 ' "Policy1": ["a", "b"],\n'
276 ' "Policy2": "c"\n' 258 ' "Policy2": "c"\n'
277 '}') 259 '}')
278 self.CompareOutputs(output, expected_output) 260 self.CompareOutputs(output, expected_output)
279 261
280 262
281 if __name__ == '__main__': 263 if __name__ == '__main__':
282 unittest.main() 264 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698