OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 '''Unit tests for grit.format.policy_templates.writers.doc_writer''' | |
7 | |
8 | |
9 import json | |
10 import os | |
11 import sys | |
12 if __name__ == '__main__': | |
13 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | |
14 | |
15 import unittest | |
16 from xml.dom import minidom | |
17 | |
18 from grit.format.policy_templates.writers import writer_unittest_common | |
19 from grit.format.policy_templates.writers import doc_writer | |
20 | |
21 | |
22 class MockMessageDictionary: | |
23 '''A mock dictionary passed to a writer as the dictionary of | |
24 localized messages. | |
25 ''' | |
26 | |
27 # Dictionary of messages. | |
28 msg_dict = {} | |
29 | |
30 class DocWriterUnittest(writer_unittest_common.WriterUnittestCommon): | |
31 '''Unit tests for DocWriter.''' | |
32 | |
33 def setUp(self): | |
34 # Create a writer for the tests. | |
35 self.writer = doc_writer.GetWriter( | |
36 config={ | |
37 'app_name': 'Chrome', | |
38 'frame_name': 'Chrome Frame', | |
39 'os_name': 'Chrome OS', | |
40 'webview_name': 'WebView', | |
41 'android_webview_restriction_prefix': 'mock.prefix:', | |
42 'win_reg_mandatory_key_name': 'MockKey', | |
43 'win_reg_recommended_key_name': 'MockKeyRec', | |
44 'build': 'test_product', | |
45 }) | |
46 self.writer.messages = { | |
47 'doc_back_to_top': {'text': '_test_back_to_top'}, | |
48 'doc_complex_policies_on_windows': {'text': '_test_complex_policies_win'}, | |
49 'doc_data_type': {'text': '_test_data_type'}, | |
50 'doc_description': {'text': '_test_description'}, | |
51 'doc_description_column_title': { | |
52 'text': '_test_description_column_title' | |
53 }, | |
54 'doc_example_value': {'text': '_test_example_value'}, | |
55 'doc_feature_dynamic_refresh': {'text': '_test_feature_dynamic_refresh'}, | |
56 'doc_feature_can_be_recommended': {'text': '_test_feature_recommended'}, | |
57 'doc_feature_can_be_mandatory': {'text': '_test_feature_mandatory'}, | |
58 'doc_intro': {'text': '_test_intro'}, | |
59 'doc_mac_linux_pref_name': {'text': '_test_mac_linux_pref_name'}, | |
60 'doc_android_restriction_name': { | |
61 'text': '_test_android_restriction_name' | |
62 }, | |
63 'doc_android_webview_restriction_name': { | |
64 'text': '_test_android_webview_restriction_name' | |
65 }, | |
66 'doc_note': {'text': '_test_note'}, | |
67 'doc_name_column_title': {'text': '_test_name_column_title'}, | |
68 'doc_not_supported': {'text': '_test_not_supported'}, | |
69 'doc_since_version': {'text': '_test_since_version'}, | |
70 'doc_supported': {'text': '_test_supported'}, | |
71 'doc_supported_features': {'text': '_test_supported_features'}, | |
72 'doc_supported_on': {'text': '_test_supported_on'}, | |
73 'doc_win_reg_loc': {'text': '_test_win_reg_loc'}, | |
74 | |
75 'doc_bla': {'text': '_test_bla'}, | |
76 } | |
77 self.writer.Init() | |
78 | |
79 # It is not worth testing the exact content of style attributes. | |
80 # Therefore we override them here with shorter texts. | |
81 for key in self.writer._STYLE.keys(): | |
82 self.writer._STYLE[key] = 'style_%s;' % key | |
83 # Add some more style attributes for additional testing. | |
84 self.writer._STYLE['key1'] = 'style1;' | |
85 self.writer._STYLE['key2'] = 'style2;' | |
86 | |
87 # Create a DOM document for the tests. | |
88 dom_impl = minidom.getDOMImplementation('') | |
89 self.doc = dom_impl.createDocument(None, 'root', None) | |
90 self.doc_root = self.doc.documentElement | |
91 | |
92 def testSkeleton(self): | |
93 # Test if DocWriter creates the skeleton of the document correctly. | |
94 self.writer.BeginTemplate() | |
95 self.assertEquals( | |
96 self.writer._main_div.toxml(), | |
97 '<div>' | |
98 '<div>' | |
99 '<a name="top"/><br/><p>_test_intro</p><br/><br/><br/>' | |
100 '<table style="style_table;">' | |
101 '<thead><tr style="style_tr;">' | |
102 '<td style="style_td;style_td.left;style_thead td;">' | |
103 '_test_name_column_title' | |
104 '</td>' | |
105 '<td style="style_td;style_td.right;style_thead td;">' | |
106 '_test_description_column_title' | |
107 '</td>' | |
108 '</tr></thead>' | |
109 '<tbody/>' | |
110 '</table>' | |
111 '</div>' | |
112 '<div/>' | |
113 '</div>') | |
114 | |
115 def testVersionAnnotation(self): | |
116 # Test if DocWriter creates the skeleton of the document correctly. | |
117 self.writer.config['version'] = '39.0.0.0' | |
118 self.writer.BeginTemplate() | |
119 self.assertEquals( | |
120 self.writer._main_div.toxml(), | |
121 '<div>' | |
122 '<!--test_product version: 39.0.0.0-->' | |
123 '<div>' | |
124 '<a name="top"/><br/><p>_test_intro</p><br/><br/><br/>' | |
125 '<table style="style_table;">' | |
126 '<thead><tr style="style_tr;">' | |
127 '<td style="style_td;style_td.left;style_thead td;">' | |
128 '_test_name_column_title' | |
129 '</td>' | |
130 '<td style="style_td;style_td.right;style_thead td;">' | |
131 '_test_description_column_title' | |
132 '</td>' | |
133 '</tr></thead>' | |
134 '<tbody/>' | |
135 '</table>' | |
136 '</div>' | |
137 '<div/>' | |
138 '</div>') | |
139 | |
140 def testGetLocalizedMessage(self): | |
141 # Test if localized messages are retrieved correctly. | |
142 self.writer.messages = { | |
143 'doc_hello_world': {'text': 'hello, vilag!'} | |
144 } | |
145 self.assertEquals( | |
146 self.writer._GetLocalizedMessage('hello_world'), | |
147 'hello, vilag!') | |
148 | |
149 def testMapListToString(self): | |
150 # Test function DocWriter.MapListToString() | |
151 self.assertEquals( | |
152 self.writer._MapListToString({'a1': 'a2', 'b1': 'b2'}, ['a1', 'b1']), | |
153 'a2, b2') | |
154 self.assertEquals( | |
155 self.writer._MapListToString({'a1': 'a2', 'b1': 'b2'}, []), | |
156 '') | |
157 result = self.writer._MapListToString( | |
158 {'a': '1', 'b': '2', 'c': '3', 'd': '4'}, ['b', 'd']) | |
159 expected_result = '2, 4' | |
160 self.assertEquals( | |
161 result, | |
162 expected_result) | |
163 | |
164 def testAddStyledElement(self): | |
165 # Test function DocWriter.AddStyledElement() | |
166 | |
167 # Test the case of zero style. | |
168 e1 = self.writer._AddStyledElement( | |
169 self.doc_root, 'z', [], {'a': 'b'}, 'text') | |
170 self.assertEquals( | |
171 e1.toxml(), | |
172 '<z a="b">text</z>') | |
173 | |
174 # Test the case of one style. | |
175 e2 = self.writer._AddStyledElement( | |
176 self.doc_root, 'z', ['key1'], {'a': 'b'}, 'text') | |
177 self.assertEquals( | |
178 e2.toxml(), | |
179 '<z a="b" style="style1;">text</z>') | |
180 | |
181 # Test the case of two styles. | |
182 e3 = self.writer._AddStyledElement( | |
183 self.doc_root, 'z', ['key1', 'key2'], {'a': 'b'}, 'text') | |
184 self.assertEquals( | |
185 e3.toxml(), | |
186 '<z a="b" style="style1;style2;">text</z>') | |
187 | |
188 def testAddDescriptionIntEnum(self): | |
189 # Test if URLs are replaced and choices of 'int-enum' policies are listed | |
190 # correctly. | |
191 policy = { | |
192 'type': 'int-enum', | |
193 'items': [ | |
194 {'value': 0, 'caption': 'Disable foo'}, | |
195 {'value': 2, 'caption': 'Solve your problem'}, | |
196 {'value': 5, 'caption': 'Enable bar'}, | |
197 ], | |
198 'desc': '''This policy disables foo, except in case of bar. | |
199 See http://policy-explanation.example.com for more details. | |
200 ''' | |
201 } | |
202 self.writer._AddDescription(self.doc_root, policy) | |
203 self.assertEquals( | |
204 self.doc_root.toxml(), | |
205 '''<root><p>This policy disables foo, except in case of bar. | |
206 See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
ample.com</a> for more details. | |
207 </p><ul><li>0 = Disable foo</li><li>2 = Solve your problem</li><li>5 = Enable ba
r</li></ul></root>''') | |
208 | |
209 def testAddDescriptionStringEnum(self): | |
210 # Test if URLs are replaced and choices of 'int-enum' policies are listed | |
211 # correctly. | |
212 policy = { | |
213 'type': 'string-enum', | |
214 'items': [ | |
215 {'value': "one", 'caption': 'Disable foo'}, | |
216 {'value': "two", 'caption': 'Solve your problem'}, | |
217 {'value': "three", 'caption': 'Enable bar'}, | |
218 ], | |
219 'desc': '''This policy disables foo, except in case of bar. | |
220 See http://policy-explanation.example.com for more details. | |
221 ''' | |
222 } | |
223 self.writer._AddDescription(self.doc_root, policy) | |
224 self.assertEquals( | |
225 self.doc_root.toxml(), | |
226 '''<root><p>This policy disables foo, except in case of bar. | |
227 See <a href="http://policy-explanation.example.com">http://policy-explanation.ex
ample.com</a> for more details. | |
228 </p><ul><li>"one" = Disable foo</li><li>"two" = Solve your p
roblem</li><li>"three" = Enable bar</li></ul></root>''') | |
229 | |
230 def testAddFeatures(self): | |
231 # Test if the list of features of a policy is handled correctly. | |
232 policy = { | |
233 'features': { | |
234 'spaceship_docking': False, | |
235 'dynamic_refresh': True, | |
236 'can_be_recommended': True, | |
237 } | |
238 } | |
239 self.writer._FEATURE_MAP = { | |
240 'can_be_recommended': 'Can Be Recommended', | |
241 'dynamic_refresh': 'Dynamic Refresh', | |
242 'spaceship_docking': 'Spaceship Docking', | |
243 } | |
244 self.writer._AddFeatures(self.doc_root, policy) | |
245 self.assertEquals( | |
246 self.doc_root.toxml(), | |
247 '<root>' | |
248 'Can Be Recommended: _test_supported, ' | |
249 'Dynamic Refresh: _test_supported, ' | |
250 'Spaceship Docking: _test_not_supported' | |
251 '</root>') | |
252 | |
253 def testAddListExample(self): | |
254 policy = { | |
255 'name': 'PolicyName', | |
256 'example_value': ['Foo', 'Bar'], | |
257 'supported_on': [ { 'platforms': ['win', 'mac', 'linux'] } ] | |
258 } | |
259 self.writer._AddListExample(self.doc_root, policy) | |
260 self.assertEquals( | |
261 self.doc_root.toxml(), | |
262 '<root>' | |
263 '<dl style="style_dd dl;">' | |
264 '<dt>Windows:</dt>' | |
265 '<dd style="style_.monospace;style_.pre;">' | |
266 'MockKey\\PolicyName\\1 = "Foo"\n' | |
267 'MockKey\\PolicyName\\2 = "Bar"' | |
268 '</dd>' | |
269 '<dt>Android/Linux:</dt>' | |
270 '<dd style="style_.monospace;">' | |
271 '["Foo", "Bar"]' | |
272 '</dd>' | |
273 '<dt>Mac:</dt>' | |
274 '<dd style="style_.monospace;style_.pre;">' | |
275 '<array>\n' | |
276 ' <string>Foo</string>\n' | |
277 ' <string>Bar</string>\n' | |
278 '</array>' | |
279 '</dd>' | |
280 '</dl>' | |
281 '</root>') | |
282 | |
283 def testBoolExample(self): | |
284 # Test representation of boolean example values. | |
285 policy = { | |
286 'name': 'PolicyName', | |
287 'type': 'main', | |
288 'example_value': True, | |
289 'supported_on': [ { 'platforms': ['win', 'mac', 'linux', 'android'] } ] | |
290 } | |
291 e1 = self.writer.AddElement(self.doc_root, 'e1') | |
292 self.writer._AddExample(e1, policy) | |
293 self.assertEquals( | |
294 e1.toxml(), | |
295 '<e1>0x00000001 (Windows),' | |
296 ' true (Linux), true (Android),' | |
297 ' <true /> (Mac)</e1>') | |
298 | |
299 policy = { | |
300 'name': 'PolicyName', | |
301 'type': 'main', | |
302 'example_value': False, | |
303 'supported_on': [ { 'platforms': ['win', 'mac', 'linux', 'android'] } ] | |
304 } | |
305 e2 = self.writer.AddElement(self.doc_root, 'e2') | |
306 self.writer._AddExample(e2, policy) | |
307 self.assertEquals( | |
308 e2.toxml(), | |
309 '<e2>0x00000000 (Windows),' | |
310 ' false (Linux), false (Android),' | |
311 ' <false /> (Mac)</e2>') | |
312 | |
313 def testIntEnumExample(self): | |
314 # Test representation of 'int-enum' example values. | |
315 policy = { | |
316 'name': 'PolicyName', | |
317 'type': 'int-enum', | |
318 'example_value': 16, | |
319 'supported_on': [ { 'platforms': ['win', 'mac', 'linux', 'android'] } ] | |
320 } | |
321 self.writer._AddExample(self.doc_root, policy) | |
322 self.assertEquals( | |
323 self.doc_root.toxml(), | |
324 '<root>0x00000010 (Windows), 16 (Linux), 16 (Android), 16 (Mac)</root>') | |
325 | |
326 def testStringEnumExample(self): | |
327 # Test representation of 'string-enum' example values. | |
328 policy = { | |
329 'name': 'PolicyName', | |
330 'type': 'string-enum', | |
331 'example_value': "wacky" | |
332 } | |
333 self.writer._AddExample(self.doc_root, policy) | |
334 self.assertEquals( | |
335 self.doc_root.toxml(), | |
336 '<root>"wacky"</root>') | |
337 | |
338 def testListExample(self): | |
339 # Test representation of 'list' example values. | |
340 policy = { | |
341 'name': 'PolicyName', | |
342 'type': 'list', | |
343 'example_value': ['one', 'two'], | |
344 'supported_on': [ { 'platforms': ['linux'] } ] | |
345 } | |
346 self.writer._AddExample(self.doc_root, policy) | |
347 self.assertEquals( | |
348 self.doc_root.toxml(), | |
349 '<root><dl style="style_dd dl;">' | |
350 '<dt>Android/Linux:</dt>' | |
351 '<dd style="style_.monospace;">' | |
352 '["one", "two"]' | |
353 '</dd></dl></root>') | |
354 | |
355 def testStringEnumListExample(self): | |
356 # Test representation of 'string-enum-list' example values. | |
357 policy = { | |
358 'name': 'PolicyName', | |
359 'type': 'string-enum-list', | |
360 'example_value': ['one', 'two'], | |
361 'supported_on': [ { 'platforms': ['linux'] } ] | |
362 } | |
363 self.writer._AddExample(self.doc_root, policy) | |
364 self.assertEquals( | |
365 self.doc_root.toxml(), | |
366 '<root><dl style="style_dd dl;">' | |
367 '<dt>Android/Linux:</dt>' | |
368 '<dd style="style_.monospace;">' | |
369 '["one", "two"]' | |
370 '</dd></dl></root>') | |
371 | |
372 def testStringExample(self): | |
373 # Test representation of 'string' example values. | |
374 policy = { | |
375 'name': 'PolicyName', | |
376 'type': 'string', | |
377 'example_value': 'awesome-example' | |
378 } | |
379 self.writer._AddExample(self.doc_root, policy) | |
380 self.assertEquals( | |
381 self.doc_root.toxml(), | |
382 '<root>"awesome-example"</root>') | |
383 | |
384 def testIntExample(self): | |
385 # Test representation of 'int' example values. | |
386 policy = { | |
387 'name': 'PolicyName', | |
388 'type': 'int', | |
389 'example_value': 26, | |
390 'supported_on': [ { 'platforms': ['win', 'mac', 'linux', 'android'] } ] | |
391 } | |
392 self.writer._AddExample(self.doc_root, policy) | |
393 self.assertEquals( | |
394 self.doc_root.toxml(), | |
395 '<root>0x0000001a (Windows), 26 (Linux), 26 (Android), 26 (Mac)</root>') | |
396 | |
397 def testAddPolicyAttribute(self): | |
398 # Test creating a policy attribute term-definition pair. | |
399 self.writer._AddPolicyAttribute( | |
400 self.doc_root, 'bla', 'hello, world', ['key1']) | |
401 self.assertEquals( | |
402 self.doc_root.toxml(), | |
403 '<root>' | |
404 '<dt style="style_dt;">_test_bla</dt>' | |
405 '<dd style="style1;">hello, world</dd>' | |
406 '</root>') | |
407 | |
408 def testAddPolicyDetails(self): | |
409 # Test if the definition list (<dl>) of policy details is created correctly. | |
410 policy = { | |
411 'type': 'main', | |
412 'name': 'TestPolicyName', | |
413 'caption': 'TestPolicyCaption', | |
414 'desc': 'TestPolicyDesc', | |
415 'supported_on': [{ | |
416 'product': 'chrome', | |
417 'platforms': ['win', 'mac', 'linux'], | |
418 'since_version': '8', | |
419 'until_version': '', | |
420 }, { | |
421 'product': 'chrome', | |
422 'platforms': ['android'], | |
423 'since_version': '30', | |
424 'until_version': '', | |
425 }, { | |
426 'product': 'webview', | |
427 'platforms': ['android'], | |
428 'since_version': '47', | |
429 'until_version': '', | |
430 }, { | |
431 'product': 'chrome', | |
432 'platforms': ['ios'], | |
433 'since_version': '34', | |
434 'until_version': '', | |
435 }], | |
436 'features': {'dynamic_refresh': False}, | |
437 'example_value': False | |
438 } | |
439 self.writer.messages['doc_since_version'] = {'text': '...$6...'} | |
440 self.writer._AddPolicyDetails(self.doc_root, policy) | |
441 self.assertEquals( | |
442 self.doc_root.toxml(), | |
443 '<root><dl>' | |
444 '<dt style="style_dt;">_test_data_type</dt>' | |
445 '<dd>Boolean [Windows:REG_DWORD]</dd>' | |
446 '<dt style="style_dt;">_test_win_reg_loc</dt>' | |
447 '<dd style="style_.monospace;">MockKey\TestPolicyName</dd>' | |
448 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' | |
449 '<dd style="style_.monospace;">TestPolicyName</dd>' | |
450 '<dt style="style_dt;">_test_android_restriction_name</dt>' | |
451 '<dd style="style_.monospace;">TestPolicyName</dd>' | |
452 '<dt style="style_dt;">_test_android_webview_restriction_name</dt>' | |
453 '<dd style="style_.monospace;">mock.prefix:TestPolicyName</dd>' | |
454 '<dt style="style_dt;">_test_supported_on</dt>' | |
455 '<dd>' | |
456 '<ul style="style_ul;">' | |
457 '<li>Chrome (Windows, Mac, Linux) ...8...</li>' | |
458 '<li>Chrome (Android) ...30...</li>' | |
459 '<li>WebView (Android) ...47...</li>' | |
460 '<li>Chrome (iOS) ...34...</li>' | |
461 '</ul>' | |
462 '</dd>' | |
463 '<dt style="style_dt;">_test_supported_features</dt>' | |
464 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
465 '<dt style="style_dt;">_test_description</dt><dd><p>TestPolicyDesc</p></dd
>' | |
466 '<dt style="style_dt;">_test_example_value</dt>' | |
467 '<dd>0x00000000 (Windows), false (Linux),' | |
468 ' false (Android), <false /> (Mac)</dd>' | |
469 '</dl></root>') | |
470 | |
471 def testAddDictPolicyDetails(self): | |
472 # Test if the definition list (<dl>) of policy details is created correctly | |
473 # for 'dict' policies. | |
474 policy = { | |
475 'type': 'dict', | |
476 'name': 'TestPolicyName', | |
477 'caption': 'TestPolicyCaption', | |
478 'desc': 'TestPolicyDesc', | |
479 'supported_on': [{ | |
480 'product': 'chrome', | |
481 'platforms': ['win', 'mac', 'linux'], | |
482 'since_version': '8', | |
483 'until_version': '', | |
484 }], | |
485 'features': {'dynamic_refresh': False}, | |
486 'example_value': { 'foo': 123 } | |
487 } | |
488 self.writer.messages['doc_since_version'] = {'text': '...$6...'} | |
489 self.writer._AddPolicyDetails(self.doc_root, policy) | |
490 self.assertEquals( | |
491 self.doc_root.toxml(), | |
492 '<root><dl>' | |
493 '<dt style="style_dt;">_test_data_type</dt>' | |
494 '<dd>Dictionary [Windows:REG_SZ] (_test_complex_policies_win)</dd>' | |
495 '<dt style="style_dt;">_test_win_reg_loc</dt>' | |
496 '<dd style="style_.monospace;">MockKey\TestPolicyName</dd>' | |
497 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' | |
498 '<dd style="style_.monospace;">TestPolicyName</dd>' | |
499 '<dt style="style_dt;">_test_supported_on</dt>' | |
500 '<dd>' | |
501 '<ul style="style_ul;">' | |
502 '<li>Chrome (Windows, Mac, Linux) ...8...</li>' | |
503 '</ul>' | |
504 '</dd>' | |
505 '<dt style="style_dt;">_test_supported_features</dt>' | |
506 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
507 '<dt style="style_dt;">_test_description</dt><dd><p>TestPolicyDesc</p></dd
>' | |
508 '<dt style="style_dt;">_test_example_value</dt>' | |
509 '<dd>' | |
510 '<dl style="style_dd dl;">' | |
511 '<dt>Windows:</dt>' | |
512 '<dd style="style_.monospace;style_.pre;">MockKey\TestPolicyName = {
"foo": 123}</dd>' | |
513 '<dt>Android/Linux:</dt>' | |
514 '<dd style="style_.monospace;">TestPolicyName: {"foo": 123
}</dd>' | |
515 '<dt>Mac:</dt>' | |
516 '<dd style="style_.monospace;style_.pre;">' | |
517 '<key>TestPolicyName</key>\n' | |
518 '<dict>\n' | |
519 ' <key>foo</key>\n' | |
520 ' <integer>123</integer>\n' | |
521 '</dict>' | |
522 '</dd>' | |
523 '</dl>' | |
524 '</dd>' | |
525 '</dl></root>') | |
526 | |
527 def testAddPolicyDetailsRecommendedOnly(self): | |
528 policy = { | |
529 'type': 'main', | |
530 'name': 'TestPolicyName', | |
531 'caption': 'TestPolicyCaption', | |
532 'desc': 'TestPolicyDesc', | |
533 'supported_on': [{ | |
534 'product': 'chrome', | |
535 'platforms': ['win', 'mac', 'linux'], | |
536 'since_version': '8', | |
537 'until_version': '', | |
538 }, { | |
539 'product': 'chrome', | |
540 'platforms': ['android'], | |
541 'since_version': '30', | |
542 'until_version': '', | |
543 }, { | |
544 'product': 'chrome', | |
545 'platforms': ['ios'], | |
546 'since_version': '34', | |
547 'until_version': '', | |
548 }], | |
549 'features': { | |
550 'dynamic_refresh': False, | |
551 'can_be_mandatory': False, | |
552 'can_be_recommended': True | |
553 }, | |
554 'example_value': False | |
555 } | |
556 self.writer.messages['doc_since_version'] = {'text': '...$6...'} | |
557 self.writer._AddPolicyDetails(self.doc_root, policy) | |
558 self.assertEquals( | |
559 self.doc_root.toxml(), | |
560 '<root><dl>' | |
561 '<dt style="style_dt;">_test_data_type</dt>' | |
562 '<dd>Boolean [Windows:REG_DWORD]</dd>' | |
563 '<dt style="style_dt;">_test_win_reg_loc</dt>' | |
564 '<dd style="style_.monospace;">MockKeyRec\TestPolicyName</dd>' | |
565 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' | |
566 '<dd style="style_.monospace;">TestPolicyName</dd>' | |
567 '<dt style="style_dt;">_test_android_restriction_name</dt>' | |
568 '<dd style="style_.monospace;">TestPolicyName</dd>' | |
569 '<dt style="style_dt;">_test_supported_on</dt>' | |
570 '<dd>' | |
571 '<ul style="style_ul;">' | |
572 '<li>Chrome (Windows, Mac, Linux) ...8...</li>' | |
573 '<li>Chrome (Android) ...30...</li>' | |
574 '<li>Chrome (iOS) ...34...</li>' | |
575 '</ul>' | |
576 '</dd>' | |
577 '<dt style="style_dt;">_test_supported_features</dt>' | |
578 '<dd>_test_feature_mandatory: _test_not_supported,' | |
579 ' _test_feature_recommended: _test_supported,' | |
580 ' _test_feature_dynamic_refresh: _test_not_supported</dd>' | |
581 '<dt style="style_dt;">_test_description</dt><dd><p>TestPolicyDesc</p></dd
>' | |
582 '<dt style="style_dt;">_test_example_value</dt>' | |
583 '<dd>0x00000000 (Windows), false (Linux),' | |
584 ' false (Android), <false /> (Mac)</dd>' | |
585 '</dl></root>') | |
586 | |
587 def testAddPolicyNote(self): | |
588 # TODO(jkummerow): The functionality tested by this test is currently not | |
589 # used for anything and will probably soon be removed. | |
590 # Test if nodes are correctly added to policies. | |
591 policy = { | |
592 'problem_href': 'http://www.example.com/5' | |
593 } | |
594 self.writer.messages['doc_note'] = {'text': '...$6...'} | |
595 self.writer._AddPolicyNote(self.doc_root, policy) | |
596 self.assertEquals( | |
597 self.doc_root.toxml(), | |
598 '<root><div style="style_div.note;"><p>...' | |
599 '<a href="http://www.example.com/5">http://www.example.com/5</a>' | |
600 '...</p></div></root>') | |
601 | |
602 def testAddPolicyRow(self): | |
603 # Test if policies are correctly added to the summary table. | |
604 policy = { | |
605 'name': 'PolicyName', | |
606 'caption': 'PolicyCaption', | |
607 'type': 'string', | |
608 } | |
609 self.writer._indent_level = 3 | |
610 self.writer._AddPolicyRow(self.doc_root, policy) | |
611 self.assertEquals( | |
612 self.doc_root.toxml(), | |
613 '<root><tr style="style_tr;">' | |
614 '<td style="style_td;style_td.left;padding-left: 49px;">' | |
615 '<a href="#PolicyName">PolicyName</a>' | |
616 '</td>' | |
617 '<td style="style_td;style_td.right;">PolicyCaption</td>' | |
618 '</tr></root>') | |
619 self.setUp() | |
620 policy = { | |
621 'name': 'PolicyName', | |
622 'caption': 'PolicyCaption', | |
623 'type': 'group', | |
624 } | |
625 self.writer._indent_level = 2 | |
626 self.writer._AddPolicyRow(self.doc_root, policy) | |
627 self.assertEquals( | |
628 self.doc_root.toxml(), | |
629 '<root><tr style="style_tr;">' | |
630 '<td colspan="2" style="style_td;style_td.left;padding-left: 35px;">' | |
631 '<a href="#PolicyName">PolicyCaption</a>' | |
632 '</td>' | |
633 '</tr></root>') | |
634 | |
635 def testAddPolicySection(self): | |
636 # Test if policy details are correctly added to the document. | |
637 policy = { | |
638 'name': 'PolicyName', | |
639 'caption': 'PolicyCaption', | |
640 'desc': 'PolicyDesc', | |
641 'type': 'string', | |
642 'supported_on': [{ | |
643 'product': 'chrome', | |
644 'platforms': ['win', 'mac'], | |
645 'since_version': '7', | |
646 'until_version': '', | |
647 }], | |
648 'features': {'dynamic_refresh': False}, | |
649 'example_value': 'False' | |
650 } | |
651 self.writer.messages['doc_since_version'] = {'text': '..$6..'} | |
652 self.writer._AddPolicySection(self.doc_root, policy) | |
653 self.assertEquals( | |
654 self.doc_root.toxml(), | |
655 '<root>' | |
656 '<div style="margin-left: 0px">' | |
657 '<h3><a name="PolicyName"/>PolicyName</h3>' | |
658 '<span>PolicyCaption</span>' | |
659 '<dl>' | |
660 '<dt style="style_dt;">_test_data_type</dt>' | |
661 '<dd>String [Windows:REG_SZ]</dd>' | |
662 '<dt style="style_dt;">_test_win_reg_loc</dt>' | |
663 '<dd style="style_.monospace;">MockKey\\PolicyName</dd>' | |
664 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' | |
665 '<dd style="style_.monospace;">PolicyName</dd>' | |
666 '<dt style="style_dt;">_test_supported_on</dt>' | |
667 '<dd>' | |
668 '<ul style="style_ul;">' | |
669 '<li>Chrome (Windows, Mac) ..7..</li>' | |
670 '</ul>' | |
671 '</dd>' | |
672 '<dt style="style_dt;">_test_supported_features</dt>' | |
673 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
674 '<dt style="style_dt;">_test_description</dt>' | |
675 '<dd><p>PolicyDesc</p></dd>' | |
676 '<dt style="style_dt;">_test_example_value</dt>' | |
677 '<dd>"False"</dd>' | |
678 '</dl>' | |
679 '<a href="#top">_test_back_to_top</a>' | |
680 '</div>' | |
681 '</root>') | |
682 # Test for groups. | |
683 self.setUp() | |
684 policy['type'] = 'group' | |
685 self.writer._AddPolicySection(self.doc_root, policy) | |
686 self.assertEquals( | |
687 self.doc_root.toxml(), | |
688 '<root>' | |
689 '<div style="margin-left: 0px">' | |
690 '<h2><a name="PolicyName"/>PolicyCaption</h2>' | |
691 '<div style="style_div.group_desc;">PolicyDesc</div>' | |
692 '<a href="#top">_test_back_to_top</a>' | |
693 '</div>' | |
694 '</root>') | |
695 | |
696 def testAddPolicySectionForWindowsOnly(self): | |
697 policy = { | |
698 'name': 'PolicyName', | |
699 'caption': 'PolicyCaption', | |
700 'desc': 'PolicyDesc', | |
701 'type': 'int', | |
702 'supported_on': [{ | |
703 'product': 'chrome', | |
704 'platforms': ['win'], | |
705 'since_version': '33', | |
706 'until_version': '', | |
707 }], | |
708 'features': {'dynamic_refresh': False}, | |
709 'example_value': 123 | |
710 } | |
711 self.writer.messages['doc_since_version'] = {'text': '..$6..'} | |
712 self.writer._AddPolicySection(self.doc_root, policy) | |
713 self.assertEquals( | |
714 self.doc_root.toxml(), | |
715 '<root>' | |
716 '<div style="margin-left: 0px">' | |
717 '<h3><a name="PolicyName"/>PolicyName</h3>' | |
718 '<span>PolicyCaption</span>' | |
719 '<dl>' | |
720 '<dt style="style_dt;">_test_data_type</dt>' | |
721 '<dd>Integer [Windows:REG_DWORD]</dd>' | |
722 '<dt style="style_dt;">_test_win_reg_loc</dt>' | |
723 '<dd style="style_.monospace;">MockKey\\PolicyName</dd>' | |
724 '<dt style="style_dt;">_test_supported_on</dt>' | |
725 '<dd>' | |
726 '<ul style="style_ul;">' | |
727 '<li>Chrome (Windows) ..33..</li>' | |
728 '</ul>' | |
729 '</dd>' | |
730 '<dt style="style_dt;">_test_supported_features</dt>' | |
731 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
732 '<dt style="style_dt;">_test_description</dt>' | |
733 '<dd><p>PolicyDesc</p></dd>' | |
734 '<dt style="style_dt;">_test_example_value</dt>' | |
735 '<dd>0x0000007b (Windows)</dd>' | |
736 '</dl>' | |
737 '<a href="#top">_test_back_to_top</a>' | |
738 '</div>' | |
739 '</root>') | |
740 | |
741 def testAddPolicySectionForMacOnly(self): | |
742 policy = { | |
743 'name': 'PolicyName', | |
744 'caption': 'PolicyCaption', | |
745 'desc': 'PolicyDesc', | |
746 'type': 'int', | |
747 'supported_on': [{ | |
748 'product': 'chrome', | |
749 'platforms': ['mac'], | |
750 'since_version': '33', | |
751 'until_version': '', | |
752 }], | |
753 'features': {'dynamic_refresh': False}, | |
754 'example_value': 123 | |
755 } | |
756 self.writer.messages['doc_since_version'] = {'text': '..$6..'} | |
757 self.writer._AddPolicySection(self.doc_root, policy) | |
758 self.assertEquals( | |
759 self.doc_root.toxml(), | |
760 '<root>' | |
761 '<div style="margin-left: 0px">' | |
762 '<h3><a name="PolicyName"/>PolicyName</h3>' | |
763 '<span>PolicyCaption</span>' | |
764 '<dl>' | |
765 '<dt style="style_dt;">_test_data_type</dt>' | |
766 '<dd>Integer</dd>' | |
767 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' | |
768 '<dd style="style_.monospace;">PolicyName</dd>' | |
769 '<dt style="style_dt;">_test_supported_on</dt>' | |
770 '<dd>' | |
771 '<ul style="style_ul;">' | |
772 '<li>Chrome (Mac) ..33..</li>' | |
773 '</ul>' | |
774 '</dd>' | |
775 '<dt style="style_dt;">_test_supported_features</dt>' | |
776 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
777 '<dt style="style_dt;">_test_description</dt>' | |
778 '<dd><p>PolicyDesc</p></dd>' | |
779 '<dt style="style_dt;">_test_example_value</dt>' | |
780 '<dd>123 (Mac)</dd>' | |
781 '</dl>' | |
782 '<a href="#top">_test_back_to_top</a>' | |
783 '</div>' | |
784 '</root>') | |
785 | |
786 def testAddPolicySectionForLinuxOnly(self): | |
787 policy = { | |
788 'name': 'PolicyName', | |
789 'caption': 'PolicyCaption', | |
790 'desc': 'PolicyDesc', | |
791 'type': 'int', | |
792 'supported_on': [{ | |
793 'product': 'chrome', | |
794 'platforms': ['linux'], | |
795 'since_version': '33', | |
796 'until_version': '', | |
797 }], | |
798 'features': {'dynamic_refresh': False}, | |
799 'example_value': 123 | |
800 } | |
801 self.writer.messages['doc_since_version'] = {'text': '..$6..'} | |
802 self.writer._AddPolicySection(self.doc_root, policy) | |
803 self.assertEquals( | |
804 self.doc_root.toxml(), | |
805 '<root>' | |
806 '<div style="margin-left: 0px">' | |
807 '<h3><a name="PolicyName"/>PolicyName</h3>' | |
808 '<span>PolicyCaption</span>' | |
809 '<dl>' | |
810 '<dt style="style_dt;">_test_data_type</dt>' | |
811 '<dd>Integer</dd>' | |
812 '<dt style="style_dt;">_test_mac_linux_pref_name</dt>' | |
813 '<dd style="style_.monospace;">PolicyName</dd>' | |
814 '<dt style="style_dt;">_test_supported_on</dt>' | |
815 '<dd>' | |
816 '<ul style="style_ul;">' | |
817 '<li>Chrome (Linux) ..33..</li>' | |
818 '</ul>' | |
819 '</dd>' | |
820 '<dt style="style_dt;">_test_supported_features</dt>' | |
821 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
822 '<dt style="style_dt;">_test_description</dt>' | |
823 '<dd><p>PolicyDesc</p></dd>' | |
824 '<dt style="style_dt;">_test_example_value</dt>' | |
825 '<dd>123 (Linux)</dd>' | |
826 '</dl>' | |
827 '<a href="#top">_test_back_to_top</a>' | |
828 '</div>' | |
829 '</root>') | |
830 | |
831 def testAddPolicySectionForAndroidOnly(self): | |
832 policy = { | |
833 'name': 'PolicyName', | |
834 'caption': 'PolicyCaption', | |
835 'desc': 'PolicyDesc', | |
836 'type': 'int', | |
837 'supported_on': [{ | |
838 'product': 'chrome', | |
839 'platforms': ['android'], | |
840 'since_version': '33', | |
841 'until_version': '', | |
842 }], | |
843 'features': {'dynamic_refresh': False}, | |
844 'example_value': 123 | |
845 } | |
846 self.writer.messages['doc_since_version'] = {'text': '..$6..'} | |
847 self.writer._AddPolicySection(self.doc_root, policy) | |
848 self.assertTrue(self.writer.IsPolicySupportedOnPlatform(policy, 'android')) | |
849 self.assertEquals( | |
850 self.doc_root.toxml(), | |
851 '<root>' | |
852 '<div style="margin-left: 0px">' | |
853 '<h3><a name="PolicyName"/>PolicyName</h3>' | |
854 '<span>PolicyCaption</span>' | |
855 '<dl>' | |
856 '<dt style="style_dt;">_test_data_type</dt>' | |
857 '<dd>Integer</dd>' | |
858 '<dt style="style_dt;">_test_android_restriction_name</dt>' | |
859 '<dd style="style_.monospace;">PolicyName</dd>' | |
860 '<dt style="style_dt;">_test_supported_on</dt>' | |
861 '<dd>' | |
862 '<ul style="style_ul;">' | |
863 '<li>Chrome (Android) ..33..</li>' | |
864 '</ul>' | |
865 '</dd>' | |
866 '<dt style="style_dt;">_test_supported_features</dt>' | |
867 '<dd>_test_feature_dynamic_refresh: _test_not_supported</dd>' | |
868 '<dt style="style_dt;">_test_description</dt>' | |
869 '<dd><p>PolicyDesc</p></dd>' | |
870 '<dt style="style_dt;">_test_example_value</dt>' | |
871 '<dd>123 (Android)</dd>' | |
872 '</dl>' | |
873 '<a href="#top">_test_back_to_top</a>' | |
874 '</div>' | |
875 '</root>') | |
876 | |
877 def testAddDictionaryExample(self): | |
878 policy = { | |
879 'name': 'PolicyName', | |
880 'caption': 'PolicyCaption', | |
881 'desc': 'PolicyDesc', | |
882 'type': 'dict', | |
883 'supported_on': [{ | |
884 'product': 'chrome', | |
885 'platforms': ['win', 'mac', 'linux'], | |
886 'since_version': '7', | |
887 'until_version': '', | |
888 }], | |
889 'features': {'dynamic_refresh': False}, | |
890 'example_value': { | |
891 "ProxyMode": "direct", | |
892 "List": ["1", "2", "3"], | |
893 "True": True, | |
894 "False": False, | |
895 "Integer": 123, | |
896 "DictList": [ { | |
897 "A": 1, | |
898 "B": 2, | |
899 }, { | |
900 "C": 3, | |
901 "D": 4, | |
902 }, | |
903 ], | |
904 }, | |
905 } | |
906 self.writer._AddDictionaryExample(self.doc_root, policy) | |
907 value = json.dumps(policy['example_value']).replace('"', '"') | |
908 self.assertEquals( | |
909 self.doc_root.toxml(), | |
910 '<root>' | |
911 '<dl style="style_dd dl;">' | |
912 '<dt>Windows:</dt>' | |
913 '<dd style="style_.monospace;style_.pre;">MockKey\PolicyName = ' | |
914 + value + | |
915 '</dd>' | |
916 '<dt>Android/Linux:</dt>' | |
917 '<dd style="style_.monospace;">PolicyName: ' + value + '</dd>' | |
918 '<dt>Mac:</dt>' | |
919 '<dd style="style_.monospace;style_.pre;">' | |
920 '<key>PolicyName</key>\n' | |
921 '<dict>\n' | |
922 ' <key>DictList</key>\n' | |
923 ' <array>\n' | |
924 ' <dict>\n' | |
925 ' <key>A</key>\n' | |
926 ' <integer>1</integer>\n' | |
927 ' <key>B</key>\n' | |
928 ' <integer>2</integer>\n' | |
929 ' </dict>\n' | |
930 ' <dict>\n' | |
931 ' <key>C</key>\n' | |
932 ' <integer>3</integer>\n' | |
933 ' <key>D</key>\n' | |
934 ' <integer>4</integer>\n' | |
935 ' </dict>\n' | |
936 ' </array>\n' | |
937 ' <key>False</key>\n' | |
938 ' <false/>\n' | |
939 ' <key>Integer</key>\n' | |
940 ' <integer>123</integer>\n' | |
941 ' <key>List</key>\n' | |
942 ' <array>\n' | |
943 ' <string>1</string>\n' | |
944 ' <string>2</string>\n' | |
945 ' <string>3</string>\n' | |
946 ' </array>\n' | |
947 ' <key>ProxyMode</key>\n' | |
948 ' <string>direct</string>\n' | |
949 ' <key>True</key>\n' | |
950 ' <true/>\n' | |
951 '</dict>' | |
952 '</dd>' | |
953 '</dl>' | |
954 '</root>') | |
955 | |
956 def testParagraphs(self): | |
957 text = 'Paragraph 1\n\nParagraph 2\n\nParagraph 3' | |
958 self.writer._AddParagraphs(self.doc_root, text) | |
959 self.assertEquals( | |
960 self.doc_root.toxml(), | |
961 '<root><p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p></root>') | |
962 | |
963 if __name__ == '__main__': | |
964 unittest.main() | |
OLD | NEW |