OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2015 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 import feature_compiler |
| 7 import unittest |
| 8 |
| 9 class FeatureCompilerTest(unittest.TestCase): |
| 10 """Test the FeatureCompiler. Note that we test that the expected features are |
| 11 generated more thoroughly in features_generation_unittest.cc. And, of course, |
| 12 this is most exhaustively tested through Chrome's compilation process (if a |
| 13 feature fails to parse, the compile fails). |
| 14 These tests primarily focus on catching errors during parsing. |
| 15 """ |
| 16 def _parseFeature(self, value): |
| 17 """Parses a feature from the given value and returns the result.""" |
| 18 f = feature_compiler.Feature('alpha') |
| 19 f.Parse(value) |
| 20 return f |
| 21 |
| 22 def _hasError(self, f, error): |
| 23 """Asserts that |error| is present somewhere in the given feature's |
| 24 errors.""" |
| 25 self.assertTrue(f.errors) |
| 26 self.assertNotEqual(-1, str(f.errors).find(error), str(f.errors)) |
| 27 |
| 28 def setUp(self): |
| 29 feature_compiler.ENABLE_ASSERTIONS = False |
| 30 feature_compiler.STRINGS_TO_UNICODE = True |
| 31 |
| 32 def testFeature(self): |
| 33 # Test some basic feature parsing for a sanity check. |
| 34 f = self._parseFeature({ |
| 35 'blacklist': ['aaa', 'bbb'], |
| 36 'channel': 'stable', |
| 37 'command_line_switch': 'switch', |
| 38 'component_extensions_auto_granted': False, |
| 39 'contexts': ['blessed_extension', 'blessed_web_page'], |
| 40 'default_parent': True, |
| 41 'dependencies': ['dependency1', 'dependency2'], |
| 42 'extension_types': ['extension'], |
| 43 'location': 'component', |
| 44 'internal': True, |
| 45 'matches': ['*://*/*'], |
| 46 'max_manifest_version': 1, |
| 47 'noparent': True, |
| 48 'platforms': ['mac', 'win'], |
| 49 'whitelist': ['zzz', 'yyy'] |
| 50 }) |
| 51 self.assertFalse(f.errors) |
| 52 |
| 53 def testUnknownKeyError(self): |
| 54 f = self._parseFeature({ |
| 55 'contexts': ['blessed_extension'], |
| 56 'channel': 'stable', |
| 57 'unknownkey': 'unknownvalue' |
| 58 }) |
| 59 self._hasError(f, 'Unrecognized key') |
| 60 |
| 61 def testUnknownEnumValue(self): |
| 62 f = self._parseFeature({ |
| 63 'contexts': ['blessed_extension', 'unknown_context'], |
| 64 'channel': 'stable' |
| 65 }) |
| 66 self._hasError(f, 'Illegal value: "unknown_context"') |
| 67 |
| 68 def testImproperType(self): |
| 69 f = self._parseFeature({'min_manifest_version': '1'}) |
| 70 self._hasError(f, 'Illegal value: "1"') |
| 71 |
| 72 def testImproperSubType(self): |
| 73 f = self._parseFeature({'dependencies': [1, 2, 3]}) |
| 74 self._hasError(f, 'Illegal value: "1"') |
| 75 |
| 76 def testImproperValue(self): |
| 77 f = self._parseFeature({'noparent': False}) |
| 78 self._hasError(f, 'Illegal value: "False"') |
| 79 |
| 80 if __name__ == '__main__': |
| 81 unittest.main() |
OLD | NEW |