Chromium Code Reviews| Index: tools/json_schema_compiler/feature_compiler_test.py |
| diff --git a/tools/json_schema_compiler/feature_compiler_test.py b/tools/json_schema_compiler/feature_compiler_test.py |
| index 6b39271d266c0fb267615e1472ab493763b6d987..b4e070564c12b7206a47c872d11ef24b940b5669 100755 |
| --- a/tools/json_schema_compiler/feature_compiler_test.py |
| +++ b/tools/json_schema_compiler/feature_compiler_test.py |
| @@ -3,6 +3,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import copy |
| import feature_compiler |
| import unittest |
| @@ -19,11 +20,16 @@ class FeatureCompilerTest(unittest.TestCase): |
| f.Parse(value) |
| return f |
| + def _createTestFeatureCompiler(self, feature_class): |
| + return feature_compiler.FeatureCompiler('chrome_root', [], feature_class, |
| + 'provider_class', 'out_root', 'out_base_filename') |
| + |
| def _hasError(self, f, error): |
| """Asserts that |error| is present somewhere in the given feature's |
| errors.""" |
| - self.assertTrue(f.errors) |
| - self.assertNotEqual(-1, str(f.errors).find(error), str(f.errors)) |
| + errors = f.GetErrors() |
| + self.assertTrue(errors) |
| + self.assertNotEqual(-1, str(errors).find(error), str(errors)) |
| def setUp(self): |
| feature_compiler.ENABLE_ASSERTIONS = False |
| @@ -32,6 +38,7 @@ class FeatureCompilerTest(unittest.TestCase): |
| def testFeature(self): |
| # Test some basic feature parsing for a sanity check. |
| f = self._parseFeature({ |
| + 'alias': 'feature', |
| 'blacklist': ['aaa', 'bbb'], |
| 'channel': 'stable', |
| 'command_line_switch': 'switch', |
| @@ -47,9 +54,10 @@ class FeatureCompilerTest(unittest.TestCase): |
| 'noparent': True, |
| 'platforms': ['mac', 'win'], |
| 'session_types': ['kiosk', 'regular'], |
| + 'source': 'feature', |
|
Devlin
2016/11/23 15:56:14
It doesn't make sense to have both an alias and a
tbarzic
2016/11/23 20:16:41
I wouldn't say it necessarily doesn't make sense,
|
| 'whitelist': ['zzz', 'yyy'] |
| }) |
| - self.assertFalse(f.errors) |
| + self.assertFalse(f.GetErrors()) |
| def testInvalidAll(self): |
| f = self._parseFeature({ |
| @@ -136,13 +144,148 @@ class FeatureCompilerTest(unittest.TestCase): |
| channel_feature = self._parseFeature({'contexts': ['blessed_extension'], |
| 'channel': 'trunk'}) |
| channel_feature.Validate('APIFeature') |
| - self.assertFalse(channel_feature.errors) |
| + self.assertFalse(channel_feature.GetErrors()) |
| dependency_feature = self._parseFeature( |
| {'contexts': ['blessed_extension'], |
| 'dependencies': ['alpha']}) |
| dependency_feature.Validate('APIFeature') |
| - self.assertFalse(dependency_feature.errors) |
| + self.assertFalse(dependency_feature.GetErrors()) |
| + |
| + def testAliasFeature(self): |
| + compiler = self._createTestFeatureCompiler('APIFeature') |
| + compiler._json = { |
| + 'feature_alpha': { |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'alias': 'feature_beta' |
| + }, |
| + 'feature_beta': { |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'source': 'feature_alpha' |
| + } |
| + }; |
| + compiler.Compile() |
| + |
| + feature = compiler._features.get('feature_alpha') |
| + self.assertTrue(feature) |
| + self.assertFalse(feature.GetErrors()) |
| + |
| + feature = compiler._features.get('feature_beta') |
| + self.assertTrue(feature) |
| + self.assertFalse(feature.GetErrors()) |
| + |
| + def testMultipleAliasesInComplexFeature(self): |
| + compiler = self._createTestFeatureCompiler('APIFeature') |
| + compiler._json = { |
| + 'feature_alpha': [{ |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'alias': 'feature_beta' |
| + }, { |
| + 'contexts': ['blessed_extension'], |
|
Devlin
2016/11/23 15:56:13
indentation
tbarzic
2016/11/23 20:16:41
Done
|
| + 'channel': 'beta', |
| + 'alias': 'feature_beta' |
| + }] |
| + }; |
| + compiler.Compile() |
| + |
| + feature = compiler._features.get('feature_alpha') |
| + self.assertTrue(feature) |
| + self._hasError(feature, 'Error parsing feature "feature_alpha" at key ' + |
| + '"alias": Key can be set at most once per feature.') |
| + |
| + def testAliasReferenceInComplexFeature(self): |
| + compiler = self._createTestFeatureCompiler('APIFeature') |
| + compiler._json = { |
| + 'feature_alpha': [{ |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'alias': 'feature_beta' |
| + }, { |
| + 'contexts': ['blessed_extension'], |
| + 'channel': 'beta', |
| + }], |
| + 'feature_beta': { |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'source': 'feature_alpha' |
| + } |
| + }; |
| + compiler.Compile() |
| + |
| + feature = compiler._features.get('feature_alpha') |
| + self.assertTrue(feature) |
| + self.assertFalse(feature.GetErrors()) |
| + |
| + feature = compiler._features.get('feature_beta') |
| + self.assertTrue(feature) |
| + self.assertFalse(feature.GetErrors()) |
| + |
| + def testSourceMissingReference(self): |
| + compiler = self._createTestFeatureCompiler('APIFeature') |
| + compiler._json = { |
| + 'feature_alpha': { |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'alias': 'feature_beta' |
| + }, |
| + 'feature_beta': { |
| + 'contexts': ['blessed_extension'], |
| + 'channel': 'beta', |
| + 'source': 'does_not_exist' |
| + } |
| + }; |
| + compiler.Compile() |
| + |
| + feature = compiler._features.get('feature_beta') |
| + self.assertTrue(feature) |
| + self._hasError(feature, 'A feature source property should reference a ' + |
| + 'feature whose alias property references it back.') |
| + |
| + |
| + def testAliasMissingReferenceInComplexFeature(self): |
| + compiler = self._createTestFeatureCompiler('APIFeature') |
| + compiler._json = { |
| + 'feature_alpha': [{ |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'alias': 'feature_beta' |
| + }, { |
| + 'contexts': ['blessed_extension'], |
|
Devlin
2016/11/23 15:56:14
indentation
tbarzic
2016/11/23 20:16:41
Done
|
| + 'channel': 'beta' |
| + }] |
| + }; |
| + compiler.Compile() |
| + |
| + feature = compiler._features.get('feature_alpha') |
| + self.assertTrue(feature) |
| + self._hasError(feature, 'A feature alias property should reference a ' + |
| + 'feature whose source property references it back.') |
| + |
| + def testAliasReferenceMissingSourceInComplexFeature(self): |
| + compiler = self._createTestFeatureCompiler('APIFeature') |
| + compiler._json = { |
| + 'feature_alpha': { |
| + 'contexts': ['blessed_extension'], |
| + 'channel': 'beta', |
| + }, |
| + 'feature_beta': { |
| + 'channel': 'beta', |
| + 'contexts': ['blessed_extension'], |
| + 'alias': 'feature_alpha' |
| + } |
| + }; |
| + compiler.Compile() |
| + |
| + feature = compiler._features.get('feature_alpha') |
| + self.assertTrue(feature) |
| + self.assertFalse(feature.GetErrors()) |
| + feature = compiler._features.get('feature_beta') |
| + self.assertTrue(feature) |
| + self._hasError(feature, 'A feature alias property should reference a ' + |
| + 'feature whose source property references it back.') |
| if __name__ == '__main__': |
| unittest.main() |