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

Unified Diff: tools/json_schema_compiler/feature_compiler_test.py

Issue 2151583003: [Extensions] Add extension feature generation code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dirk's Created 4 years, 5 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 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
new file mode 100755
index 0000000000000000000000000000000000000000..02d366fb505b5e3e90e09e403a158ace70efce53
--- /dev/null
+++ b/tools/json_schema_compiler/feature_compiler_test.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import feature_compiler
+import unittest
+
+class FeatureCompilerTest(unittest.TestCase):
+ """Test the FeatureCompiler. Note that we test that the expected features are
+ generated more thoroughly in features_generation_unittest.cc. And, of course,
+ this is most exhaustively tested through Chrome's compilation process (if a
+ feature fails to parse, the compile fails).
+ These tests primarily focus on catching errors during parsing.
+ """
+ def _parseFeature(self, value):
+ """Parses a feature from the given value and returns the result."""
+ f = feature_compiler.Feature('alpha')
+ f.Parse(value)
+ return f
+
+ 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))
+
+ def setUp(self):
+ feature_compiler.ENABLE_ASSERTIONS = False
+ feature_compiler.STRINGS_TO_UNICODE = True
+
+ def testFeature(self):
+ # Test some basic feature parsing for a sanity check.
+ f = self._parseFeature({
+ 'blacklist': ['aaa', 'bbb'],
+ 'channel': 'stable',
+ 'command_line_switch': 'switch',
+ 'component_extensions_auto_granted': False,
+ 'contexts': ['blessed_extension', 'blessed_web_page'],
+ 'default_parent': True,
+ 'dependencies': ['dependency1', 'dependency2'],
+ 'extension_types': ['extension'],
+ 'location': 'component',
+ 'internal': True,
+ 'matches': ['*://*/*'],
+ 'max_manifest_version': 1,
+ 'noparent': True,
+ 'platforms': ['mac', 'win'],
+ 'whitelist': ['zzz', 'yyy']
+ })
+ self.assertFalse(f.errors)
+
+ def testUnknownKeyError(self):
+ f = self._parseFeature({
+ 'contexts': ['blessed_extension'],
+ 'channel': 'stable',
+ 'unknownkey': 'unknownvalue'
+ })
+ self._hasError(f, 'Unrecognized key')
+
+ def testUnknownEnumValue(self):
+ f = self._parseFeature({
+ 'contexts': ['blessed_extension', 'unknown_context'],
+ 'channel': 'stable'
+ })
+ self._hasError(f, 'Illegal value: "unknown_context"')
+
+ def testImproperType(self):
+ f = self._parseFeature({'min_manifest_version': '1'})
+ self._hasError(f, 'Illegal value: "1"')
+
+ def testImproperSubType(self):
+ f = self._parseFeature({'dependencies': [1, 2, 3]})
+ self._hasError(f, 'Illegal value: "1"')
+
+ def testImproperValue(self):
+ f = self._parseFeature({'noparent': False})
+ self._hasError(f, 'Illegal value: "False"')
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698