| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "services/video_capture/test/fake_device_descriptor_test.h" | 6 #include "services/video_capture/test/fake_device_descriptor_test.h" |
| 7 #include "services/video_capture/test/mock_receiver.h" | 7 #include "services/video_capture/test/mock_receiver.h" |
| 8 | 8 |
| 9 using testing::_; | 9 using testing::_; |
| 10 using testing::InvokeWithoutArgs; | 10 using testing::InvokeWithoutArgs; |
| 11 | 11 |
| 12 namespace video_capture { | 12 namespace video_capture { |
| 13 | 13 |
| 14 class MockCreateDeviceProxyCallback { | 14 class MockCreateDeviceProxyCallback { |
| 15 public: | 15 public: |
| 16 MOCK_METHOD1(Run, void(mojom::DeviceAccessResultCode result_code)); | 16 MOCK_METHOD1(Run, void(mojom::DeviceAccessResultCode result_code)); |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 // This alias ensures test output is easily attributed to this service's tests. | 19 // This alias ensures test output is easily attributed to this service's tests. |
| 20 // TODO(rockot/chfremer): Consider just renaming the type. | 20 // TODO(rockot/chfremer): Consider just renaming the type. |
| 21 using FakeVideoCaptureDeviceDescriptorTest = FakeDeviceDescriptorTest; | 21 using FakeVideoCaptureDeviceDescriptorTest = FakeDeviceDescriptorTest; |
| 22 | 22 |
| 23 // Tests that when requesting a second proxy for a device without closing the | 23 // Tests that when requesting a second proxy for a device without closing the |
| 24 // first one, the service revokes access to the first one by closing the | 24 // first one, the service revokes access to the first one by closing the |
| 25 // connection. | 25 // connection. |
| 26 TEST_F(FakeVideoCaptureDeviceDescriptorTest, | 26 TEST_F(FakeVideoCaptureDeviceDescriptorTest, AccessIsRevokedOnSecondAccess) { |
| 27 DISABLED_AccessIsRevokedOnSecondAccess) { | |
| 28 mojom::DevicePtr device_proxy_1; | 27 mojom::DevicePtr device_proxy_1; |
| 29 bool device_access_1_revoked = false; | 28 bool device_access_1_revoked = false; |
| 30 MockCreateDeviceProxyCallback create_device_proxy_callback_1; | 29 MockCreateDeviceProxyCallback create_device_proxy_callback_1; |
| 31 EXPECT_CALL(create_device_proxy_callback_1, | 30 EXPECT_CALL(create_device_proxy_callback_1, |
| 32 Run(mojom::DeviceAccessResultCode::SUCCESS)) | 31 Run(mojom::DeviceAccessResultCode::SUCCESS)) |
| 33 .Times(1); | 32 .Times(1); |
| 34 factory_->CreateDevice( | 33 factory_->CreateDevice( |
| 35 fake_device_info_.descriptor.device_id, | 34 fake_device_info_.descriptor.device_id, |
| 36 mojo::MakeRequest(&device_proxy_1), | 35 mojo::MakeRequest(&device_proxy_1), |
| 37 base::Bind(&MockCreateDeviceProxyCallback::Run, | 36 base::Bind(&MockCreateDeviceProxyCallback::Run, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 55 base::Unretained(&create_device_proxy_callback_2))); | 54 base::Unretained(&create_device_proxy_callback_2))); |
| 56 device_proxy_2.set_connection_error_handler( | 55 device_proxy_2.set_connection_error_handler( |
| 57 base::Bind([](bool* access_revoked) { *access_revoked = true; }, | 56 base::Bind([](bool* access_revoked) { *access_revoked = true; }, |
| 58 &device_access_2_revoked)); | 57 &device_access_2_revoked)); |
| 59 wait_loop.Run(); | 58 wait_loop.Run(); |
| 60 ASSERT_TRUE(device_access_1_revoked); | 59 ASSERT_TRUE(device_access_1_revoked); |
| 61 ASSERT_FALSE(device_access_2_revoked); | 60 ASSERT_FALSE(device_access_2_revoked); |
| 62 } | 61 } |
| 63 | 62 |
| 64 // Tests that a second proxy requested for a device can be used successfully. | 63 // Tests that a second proxy requested for a device can be used successfully. |
| 65 TEST_F(FakeVideoCaptureDeviceDescriptorTest, | 64 TEST_F(FakeVideoCaptureDeviceDescriptorTest, CanUseSecondRequestedProxy) { |
| 66 DISABLED_CanUseSecondRequestedProxy) { | |
| 67 mojom::DevicePtr device_proxy_1; | 65 mojom::DevicePtr device_proxy_1; |
| 68 factory_->CreateDevice( | 66 factory_->CreateDevice( |
| 69 fake_device_info_.descriptor.device_id, | 67 fake_device_info_.descriptor.device_id, |
| 70 mojo::MakeRequest(&device_proxy_1), | 68 mojo::MakeRequest(&device_proxy_1), |
| 71 base::Bind([](mojom::DeviceAccessResultCode result_code) {})); | 69 base::Bind([](mojom::DeviceAccessResultCode result_code) {})); |
| 72 | 70 |
| 73 base::RunLoop wait_loop; | 71 base::RunLoop wait_loop; |
| 74 mojom::DevicePtr device_proxy_2; | 72 mojom::DevicePtr device_proxy_2; |
| 75 factory_->CreateDevice( | 73 factory_->CreateDevice( |
| 76 fake_device_info_.descriptor.device_id, | 74 fake_device_info_.descriptor.device_id, |
| 77 mojo::MakeRequest(&device_proxy_2), | 75 mojo::MakeRequest(&device_proxy_2), |
| 78 base::Bind( | 76 base::Bind( |
| 79 [](base::RunLoop* wait_loop, | 77 [](base::RunLoop* wait_loop, |
| 80 mojom::DeviceAccessResultCode result_code) { wait_loop->Quit(); }, | 78 mojom::DeviceAccessResultCode result_code) { wait_loop->Quit(); }, |
| 81 &wait_loop)); | 79 &wait_loop)); |
| 82 wait_loop.Run(); | 80 wait_loop.Run(); |
| 83 | 81 |
| 84 media::VideoCaptureParams arbitrary_requested_settings; | 82 media::VideoCaptureParams arbitrary_requested_settings; |
| 85 arbitrary_requested_settings.requested_format.frame_size.SetSize(640, 480); | 83 arbitrary_requested_settings.requested_format.frame_size.SetSize(640, 480); |
| 86 arbitrary_requested_settings.requested_format.frame_rate = 15; | 84 arbitrary_requested_settings.requested_format.frame_rate = 15; |
| 87 arbitrary_requested_settings.resolution_change_policy = | 85 arbitrary_requested_settings.resolution_change_policy = |
| 88 media::RESOLUTION_POLICY_FIXED_RESOLUTION; | 86 media::RESOLUTION_POLICY_FIXED_RESOLUTION; |
| 89 arbitrary_requested_settings.power_line_frequency = | 87 arbitrary_requested_settings.power_line_frequency = |
| 90 media::PowerLineFrequency::FREQUENCY_DEFAULT; | 88 media::PowerLineFrequency::FREQUENCY_DEFAULT; |
| 91 | 89 |
| 92 base::RunLoop wait_loop_2; | 90 base::RunLoop wait_loop_2; |
| 93 mojom::ReceiverPtr receiver_proxy; | 91 mojom::ReceiverPtr receiver_proxy; |
| 94 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); | 92 MockReceiver receiver(mojo::MakeRequest(&receiver_proxy)); |
| 95 EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_)) | 93 EXPECT_CALL(receiver, DoOnNewBufferHandle(_, _)); |
| 94 EXPECT_CALL(receiver, DoOnFrameReadyInBuffer(_, _, _, _)) |
| 96 .WillRepeatedly( | 95 .WillRepeatedly( |
| 97 InvokeWithoutArgs([&wait_loop_2]() { wait_loop_2.Quit(); })); | 96 InvokeWithoutArgs([&wait_loop_2]() { wait_loop_2.Quit(); })); |
| 98 | 97 |
| 99 device_proxy_2->Start(arbitrary_requested_settings, | 98 device_proxy_2->Start(arbitrary_requested_settings, |
| 100 std::move(receiver_proxy)); | 99 std::move(receiver_proxy)); |
| 101 wait_loop_2.Run(); | 100 wait_loop_2.Run(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 } // namespace video_capture | 103 } // namespace video_capture |
| OLD | NEW |