| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 private: | 108 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 109 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // 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 |
| 113 // track of clients. | 113 // track of clients. |
| 114 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 114 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
| 115 media::VideoCaptureParams session_100; | 115 media::VideoCaptureParams session_100; |
| 116 session_100.session_id = 100; | 116 session_100.session_id = 100; |
| 117 session_100.requested_format = media::VideoCaptureFormat( | 117 session_100.requested_format = media::VideoCaptureFormat( |
| 118 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); | 118 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 119 | |
| 120 media::VideoCaptureParams session_200 = session_100; | 119 media::VideoCaptureParams session_200 = session_100; |
| 121 session_200.session_id = 200; | 120 session_200.session_id = 200; |
| 122 | 121 |
| 123 media::VideoCaptureParams session_300 = session_100; | 122 media::VideoCaptureParams session_300 = session_100; |
| 124 session_300.session_id = 300; | 123 session_300.session_id = 300; |
| 125 | 124 |
| 126 media::VideoCaptureParams session_400 = session_100; | 125 media::VideoCaptureParams session_400 = session_100; |
| 127 session_400.session_id = 400; | 126 session_400.session_id = 400; |
| 128 | 127 |
| 129 // Intentionally use the same route ID for two of the clients: the device_ids | 128 // Intentionally use the same route ID for two of the clients: the device_ids |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 << "Client count should return to zero after all clients are gone."; | 201 << "Client count should return to zero after all clients are gone."; |
| 203 } | 202 } |
| 204 | 203 |
| 205 // This test will connect and disconnect several clients while simulating an | 204 // This test will connect and disconnect several clients while simulating an |
| 206 // active capture device being started and generating frames. It runs on one | 205 // active capture device being started and generating frames. It runs on one |
| 207 // thread and is intended to behave deterministically. | 206 // thread and is intended to behave deterministically. |
| 208 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 207 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
| 209 media::VideoCaptureParams session_100; | 208 media::VideoCaptureParams session_100; |
| 210 session_100.session_id = 100; | 209 session_100.session_id = 100; |
| 211 session_100.requested_format = media::VideoCaptureFormat( | 210 session_100.requested_format = media::VideoCaptureFormat( |
| 212 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); | 211 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 213 | 212 |
| 214 media::VideoCaptureParams session_200 = session_100; | 213 media::VideoCaptureParams session_200 = session_100; |
| 215 session_200.session_id = 200; | 214 session_200.session_id = 200; |
| 216 | 215 |
| 217 media::VideoCaptureParams session_300 = session_100; | 216 media::VideoCaptureParams session_300 = session_100; |
| 218 session_300.session_id = 300; | 217 session_300.session_id = 300; |
| 219 | 218 |
| 220 media::VideoCaptureParams session_1 = session_100; | 219 media::VideoCaptureParams session_1 = session_100; |
| 221 session_1.session_id = 1; | 220 session_1.session_id = 1; |
| 222 | 221 |
| 223 gfx::Size capture_resolution(444, 200); | 222 gfx::Size capture_resolution(444, 200); |
| 224 | 223 |
| 225 // The device format needn't match the VideoCaptureParams (the camera can do | 224 // The device format needn't match the VideoCaptureParams (the camera can do |
| 226 // what it wants). Pick something random. | 225 // what it wants). Pick something random. |
| 227 media::VideoCaptureCapability device_format( | 226 media::VideoCaptureFormat device_format( |
| 228 10, 10, 25, media::PIXEL_FORMAT_RGB24, | 227 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_RGB24); |
| 229 media::ConstantResolutionVideoCaptureDevice); | |
| 230 | 228 |
| 231 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); | 229 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); |
| 232 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); | 230 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); |
| 233 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); | 231 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); |
| 234 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); | 232 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); |
| 235 | 233 |
| 236 // Start with two clients. | 234 // Start with two clients. |
| 237 controller_->AddClient(client_a_route_1, client_a_.get(), | 235 controller_->AddClient(client_a_route_1, client_a_.get(), |
| 238 base::kNullProcessHandle, session_100); | 236 base::kNullProcessHandle, session_100); |
| 239 controller_->AddClient(client_b_route_1, client_b_.get(), | 237 controller_->AddClient(client_b_route_1, client_b_.get(), |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 Mock::VerifyAndClearExpectations(client_a_.get()); | 374 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 377 Mock::VerifyAndClearExpectations(client_b_.get()); | 375 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 378 } | 376 } |
| 379 | 377 |
| 380 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 378 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 381 // behavior of various operations after the error state has been signalled. | 379 // behavior of various operations after the error state has been signalled. |
| 382 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 380 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
| 383 media::VideoCaptureParams session_100; | 381 media::VideoCaptureParams session_100; |
| 384 session_100.session_id = 100; | 382 session_100.session_id = 100; |
| 385 session_100.requested_format = media::VideoCaptureFormat( | 383 session_100.requested_format = media::VideoCaptureFormat( |
| 386 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); | 384 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 387 | 385 |
| 388 media::VideoCaptureParams session_200 = session_100; | 386 media::VideoCaptureParams session_200 = session_100; |
| 389 session_200.session_id = 200; | 387 session_200.session_id = 200; |
| 390 | 388 |
| 391 const gfx::Size capture_resolution(320, 240); | 389 const gfx::Size capture_resolution(320, 240); |
| 392 | 390 |
| 393 const VideoCaptureControllerID route_id(0x99); | 391 const VideoCaptureControllerID route_id(0x99); |
| 394 | 392 |
| 395 // Start with one client. | 393 // Start with one client. |
| 396 controller_->AddClient(route_id, client_a_.get(), | 394 controller_->AddClient(route_id, client_a_.get(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 418 | 416 |
| 419 base::RunLoop().RunUntilIdle(); | 417 base::RunLoop().RunUntilIdle(); |
| 420 } | 418 } |
| 421 | 419 |
| 422 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 420 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 423 // behavior of various operations after the error state has been signalled. | 421 // behavior of various operations after the error state has been signalled. |
| 424 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 422 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
| 425 media::VideoCaptureParams session_100; | 423 media::VideoCaptureParams session_100; |
| 426 session_100.session_id = 100; | 424 session_100.session_id = 100; |
| 427 session_100.requested_format = media::VideoCaptureFormat( | 425 session_100.requested_format = media::VideoCaptureFormat( |
| 428 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); | 426 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 429 | 427 |
| 430 media::VideoCaptureParams session_200 = session_100; | 428 media::VideoCaptureParams session_200 = session_100; |
| 431 session_200.session_id = 200; | 429 session_200.session_id = 200; |
| 432 | 430 |
| 433 const VideoCaptureControllerID route_id(0x99); | 431 const VideoCaptureControllerID route_id(0x99); |
| 434 | 432 |
| 435 // Start with one client. | 433 // Start with one client. |
| 436 controller_->AddClient(route_id, client_a_.get(), | 434 controller_->AddClient(route_id, client_a_.get(), |
| 437 base::kNullProcessHandle, session_100); | 435 base::kNullProcessHandle, session_100); |
| 438 // OnFrameInfo from the VCD should become a no-op after the error occurs. | 436 media::VideoCaptureFormat device_format( |
| 439 media::VideoCaptureCapability device_format( | 437 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); |
| 440 10, 10, 25, media::PIXEL_FORMAT_ARGB, | |
| 441 media::ConstantResolutionVideoCaptureDevice); | |
| 442 | 438 |
| 443 // Start the device. Then, before the first buffer, signal an error and | 439 // Start the device. Then, before the first buffer, signal an error and |
| 444 // deliver the buffer. The error should be propagated to clients; the buffer | 440 // deliver the buffer. The error should be propagated to clients; the buffer |
| 445 // should not be. | 441 // should not be. |
| 446 base::RunLoop().RunUntilIdle(); | 442 base::RunLoop().RunUntilIdle(); |
| 447 Mock::VerifyAndClearExpectations(client_a_.get()); | 443 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 448 | 444 |
| 449 const gfx::Size dims(320, 240); | 445 const gfx::Size dims(320, 240); |
| 450 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 446 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 451 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); | 447 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 465 | 461 |
| 466 // Second client connects after the error state. It also should get told of | 462 // Second client connects after the error state. It also should get told of |
| 467 // the error. | 463 // the error. |
| 468 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 464 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 469 controller_->AddClient(route_id, client_b_.get(), | 465 controller_->AddClient(route_id, client_b_.get(), |
| 470 base::kNullProcessHandle, session_200); | 466 base::kNullProcessHandle, session_200); |
| 471 Mock::VerifyAndClearExpectations(client_b_.get()); | 467 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 472 } | 468 } |
| 473 | 469 |
| 474 } // namespace content | 470 } // namespace content |
| OLD | NEW |