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

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

Issue 2673423002: Web MIDI: add dynamic MidiManager instantiation support for Linux (Closed)
Patch Set: update metrics Created 3 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.h" 5 #include "media/midi/midi_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/system_monitor/system_monitor.h" 19 #include "base/system_monitor/system_monitor.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "media/midi/midi_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace midi { 24 namespace midi {
24 25
25 namespace { 26 namespace {
26 27
27 using mojom::PortState; 28 using mojom::PortState;
28 using mojom::Result; 29 using mojom::Result;
29 30
30 class FakeMidiManager : public MidiManager { 31 class FakeMidiManager : public MidiManager {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 Result result_; 105 Result result_;
105 bool wait_for_result_; 106 bool wait_for_result_;
106 107
107 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); 108 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient);
108 }; 109 };
109 110
110 class MidiManagerTest : public ::testing::Test { 111 class MidiManagerTest : public ::testing::Test {
111 public: 112 public:
112 MidiManagerTest() 113 MidiManagerTest()
113 : manager_(new FakeMidiManager), 114 : manager_(new FakeMidiManager),
115 service_(new MidiService(base::WrapUnique(manager_))),
114 message_loop_(new base::MessageLoop) {} 116 message_loop_(new base::MessageLoop) {}
115 ~MidiManagerTest() override { 117 ~MidiManagerTest() override {
116 manager_->Shutdown(); 118 manager_->Shutdown();
117 base::RunLoop run_loop; 119 base::RunLoop run_loop;
118 run_loop.RunUntilIdle(); 120 run_loop.RunUntilIdle();
119 EXPECT_EQ(manager_->start_initialization_is_called_, 121 EXPECT_EQ(manager_->start_initialization_is_called_,
120 manager_->finalize_is_called_); 122 manager_->finalize_is_called_);
121 } 123 }
122 124
123 protected: 125 protected:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void CompleteInitialization(Result result) { 158 void CompleteInitialization(Result result) {
157 manager_->CallCompleteInitialization(result); 159 manager_->CallCompleteInitialization(result);
158 } 160 }
159 161
160 void RunLoopUntilIdle() { 162 void RunLoopUntilIdle() {
161 base::RunLoop run_loop; 163 base::RunLoop run_loop;
162 run_loop.RunUntilIdle(); 164 run_loop.RunUntilIdle();
163 } 165 }
164 166
165 protected: 167 protected:
166 std::unique_ptr<FakeMidiManager> manager_; 168 FakeMidiManager* manager_; // Owned by |service_|.
169 std::unique_ptr<MidiService> service_;
167 170
168 private: 171 private:
169 std::unique_ptr<base::MessageLoop> message_loop_; 172 std::unique_ptr<base::MessageLoop> message_loop_;
170 173
171 DISALLOW_COPY_AND_ASSIGN(MidiManagerTest); 174 DISALLOW_COPY_AND_ASSIGN(MidiManagerTest);
172 }; 175 };
173 176
174 TEST_F(MidiManagerTest, StartAndEndSession) { 177 TEST_F(MidiManagerTest, StartAndEndSession) {
175 std::unique_ptr<FakeMidiManagerClient> client; 178 std::unique_ptr<FakeMidiManagerClient> client;
176 client.reset(new FakeMidiManagerClient); 179 client.reset(new FakeMidiManagerClient);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 base::RunLoop run_loop; 295 base::RunLoop run_loop;
293 run_loop.RunUntilIdle(); 296 run_loop.RunUntilIdle();
294 } 297 }
295 298
296 // TODO(toyoshim): Add multi-threaded unit tests to check races around 299 // TODO(toyoshim): Add multi-threaded unit tests to check races around
297 // StartInitialization(), CompleteInitialization(), and Finalize(). 300 // StartInitialization(), CompleteInitialization(), and Finalize().
298 301
299 } // namespace 302 } // namespace
300 303
301 } // namespace midi 304 } // namespace midi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698