OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 idl_schema | 6 import idl_schema |
7 import json_parse | 7 import json_parse |
8 from js_externs_generator import JsExternsGenerator | 8 from js_externs_generator import JsExternsGenerator |
9 from datetime import datetime | 9 from datetime import datetime |
10 import model | 10 import model |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 * @deprecated Use a new method. | 154 * @deprecated Use a new method. |
155 * @see https://developer.chrome.com/extensions/fakeApi#method-returnString | 155 * @see https://developer.chrome.com/extensions/fakeApi#method-returnString |
156 */ | 156 */ |
157 chrome.fakeApi.returnString = function() {}; | 157 chrome.fakeApi.returnString = function() {}; |
158 | 158 |
159 /** | 159 /** |
160 * Fired when we realize it's a trap! | 160 * Fired when we realize it's a trap! |
161 * @type {!ChromeEvent} | 161 * @type {!ChromeEvent} |
162 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected | 162 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected |
163 */ | 163 */ |
164 chrome.fakeApi.onTrapDetected; | 164 chrome.fakeApi.onTrapDetected;""" |
165 """ | |
166 | 165 |
167 | 166 |
168 fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved. | 167 fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved. |
169 // Use of this source code is governed by a BSD-style license that can be | 168 // Use of this source code is governed by a BSD-style license that can be |
170 // found in the LICENSE file. | 169 // found in the LICENSE file. |
171 | 170 |
172 [ | 171 [ |
173 { | 172 { |
174 "namespace": "fakeJson", | 173 "namespace": "fakeJson", |
175 "description": "Fake JSON API Stuff", | 174 "description": "Fake JSON API Stuff", |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 * description that causes problems! | 264 * description that causes problems! |
266 * @param {function({ | 265 * @param {function({ |
267 * str: string | 266 * str: string |
268 * }):void} callback The callback to this heinous method | 267 * }):void} callback The callback to this heinous method |
269 * @return {{ | 268 * @return {{ |
270 * str: string, | 269 * str: string, |
271 * int: number | 270 * int: number |
272 * }} | 271 * }} |
273 * @see https://developer.chrome.com/extensions/fakeJson#method-funcWithInlineOb
j | 272 * @see https://developer.chrome.com/extensions/fakeJson#method-funcWithInlineOb
j |
274 */ | 273 */ |
275 chrome.fakeJson.funcWithInlineObj = function(inlineObj, callback) {}; | 274 chrome.fakeJson.funcWithInlineObj = function(inlineObj, callback) {};""" |
276 """ | |
277 | 275 |
278 | 276 |
279 class JsExternGeneratorTest(unittest.TestCase): | 277 class JsExternGeneratorTest(unittest.TestCase): |
280 def _GetNamespace(self, fake_content, filename, is_idl): | 278 def _GetNamespace(self, fake_content, filename, is_idl): |
281 """Returns a namespace object for the given content""" | 279 """Returns a namespace object for the given content""" |
282 api_def = (idl_schema.Process(fake_content, filename) if is_idl | 280 api_def = (idl_schema.Process(fake_content, filename) if is_idl |
283 else json_parse.Parse(fake_content)) | 281 else json_parse.Parse(fake_content)) |
284 m = model.Model() | 282 m = model.Model() |
285 return m.AddNamespace(api_def[0], filename) | 283 return m.AddNamespace(api_def[0], filename) |
286 | 284 |
287 def setUp(self): | 285 def setUp(self): |
288 self.maxDiff = None # Lets us see the full diff when inequal. | 286 self.maxDiff = None # Lets us see the full diff when inequal. |
289 | 287 |
290 def testBasic(self): | 288 def testBasic(self): |
291 namespace = self._GetNamespace(fake_idl, 'fake_api.idl', True) | 289 namespace = self._GetNamespace(fake_idl, 'fake_api.idl', True) |
292 self.assertMultiLineEqual(expected_output, | 290 self.assertMultiLineEqual(expected_output, |
293 JsExternsGenerator().Generate(namespace).Render()) | 291 JsExternsGenerator().Generate(namespace).Render()) |
294 | 292 |
295 def testJsonWithInlineObjects(self): | 293 def testJsonWithInlineObjects(self): |
296 namespace = self._GetNamespace(fake_json, 'fake_api.json', False) | 294 namespace = self._GetNamespace(fake_json, 'fake_api.json', False) |
297 self.assertMultiLineEqual(json_expected, | 295 self.assertMultiLineEqual(json_expected, |
298 JsExternsGenerator().Generate(namespace).Render()) | 296 JsExternsGenerator().Generate(namespace).Render()) |
299 | 297 |
300 | 298 |
301 if __name__ == '__main__': | 299 if __name__ == '__main__': |
302 unittest.main() | 300 unittest.main() |
OLD | NEW |