summaryrefslogtreecommitdiffstats
path: root/dom/bindings/parser/tests/test_union_callback_dict.py
blob: 3e87e16ad471edc4f4d2875bda7a0162acefee40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import WebIDL


def WebIDLTest(parser, harness):
    parser = parser.reset()
    threw = False
    try:
        parser.parse(
            """
            dictionary TestDict {
            DOMString member;
            };
            [LegacyTreatNonObjectAsNull] callback TestCallback = undefined ();
            typedef (TestCallback or TestDict) TestUnionCallbackDict;
            """
        )
        results = parser.finish()
    except WebIDL.WebIDLError:
        threw = True
    harness.ok(
        threw,
        "Should not allow Dict/Callback union where callback is [LegacyTreatNonObjectAsNull]",
    )

    parser = parser.reset()

    threw = False
    try:
        parser.parse(
            """
            dictionary TestDict {
            DOMString member;
            };
            [LegacyTreatNonObjectAsNull] callback TestCallback = undefined ();
            typedef (TestDict or TestCallback) TestUnionCallbackDict;
            """
        )
        results = parser.finish()
    except WebIDL.WebIDLError:
        threw = True
    harness.ok(
        threw,
        "Should not allow Dict/Callback union where callback is [LegacyTreatNonObjectAsNull]",
    )

    parser = parser.reset()

    parser.parse(
        """
        dictionary TestDict {
          DOMString member;
        };
        callback TestCallback = undefined ();
        typedef (TestCallback or TestDict) TestUnionCallbackDict;
        """
    )
    results = parser.finish()

    harness.ok(True, "TestUnionCallbackDict interface parsed without error")
    harness.check(len(results), 3, "Document should have 3 types")

    myDict = results[0]
    harness.ok(isinstance(myDict, WebIDL.IDLDictionary), "Expect an IDLDictionary")

    myCallback = results[1]
    harness.ok(isinstance(myCallback, WebIDL.IDLCallback), "Expect an IDLCallback")

    myUnion = results[2]
    harness.ok(isinstance(myUnion, WebIDL.IDLTypedef), "Expect a IDLTypedef")
    harness.ok(
        isinstance(myUnion.innerType, WebIDL.IDLUnionType), "Expect a IDLUnionType"
    )
    harness.ok(
        isinstance(myUnion.innerType.memberTypes[0], WebIDL.IDLCallbackType),
        "Expect a IDLCallbackType",
    )
    harness.ok(
        isinstance(myUnion.innerType.memberTypes[1], WebIDL.IDLWrapperType),
        "Expect a IDLDictionary",
    )
    harness.ok(
        (myUnion.innerType.memberTypes[0].callback == myCallback),
        "Expect left Union member to be MyCallback",
    )
    harness.ok(
        (myUnion.innerType.memberTypes[1].inner == myDict),
        "Expect right Union member to be MyDict",
    )

    parser = parser.reset()

    parser.parse(
        """
        dictionary TestDict {
          DOMString member;
        };
        callback TestCallback = undefined ();
        typedef (TestDict or TestCallback) TestUnionCallbackDict;
        """
    )
    results = parser.finish()

    harness.ok(True, "TestUnionCallbackDict interface parsed without error")
    harness.check(len(results), 3, "Document should have 3 types")

    myDict = results[0]
    harness.ok(isinstance(myDict, WebIDL.IDLDictionary), "Expect an IDLDictionary")

    myCallback = results[1]
    harness.ok(isinstance(myCallback, WebIDL.IDLCallback), "Expect an IDLCallback")

    myUnion = results[2]
    harness.ok(isinstance(myUnion, WebIDL.IDLTypedef), "Expect a IDLTypedef")
    harness.ok(
        isinstance(myUnion.innerType, WebIDL.IDLUnionType), "Expect a IDLUnionType"
    )
    harness.ok(
        isinstance(myUnion.innerType.memberTypes[0], WebIDL.IDLWrapperType),
        "Expect a IDLDictionary",
    )
    harness.ok(
        isinstance(myUnion.innerType.memberTypes[1], WebIDL.IDLCallbackType),
        "Expect a IDLCallbackType",
    )
    harness.ok(
        (myUnion.innerType.memberTypes[0].inner == myDict),
        "Expect right Union member to be MyDict",
    )
    harness.ok(
        (myUnion.innerType.memberTypes[1].callback == myCallback),
        "Expect left Union member to be MyCallback",
    )