summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/webmidi/requestmidiaccess.html
blob: 0696dc7a2544769704da52862ac1dbfd7ad0d56e (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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
<script src="../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests navigator.requestMIDIAccess.");

var access;

function successCallback1(a) {
    access = a;

    testPassed('requestMIDIAccess() succeeded with access ' + access + '.');

    // Validate that we have one mock input and one mock output.
    shouldBe('access.inputs().length', '1');
    shouldBe('access.outputs().length', '1');

    var inputs = access.inputs();
    var outputs = access.outputs();
    var input = inputs[0];
    var output = outputs[0];

    // Validate the values of the attributes on the input and output.
    if (input.id == "MockInputID" &&
        input.manufacturer == "MockInputManufacturer" &&
        input.name == "MockInputName" &&
        input.version == "MockInputVersion") {
        testPassed('input attributes are correct');
    } else {
        testFailed('input attributes are not correct');
    }

    if (output.id == "MockOutputID" &&
        output.manufacturer == "MockOutputManufacturer" &&
        output.name == "MockOutputName" &&
        output.version == "MockOutputVersion") {
        testPassed('output attributes are correct');
    } else {
        testFailed('output attributes are not correct');
    }

    // Test sending of MIDI data with a Uint8Array.
    var typedArrayData = new Uint8Array([0x90, 0x45, 0x7f]);
    output.send(typedArrayData);

    // Test sending of MIDI data with a regular Array.
    output.send([0x90, 0x45, 0x7f]);

    // Test sending of MIDI data with a regular Array giving an explicit timestamp.
    output.send([0x90, 0x45, 0x7f], performance.now());

    // Now test System Exclusive access - our test mock should not allow this type of access.
    try {
        navigator.requestMIDIAccess( { sysex: true } ).then(successCallback2, errorCallback2);
        testPassed('navigator.requestMIDIAccess() did not throw exception.');
    } catch(e) {
        testFailed('navigator.requestMIDIAccess() should not throw exception.');
        finishJSTest();
    }
}

function errorCallback1(error) {
    testFailed('requestMIDIAccess() error callback should not be called when requesting basic access.');
    finishJSTest();
}

function successCallback2(access) {
    testFailed('requestMIDIAccess() was not correctly blocked for System Exclusive access.');
    finishJSTest();
}

function errorCallback2(error) {
    testPassed('requestMIDIAccess() was correctly blocked for System Exclusive access with error ' + error + '.');
    finishJSTest();
}

window.jsTestIsAsync = true;

// Test basic access, with no System Exclusive.
try {
    navigator.requestMIDIAccess().then(successCallback1, errorCallback1);
    testPassed('navigator.requestMIDIAccess() did not throw exception.');
} catch(e) {
    testFailed('navigator.requestMIDIAccess() should not throw exception.');
    finishJSTest();
}

window.successfullyParsed = true;

</script>
<script src="../fast/js/resources/js-test-post.js"></script>
</body>
</html>