Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webmidi / requestmidiaccess.html
blob72b004fbd6078d5798373ccd8e3e28607c282a45
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.");
10 var access;
11 var input;
12 var output;
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 shouldBeEqualToString("input.state", "connected");
24 shouldBeEqualToString("input.type", "input");
26 debug("for (var input of inputs.keys())");
27 for (var key of inputs.keys()) {
28 window.inputKey = key;
29 shouldBeEqualToString("inputKey", "MockInputID");
31 debug("for (var input of inputs.entries())");
32 for (var entry of inputs.entries()) {
33 window.entry = entry;
34 shouldBe("entry[0]", "inputKey");
35 shouldBe("entry[1]", "input");
37 debug("for (var input of inputs)");
38 for (var entry of inputs) {
39 window.entry = entry;
40 shouldBe("entry[0]", "inputKey");
41 shouldBe("entry[1]", "input");
43 shouldBeTrue("inputs.has('MockInputID')");
44 shouldBeFalse("inputs.has('MockOutputID')");
45 shouldBe("inputs.get('MockInputID')", "input");
46 shouldBeUndefined("inputs.get('MockOutputID')");
47 debug("inputs.forEach(...)");
48 inputs.forEach(function (input, key, map) {
49 window.forEachInput = input;
50 shouldBe("forEachInput", "input");
51 window.forEachInputKey = key;
52 shouldBe("forEachInputKey", "inputKey");
53 window.forEachMap = map;
54 shouldBe("forEachMap", "inputs");
55 });
58 function checkOutputMap(outputs) {
59 window.outputs = outputs;
60 debug("for (var output of outputs.values())");
61 for (var output of outputs.values()) {
62 window.output = output;
63 shouldBeEqualToString("output.id", "MockOutputID");
64 shouldBeEqualToString("output.manufacturer", "MockOutputManufacturer");
65 shouldBeEqualToString("output.name", "MockOutputName");
66 shouldBeEqualToString("output.version", "MockOutputVersion");
67 shouldBeEqualToString("output.state", "connected");
68 shouldBeEqualToString("output.type", "output");
70 debug("for (var output of outputs.keys())");
71 for (var key of outputs.keys()) {
72 window.outputKey = key;
73 shouldBeEqualToString("outputKey", "MockOutputID");
75 debug("for (var output of outputs.entries())");
76 for (var entry of outputs.entries()) {
77 window.entry = entry;
78 shouldBe("entry[0]", "outputKey");
79 shouldBe("entry[1]", "output");
81 debug("for (var output of outputs)");
82 for (var entry of outputs) {
83 window.entry = entry;
84 shouldBe("entry[0]", "outputKey");
85 shouldBe("entry[1]", "output");
87 shouldBeTrue("outputs.has('MockOutputID')");
88 shouldBeFalse("outputs.has('MockInputID')");
89 shouldBe("outputs.get('MockOutputID')", "output");
90 shouldBeUndefined("outputs.get('MockInputID')");
91 debug("outputs.forEach(...)");
92 outputs.forEach(function (output, key, map) {
93 window.forEachOutput = output;
94 shouldBe("forEachOutput", "output");
95 window.forEachOutputKey = key;
96 shouldBe("forEachOutputKey", "outputKey");
97 window.forEachMap = map;
98 shouldBe("forEachMap", "outputs");
99 });
102 function successCallback1(a) {
103 access = a;
105 testPassed("requestMIDIAccess() succeeded with access " + access + ".");
107 // Validate the values of the attributes on the access.
108 shouldBeDefined("access.sysexEnabled");
109 shouldBeFalse("access.sysexEnabled");
110 shouldBe("access.inputs.size", "1");
111 shouldBe("access.outputs.size", "1");
112 checkInputMap(access.inputs);
113 checkOutputMap(access.outputs);
115 window.output = access.outputs.values().next().value;
116 // Test sending of MIDI data with a Uint8Array.
117 var typedArrayData = new Uint8Array([0x90, 0x45, 0x7f]);
118 output.send(typedArrayData);
120 // Test sending of MIDI data with a regular Array.
121 output.send([0x90, 0x45, 0x7f]);
122 testPassed("a note on message is sent without timestamp");
124 // Test sending of MIDI data with a regular Array giving an explicit timestamp.
125 output.send([0x90, 0x45, 0x7f], performance.now());
126 testPassed("a note on message is sent with timestamp");
128 // Test sending of invalid MIDI data.
129 shouldThrow('output.send([0xfff, 0x45, 0x7f])');
131 // Test sending system exclusive messages. These should throw, since we don't have sysex access.
132 shouldThrow('output.send([0xf0, 0x45, 0xf7])');
134 // Now test System Exclusive access - our test mock should not allow this type of access.
135 navigator.requestMIDIAccess({sysex: true}).then(successCallback2, errorCallback2);
138 function errorCallback1(error) {
139 testFailed("requestMIDIAccess() error callback should not be called when requesting basic access.");
140 finishJSTest();
143 function successCallback2(access) {
144 testFailed("requestMIDIAccess() was not correctly blocked for System Exclusive access.");
145 finishJSTest();
148 function errorCallback2(error) {
149 testPassed("requestMIDIAccess() was correctly blocked for System Exclusive access with error " + error + ".");
150 finishJSTest();
153 window.jsTestIsAsync = true;
155 // Test basic access, with no System Exclusive.
156 navigator.requestMIDIAccess().then(successCallback1, errorCallback1);
158 </script>
159 </body>
160 </html>