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
4 # found in the LICENSE file.
9 from availability_finder import AvailabilityFinder
10 from api_schema_graph import LookupResult
11 from branch_utility import BranchUtility, ChannelInfo
12 from compiled_file_system import CompiledFileSystem
13 from fake_url_fetcher import FakeUrlFetcher
14 from host_file_system_iterator import HostFileSystemIterator
15 from object_store_creator import ObjectStoreCreator
16 from test_file_system import TestFileSystem
17 from test_data.canned_data import (CANNED_API_FILE_SYSTEM_DATA, CANNED_BRANCHES)
18 from test_data.object_level_availability.tabs import TABS_SCHEMA_BRANCHES
21 class FakeHostFileSystemProvider(object):
23 def __init__(self, file_system_data):
24 self._file_system_data = file_system_data
27 return self.GetBranch('trunk')
29 def GetBranch(self, branch):
30 return TestFileSystem(self._file_system_data[str(branch)])
33 class AvailabilityFinderTest(unittest.TestCase):
36 self._branch_utility = BranchUtility(
37 os.path.join('branch_utility', 'first.json'),
38 os.path.join('branch_utility', 'second.json'),
39 FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')),
40 ObjectStoreCreator.ForTest())
42 def create_availability_finder(file_system_data):
43 fake_host_fs_creator = FakeHostFileSystemProvider(file_system_data)
44 test_object_store = ObjectStoreCreator.ForTest()
45 return AvailabilityFinder(self._branch_utility,
46 CompiledFileSystem.Factory(test_object_store),
47 HostFileSystemIterator(fake_host_fs_creator,
48 self._branch_utility),
49 fake_host_fs_creator.GetTrunk(),
52 self._avail_finder = create_availability_finder(CANNED_API_FILE_SYSTEM_DATA)
53 self._node_avail_finder = create_availability_finder(TABS_SCHEMA_BRANCHES)
55 def testGetApiAvailability(self):
56 # Key: Using 'channel' (i.e. 'beta') to represent an availability listing
57 # for an API in a _features.json file, and using |channel| (i.e. |dev|) to
58 # represent the development channel, or phase of development, where an API's
59 # availability is being checked.
61 # Testing a whitelisted API.
63 ChannelInfo('beta', CANNED_BRANCHES[27], 27),
64 self._avail_finder.GetApiAvailability('declarativeWebRequest'))
66 # Testing APIs found only by checking file system existence.
68 ChannelInfo('stable', CANNED_BRANCHES[23], 23),
69 self._avail_finder.GetApiAvailability('windows'))
71 ChannelInfo('stable', CANNED_BRANCHES[18], 18),
72 self._avail_finder.GetApiAvailability('tabs'))
74 ChannelInfo('stable', CANNED_BRANCHES[18], 18),
75 self._avail_finder.GetApiAvailability('input.ime'))
77 # Testing API channel existence for _api_features.json.
78 # Listed as 'dev' on |beta|, 'dev' on |dev|.
80 ChannelInfo('dev', CANNED_BRANCHES[28], 28),
81 self._avail_finder.GetApiAvailability('systemInfo.stuff'))
82 # Listed as 'stable' on |beta|.
84 ChannelInfo('beta', CANNED_BRANCHES[27], 27),
85 self._avail_finder.GetApiAvailability('systemInfo.cpu'))
87 # Testing API channel existence for _manifest_features.json.
88 # Listed as 'trunk' on all channels.
90 ChannelInfo('trunk', 'trunk', 'trunk'),
91 self._avail_finder.GetApiAvailability('sync'))
92 # No records of API until |trunk|.
94 ChannelInfo('trunk', 'trunk', 'trunk'),
95 self._avail_finder.GetApiAvailability('history'))
96 # Listed as 'dev' on |dev|.
98 ChannelInfo('dev', CANNED_BRANCHES[28], 28),
99 self._avail_finder.GetApiAvailability('storage'))
100 # Stable in _manifest_features and into pre-18 versions.
102 ChannelInfo('stable', CANNED_BRANCHES[8], 8),
103 self._avail_finder.GetApiAvailability('pageAction'))
105 # Testing API channel existence for _permission_features.json.
106 # Listed as 'beta' on |trunk|.
108 ChannelInfo('trunk', 'trunk', 'trunk'),
109 self._avail_finder.GetApiAvailability('falseBetaAPI'))
110 # Listed as 'trunk' on |trunk|.
112 ChannelInfo('trunk', 'trunk', 'trunk'),
113 self._avail_finder.GetApiAvailability('trunkAPI'))
114 # Listed as 'trunk' on all development channels.
116 ChannelInfo('trunk', 'trunk', 'trunk'),
117 self._avail_finder.GetApiAvailability('declarativeContent'))
118 # Listed as 'dev' on all development channels.
120 ChannelInfo('dev', CANNED_BRANCHES[28], 28),
121 self._avail_finder.GetApiAvailability('bluetooth'))
122 # Listed as 'dev' on |dev|.
124 ChannelInfo('dev', CANNED_BRANCHES[28], 28),
125 self._avail_finder.GetApiAvailability('cookies'))
126 # Treated as 'stable' APIs.
128 ChannelInfo('stable', CANNED_BRANCHES[24], 24),
129 self._avail_finder.GetApiAvailability('alarms'))
131 ChannelInfo('stable', CANNED_BRANCHES[21], 21),
132 self._avail_finder.GetApiAvailability('bookmarks'))
134 # Testing older API existence using extension_api.json.
136 ChannelInfo('stable', CANNED_BRANCHES[6], 6),
137 self._avail_finder.GetApiAvailability('menus'))
139 ChannelInfo('stable', CANNED_BRANCHES[5], 5),
140 self._avail_finder.GetApiAvailability('idle'))
142 # Switches between _features.json files across branches.
143 # Listed as 'trunk' on all channels, in _api, _permission, or _manifest.
145 ChannelInfo('trunk', 'trunk', 'trunk'),
146 self._avail_finder.GetApiAvailability('contextMenus'))
147 # Moves between _permission and _manifest as file system is traversed.
149 ChannelInfo('stable', CANNED_BRANCHES[23], 23),
150 self._avail_finder.GetApiAvailability('systemInfo.display'))
152 ChannelInfo('stable', CANNED_BRANCHES[17], 17),
153 self._avail_finder.GetApiAvailability('webRequest'))
156 # Listed as 'dev' on |beta| and 'beta' on |dev|.
158 ChannelInfo('dev', CANNED_BRANCHES[28], 28),
159 self._avail_finder.GetApiAvailability('notifications'))
160 # Listed as 'beta' on |stable|, 'dev' on |beta| ... until |stable| on trunk.
162 ChannelInfo('trunk', 'trunk', 'trunk'),
163 self._avail_finder.GetApiAvailability('events'))
165 def testGetApiNodeAvailability(self):
166 availability_graph = self._node_avail_finder.GetApiNodeAvailability('tabs')
169 LookupResult(True, self._branch_utility.GetChannelInfo('trunk')),
170 availability_graph.Lookup('tabs', 'properties',
171 'fakeTabsProperty3'))
173 LookupResult(True, self._branch_utility.GetChannelInfo('dev')),
174 availability_graph.Lookup('tabs', 'events', 'onActivated',
175 'parameters', 'activeInfo', 'properties',
178 LookupResult(True, self._branch_utility.GetChannelInfo('dev')),
179 availability_graph.Lookup('tabs', 'events', 'onUpdated', 'parameters',
182 LookupResult(True, self._branch_utility.GetChannelInfo('beta')),
183 availability_graph.Lookup('tabs', 'events','onActivated'))
185 LookupResult(True, self._branch_utility.GetChannelInfo('beta')),
186 availability_graph.Lookup('tabs', 'functions', 'get', 'parameters',
189 LookupResult(True, self._branch_utility.GetChannelInfo('stable')),
190 availability_graph.Lookup('tabs', 'types', 'InjectDetails',
191 'properties', 'code'))
193 LookupResult(True, self._branch_utility.GetChannelInfo('stable')),
194 availability_graph.Lookup('tabs', 'types', 'InjectDetails',
195 'properties', 'file'))
197 LookupResult(True, self._branch_utility.GetStableChannelInfo(25)),
198 availability_graph.Lookup('tabs', 'types', 'InjectDetails'))
200 # Nothing new in version 24 or 23.
203 LookupResult(True, self._branch_utility.GetStableChannelInfo(22)),
204 availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
207 LookupResult(True, self._branch_utility.GetStableChannelInfo(21)),
208 availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
211 # Nothing new in version 20.
214 LookupResult(True, self._branch_utility.GetStableChannelInfo(19)),
215 availability_graph.Lookup('tabs', 'functions', 'getCurrent'))
217 LookupResult(True, self._branch_utility.GetStableChannelInfo(18)),
218 availability_graph.Lookup('tabs', 'types', 'Tab', 'properties',
221 LookupResult(True, self._branch_utility.GetStableChannelInfo(17)),
222 availability_graph.Lookup('tabs', 'events', 'onUpdated', 'parameters',
225 # Nothing new in version 16.
228 LookupResult(True, self._branch_utility.GetStableChannelInfo(15)),
229 availability_graph.Lookup('tabs', 'properties',
230 'fakeTabsProperty2'))
232 # Everything else is available at the API's release, version 14 here.
234 LookupResult(True, self._branch_utility.GetStableChannelInfo(14)),
235 availability_graph.Lookup('tabs', 'types', 'Tab'))
237 LookupResult(True, self._branch_utility.GetStableChannelInfo(14)),
238 availability_graph.Lookup('tabs', 'types', 'Tab',
239 'properties', 'url'))
241 LookupResult(True, self._branch_utility.GetStableChannelInfo(14)),
242 availability_graph.Lookup('tabs', 'properties',
243 'fakeTabsProperty1'))
245 LookupResult(True, self._branch_utility.GetStableChannelInfo(14)),
246 availability_graph.Lookup('tabs', 'functions', 'get', 'parameters',
249 LookupResult(True, self._branch_utility.GetStableChannelInfo(14)),
250 availability_graph.Lookup('tabs', 'events', 'onUpdated'))
252 # Test things that aren't available.
253 self.assertEqual(LookupResult(False, None),
254 availability_graph.Lookup('tabs', 'types',
256 self.assertEqual(LookupResult(False, None),
257 availability_graph.Lookup('tabs', 'functions', 'get',
258 'parameters', 'callback',
259 'parameters', 'tab', 'id'))
260 self.assertEqual(LookupResult(False, None),
261 availability_graph.Lookup('functions'))
262 self.assertEqual(LookupResult(False, None),
263 availability_graph.Lookup('events', 'onActivated',
264 'parameters', 'activeInfo',
268 if __name__ == '__main__':