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