Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2015 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.android_policy_writer''' | |
| 7 | |
| 8 | |
| 9 import os | |
| 10 import sys | |
| 11 if __name__ == '__main__': | |
| 12 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | |
| 13 | |
| 14 import unittest | |
| 15 from xml.dom import minidom | |
| 16 | |
| 17 from grit.format.policy_templates.writers import writer_unittest_common | |
| 18 from grit.format.policy_templates.writers import android_policy_writer | |
| 19 | |
| 20 class AndroidPolicyWriterUnittest(writer_unittest_common.WriterUnittestCommon): | |
|
Nico
2015/03/02 19:02:06
nit: two newlines
knn
2015/03/02 19:54:35
Done.
| |
| 21 '''Unit tests to test assumptions in Android Policy Writer''' | |
| 22 | |
| 23 def testPolicyWithoutItems(self): | |
| 24 # Test an example policy without items. | |
| 25 policy = { | |
| 26 'name': '_policy_name', | |
| 27 'caption': '_policy_caption', | |
| 28 'desc': 'This is a long policy caption. More than one sentence in a single line because it is very important.\nIgnore this.' | |
| 29 } | |
| 30 writer = android_policy_writer.GetWriter({}) | |
| 31 writer.Init() | |
| 32 writer.BeginTemplate() | |
| 33 writer.WritePolicy(policy) | |
| 34 self.assertEquals( | |
| 35 writer._resources.toxml(), | |
| 36 '<resources>' | |
| 37 '<string name="_policy_nameTitle">_policy_caption</string>' | |
| 38 '<string name="_policy_nameDesc">This is a long policy caption.' | |
| 39 ' More than one sentence in a single line because it is very important.< /string>' | |
| 40 '</resources>') | |
| 41 | |
| 42 def testPolicyWithItems(self): | |
| 43 # Test an example policy without items. | |
| 44 policy = { | |
| 45 'name': '_policy_name', | |
| 46 'caption': '_policy_caption', | |
| 47 'desc': '_policy_desc_first.\n_ignored_policy_desc', | |
| 48 'items': [ | |
| 49 { | |
| 50 'caption':'_caption1', | |
| 51 'value':'_value1', | |
| 52 }, | |
| 53 { | |
| 54 'caption':'_caption2', | |
| 55 'value':'_value2', | |
| 56 } | |
| 57 ] | |
| 58 } | |
| 59 writer = android_policy_writer.GetWriter({}) | |
| 60 writer.Init() | |
| 61 writer.BeginTemplate() | |
| 62 writer.WritePolicy(policy) | |
| 63 self.assertEquals( | |
| 64 writer._resources.toxml(), | |
| 65 '<resources>' | |
| 66 '<string name="_policy_nameTitle">_policy_caption</string>' | |
| 67 '<string name="_policy_nameDesc">_policy_desc_first.</string>' | |
| 68 '<string-array name="_policy_nameEntries">' | |
| 69 '<item>_caption1</item>' | |
| 70 '<item>_caption2</item>' | |
| 71 '</string-array>' | |
| 72 '<string-array name="_policy_nameValues">' | |
| 73 '<item>_value1</item>' | |
| 74 '<item>_value2</item>' | |
| 75 '</string-array>' | |
| 76 '</resources>') | |
| 77 | |
| 78 if __name__ == '__main__': | |
| 79 unittest.main() | |
| OLD | NEW |