| Index: third_party/WebKit/Source/bindings/scripts/idl_types_test.py
|
| diff --git a/third_party/WebKit/Source/bindings/scripts/idl_types_test.py b/third_party/WebKit/Source/bindings/scripts/idl_types_test.py
|
| index 931c465461a159b0a8571fa7abab0b4ec603f990..c92fb42fd915363358571764fa516f780afddaee 100644
|
| --- a/third_party/WebKit/Source/bindings/scripts/idl_types_test.py
|
| +++ b/third_party/WebKit/Source/bindings/scripts/idl_types_test.py
|
| @@ -8,9 +8,11 @@
|
|
|
| import unittest
|
|
|
| +from idl_types import IdlNullableType
|
| from idl_types import IdlRecordType
|
| from idl_types import IdlSequenceType
|
| from idl_types import IdlType
|
| +from idl_types import IdlUnionType
|
|
|
|
|
| class IdlTypeTest(unittest.TestCase):
|
| @@ -76,3 +78,61 @@ class IdlRecordTypeTest(unittest.TestCase):
|
| IdlRecordType(IdlType('ByteString'),
|
| IdlSequenceType(IdlType('unsigned short'))))
|
| self.assertEqual(idl_type.name, 'StringByteStringUnsignedShortSequenceRecordRecord')
|
| +
|
| +
|
| +class IdlUnionTypeTest(unittest.TestCase):
|
| +
|
| + def test_flattened_member_types(self):
|
| + # We are only testing the algorithm here, so we do create some ambiguous union types.
|
| +
|
| + def compare_flattened_members(actual, expected):
|
| + """Compare a set of IDL types by name, as the objects are different"""
|
| + actual_names = set([member.name for member in actual])
|
| + expected_names = set([member.name for member in expected])
|
| + self.assertEqual(actual_names, expected_names)
|
| +
|
| + idl_type = IdlUnionType([IdlType('long'), IdlType('SomeInterface')])
|
| + compare_flattened_members(
|
| + idl_type.flattened_member_types,
|
| + set([IdlType('long'), IdlType('SomeInterface')]))
|
| +
|
| + idl_type = IdlUnionType([IdlUnionType([IdlType('ByteString'), IdlType('float')]),
|
| + IdlType('boolean')])
|
| + compare_flattened_members(
|
| + idl_type.flattened_member_types,
|
| + set([IdlType('float'), IdlType('boolean'), IdlType('ByteString')]))
|
| +
|
| + idl_type = IdlUnionType([IdlUnionType([IdlType('ByteString'), IdlType('DOMString')]),
|
| + IdlType('DOMString')])
|
| + compare_flattened_members(
|
| + idl_type.flattened_member_types,
|
| + set([IdlType('DOMString'), IdlType('ByteString')]))
|
| +
|
| + idl_type = IdlUnionType(
|
| + [IdlNullableType(IdlType('ByteString')), IdlType('byte')])
|
| + compare_flattened_members(
|
| + idl_type.flattened_member_types,
|
| + set([IdlType('ByteString'), IdlType('byte')]))
|
| +
|
| + idl_type = IdlUnionType(
|
| + [IdlNullableType(IdlType('ByteString')), IdlType('byte'),
|
| + IdlUnionType([IdlType('ByteString'), IdlType('float')])])
|
| + self.assertEqual(len(idl_type.flattened_member_types), 3)
|
| + compare_flattened_members(
|
| + idl_type.flattened_member_types,
|
| + set([IdlType('ByteString'), IdlType('byte'), IdlType('float')]))
|
| +
|
| + # From the example in the spec: "the flattened member types of the union type (Node or (sequence<long> or Event) or
|
| + # (XMLHttpRequest or DOMString)? or sequence<(sequence<double> or NodeList)>) are the six types Node, sequence<long>,
|
| + # Event, XMLHttpRequest, DOMString and sequence<(sequence<double> or NodeList)>"
|
| + idl_type = IdlUnionType(
|
| + [IdlType('Node'),
|
| + IdlUnionType([IdlSequenceType(IdlType('long')), IdlType('Event')]),
|
| + IdlNullableType(IdlUnionType([IdlType('XMLHttpRequest'), IdlType('DOMString')])),
|
| + IdlSequenceType(IdlUnionType([IdlSequenceType(IdlType('double')), IdlType('NodeList')]))])
|
| + self.assertEqual(len(idl_type.flattened_member_types), 6)
|
| + compare_flattened_members(
|
| + idl_type.flattened_member_types,
|
| + set([IdlType('Node'), IdlSequenceType(IdlType('long')), IdlType('Event'),
|
| + IdlType('XMLHttpRequest'), IdlType('DOMString'),
|
| + IdlSequenceType(IdlUnionType([IdlSequenceType(IdlType('double')), IdlType('NodeList')]))]))
|
|
|