OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Unit tests for grit.format.policy_templates.writers.plist_strings_writer''' |
| 7 |
| 8 |
| 9 import os |
| 10 import sys |
| 11 if __name__ == '__main__': |
| 12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../..')) |
| 13 |
| 14 import tempfile |
| 15 import unittest |
| 16 import StringIO |
| 17 |
| 18 from grit.format.policy_templates.writers import writer_unittest_common |
| 19 from grit import grd_reader |
| 20 from grit import util |
| 21 from grit.tool import build |
| 22 |
| 23 |
| 24 class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): |
| 25 '''Unit tests for PListStringsWriter.''' |
| 26 |
| 27 def testEmpty(self): |
| 28 # Test PListStringsWriter in case of empty polices. |
| 29 grd = self.PrepareTest(''' |
| 30 { |
| 31 'policy_definitions': [], |
| 32 'placeholders': [], |
| 33 'messages': { |
| 34 'mac_chrome_preferences': { |
| 35 'text': '$1 preferen"ces', |
| 36 'desc': 'blah' |
| 37 } |
| 38 } |
| 39 }''') |
| 40 output = self.GetOutput( |
| 41 grd, |
| 42 'fr', |
| 43 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, |
| 44 'plist_strings', |
| 45 'en') |
| 46 expected_output = ( |
| 47 'Chromium.pfm_title = "Chromium";\n' |
| 48 'Chromium.pfm_description = "Chromium preferen\\"ces";') |
| 49 self.assertEquals(output.strip(), expected_output.strip()) |
| 50 |
| 51 def testMainPolicy(self): |
| 52 # Tests a policy group with a single policy of type 'main'. |
| 53 grd = self.PrepareTest(''' |
| 54 { |
| 55 'policy_definitions': [ |
| 56 { |
| 57 'name': 'MainGroup', |
| 58 'type': 'group', |
| 59 'caption': 'Caption of main.', |
| 60 'desc': 'Description of main.', |
| 61 'policies': [{ |
| 62 'name': 'MainPolicy', |
| 63 'type': 'main', |
| 64 'supported_on': ['chrome.mac:8-'], |
| 65 'caption': 'Caption of main policy.', |
| 66 'desc': 'Description of main policy.', |
| 67 }], |
| 68 }, |
| 69 ], |
| 70 'placeholders': [], |
| 71 'messages': { |
| 72 'mac_chrome_preferences': { |
| 73 'text': 'Preferences of $1', |
| 74 'desc': 'blah' |
| 75 } |
| 76 } |
| 77 }''') |
| 78 output = self.GetOutput( |
| 79 grd, |
| 80 'fr', |
| 81 {'_google_chrome' : '1', 'mac_bundle_id': 'com.example.Test'}, |
| 82 'plist_strings', |
| 83 'en') |
| 84 expected_output = ( |
| 85 'Google_Chrome.pfm_title = "Google Chrome";\n' |
| 86 'Google_Chrome.pfm_description = "Preferences of Google Chrome";\n' |
| 87 'MainPolicy.pfm_title = "Caption of main policy.";\n' |
| 88 'MainPolicy.pfm_description = "Description of main policy.";') |
| 89 self.assertEquals(output.strip(), expected_output.strip()) |
| 90 |
| 91 def testStringPolicy(self): |
| 92 # Tests a policy group with a single policy of type 'string'. Also test |
| 93 # inheriting group description to policy description. |
| 94 grd = self.PrepareTest(''' |
| 95 { |
| 96 'policy_definitions': [ |
| 97 { |
| 98 'name': 'StringGroup', |
| 99 'type': 'group', |
| 100 'caption': 'Caption of group.', |
| 101 'desc': """Description of group. |
| 102 With a newline.""", |
| 103 'policies': [{ |
| 104 'name': 'StringPolicy', |
| 105 'type': 'string', |
| 106 'caption': 'Caption of policy.', |
| 107 'desc': """Description of policy. |
| 108 With a newline.""", |
| 109 'supported_on': ['chrome.mac:8-'], |
| 110 }], |
| 111 }, |
| 112 ], |
| 113 'placeholders': [], |
| 114 'messages': { |
| 115 'mac_chrome_preferences': { |
| 116 'text': 'Preferences of $1', |
| 117 'desc': 'blah' |
| 118 } |
| 119 } |
| 120 }''') |
| 121 output = self.GetOutput( |
| 122 grd, |
| 123 'fr', |
| 124 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, |
| 125 'plist_strings', |
| 126 'en') |
| 127 expected_output = ( |
| 128 'Chromium.pfm_title = "Chromium";\n' |
| 129 'Chromium.pfm_description = "Preferences of Chromium";\n' |
| 130 'StringPolicy.pfm_title = "Caption of policy.";\n' |
| 131 'StringPolicy.pfm_description = ' |
| 132 '"Description of policy.\\nWith a newline.";') |
| 133 self.assertEquals(output.strip(), expected_output.strip()) |
| 134 |
| 135 def testIntEnumPolicy(self): |
| 136 # Tests a policy group with a single policy of type 'int-enum'. |
| 137 grd = self.PrepareTest(''' |
| 138 { |
| 139 'policy_definitions': [ |
| 140 { |
| 141 'name': 'EnumGroup', |
| 142 'type': 'group', |
| 143 'desc': '', |
| 144 'caption': '', |
| 145 'policies': [{ |
| 146 'name': 'EnumPolicy', |
| 147 'type': 'int-enum', |
| 148 'desc': 'Description of policy.', |
| 149 'caption': 'Caption of policy.', |
| 150 'items': [ |
| 151 { |
| 152 'name': 'ProxyServerDisabled', |
| 153 'value': 0, |
| 154 'caption': 'Option1' |
| 155 }, |
| 156 { |
| 157 'name': 'ProxyServerAutoDetect', |
| 158 'value': 1, |
| 159 'caption': 'Option2' |
| 160 }, |
| 161 ], |
| 162 'supported_on': ['chrome.mac:8-'], |
| 163 }], |
| 164 }, |
| 165 ], |
| 166 'placeholders': [], |
| 167 'messages': { |
| 168 'mac_chrome_preferences': { |
| 169 'text': '$1 preferences', |
| 170 'desc': 'blah' |
| 171 } |
| 172 } |
| 173 }''') |
| 174 output = self.GetOutput( |
| 175 grd, |
| 176 'fr', |
| 177 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, |
| 178 'plist_strings', |
| 179 'en') |
| 180 expected_output = ( |
| 181 'Google_Chrome.pfm_title = "Google Chrome";\n' |
| 182 'Google_Chrome.pfm_description = "Google Chrome preferences";\n' |
| 183 'EnumPolicy.pfm_title = "Caption of policy.";\n' |
| 184 'EnumPolicy.pfm_description = ' |
| 185 '"0 - Option1\\n1 - Option2\\nDescription of policy.";\n') |
| 186 |
| 187 self.assertEquals(output.strip(), expected_output.strip()) |
| 188 |
| 189 def testStringEnumPolicy(self): |
| 190 # Tests a policy group with a single policy of type 'string-enum'. |
| 191 grd = self.PrepareTest(''' |
| 192 { |
| 193 'policy_definitions': [ |
| 194 { |
| 195 'name': 'EnumGroup', |
| 196 'type': 'group', |
| 197 'desc': '', |
| 198 'caption': '', |
| 199 'policies': [{ |
| 200 'name': 'EnumPolicy', |
| 201 'type': 'string-enum', |
| 202 'desc': 'Description of policy.', |
| 203 'caption': 'Caption of policy.', |
| 204 'items': [ |
| 205 { |
| 206 'name': 'ProxyServerDisabled', |
| 207 'value': 'one', |
| 208 'caption': 'Option1' |
| 209 }, |
| 210 { |
| 211 'name': 'ProxyServerAutoDetect', |
| 212 'value': 'two', |
| 213 'caption': 'Option2' |
| 214 }, |
| 215 ], |
| 216 'supported_on': ['chrome.mac:8-'], |
| 217 }], |
| 218 }, |
| 219 ], |
| 220 'placeholders': [], |
| 221 'messages': { |
| 222 'mac_chrome_preferences': { |
| 223 'text': '$1 preferences', |
| 224 'desc': 'blah' |
| 225 } |
| 226 } |
| 227 }''') |
| 228 output = self.GetOutput( |
| 229 grd, |
| 230 'fr', |
| 231 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, |
| 232 'plist_strings', |
| 233 'en') |
| 234 expected_output = ( |
| 235 'Google_Chrome.pfm_title = "Google Chrome";\n' |
| 236 'Google_Chrome.pfm_description = "Google Chrome preferences";\n' |
| 237 'EnumPolicy.pfm_title = "Caption of policy.";\n' |
| 238 'EnumPolicy.pfm_description = ' |
| 239 '"one - Option1\\ntwo - Option2\\nDescription of policy.";\n') |
| 240 |
| 241 self.assertEquals(output.strip(), expected_output.strip()) |
| 242 |
| 243 def testNonSupportedPolicy(self): |
| 244 # Tests a policy that is not supported on Mac, so its strings shouldn't |
| 245 # be included in the plist string table. |
| 246 grd = self.PrepareTest(''' |
| 247 { |
| 248 'policy_definitions': [ |
| 249 { |
| 250 'name': 'NonMacGroup', |
| 251 'type': 'group', |
| 252 'caption': '', |
| 253 'desc': '', |
| 254 'policies': [{ |
| 255 'name': 'NonMacPolicy', |
| 256 'type': 'string', |
| 257 'caption': '', |
| 258 'desc': '', |
| 259 'supported_on': ['chrome_os:8-'], |
| 260 }], |
| 261 }, |
| 262 ], |
| 263 'placeholders': [], |
| 264 'messages': { |
| 265 'mac_chrome_preferences': { |
| 266 'text': '$1 preferences', |
| 267 'desc': 'blah' |
| 268 } |
| 269 } |
| 270 }''') |
| 271 output = self.GetOutput( |
| 272 grd, |
| 273 'fr', |
| 274 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, |
| 275 'plist_strings', |
| 276 'en') |
| 277 expected_output = ( |
| 278 'Google_Chrome.pfm_title = "Google Chrome";\n' |
| 279 'Google_Chrome.pfm_description = "Google Chrome preferences";') |
| 280 self.assertEquals(output.strip(), expected_output.strip()) |
| 281 |
| 282 |
| 283 if __name__ == '__main__': |
| 284 unittest.main() |
OLD | NEW |