OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 | 5 |
6 import json | 6 import json |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 import unittest | 9 import unittest |
10 | 10 |
11 from api_data_source import (_JSCModel, | 11 from api_data_source import (_JSCModel, |
12 _FormatValue, | 12 _FormatValue, |
13 _GetEventByNameFromEvents) | 13 _GetEventByNameFromEvents) |
14 from api_models import ContentScriptAPI | |
14 from api_schema_graph import APISchemaGraph | 15 from api_schema_graph import APISchemaGraph |
15 from availability_finder import AvailabilityFinder, AvailabilityInfo | 16 from availability_finder import AvailabilityFinder, AvailabilityInfo |
16 from branch_utility import BranchUtility, ChannelInfo | 17 from branch_utility import BranchUtility, ChannelInfo |
17 from compiled_file_system import CompiledFileSystem | 18 from compiled_file_system import CompiledFileSystem |
18 from extensions_paths import CHROME_EXTENSIONS | 19 from extensions_paths import CHROME_EXTENSIONS |
19 from fake_host_file_system_provider import FakeHostFileSystemProvider | 20 from fake_host_file_system_provider import FakeHostFileSystemProvider |
20 from fake_url_fetcher import FakeUrlFetcher | 21 from fake_url_fetcher import FakeUrlFetcher |
21 from features_bundle import FeaturesBundle | 22 from features_bundle import FeaturesBundle |
22 from file_system import FileNotFoundError | 23 from file_system import FileNotFoundError |
23 from future import Future | 24 from future import Future |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 events['types'][0]['functions'].append(add_rules) | 128 events['types'][0]['functions'].append(add_rules) |
128 self.assertEqual(add_rules, | 129 self.assertEqual(add_rules, |
129 _GetEventByNameFromEvents(events)['addRules']) | 130 _GetEventByNameFromEvents(events)['addRules']) |
130 | 131 |
131 events['types'][0]['functions'].append(add_rules) | 132 events['types'][0]['functions'].append(add_rules) |
132 # Duplicates are an error. | 133 # Duplicates are an error. |
133 self.assertRaises(AssertionError, _GetEventByNameFromEvents, events) | 134 self.assertRaises(AssertionError, _GetEventByNameFromEvents, events) |
134 | 135 |
135 def testCreateId(self): | 136 def testCreateId(self): |
136 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 137 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
137 dict_ = _JSCModel(self._api_models.GetModel('tester').Get(), | 138 dict_ = _JSCModel(self._api_models, |
139 self._api_models.GetModel('tester').Get(), | |
138 fake_avail_finder, | 140 fake_avail_finder, |
139 self._json_cache, | 141 self._json_cache, |
140 _FakeTemplateCache(), | 142 _FakeTemplateCache(), |
141 self._features_bundle, | 143 self._features_bundle, |
142 None).ToDict() | 144 None).ToDict() |
143 self.assertEquals('type-TypeA', dict_['types'][0]['id']) | 145 self.assertEquals('type-TypeA', dict_['types'][0]['id']) |
144 self.assertEquals('property-TypeA-b', | 146 self.assertEquals('property-TypeA-b', |
145 dict_['types'][0]['properties'][0]['id']) | 147 dict_['types'][0]['properties'][0]['id']) |
146 self.assertEquals('method-get', dict_['functions'][0]['id']) | 148 self.assertEquals('method-get', dict_['functions'][0]['id']) |
147 self.assertEquals('event-EventA', dict_['events'][0]['id']) | 149 self.assertEquals('event-EventA', dict_['events'][0]['id']) |
148 | 150 |
149 # TODO(kalman): re-enable this when we have a rebase option. | 151 # TODO(kalman): re-enable this when we have a rebase option. |
150 def DISABLED_testToDict(self): | 152 def DISABLED_testToDict(self): |
151 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 153 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
152 expected_json = self._LoadJSON('expected_tester.json') | 154 expected_json = self._LoadJSON('expected_tester.json') |
153 dict_ = _JSCModel(self._api_models.GetModel('tester').Get(), | 155 dict_ = _JSCModel(self._api_models, |
156 self._api_models.GetModel('tester').Get(), | |
154 fake_avail_finder, | 157 fake_avail_finder, |
155 self._json_cache, | 158 self._json_cache, |
156 _FakeTemplateCache(), | 159 _FakeTemplateCache(), |
157 self._features_bundle, | 160 self._features_bundle, |
158 None).ToDict() | 161 None).ToDict() |
159 self.assertEquals(expected_json, dict_) | 162 self.assertEquals(expected_json, dict_) |
160 | 163 |
161 def testAddRules(self): | 164 def testAddRules(self): |
162 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 165 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
163 dict_ = _JSCModel(self._api_models.GetModel('add_rules_tester').Get(), | 166 dict_ = _JSCModel(self._api_models, |
167 self._api_models.GetModel('add_rules_tester').Get(), | |
164 fake_avail_finder, | 168 fake_avail_finder, |
165 #self._fake_availability, | 169 #self._fake_availability, |
166 self._json_cache, | 170 self._json_cache, |
167 _FakeTemplateCache(), | 171 _FakeTemplateCache(), |
168 self._features_bundle, | 172 self._features_bundle, |
169 self._FakeLoadAddRulesSchema()).ToDict() | 173 self._FakeLoadAddRulesSchema()).ToDict() |
170 | 174 |
171 # Check that the first event has the addRulesFunction defined. | 175 # Check that the first event has the addRulesFunction defined. |
172 self.assertEquals('add_rules_tester', dict_['name']) | 176 self.assertEquals('add_rules_tester', dict_['name']) |
173 self.assertEquals('rules', dict_['events'][0]['name']) | 177 self.assertEquals('rules', dict_['events'][0]['name']) |
174 self.assertEquals('notable_name_to_check_for', | 178 self.assertEquals('notable_name_to_check_for', |
175 dict_['events'][0]['byName']['addRules'][ | 179 dict_['events'][0]['byName']['addRules'][ |
176 'parameters'][0]['name']) | 180 'parameters'][0]['name']) |
177 | 181 |
178 # Check that the second event has addListener defined. | 182 # Check that the second event has addListener defined. |
179 self.assertEquals('noRules', dict_['events'][1]['name']) | 183 self.assertEquals('noRules', dict_['events'][1]['name']) |
180 self.assertEquals('add_rules_tester', dict_['name']) | 184 self.assertEquals('add_rules_tester', dict_['name']) |
181 self.assertEquals('noRules', dict_['events'][1]['name']) | 185 self.assertEquals('noRules', dict_['events'][1]['name']) |
182 self.assertEquals('callback', | 186 self.assertEquals('callback', |
183 dict_['events'][0]['byName']['addListener'][ | 187 dict_['events'][0]['byName']['addListener'][ |
184 'parameters'][0]['name']) | 188 'parameters'][0]['name']) |
185 | 189 |
186 def testGetIntroList(self): | 190 def testGetIntroList(self): |
187 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) | 191 fake_avail_finder = _FakeAvailabilityFinder(self._fake_availability) |
188 model = _JSCModel(self._api_models.GetModel('tester').Get(), | 192 model = _JSCModel(self._api_models, |
193 self._api_models.GetModel('tester').Get(), | |
189 fake_avail_finder, | 194 fake_avail_finder, |
190 self._json_cache, | 195 self._json_cache, |
191 _FakeTemplateCache(), | 196 _FakeTemplateCache(), |
192 self._features_bundle, | 197 self._features_bundle, |
193 None) | 198 None) |
199 expected_content_script_support = ContentScriptAPI('tester') | |
194 expected_list = [ | 200 expected_list = [ |
195 { 'title': 'Description', | 201 { 'title': 'Description', |
196 'content': [ | 202 'content': [ |
197 { 'text': 'a test api' } | 203 { 'text': 'a test api' } |
198 ] | 204 ] |
199 }, | 205 }, |
200 { 'title': 'Availability', | 206 { 'title': 'Availability', |
201 'content': [ | 207 'content': [ |
202 { 'partial': 'handlebar chrome/common/extensions/docs/' + | 208 { 'partial': 'handlebar chrome/common/extensions/docs/' + |
203 'templates/private/intro_tables/stable_message.html', | 209 'templates/private/intro_tables/stable_message.html', |
(...skipping 10 matching lines...) Expand all Loading... | |
214 { 'text': 'is an API for testing things.' } | 220 { 'text': 'is an API for testing things.' } |
215 ] | 221 ] |
216 }, | 222 }, |
217 { 'title': 'Manifest', | 223 { 'title': 'Manifest', |
218 'content': [ | 224 'content': [ |
219 { 'class': 'code', | 225 { 'class': 'code', |
220 'text': '"tester": {...}' | 226 'text': '"tester": {...}' |
221 } | 227 } |
222 ] | 228 ] |
223 }, | 229 }, |
230 { 'title': 'Content Scripts', | |
231 'content': [ | |
232 { | |
233 'partial': 'handlebar chrome/common/extensions/docs' + | |
234 '/templates/private/intro_tables/content_scripts.html', | |
235 'contentScriptSupport': expected_content_script_support.__dict__ | |
not at google - send to devlin
2014/07/15 21:34:39
I'd rather you test the dict output directly rathe
| |
236 } | |
237 ] | |
238 }, | |
224 { 'title': 'Learn More', | 239 { 'title': 'Learn More', |
225 'content': [ | 240 'content': [ |
226 { 'link': 'https://tester.test.com/welcome.html', | 241 { 'link': 'https://tester.test.com/welcome.html', |
227 'text': 'Welcome!' | 242 'text': 'Welcome!' |
228 } | 243 } |
229 ] | 244 ] |
230 } | 245 } |
231 ] | 246 ] |
232 self.assertEquals(model._GetIntroTableList(), expected_list) | 247 self.assertEquals(model._GetIntroTableList(), expected_list) |
233 | 248 |
234 # Tests the same data with a scheduled availability. | 249 # Tests the same data with a scheduled availability. |
235 fake_avail_finder = _FakeAvailabilityFinder( | 250 fake_avail_finder = _FakeAvailabilityFinder( |
236 AvailabilityInfo(ChannelInfo('beta', '1453', 27), scheduled=28)) | 251 AvailabilityInfo(ChannelInfo('beta', '1453', 27), scheduled=28)) |
237 model = _JSCModel(self._api_models.GetModel('tester').Get(), | 252 model = _JSCModel(self._api_models, |
238 fake_avail_finder, | 253 self._api_models.GetModel('tester').Get(), |
239 self._json_cache, | 254 fake_avail_finder, |
240 _FakeTemplateCache(), | 255 self._json_cache, |
241 self._features_bundle, | 256 _FakeTemplateCache(), |
242 None) | 257 self._features_bundle, |
258 None) | |
243 expected_list[1] = { | 259 expected_list[1] = { |
244 'title': 'Availability', | 260 'title': 'Availability', |
245 'content': [ | 261 'content': [ |
246 { 'partial': 'handlebar chrome/common/extensions/docs/' + | 262 { 'partial': 'handlebar chrome/common/extensions/docs/' + |
247 'templates/private/intro_tables/beta_message.html', | 263 'templates/private/intro_tables/beta_message.html', |
248 'version': 27, | 264 'version': 27, |
249 'scheduled': 28 | 265 'scheduled': 28 |
250 } | 266 } |
251 ] | 267 ] |
252 } | 268 } |
(...skipping 17 matching lines...) Expand all Loading... | |
270 api_availabilities = { | 286 api_availabilities = { |
271 'bluetooth': 28, | 287 'bluetooth': 28, |
272 'contextMenus': 'trunk', | 288 'contextMenus': 'trunk', |
273 'jsonStableAPI': 20, | 289 'jsonStableAPI': 20, |
274 'idle': 5, | 290 'idle': 5, |
275 'input.ime': 18, | 291 'input.ime': 18, |
276 'tabs': 18 | 292 'tabs': 18 |
277 } | 293 } |
278 for api_name, availability in api_availabilities.iteritems(): | 294 for api_name, availability in api_availabilities.iteritems(): |
279 model_dict = _JSCModel( | 295 model_dict = _JSCModel( |
296 self._api_models, | |
280 self._api_models.GetModel(api_name).Get(), | 297 self._api_models.GetModel(api_name).Get(), |
281 self._avail_finder, | 298 self._avail_finder, |
282 self._json_cache, | 299 self._json_cache, |
283 _FakeTemplateCache(), | 300 _FakeTemplateCache(), |
284 _FakeFeaturesBundle(), | 301 _FakeFeaturesBundle(), |
285 None).ToDict() | 302 None).ToDict() |
286 self.assertEquals(availability, | 303 self.assertEquals(availability, |
287 model_dict['introList'][1]['content'][0]['version']) | 304 model_dict['introList'][1]['content'][0]['version']) |
288 | 305 |
289 | 306 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 | 354 |
338 def testGetAPINodeAvailability(self): | 355 def testGetAPINodeAvailability(self): |
339 def assertEquals(node, actual): | 356 def assertEquals(node, actual): |
340 node_availabilities = { | 357 node_availabilities = { |
341 'tabs.get': None, | 358 'tabs.get': None, |
342 'tabs.getCurrent': 19 | 359 'tabs.getCurrent': 19 |
343 } | 360 } |
344 self.assertEquals(node_availabilities[node], actual) | 361 self.assertEquals(node_availabilities[node], actual) |
345 | 362 |
346 model_dict = _JSCModel( | 363 model_dict = _JSCModel( |
364 self._api_models, | |
347 self._api_models.GetModel('tabs').Get(), | 365 self._api_models.GetModel('tabs').Get(), |
348 self._avail_finder, | 366 self._avail_finder, |
349 self._json_cache, | 367 self._json_cache, |
350 _FakeTemplateCache(), | 368 _FakeTemplateCache(), |
351 _FakeFeaturesBundle(), | 369 _FakeFeaturesBundle(), |
352 None).ToDict() | 370 None).ToDict() |
353 | 371 |
354 # Test nodes that have the same availability as their parent. | 372 # Test nodes that have the same availability as their parent. |
355 assertEquals('tabs.get', model_dict['functions'][1]['availability']) | 373 assertEquals('tabs.get', model_dict['functions'][1]['availability']) |
356 # Test nodes with varying availabilities. | 374 # Test nodes with varying availabilities. |
357 assertEquals('tabs.getCurrent', | 375 assertEquals('tabs.getCurrent', |
358 model_dict['functions'][0]['availability']['version']) | 376 model_dict['functions'][0]['availability']['version']) |
359 | 377 |
360 | 378 |
361 if __name__ == '__main__': | 379 if __name__ == '__main__': |
362 unittest.main() | 380 unittest.main() |
OLD | NEW |