| 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 #include "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
| 6 #include "content/common/media/video_capture_messages.h" | 6 #include "content/common/media/video_capture_messages.h" |
| 7 #include "content/renderer/media/video_capture_message_filter.h" | 7 #include "content/renderer/media/video_capture_message_filter.h" |
| 8 #include "ipc/ipc_test_sink.h" | 8 #include "ipc/ipc_test_sink.h" |
| 9 #include "media/video/capture/video_capture_types.h" | 9 #include "media/video/capture/video_capture_types.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using ::testing::_; | 13 using ::testing::_; |
| 14 using ::testing::AllOf; | |
| 15 using ::testing::AnyNumber; | 14 using ::testing::AnyNumber; |
| 16 using ::testing::Field; | |
| 17 using ::testing::Mock; | 15 using ::testing::Mock; |
| 18 using ::testing::Return; | 16 using ::testing::Return; |
| 17 using ::testing::SaveArg; |
| 19 using ::testing::StrictMock; | 18 using ::testing::StrictMock; |
| 20 | 19 |
| 21 namespace content { | 20 namespace content { |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { | 23 class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { |
| 25 public: | 24 public: |
| 26 MockVideoCaptureDelegate() : device_id_(0) {} | 25 MockVideoCaptureDelegate() : device_id_(0) {} |
| 27 | 26 |
| 28 // VideoCaptureMessageFilter::Delegate implementation. | 27 // VideoCaptureMessageFilter::Delegate implementation. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #endif | 74 #endif |
| 76 EXPECT_CALL(delegate, OnBufferCreated(handle, 100, 1)); | 75 EXPECT_CALL(delegate, OnBufferCreated(handle, 100, 1)); |
| 77 filter->OnMessageReceived(VideoCaptureMsg_NewBuffer( | 76 filter->OnMessageReceived(VideoCaptureMsg_NewBuffer( |
| 78 delegate.device_id(), handle, 100, 1)); | 77 delegate.device_id(), handle, 100, 1)); |
| 79 Mock::VerifyAndClearExpectations(&delegate); | 78 Mock::VerifyAndClearExpectations(&delegate); |
| 80 | 79 |
| 81 // VideoCaptureMsg_BufferReady | 80 // VideoCaptureMsg_BufferReady |
| 82 int buffer_id = 22; | 81 int buffer_id = 22; |
| 83 base::Time timestamp = base::Time::FromInternalValue(1); | 82 base::Time timestamp = base::Time::FromInternalValue(1); |
| 84 | 83 |
| 85 media::VideoCaptureFormat format(234, 512, 30, | 84 media::VideoCaptureFormat format( |
| 86 media::ConstantResolutionVideoCaptureDevice); | 85 gfx::Size(234, 512), 30, media::PIXEL_FORMAT_I420); |
| 87 EXPECT_CALL(delegate, OnBufferReceived(buffer_id, timestamp, | 86 media::VideoCaptureFormat saved_format; |
| 88 AllOf(Field(&media::VideoCaptureFormat::width, 234), | 87 EXPECT_CALL(delegate, OnBufferReceived(buffer_id, timestamp, _)) |
| 89 Field(&media::VideoCaptureFormat::height, 512), | 88 .WillRepeatedly(SaveArg<2>(&saved_format)); |
| 90 Field(&media::VideoCaptureFormat::frame_rate, 30)))); | |
| 91 filter->OnMessageReceived(VideoCaptureMsg_BufferReady( | 89 filter->OnMessageReceived(VideoCaptureMsg_BufferReady( |
| 92 delegate.device_id(), buffer_id, timestamp, format)); | 90 delegate.device_id(), buffer_id, timestamp, format)); |
| 93 Mock::VerifyAndClearExpectations(&delegate); | 91 Mock::VerifyAndClearExpectations(&delegate); |
| 92 EXPECT_EQ(234, saved_format.frame_size.width()); |
| 93 EXPECT_EQ(512, saved_format.frame_size.height()); |
| 94 EXPECT_EQ(30, saved_format.frame_rate); |
| 94 | 95 |
| 95 // VideoCaptureMsg_FreeBuffer | 96 // VideoCaptureMsg_FreeBuffer |
| 96 EXPECT_CALL(delegate, OnBufferDestroyed(buffer_id)); | 97 EXPECT_CALL(delegate, OnBufferDestroyed(buffer_id)); |
| 97 filter->OnMessageReceived(VideoCaptureMsg_FreeBuffer( | 98 filter->OnMessageReceived(VideoCaptureMsg_FreeBuffer( |
| 98 delegate.device_id(), buffer_id)); | 99 delegate.device_id(), buffer_id)); |
| 99 Mock::VerifyAndClearExpectations(&delegate); | 100 Mock::VerifyAndClearExpectations(&delegate); |
| 100 } | 101 } |
| 101 | 102 |
| 102 TEST(VideoCaptureMessageFilterTest, Delegates) { | 103 TEST(VideoCaptureMessageFilterTest, Delegates) { |
| 103 scoped_refptr<VideoCaptureMessageFilter> filter( | 104 scoped_refptr<VideoCaptureMessageFilter> filter( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 133 VideoCaptureMsg_StateChanged(delegate1.device_id(), | 134 VideoCaptureMsg_StateChanged(delegate1.device_id(), |
| 134 VIDEO_CAPTURE_STATE_ENDED)); | 135 VIDEO_CAPTURE_STATE_ENDED)); |
| 135 | 136 |
| 136 filter->RemoveDelegate(&delegate2); | 137 filter->RemoveDelegate(&delegate2); |
| 137 filter->OnMessageReceived( | 138 filter->OnMessageReceived( |
| 138 VideoCaptureMsg_StateChanged(delegate2.device_id(), | 139 VideoCaptureMsg_StateChanged(delegate2.device_id(), |
| 139 VIDEO_CAPTURE_STATE_ENDED)); | 140 VIDEO_CAPTURE_STATE_ENDED)); |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace content | 143 } // namespace content |
| OLD | NEW |