| 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 <array> | 5 #include <array> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 TEST_F(VideoCaptureImplManagerTest, SuspendAndResumeSessions) { | 229 TEST_F(VideoCaptureImplManagerTest, SuspendAndResumeSessions) { |
| 230 std::array<base::Closure, kNumClients> release_callbacks; | 230 std::array<base::Closure, kNumClients> release_callbacks; |
| 231 for (size_t i = 0; i < kNumClients; ++i) { | 231 for (size_t i = 0; i < kNumClients; ++i) { |
| 232 release_callbacks[i] = | 232 release_callbacks[i] = |
| 233 manager_->UseDevice(static_cast<media::VideoCaptureSessionId>(i)); | 233 manager_->UseDevice(static_cast<media::VideoCaptureSessionId>(i)); |
| 234 } | 234 } |
| 235 std::array<base::Closure, kNumClients> stop_callbacks = | 235 std::array<base::Closure, kNumClients> stop_callbacks = |
| 236 StartCaptureForAllClients(false); | 236 StartCaptureForAllClients(false); |
| 237 | 237 |
| 238 // Call SuspendDevices(true) to suspend all clients, and expect all to be | |
| 239 // paused. | |
| 240 { | |
| 241 base::RunLoop run_loop; | |
| 242 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | |
| 243 EXPECT_CALL(*this, OnPaused(0)).Times(1).RetiresOnSaturation(); | |
| 244 EXPECT_CALL(*this, OnPaused(1)).Times(1).RetiresOnSaturation(); | |
| 245 EXPECT_CALL(*this, OnPaused(2)).WillOnce(RunClosure(quit_closure)) | |
| 246 .RetiresOnSaturation(); | |
| 247 manager_->SuspendDevices(true); | |
| 248 run_loop.Run(); | |
| 249 } | |
| 250 | |
| 251 // Call SuspendDevices(false) and expect all to be resumed. | |
| 252 { | |
| 253 base::RunLoop run_loop; | |
| 254 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | |
| 255 EXPECT_CALL(*this, OnResumed(0)).Times(1).RetiresOnSaturation(); | |
| 256 EXPECT_CALL(*this, OnResumed(1)).Times(1).RetiresOnSaturation(); | |
| 257 EXPECT_CALL(*this, OnResumed(2)).WillOnce(RunClosure(quit_closure)) | |
| 258 .RetiresOnSaturation(); | |
| 259 manager_->SuspendDevices(false); | |
| 260 run_loop.Run(); | |
| 261 } | |
| 262 | |
| 263 // Suspend just the first client and expect just the first client to be | 238 // Suspend just the first client and expect just the first client to be |
| 264 // paused. | 239 // paused. |
| 265 { | 240 { |
| 266 base::RunLoop run_loop; | 241 base::RunLoop run_loop; |
| 267 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 242 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
| 268 EXPECT_CALL(*this, OnPaused(0)).WillOnce(RunClosure(quit_closure)) | 243 EXPECT_CALL(*this, OnPaused(0)).WillOnce(RunClosure(quit_closure)) |
| 269 .RetiresOnSaturation(); | 244 .RetiresOnSaturation(); |
| 270 manager_->Suspend(0); | 245 manager_->Suspend(0); |
| 271 run_loop.Run(); | 246 run_loop.Run(); |
| 272 } | 247 } |
| 273 | 248 |
| 274 // Now call SuspendDevices(true) again, and expect just the second and third | 249 // Resume just the first client, and expect just the first client to be |
| 275 // clients to be paused. | 250 // resumed. |
| 276 { | 251 { |
| 277 base::RunLoop run_loop; | 252 base::RunLoop run_loop; |
| 278 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | 253 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); |
| 279 EXPECT_CALL(*this, OnPaused(1)).Times(1).RetiresOnSaturation(); | 254 EXPECT_CALL(*this, OnResumed(0)) |
| 280 EXPECT_CALL(*this, OnPaused(2)).WillOnce(RunClosure(quit_closure)) | 255 .WillOnce(RunClosure(quit_closure)) |
| 281 .RetiresOnSaturation(); | 256 .RetiresOnSaturation(); |
| 282 manager_->SuspendDevices(true); | 257 manager_->Resume(0); |
| 283 run_loop.Run(); | 258 run_loop.Run(); |
| 284 } | 259 } |
| 285 | 260 |
| 286 // Resume just the first client, but it should not resume because all devices | |
| 287 // are supposed to be suspended. | |
| 288 { | |
| 289 manager_->Resume(0); | |
| 290 base::RunLoop().RunUntilIdle(); | |
| 291 } | |
| 292 | |
| 293 // Now, call SuspendDevices(false) and expect all to be resumed. | |
| 294 { | |
| 295 base::RunLoop run_loop; | |
| 296 base::Closure quit_closure = BindToCurrentLoop(run_loop.QuitClosure()); | |
| 297 EXPECT_CALL(*this, OnResumed(0)).Times(1).RetiresOnSaturation(); | |
| 298 EXPECT_CALL(*this, OnResumed(1)).Times(1).RetiresOnSaturation(); | |
| 299 EXPECT_CALL(*this, OnResumed(2)).WillOnce(RunClosure(quit_closure)) | |
| 300 .RetiresOnSaturation(); | |
| 301 manager_->SuspendDevices(false); | |
| 302 run_loop.Run(); | |
| 303 } | |
| 304 | |
| 305 StopCaptureForAllClients(&stop_callbacks); | 261 StopCaptureForAllClients(&stop_callbacks); |
| 306 for (const auto& release_callback : release_callbacks) | 262 for (const auto& release_callback : release_callbacks) |
| 307 release_callback.Run(); | 263 release_callback.Run(); |
| 308 cleanup_run_loop_.Run(); | 264 cleanup_run_loop_.Run(); |
| 309 } | 265 } |
| 310 | 266 |
| 311 } // namespace content | 267 } // namespace content |
| OLD | NEW |