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 <vector> | 7 #include <vector> |
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" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 StartTheFirstSession(client.get()); | 165 StartTheFirstSession(client.get()); |
166 CompleteInitialization(MIDI_INITIALIZATION_ERROR); | 166 CompleteInitialization(MIDI_INITIALIZATION_ERROR); |
167 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, client->WaitForResult()); | 167 EXPECT_EQ(MIDI_INITIALIZATION_ERROR, client->WaitForResult()); |
168 EndSession(client.get(), 0U, 0U); | 168 EndSession(client.get(), 0U, 0U); |
169 } | 169 } |
170 | 170 |
171 TEST_F(MidiManagerTest, StartMultipleSessions) { | 171 TEST_F(MidiManagerTest, StartMultipleSessions) { |
172 scoped_ptr<FakeMidiManagerClient> client1; | 172 scoped_ptr<FakeMidiManagerClient> client1; |
173 scoped_ptr<FakeMidiManagerClient> client2; | 173 scoped_ptr<FakeMidiManagerClient> client2; |
| 174 scoped_ptr<FakeMidiManagerClient> client3; |
174 client1.reset(new FakeMidiManagerClient(0)); | 175 client1.reset(new FakeMidiManagerClient(0)); |
175 client2.reset(new FakeMidiManagerClient(1)); | 176 client2.reset(new FakeMidiManagerClient(1)); |
| 177 client3.reset(new FakeMidiManagerClient(1)); |
176 | 178 |
177 StartTheFirstSession(client1.get()); | 179 StartTheFirstSession(client1.get()); |
178 StartTheNthSession(client2.get(), 2); | 180 StartTheNthSession(client2.get(), 2); |
| 181 StartTheNthSession(client3.get(), 3); |
179 CompleteInitialization(MIDI_OK); | 182 CompleteInitialization(MIDI_OK); |
180 EXPECT_EQ(MIDI_OK, client1->WaitForResult()); | 183 EXPECT_EQ(MIDI_OK, client1->WaitForResult()); |
181 EXPECT_EQ(MIDI_OK, client2->WaitForResult()); | 184 EXPECT_EQ(MIDI_OK, client2->WaitForResult()); |
182 EndSession(client1.get(), 2U, 1U); | 185 EXPECT_EQ(MIDI_OK, client3->WaitForResult()); |
183 EndSession(client2.get(), 1U, 0U); | 186 EndSession(client1.get(), 3U, 2U); |
| 187 EndSession(client2.get(), 2U, 1U); |
| 188 EndSession(client3.get(), 1U, 0U); |
184 } | 189 } |
185 | 190 |
| 191 // TODO(toyoshim): Add a test for a MidiManagerClient that has multiple |
| 192 // sessions with multiple client_id. |
| 193 |
186 TEST_F(MidiManagerTest, TooManyPendingSessions) { | 194 TEST_F(MidiManagerTest, TooManyPendingSessions) { |
187 // Push as many client requests for starting session as possible. | 195 // Push as many client requests for starting session as possible. |
188 ScopedVector<FakeMidiManagerClient> many_existing_clients; | 196 ScopedVector<FakeMidiManagerClient> many_existing_clients; |
189 many_existing_clients.resize(MidiManager::kMaxPendingClientCount); | 197 many_existing_clients.resize(MidiManager::kMaxPendingClientCount); |
190 for (size_t i = 0; i < MidiManager::kMaxPendingClientCount; ++i) { | 198 for (size_t i = 0; i < MidiManager::kMaxPendingClientCount; ++i) { |
191 many_existing_clients[i] = new FakeMidiManagerClient(i); | 199 many_existing_clients[i] = new FakeMidiManagerClient(i); |
192 StartTheNthSession(many_existing_clients[i], i + 1); | 200 StartTheNthSession(many_existing_clients[i], i + 1); |
193 } | 201 } |
194 | 202 |
195 // Push the last client that should be rejected for too many pending requests. | 203 // Push the last client that should be rejected for too many pending requests. |
(...skipping 14 matching lines...) Expand all Loading... |
210 CompleteInitialization(MIDI_OK); | 218 CompleteInitialization(MIDI_OK); |
211 for (size_t i = 0; i < many_existing_clients.size(); ++i) | 219 for (size_t i = 0; i < many_existing_clients.size(); ++i) |
212 EXPECT_EQ(MIDI_OK, many_existing_clients[i]->WaitForResult()); | 220 EXPECT_EQ(MIDI_OK, many_existing_clients[i]->WaitForResult()); |
213 | 221 |
214 // Close all successful sessions in FIFO order. | 222 // Close all successful sessions in FIFO order. |
215 size_t sessions = many_existing_clients.size(); | 223 size_t sessions = many_existing_clients.size(); |
216 for (size_t i = 0; i < many_existing_clients.size(); ++i, --sessions) | 224 for (size_t i = 0; i < many_existing_clients.size(); ++i, --sessions) |
217 EndSession(many_existing_clients[i], sessions, sessions - 1); | 225 EndSession(many_existing_clients[i], sessions, sessions - 1); |
218 } | 226 } |
219 | 227 |
| 228 TEST_F(MidiManagerTest, AbortSession) { |
| 229 // A client starting a session can be destructed while an asynchronous |
| 230 // initialization is performed. |
| 231 scoped_ptr<FakeMidiManagerClient> client; |
| 232 client.reset(new FakeMidiManagerClient(0)); |
| 233 |
| 234 StartTheFirstSession(client.get()); |
| 235 EndSession(client.get(), 0, 0); |
| 236 client.reset(); |
| 237 |
| 238 // Following function should not call the destructed |client| function. |
| 239 CompleteInitialization(MIDI_OK); |
| 240 base::RunLoop run_loop; |
| 241 run_loop.RunUntilIdle(); |
| 242 } |
| 243 |
220 TEST_F(MidiManagerTest, CreateMidiManager) { | 244 TEST_F(MidiManagerTest, CreateMidiManager) { |
221 scoped_ptr<FakeMidiManagerClient> client; | 245 scoped_ptr<FakeMidiManagerClient> client; |
222 client.reset(new FakeMidiManagerClient(0)); | 246 client.reset(new FakeMidiManagerClient(0)); |
223 | 247 |
224 scoped_ptr<MidiManager> manager(MidiManager::Create()); | 248 scoped_ptr<MidiManager> manager(MidiManager::Create()); |
225 manager->StartSession(client.get(), client->client_id()); | 249 manager->StartSession(client.get(), client->client_id()); |
226 | 250 |
227 MidiResult result = client->WaitForResult(); | 251 MidiResult result = client->WaitForResult(); |
228 // This #ifdef needs to be identical to the one in media/midi/midi_manager.cc. | 252 // This #ifdef needs to be identical to the one in media/midi/midi_manager.cc. |
229 // Do not change the condition for disabling this test. | 253 // Do not change the condition for disabling this test. |
230 #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA) && \ | 254 #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA) && \ |
231 !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 255 !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
232 EXPECT_EQ(MIDI_NOT_SUPPORTED, result); | 256 EXPECT_EQ(MIDI_NOT_SUPPORTED, result); |
233 #elif defined(USE_ALSA) | 257 #elif defined(USE_ALSA) |
234 // Temporary until http://crbug.com/371230 is resolved. | 258 // Temporary until http://crbug.com/371230 is resolved. |
235 EXPECT_TRUE((result == MIDI_OK) || (result == MIDI_INITIALIZATION_ERROR)); | 259 EXPECT_TRUE((result == MIDI_OK) || (result == MIDI_INITIALIZATION_ERROR)); |
236 #else | 260 #else |
237 EXPECT_EQ(MIDI_OK, result); | 261 EXPECT_EQ(MIDI_OK, result); |
238 #endif | 262 #endif |
239 } | 263 } |
240 | 264 |
241 } // namespace | 265 } // namespace |
242 | 266 |
243 } // namespace media | 267 } // namespace media |
OLD | NEW |