OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 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 json |
| 7 import unittest |
| 8 |
| 9 from extensions_paths import CHROME_API, CHROME_EXTENSIONS |
| 10 from mock_file_system import MockFileSystem |
| 11 from server_instance import ServerInstance |
| 12 from test_file_system import TestFileSystem |
| 13 from test_util import ReadFile |
| 14 |
| 15 |
| 16 _TEST_DATA = { |
| 17 'api': { |
| 18 'devtools': { |
| 19 'inspected_window.json': ReadFile( |
| 20 CHROME_API, 'devtools', 'inspected_window.json'), |
| 21 }, |
| 22 '_api_features.json': json.dumps({ |
| 23 'alarms': {}, |
| 24 'app': {'extension_types': ['platform_app']}, |
| 25 'app.runtime': {'noparent': True}, |
| 26 'app.runtime.foo': {'extension_types': ['extension']}, |
| 27 'declarativeWebRequest': {'extension_types': ['extension']}, |
| 28 'devtools.inspectedWindow': {'extension_types': ['extension']}, |
| 29 'input': {'extension_types': 'all'}, |
| 30 'input.ime': {'extension_types': ['extension', 'platform_app']}, |
| 31 'storage': {'extension_types': ['extension']}, |
| 32 }), |
| 33 '_manifest_features.json': '{}', |
| 34 '_permission_features.json': '{}', |
| 35 'alarms.idl': ReadFile(CHROME_API, 'alarms.idl'), |
| 36 'declarative_web_request.json': ReadFile( |
| 37 CHROME_API, 'declarative_web_request.json'), |
| 38 'input_ime.json': ReadFile(CHROME_API, 'input_ime.json'), |
| 39 'page_action.json': ReadFile(CHROME_API, 'page_action.json'), |
| 40 }, |
| 41 'docs': { |
| 42 'templates': { |
| 43 'json': { |
| 44 'manifest.json': '{}', |
| 45 'permissions.json': '{}', |
| 46 } |
| 47 } |
| 48 }, |
| 49 } |
| 50 |
| 51 |
| 52 class PlatformBundleTest(unittest.TestCase): |
| 53 def setUp(self): |
| 54 mock_file_system = MockFileSystem( |
| 55 TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS)) |
| 56 server_instance = ServerInstance.ForTest(file_system=mock_file_system) |
| 57 self._platform_bundle = server_instance.platform_bundle |
| 58 |
| 59 def testGetters(self): |
| 60 self.assertEqual([ |
| 61 'alarms', |
| 62 'app.runtime', |
| 63 'declarativeWebRequest', |
| 64 'devtools.inspectedWindow', |
| 65 'input', |
| 66 'storage' |
| 67 ], sorted(self._platform_bundle.GetAPIModels('extensions').GetNames())) |
| 68 |
| 69 self.assertEqual([ |
| 70 'alarms', |
| 71 'app', |
| 72 'app.runtime', |
| 73 'input' |
| 74 ], sorted(self._platform_bundle.GetAPIModels('apps').GetNames())) |
| 75 |
| 76 self.assertEqual({ |
| 77 'app.runtime': { |
| 78 'name': 'app.runtime', |
| 79 'noparent': True, |
| 80 'channel': 'stable' |
| 81 }, |
| 82 'declarativeWebRequest': { |
| 83 'name': 'declarativeWebRequest', |
| 84 'channel': 'stable', |
| 85 'extension_types': ['extension'], |
| 86 }, |
| 87 'app.runtime.foo': { |
| 88 'name': 'app.runtime.foo', |
| 89 'channel': 'stable', |
| 90 'extension_types': ['extension'], |
| 91 }, |
| 92 'storage': { |
| 93 'name': 'storage', |
| 94 'channel': 'stable', |
| 95 'extension_types': ['extension'], |
| 96 }, |
| 97 'input.ime': { |
| 98 'name': 'input.ime', |
| 99 'channel': 'stable', |
| 100 'extension_types': ['extension', 'platform_app'], |
| 101 }, |
| 102 'alarms': { |
| 103 'name': 'alarms', |
| 104 'channel': 'stable' |
| 105 }, |
| 106 'input': { |
| 107 'name': 'input', |
| 108 'channel': 'stable', |
| 109 'extension_types': 'all' |
| 110 }, |
| 111 'devtools.inspectedWindow': { |
| 112 'name': 'devtools.inspectedWindow', |
| 113 'channel': 'stable', |
| 114 'extension_types': ['extension'], |
| 115 } |
| 116 }, self._platform_bundle.GetFeaturesBundle( |
| 117 'extensions').GetAPIFeatures().Get()) |
| 118 |
| 119 self.assertEqual({ |
| 120 'app.runtime': { |
| 121 'name': 'app.runtime', |
| 122 'noparent': True, |
| 123 'channel': 'stable' |
| 124 }, |
| 125 'input': { |
| 126 'name': 'input', |
| 127 'channel': 'stable', |
| 128 'extension_types': 'all' |
| 129 }, |
| 130 'input.ime': { |
| 131 'name': 'input.ime', |
| 132 'channel': 'stable', |
| 133 'extension_types': ['extension', 'platform_app'], |
| 134 }, |
| 135 'app': { |
| 136 'name': 'app', |
| 137 'channel': 'stable', |
| 138 'extension_types': ['platform_app'], |
| 139 }, |
| 140 'alarms': { |
| 141 'name': 'alarms', |
| 142 'channel': 'stable' |
| 143 } |
| 144 }, self._platform_bundle.GetFeaturesBundle('apps').GetAPIFeatures().Get()) |
| 145 |
| 146 # Check that 'app' is resolved successfully in apps, but is None otherwise. |
| 147 self.assertNotEqual( |
| 148 None, |
| 149 self._platform_bundle.GetReferenceResolver('apps').GetLink('app')) |
| 150 self.assertEqual( |
| 151 None, |
| 152 self._platform_bundle.GetReferenceResolver('extensions').GetLink('app')) |
| 153 |
| 154 if __name__ == '__main__': |
| 155 unittest.main() |
OLD | NEW |