OLD | NEW |
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/ptr_util.h" |
17 #include "base/memory/scoped_vector.h" | |
18 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
19 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
20 #include "base/system_monitor/system_monitor.h" | 19 #include "base/system_monitor/system_monitor.h" |
21 #include "build/build_config.h" | 20 #include "build/build_config.h" |
22 #include "media/midi/midi_service.h" | 21 #include "media/midi/midi_service.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
24 | 23 |
25 namespace midi { | 24 namespace midi { |
26 | 25 |
27 namespace { | 26 namespace { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 EndSession(client1.get(), 3U, 2U); | 214 EndSession(client1.get(), 3U, 2U); |
216 EndSession(client2.get(), 2U, 1U); | 215 EndSession(client2.get(), 2U, 1U); |
217 EndSession(client3.get(), 1U, 0U); | 216 EndSession(client3.get(), 1U, 0U); |
218 } | 217 } |
219 | 218 |
220 // TODO(toyoshim): Add a test for a MidiManagerClient that has multiple | 219 // TODO(toyoshim): Add a test for a MidiManagerClient that has multiple |
221 // sessions with multiple client_id. | 220 // sessions with multiple client_id. |
222 | 221 |
223 TEST_F(MidiManagerTest, TooManyPendingSessions) { | 222 TEST_F(MidiManagerTest, TooManyPendingSessions) { |
224 // Push as many client requests for starting session as possible. | 223 // Push as many client requests for starting session as possible. |
225 ScopedVector<FakeMidiManagerClient> many_existing_clients; | 224 std::vector<std::unique_ptr<FakeMidiManagerClient>> many_existing_clients; |
226 many_existing_clients.resize(MidiManager::kMaxPendingClientCount); | 225 many_existing_clients.resize(MidiManager::kMaxPendingClientCount); |
227 for (size_t i = 0; i < MidiManager::kMaxPendingClientCount; ++i) { | 226 for (size_t i = 0; i < MidiManager::kMaxPendingClientCount; ++i) { |
228 many_existing_clients[i] = new FakeMidiManagerClient; | 227 many_existing_clients[i] = base::MakeUnique<FakeMidiManagerClient>(); |
229 StartTheNthSession(many_existing_clients[i], i + 1); | 228 StartTheNthSession(many_existing_clients[i].get(), i + 1); |
230 } | 229 } |
231 EXPECT_TRUE(manager_->start_initialization_is_called_); | 230 EXPECT_TRUE(manager_->start_initialization_is_called_); |
232 | 231 |
233 // Push the last client that should be rejected for too many pending requests. | 232 // Push the last client that should be rejected for too many pending requests. |
234 std::unique_ptr<FakeMidiManagerClient> additional_client( | 233 std::unique_ptr<FakeMidiManagerClient> additional_client( |
235 new FakeMidiManagerClient); | 234 new FakeMidiManagerClient); |
236 manager_->start_initialization_is_called_ = false; | 235 manager_->start_initialization_is_called_ = false; |
237 manager_->StartSession(additional_client.get()); | 236 manager_->StartSession(additional_client.get()); |
238 EXPECT_FALSE(manager_->start_initialization_is_called_); | 237 EXPECT_FALSE(manager_->start_initialization_is_called_); |
239 manager_->start_initialization_is_called_ = true; | 238 manager_->start_initialization_is_called_ = true; |
240 EXPECT_EQ(Result::INITIALIZATION_ERROR, additional_client->result()); | 239 EXPECT_EQ(Result::INITIALIZATION_ERROR, additional_client->result()); |
241 | 240 |
242 // Other clients still should not receive a result. | 241 // Other clients still should not receive a result. |
243 RunLoopUntilIdle(); | 242 RunLoopUntilIdle(); |
244 for (size_t i = 0; i < many_existing_clients.size(); ++i) | 243 for (size_t i = 0; i < many_existing_clients.size(); ++i) |
245 EXPECT_EQ(Result::NOT_SUPPORTED, many_existing_clients[i]->result()); | 244 EXPECT_EQ(Result::NOT_SUPPORTED, many_existing_clients[i]->result()); |
246 | 245 |
247 // The Result::OK should be distributed to other clients. | 246 // The Result::OK should be distributed to other clients. |
248 CompleteInitialization(Result::OK); | 247 CompleteInitialization(Result::OK); |
249 for (size_t i = 0; i < many_existing_clients.size(); ++i) | 248 for (size_t i = 0; i < many_existing_clients.size(); ++i) |
250 EXPECT_EQ(Result::OK, many_existing_clients[i]->WaitForResult()); | 249 EXPECT_EQ(Result::OK, many_existing_clients[i]->WaitForResult()); |
251 | 250 |
252 // Close all successful sessions in FIFO order. | 251 // Close all successful sessions in FIFO order. |
253 size_t sessions = many_existing_clients.size(); | 252 size_t sessions = many_existing_clients.size(); |
254 for (size_t i = 0; i < many_existing_clients.size(); ++i, --sessions) | 253 for (size_t i = 0; i < many_existing_clients.size(); ++i, --sessions) |
255 EndSession(many_existing_clients[i], sessions, sessions - 1); | 254 EndSession(many_existing_clients[i].get(), sessions, sessions - 1); |
256 } | 255 } |
257 | 256 |
258 TEST_F(MidiManagerTest, AbortSession) { | 257 TEST_F(MidiManagerTest, AbortSession) { |
259 // A client starting a session can be destructed while an asynchronous | 258 // A client starting a session can be destructed while an asynchronous |
260 // initialization is performed. | 259 // initialization is performed. |
261 std::unique_ptr<FakeMidiManagerClient> client; | 260 std::unique_ptr<FakeMidiManagerClient> client; |
262 client.reset(new FakeMidiManagerClient); | 261 client.reset(new FakeMidiManagerClient); |
263 | 262 |
264 StartTheFirstSession(client.get()); | 263 StartTheFirstSession(client.get()); |
265 EndSession(client.get(), 0, 0); | 264 EndSession(client.get(), 0, 0); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 base::RunLoop run_loop; | 297 base::RunLoop run_loop; |
299 run_loop.RunUntilIdle(); | 298 run_loop.RunUntilIdle(); |
300 } | 299 } |
301 | 300 |
302 // TODO(toyoshim): Add multi-threaded unit tests to check races around | 301 // TODO(toyoshim): Add multi-threaded unit tests to check races around |
303 // StartInitialization(), CompleteInitialization(), and Finalize(). | 302 // StartInitialization(), CompleteInitialization(), and Finalize(). |
304 | 303 |
305 } // namespace | 304 } // namespace |
306 | 305 |
307 } // namespace midi | 306 } // namespace midi |
OLD | NEW |