Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: tools/json_schema_compiler/js_externs_generator_test.py

Issue 2766363002: [Closure Externs] Handle optional params sent to an API callback (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 object dict; 56 object dict;
57 57
58 static void go(); 58 static void go();
59 static void stop(); 59 static void stop();
60 }; 60 };
61 61
62 callback VoidCallback = void(); 62 callback VoidCallback = void();
63 63
64 callback BazGreekCallback = void(Baz baz, Greek greek); 64 callback BazGreekCallback = void(Baz baz, Greek greek);
65 65
66 callback OptionalParamCallback = void(optional Qux qux);
67
66 interface Functions { 68 interface Functions {
67 // Does something exciting! And what's more, this is a multiline function 69 // Does something exciting! And what's more, this is a multiline function
68 // comment! It goes onto multiple lines! 70 // comment! It goes onto multiple lines!
69 // |baz| : The baz to use. 71 // |baz| : The baz to use.
70 static void doSomething(Baz baz, VoidCallback callback); 72 static void doSomething(Baz baz, VoidCallback callback);
71 73
72 // |callback| : The callback which will most assuredly in all cases be 74 // |callback| : The callback which will most assuredly in all cases be
73 // called; that is, of course, iff such a callback was provided and is 75 // called; that is, of course, iff such a callback was provided and is
74 // not at all null. 76 // not at all null.
75 static void bazGreek(optional BazGreekCallback callback); 77 static void bazGreek(optional BazGreekCallback callback);
76 78
77 [deprecated="Use a new method."] static DOMString returnString(); 79 [deprecated="Use a new method."] static DOMString returnString();
80
81 static void optionalParam(optional OptionalParamCallback callback);
78 }; 82 };
79 83
80 interface Events { 84 interface Events {
81 // Fired when we realize it's a trap! 85 // Fired when we realize it's a trap!
82 static void onTrapDetected(Baz baz); 86 static void onTrapDetected(Baz baz);
83 }; 87 };
84 }; 88 };
85 """ 89 """
86 90
87 # The output we expect from our fake idl file. 91 # The output we expect from our fake idl file.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 chrome.fakeApi.bazGreek = function(callback) {}; 202 chrome.fakeApi.bazGreek = function(callback) {};
199 203
200 /** 204 /**
201 * @return {string} 205 * @return {string}
202 * @deprecated Use a new method. 206 * @deprecated Use a new method.
203 * @see https://developer.chrome.com/extensions/fakeApi#method-returnString 207 * @see https://developer.chrome.com/extensions/fakeApi#method-returnString
204 */ 208 */
205 chrome.fakeApi.returnString = function() {}; 209 chrome.fakeApi.returnString = function() {};
206 210
207 /** 211 /**
212 * @param {function(!chrome.fakeApi.Qux|undefined):void=} callback
213 * @see https://developer.chrome.com/extensions/fakeApi#method-optionalParam
214 */
215 chrome.fakeApi.optionalParam = function(callback) {};
216
217 /**
208 * Fired when we realize it's a trap! 218 * Fired when we realize it's a trap!
209 * @type {!ChromeEvent} 219 * @type {!ChromeEvent}
210 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected 220 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected
211 */ 221 */
212 chrome.fakeApi.onTrapDetected;""" % (datetime.now().year, sys.argv[0])) 222 chrome.fakeApi.onTrapDetected;""" % (datetime.now().year, sys.argv[0]))
213 223
214 224
215 fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved. 225 fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved.
216 // Use of this source code is governed by a BSD-style license that can be 226 // Use of this source code is governed by a BSD-style license that can be
217 // found in the LICENSE file. 227 // found in the LICENSE file.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 JsExternsGenerator().Generate(namespace).Render()) 365 JsExternsGenerator().Generate(namespace).Render())
356 366
357 def testJsonWithInlineObjects(self): 367 def testJsonWithInlineObjects(self):
358 namespace = self._GetNamespace(fake_json, 'fake_api.json', False) 368 namespace = self._GetNamespace(fake_json, 'fake_api.json', False)
359 self.assertMultiLineEqual(json_expected, 369 self.assertMultiLineEqual(json_expected,
360 JsExternsGenerator().Generate(namespace).Render()) 370 JsExternsGenerator().Generate(namespace).Render())
361 371
362 372
363 if __name__ == '__main__': 373 if __name__ == '__main__':
364 unittest.main() 374 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698