OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.6 |
| 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 |
| 7 '''Unit tests for grit.format.policy_templates.writers.reg_writer''' |
| 8 |
| 9 |
| 10 import os |
| 11 import sys |
| 12 if __name__ == '__main__': |
| 13 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../..')) |
| 14 |
| 15 import unittest |
| 16 |
| 17 from grit.format.policy_templates.writers import writer_unittest_common |
| 18 |
| 19 |
| 20 class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon): |
| 21 '''Unit tests for RegWriter.''' |
| 22 |
| 23 NEWLINE = '\r\n' |
| 24 |
| 25 def CompareOutputs(self, output, expected_output): |
| 26 '''Compares the output of the reg_writer with its expected output. |
| 27 |
| 28 Args: |
| 29 output: The output of the reg writer as returned by grit. |
| 30 expected_output: The expected output. |
| 31 |
| 32 Raises: |
| 33 AssertionError: if the two strings are not equivalent. |
| 34 ''' |
| 35 self.assertEquals( |
| 36 output.strip(), |
| 37 expected_output.strip()) |
| 38 |
| 39 def testEmpty(self): |
| 40 # Test the handling of an empty policy list. |
| 41 grd = self.PrepareTest( |
| 42 '{' |
| 43 ' "policy_definitions": [],' |
| 44 ' "placeholders": [],' |
| 45 ' "messages": {}' |
| 46 '}') |
| 47 output = self.GetOutput(grd, 'fr', {'_chromium': '1', }, 'reg', 'en') |
| 48 expected_output = 'Windows Registry Editor Version 5.00' |
| 49 self.CompareOutputs(output, expected_output) |
| 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": "MainPolicy",' |
| 58 ' "type": "main",' |
| 59 ' "caption": "",' |
| 60 ' "desc": "",' |
| 61 ' "supported_on": ["chrome.win:8-"],' |
| 62 ' "example_value": True' |
| 63 ' },' |
| 64 ' ],' |
| 65 ' "placeholders": [],' |
| 66 ' "messages": {},' |
| 67 '}') |
| 68 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'reg', 'en') |
| 69 expected_output = self.NEWLINE.join([ |
| 70 'Windows Registry Editor Version 5.00', |
| 71 '', |
| 72 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Google\\Chrome]', |
| 73 '"MainPolicy"=dword:00000001']) |
| 74 self.CompareOutputs(output, expected_output) |
| 75 |
| 76 def testStringPolicy(self): |
| 77 # Tests a policy group with a single policy of type 'string'. |
| 78 grd = self.PrepareTest( |
| 79 '{' |
| 80 ' "policy_definitions": [' |
| 81 ' {' |
| 82 ' "name": "StringPolicy",' |
| 83 ' "type": "string",' |
| 84 ' "caption": "",' |
| 85 ' "desc": "",' |
| 86 ' "supported_on": ["chrome.win:8-"],' |
| 87 ' "example_value": "hello, world! \\\" \\\\"' |
| 88 ' },' |
| 89 ' ],' |
| 90 ' "placeholders": [],' |
| 91 ' "messages": {},' |
| 92 '}') |
| 93 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'reg', 'en') |
| 94 expected_output = self.NEWLINE.join([ |
| 95 'Windows Registry Editor Version 5.00', |
| 96 '', |
| 97 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Chromium]', |
| 98 '"StringPolicy"="hello, world! \\\" \\\\"']) |
| 99 self.CompareOutputs(output, expected_output) |
| 100 |
| 101 def testIntPolicy(self): |
| 102 # Tests a policy group with a single policy of type 'int'. |
| 103 grd = self.PrepareTest( |
| 104 '{' |
| 105 ' "policy_definitions": [' |
| 106 ' {' |
| 107 ' "name": "IntPolicy",' |
| 108 ' "type": "int",' |
| 109 ' "caption": "",' |
| 110 ' "desc": "",' |
| 111 ' "supported_on": ["chrome.win:8-"],' |
| 112 ' "example_value": 26' |
| 113 ' },' |
| 114 ' ],' |
| 115 ' "placeholders": [],' |
| 116 ' "messages": {},' |
| 117 '}') |
| 118 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'reg', 'en') |
| 119 expected_output = self.NEWLINE.join([ |
| 120 'Windows Registry Editor Version 5.00', |
| 121 '', |
| 122 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Chromium]', |
| 123 '"IntPolicy"=dword:0000001a']) |
| 124 self.CompareOutputs(output, expected_output) |
| 125 |
| 126 def testIntEnumPolicy(self): |
| 127 # Tests a policy group with a single policy of type 'int-enum'. |
| 128 grd = self.PrepareTest( |
| 129 '{' |
| 130 ' "policy_definitions": [' |
| 131 ' {' |
| 132 ' "name": "EnumPolicy",' |
| 133 ' "type": "int-enum",' |
| 134 ' "caption": "",' |
| 135 ' "desc": "",' |
| 136 ' "items": [' |
| 137 ' {"name": "ProxyServerDisabled", "value": 0, "caption": ""},' |
| 138 ' {"name": "ProxyServerAutoDetect", "value": 1, "caption": ""},' |
| 139 ' ],' |
| 140 ' "supported_on": ["chrome.win:8-"],' |
| 141 ' "example_value": 1' |
| 142 ' },' |
| 143 ' ],' |
| 144 ' "placeholders": [],' |
| 145 ' "messages": {},' |
| 146 '}') |
| 147 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'reg', 'en') |
| 148 expected_output = self.NEWLINE.join([ |
| 149 'Windows Registry Editor Version 5.00', |
| 150 '', |
| 151 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Google\\Chrome]', |
| 152 '"EnumPolicy"=dword:00000001']) |
| 153 self.CompareOutputs(output, expected_output) |
| 154 |
| 155 def testStringEnumPolicy(self): |
| 156 # Tests a policy group with a single policy of type 'string-enum'. |
| 157 grd = self.PrepareTest( |
| 158 '{' |
| 159 ' "policy_definitions": [' |
| 160 ' {' |
| 161 ' "name": "EnumPolicy",' |
| 162 ' "type": "string-enum",' |
| 163 ' "caption": "",' |
| 164 ' "desc": "",' |
| 165 ' "items": [' |
| 166 ' {"name": "ProxyServerDisabled", "value": "one",' |
| 167 ' "caption": ""},' |
| 168 ' {"name": "ProxyServerAutoDetect", "value": "two",' |
| 169 ' "caption": ""},' |
| 170 ' ],' |
| 171 ' "supported_on": ["chrome.win:8-"],' |
| 172 ' "example_value": "two"' |
| 173 ' },' |
| 174 ' ],' |
| 175 ' "placeholders": [],' |
| 176 ' "messages": {},' |
| 177 '}') |
| 178 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'reg', 'en') |
| 179 expected_output = self.NEWLINE.join([ |
| 180 'Windows Registry Editor Version 5.00', |
| 181 '', |
| 182 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Google\\Chrome]', |
| 183 '"EnumPolicy"="two"']) |
| 184 self.CompareOutputs(output, expected_output) |
| 185 |
| 186 def testListPolicy(self): |
| 187 # Tests a policy group with a single policy of type 'list'. |
| 188 grd = self.PrepareTest( |
| 189 '{' |
| 190 ' "policy_definitions": [' |
| 191 ' {' |
| 192 ' "name": "ListPolicy",' |
| 193 ' "type": "list",' |
| 194 ' "caption": "",' |
| 195 ' "desc": "",' |
| 196 ' "supported_on": ["chrome.linux:8-"],' |
| 197 ' "example_value": ["foo", "bar"]' |
| 198 ' },' |
| 199 ' ],' |
| 200 ' "placeholders": [],' |
| 201 ' "messages": {},' |
| 202 '}') |
| 203 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'reg', 'en') |
| 204 expected_output = self.NEWLINE.join([ |
| 205 'Windows Registry Editor Version 5.00', |
| 206 '', |
| 207 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Chromium\\ListPolicy]', |
| 208 '"1"="foo"', |
| 209 '"2"="bar"']) |
| 210 |
| 211 def testNonSupportedPolicy(self): |
| 212 # Tests a policy that is not supported on Windows, so it shouldn't |
| 213 # be included in the .REG file. |
| 214 grd = self.PrepareTest( |
| 215 '{' |
| 216 ' "policy_definitions": [' |
| 217 ' {' |
| 218 ' "name": "NonWindowsPolicy",' |
| 219 ' "type": "list",' |
| 220 ' "caption": "",' |
| 221 ' "desc": "",' |
| 222 ' "supported_on": ["chrome.mac:8-"],' |
| 223 ' "example_value": ["a"]' |
| 224 ' },' |
| 225 ' ],' |
| 226 ' "placeholders": [],' |
| 227 ' "messages": {},' |
| 228 '}') |
| 229 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'reg', 'en') |
| 230 expected_output = self.NEWLINE.join([ |
| 231 'Windows Registry Editor Version 5.00']) |
| 232 self.CompareOutputs(output, expected_output) |
| 233 |
| 234 def testPolicyGroup(self): |
| 235 # Tests a policy group that has more than one policies. |
| 236 grd = self.PrepareTest( |
| 237 '{' |
| 238 ' "policy_definitions": [' |
| 239 ' {' |
| 240 ' "name": "Group1",' |
| 241 ' "type": "group",' |
| 242 ' "caption": "",' |
| 243 ' "desc": "",' |
| 244 ' "policies": [{' |
| 245 ' "name": "Policy1",' |
| 246 ' "type": "list",' |
| 247 ' "caption": "",' |
| 248 ' "desc": "",' |
| 249 ' "supported_on": ["chrome.win:8-"],' |
| 250 ' "example_value": ["a", "b"]' |
| 251 ' },{' |
| 252 ' "name": "Policy2",' |
| 253 ' "type": "string",' |
| 254 ' "caption": "",' |
| 255 ' "desc": "",' |
| 256 ' "supported_on": ["chrome.win:8-"],' |
| 257 ' "example_value": "c"' |
| 258 ' }],' |
| 259 ' },' |
| 260 ' ],' |
| 261 ' "placeholders": [],' |
| 262 ' "messages": {},' |
| 263 '}') |
| 264 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'reg', 'en') |
| 265 expected_output = self.NEWLINE.join([ |
| 266 'Windows Registry Editor Version 5.00', |
| 267 '', |
| 268 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Chromium]', |
| 269 '"Policy2"="c"', |
| 270 '', |
| 271 '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Chromium\\Policy1]', |
| 272 '"1"="a"', |
| 273 '"2"="b"']) |
| 274 self.CompareOutputs(output, expected_output) |
| 275 |
| 276 |
| 277 if __name__ == '__main__': |
| 278 unittest.main() |
OLD | NEW |