OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 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 os |
| 8 import unittest |
| 9 |
| 10 from availability_data_source import AvailabilityDataSource |
| 11 from caching_file_system import CachingFileSystem |
| 12 from object_store_creator import ObjectStoreCreator |
| 13 from test_file_system import TestFileSystem |
| 14 |
| 15 _TEST_DIR = 'test_data/availability_data_source/' |
| 16 |
| 17 def _LoadJson(name, mode='rb'): |
| 18 with open(os.path.join(_TEST_DIR, name), mode) as f: |
| 19 return json.load(f) |
| 20 |
| 21 def _CreateSvnFileSystemForBranch(branch): |
| 22 file_system_json = _LoadJson('test_avail_file_system.json') |
| 23 test_file_system = TestFileSystem(file_system_json[branch]) |
| 24 return test_file_system |
| 25 |
| 26 class _FakeChromeVersionUtility(object): |
| 27 def GetLatestVersionNumber(self): |
| 28 return '27' |
| 29 |
| 30 def GetBranchNumberForVersion(self, version_number): |
| 31 branch_dict_json = _LoadJson('test_avail_branch_list.json') |
| 32 branch_number = branch_dict_json[version_number] |
| 33 return branch_number |
| 34 |
| 35 class AvailabilityDataSourceTest(unittest.TestCase): |
| 36 def setUp(self): |
| 37 file_system_json = _LoadJson('test_avail_file_system.json') |
| 38 test_file_system = TestFileSystem(file_system_json) |
| 39 self._avail_ds_factory = AvailabilityDataSource.Factory( |
| 40 _FakeChromeVersionUtility(), |
| 41 ObjectStoreCreator.TestFactory(), |
| 42 test_file_system) |
| 43 self._avail_ds_factory._existing_availabilities = {'earlyAPI' : '10'} |
| 44 self._avail_ds = self._avail_ds_factory.Create() |
| 45 self._avail_ds._CreateSvnFileSystemForBranch = _CreateSvnFileSystemForBranch |
| 46 self._avail_ds._permission_apis = ['alarms', 'bookmarks', 'cookies'] |
| 47 self._avail_ds._manifest_apis = ['storage', 'runtime'] |
| 48 self._avail_ds._orphan_apis = ['tabs', 'windows'] |
| 49 |
| 50 def testCheckFileSystemExistence(self): |
| 51 self.assertEquals(True, |
| 52 self._avail_ds._CheckFileSystemExistence('tabs', '20')) |
| 53 self.assertEquals(False, |
| 54 self._avail_ds._CheckFileSystemExistence('tabs', '19')) |
| 55 self.assertEquals(False, |
| 56 self._avail_ds._CheckFileSystemExistence('windows', '22')) |
| 57 self.assertEquals(True, |
| 58 self._avail_ds._CheckFileSystemExistence('windows', '24')) |
| 59 |
| 60 def testCheckManifestExistence(self): |
| 61 self.assertEquals(True, |
| 62 self._avail_ds._CheckManifestExistence('storage', '27')) |
| 63 self.assertEquals(False, |
| 64 self._avail_ds._CheckManifestExistence('storage', '26')) |
| 65 self.assertEquals(True, |
| 66 self._avail_ds._CheckManifestExistence('runtime', '21')) |
| 67 self.assertEquals(False, |
| 68 self._avail_ds._CheckManifestExistence('runtime', '20')) |
| 69 |
| 70 def testCheckPermissionExistence(self): |
| 71 self.assertEquals(False, |
| 72 self._avail_ds._CheckStablePermissionExistence('cookies', '27')) |
| 73 self.assertEquals(True, |
| 74 self._avail_ds._CheckStablePermissionExistence('alarms', '24')) |
| 75 self.assertEquals(False, |
| 76 self._avail_ds._CheckStablePermissionExistence('alarms', '23')) |
| 77 self.assertEquals(True, |
| 78 self._avail_ds._CheckStablePermissionExistence('bookmarks', '21')) |
| 79 self.assertEquals(False, |
| 80 self._avail_ds._CheckStablePermissionExistence('bookmarks', '20')) |
| 81 |
| 82 def testFindEarliestStableAvailability(self): |
| 83 self.assertEquals('20', |
| 84 self._avail_ds._FindEarliestStableAvailability('tabs', 27)) |
| 85 self.assertEquals('24', |
| 86 self._avail_ds._FindEarliestStableAvailability('alarms', 27)) |
| 87 self.assertEquals('23', |
| 88 self._avail_ds._FindEarliestStableAvailability('windows', 27)) |
| 89 self.assertEquals('27', |
| 90 self._avail_ds._FindEarliestStableAvailability('storage', 27)) |
| 91 |
| 92 def testGetAvailability(self): |
| 93 self.assertEquals('10', |
| 94 self._avail_ds.GetAvailability('earlyAPI')) |
| 95 self.assertEquals('20', |
| 96 self._avail_ds.GetAvailability('tabs')) |
| 97 self.assertEquals('21', |
| 98 self._avail_ds.GetAvailability('bookmarks')) |
| 99 self.assertEquals('23', |
| 100 self._avail_ds.GetAvailability('windows')) |
| 101 self.assertEquals('27', |
| 102 self._avail_ds.GetAvailability('storage')) |
| 103 self.assertEquals('24', |
| 104 self._avail_ds.GetAvailability('alarms')) |
| 105 |
| 106 if __name__ == '__main__': |
| 107 unittest.main() |
OLD | NEW |