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