Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/capture/video/chromeos/camera_hal_delegate_unittest.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/run_loop.h" | |
| 15 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 using testing::_; | |
| 20 using testing::A; | |
| 21 using testing::Invoke; | |
| 22 | |
| 23 namespace media { | |
| 24 | |
| 25 class CameraHalDelegateTest : public ::testing::Test { | |
| 26 public: | |
| 27 CameraHalDelegateTest() | |
| 28 : message_loop_(new base::MessageLoop), | |
| 29 hal_delegate_thread_("HalDelegateThread") {} | |
| 30 | |
| 31 void SetUp() override { | |
| 32 hal_delegate_thread_.Start(); | |
| 33 camera_hal_delegate_ = | |
| 34 new CameraHalDelegate(hal_delegate_thread_.task_runner()); | |
| 35 camera_hal_delegate_->StartForTesting( | |
| 36 mock_camera_module_.GetInterfacePtrInfo()); | |
| 37 } | |
| 38 | |
| 39 void TearDown() override { | |
| 40 while (!camera_hal_delegate_->HasOneRef()) { | |
| 41 base::PlatformThread::YieldCurrentThread(); | |
| 42 } | |
|
chfremer
2017/05/26 17:40:57
Same as in the production code, this while loop lo
jcliang
2017/05/31 14:58:06
We can remove the while loop here by explicitly ca
chfremer
2017/06/01 00:16:27
It appears to me that a lot of the code in this CL
| |
| 43 camera_hal_delegate_ = nullptr; | |
| 44 hal_delegate_thread_.Stop(); | |
| 45 } | |
| 46 | |
| 47 void Wait() { | |
|
chfremer
2017/05/26 17:40:57
Couldn't find where this is used. Can it be remove
jcliang
2017/05/31 14:58:07
Done.
| |
| 48 run_loop_.reset(new base::RunLoop()); | |
| 49 run_loop_->Run(); | |
| 50 } | |
| 51 | |
| 52 protected: | |
| 53 scoped_refptr<CameraHalDelegate> camera_hal_delegate_; | |
| 54 testing::StrictMock<unittest_internal::MockCameraModule> mock_camera_module_; | |
| 55 | |
| 56 private: | |
| 57 std::unique_ptr<base::MessageLoop> message_loop_; | |
|
chfremer
2017/05/26 17:40:58
IIUC, it is now encouraged to use a ScopedTaskEnvi
jcliang
2017/05/31 14:58:07
Thanks for the pointer. I'm removing this for now.
| |
| 58 base::Thread hal_delegate_thread_; | |
| 59 std::unique_ptr<base::RunLoop> run_loop_; | |
| 60 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegateTest); | |
| 61 }; | |
| 62 | |
| 63 TEST_F(CameraHalDelegateTest, GetBuiltinCameraInfo) { | |
| 64 auto get_number_of_cameras_cb = | |
| 65 [](arc::mojom::CameraModule::GetNumberOfCamerasCallback& cb) { | |
| 66 std::move(cb).Run(2); | |
| 67 }; | |
|
chfremer
2017/05/26 17:40:58
I would be okay with this, but not sure if this ma
jcliang
2017/05/31 14:58:06
I see that binding captureless lambda is documente
| |
| 68 | |
| 69 auto get_camera_info_cb = | |
| 70 [](uint32_t camera_id, | |
| 71 arc::mojom::CameraModule::GetCameraInfoCallback& cb) { | |
| 72 arc::mojom::CameraInfoPtr camera_info = arc::mojom::CameraInfo::New(); | |
| 73 arc::mojom::CameraMetadataPtr static_metadata = | |
| 74 arc::mojom::CameraMetadata::New(); | |
| 75 switch (camera_id) { | |
| 76 case 0: | |
| 77 camera_info->facing = arc::mojom::CameraFacing::CAMERA_FACING_BACK; | |
| 78 camera_info->orientation = 0; | |
| 79 camera_info->static_camera_characteristics = | |
| 80 std::move(static_metadata); | |
| 81 break; | |
| 82 case 1: | |
| 83 camera_info->facing = arc::mojom::CameraFacing::CAMERA_FACING_FRONT; | |
| 84 camera_info->orientation = 0; | |
| 85 camera_info->static_camera_characteristics = | |
| 86 std::move(static_metadata); | |
| 87 break; | |
| 88 default: | |
| 89 FAIL() << "Invalid camera id"; | |
| 90 } | |
| 91 std::move(cb).Run(0, std::move(camera_info)); | |
| 92 }; | |
| 93 | |
| 94 EXPECT_CALL(mock_camera_module_, DoGetNumberOfCameras(_)) | |
| 95 .Times(1) | |
| 96 .WillOnce(Invoke(get_number_of_cameras_cb)); | |
| 97 EXPECT_CALL( | |
| 98 mock_camera_module_, | |
| 99 DoSetCallbacks(A<arc::mojom::CameraModuleCallbacksPtr&>(), | |
| 100 A<arc::mojom::CameraModule::SetCallbacksCallback&>())) | |
| 101 .Times(1); | |
| 102 EXPECT_CALL( | |
| 103 mock_camera_module_, | |
| 104 DoGetCameraInfo(0, A<arc::mojom::CameraModule::GetCameraInfoCallback&>())) | |
| 105 .Times(1) | |
| 106 .WillOnce(Invoke(get_camera_info_cb)); | |
| 107 EXPECT_CALL( | |
| 108 mock_camera_module_, | |
| 109 DoGetCameraInfo(1, A<arc::mojom::CameraModule::GetCameraInfoCallback&>())) | |
| 110 .Times(1) | |
| 111 .WillOnce(Invoke(get_camera_info_cb)); | |
| 112 | |
| 113 VideoCaptureDeviceDescriptors descriptors; | |
| 114 camera_hal_delegate_->GetDeviceDescriptors(&descriptors); | |
| 115 | |
| 116 ASSERT_EQ(2U, descriptors.size()); | |
| 117 ASSERT_EQ(std::to_string(0), descriptors[0].device_id); | |
|
chfremer
2017/05/26 17:40:58
Where does this expectation come from? I do not se
jcliang
2017/05/31 14:58:07
The device_id is filled in camera_hal_delegate_->G
chfremer
2017/05/31 18:30:41
I see. So this basically just verifies that Camera
| |
| 118 ASSERT_EQ(VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT, | |
| 119 descriptors[0].facing); | |
| 120 ASSERT_EQ(std::to_string(1), descriptors[1].device_id); | |
| 121 ASSERT_EQ(VideoFacingMode::MEDIA_VIDEO_FACING_USER, descriptors[1].facing); | |
| 122 | |
| 123 VideoCaptureFormats supported_formats; | |
| 124 camera_hal_delegate_->GetSupportedFormats(descriptors[0], &supported_formats); | |
| 125 | |
| 126 ASSERT_EQ(1U, supported_formats.size()); | |
| 127 ASSERT_EQ(gfx::Size(1280, 720), supported_formats[0].frame_size); | |
| 128 ASSERT_EQ(60.0, supported_formats[0].frame_rate); | |
| 129 ASSERT_EQ(PIXEL_FORMAT_NV12, supported_formats[0].pixel_format); | |
|
chfremer
2017/05/26 17:40:58
Where do these expected values come from?
jcliang
2017/05/31 14:58:06
This was from a workaround I had in CameraHalDeleg
| |
| 130 } | |
| 131 | |
| 132 } // namespace media | |
| OLD | NEW |