| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 os | 7 import os |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 from jsc_view import GetEventByNameFromEvents | 10 from jsc_view import GetEventByNameFromEvents |
| 11 from api_schema_graph import APISchemaGraph | 11 from api_schema_graph import APISchemaGraph |
| 12 from availability_finder import AvailabilityFinder, AvailabilityInfo | 12 from availability_finder import AvailabilityFinder, AvailabilityInfo |
| 13 from branch_utility import BranchUtility, ChannelInfo | 13 from branch_utility import BranchUtility, ChannelInfo |
| 14 from compiled_file_system import CompiledFileSystem | 14 from compiled_file_system import CompiledFileSystem |
| 15 from extensions_paths import CHROME_EXTENSIONS | 15 from extensions_paths import CHROME_EXTENSIONS |
| 16 from fake_host_file_system_provider import FakeHostFileSystemProvider | 16 from fake_host_file_system_provider import FakeHostFileSystemProvider |
| 17 from fake_url_fetcher import FakeUrlFetcher | 17 from fake_url_fetcher import FakeUrlFetcher |
| 18 from features_bundle import FeaturesBundle | 18 from features_bundle import FeaturesBundle |
| 19 from future import Future | 19 from future import Future |
| 20 from host_file_system_iterator import HostFileSystemIterator | 20 from host_file_system_iterator import HostFileSystemIterator |
| 21 from jsc_view import JSCView, _FormatValue | 21 from jsc_view import JSCView, _FormatValue |
| 22 from object_store_creator import ObjectStoreCreator | 22 from object_store_creator import ObjectStoreCreator |
| 23 from schema_processor import SchemaProcessorFactoryForTest | 23 from schema_processor import SchemaProcessorFactoryForTest |
| 24 from server_instance import ServerInstance | 24 from server_instance import ServerInstance |
| 25 from test_data.api_data_source.canned_trunk_fs import CANNED_TRUNK_FS_DATA | 25 from test_data.api_data_source.canned_master_fs import CANNED_MASTER_FS_DATA |
| 26 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA | 26 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA |
| 27 from test_data.object_level_availability.tabs import TABS_SCHEMA_BRANCHES | 27 from test_data.object_level_availability.tabs import TABS_SCHEMA_BRANCHES |
| 28 from test_file_system import TestFileSystem | 28 from test_file_system import TestFileSystem |
| 29 from test_util import Server2Path | 29 from test_util import Server2Path |
| 30 | 30 |
| 31 | 31 |
| 32 class _FakeTemplateCache(object): | 32 class _FakeTemplateCache(object): |
| 33 | 33 |
| 34 def GetFromFile(self, key): | 34 def GetFromFile(self, key): |
| 35 return Future(value='motemplate %s' % key) | 35 return Future(value='motemplate %s' % key) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 class _FakeAvailabilityFinder(object): | 50 class _FakeAvailabilityFinder(object): |
| 51 def __init__(self, fake_availability): | 51 def __init__(self, fake_availability): |
| 52 self._fake_availability = fake_availability | 52 self._fake_availability = fake_availability |
| 53 | 53 |
| 54 def GetAPIAvailability(self, api_name): | 54 def GetAPIAvailability(self, api_name): |
| 55 return self._fake_availability | 55 return self._fake_availability |
| 56 | 56 |
| 57 def GetAPINodeAvailability(self, api_name): | 57 def GetAPINodeAvailability(self, api_name): |
| 58 schema_graph = APISchemaGraph() | 58 schema_graph = APISchemaGraph() |
| 59 api_graph = APISchemaGraph(json.loads( | 59 api_graph = APISchemaGraph(json.loads( |
| 60 CANNED_TRUNK_FS_DATA['api'][api_name + '.json'])) | 60 CANNED_MASTER_FS_DATA['api'][api_name + '.json'])) |
| 61 # Give the graph fake ChannelInfo; it's not used in tests. | 61 # Give the graph fake ChannelInfo; it's not used in tests. |
| 62 channel_info = ChannelInfo('stable', '28', 28) | 62 channel_info = ChannelInfo('stable', '28', 28) |
| 63 schema_graph.Update(api_graph, lambda _: channel_info) | 63 schema_graph.Update(api_graph, lambda _: channel_info) |
| 64 return schema_graph | 64 return schema_graph |
| 65 | 65 |
| 66 | 66 |
| 67 class JSCViewTest(unittest.TestCase): | 67 class JSCViewTest(unittest.TestCase): |
| 68 def setUp(self): | 68 def setUp(self): |
| 69 self._base_path = Server2Path('test_data', 'test_json') | 69 self._base_path = Server2Path('test_data', 'test_json') |
| 70 | 70 |
| 71 server_instance = ServerInstance.ForTest( | 71 server_instance = ServerInstance.ForTest( |
| 72 TestFileSystem(CANNED_TRUNK_FS_DATA, relative_to=CHROME_EXTENSIONS)) | 72 TestFileSystem(CANNED_MASTER_FS_DATA, relative_to=CHROME_EXTENSIONS)) |
| 73 file_system = server_instance.host_file_system_provider.GetTrunk() | 73 file_system = server_instance.host_file_system_provider.GetMaster() |
| 74 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) | 74 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) |
| 75 self._features_bundle = FeaturesBundle(file_system, | 75 self._features_bundle = FeaturesBundle(file_system, |
| 76 server_instance.compiled_fs_factory, | 76 server_instance.compiled_fs_factory, |
| 77 server_instance.object_store_creator, | 77 server_instance.object_store_creator, |
| 78 'extensions') | 78 'extensions') |
| 79 self._api_models = server_instance.platform_bundle.GetAPIModels( | 79 self._api_models = server_instance.platform_bundle.GetAPIModels( |
| 80 'extensions') | 80 'extensions') |
| 81 self._fake_availability = AvailabilityInfo(ChannelInfo('stable', '396', 5)) | 81 self._fake_availability = AvailabilityInfo(ChannelInfo('stable', '396', 5)) |
| 82 | 82 |
| 83 def _ReadLocalFile(self, filename): | 83 def _ReadLocalFile(self, filename): |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 | 260 |
| 261 class JSCViewWithoutNodeAvailabilityTest(unittest.TestCase): | 261 class JSCViewWithoutNodeAvailabilityTest(unittest.TestCase): |
| 262 def setUp(self): | 262 def setUp(self): |
| 263 server_instance = ServerInstance.ForTest( | 263 server_instance = ServerInstance.ForTest( |
| 264 file_system_provider=FakeHostFileSystemProvider( | 264 file_system_provider=FakeHostFileSystemProvider( |
| 265 CANNED_API_FILE_SYSTEM_DATA)) | 265 CANNED_API_FILE_SYSTEM_DATA)) |
| 266 self._api_models = server_instance.platform_bundle.GetAPIModels( | 266 self._api_models = server_instance.platform_bundle.GetAPIModels( |
| 267 'extensions') | 267 'extensions') |
| 268 self._json_cache = server_instance.compiled_fs_factory.ForJson( | 268 self._json_cache = server_instance.compiled_fs_factory.ForJson( |
| 269 server_instance.host_file_system_provider.GetTrunk()) | 269 server_instance.host_file_system_provider.GetMaster()) |
| 270 self._avail_finder = server_instance.platform_bundle.GetAvailabilityFinder( | 270 self._avail_finder = server_instance.platform_bundle.GetAvailabilityFinder( |
| 271 'extensions') | 271 'extensions') |
| 272 | 272 |
| 273 | 273 |
| 274 def testGetAPIAvailability(self): | 274 def testGetAPIAvailability(self): |
| 275 api_availabilities = { | 275 api_availabilities = { |
| 276 'bluetooth': 31, | 276 'bluetooth': 31, |
| 277 'contextMenus': 'trunk', | 277 'contextMenus': 'master', |
| 278 'jsonStableAPI': 20, | 278 'jsonStableAPI': 20, |
| 279 'idle': 5, | 279 'idle': 5, |
| 280 'input.ime': 18, | 280 'input.ime': 18, |
| 281 'tabs': 18 | 281 'tabs': 18 |
| 282 } | 282 } |
| 283 for api_name, availability in api_availabilities.iteritems(): | 283 for api_name, availability in api_availabilities.iteritems(): |
| 284 model_dict = JSCView( | 284 model_dict = JSCView( |
| 285 self._api_models.GetContentScriptAPIs().Get(), | 285 self._api_models.GetContentScriptAPIs().Get(), |
| 286 self._api_models.GetModel(api_name).Get(), | 286 self._api_models.GetModel(api_name).Get(), |
| 287 self._avail_finder, | 287 self._avail_finder, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 303 FakeUrlFetcher(Server2Path('test_data')), | 303 FakeUrlFetcher(Server2Path('test_data')), |
| 304 ObjectStoreCreator.ForTest()) | 304 ObjectStoreCreator.ForTest()) |
| 305 self._node_fs_creator = FakeHostFileSystemProvider(TABS_SCHEMA_BRANCHES) | 305 self._node_fs_creator = FakeHostFileSystemProvider(TABS_SCHEMA_BRANCHES) |
| 306 self._node_fs_iterator = HostFileSystemIterator(self._node_fs_creator, | 306 self._node_fs_iterator = HostFileSystemIterator(self._node_fs_creator, |
| 307 self._branch_utility) | 307 self._branch_utility) |
| 308 test_object_store = ObjectStoreCreator.ForTest() | 308 test_object_store = ObjectStoreCreator.ForTest() |
| 309 self._avail_finder = AvailabilityFinder( | 309 self._avail_finder = AvailabilityFinder( |
| 310 self._branch_utility, | 310 self._branch_utility, |
| 311 CompiledFileSystem.Factory(test_object_store), | 311 CompiledFileSystem.Factory(test_object_store), |
| 312 self._node_fs_iterator, | 312 self._node_fs_iterator, |
| 313 self._node_fs_creator.GetTrunk(), | 313 self._node_fs_creator.GetMaster(), |
| 314 test_object_store, | 314 test_object_store, |
| 315 'extensions', | 315 'extensions', |
| 316 SchemaProcessorFactoryForTest()) | 316 SchemaProcessorFactoryForTest()) |
| 317 | 317 |
| 318 server_instance = ServerInstance.ForTest( | 318 server_instance = ServerInstance.ForTest( |
| 319 file_system_provider=FakeHostFileSystemProvider( | 319 file_system_provider=FakeHostFileSystemProvider( |
| 320 TABS_SCHEMA_BRANCHES)) | 320 TABS_SCHEMA_BRANCHES)) |
| 321 self._api_models = server_instance.platform_bundle.GetAPIModels( | 321 self._api_models = server_instance.platform_bundle.GetAPIModels( |
| 322 'extensions') | 322 'extensions') |
| 323 self._json_cache = server_instance.compiled_fs_factory.ForJson( | 323 self._json_cache = server_instance.compiled_fs_factory.ForJson( |
| 324 server_instance.host_file_system_provider.GetTrunk()) | 324 server_instance.host_file_system_provider.GetMaster()) |
| 325 | 325 |
| 326 # Imitate the actual SVN file system by incrementing the stats for paths | 326 # Imitate the actual SVN file system by incrementing the stats for paths |
| 327 # where an API schema has changed. | 327 # where an API schema has changed. |
| 328 last_stat = type('last_stat', (object,), {'val': 0}) | 328 last_stat = type('last_stat', (object,), {'val': 0}) |
| 329 | 329 |
| 330 def stat_paths(file_system, channel_info): | 330 def stat_paths(file_system, channel_info): |
| 331 if channel_info.version not in tabs_unmodified_versions: | 331 if channel_info.version not in tabs_unmodified_versions: |
| 332 last_stat.val += 1 | 332 last_stat.val += 1 |
| 333 # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem. | 333 # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem. |
| 334 # Increment the TestFileSystem stat count. | 334 # Increment the TestFileSystem stat count. |
| 335 file_system._file_system.IncrementStat(by=last_stat.val) | 335 file_system._file_system.IncrementStat(by=last_stat.val) |
| 336 # Continue looping. The iterator will stop after 'trunk' automatically. | 336 # Continue looping. The iterator will stop after 'master' automatically. |
| 337 return True | 337 return True |
| 338 | 338 |
| 339 # Use the HostFileSystemIterator created above to change global stat values | 339 # Use the HostFileSystemIterator created above to change global stat values |
| 340 # for the TestFileSystems that it creates. | 340 # for the TestFileSystems that it creates. |
| 341 self._node_fs_iterator.Ascending( | 341 self._node_fs_iterator.Ascending( |
| 342 # The earliest version represented with the tabs' test data is 13. | 342 # The earliest version represented with the tabs' test data is 13. |
| 343 self._branch_utility.GetStableChannelInfo(13), | 343 self._branch_utility.GetStableChannelInfo(13), |
| 344 stat_paths) | 344 stat_paths) |
| 345 | 345 |
| 346 def testGetAPINodeAvailability(self): | 346 def testGetAPINodeAvailability(self): |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 # Test a node that became deprecated. | 397 # Test a node that became deprecated. |
| 398 self.assertEquals({ | 398 self.assertEquals({ |
| 399 'scheduled': None, | 399 'scheduled': None, |
| 400 'version': 26, | 400 'version': 26, |
| 401 'partial': 'motemplate chrome/common/extensions/docs/templates/' + | 401 'partial': 'motemplate chrome/common/extensions/docs/templates/' + |
| 402 'private/intro_tables/deprecated_message.html' | 402 'private/intro_tables/deprecated_message.html' |
| 403 }, model_dict['types'][2]['availability']) | 403 }, model_dict['types'][2]['availability']) |
| 404 | 404 |
| 405 if __name__ == '__main__': | 405 if __name__ == '__main__': |
| 406 unittest.main() | 406 unittest.main() |
| OLD | NEW |