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

Side by Side Diff: grit/format/policy_templates/writers/doc_writer_unittest.py

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

Powered by Google App Engine
This is Rietveld 408576698