Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / webmidi / requestmidiaccess.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Tests navigator.requestMIDIAccess.");
9
10 var access;
11 var input;
12 var output;
13
14 function checkInputMap(inputs) {
15     window.inputs = inputs;
16     debug("for (var input of inputs.values())");
17     for (var input of inputs.values()) {
18         window.input = input;
19         shouldBeEqualToString("input.id", "MockInputID");
20         shouldBeEqualToString("input.manufacturer", "MockInputManufacturer");
21         shouldBeEqualToString("input.name", "MockInputName");
22         shouldBeEqualToString("input.version", "MockInputVersion");
23     }
24     debug("for (var input of inputs.keys())");
25     for (var key of inputs.keys()) {
26         window.inputKey = key;
27         shouldBeEqualToString("inputKey", "MockInputID");
28     }
29     debug("for (var input of inputs.entries())");
30     for (var entry of inputs.entries()) {
31         window.entry = entry;
32         shouldBe("entry[0]", "inputKey");
33         shouldBe("entry[1]", "input");
34     }
35     debug("for (var input of inputs)");
36     for (var entry of inputs) {
37         window.entry = entry;
38         shouldBe("entry[0]", "inputKey");
39         shouldBe("entry[1]", "input");
40     }
41     shouldBeTrue("inputs.has('MockInputID')");
42     shouldBeFalse("inputs.has('MockOutputID')");
43     shouldBe("inputs.get('MockInputID')", "input");
44     shouldBeUndefined("inputs.get('MockOutputID')");
45 }
46
47 function checkOutputMap(outputs) {
48     window.outputs = outputs;
49     debug("for (var output of outputs.values())");
50     for (var output of outputs.values()) {
51         window.output = output;
52         shouldBeEqualToString("output.id", "MockOutputID");
53         shouldBeEqualToString("output.manufacturer", "MockOutputManufacturer");
54         shouldBeEqualToString("output.name", "MockOutputName");
55         shouldBeEqualToString("output.version", "MockOutputVersion");
56     }
57     debug("for (var output of outputs.keys())");
58     for (var key of outputs.keys()) {
59         window.outputKey = key;
60         shouldBeEqualToString("outputKey", "MockOutputID");
61     }
62     debug("for (var output of outputs.entries())");
63     for (var entry of outputs.entries()) {
64         window.entry = entry;
65         shouldBe("entry[0]", "outputKey");
66         shouldBe("entry[1]", "output");
67     }
68     debug("for (var output of outputs)");
69     for (var entry of outputs) {
70         window.entry = entry;
71         shouldBe("entry[0]", "outputKey");
72         shouldBe("entry[1]", "output");
73     }
74     shouldBeTrue("outputs.has('MockOutputID')");
75     shouldBeFalse("outputs.has('MockInputID')");
76     shouldBe("outputs.get('MockOutputID')", "output");
77     shouldBeUndefined("outputs.get('MockInputID')");
78 }
79
80 function successCallback1(a) {
81     access = a;
82
83     testPassed("requestMIDIAccess() succeeded with access " + access + ".");
84
85     // Validate the values of the attributes on the access.
86     shouldBeDefined("access.sysexEnabled");
87     shouldBeFalse("access.sysexEnabled");
88     shouldBe("access.inputs.size", "1");
89     shouldBe("access.outputs.size", "1");
90     checkInputMap(access.inputs);
91     checkOutputMap(access.outputs);
92
93     window.output = access.outputs.values().next().value;
94     // Test sending of MIDI data with a Uint8Array.
95     var typedArrayData = new Uint8Array([0x90, 0x45, 0x7f]);
96     output.send(typedArrayData);
97
98     // Test sending of MIDI data with a regular Array.
99     output.send([0x90, 0x45, 0x7f]);
100     testPassed("a note on message is sent without timestamp");
101
102     // Test sending of MIDI data with a regular Array giving an explicit timestamp.
103     output.send([0x90, 0x45, 0x7f], performance.now());
104     testPassed("a note on message is sent with timestamp");
105
106     // Test sending of invalid MIDI data.
107     shouldThrow('output.send([0xfff, 0x45, 0x7f])');
108
109     // Test sending system exclusive messages. These should throw, since we don't have sysex access.
110     shouldThrow('output.send([0xf0, 0x45, 0xf7])');
111
112     // Now test System Exclusive access - our test mock should not allow this type of access.
113     navigator.requestMIDIAccess({sysex: true}).then(successCallback2, errorCallback2);
114 }
115
116 function errorCallback1(error) {
117     testFailed("requestMIDIAccess() error callback should not be called when requesting basic access.");
118     finishJSTest();
119 }
120
121 function successCallback2(access) {
122     testFailed("requestMIDIAccess() was not correctly blocked for System Exclusive access.");
123     finishJSTest();
124 }
125
126 function errorCallback2(error) {
127     testPassed("requestMIDIAccess() was correctly blocked for System Exclusive access with error " + error + ".");
128     finishJSTest();
129 }
130
131 window.jsTestIsAsync = true;
132
133 // Test basic access, with no System Exclusive.
134 navigator.requestMIDIAccess().then(successCallback1, errorCallback1);
135
136 </script>
137 </body>
138 </html>