Index: chrome/common/extensions/docs/server2/manifest_data_source_test.py |
diff --git a/chrome/common/extensions/docs/server2/manifest_data_source_test.py b/chrome/common/extensions/docs/server2/manifest_data_source_test.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..72c6be2b4b47d4be974af02b598b59b845c203b8 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/manifest_data_source_test.py |
@@ -0,0 +1,102 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2013 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 types |
+import unittest |
+ |
+from manifest_data_source import ManifestDataSource |
+ |
+class MockCompiledFileSystem(object): |
+ class Factory(object): |
not at google - send to devlin
2013/05/10 04:14:14
It doesn't look like having a Factory here achieve
jshumway
2013/05/11 02:37:08
Replaced all of this stuff with the project's test
|
+ def Create(self, _, __): |
+ return MockCompiledFileSystem() |
+ |
+ def GetFromFile(self, path): |
+ if path == 'features_path': |
+ # Our example _manifest_features.json. |
+ return { |
+ 'req0': { |
+ 'channel': 'stable', |
+ 'extension_types': ['packaged_app', 'extension'] |
+ }, |
+ 'req1': { |
+ 'channel': 'dev', |
+ 'extension_types': 'all' |
+ }, |
+ 'opt0': { |
+ 'channel': 'trunk', |
+ 'extension_types': ['extension'] |
+ }, |
+ 'opt1': { |
+ 'channel': 'stable', |
+ 'extension_types': ['hosted_app'] |
+ }, |
+ 'free0': { |
+ 'channel': 'stable', |
+ 'extension_types': ['platform_app'] |
+ }, |
+ 'free1': { |
+ 'channel': 'dev', |
+ 'extension_types': ['packaged_app', 'hosted_app', 'extension'] |
+ } |
+ } |
+ |
+def LoadManifestData(self, _): |
+ # Our example manifest.json. |
+ return { |
+ 'required': [ |
+ {'name': 'req0'}, |
+ {'name': 'req1'} |
+ ], |
+ 'optional': [ |
+ {'name': 'opt0'}, |
+ {'name': 'opt1'} |
+ ] |
+ } |
+def Nothing(self, _): |
+ # Do nothing. We don't care what Apply{Apps,Extensions}Transformations methods |
+ # do because they change depending on data. |
+ pass |
+ |
+class ManifestDataSourceTest(unittest.TestCase): |
+ def testCreateManifestData(self): |
+ expected_extensions = { |
+ 'required': [ |
+ {'name': 'req0'}, |
+ {'name': 'req1'} |
+ ], |
+ 'optional': [ |
+ {'name': 'free1'}, |
+ ] |
+ } |
+ |
+ expected_apps = { |
+ 'required': [ |
+ {'name': 'req0'}, |
+ {'name': 'req1'} |
+ ], |
+ 'optional': [ |
+ {'name': 'opt1'}, |
+ {'name': 'free0'}, |
+ {'name': 'free1'} |
+ ] |
+ } |
+ |
+ mds = ManifestDataSource( |
+ MockCompiledFileSystem.Factory(), 'manifest_path', 'features_path', |
not at google - send to devlin
2013/05/10 04:14:14
4 space
jshumway
2013/05/11 02:37:08
Done.
|
+ 'dev') |
+ |
+ # Prevent an actual file load by patching in our load function. |
not at google - send to devlin
2013/05/10 04:14:14
cool test data, but the test object store / file s
jshumway
2013/05/11 02:37:08
Fixed them up. I still override the two Apply*Tran
|
+ mds._LoadManifestData = types.MethodType(LoadManifestData, mds) |
+ mds._ApplyAppsTransformations = types.MethodType(Nothing, mds) |
+ mds._ApplyExtensionsTransformations = types.MethodType(Nothing, mds) |
+ |
+ results = mds._CreateManifestData(None, None) |
+ |
+ self.assertEqual(expected_extensions, dict(results['extensions'])) |
+ self.assertEqual(expected_apps, dict(results['apps'])) |
+ |
+if __name__ == '__main__': |
+ unittest.main() |