11cb0ef41Sopenharmony_ci// Step 1.
21cb0ef41Sopenharmony_citest(function() {
31cb0ef41Sopenharmony_ci    assert_throws_dom("TypeMismatchError", function() {
41cb0ef41Sopenharmony_ci        self.crypto.getRandomValues(new Float32Array(6))
51cb0ef41Sopenharmony_ci    }, "Float32Array")
61cb0ef41Sopenharmony_ci    assert_throws_dom("TypeMismatchError", function() {
71cb0ef41Sopenharmony_ci        self.crypto.getRandomValues(new Float64Array(6))
81cb0ef41Sopenharmony_ci    }, "Float64Array")
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci    assert_throws_dom("TypeMismatchError", function() {
111cb0ef41Sopenharmony_ci        const len = 65536 / Float32Array.BYTES_PER_ELEMENT + 1;
121cb0ef41Sopenharmony_ci        self.crypto.getRandomValues(new Float32Array(len));
131cb0ef41Sopenharmony_ci    }, "Float32Array (too long)")
141cb0ef41Sopenharmony_ci    assert_throws_dom("TypeMismatchError", function() {
151cb0ef41Sopenharmony_ci        const len = 65536 / Float64Array.BYTES_PER_ELEMENT + 1;
161cb0ef41Sopenharmony_ci        self.crypto.getRandomValues(new Float64Array(len))
171cb0ef41Sopenharmony_ci    }, "Float64Array (too long)")
181cb0ef41Sopenharmony_ci}, "Float arrays");
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_citest(function() {
211cb0ef41Sopenharmony_ci    assert_throws_dom("TypeMismatchError", function() {
221cb0ef41Sopenharmony_ci        self.crypto.getRandomValues(new DataView(new ArrayBuffer(6)))
231cb0ef41Sopenharmony_ci    }, "DataView")
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    assert_throws_dom("TypeMismatchError", function() {
261cb0ef41Sopenharmony_ci        self.crypto.getRandomValues(new DataView(new ArrayBuffer(65536 + 1)))
271cb0ef41Sopenharmony_ci    }, "DataView (too long)")
281cb0ef41Sopenharmony_ci}, "DataView");
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciconst arrays = [
311cb0ef41Sopenharmony_ci    'Int8Array',
321cb0ef41Sopenharmony_ci    'Int16Array',
331cb0ef41Sopenharmony_ci    'Int32Array',
341cb0ef41Sopenharmony_ci    'BigInt64Array',
351cb0ef41Sopenharmony_ci    'Uint8Array',
361cb0ef41Sopenharmony_ci    'Uint8ClampedArray',
371cb0ef41Sopenharmony_ci    'Uint16Array',
381cb0ef41Sopenharmony_ci    'Uint32Array',
391cb0ef41Sopenharmony_ci    'BigUint64Array',
401cb0ef41Sopenharmony_ci];
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_cifor (const array of arrays) {
431cb0ef41Sopenharmony_ci    const ctor = globalThis[array];
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci    test(function() {
461cb0ef41Sopenharmony_ci        assert_equals(self.crypto.getRandomValues(new ctor(8)).constructor,
471cb0ef41Sopenharmony_ci                      ctor, "crypto.getRandomValues(new " + array + "(8))")
481cb0ef41Sopenharmony_ci    }, "Integer array: " + array);
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci    test(function() {
511cb0ef41Sopenharmony_ci        const maxlength = 65536 / ctor.BYTES_PER_ELEMENT;
521cb0ef41Sopenharmony_ci        assert_throws_dom("QuotaExceededError", function() {
531cb0ef41Sopenharmony_ci            self.crypto.getRandomValues(new ctor(maxlength + 1))
541cb0ef41Sopenharmony_ci        }, "crypto.getRandomValues length over 65536")
551cb0ef41Sopenharmony_ci    }, "Large length: " + array);
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci    test(function() {
581cb0ef41Sopenharmony_ci        assert_true(self.crypto.getRandomValues(new ctor(0)).length == 0)
591cb0ef41Sopenharmony_ci    }, "Null arrays: " + array);
601cb0ef41Sopenharmony_ci}
61