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 api_list_data_source import APIListDataSource
10 from api_models import ContentScriptAPI
11 from extensions_paths import CHROME_EXTENSIONS
12 from server_instance import ServerInstance
13 from test_file_system import TestFileSystem
17 '''Transforms |obj| into test data by turning a list of files into an object
18 mapping that file to its contents (derived from its name).
20 return dict((name, name) for name in obj)
23 def _ToTestFeatures(names):
24 '''Transforms a list of strings into a minimal JSON features object.
26 def platforms_to_extension_types(platforms):
27 return ['platform_app' if platform == 'apps' else 'extension'
28 for platform in platforms]
29 features = dict((name, {
31 'extension_types': platforms_to_extension_types(platforms),
33 }) for name, platforms, context in names)
34 features['sockets.udp']['channel'] = 'dev'
38 def _ToTestAPIData(names):
39 api_data = dict((name, [{'namespace': name, 'description': description}])
40 for name, description in names)
44 def _ToTestAPISchema(names, apis):
45 for name, json_file in names:
46 apis['api'][json_file] = json.dumps(_TEST_API_DATA[name])
50 _TEST_API_FEATURES = _ToTestFeatures([
51 ('alarms', ['apps', 'extensions'], ['content_script']),
52 ('app.window', ['apps'], []),
53 ('browserAction', ['extensions'], []),
54 ('experimental.bluetooth', ['apps'], []),
55 ('experimental.history', ['extensions'], []),
56 ('experimental.power', ['apps', 'extensions'], []),
57 ('extension', ['extensions'], ['content_script']),
58 ('extension.onRequest', ['extensions'], ['content_script']),
59 ('extension.sendNativeMessage', ['extensions'], []),
60 ('extension.sendRequest', ['extensions'], ['content_script']),
61 ('infobars', ['extensions'], []),
62 ('something_internal', ['apps'], []),
63 ('something_else_internal', ['extensions'], []),
64 ('storage', ['apps', 'extensions'], []),
65 ('sockets.udp', ['apps', 'extensions'], [])
69 _TEST_API_DATA = _ToTestAPIData([
70 ('alarms', u'<code>alarms</code>'),
71 ('app.window', u'<code>app.window</code>'),
72 ('browserAction', u'<code>browserAction</code>'),
73 ('experimental.bluetooth', u'<code>experimental.bluetooth</code>'),
74 ('experimental.history', u'<code>experimental.history</code>'),
75 ('experimental.power', u'<code>experimental.power</code>'),
76 ('extension', u'<code>extension</code>'),
77 ('infobars', u'<code>infobars</code>'),
78 ('something_internal', u'<code>something_internal</code>'),
79 ('something_else_internal', u'<code>something_else_internal</code>'),
80 ('storage', u'<code>storage</code>'),
81 ('sockets.udp', u'<code>sockets.udp</code>')
86 ('alarms', 'alarms.json'),
87 ('app.window', 'app_window.json'),
88 ('browserAction', 'browser_action.json'),
89 ('experimental.bluetooth', 'experimental_bluetooth.json'),
90 ('experimental.history', 'experimental_history.json'),
91 ('experimental.power', 'experimental_power.json'),
92 ('extension', 'extension.json'),
93 ('infobars', 'infobars.json'),
94 ('something_internal', 'something_internal.json'),
95 ('something_else_internal', 'something_else_internal.json'),
96 ('storage', 'storage.json'),
97 ('sockets.udp', 'sockets_udp.json')
101 _TEST_DATA = _ToTestAPISchema(_TEST_API_SCHEMA, {
103 '_api_features.json': json.dumps(_TEST_API_FEATURES),
104 '_manifest_features.json': '{}',
105 '_permission_features.json': '{}',
110 'api_availabilities.json': '{}',
111 'manifest.json': '{}',
112 'permissions.json': '{}',
115 'apps': _ToTestData([
118 'experimental_bluetooth.html',
119 'experimental_power.html',
123 'extensions': _ToTestData([
125 'browserAction.html',
126 'experimental_history.html',
127 'experimental_power.html',
139 class APIListDataSourceTest(unittest.TestCase):
141 server_instance = ServerInstance.ForTest(
142 TestFileSystem(_TEST_DATA, relative_to=CHROME_EXTENSIONS))
143 # APIListDataSource takes a request but doesn't use it,
145 self._api_list = APIListDataSource(server_instance, None)
154 'description': u'<code>alarms</code>'
157 'name': 'app.window',
158 # Availability logic will look for a camelCase format filename
159 # (i.e. 'app.window.html') at version 20 and below, but the
160 # unix_name format above won't be found at these versions.
162 'description': u'<code>app.window</code>'
168 'description': u'<code>storage</code>'
172 'name': 'sockets.udp',
174 'description': u'<code>sockets.udp</code>'
178 }, self._api_list.get('apps').get('chrome'))
180 def testExperimentalApps(self):
183 'name': 'experimental.bluetooth',
184 'description': u'<code>experimental.bluetooth</code>'
187 'name': 'experimental.power',
189 'description': u'<code>experimental.power</code>'
190 }], self._api_list.get('apps').get('experimental'))
192 def testExtensions(self):
198 'description': u'<code>alarms</code>'
201 'name': 'browserAction',
202 # See comment above for 'app.window'.
204 'description': u'<code>browserAction</code>'
209 'description': u'<code>extension</code>'
214 'description': u'<code>infobars</code>'
220 'description': u'<code>storage</code>'
224 'name': 'sockets.udp',
226 'description': u'<code>sockets.udp</code>'
230 }, self._api_list.get('extensions').get('chrome'))
232 def testExperimentalExtensions(self):
235 'name': 'experimental.history',
236 'description': u'<code>experimental.history</code>'
239 'name': 'experimental.power',
240 'description': u'<code>experimental.power</code>',
242 }], self._api_list.get('extensions').get('experimental'))
244 def testContentScripts(self):
255 'node': 'sendRequest',
258 }], self._api_list.get('contentScripts'))
260 if __name__ == '__main__':