| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 base::SharedMemoryHandle handle, | 52 base::SharedMemoryHandle handle, |
| 53 int length, int buffer_id) OVERRIDE { | 53 int length, int buffer_id) OVERRIDE { |
| 54 DoBufferCreated(id); | 54 DoBufferCreated(id); |
| 55 } | 55 } |
| 56 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 56 virtual void OnBufferReady(const VideoCaptureControllerID& id, |
| 57 int buffer_id, | 57 int buffer_id, |
| 58 base::Time timestamp) OVERRIDE { | 58 base::Time timestamp) OVERRIDE { |
| 59 DoBufferReady(id); | 59 DoBufferReady(id); |
| 60 base::MessageLoop::current()->PostTask(FROM_HERE, | 60 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 61 base::Bind(&VideoCaptureController::ReturnBuffer, | 61 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 62 controller_, id, this, buffer_id)); | 62 base::Unretained(controller_), id, this, buffer_id)); |
| 63 } | 63 } |
| 64 virtual void OnFrameInfo( | 64 virtual void OnFrameInfo( |
| 65 const VideoCaptureControllerID& id, | 65 const VideoCaptureControllerID& id, |
| 66 const media::VideoCaptureCapability& format) OVERRIDE { | 66 const media::VideoCaptureCapability& format) OVERRIDE { |
| 67 DoFrameInfo(id); | 67 DoFrameInfo(id); |
| 68 } | 68 } |
| 69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
| 70 DoEnded(id); | 70 DoEnded(id); |
| 71 // OnEnded() must respond by (eventually) unregistering the client. | 71 // OnEnded() must respond by (eventually) unregistering the client. |
| 72 base::MessageLoop::current()->PostTask(FROM_HERE, | 72 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 73 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 73 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
| 74 controller_, id, this)); | 74 base::Unretained(controller_), id, this)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 scoped_refptr<VideoCaptureController> controller_; | 77 VideoCaptureController* controller_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 // Test class. | 80 // Test class. |
| 81 class VideoCaptureControllerTest : public testing::Test { | 81 class VideoCaptureControllerTest : public testing::Test { |
| 82 public: | 82 public: |
| 83 VideoCaptureControllerTest() {} | 83 VideoCaptureControllerTest() {} |
| 84 virtual ~VideoCaptureControllerTest() {} | 84 virtual ~VideoCaptureControllerTest() {} |
| 85 | 85 |
| 86 protected: | 86 protected: |
| 87 static const int kPoolSize = 3; | 87 static const int kPoolSize = 3; |
| 88 | 88 |
| 89 virtual void SetUp() OVERRIDE { | 89 virtual void SetUp() OVERRIDE { |
| 90 controller_ = new VideoCaptureController(); | 90 controller_.reset(new VideoCaptureController()); |
| 91 device_ = controller_->NewDeviceClient().Pass(); |
| 91 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 92 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
| 92 controller_.get())); | 93 controller_.get())); |
| 93 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 94 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
| 94 controller_.get())); | 95 controller_.get())); |
| 95 } | 96 } |
| 96 | 97 |
| 97 virtual void TearDown() OVERRIDE { | 98 virtual void TearDown() OVERRIDE { |
| 98 base::RunLoop().RunUntilIdle(); | 99 base::RunLoop().RunUntilIdle(); |
| 99 } | 100 } |
| 100 | 101 |
| 101 TestBrowserThreadBundle bindle_; | 102 TestBrowserThreadBundle bindle_; |
| 102 scoped_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 103 scoped_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
| 103 scoped_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 104 scoped_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
| 104 scoped_refptr<VideoCaptureController> controller_; | 105 scoped_ptr<VideoCaptureController> controller_; |
| 106 scoped_ptr<media::VideoCaptureDevice::EventHandler> device_; |
| 105 | 107 |
| 106 private: | 108 private: |
| 107 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 109 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 // A simple test of VideoCaptureController's ability to add, remove, and keep | 112 // A simple test of VideoCaptureController's ability to add, remove, and keep |
| 111 // track of clients. | 113 // track of clients. |
| 112 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 114 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
| 113 media::VideoCaptureParams session_100; | 115 media::VideoCaptureParams session_100; |
| 114 session_100.session_id = 100; | 116 session_100.session_id = 100; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); | 235 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); |
| 234 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); | 236 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); |
| 235 | 237 |
| 236 // Start with two clients. | 238 // Start with two clients. |
| 237 controller_->AddClient(client_a_route_1, client_a_.get(), | 239 controller_->AddClient(client_a_route_1, client_a_.get(), |
| 238 base::kNullProcessHandle, session_100); | 240 base::kNullProcessHandle, session_100); |
| 239 controller_->AddClient(client_b_route_1, client_b_.get(), | 241 controller_->AddClient(client_b_route_1, client_b_.get(), |
| 240 base::kNullProcessHandle, session_300); | 242 base::kNullProcessHandle, session_300); |
| 241 ASSERT_EQ(2, controller_->GetClientCount()); | 243 ASSERT_EQ(2, controller_->GetClientCount()); |
| 242 | 244 |
| 245 // The OnFrameInfo() event from the device, when processed by the controller, |
| 246 // should generate client OnFrameInfo() and OnBufferCreated() events. |
| 243 { | 247 { |
| 244 InSequence s; | 248 InSequence s; |
| 245 EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_1)).Times(1); | 249 EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_1)).Times(1); |
| 246 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(kPoolSize); | 250 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(kPoolSize); |
| 247 } | 251 } |
| 248 { | 252 { |
| 249 InSequence s; | 253 InSequence s; |
| 250 EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_1)).Times(1); | 254 EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_1)).Times(1); |
| 251 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(kPoolSize); | 255 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(kPoolSize); |
| 252 } | 256 } |
| 253 // The Controller OnFrameInfo(), when processed, should turn into client | 257 device_->OnFrameInfo(device_format); |
| 254 // OnFrameInfo() and OnBufferCreated() events. | |
| 255 controller_->OnFrameInfo(device_format); | |
| 256 base::RunLoop().RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
| 257 Mock::VerifyAndClearExpectations(client_a_.get()); | 259 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 258 Mock::VerifyAndClearExpectations(client_b_.get()); | 260 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 259 | 261 |
| 260 // When a third clients is subsequently added, the frame info and buffers | 262 // When a third clients is subsequently added, the frame info and buffers |
| 261 // should immediately be shared to the new clients. | 263 // should immediately be shared to the new clients. |
| 262 { | 264 { |
| 263 InSequence s; | 265 InSequence s; |
| 264 EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_2)).Times(1); | 266 EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_2)).Times(1); |
| 265 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(kPoolSize); | 267 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(kPoolSize); |
| 266 } | 268 } |
| 267 controller_->AddClient(client_a_route_2, client_a_.get(), | 269 controller_->AddClient(client_a_route_2, client_a_.get(), |
| 268 base::kNullProcessHandle, session_200); | 270 base::kNullProcessHandle, session_200); |
| 269 Mock::VerifyAndClearExpectations(client_a_.get()); | 271 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 270 | 272 |
| 271 // Now, simulate an incoming captured frame from the capture device. | 273 // Now, simulate an incoming captured frame from the capture device. |
| 272 uint8 frame_no = 1; | 274 uint8 frame_no = 1; |
| 273 scoped_refptr<media::VideoFrame> frame; | 275 scoped_refptr<media::VideoFrame> frame; |
| 274 frame = controller_->ReserveOutputBuffer(); | 276 frame = device_->ReserveOutputBuffer(); |
| 275 ASSERT_TRUE(frame); | 277 ASSERT_TRUE(frame); |
| 276 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 278 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
| 277 controller_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 279 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 278 frame = NULL; | 280 frame = NULL; |
| 279 | 281 |
| 280 // The buffer should be delivered to the clients in any order. | 282 // The buffer should be delivered to the clients in any order. |
| 281 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 283 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
| 282 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 284 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
| 283 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 285 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
| 284 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
| 285 Mock::VerifyAndClearExpectations(client_a_.get()); | 287 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 286 Mock::VerifyAndClearExpectations(client_b_.get()); | 288 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 287 | 289 |
| 288 // Second frame. In this case pretend that the VideoFrame pointer is held | 290 // Second frame. In this case pretend that the VideoFrame pointer is held |
| 289 // by the device for a long delay. This shouldn't affect anything. | 291 // by the device for a long delay. This shouldn't affect anything. |
| 290 frame = controller_->ReserveOutputBuffer(); | 292 frame = device_->ReserveOutputBuffer(); |
| 291 ASSERT_TRUE(frame); | 293 ASSERT_TRUE(frame); |
| 292 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 294 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
| 293 controller_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 295 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 294 | 296 |
| 295 // The buffer should be delivered to the clients in any order. | 297 // The buffer should be delivered to the clients in any order. |
| 296 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 298 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
| 297 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 299 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
| 298 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 300 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
| 299 base::RunLoop().RunUntilIdle(); | 301 base::RunLoop().RunUntilIdle(); |
| 300 Mock::VerifyAndClearExpectations(client_a_.get()); | 302 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 301 Mock::VerifyAndClearExpectations(client_b_.get()); | 303 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 302 frame = NULL; | 304 frame = NULL; |
| 303 | 305 |
| 304 // Add a fourth client now that some frames have come through. It should get | 306 // Add a fourth client now that some frames have come through. It should get |
| 305 // the buffer info, but it won't get any frames until new ones are captured. | 307 // the buffer info, but it won't get any frames until new ones are captured. |
| 306 { | 308 { |
| 307 InSequence s; | 309 InSequence s; |
| 308 EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_2)).Times(1); | 310 EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_2)).Times(1); |
| 309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 311 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 310 } | 312 } |
| 311 controller_->AddClient(client_b_route_2, client_b_.get(), | 313 controller_->AddClient(client_b_route_2, client_b_.get(), |
| 312 base::kNullProcessHandle, session_1); | 314 base::kNullProcessHandle, session_1); |
| 313 Mock::VerifyAndClearExpectations(client_b_.get()); | 315 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 314 | 316 |
| 315 // Third, fourth, and fifth frames. Pretend they all arrive at the same time. | 317 // Third, fourth, and fifth frames. Pretend they all arrive at the same time. |
| 316 for (int i = 0; i < kPoolSize; i++) { | 318 for (int i = 0; i < kPoolSize; i++) { |
| 317 frame = controller_->ReserveOutputBuffer(); | 319 frame = device_->ReserveOutputBuffer(); |
| 318 ASSERT_TRUE(frame); | 320 ASSERT_TRUE(frame); |
| 319 ASSERT_EQ(media::VideoFrame::I420, frame->format()); | 321 ASSERT_EQ(media::VideoFrame::I420, frame->format()); |
| 320 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 322 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
| 321 controller_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 323 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 322 | 324 |
| 323 } | 325 } |
| 324 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 326 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 325 ASSERT_FALSE(controller_->ReserveOutputBuffer()); | 327 ASSERT_FALSE(device_->ReserveOutputBuffer()); |
| 326 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); | 328 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); |
| 327 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); | 329 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); |
| 328 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize); | 330 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize); |
| 329 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); | 331 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); |
| 330 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
| 331 Mock::VerifyAndClearExpectations(client_a_.get()); | 333 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 332 Mock::VerifyAndClearExpectations(client_b_.get()); | 334 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 333 | 335 |
| 334 // Now test the interaction of client shutdown and frame delivery. | 336 // Now test the interaction of client shutdown and frame delivery. |
| 335 // Kill A1 via renderer disconnect (synchronous). | 337 // Kill A1 via renderer disconnect (synchronous). |
| 336 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 338 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
| 337 // Kill B1 via session close (posts a task to disconnect). | 339 // Kill B1 via session close (posts a task to disconnect). |
| 338 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 340 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
| 339 controller_->StopSession(300); | 341 controller_->StopSession(300); |
| 340 // Queue up another frame. | 342 // Queue up another frame. |
| 341 frame = controller_->ReserveOutputBuffer(); | 343 frame = device_->ReserveOutputBuffer(); |
| 342 ASSERT_TRUE(frame); | 344 ASSERT_TRUE(frame); |
| 343 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 345 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
| 344 controller_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 346 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 345 frame = controller_->ReserveOutputBuffer(); | 347 frame = device_->ReserveOutputBuffer(); |
| 346 { | 348 { |
| 347 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 349 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 348 // be sent either of these two frames).. | 350 // be sent either of these two frames).. |
| 349 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 351 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 350 controller_->StopSession(200); | 352 controller_->StopSession(200); |
| 351 } | 353 } |
| 352 ASSERT_TRUE(frame); | 354 ASSERT_TRUE(frame); |
| 353 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 355 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
| 354 controller_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 356 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 355 // B2 is the only client left, and is the only one that should | 357 // B2 is the only client left, and is the only one that should |
| 356 // get the frame. | 358 // get the frame. |
| 357 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 359 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
| 358 base::RunLoop().RunUntilIdle(); | 360 base::RunLoop().RunUntilIdle(); |
| 359 Mock::VerifyAndClearExpectations(client_a_.get()); | 361 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 360 Mock::VerifyAndClearExpectations(client_b_.get()); | 362 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 361 } | 363 } |
| 362 | 364 |
| 363 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 365 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 364 // behavior of various operations after the error state has been signalled. | 366 // behavior of various operations after the error state has been signalled. |
| 365 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 367 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
| 366 media::VideoCaptureParams session_100; | 368 media::VideoCaptureParams session_100; |
| 367 session_100.session_id = 100; | 369 session_100.session_id = 100; |
| 368 session_100.width = 320; | 370 session_100.width = 320; |
| 369 session_100.height = 240; | 371 session_100.height = 240; |
| 370 session_100.frame_rate = 30; | 372 session_100.frame_rate = 30; |
| 371 | 373 |
| 372 media::VideoCaptureParams session_200 = session_100; | 374 media::VideoCaptureParams session_200 = session_100; |
| 373 session_200.session_id = 200; | 375 session_200.session_id = 200; |
| 374 | 376 |
| 375 const VideoCaptureControllerID route_id(0x99); | 377 const VideoCaptureControllerID route_id(0x99); |
| 376 | 378 |
| 377 // Start with one client. | 379 // Start with one client. |
| 378 controller_->AddClient(route_id, client_a_.get(), | 380 controller_->AddClient(route_id, client_a_.get(), |
| 379 base::kNullProcessHandle, session_100); | 381 base::kNullProcessHandle, session_100); |
| 380 controller_->OnError(); | 382 device_->OnError(); |
| 381 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 383 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 382 base::RunLoop().RunUntilIdle(); | 384 base::RunLoop().RunUntilIdle(); |
| 383 Mock::VerifyAndClearExpectations(client_a_.get()); | 385 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 384 | 386 |
| 385 // Second client connects after the error state. It also should get told of | 387 // Second client connects after the error state. It also should get told of |
| 386 // the error. | 388 // the error. |
| 387 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 389 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 388 controller_->AddClient(route_id, client_b_.get(), | 390 controller_->AddClient(route_id, client_b_.get(), |
| 389 base::kNullProcessHandle, session_200); | 391 base::kNullProcessHandle, session_200); |
| 390 base::RunLoop().RunUntilIdle(); | 392 base::RunLoop().RunUntilIdle(); |
| 391 Mock::VerifyAndClearExpectations(client_b_.get()); | 393 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 392 | 394 |
| 393 // OnFrameInfo from the VCD should become a no-op after the error occurs. | 395 // OnFrameInfo from the VCD should become a no-op after the error occurs. |
| 394 media::VideoCaptureCapability device_format( | 396 media::VideoCaptureCapability device_format( |
| 395 10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false, | 397 10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false, |
| 396 media::ConstantResolutionVideoCaptureDevice); | 398 media::ConstantResolutionVideoCaptureDevice); |
| 397 | 399 |
| 398 controller_->OnFrameInfo(device_format); | 400 device_->OnFrameInfo(device_format); |
| 399 base::RunLoop().RunUntilIdle(); | 401 base::RunLoop().RunUntilIdle(); |
| 400 } | 402 } |
| 401 | 403 |
| 402 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 404 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 403 // behavior of various operations after the error state has been signalled. | 405 // behavior of various operations after the error state has been signalled. |
| 404 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 406 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
| 405 media::VideoCaptureParams session_100; | 407 media::VideoCaptureParams session_100; |
| 406 session_100.session_id = 100; | 408 session_100.session_id = 100; |
| 407 session_100.width = 320; | 409 session_100.width = 320; |
| 408 session_100.height = 240; | 410 session_100.height = 240; |
| 409 session_100.frame_rate = 30; | 411 session_100.frame_rate = 30; |
| 410 | 412 |
| 411 media::VideoCaptureParams session_200 = session_100; | 413 media::VideoCaptureParams session_200 = session_100; |
| 412 session_200.session_id = 200; | 414 session_200.session_id = 200; |
| 413 | 415 |
| 414 const VideoCaptureControllerID route_id(0x99); | 416 const VideoCaptureControllerID route_id(0x99); |
| 415 | 417 |
| 416 // Start with one client. | 418 // Start with one client. |
| 417 controller_->AddClient(route_id, client_a_.get(), | 419 controller_->AddClient(route_id, client_a_.get(), |
| 418 base::kNullProcessHandle, session_100); | 420 base::kNullProcessHandle, session_100); |
| 419 // OnFrameInfo from the VCD should become a no-op after the error occurs. | 421 // OnFrameInfo from the VCD should become a no-op after the error occurs. |
| 420 media::VideoCaptureCapability device_format( | 422 media::VideoCaptureCapability device_format( |
| 421 10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false, | 423 10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false, |
| 422 media::ConstantResolutionVideoCaptureDevice); | 424 media::ConstantResolutionVideoCaptureDevice); |
| 423 | 425 |
| 424 // Start the device and get as far as exchanging buffers with the subprocess. | 426 // Start the device and get as far as exchanging buffers with the subprocess. |
| 425 // Then, signal an error and deliver the frame. The error should be propagated | 427 // Then, signal an error and deliver the frame. The error should be propagated |
| 426 // to clients; the frame should not be. | 428 // to clients; the frame should not be. |
| 427 controller_->OnFrameInfo(device_format); | 429 device_->OnFrameInfo(device_format); |
| 428 EXPECT_CALL(*client_a_, DoFrameInfo(route_id)).Times(1); | 430 EXPECT_CALL(*client_a_, DoFrameInfo(route_id)).Times(1); |
| 429 EXPECT_CALL(*client_a_, DoBufferCreated(route_id)).Times(kPoolSize); | 431 EXPECT_CALL(*client_a_, DoBufferCreated(route_id)).Times(kPoolSize); |
| 430 base::RunLoop().RunUntilIdle(); | 432 base::RunLoop().RunUntilIdle(); |
| 431 Mock::VerifyAndClearExpectations(client_a_.get()); | 433 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 432 | 434 |
| 433 scoped_refptr<media::VideoFrame> frame = controller_->ReserveOutputBuffer(); | 435 scoped_refptr<media::VideoFrame> frame = device_->ReserveOutputBuffer(); |
| 434 ASSERT_TRUE(frame); | 436 ASSERT_TRUE(frame); |
| 435 | 437 |
| 436 controller_->OnError(); | 438 device_->OnError(); |
| 437 controller_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 439 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 438 frame = NULL; | 440 frame = NULL; |
| 439 | 441 |
| 440 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 442 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 441 base::RunLoop().RunUntilIdle(); | 443 base::RunLoop().RunUntilIdle(); |
| 442 Mock::VerifyAndClearExpectations(client_a_.get()); | 444 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 443 | 445 |
| 444 // Second client connects after the error state. It also should get told of | 446 // Second client connects after the error state. It also should get told of |
| 445 // the error. | 447 // the error. |
| 446 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 448 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 447 controller_->AddClient(route_id, client_b_.get(), | 449 controller_->AddClient(route_id, client_b_.get(), |
| 448 base::kNullProcessHandle, session_200); | 450 base::kNullProcessHandle, session_200); |
| 449 Mock::VerifyAndClearExpectations(client_b_.get()); | 451 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 450 } | 452 } |
| 451 | 453 |
| 452 } // namespace content | 454 } // namespace content |
| OLD | NEW |