OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2017 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 """Unittests for writers.chromeos_admx_writer.""" |
| 8 |
| 9 |
| 10 import os |
| 11 import sys |
| 12 import unittest |
| 13 if __name__ == '__main__': |
| 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) |
| 15 |
| 16 |
| 17 from writers import chromeos_admx_writer |
| 18 from writers import admx_writer_unittest |
| 19 |
| 20 |
| 21 class ChromeOsAdmxWriterUnittest( |
| 22 admx_writer_unittest.AdmxWriterUnittest): |
| 23 |
| 24 # Overridden. |
| 25 def _GetWriter(self, config): |
| 26 return chromeos_admx_writer.GetWriter(config) |
| 27 |
| 28 # Overridden. |
| 29 def _GetKey(self): |
| 30 return "CrOSTest" |
| 31 |
| 32 # Overridden. |
| 33 def _GetCategory(self): |
| 34 return "cros_test_category"; |
| 35 |
| 36 # Overridden. |
| 37 def _GetCategoryRec(self): |
| 38 return "cros_test_recommended_category"; |
| 39 |
| 40 # Overridden. |
| 41 def _GetNamespace(self): |
| 42 return "ADMXWriter.Test.Namespace.ChromeOS"; |
| 43 |
| 44 # Overridden. |
| 45 def testPlatform(self): |
| 46 # Test that the writer correctly chooses policies of platform Chrome OS. |
| 47 self.assertTrue(self.writer.IsPolicySupported({ |
| 48 'supported_on': [ |
| 49 {'platforms': ['chrome_os', 'zzz']}, {'platforms': ['aaa']} |
| 50 ] |
| 51 })) |
| 52 self.assertFalse(self.writer.IsPolicySupported({ |
| 53 'supported_on': [ |
| 54 {'platforms': ['win', 'mac', 'linux']}, {'platforms': ['aaa']} |
| 55 ] |
| 56 })) |
| 57 |
| 58 def testUserPolicy(self): |
| 59 self.doTestUserOrDevicePolicy(False); |
| 60 |
| 61 def testDevicePolicy(self): |
| 62 self.doTestUserOrDevicePolicy(True); |
| 63 |
| 64 def doTestUserOrDevicePolicy(self, is_device_only): |
| 65 # Tests whether CLASS attribute is 'User' for user policies and 'Machine' |
| 66 # for device policies. |
| 67 main_policy = { |
| 68 'name': 'DummyMainPolicy', |
| 69 'type': 'main', |
| 70 'device_only': is_device_only, |
| 71 } |
| 72 |
| 73 expected_class = 'Machine' if is_device_only else 'User'; |
| 74 |
| 75 self._initWriterForPolicy(self.writer, main_policy) |
| 76 self.writer.WritePolicy(main_policy) |
| 77 |
| 78 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) |
| 79 expected_output = ( |
| 80 '<policy class="' + expected_class + '"' |
| 81 ' displayName="$(string.DummyMainPolicy)"' |
| 82 ' explainText="$(string.DummyMainPolicy_Explain)"' |
| 83 ' key="Software\\Policies\\' + self._GetKey() + '"' |
| 84 ' name="DummyMainPolicy"' |
| 85 ' presentation="$(presentation.DummyMainPolicy)"' |
| 86 ' valueName="DummyMainPolicy">\n' |
| 87 ' <parentCategory ref="PolicyGroup"/>\n' |
| 88 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' |
| 89 ' <enabledValue>\n' |
| 90 ' <decimal value="1"/>\n' |
| 91 ' </enabledValue>\n' |
| 92 ' <disabledValue>\n' |
| 93 ' <decimal value="0"/>\n' |
| 94 ' </disabledValue>\n' |
| 95 '</policy>') |
| 96 |
| 97 self.AssertXMLEquals(output, expected_output) |
| 98 |
| 99 |
| 100 if __name__ == '__main__': |
| 101 unittest.main() |
OLD | NEW |