Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 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 from api_data_source import APIDataSource | |
| 7 from availability_data_source import AvailabilityDataSource | |
| 8 from compiled_file_system import CompiledFileSystem | |
| 9 from in_memory_object_store import InMemoryObjectStore | |
| 10 import json | |
|
cduvall
2013/03/21 18:43:53
separate python stdlib includes from your own
epeterson
2013/03/25 19:35:11
Done.
| |
| 11 from memcache_file_system import MemcacheFileSystem | |
| 12 import os | |
| 13 from test_file_system import TestFileSystem | |
| 14 import unittest | |
| 15 | |
| 16 _TEST_DIR = 'test_data/test_avail/' | |
| 17 | |
| 18 _FILE_SYSTEMS = json.load( | |
| 19 open(os.path.join(_TEST_DIR, 'test_avail_file_system.json'), 'r')) | |
| 20 | |
| 21 _BRANCH_DICT = json.load( | |
| 22 open(os.path.join(_TEST_DIR, 'test_avail_branch_list.json'), 'r')) | |
| 23 | |
| 24 class _FakeSamplesDataSource(object): | |
| 25 def Create(self, request): | |
| 26 return {} | |
| 27 | |
| 28 class _FakeRefResolver(object): | |
| 29 def Create(self, request): | |
| 30 return {} | |
| 31 | |
| 32 class _FakeChromeVersionDataSource(object): | |
| 33 def GetDataSourceForVersion(self, version_number): | |
| 34 branch_number = _BRANCH_DICT[version_number] | |
| 35 branch_api_data_source = self._CreateMemcacheForBranch(branch_number) | |
| 36 return branch_api_data_source | |
| 37 | |
| 38 def _CreateMemcacheForBranch(self, branch_number): | |
| 39 branch_memcache = InMemoryObjectStore(branch_number) | |
| 40 file_system = MemcacheFileSystem( | |
| 41 TestFileSystem(_FILE_SYSTEMS[branch_number]), | |
| 42 branch_memcache) | |
| 43 cache_factory = CompiledFileSystem.Factory( | |
| 44 file_system, | |
| 45 branch_memcache, | |
| 46 branch_number) | |
| 47 api_data_source_factory = APIDataSource.Factory(cache_factory, 'api') | |
| 48 api_data_source_factory.SetReferenceResolverFactory(_FakeRefResolver()) | |
| 49 api_data_source_factory.SetSamplesDataSourceFactory( | |
| 50 _FakeSamplesDataSource()) | |
| 51 return api_data_source_factory.Create(None) | |
| 52 | |
| 53 class AvailabilityDataSourceTest(unittest.TestCase): | |
| 54 def setUp(self): | |
| 55 self._availability_ds = AvailabilityDataSource( | |
| 56 _FakeChromeVersionDataSource(), | |
| 57 '26', | |
| 58 InMemoryObjectStore('')) | |
| 59 APIDataSource.Factory._LoadJsonAPI = self._LoadJsonAPI | |
| 60 APIDataSource.Factory._LoadIdlAPI = self._LoadIdlAPI | |
| 61 | |
| 62 ''' These will prevent an api_data_source from actually loading an api, | |
| 63 since that doesn't need to happen here; we're only interested in whether or | |
| 64 not the api is available to be loaded. | |
| 65 ''' | |
| 66 def _LoadJsonAPI(self, api, disable_refs): | |
|
cduvall
2013/03/21 18:43:53
Move these out of the class
epeterson
2013/03/25 19:35:11
Done.
| |
| 67 return {} | |
| 68 def _LoadIdlAPI(self, api, disable_refs): | |
| 69 return {} | |
| 70 | |
| 71 def testFindEarliestAvailability(self): | |
| 72 self.assertEquals('27', | |
| 73 self._availability_ds.FindEarliestAvailability('gobblediegook')) | |
| 74 self.assertEquals('21', | |
| 75 self._availability_ds.FindEarliestAvailability('alarms')) | |
| 76 self.assertEquals('18', | |
| 77 self._availability_ds.FindEarliestAvailability('bookmarks')) | |
| 78 self.assertEquals('18', | |
| 79 self._availability_ds.FindEarliestAvailability('browserAction')) | |
| 80 self.assertEquals('18', | |
| 81 self._availability_ds.FindEarliestAvailability('contextMenus')) | |
| 82 self.assertEquals('18', | |
| 83 self._availability_ds.FindEarliestAvailability('cookies')) | |
| 84 self.assertEquals('21', | |
| 85 self._availability_ds.FindEarliestAvailability('fileSystem')) | |
| 86 self.assertEquals('24', | |
| 87 self._availability_ds.FindEarliestAvailability('pushMessaging')) | |
| 88 self.assertEquals('21', | |
| 89 self._availability_ds.FindEarliestAvailability('runtime')) | |
| 90 self.assertEquals('19', | |
| 91 self._availability_ds.FindEarliestAvailability('storage')) | |
| 92 self.assertEquals('18', | |
| 93 self._availability_ds.FindEarliestAvailability('tabs')) | |
| 94 | |
| 95 if __name__ == '__main__': | |
| 96 unittest.main() | |
| OLD | NEW |