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

Unified Diff: tools/json_schema_compiler/feature_compiler_test.py

Issue 2494653005: Support API aliases (Closed)
Patch Set: . Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..17e5dede357b3ba3fe77a70df4fef6116a699796 100755
--- a/tools/json_schema_compiler/feature_compiler_test.py
+++ b/tools/json_schema_compiler/feature_compiler_test.py
@@ -19,11 +19,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 +37,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 +53,10 @@ class FeatureCompilerTest(unittest.TestCase):
'noparent': True,
'platforms': ['mac', 'win'],
'session_types': ['kiosk', 'regular'],
+ 'source': 'feature',
'whitelist': ['zzz', 'yyy']
})
- self.assertFalse(f.errors)
+ self.assertFalse(f.GetErrors())
def testInvalidAll(self):
f = self._parseFeature({
@@ -136,13 +143,120 @@ 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 testAliasInComplexFeature(self):
+ compiler = self._createTestFeatureCompiler('APIFeature')
+ compiler._CompileFeature('feature_alpha', [{
+ 'channel': 'beta',
+ 'contexts': ['blessed_extension'],
+ 'alias': 'feature_beta'
+ }, {
+ 'contexts': ['blessed_extension'],
+ 'channel': 'beta'
+ }]);
+ feature = compiler._features.get('feature_alpha')
+ self.assertTrue(feature)
+ self.assertFalse(feature.GetErrors())
+
+ def testMultipleAliasesInComplexFeature(self):
+ compiler = self._createTestFeatureCompiler('APIFeature')
+ compiler._CompileFeature('feature_alpha', [{
+ 'channel': 'beta',
+ 'contexts': ['blessed_extension'],
+ 'alias': 'feature_beta'
+ }, {
+ 'contexts': ['blessed_extension'],
+ 'channel': 'beta',
+ 'alias': 'feature_beta'
+ }]);
+ 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._CompileFeature('feature_alpha', [{
Devlin 2016/11/21 16:55:53 I think instead of this approach, it would be a bi
tbarzic 2016/11/21 23:49:48 Done.
+ 'channel': 'beta',
+ 'contexts': ['blessed_extension'],
+ 'alias': 'feature_beta'
+ }, {
+ 'contexts': ['blessed_extension'],
+ 'channel': 'beta',
+ }]);
+ compiler._CompileFeature('feature_beta', {
+ 'channel': 'beta',
+ 'contexts': ['blessed_extension'],
+ 'source': 'feature_alpha'
+ });
+
+ feature = compiler._features.get('feature_alpha')
+ self.assertTrue(feature)
+ self.assertFalse(feature.GetErrors())
+
+ feature.ValidateFeatureReferences(compiler._features)
+ self.assertFalse(feature.GetErrors())
+
+ feature = compiler._features.get('feature_beta')
+ self.assertTrue(feature)
+ self.assertFalse(feature.GetErrors())
+
+ feature.ValidateFeatureReferences(compiler._features)
+ self.assertFalse(feature.GetErrors())
+
+
+ def testAliasMissingReferenceInComplexFeature(self):
+ compiler = self._createTestFeatureCompiler('APIFeature')
+ compiler._CompileFeature('feature_alpha', [{
+ 'channel': 'beta',
+ 'contexts': ['blessed_extension'],
+ 'alias': 'feature_beta'
+ }, {
+ 'contexts': ['blessed_extension'],
+ 'channel': 'beta',
+ }]);
+
+ feature = compiler._features.get('feature_alpha')
+ self.assertTrue(feature)
+ self.assertFalse(feature.GetErrors())
+
+ feature.ValidateFeatureReferences(compiler._features)
+ self._hasError(feature, 'Error parsing feature "feature_alpha" at key ' +
+ '"alias": feature_beta is not a feature.')
+
+ def testAliasReferenceMissingSourceInComplexFeature(self):
+ compiler = self._createTestFeatureCompiler('APIFeature')
+ compiler._CompileFeature('feature_alpha', {
+ 'contexts': ['blessed_extension'],
+ 'channel': 'beta',
+ });
+ compiler._CompileFeature('feature_beta', {
+ 'channel': 'beta',
+ 'contexts': ['blessed_extension'],
+ 'alias': 'feature_alpha'
+ });
+
+ feature = compiler._features.get('feature_alpha')
+ self.assertTrue(feature)
+ self.assertFalse(feature.GetErrors())
+
+ feature.ValidateFeatureReferences(compiler._features)
+ self.assertFalse(feature.GetErrors())
+
+ feature = compiler._features.get('feature_beta')
+ self.assertTrue(feature)
+ self.assertFalse(feature.GetErrors())
+ feature.ValidateFeatureReferences(compiler._features)
+ self._hasError(feature, 'Error parsing feature "feature_beta" at key ' +
+ '"alias": Referenced feature ("feature_alpha") ' +
+ 'should have "source" set to "feature_beta".')
if __name__ == '__main__':
unittest.main()

Powered by Google App Engine
This is Rietveld 408576698