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

Side by Side Diff: headless/lib/browser/client_api_generator_unittest.py

Issue 2278123002: headless: Ensure all commands have parameters and return types (Closed)
Patch Set: Created 4 years, 3 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 | « headless/lib/browser/client_api_generator.py ('k') | headless/lib/browser/domain_cc.template » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import argparse 5 import argparse
6 import client_api_generator 6 import client_api_generator
7 import shutil 7 import shutil
8 import sys 8 import sys
9 import tempfile 9 import tempfile
10 import unittest 10 import unittest
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 ], 364 ],
365 'events': [ 365 'events': [
366 { 366 {
367 'name': 'BarEvent', 367 'name': 'BarEvent',
368 } 368 }
369 ] 369 ]
370 } 370 }
371 ] 371 ]
372 } 372 }
373 expected_types = [
374 {
375 'type': 'object',
376 'id': 'FooCommandParams',
377 'description': 'Parameters for the FooCommand command.',
378 'properties': [],
379 },
380 {
381 'type': 'object',
382 'id': 'FooCommandResult',
383 'description': 'Result for the FooCommand command.',
384 'properties': [],
385 },
386 {
387 'type': 'object',
388 'id': 'BarEventParams',
389 'description': 'Parameters for the BarEvent event.',
390 'properties': [],
391 }
392 ]
393 client_api_generator.PatchExperimentalCommandsAndEvents(json_api) 373 client_api_generator.PatchExperimentalCommandsAndEvents(json_api)
394 client_api_generator.SynthesizeCommandTypes(json_api)
395 client_api_generator.SynthesizeEventTypes(json_api)
396 for command in json_api['domains'][0]['commands']: 374 for command in json_api['domains'][0]['commands']:
397 self.assertTrue(command['experimental']) 375 self.assertTrue(command['experimental'])
398 for event in json_api['domains'][0]['events']: 376 for event in json_api['domains'][0]['events']:
399 self.assertTrue(command['experimental']) 377 self.assertTrue(command['experimental'])
400 types = json_api['domains'][0]['types']
401 self.assertListEqual(types, expected_types)
402 378
403 def test_PatchExperimentalCommandsAndEvents(self): 379 def test_EnsureCommandsHaveParametersAndReturnTypes(self):
404 json_api = { 380 json_api = {
405 'domains': [ 381 'domains': [
406 { 382 {
407 'domain': 'domain', 383 'domain': 'domain',
408 'commands': [ 384 'commands': [
409 { 385 {
410 'name': 'FooCommand', 386 'name': 'FooCommand',
411 'experimental': True,
412 } 387 }
413 ], 388 ],
414 'events': [ 389 'events': [
415 { 390 {
416 'name': 'BarEvent', 391 'name': 'BarEvent',
417 'experimental': True,
418 } 392 }
419 ] 393 ]
420 } 394 }
421 ] 395 ]
422 } 396 }
423 expected_types = [ 397 expected_types = [
424 { 398 {
425 'type': 'object', 399 'type': 'object',
426 'id': 'FooCommandParams', 400 'id': 'FooCommandParams',
427 'description': 'Parameters for the FooCommand command.', 401 'description': 'Parameters for the FooCommand command.',
428 'properties': [], 402 'properties': [],
429 }, 403 },
430 { 404 {
431 'type': 'object', 405 'type': 'object',
432 'id': 'FooCommandResult', 406 'id': 'FooCommandResult',
433 'description': 'Result for the FooCommand command.', 407 'description': 'Result for the FooCommand command.',
434 'properties': [], 408 'properties': [],
435 }, 409 },
436 { 410 {
437 'type': 'object', 411 'type': 'object',
438 'id': 'BarEventParams', 412 'id': 'BarEventParams',
439 'description': 'Parameters for the BarEvent event.', 413 'description': 'Parameters for the BarEvent event.',
440 'properties': [], 414 'properties': [],
441 } 415 }
442 ] 416 ]
443 client_api_generator.PatchExperimentalCommandsAndEvents(json_api) 417 client_api_generator.EnsureCommandsHaveParametersAndReturnTypes(json_api)
444 client_api_generator.SynthesizeCommandTypes(json_api) 418 client_api_generator.SynthesizeCommandTypes(json_api)
445 client_api_generator.SynthesizeEventTypes(json_api) 419 client_api_generator.SynthesizeEventTypes(json_api)
446 for command in json_api['domains'][0]['commands']:
447 self.assertTrue(command['experimental'])
448 for event in json_api['domains'][0]['events']:
449 self.assertTrue(command['experimental'])
450 types = json_api['domains'][0]['types'] 420 types = json_api['domains'][0]['types']
451 self.assertListEqual(types, expected_types) 421 self.assertListEqual(types, expected_types)
452 422
453 def test_Generate(self): 423 def test_Generate(self):
454 json_api = { 424 json_api = {
455 'domains': [ 425 'domains': [
456 { 426 {
457 'domain': 'domain', 427 'domain': 'domain',
458 'types': [ 428 'types': [
459 { 429 {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 497
528 498
529 if __name__ == '__main__': 499 if __name__ == '__main__':
530 cmdline_parser = argparse.ArgumentParser() 500 cmdline_parser = argparse.ArgumentParser()
531 cmdline_parser.add_argument('--stamp') 501 cmdline_parser.add_argument('--stamp')
532 args = cmdline_parser.parse_args() 502 args = cmdline_parser.parse_args()
533 unittest.main(verbosity=2, exit=False, argv=sys.argv[:1]) 503 unittest.main(verbosity=2, exit=False, argv=sys.argv[:1])
534 if args.stamp: 504 if args.stamp:
535 with open(args.stamp, 'a') as f: 505 with open(args.stamp, 'a') as f:
536 pass 506 pass
OLDNEW
« no previous file with comments | « headless/lib/browser/client_api_generator.py ('k') | headless/lib/browser/domain_cc.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698