summaryrefslogtreecommitdiffstats
path: root/dom/bindings/test/test_attributes_on_types.html
blob: ce606d2014ddf067a80f12136371bd5f0af4b297 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1295322
-->
<head>
  <meta charset="utf-8">
  <title>Test for WebIDL attributes on types</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1295322">Mozilla Bug 1295322</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
  <script type="application/javascript">
    /* global TestFunctions */

    add_task(async function push_permission() {
      await SpecialPowers.pushPrefEnv({set: [["dom.expose_test_interfaces", true]]});
    });

    add_task(function testClampedNullableOctet() {
      let test = new TestFunctions();
      test.clampedNullableOctet = null;
      is(test.clampedNullableOctet, null, "clampedNullableOctet should be null");
      test.clampedNullableOctet = -1;
      is(test.clampedNullableOctet, 0, "clampedNullableOctet should be clamped to 0");
      test.clampedNullableOctet = 256;
      is(test.clampedNullableOctet, 255, "clampedNullableOctet should be clamped 255");
      test.clampedNullableOctet = 200;
      is(test.clampedNullableOctet, 200, "clampedNullableOctet should be 200");
      test.clampedNullableOctet = null;
      is(test.clampedNullableOctet, null, "clampedNullableOctet should be null");
    });

    add_task(function testEnforcedNullableOctet() {
      let test = new TestFunctions();
      test.enforcedNullableOctet = null;
      is(test.enforcedNullableOctet, null, "enforcedNullableOctet should be null");
      try {
        test.enforcedNullableOctet = -1;
        ok(false, "Setting -1 to enforcedNullableOctet should throw exception");
      } catch(e) {}
      is(test.enforcedNullableOctet, null, "enforcedNullableOctet should still be null");
      try {
        test.enforcedNullableOctet = 256;
        ok(false, "Setting 256 to enforcedNullableOctet should throw exception");
      } catch(e) {}
      is(test.enforcedNullableOctet, null, "enforcedNullableOctet should still be null");
      test.enforcedNullableOctet = 200;
      is(test.enforcedNullableOctet, 200, "enforcedNullableOctet should be 200");
      test.enforcedNullableOctet = null;
      is(test.enforcedNullableOctet, null, "enforcedNullableOctet should be null");
    });

    add_task(function testAllowShared() {
      let test = new TestFunctions();
      [{type: "ArrayBuffer", isShared: false},
       {type: "SharedArrayBuffer", isShared: true}].forEach(arrayBuffer => {
        if (self[arrayBuffer.type] === undefined) {
          // https://bugzilla.mozilla.org/show_bug.cgi?id=1606624
          // Once we enable SharedArrayBuffer on all channel, we could remove
          // this.
          todo(false, `${arrayBuffer.type} is unavailable.`);
          return;
        }

        let buffer = new self[arrayBuffer.type](32);
        let threw = false;
        // Test Not Allow Shared
        try {
          test.testNotAllowShared(buffer);
          threw = false;
        } catch(e) {
          threw = true;
        }
        is(threw, arrayBuffer.isShared, `Call testNotAllowShared with ${arrayBuffer.type}`);

        try {
          test.testDictWithAllowShared({arrayBuffer: buffer});
          threw = false;
        } catch(e) {
          threw = true;
        }
        is(threw, arrayBuffer.isShared, `Call testDictWithAllowShared with {arrayBuffer: ${arrayBuffer.type}}`);

        try {
          test.testUnionOfBuffferSource(buffer);
          threw = false;
        } catch(e) {
          threw = true;
        }
        is(threw, arrayBuffer.isShared, `Call testUnionOfBuffferSource with ${arrayBuffer.type}`);

        try {
          test.arrayBuffer = buffer;
          threw = false;
        } catch(e) {
          threw = true;
        }
        is(threw, arrayBuffer.isShared, `Set arrayBuffer to ${arrayBuffer.type}`);

        try {
          test.sequenceOfArrayBuffer = [buffer];
          threw = false;
        } catch(e) {
          threw = true;
        }
        is(threw, arrayBuffer.isShared, `Set sequenceOfArrayBuffer to [${arrayBuffer.type}]`);

        // Test Allow Shared
        try {
          test.testAllowShared(buffer);
          threw = false;
        } catch(e) {
          threw = true;
        }
        ok(!threw, `Call testAllowShared with ${arrayBuffer.type}`);

        try {
          test.testDictWithAllowShared({allowSharedArrayBuffer: buffer});
          threw = false;
        } catch(e) {
          threw = true;
        }
        ok(!threw, `Call testDictWithAllowShared with {allowSharedArrayBuffer: ${arrayBuffer.type}}`);

        try {
          test.testUnionOfAllowSharedBuffferSource(buffer);
          threw = false;
        } catch(e) {
          threw = true;
        }
        ok(!threw, `Call testUnionOfAllowSharedBuffferSource with ${arrayBuffer.type}`);

        try {
          test.allowSharedArrayBuffer = buffer;
          threw = false;
        } catch(e) {
          threw = true;
        }
        ok(!threw, `Set allowSharedArrayBuffer to ${arrayBuffer.type}`);

        try {
          test.sequenceOfAllowSharedArrayBuffer = [buffer];
          threw = false;
        } catch(e) {
          threw = true;
        }
        ok(!threw, `Set sequenceOfAllowSharedArrayBuffer to [${arrayBuffer.type}]`);

        ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array",
         "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "DataView"].forEach(arrayType => {
          let array = new self[arrayType](buffer);
          // Test Not Allow Shared
          try {
            test.testNotAllowShared(array);
            threw = false;
          } catch(e) {
            threw = true;
          }
          is(threw, arrayBuffer.isShared, `Call testNotAllowShared with ${arrayType} (${arrayBuffer.type})`);

          try {
            test.testDictWithAllowShared({arrayBufferView: array});
            threw = false;
          } catch(e) {
            threw = true;
          }
          is(threw, arrayBuffer.isShared, `Call testDictWithAllowShared with {arrayBufferView: ${arrayType} (${arrayBuffer.type})}`);

          try {
            test.testUnionOfBuffferSource(array);
            threw = false;
          } catch(e) {
            threw = true;
          }
          is(threw, arrayBuffer.isShared, `Call testUnionOfBuffferSource with ${arrayType} (${arrayBuffer.type})`);

          try {
            test.arrayBufferView = array;
            threw = false;
          } catch(e) {
            threw = true;
          }
          is(threw, arrayBuffer.isShared, `Set arrayBufferView to ${arrayType} (${arrayBuffer.type})`);

          try {
            test.sequenceOfArrayBufferView = [array];
            threw = false;
          } catch(e) {
            threw = true;
          }
          is(threw, arrayBuffer.isShared, `Set sequenceOfArrayBufferView to [${arrayType} (${arrayBuffer.type})]`);

          // Test Allow Shared
          try {
            test.testAllowShared(array);
            threw = false;
          } catch(e) {
            threw = true;
          }
          ok(!threw, `Call testAllowShared with ${arrayType} (${arrayBuffer.type})`);

          try {
            test.testDictWithAllowShared({allowSharedArrayBufferView: array});
            threw = false;
          } catch(e) {
            threw = true;
          }
          ok(!threw, `Call testDictWithAllowShared with {allowSharedArrayBufferView: ${arrayType} (${arrayBuffer.type})}`);

          try {
            test.testUnionOfAllowSharedBuffferSource(array);
            threw = false;
          } catch(e) {
            threw = true;
          }
          ok(!threw, `Call testUnionOfAllowSharedBuffferSource with ${arrayType} (${arrayBuffer.type})`);

          try {
            test.allowSharedArrayBufferView = array;
            threw = false;
          } catch(e) {
            threw = true;
          }
          ok(!threw, `Set allowSharedArrayBufferView to ${arrayType} (${arrayBuffer.type})`);

          try {
            test.sequenceOfAllowSharedArrayBufferView = [array];
            threw = false;
          } catch(e) {
            threw = true;
          }
          ok(!threw, `Set sequenceOfAllowSharedArrayBufferView to [${arrayType} (${arrayBuffer.type})]`);
        });
      });
    });
  </script>
</body>
</html>