| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 from api_models import APIModels | 9 from api_models import APIModels |
| 10 from compiled_file_system import CompiledFileSystem | 10 from compiled_file_system import CompiledFileSystem |
| 11 from extensions_paths import API_PATHS, CHROME_API, CHROME_EXTENSIONS | 11 from extensions_paths import API_PATHS, CHROME_API, CHROME_EXTENSIONS |
| 12 from features_bundle import FeaturesBundle | 12 from features_bundle import FeaturesBundle |
| 13 from file_system import FileNotFoundError | 13 from file_system import FileNotFoundError |
| 14 from mock_file_system import MockFileSystem | 14 from mock_file_system import MockFileSystem |
| 15 from object_store_creator import ObjectStoreCreator | 15 from object_store_creator import ObjectStoreCreator |
| 16 from test_file_system import TestFileSystem | 16 from test_file_system import TestFileSystem |
| 17 from test_util import ReadFile | 17 from test_util import ReadFile |
| 18 from future import Future |
| 19 from process_schema import ProcessSchemaFactoryForTest |
| 18 | 20 |
| 19 | 21 |
| 20 _TEST_DATA = { | 22 _TEST_DATA = { |
| 21 'api': { | 23 'api': { |
| 22 'devtools': { | 24 'devtools': { |
| 23 'inspected_window.json': ReadFile( | 25 'inspected_window.json': ReadFile( |
| 24 CHROME_API, 'devtools', 'inspected_window.json'), | 26 CHROME_API, 'devtools', 'inspected_window.json'), |
| 25 }, | 27 }, |
| 26 '_api_features.json': json.dumps({ | 28 '_api_features.json': json.dumps({ |
| 27 'alarms': {}, | 29 'alarms': {}, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 self._mock_file_system = MockFileSystem( | 62 self._mock_file_system = MockFileSystem( |
| 61 TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS)) | 63 TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS)) |
| 62 features_bundle = FeaturesBundle(self._mock_file_system, | 64 features_bundle = FeaturesBundle(self._mock_file_system, |
| 63 compiled_fs_factory, | 65 compiled_fs_factory, |
| 64 object_store_creator, | 66 object_store_creator, |
| 65 'extensions') | 67 'extensions') |
| 66 self._api_models = APIModels(features_bundle, | 68 self._api_models = APIModels(features_bundle, |
| 67 compiled_fs_factory, | 69 compiled_fs_factory, |
| 68 self._mock_file_system, | 70 self._mock_file_system, |
| 69 object_store_creator, | 71 object_store_creator, |
| 70 'extensions') | 72 'extensions', |
| 73 ProcessSchemaFactoryForTest()) |
| 71 | 74 |
| 72 def testGetNames(self): | 75 def testGetNames(self): |
| 73 # Both 'app' and 'app.runtime' appear here because 'app.runtime' has | 76 # Both 'app' and 'app.runtime' appear here because 'app.runtime' has |
| 74 # noparent:true, but 'app.runtime.foo' etc doesn't so it's a sub-feature of | 77 # noparent:true, but 'app.runtime.foo' etc doesn't so it's a sub-feature of |
| 75 # 'app.runtime' not a separate API. 'devtools.inspectedWindow' is an API | 78 # 'app.runtime' not a separate API. 'devtools.inspectedWindow' is an API |
| 76 # because there is no 'devtools'. | 79 # because there is no 'devtools'. |
| 77 self.assertEqual( | 80 self.assertEqual( |
| 78 ['alarms', 'app', 'app.runtime', 'declarativeWebRequest', | 81 ['alarms', 'app', 'app.runtime', 'declarativeWebRequest', |
| 79 'devtools.inspectedWindow', 'input', 'storage'], | 82 'devtools.inspectedWindow', 'input', 'storage'], |
| 80 sorted(self._api_models.GetNames())) | 83 sorted(self._api_models.GetNames())) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 # No reads (still cached). | 151 # No reads (still cached). |
| 149 future = self._api_models.GetModel('alarms') | 152 future = self._api_models.GetModel('alarms') |
| 150 self.assertTrue(*self._mock_file_system.CheckAndReset( | 153 self.assertTrue(*self._mock_file_system.CheckAndReset( |
| 151 stat_count=len(API_PATHS)*2)) | 154 stat_count=len(API_PATHS)*2)) |
| 152 future.Get() | 155 future.Get() |
| 153 self.assertTrue(*self._mock_file_system.CheckAndReset()) | 156 self.assertTrue(*self._mock_file_system.CheckAndReset()) |
| 154 | 157 |
| 155 | 158 |
| 156 if __name__ == '__main__': | 159 if __name__ == '__main__': |
| 157 unittest.main() | 160 unittest.main() |
| OLD | NEW |