Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: trunk/src/content/browser/renderer_host/media/midi_host_unittest.cc

Issue 93583002: Revert 237558 "Use MIDIMessageQueue/IsValidWebMIDIData for MIDI ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/media/midi_host.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace content {
10 namespace {
11
12 const uint8 kGMOn[] = { 0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7 };
13 const uint8 kGSOn[] = {
14 0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, 0x7f, 0x00, 0x41, 0xf7,
15 };
16 const uint8 kNoteOn[] = { 0x90, 0x3c, 0x7f };
17 const uint8 kNoteOnWithRunningStatus[] = {
18 0x90, 0x3c, 0x7f, 0x3c, 0x7f, 0x3c, 0x7f,
19 };
20 const uint8 kChannelPressure[] = { 0xd0, 0x01 };
21 const uint8 kChannelPressureWithRunningStatus[] = {
22 0xd0, 0x01, 0x01, 0x01,
23 };
24 const uint8 kTimingClock[] = { 0xf8 };
25 const uint8 kBrokenData1[] = { 0x90 };
26 const uint8 kBrokenData2[] = { 0xf7 };
27 const uint8 kBrokenData3[] = { 0xf2, 0x00 };
28 const uint8 kDataByte0[] = { 0x00 };
29
30 template <typename T, size_t N>
31 const std::vector<T> AsVector(const T(&data)[N]) {
32 std::vector<T> buffer;
33 buffer.insert(buffer.end(), data, data + N);
34 return buffer;
35 }
36
37 template <typename T, size_t N>
38 void PushToVector(const T(&data)[N], std::vector<T>* buffer) {
39 buffer->insert(buffer->end(), data, data + N);
40 }
41
42 } // namespace
43
44 TEST(MIDIHostTest, IsValidWebMIDIData) {
45 // Test single event scenario
46 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(AsVector(kGMOn)));
47 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(AsVector(kGSOn)));
48 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(AsVector(kNoteOn)));
49 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(AsVector(kChannelPressure)));
50 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(AsVector(kTimingClock)));
51 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(AsVector(kBrokenData1)));
52 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(AsVector(kBrokenData2)));
53 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(AsVector(kBrokenData3)));
54 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(AsVector(kDataByte0)));
55
56 // MIDI running status should be disallowed
57 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(
58 AsVector(kNoteOnWithRunningStatus)));
59 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(
60 AsVector(kChannelPressureWithRunningStatus)));
61
62 // Multiple messages are allowed as long as each of them is complete.
63 {
64 std::vector<uint8> buffer;
65 PushToVector(kGMOn, &buffer);
66 PushToVector(kNoteOn, &buffer);
67 PushToVector(kGSOn, &buffer);
68 PushToVector(kTimingClock, &buffer);
69 PushToVector(kNoteOn, &buffer);
70 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(buffer));
71 PushToVector(kBrokenData1, &buffer);
72 EXPECT_FALSE(MIDIHost::IsValidWebMIDIData(buffer));
73 }
74
75 // MIDI realtime message can be placed at any position.
76 {
77 const uint8 kNoteOnWithRealTimeClock[] = {
78 0x90, 0xf8, 0x3c, 0x7f, 0x90, 0xf8, 0x3c, 0xf8, 0x7f, 0xf8,
79 };
80 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(
81 AsVector(kNoteOnWithRealTimeClock)));
82
83 const uint8 kGMOnWithRealTimeClock[] = {
84 0xf0, 0xf8, 0x7e, 0x7f, 0x09, 0x01, 0xf8, 0xf7,
85 };
86 EXPECT_TRUE(MIDIHost::IsValidWebMIDIData(AsVector(kGMOnWithRealTimeClock)));
87 }
88 }
89
90 } // namespace conent
OLDNEW
« no previous file with comments | « trunk/src/content/browser/renderer_host/media/midi_host.cc ('k') | trunk/src/content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698