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

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

Issue 2673423002: Web MIDI: add dynamic MidiManager instantiation support for Linux (Closed)
Patch Set: rebase again 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
« no previous file with comments | « media/midi/midi_manager_mac_unittest.cc ('k') | media/midi/midi_manager_usb.h » ('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 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/ptr_util.h"
16 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 19 #include "base/run_loop.h"
19 #include "base/system_monitor/system_monitor.h" 20 #include "base/system_monitor/system_monitor.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "media/midi/midi_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 namespace midi { 25 namespace midi {
24 26
25 namespace { 27 namespace {
26 28
27 using mojom::PortState; 29 using mojom::PortState;
28 using mojom::Result; 30 using mojom::Result;
29 31
30 class FakeMidiManager : public MidiManager { 32 class FakeMidiManager : public MidiManager {
31 public: 33 public:
32 FakeMidiManager() 34 FakeMidiManager()
33 : start_initialization_is_called_(false), finalize_is_called_(false) {} 35 : MidiManager(nullptr),
36 start_initialization_is_called_(false),
37 finalize_is_called_(false) {}
34 ~FakeMidiManager() override {} 38 ~FakeMidiManager() override {}
35 39
36 // MidiManager implementation. 40 // MidiManager implementation.
37 void StartInitialization() override { 41 void StartInitialization() override {
38 start_initialization_is_called_ = true; 42 start_initialization_is_called_ = true;
39 } 43 }
40 44
41 void Finalize() override { finalize_is_called_ = true; } 45 void Finalize() override { finalize_is_called_ = true; }
42 46
43 void DispatchSendMidiData(MidiManagerClient* client, 47 void DispatchSendMidiData(MidiManagerClient* client,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 Result result_; 108 Result result_;
105 bool wait_for_result_; 109 bool wait_for_result_;
106 110
107 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); 111 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient);
108 }; 112 };
109 113
110 class MidiManagerTest : public ::testing::Test { 114 class MidiManagerTest : public ::testing::Test {
111 public: 115 public:
112 MidiManagerTest() 116 MidiManagerTest()
113 : manager_(new FakeMidiManager), 117 : manager_(new FakeMidiManager),
118 service_(new MidiService(base::WrapUnique(manager_))),
114 message_loop_(new base::MessageLoop) {} 119 message_loop_(new base::MessageLoop) {}
115 ~MidiManagerTest() override { 120 ~MidiManagerTest() override {
116 manager_->Shutdown(); 121 manager_->Shutdown();
117 base::RunLoop run_loop; 122 base::RunLoop run_loop;
118 run_loop.RunUntilIdle(); 123 run_loop.RunUntilIdle();
119 EXPECT_EQ(manager_->start_initialization_is_called_, 124 EXPECT_EQ(manager_->start_initialization_is_called_,
120 manager_->finalize_is_called_); 125 manager_->finalize_is_called_);
121 } 126 }
122 127
123 protected: 128 protected:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void CompleteInitialization(Result result) { 161 void CompleteInitialization(Result result) {
157 manager_->CallCompleteInitialization(result); 162 manager_->CallCompleteInitialization(result);
158 } 163 }
159 164
160 void RunLoopUntilIdle() { 165 void RunLoopUntilIdle() {
161 base::RunLoop run_loop; 166 base::RunLoop run_loop;
162 run_loop.RunUntilIdle(); 167 run_loop.RunUntilIdle();
163 } 168 }
164 169
165 protected: 170 protected:
166 std::unique_ptr<FakeMidiManager> manager_; 171 FakeMidiManager* manager_; // Owned by |service_|.
172 std::unique_ptr<MidiService> service_;
167 173
168 private: 174 private:
169 std::unique_ptr<base::MessageLoop> message_loop_; 175 std::unique_ptr<base::MessageLoop> message_loop_;
170 176
171 DISALLOW_COPY_AND_ASSIGN(MidiManagerTest); 177 DISALLOW_COPY_AND_ASSIGN(MidiManagerTest);
172 }; 178 };
173 179
174 TEST_F(MidiManagerTest, StartAndEndSession) { 180 TEST_F(MidiManagerTest, StartAndEndSession) {
175 std::unique_ptr<FakeMidiManagerClient> client; 181 std::unique_ptr<FakeMidiManagerClient> client;
176 client.reset(new FakeMidiManagerClient); 182 client.reset(new FakeMidiManagerClient);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Following function should not call the destructed |client| function. 268 // Following function should not call the destructed |client| function.
263 CompleteInitialization(Result::OK); 269 CompleteInitialization(Result::OK);
264 base::RunLoop run_loop; 270 base::RunLoop run_loop;
265 run_loop.RunUntilIdle(); 271 run_loop.RunUntilIdle();
266 } 272 }
267 273
268 TEST_F(MidiManagerTest, CreateMidiManager) { 274 TEST_F(MidiManagerTest, CreateMidiManager) {
269 // SystemMonitor is needed on Windows. 275 // SystemMonitor is needed on Windows.
270 base::SystemMonitor system_monitor; 276 base::SystemMonitor system_monitor;
271 277
272 std::unique_ptr<FakeMidiManagerClient> client; 278 std::unique_ptr<FakeMidiManagerClient> client(
273 client.reset(new FakeMidiManagerClient); 279 base::MakeUnique<FakeMidiManagerClient>());
274 280
275 std::unique_ptr<MidiManager> manager(MidiManager::Create()); 281 std::unique_ptr<MidiService> service(base::MakeUnique<MidiService>());
276 manager->StartSession(client.get()); 282 service->StartSession(client.get());
277 283
278 Result result = client->WaitForResult(); 284 Result result = client->WaitForResult();
279 // This #ifdef needs to be identical to the one in media/midi/midi_manager.cc. 285 // This #ifdef needs to be identical to the one in media/midi/midi_manager.cc.
280 // Do not change the condition for disabling this test. 286 // Do not change the condition for disabling this test.
281 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \ 287 #if !defined(OS_MACOSX) && !defined(OS_WIN) && \
282 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID) 288 !(defined(USE_ALSA) && defined(USE_UDEV)) && !defined(OS_ANDROID)
283 EXPECT_EQ(Result::NOT_SUPPORTED, result); 289 EXPECT_EQ(Result::NOT_SUPPORTED, result);
284 #elif defined(USE_ALSA) 290 #elif defined(USE_ALSA)
285 // Temporary until http://crbug.com/371230 is resolved. 291 // Temporary until http://crbug.com/371230 is resolved.
286 EXPECT_TRUE(result == Result::OK || result == Result::INITIALIZATION_ERROR); 292 EXPECT_TRUE(result == Result::OK || result == Result::INITIALIZATION_ERROR);
287 #else 293 #else
288 EXPECT_EQ(Result::OK, result); 294 EXPECT_EQ(Result::OK, result);
289 #endif 295 #endif
290 296
291 manager->Shutdown(); 297 service->Shutdown();
292 base::RunLoop run_loop; 298 base::RunLoop run_loop;
293 run_loop.RunUntilIdle(); 299 run_loop.RunUntilIdle();
294 } 300 }
295 301
296 // TODO(toyoshim): Add multi-threaded unit tests to check races around 302 // TODO(toyoshim): Add multi-threaded unit tests to check races around
297 // StartInitialization(), CompleteInitialization(), and Finalize(). 303 // StartInitialization(), CompleteInitialization(), and Finalize().
298 304
299 } // namespace 305 } // namespace
300 306
301 } // namespace midi 307 } // namespace midi
OLDNEW
« no previous file with comments | « media/midi/midi_manager_mac_unittest.cc ('k') | media/midi/midi_manager_usb.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698