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

Side by Side Diff: components/policy/tools/template_writers/writers/json_writer_unittest.py

Issue 2653823006: Include 'external' policies in grit output (admx, adm, doc etc.) (Closed)
Patch Set: Whitespace fix Created 3 years, 2 months 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Unit tests for writers.json_writer''' 6 '''Unit tests for writers.json_writer'''
7 7
8 8
9 import os 9 import os
10 import sys 10 import sys
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 expected_output = ( 351 expected_output = (
352 TEMPLATE_HEADER + 352 TEMPLATE_HEADER +
353 ' // Example Dictionary Policy\n' + 353 ' // Example Dictionary Policy\n' +
354 HEADER_DELIMETER + 354 HEADER_DELIMETER +
355 ' // Example Dictionary Policy\n\n' 355 ' // Example Dictionary Policy\n\n'
356 ' //"DictionaryPolicy": {"bool": true, "dict": {"a": 1, ' 356 ' //"DictionaryPolicy": {"bool": true, "dict": {"a": 1, '
357 '"b": 2}, "int": 10, "list": [1, 2, 3], "string": "abc"}\n\n' 357 '"b": 2}, "int": 10, "list": [1, 2, 3], "string": "abc"}\n\n'
358 '}') 358 '}')
359 self.CompareOutputs(output, expected_output) 359 self.CompareOutputs(output, expected_output)
360 360
361 def testExternalPolicy(self):
362 # Tests a policy group with a single policy of type 'external'.
363 example = {
364 "url": "https://example.com/avatar.jpg",
365 "hash": "deadbeef",
366 }
367 policy_json = '''
368 {
369 "policy_definitions": [
370 {
371 "name": "ExternalPolicy",
372 "type": "external",
373 "caption": "Example External Policy",
374 "desc": "Example External Policy",
375 "supported_on": ["chrome.linux:8-"],
376 "example_value": %s
377 },
378 ],
379 "placeholders": [],
380 "messages": {},
381 }''' % str(example)
382 output = self.GetOutput(policy_json, {'_chromium' : '1'}, 'json')
383 expected_output = (
384 TEMPLATE_HEADER +
385 ' // Example External Policy\n' +
386 HEADER_DELIMETER +
387 ' // Example External Policy\n\n'
388 ' //"ExternalPolicy": {"hash": "deadbeef", "url": "https://example.com/ avatar.jpg"}\n\n'
389 '}')
390 self.CompareOutputs(output, expected_output)
391
361 def testNonSupportedPolicy(self): 392 def testNonSupportedPolicy(self):
362 # Tests a policy that is not supported on Linux, so it shouldn't 393 # Tests a policy that is not supported on Linux, so it shouldn't
363 # be included in the JSON file. 394 # be included in the JSON file.
364 policy_json = ''' 395 policy_json = '''
365 { 396 {
366 "policy_definitions": [ 397 "policy_definitions": [
367 { 398 {
368 "name": "NonLinuxPolicy", 399 "name": "NonLinuxPolicy",
369 "type": "list", 400 "type": "list",
370 "caption": "", 401 "caption": "",
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ' // Policy Two\n' + 451 ' // Policy Two\n' +
421 HEADER_DELIMETER + 452 HEADER_DELIMETER +
422 ' // Policy Two\n\n' 453 ' // Policy Two\n\n'
423 ' //"Policy2": "c"\n\n' 454 ' //"Policy2": "c"\n\n'
424 '}') 455 '}')
425 self.CompareOutputs(output, expected_output) 456 self.CompareOutputs(output, expected_output)
426 457
427 458
428 if __name__ == '__main__': 459 if __name__ == '__main__':
429 unittest.main() 460 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698