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

Side by Side Diff: media/midi/midi_manager_mac_unittest.cc

Issue 971593002: Web MIDI: speculative valgrind fix for a unit test on mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not use gtest macros outside test thread Created 5 years, 9 months 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
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/media_unittests.gtest_mac.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/midi/midi_manager_mac.h" 5 #include "media/midi/midi_manager_mac.h"
6 6
7 #include <CoreMIDI/MIDIServices.h> 7 #include <CoreMIDI/MIDIServices.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/synchronization/lock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace media { 16 namespace media {
16 17
17 namespace { 18 namespace {
18 19
19 void Noop(const MIDIPacketList*, void*, void*) {} 20 void Noop(const MIDIPacketList*, void*, void*) {}
20 21
21 class FakeMidiManagerClient : public MidiManagerClient { 22 class FakeMidiManagerClient : public MidiManagerClient {
22 public: 23 public:
23 FakeMidiManagerClient() 24 FakeMidiManagerClient()
24 : result_(MIDI_NOT_SUPPORTED), 25 : result_(MIDI_NOT_SUPPORTED),
25 wait_for_result_(true), 26 wait_for_result_(true),
26 wait_for_port_(true) {} 27 wait_for_port_(true),
28 unexpected_callback_(false) {}
27 29
28 // MidiManagerClient implementation. 30 // MidiManagerClient implementation.
29 void AddInputPort(const MidiPortInfo& info) override {} 31 void AddInputPort(const MidiPortInfo& info) override {}
30 void AddOutputPort(const MidiPortInfo& info) override { 32 void AddOutputPort(const MidiPortInfo& info) override {
31 CHECK(!wait_for_result_); 33 base::AutoLock lock(lock_);
34 // AddOutputPort may be called before CompleteStartSession() is invoked
35 // if one or more MIDI devices including virtual ports are connected.
36 // Just ignore in such cases.
37 if (wait_for_result_)
38 return;
39
40 // Check if this is the first call after CompleteStartSession(), and
41 // the case should not happen twice.
42 if (!wait_for_port_)
43 unexpected_callback_ = true;
44
32 info_ = info; 45 info_ = info;
33 wait_for_port_ = false; 46 wait_for_port_ = false;
34 } 47 }
35 void SetInputPortState(uint32 port_index, MidiPortState state) override {} 48 void SetInputPortState(uint32 port_index, MidiPortState state) override {}
36 void SetOutputPortState(uint32 port_index, MidiPortState state) override {} 49 void SetOutputPortState(uint32 port_index, MidiPortState state) override {}
37 50
38 void CompleteStartSession(MidiResult result) override { 51 void CompleteStartSession(MidiResult result) override {
39 EXPECT_TRUE(wait_for_result_); 52 base::AutoLock lock(lock_);
53 if (!wait_for_result_)
54 unexpected_callback_ = true;
55
40 result_ = result; 56 result_ = result;
41 wait_for_result_ = false; 57 wait_for_result_ = false;
42 } 58 }
43 59
44 void ReceiveMidiData(uint32 port_index, const uint8* data, size_t size, 60 void ReceiveMidiData(uint32 port_index, const uint8* data, size_t size,
45 double timestamp) override {} 61 double timestamp) override {}
46 void AccumulateMidiBytesSent(size_t size) override {} 62 void AccumulateMidiBytesSent(size_t size) override {}
47 63
64 bool GetWaitForResult() {
65 base::AutoLock lock(lock_);
66 return wait_for_result_;
67 }
68
69 bool GetWaitForPort() {
70 base::AutoLock lock(lock_);
71 return wait_for_port_;
72 }
73
48 MidiResult WaitForResult() { 74 MidiResult WaitForResult() {
49 while (wait_for_result_) { 75 while (GetWaitForResult()) {
50 base::RunLoop run_loop; 76 base::RunLoop run_loop;
51 run_loop.RunUntilIdle(); 77 run_loop.RunUntilIdle();
52 } 78 }
79 EXPECT_FALSE(unexpected_callback_);
53 return result_; 80 return result_;
54 } 81 }
55 MidiPortInfo WaitForPort() { 82 MidiPortInfo WaitForPort() {
56 while (wait_for_port_) { 83 while (GetWaitForPort()) {
57 base::RunLoop run_loop; 84 base::RunLoop run_loop;
58 run_loop.RunUntilIdle(); 85 run_loop.RunUntilIdle();
59 } 86 }
87 EXPECT_FALSE(unexpected_callback_);
60 return info_; 88 return info_;
61 } 89 }
62 90
63 private: 91 private:
92 base::Lock lock_;
64 MidiResult result_; 93 MidiResult result_;
65 bool wait_for_result_; 94 bool wait_for_result_;
66 MidiPortInfo info_; 95 MidiPortInfo info_;
67 bool wait_for_port_; 96 bool wait_for_port_;
97 bool unexpected_callback_;
68 98
69 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); 99 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient);
70 }; 100 };
71 101
72 class MidiManagerMacTest : public ::testing::Test { 102 class MidiManagerMacTest : public ::testing::Test {
73 public: 103 public:
74 MidiManagerMacTest() 104 MidiManagerMacTest()
75 : manager_(new MidiManagerMac), 105 : manager_(new MidiManagerMac),
76 message_loop_(new base::MessageLoop) {} 106 message_loop_(new base::MessageLoop) {}
77 107
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EndSession(client.get()); 147 EndSession(client.get());
118 if (ep) 148 if (ep)
119 MIDIEndpointDispose(ep); 149 MIDIEndpointDispose(ep);
120 if (midi_client) 150 if (midi_client)
121 MIDIClientDispose(midi_client); 151 MIDIClientDispose(midi_client);
122 } 152 }
123 153
124 } // namespace 154 } // namespace
125 155
126 } // namespace media 156 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/media_unittests.gtest_mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698