| 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 import os | 5 import os |
| 6 import sys | 6 import sys |
| 7 import unittest | 7 import unittest |
| 8 | 8 |
| 9 import api_schema_graph | 9 import api_schema_graph |
| 10 from availability_finder import AvailabilityFinder, AvailabilityInfo | 10 from availability_finder import AvailabilityFinder, AvailabilityInfo |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 def _create_availability_finder(self, | 28 def _create_availability_finder(self, |
| 29 host_fs_creator, | 29 host_fs_creator, |
| 30 host_fs_iterator, | 30 host_fs_iterator, |
| 31 platform): | 31 platform): |
| 32 test_object_store = ObjectStoreCreator.ForTest() | 32 test_object_store = ObjectStoreCreator.ForTest() |
| 33 return AvailabilityFinder( | 33 return AvailabilityFinder( |
| 34 self._branch_utility, | 34 self._branch_utility, |
| 35 CompiledFileSystem.Factory(test_object_store), | 35 CompiledFileSystem.Factory(test_object_store), |
| 36 host_fs_iterator, | 36 host_fs_iterator, |
| 37 host_fs_creator.GetTrunk(), | 37 host_fs_creator.GetMaster(), |
| 38 test_object_store, | 38 test_object_store, |
| 39 platform) | 39 platform) |
| 40 | 40 |
| 41 def setUp(self): | 41 def setUp(self): |
| 42 self._branch_utility = BranchUtility( | 42 self._branch_utility = BranchUtility( |
| 43 os.path.join('branch_utility', 'first.json'), | 43 os.path.join('branch_utility', 'first.json'), |
| 44 os.path.join('branch_utility', 'second.json'), | 44 os.path.join('branch_utility', 'second.json'), |
| 45 FakeUrlFetcher(Server2Path('test_data')), | 45 FakeUrlFetcher(Server2Path('test_data')), |
| 46 ObjectStoreCreator.ForTest()) | 46 ObjectStoreCreator.ForTest()) |
| 47 self._api_fs_creator = FakeHostFileSystemProvider( | 47 self._api_fs_creator = FakeHostFileSystemProvider( |
| 48 CANNED_API_FILE_SYSTEM_DATA) | 48 CANNED_API_FILE_SYSTEM_DATA) |
| 49 self._node_fs_creator = FakeHostFileSystemProvider(TABS_SCHEMA_BRANCHES) | 49 self._node_fs_creator = FakeHostFileSystemProvider(TABS_SCHEMA_BRANCHES) |
| 50 self._api_fs_iterator = HostFileSystemIterator(self._api_fs_creator, | 50 self._api_fs_iterator = HostFileSystemIterator(self._api_fs_creator, |
| 51 self._branch_utility) | 51 self._branch_utility) |
| 52 self._node_fs_iterator = HostFileSystemIterator(self._node_fs_creator, | 52 self._node_fs_iterator = HostFileSystemIterator(self._node_fs_creator, |
| 53 self._branch_utility) | 53 self._branch_utility) |
| 54 | 54 |
| 55 # Imitate the actual SVN file system by incrementing the stats for paths | 55 # Imitate the actual SVN file system by incrementing the stats for paths |
| 56 # where an API schema has changed. | 56 # where an API schema has changed. |
| 57 last_stat = type('last_stat', (object,), {'val': 0}) | 57 last_stat = type('last_stat', (object,), {'val': 0}) |
| 58 | 58 |
| 59 def stat_paths(file_system, channel_info): | 59 def stat_paths(file_system, channel_info): |
| 60 if channel_info.version not in TABS_UNMODIFIED_VERSIONS: | 60 if channel_info.version not in TABS_UNMODIFIED_VERSIONS: |
| 61 last_stat.val += 1 | 61 last_stat.val += 1 |
| 62 # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem. | 62 # HACK: |file_system| is a MockFileSystem backed by a TestFileSystem. |
| 63 # Increment the TestFileSystem stat count. | 63 # Increment the TestFileSystem stat count. |
| 64 file_system._file_system.IncrementStat(by=last_stat.val) | 64 file_system._file_system.IncrementStat(by=last_stat.val) |
| 65 # Continue looping. The iterator will stop after 'trunk' automatically. | 65 # Continue looping. The iterator will stop after 'master' automatically. |
| 66 return True | 66 return True |
| 67 | 67 |
| 68 # Use the HostFileSystemIterator created above to change global stat values | 68 # Use the HostFileSystemIterator created above to change global stat values |
| 69 # for the TestFileSystems that it creates. | 69 # for the TestFileSystems that it creates. |
| 70 self._node_fs_iterator.Ascending( | 70 self._node_fs_iterator.Ascending( |
| 71 # The earliest version represented with the tabs' test data is 13. | 71 # The earliest version represented with the tabs' test data is 13. |
| 72 self._branch_utility.GetStableChannelInfo(13), | 72 self._branch_utility.GetStableChannelInfo(13), |
| 73 stat_paths) | 73 stat_paths) |
| 74 | 74 |
| 75 def testGraphOptimization(self): | 75 def testGraphOptimization(self): |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 def assertGet(ch_info, api, only_on=None, scheduled=None): | 107 def assertGet(ch_info, api, only_on=None, scheduled=None): |
| 108 for platform in GetPlatforms(): | 108 for platform in GetPlatforms(): |
| 109 get_availability = self._create_availability_finder( | 109 get_availability = self._create_availability_finder( |
| 110 self._api_fs_creator, | 110 self._api_fs_creator, |
| 111 self._api_fs_iterator, | 111 self._api_fs_iterator, |
| 112 platform if only_on is None else only_on).GetAPIAvailability | 112 platform if only_on is None else only_on).GetAPIAvailability |
| 113 self.assertEqual(AvailabilityInfo(ch_info, scheduled=scheduled), | 113 self.assertEqual(AvailabilityInfo(ch_info, scheduled=scheduled), |
| 114 get_availability(api)) | 114 get_availability(api)) |
| 115 | 115 |
| 116 # Testing APIs with predetermined availability. | 116 # Testing APIs with predetermined availability. |
| 117 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'jsonTrunkAPI') | 117 assertGet(ChannelInfo('master', 'master', 'master'), 'jsonTrunkAPI') |
| 118 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'jsonDevAPI') | 118 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'jsonDevAPI') |
| 119 assertGet(ChannelInfo('beta', CANNED_BRANCHES[30], 30), 'jsonBetaAPI') | 119 assertGet(ChannelInfo('beta', CANNED_BRANCHES[30], 30), 'jsonBetaAPI') |
| 120 assertGet(ChannelInfo('stable', CANNED_BRANCHES[20], 20), 'jsonStableAPI') | 120 assertGet(ChannelInfo('stable', CANNED_BRANCHES[20], 20), 'jsonStableAPI') |
| 121 | 121 |
| 122 # Testing a whitelisted API. | 122 # Testing a whitelisted API. |
| 123 assertGet(ChannelInfo('beta', CANNED_BRANCHES[30], 30), | 123 assertGet(ChannelInfo('beta', CANNED_BRANCHES[30], 30), |
| 124 'declarativeWebRequest') | 124 'declarativeWebRequest') |
| 125 | 125 |
| 126 # Testing APIs found only by checking file system existence. | 126 # Testing APIs found only by checking file system existence. |
| 127 assertGet(ChannelInfo('stable', CANNED_BRANCHES[23], 23), 'windows') | 127 assertGet(ChannelInfo('stable', CANNED_BRANCHES[23], 23), 'windows') |
| 128 assertGet(ChannelInfo('stable', CANNED_BRANCHES[18], 18), 'tabs') | 128 assertGet(ChannelInfo('stable', CANNED_BRANCHES[18], 18), 'tabs') |
| 129 assertGet(ChannelInfo('stable', CANNED_BRANCHES[18], 18), 'input.ime') | 129 assertGet(ChannelInfo('stable', CANNED_BRANCHES[18], 18), 'input.ime') |
| 130 | 130 |
| 131 # Testing API channel existence for _api_features.json. | 131 # Testing API channel existence for _api_features.json. |
| 132 # Listed as 'dev' on |beta|, 'dev' on |dev|. | 132 # Listed as 'dev' on |beta|, 'dev' on |dev|. |
| 133 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'systemInfo.stuff') | 133 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'systemInfo.stuff') |
| 134 # Listed as 'stable' on |beta|. | 134 # Listed as 'stable' on |beta|. |
| 135 assertGet(ChannelInfo('beta', CANNED_BRANCHES[30], 30), | 135 assertGet(ChannelInfo('beta', CANNED_BRANCHES[30], 30), |
| 136 'systemInfo.cpu', | 136 'systemInfo.cpu', |
| 137 scheduled=31) | 137 scheduled=31) |
| 138 | 138 |
| 139 # Testing API channel existence for _manifest_features.json. | 139 # Testing API channel existence for _manifest_features.json. |
| 140 # Listed as 'trunk' on all channels. | 140 # Listed as 'master' on all channels. |
| 141 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'sync') | 141 assertGet(ChannelInfo('master', 'master', 'master'), 'sync') |
| 142 # No records of API until |trunk|. | 142 # No records of API until |master|. |
| 143 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'history') | 143 assertGet(ChannelInfo('master', 'master', 'master'), 'history') |
| 144 # Listed as 'dev' on |dev|. | 144 # Listed as 'dev' on |dev|. |
| 145 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'storage') | 145 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'storage') |
| 146 # Stable in _manifest_features and into pre-18 versions. | 146 # Stable in _manifest_features and into pre-18 versions. |
| 147 assertGet(ChannelInfo('stable', CANNED_BRANCHES[8], 8), 'pageAction') | 147 assertGet(ChannelInfo('stable', CANNED_BRANCHES[8], 8), 'pageAction') |
| 148 | 148 |
| 149 # Testing API channel existence for _permission_features.json. | 149 # Testing API channel existence for _permission_features.json. |
| 150 # Listed as 'beta' on |trunk|. | 150 # Listed as 'beta' on |master|. |
| 151 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'falseBetaAPI') | 151 assertGet(ChannelInfo('master', 'master', 'master'), 'falseBetaAPI') |
| 152 # Listed as 'trunk' on |trunk|. | 152 # Listed as 'master' on |master|. |
| 153 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'trunkAPI') | 153 assertGet(ChannelInfo('master', 'master', 'master'), 'masterAPI') |
| 154 # Listed as 'trunk' on all development channels. | 154 # Listed as 'master' on all development channels. |
| 155 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'declarativeContent') | 155 assertGet(ChannelInfo('master', 'master', 'master'), 'declarativeContent') |
| 156 # Listed as 'dev' on all development channels. | 156 # Listed as 'dev' on all development channels. |
| 157 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'bluetooth') | 157 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'bluetooth') |
| 158 # Listed as 'dev' on |dev|. | 158 # Listed as 'dev' on |dev|. |
| 159 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'cookies') | 159 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'cookies') |
| 160 # Treated as 'stable' APIs. | 160 # Treated as 'stable' APIs. |
| 161 assertGet(ChannelInfo('stable', CANNED_BRANCHES[24], 24), 'alarms') | 161 assertGet(ChannelInfo('stable', CANNED_BRANCHES[24], 24), 'alarms') |
| 162 assertGet(ChannelInfo('stable', CANNED_BRANCHES[21], 21), 'bookmarks') | 162 assertGet(ChannelInfo('stable', CANNED_BRANCHES[21], 21), 'bookmarks') |
| 163 | 163 |
| 164 # Testing older API existence using extension_api.json. | 164 # Testing older API existence using extension_api.json. |
| 165 assertGet(ChannelInfo('stable', CANNED_BRANCHES[6], 6), 'menus') | 165 assertGet(ChannelInfo('stable', CANNED_BRANCHES[6], 6), 'menus') |
| 166 assertGet(ChannelInfo('stable', CANNED_BRANCHES[5], 5), 'idle') | 166 assertGet(ChannelInfo('stable', CANNED_BRANCHES[5], 5), 'idle') |
| 167 | 167 |
| 168 # Switches between _features.json files across branches. | 168 # Switches between _features.json files across branches. |
| 169 # Listed as 'trunk' on all channels, in _api, _permission, or _manifest. | 169 # Listed as 'master' on all channels, in _api, _permission, or _manifest. |
| 170 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'contextMenus') | 170 assertGet(ChannelInfo('master', 'master', 'master'), 'contextMenus') |
| 171 # Moves between _permission and _manifest as file system is traversed. | 171 # Moves between _permission and _manifest as file system is traversed. |
| 172 assertGet(ChannelInfo('stable', CANNED_BRANCHES[23], 23), | 172 assertGet(ChannelInfo('stable', CANNED_BRANCHES[23], 23), |
| 173 'systemInfo.display') | 173 'systemInfo.display') |
| 174 assertGet(ChannelInfo('stable', CANNED_BRANCHES[17], 17), 'webRequest') | 174 assertGet(ChannelInfo('stable', CANNED_BRANCHES[17], 17), 'webRequest') |
| 175 | 175 |
| 176 # Mid-upgrade cases: | 176 # Mid-upgrade cases: |
| 177 # Listed as 'dev' on |beta| and 'beta' on |dev|. | 177 # Listed as 'dev' on |beta| and 'beta' on |dev|. |
| 178 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'notifications') | 178 assertGet(ChannelInfo('dev', CANNED_BRANCHES[31], 31), 'notifications') |
| 179 # Listed as 'beta' on |stable|, 'dev' on |beta|...until |stable| on trunk. | 179 # Listed as 'beta' on |stable|, 'dev' on |beta|...until |stable| on master. |
| 180 assertGet(ChannelInfo('trunk', 'trunk', 'trunk'), 'events') | 180 assertGet(ChannelInfo('master', 'master', 'master'), 'events') |
| 181 | 181 |
| 182 # Check for differing availability across apps|extensions | 182 # Check for differing availability across apps|extensions |
| 183 assertGet(ChannelInfo('stable', CANNED_BRANCHES[26], 26), | 183 assertGet(ChannelInfo('stable', CANNED_BRANCHES[26], 26), |
| 184 'appsFirst', | 184 'appsFirst', |
| 185 only_on='extensions') | 185 only_on='extensions') |
| 186 assertGet(ChannelInfo('stable', CANNED_BRANCHES[25], 25), | 186 assertGet(ChannelInfo('stable', CANNED_BRANCHES[25], 25), |
| 187 'appsFirst', | 187 'appsFirst', |
| 188 only_on='apps') | 188 only_on='apps') |
| 189 | 189 |
| 190 def testGetAPINodeAvailability(self): | 190 def testGetAPINodeAvailability(self): |
| 191 def assertEquals(found, channel_info, actual, scheduled=None): | 191 def assertEquals(found, channel_info, actual, scheduled=None): |
| 192 lookup_result = api_schema_graph.LookupResult | 192 lookup_result = api_schema_graph.LookupResult |
| 193 if channel_info is None: | 193 if channel_info is None: |
| 194 self.assertEquals(lookup_result(found, None), actual) | 194 self.assertEquals(lookup_result(found, None), actual) |
| 195 else: | 195 else: |
| 196 self.assertEquals(lookup_result(found, AvailabilityInfo(channel_info, | 196 self.assertEquals(lookup_result(found, AvailabilityInfo(channel_info, |
| 197 scheduled=scheduled)), actual) | 197 scheduled=scheduled)), actual) |
| 198 | 198 |
| 199 for platform in GetPlatforms(): | 199 for platform in GetPlatforms(): |
| 200 # Allow the LookupResult constructions below to take just one line. | 200 # Allow the LookupResult constructions below to take just one line. |
| 201 avail_finder = self._create_availability_finder( | 201 avail_finder = self._create_availability_finder( |
| 202 self._node_fs_creator, | 202 self._node_fs_creator, |
| 203 self._node_fs_iterator, | 203 self._node_fs_iterator, |
| 204 platform) | 204 platform) |
| 205 tabs_graph = avail_finder.GetAPINodeAvailability('tabs') | 205 tabs_graph = avail_finder.GetAPINodeAvailability('tabs') |
| 206 fake_tabs_graph = avail_finder.GetAPINodeAvailability('fakeTabs') | 206 fake_tabs_graph = avail_finder.GetAPINodeAvailability('fakeTabs') |
| 207 | 207 |
| 208 assertEquals(True, self._branch_utility.GetChannelInfo('trunk'), | 208 assertEquals(True, self._branch_utility.GetChannelInfo('master'), |
| 209 tabs_graph.Lookup('tabs', 'properties', 'fakeTabsProperty3')) | 209 tabs_graph.Lookup('tabs', 'properties', 'fakeTabsProperty3')) |
| 210 assertEquals(True, self._branch_utility.GetChannelInfo('dev'), | 210 assertEquals(True, self._branch_utility.GetChannelInfo('dev'), |
| 211 tabs_graph.Lookup('tabs', 'events', 'onActivated', 'parameters', | 211 tabs_graph.Lookup('tabs', 'events', 'onActivated', 'parameters', |
| 212 'activeInfo', 'properties', 'windowId'), scheduled=31) | 212 'activeInfo', 'properties', 'windowId'), scheduled=31) |
| 213 assertEquals(True, self._branch_utility.GetChannelInfo('dev'), | 213 assertEquals(True, self._branch_utility.GetChannelInfo('dev'), |
| 214 tabs_graph.Lookup('tabs', 'events', 'onUpdated', 'parameters', 'tab'), | 214 tabs_graph.Lookup('tabs', 'events', 'onUpdated', 'parameters', 'tab'), |
| 215 scheduled=31) | 215 scheduled=31) |
| 216 assertEquals(True, self._branch_utility.GetChannelInfo('beta'), | 216 assertEquals(True, self._branch_utility.GetChannelInfo('beta'), |
| 217 tabs_graph.Lookup('tabs', 'events', 'onActivated'), scheduled=30) | 217 tabs_graph.Lookup('tabs', 'events', 'onActivated'), scheduled=30) |
| 218 assertEquals(True, self._branch_utility.GetChannelInfo('beta'), | 218 assertEquals(True, self._branch_utility.GetChannelInfo('beta'), |
| 219 tabs_graph.Lookup('tabs', 'functions', 'get', 'parameters', 'tabId'), | 219 tabs_graph.Lookup('tabs', 'functions', 'get', 'parameters', 'tabId'), |
| 220 scheduled=30) | 220 scheduled=30) |
| 221 assertEquals(True, self._branch_utility.GetChannelInfo('stable'), | 221 assertEquals(True, self._branch_utility.GetChannelInfo('stable'), |
| 222 tabs_graph.Lookup('tabs', 'types', 'InjectDetails', 'properties', | 222 tabs_graph.Lookup('tabs', 'types', 'InjectDetails', 'properties', |
| 223 'code')) | 223 'code')) |
| 224 assertEquals(True, self._branch_utility.GetChannelInfo('stable'), | 224 assertEquals(True, self._branch_utility.GetChannelInfo('stable'), |
| 225 tabs_graph.Lookup('tabs', 'types', 'InjectDetails', 'properties', | 225 tabs_graph.Lookup('tabs', 'types', 'InjectDetails', 'properties', |
| 226 'file')) | 226 'file')) |
| 227 assertEquals(True, self._branch_utility.GetStableChannelInfo(25), | 227 assertEquals(True, self._branch_utility.GetStableChannelInfo(25), |
| 228 tabs_graph.Lookup('tabs', 'types', 'InjectDetails')) | 228 tabs_graph.Lookup('tabs', 'types', 'InjectDetails')) |
| 229 | 229 |
| 230 # Test inlined type. | 230 # Test inlined type. |
| 231 assertEquals(True, self._branch_utility.GetChannelInfo('trunk'), | 231 assertEquals(True, self._branch_utility.GetChannelInfo('master'), |
| 232 tabs_graph.Lookup('tabs', 'types', 'InlinedType')) | 232 tabs_graph.Lookup('tabs', 'types', 'InlinedType')) |
| 233 | 233 |
| 234 # Test implicitly inlined type. | 234 # Test implicitly inlined type. |
| 235 assertEquals(True, self._branch_utility.GetStableChannelInfo(25), | 235 assertEquals(True, self._branch_utility.GetStableChannelInfo(25), |
| 236 fake_tabs_graph.Lookup('fakeTabs', 'types', | 236 fake_tabs_graph.Lookup('fakeTabs', 'types', |
| 237 'WasImplicitlyInlinedType')) | 237 'WasImplicitlyInlinedType')) |
| 238 | 238 |
| 239 # Test a node that was restricted to dev channel when it was introduced. | 239 # Test a node that was restricted to dev channel when it was introduced. |
| 240 assertEquals(True, self._branch_utility.GetChannelInfo('beta'), | 240 assertEquals(True, self._branch_utility.GetChannelInfo('beta'), |
| 241 tabs_graph.Lookup('tabs', 'functions', 'restrictedFunc'), | 241 tabs_graph.Lookup('tabs', 'functions', 'restrictedFunc'), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 'UpdateInfo')) | 286 'UpdateInfo')) |
| 287 assertEquals(False, None, tabs_graph.Lookup('tabs', 'functions', 'get', | 287 assertEquals(False, None, tabs_graph.Lookup('tabs', 'functions', 'get', |
| 288 'parameters', 'callback', 'parameters', 'tab', 'id')) | 288 'parameters', 'callback', 'parameters', 'tab', 'id')) |
| 289 assertEquals(False, None, tabs_graph.Lookup('functions')) | 289 assertEquals(False, None, tabs_graph.Lookup('functions')) |
| 290 assertEquals(False, None, tabs_graph.Lookup('events', 'onActivated', | 290 assertEquals(False, None, tabs_graph.Lookup('events', 'onActivated', |
| 291 'parameters', 'activeInfo', 'tabId')) | 291 'parameters', 'activeInfo', 'tabId')) |
| 292 | 292 |
| 293 | 293 |
| 294 if __name__ == '__main__': | 294 if __name__ == '__main__': |
| 295 unittest.main() | 295 unittest.main() |
| OLD | NEW |