OLD | NEW |
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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 'type': 'object', | 342 'type': 'object', |
343 'id': 'TestEventWithNoParamsParams', | 343 'id': 'TestEventWithNoParamsParams', |
344 'description': 'Parameters for the TestEventWithNoParams event.', | 344 'description': 'Parameters for the TestEventWithNoParams event.', |
345 'properties': [], | 345 'properties': [], |
346 } | 346 } |
347 ] | 347 ] |
348 client_api_generator.SynthesizeEventTypes(json_api) | 348 client_api_generator.SynthesizeEventTypes(json_api) |
349 types = json_api['domains'][0]['types'] | 349 types = json_api['domains'][0]['types'] |
350 self.assertListEqual(types, expected_types) | 350 self.assertListEqual(types, expected_types) |
351 | 351 |
| 352 def test_PatchHiddenDomains(self): |
| 353 json_api = { |
| 354 'domains': [ |
| 355 { |
| 356 'domain': 'domain', |
| 357 'hidden': True, |
| 358 'commands': [ |
| 359 { |
| 360 'name': 'FooCommand', |
| 361 } |
| 362 ], |
| 363 'events': [ |
| 364 { |
| 365 'name': 'BarEvent', |
| 366 } |
| 367 ] |
| 368 } |
| 369 ] |
| 370 } |
| 371 expected_types = [ |
| 372 { |
| 373 'type': 'object', |
| 374 'id': 'FooCommandParams', |
| 375 'description': 'Parameters for the FooCommand command.', |
| 376 'properties': [], |
| 377 }, |
| 378 { |
| 379 'type': 'object', |
| 380 'id': 'FooCommandResult', |
| 381 'description': 'Result for the FooCommand command.', |
| 382 'properties': [], |
| 383 }, |
| 384 { |
| 385 'type': 'object', |
| 386 'id': 'BarEventParams', |
| 387 'description': 'Parameters for the BarEvent event.', |
| 388 'properties': [], |
| 389 } |
| 390 ] |
| 391 client_api_generator.PatchHiddenCommandsAndEvents(json_api) |
| 392 client_api_generator.SynthesizeCommandTypes(json_api) |
| 393 client_api_generator.SynthesizeEventTypes(json_api) |
| 394 for command in json_api['domains'][0]['commands']: |
| 395 self.assertTrue(command['hidden']) |
| 396 for event in json_api['domains'][0]['events']: |
| 397 self.assertTrue(command['hidden']) |
| 398 types = json_api['domains'][0]['types'] |
| 399 self.assertListEqual(types, expected_types) |
| 400 |
| 401 def test_PatchHiddenCommandsAndEvents(self): |
| 402 json_api = { |
| 403 'domains': [ |
| 404 { |
| 405 'domain': 'domain', |
| 406 'commands': [ |
| 407 { |
| 408 'name': 'FooCommand', |
| 409 'hidden': True, |
| 410 } |
| 411 ], |
| 412 'events': [ |
| 413 { |
| 414 'name': 'BarEvent', |
| 415 'hidden': True, |
| 416 } |
| 417 ] |
| 418 } |
| 419 ] |
| 420 } |
| 421 expected_types = [ |
| 422 { |
| 423 'type': 'object', |
| 424 'id': 'FooCommandParams', |
| 425 'description': 'Parameters for the FooCommand command.', |
| 426 'properties': [], |
| 427 }, |
| 428 { |
| 429 'type': 'object', |
| 430 'id': 'FooCommandResult', |
| 431 'description': 'Result for the FooCommand command.', |
| 432 'properties': [], |
| 433 }, |
| 434 { |
| 435 'type': 'object', |
| 436 'id': 'BarEventParams', |
| 437 'description': 'Parameters for the BarEvent event.', |
| 438 'properties': [], |
| 439 } |
| 440 ] |
| 441 client_api_generator.PatchHiddenCommandsAndEvents(json_api) |
| 442 client_api_generator.SynthesizeCommandTypes(json_api) |
| 443 client_api_generator.SynthesizeEventTypes(json_api) |
| 444 for command in json_api['domains'][0]['commands']: |
| 445 self.assertTrue(command['hidden']) |
| 446 for event in json_api['domains'][0]['events']: |
| 447 self.assertTrue(command['hidden']) |
| 448 types = json_api['domains'][0]['types'] |
| 449 self.assertListEqual(types, expected_types) |
| 450 |
352 def test_Generate(self): | 451 def test_Generate(self): |
353 json_api = { | 452 json_api = { |
354 'domains': [ | 453 'domains': [ |
355 { | 454 { |
356 'domain': 'domain', | 455 'domain': 'domain', |
357 'types': [ | 456 'types': [ |
358 { | 457 { |
359 'id': 'TestType', | 458 'id': 'TestType', |
360 'type': 'object', | 459 'type': 'object', |
361 'properties': [ | 460 'properties': [ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 525 |
427 | 526 |
428 if __name__ == '__main__': | 527 if __name__ == '__main__': |
429 cmdline_parser = argparse.ArgumentParser() | 528 cmdline_parser = argparse.ArgumentParser() |
430 cmdline_parser.add_argument('--stamp') | 529 cmdline_parser.add_argument('--stamp') |
431 args = cmdline_parser.parse_args() | 530 args = cmdline_parser.parse_args() |
432 unittest.main(verbosity=2, exit=False, argv=sys.argv[:1]) | 531 unittest.main(verbosity=2, exit=False, argv=sys.argv[:1]) |
433 if args.stamp: | 532 if args.stamp: |
434 with open(args.stamp, 'a') as f: | 533 with open(args.stamp, 'a') as f: |
435 pass | 534 pass |
OLD | NEW |