| 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.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(__file__), '../../../..')) | |
| 13 | |
| 14 import unittest | |
| 15 | |
| 16 from grit.format.policy_templates.writers import writer_unittest_common | |
| 17 | |
| 18 | |
| 19 class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon): | |
| 20 '''Unit tests for PListStringsWriter.''' | |
| 21 | |
| 22 def testEmpty(self): | |
| 23 # Test PListStringsWriter in case of empty polices. | |
| 24 grd = self.PrepareTest(''' | |
| 25 { | |
| 26 'policy_definitions': [], | |
| 27 'placeholders': [], | |
| 28 'messages': { | |
| 29 'mac_chrome_preferences': { | |
| 30 'text': '$1 preferen"ces', | |
| 31 'desc': 'blah' | |
| 32 } | |
| 33 } | |
| 34 }''') | |
| 35 output = self.GetOutput( | |
| 36 grd, | |
| 37 'fr', | |
| 38 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'}, | |
| 39 'plist_strings', | |
| 40 'en') | |
| 41 expected_output = ( | |
| 42 'Chromium.pfm_title = "Chromium";\n' | |
| 43 'Chromium.pfm_description = "Chromium preferen\\"ces";') | |
| 44 self.assertEquals(output.strip(), expected_output.strip()) | |
| 45 | |
| 46 def testEmptyVersion(self): | |
| 47 # Test PListStringsWriter in case of empty polices. | |
| 48 grd = self.PrepareTest(''' | |
| 49 { | |
| 50 'policy_definitions': [], | |
| 51 'placeholders': [], | |
| 52 'messages': { | |
| 53 'mac_chrome_preferences': { | |
| 54 'text': '$1 preferen"ces', | |
| 55 'desc': 'blah' | |
| 56 } | |
| 57 } | |
| 58 }''') | |
| 59 output = self.GetOutput( | |
| 60 grd, | |
| 61 'fr', | |
| 62 {'_chromium': '1', | |
| 63 'mac_bundle_id': 'com.example.Test', | |
| 64 'version': '39.0.0.0'}, | |
| 65 'plist_strings', | |
| 66 'en') | |
| 67 expected_output = ( | |
| 68 '/* chromium version: 39.0.0.0 */\n' | |
| 69 'Chromium.pfm_title = "Chromium";\n' | |
| 70 'Chromium.pfm_description = "Chromium preferen\\"ces";') | |
| 71 self.assertEquals(output.strip(), expected_output.strip()) | |
| 72 | |
| 73 def testMainPolicy(self): | |
| 74 # Tests a policy group with a single policy of type 'main'. | |
| 75 grd = self.PrepareTest(''' | |
| 76 { | |
| 77 'policy_definitions': [ | |
| 78 { | |
| 79 'name': 'MainGroup', | |
| 80 'type': 'group', | |
| 81 'caption': 'Caption of main.', | |
| 82 'desc': 'Description of main.', | |
| 83 'policies': [{ | |
| 84 'name': 'MainPolicy', | |
| 85 'type': 'main', | |
| 86 'supported_on': ['chrome.mac:8-'], | |
| 87 'caption': 'Caption of main policy.', | |
| 88 'desc': 'Description of main policy.', | |
| 89 }], | |
| 90 }, | |
| 91 ], | |
| 92 'placeholders': [], | |
| 93 'messages': { | |
| 94 'mac_chrome_preferences': { | |
| 95 'text': 'Preferences of $1', | |
| 96 'desc': 'blah' | |
| 97 } | |
| 98 } | |
| 99 }''') | |
| 100 output = self.GetOutput( | |
| 101 grd, | |
| 102 'fr', | |
| 103 {'_google_chrome' : '1', 'mac_bundle_id': 'com.example.Test'}, | |
| 104 'plist_strings', | |
| 105 'en') | |
| 106 expected_output = ( | |
| 107 'Google_Chrome.pfm_title = "Google Chrome";\n' | |
| 108 'Google_Chrome.pfm_description = "Preferences of Google Chrome";\n' | |
| 109 'MainPolicy.pfm_title = "Caption of main policy.";\n' | |
| 110 'MainPolicy.pfm_description = "Description of main policy.";') | |
| 111 self.assertEquals(output.strip(), expected_output.strip()) | |
| 112 | |
| 113 def testStringPolicy(self): | |
| 114 # Tests a policy group with a single policy of type 'string'. Also test | |
| 115 # inheriting group description to policy description. | |
| 116 grd = self.PrepareTest(''' | |
| 117 { | |
| 118 'policy_definitions': [ | |
| 119 { | |
| 120 'name': 'StringGroup', | |
| 121 'type': 'group', | |
| 122 'caption': 'Caption of group.', | |
| 123 'desc': """Description of group. | |
| 124 With a newline.""", | |
| 125 'policies': [{ | |
| 126 'name': 'StringPolicy', | |
| 127 'type': 'string', | |
| 128 'caption': 'Caption of policy.', | |
| 129 'desc': """Description of policy. | |
| 130 With a newline.""", | |
| 131 'supported_on': ['chrome.mac:8-'], | |
| 132 }], | |
| 133 }, | |
| 134 ], | |
| 135 'placeholders': [], | |
| 136 'messages': { | |
| 137 'mac_chrome_preferences': { | |
| 138 'text': 'Preferences of $1', | |
| 139 'desc': 'blah' | |
| 140 } | |
| 141 } | |
| 142 }''') | |
| 143 output = self.GetOutput( | |
| 144 grd, | |
| 145 'fr', | |
| 146 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, | |
| 147 'plist_strings', | |
| 148 'en') | |
| 149 expected_output = ( | |
| 150 'Chromium.pfm_title = "Chromium";\n' | |
| 151 'Chromium.pfm_description = "Preferences of Chromium";\n' | |
| 152 'StringPolicy.pfm_title = "Caption of policy.";\n' | |
| 153 'StringPolicy.pfm_description = ' | |
| 154 '"Description of policy.\\nWith a newline.";') | |
| 155 self.assertEquals(output.strip(), expected_output.strip()) | |
| 156 | |
| 157 def testStringListPolicy(self): | |
| 158 # Tests a policy group with a single policy of type 'list'. | |
| 159 grd = self.PrepareTest(''' | |
| 160 { | |
| 161 'policy_definitions': [ | |
| 162 { | |
| 163 'name': 'ListGroup', | |
| 164 'type': 'group', | |
| 165 'caption': '', | |
| 166 'desc': '', | |
| 167 'policies': [{ | |
| 168 'name': 'ListPolicy', | |
| 169 'type': 'list', | |
| 170 'caption': 'Caption of policy.', | |
| 171 'desc': """Description of policy. | |
| 172 With a newline.""", | |
| 173 'schema': { | |
| 174 'type': 'array', | |
| 175 'items': { 'type': 'string' }, | |
| 176 }, | |
| 177 'supported_on': ['chrome.mac:8-'], | |
| 178 }], | |
| 179 }, | |
| 180 ], | |
| 181 'placeholders': [], | |
| 182 'messages': { | |
| 183 'mac_chrome_preferences': { | |
| 184 'text': 'Preferences of $1', | |
| 185 'desc': 'blah' | |
| 186 } | |
| 187 } | |
| 188 }''') | |
| 189 output = self.GetOutput( | |
| 190 grd, | |
| 191 'fr', | |
| 192 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, | |
| 193 'plist_strings', | |
| 194 'en') | |
| 195 expected_output = ( | |
| 196 'Chromium.pfm_title = "Chromium";\n' | |
| 197 'Chromium.pfm_description = "Preferences of Chromium";\n' | |
| 198 'ListPolicy.pfm_title = "Caption of policy.";\n' | |
| 199 'ListPolicy.pfm_description = ' | |
| 200 '"Description of policy.\\nWith a newline.";') | |
| 201 self.assertEquals(output.strip(), expected_output.strip()) | |
| 202 | |
| 203 def testStringEnumListPolicy(self): | |
| 204 # Tests a policy group with a single policy of type 'string-enum-list'. | |
| 205 grd = self.PrepareTest(''' | |
| 206 { | |
| 207 'policy_definitions': [ | |
| 208 { | |
| 209 'name': 'EnumGroup', | |
| 210 'type': 'group', | |
| 211 'caption': '', | |
| 212 'desc': '', | |
| 213 'policies': [{ | |
| 214 'name': 'EnumPolicy', | |
| 215 'type': 'string-enum-list', | |
| 216 'caption': 'Caption of policy.', | |
| 217 'desc': """Description of policy. | |
| 218 With a newline.""", | |
| 219 'schema': { | |
| 220 'type': 'array', | |
| 221 'items': { 'type': 'string' }, | |
| 222 }, | |
| 223 'items': [ | |
| 224 { | |
| 225 'name': 'ProxyServerDisabled', | |
| 226 'value': 'one', | |
| 227 'caption': 'Option1' | |
| 228 }, | |
| 229 { | |
| 230 'name': 'ProxyServerAutoDetect', | |
| 231 'value': 'two', | |
| 232 'caption': 'Option2' | |
| 233 }, | |
| 234 ], | |
| 235 'supported_on': ['chrome.mac:8-'], | |
| 236 }], | |
| 237 }, | |
| 238 ], | |
| 239 'placeholders': [], | |
| 240 'messages': { | |
| 241 'mac_chrome_preferences': { | |
| 242 'text': 'Preferences of $1', | |
| 243 'desc': 'blah' | |
| 244 } | |
| 245 } | |
| 246 }''') | |
| 247 output = self.GetOutput( | |
| 248 grd, | |
| 249 'fr', | |
| 250 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, | |
| 251 'plist_strings', | |
| 252 'en') | |
| 253 expected_output = ( | |
| 254 'Chromium.pfm_title = "Chromium";\n' | |
| 255 'Chromium.pfm_description = "Preferences of Chromium";\n' | |
| 256 'EnumPolicy.pfm_title = "Caption of policy.";\n' | |
| 257 'EnumPolicy.pfm_description = ' | |
| 258 '"one - Option1\\ntwo - Option2\\n' | |
| 259 'Description of policy.\\nWith a newline.";') | |
| 260 self.assertEquals(output.strip(), expected_output.strip()) | |
| 261 | |
| 262 def testIntEnumPolicy(self): | |
| 263 # Tests a policy group with a single policy of type 'int-enum'. | |
| 264 grd = self.PrepareTest(''' | |
| 265 { | |
| 266 'policy_definitions': [ | |
| 267 { | |
| 268 'name': 'EnumGroup', | |
| 269 'type': 'group', | |
| 270 'desc': '', | |
| 271 'caption': '', | |
| 272 'policies': [{ | |
| 273 'name': 'EnumPolicy', | |
| 274 'type': 'int-enum', | |
| 275 'desc': 'Description of policy.', | |
| 276 'caption': 'Caption of policy.', | |
| 277 'items': [ | |
| 278 { | |
| 279 'name': 'ProxyServerDisabled', | |
| 280 'value': 0, | |
| 281 'caption': 'Option1' | |
| 282 }, | |
| 283 { | |
| 284 'name': 'ProxyServerAutoDetect', | |
| 285 'value': 1, | |
| 286 'caption': 'Option2' | |
| 287 }, | |
| 288 ], | |
| 289 'supported_on': ['chrome.mac:8-'], | |
| 290 }], | |
| 291 }, | |
| 292 ], | |
| 293 'placeholders': [], | |
| 294 'messages': { | |
| 295 'mac_chrome_preferences': { | |
| 296 'text': '$1 preferences', | |
| 297 'desc': 'blah' | |
| 298 } | |
| 299 } | |
| 300 }''') | |
| 301 output = self.GetOutput( | |
| 302 grd, | |
| 303 'fr', | |
| 304 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, | |
| 305 'plist_strings', | |
| 306 'en') | |
| 307 expected_output = ( | |
| 308 'Google_Chrome.pfm_title = "Google Chrome";\n' | |
| 309 'Google_Chrome.pfm_description = "Google Chrome preferences";\n' | |
| 310 'EnumPolicy.pfm_title = "Caption of policy.";\n' | |
| 311 'EnumPolicy.pfm_description = ' | |
| 312 '"0 - Option1\\n1 - Option2\\nDescription of policy.";\n') | |
| 313 | |
| 314 self.assertEquals(output.strip(), expected_output.strip()) | |
| 315 | |
| 316 def testStringEnumPolicy(self): | |
| 317 # Tests a policy group with a single policy of type 'string-enum'. | |
| 318 grd = self.PrepareTest(''' | |
| 319 { | |
| 320 'policy_definitions': [ | |
| 321 { | |
| 322 'name': 'EnumGroup', | |
| 323 'type': 'group', | |
| 324 'desc': '', | |
| 325 'caption': '', | |
| 326 'policies': [{ | |
| 327 'name': 'EnumPolicy', | |
| 328 'type': 'string-enum', | |
| 329 'desc': 'Description of policy.', | |
| 330 'caption': 'Caption of policy.', | |
| 331 'items': [ | |
| 332 { | |
| 333 'name': 'ProxyServerDisabled', | |
| 334 'value': 'one', | |
| 335 'caption': 'Option1' | |
| 336 }, | |
| 337 { | |
| 338 'name': 'ProxyServerAutoDetect', | |
| 339 'value': 'two', | |
| 340 'caption': 'Option2' | |
| 341 }, | |
| 342 ], | |
| 343 'supported_on': ['chrome.mac:8-'], | |
| 344 }], | |
| 345 }, | |
| 346 ], | |
| 347 'placeholders': [], | |
| 348 'messages': { | |
| 349 'mac_chrome_preferences': { | |
| 350 'text': '$1 preferences', | |
| 351 'desc': 'blah' | |
| 352 } | |
| 353 } | |
| 354 }''') | |
| 355 output = self.GetOutput( | |
| 356 grd, | |
| 357 'fr', | |
| 358 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, | |
| 359 'plist_strings', | |
| 360 'en') | |
| 361 expected_output = ( | |
| 362 'Google_Chrome.pfm_title = "Google Chrome";\n' | |
| 363 'Google_Chrome.pfm_description = "Google Chrome preferences";\n' | |
| 364 'EnumPolicy.pfm_title = "Caption of policy.";\n' | |
| 365 'EnumPolicy.pfm_description = ' | |
| 366 '"one - Option1\\ntwo - Option2\\nDescription of policy.";\n') | |
| 367 | |
| 368 self.assertEquals(output.strip(), expected_output.strip()) | |
| 369 | |
| 370 def testNonSupportedPolicy(self): | |
| 371 # Tests a policy that is not supported on Mac, so its strings shouldn't | |
| 372 # be included in the plist string table. | |
| 373 grd = self.PrepareTest(''' | |
| 374 { | |
| 375 'policy_definitions': [ | |
| 376 { | |
| 377 'name': 'NonMacGroup', | |
| 378 'type': 'group', | |
| 379 'caption': '', | |
| 380 'desc': '', | |
| 381 'policies': [{ | |
| 382 'name': 'NonMacPolicy', | |
| 383 'type': 'string', | |
| 384 'caption': '', | |
| 385 'desc': '', | |
| 386 'supported_on': ['chrome_os:8-'], | |
| 387 }], | |
| 388 }, | |
| 389 ], | |
| 390 'placeholders': [], | |
| 391 'messages': { | |
| 392 'mac_chrome_preferences': { | |
| 393 'text': '$1 preferences', | |
| 394 'desc': 'blah' | |
| 395 } | |
| 396 } | |
| 397 }''') | |
| 398 output = self.GetOutput( | |
| 399 grd, | |
| 400 'fr', | |
| 401 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'}, | |
| 402 'plist_strings', | |
| 403 'en') | |
| 404 expected_output = ( | |
| 405 'Google_Chrome.pfm_title = "Google Chrome";\n' | |
| 406 'Google_Chrome.pfm_description = "Google Chrome preferences";') | |
| 407 self.assertEquals(output.strip(), expected_output.strip()) | |
| 408 | |
| 409 | |
| 410 if __name__ == '__main__': | |
| 411 unittest.main() | |
| OLD | NEW |