| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:mojo/bindings.dart' as bindings; | 10 import 'package:mojo/bindings.dart' as bindings; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 403 } |
| 404 | 404 |
| 405 testValidateMojomTypes() { | 405 testValidateMojomTypes() { |
| 406 testValidateEnumType(); | 406 testValidateEnumType(); |
| 407 testValidateStructType(); | 407 testValidateStructType(); |
| 408 testValidateUnionType(); | 408 testValidateUnionType(); |
| 409 testValidateTestStructWithImportType(); | 409 testValidateTestStructWithImportType(); |
| 410 testValidateInterfaceType(); | 410 testValidateInterfaceType(); |
| 411 } | 411 } |
| 412 | 412 |
| 413 // computeTypeKey encapsulates the algorithm for computing the type key |
| 414 // of a type given its fully-qualified name. |
| 415 // |
| 416 // TODO(rudominer) Delete this when we add accessors for Mojom types |
| 417 // in the Dart bindings. |
| 418 String computeTypeKey(String fullyQualifiedName) { |
| 419 return "TYPE_KEY:" + fullyQualifiedName; |
| 420 } |
| 421 |
| 413 // Test that mojom type descriptors were generated correctly for validation's | 422 // Test that mojom type descriptors were generated correctly for validation's |
| 414 // BasicEnum. | 423 // BasicEnum. |
| 415 testValidateEnumType() { | 424 testValidateEnumType() { |
| 416 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | 425 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); |
| 417 String enumID = "validation_test_interfaces_BasicEnum__"; | |
| 418 String shortName = "BasicEnum"; | 426 String shortName = "BasicEnum"; |
| 419 String fullIdentifier = "mojo.test.BasicEnum"; | 427 String fullIdentifier = "mojo.test.BasicEnum"; |
| 428 String enumID = computeTypeKey(fullIdentifier); |
| 420 Map<String, int> labelMap = <String, int>{ | 429 Map<String, int> labelMap = <String, int>{ |
| 421 "A": 0, | 430 "A": 0, |
| 422 "B": 1, | 431 "B": 1, |
| 423 "C": 0, | 432 "C": 0, |
| 424 "D": -3, | 433 "D": -3, |
| 425 "E": 0xA, | 434 "E": 0xA, |
| 426 }; | 435 }; |
| 427 | 436 |
| 428 // Extract the UserDefinedType from the descriptor using enumID. | 437 // Extract the UserDefinedType from the descriptor using enumID. |
| 429 mojom_types.UserDefinedType udt = testValidationDescriptor[enumID]; | 438 mojom_types.UserDefinedType udt = testValidationDescriptor[enumID]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 447 // Check that the enumTypeKey matches the enumID. | 456 // Check that the enumTypeKey matches the enumID. |
| 448 Expect.equals(ev.enumTypeKey, enumID); | 457 Expect.equals(ev.enumTypeKey, enumID); |
| 449 Expect.equals(ev.intValue, labelMap[ev.declData.shortName]); | 458 Expect.equals(ev.intValue, labelMap[ev.declData.shortName]); |
| 450 }); | 459 }); |
| 451 } | 460 } |
| 452 | 461 |
| 453 // Test that mojom type descriptors were generated correctly for validation's | 462 // Test that mojom type descriptors were generated correctly for validation's |
| 454 // StructE. | 463 // StructE. |
| 455 testValidateStructType() { | 464 testValidateStructType() { |
| 456 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | 465 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); |
| 457 String structID = "validation_test_interfaces_StructE__"; | |
| 458 String shortName = "StructE"; | 466 String shortName = "StructE"; |
| 459 String fullIdentifier = "mojo.test.StructE"; | 467 String fullIdentifier = "mojo.test.StructE"; |
| 468 String structID = computeTypeKey(fullIdentifier); |
| 460 Map<int, String> expectedFields = <int, String>{ | 469 Map<int, String> expectedFields = <int, String>{ |
| 461 0: "StructD", | 470 0: "struct_d", |
| 462 1: "DataPipeConsumer", | 471 1: "data_pipe_consumer", |
| 463 }; | 472 }; |
| 464 | 473 |
| 465 // Extract the UserDefinedType from the descriptor using structID. | 474 // Extract the UserDefinedType from the descriptor using structID. |
| 466 mojom_types.UserDefinedType udt = testValidationDescriptor[structID]; | 475 mojom_types.UserDefinedType udt = testValidationDescriptor[structID]; |
| 467 Expect.isNotNull(udt); | 476 Expect.isNotNull(udt); |
| 468 | 477 |
| 469 // The structType must be present and declared properly. | 478 // The structType must be present and declared properly. |
| 470 mojom_types.MojomStruct ms = udt.structType; | 479 mojom_types.MojomStruct ms = udt.structType; |
| 471 Expect.isNotNull(ms); | 480 Expect.isNotNull(ms); |
| 472 Expect.isNotNull(ms.declData); | 481 Expect.isNotNull(ms.declData); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 483 Expect.equals(expectedFields[i], field.declData.shortName); | 492 Expect.equals(expectedFields[i], field.declData.shortName); |
| 484 | 493 |
| 485 // Special case each field since we already know what should be inside. | 494 // Special case each field since we already know what should be inside. |
| 486 switch (i) { | 495 switch (i) { |
| 487 case 0: // This is a TypeReference to StructD. | 496 case 0: // This is a TypeReference to StructD. |
| 488 mojom_types.Type t = field.type; | 497 mojom_types.Type t = field.type; |
| 489 Expect.isNotNull(t.typeReference); | 498 Expect.isNotNull(t.typeReference); |
| 490 | 499 |
| 491 // Type key, identifier, and expected reference id should match up. | 500 // Type key, identifier, and expected reference id should match up. |
| 492 mojom_types.TypeReference tr = t.typeReference; | 501 mojom_types.TypeReference tr = t.typeReference; |
| 493 String expectedRefID = "validation_test_interfaces_StructD__"; | 502 String expectedRefID = computeTypeKey("mojo.test.StructD"); |
| 494 Expect.equals(expectedRefID, tr.identifier); | 503 Expect.equals("StructD", tr.identifier); |
| 495 Expect.equals(expectedRefID, tr.typeKey); | 504 Expect.equals(expectedRefID, tr.typeKey); |
| 496 break; | 505 break; |
| 497 case 1: // This is a non-nullable DataPipeConsumer HandleType. | 506 case 1: // This is a non-nullable DataPipeConsumer HandleType. |
| 498 mojom_types.Type t = field.type; | 507 mojom_types.Type t = field.type; |
| 499 Expect.isNotNull(t.handleType); | 508 Expect.isNotNull(t.handleType); |
| 500 | 509 |
| 501 mojom_types.HandleType ht = t.handleType; | 510 mojom_types.HandleType ht = t.handleType; |
| 502 Expect.isFalse(ht.nullable); | 511 Expect.isFalse(ht.nullable); |
| 503 Expect.equals(mojom_types.HandleTypeKind.dataPipeConsumer, ht.kind); | 512 Expect.equals(mojom_types.HandleTypeKind.dataPipeConsumer, ht.kind); |
| 504 break; | 513 break; |
| 505 default: | 514 default: |
| 506 assert(false); | 515 assert(false); |
| 507 } | 516 } |
| 508 | 517 |
| 509 i++; | 518 i++; |
| 510 }); | 519 }); |
| 511 } | 520 } |
| 512 | 521 |
| 513 // Test that mojom type descriptors were generated correctly for validation's | 522 // Test that mojom type descriptors were generated correctly for validation's |
| 514 // UnionB. | 523 // UnionB. |
| 515 testValidateUnionType() { | 524 testValidateUnionType() { |
| 516 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | 525 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); |
| 517 String unionID = "validation_test_interfaces_UnionB__"; | |
| 518 String shortName = "UnionB"; | 526 String shortName = "UnionB"; |
| 519 String fullIdentifier = "mojo.test.UnionB"; | 527 String fullIdentifier = "mojo.test.UnionB"; |
| 528 String unionID = computeTypeKey(fullIdentifier); |
| 520 Map<int, String> expectedFields = <int, String>{ | 529 Map<int, String> expectedFields = <int, String>{ |
| 521 0: "A", | 530 0: "a", |
| 522 1: "B", | 531 1: "b", |
| 523 2: "C", | 532 2: "c", |
| 524 3: "D", | 533 3: "d", |
| 525 }; | 534 }; |
| 526 | 535 |
| 527 // Extract the UserDefinedType from the descriptor using unionID. | 536 // Extract the UserDefinedType from the descriptor using unionID. |
| 528 mojom_types.UserDefinedType udt = testValidationDescriptor[unionID]; | 537 mojom_types.UserDefinedType udt = testValidationDescriptor[unionID]; |
| 529 Expect.isNotNull(udt); | 538 Expect.isNotNull(udt); |
| 530 | 539 |
| 531 // The unionType must be present and declared properly. | 540 // The unionType must be present and declared properly. |
| 532 mojom_types.MojomUnion mu = udt.unionType; | 541 mojom_types.MojomUnion mu = udt.unionType; |
| 533 Expect.isNotNull(mu); | 542 Expect.isNotNull(mu); |
| 534 Expect.isNotNull(mu.declData); | 543 Expect.isNotNull(mu.declData); |
| 535 Expect.equals(mu.declData.shortName, shortName); | 544 Expect.equals(mu.declData.shortName, shortName); |
| 536 Expect.equals(mu.declData.fullIdentifier, fullIdentifier); | 545 Expect.equals(mu.declData.fullIdentifier, fullIdentifier); |
| 537 | 546 |
| 538 // Now compare the fields to verify that the union fields match the expected | 547 // Now compare the fields to verify that the union fields match the expected |
| 539 // ones. | 548 // ones. |
| 540 Expect.equals(mu.fields.length, expectedFields.length); | 549 Expect.equals(mu.fields.length, expectedFields.length); |
| 550 // TODO(rudominer) Currently ordinal tags in enums are not being populated by |
| 551 // the Mojom parser in mojom_types.mojom so for now we must assume that |
| 552 // the ordinals are in sequential order (which they are in the .mojom |
| 553 // file being used for this test.) |
| 554 int nextOrdinal = 0; |
| 541 mu.fields.forEach((mojom_types.UnionField field) { | 555 mu.fields.forEach((mojom_types.UnionField field) { |
| 542 int ordinal = field.tag; | 556 int ordinal = nextOrdinal; |
| 557 nextOrdinal++; |
| 543 | 558 |
| 544 // Check that the declData is correct... | 559 // Check that the declData is correct... |
| 545 Expect.isNotNull(field.declData); | 560 Expect.isNotNull(field.declData); |
| 546 Expect.equals(expectedFields[ordinal], field.declData.shortName); | 561 Expect.equals(expectedFields[ordinal], field.declData.shortName); |
| 547 | 562 |
| 548 // Special: It turns out that all types are simple types. | 563 // Special: It turns out that all types are simple types. |
| 549 mojom_types.Type t = field.type; | 564 mojom_types.Type t = field.type; |
| 550 Expect.isNotNull(t.simpleType); | 565 Expect.isNotNull(t.simpleType); |
| 551 mojom_types.SimpleType st = t.simpleType; | 566 mojom_types.SimpleType st = t.simpleType; |
| 552 | 567 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 565 default: | 580 default: |
| 566 assert(false); | 581 assert(false); |
| 567 } | 582 } |
| 568 }); | 583 }); |
| 569 } | 584 } |
| 570 | 585 |
| 571 // Test that mojom type descriptors were generated correctly for validation's | 586 // Test that mojom type descriptors were generated correctly for validation's |
| 572 // IncludingStruct, which contains a union imported from test_included_unions. | 587 // IncludingStruct, which contains a union imported from test_included_unions. |
| 573 testValidateTestStructWithImportType() { | 588 testValidateTestStructWithImportType() { |
| 574 var testUnionsDescriptor = unions.getAllMojomTypeDefinitions(); | 589 var testUnionsDescriptor = unions.getAllMojomTypeDefinitions(); |
| 575 String structID = "test_unions_IncludingStruct__"; | |
| 576 String shortName = "IncludingStruct"; | 590 String shortName = "IncludingStruct"; |
| 577 String fullIdentifier = "mojo.test.IncludingStruct"; | 591 String fullIdentifier = "mojo.test.IncludingStruct"; |
| 578 Map<int, String> expectedFields = <int, String>{0: "A",}; | 592 String structID = computeTypeKey(fullIdentifier); |
| 593 Map<int, String> expectedFields = <int, String>{0: "a",}; |
| 579 | 594 |
| 580 // Extract the UserDefinedType from the descriptor using structID. | 595 // Extract the UserDefinedType from the descriptor using structID. |
| 581 mojom_types.UserDefinedType udt = testUnionsDescriptor[structID]; | 596 mojom_types.UserDefinedType udt = testUnionsDescriptor[structID]; |
| 582 Expect.isNotNull(udt); | 597 Expect.isNotNull(udt); |
| 583 | 598 |
| 584 // The structType must be present and declared properly. | 599 // The structType must be present and declared properly. |
| 585 mojom_types.MojomStruct ms = udt.structType; | 600 mojom_types.MojomStruct ms = udt.structType; |
| 586 Expect.isNotNull(ms); | 601 Expect.isNotNull(ms); |
| 587 Expect.isNotNull(ms.declData); | 602 Expect.isNotNull(ms.declData); |
| 588 Expect.equals(ms.declData.shortName, shortName); | 603 Expect.equals(ms.declData.shortName, shortName); |
| 589 Expect.equals(ms.declData.fullIdentifier, fullIdentifier); | 604 Expect.equals(ms.declData.fullIdentifier, fullIdentifier); |
| 590 | 605 |
| 591 // Now compare the fields to verify that the struct fields match the expected | 606 // Now compare the fields to verify that the struct fields match the expected |
| 592 // ones. | 607 // ones. |
| 593 Expect.equals(ms.fields.length, expectedFields.length); | 608 Expect.equals(ms.fields.length, expectedFields.length); |
| 594 int i = 0; | 609 int i = 0; |
| 595 ms.fields.forEach((mojom_types.StructField field) { | 610 ms.fields.forEach((mojom_types.StructField field) { |
| 596 // Check that the declData is correct... | 611 // Check that the declData is correct... |
| 597 Expect.isNotNull(field.declData); | 612 Expect.isNotNull(field.declData); |
| 598 Expect.equals(expectedFields[i], field.declData.shortName); | 613 Expect.equals(expectedFields[i], field.declData.shortName); |
| 599 | 614 |
| 600 // Special case each field since we already know what should be inside. | 615 // Special case each field since we already know what should be inside. |
| 601 switch (i) { | 616 switch (i) { |
| 602 case 0: // This is a TypeReference to a Union. | 617 case 0: // This is a TypeReference to a Union. |
| 603 mojom_types.Type t = field.type; | 618 mojom_types.Type t = field.type; |
| 604 Expect.isNotNull(t.typeReference); | 619 Expect.isNotNull(t.typeReference); |
| 605 | 620 |
| 606 // Type key, identifier, and expected reference id should match up. | 621 // Type key, identifier, and expected reference id should match up. |
| 607 mojom_types.TypeReference tr = t.typeReference; | 622 mojom_types.TypeReference tr = t.typeReference; |
| 608 String expectedRefID = "test_included_unions_IncludedUnion__"; | 623 String expectedRefID = computeTypeKey("mojo.test.IncludedUnion"); |
| 609 Expect.equals(expectedRefID, tr.identifier); | 624 Expect.equals("IncludedUnion", tr.identifier); |
| 610 Expect.equals(expectedRefID, tr.typeKey); | 625 Expect.equals(expectedRefID, tr.typeKey); |
| 611 break; | 626 break; |
| 612 default: | 627 default: |
| 613 assert(false); | 628 assert(false); |
| 614 } | 629 } |
| 615 | 630 |
| 616 i++; | 631 i++; |
| 617 }); | 632 }); |
| 618 } | 633 } |
| 619 | 634 |
| 620 // Test that mojom type descriptors were generated correctly for validation's | 635 // Test that mojom type descriptors were generated correctly for validation's |
| 621 // BoundsCheckTestInterface. | 636 // BoundsCheckTestInterface. |
| 622 testValidateInterfaceType() { | 637 testValidateInterfaceType() { |
| 623 // interface BoundsCheckTestInterface { | 638 // interface BoundsCheckTestInterface { |
| 624 // Method0(uint8 param0) => (uint8 param0); | 639 // Method0(uint8 param0) => (uint8 param0); |
| 625 // Method1(uint8 param0); | 640 // Method1(uint8 param0); |
| 626 // }; | 641 // }; |
| 627 | 642 |
| 628 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | 643 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); |
| 629 String interfaceID = "validation_test_interfaces_BoundsCheckTestInterface__"; | |
| 630 String shortName = "BoundsCheckTestInterface"; | 644 String shortName = "BoundsCheckTestInterface"; |
| 631 String fullIdentifier = "mojo.test.BoundsCheckTestInterface"; | 645 String fullIdentifier = "mojo.test.BoundsCheckTestInterface"; |
| 646 String interfaceID = computeTypeKey(fullIdentifier); |
| 632 Map<int, String> methodMap = <int, String>{0: "Method0", 1: "Method1",}; | 647 Map<int, String> methodMap = <int, String>{0: "Method0", 1: "Method1",}; |
| 633 | 648 |
| 634 mojom_types.UserDefinedType udt = testValidationDescriptor[interfaceID]; | 649 mojom_types.UserDefinedType udt = testValidationDescriptor[interfaceID]; |
| 635 Expect.isNotNull(udt); | 650 Expect.isNotNull(udt); |
| 636 | 651 |
| 637 mojom_types.MojomInterface mi = udt.interfaceType; | 652 mojom_types.MojomInterface mi = udt.interfaceType; |
| 638 Expect.isNotNull(mi); | 653 Expect.isNotNull(mi); |
| 639 | 654 |
| 640 _checkMojomInterface(mi, shortName, fullIdentifier, methodMap); | 655 _checkMojomInterface(mi, shortName, fullIdentifier, methodMap); |
| 641 | 656 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 testValidateMojomTypes(); | 756 testValidateMojomTypes(); |
| 742 testCamelCase(); | 757 testCamelCase(); |
| 743 testSerializeErrorMessage(); | 758 testSerializeErrorMessage(); |
| 744 await testEnums(); | 759 await testEnums(); |
| 745 await testCallResponse(); | 760 await testCallResponse(); |
| 746 await testAwaitCallResponse(); | 761 await testAwaitCallResponse(); |
| 747 await runOnClosedTest(); | 762 await runOnClosedTest(); |
| 748 await testRegression551(); | 763 await testRegression551(); |
| 749 await testServiceName(); | 764 await testServiceName(); |
| 750 } | 765 } |
| OLD | NEW |