| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "base/message_loop.h" | |
| 6 #include "content/renderer/media/video_capture_impl.h" | |
| 7 #include "testing/gmock/include/gmock/gmock.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 using ::testing::_; | |
| 11 using ::testing::Return; | |
| 12 | |
| 13 #define DEFAULT_CAPABILITY {176, 144, 30, 0, media::VideoFrame::I420, \ | |
| 14 false, false } | |
| 15 | |
| 16 ACTION_P(DeleteMessage, return_value) { | |
| 17 delete arg0; | |
| 18 return return_value; | |
| 19 } | |
| 20 | |
| 21 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { | |
| 22 public: | |
| 23 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter(1) {} | |
| 24 virtual ~MockVideoCaptureMessageFilter() {} | |
| 25 | |
| 26 // Filter implementation. | |
| 27 MOCK_METHOD1(Send, bool(IPC::Message* message)); | |
| 28 MOCK_METHOD0(ReadyToSend, bool()); | |
| 29 | |
| 30 private: | |
| 31 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); | |
| 32 }; | |
| 33 | |
| 34 class MockVideoCaptureClient : public media::VideoCapture::EventHandler { | |
| 35 public: | |
| 36 MockVideoCaptureClient() {} | |
| 37 virtual ~MockVideoCaptureClient() {} | |
| 38 | |
| 39 // Filter implementation. | |
| 40 MOCK_METHOD1(OnStarted, void(media::VideoCapture* capture)); | |
| 41 MOCK_METHOD1(OnStopped, void(media::VideoCapture* capture)); | |
| 42 MOCK_METHOD1(OnPaused, void(media::VideoCapture* capture)); | |
| 43 MOCK_METHOD2(OnError, void(media::VideoCapture* capture, int error_code)); | |
| 44 MOCK_METHOD2(OnBufferReady, | |
| 45 void(media::VideoCapture* capture, | |
| 46 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf)); | |
| 47 MOCK_METHOD2(OnDeviceInfoReceived, | |
| 48 void(media::VideoCapture* capture, | |
| 49 const media::VideoCaptureParams& device_info)); | |
| 50 | |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureClient); | |
| 53 }; | |
| 54 | |
| 55 class VideoCaptureImplTest : public ::testing::Test { | |
| 56 public: | |
| 57 VideoCaptureImplTest() { | |
| 58 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | |
| 59 message_loop_proxy_ = | |
| 60 base::MessageLoopProxy::CreateForCurrentThread().get(); | |
| 61 | |
| 62 message_filter_ = new MockVideoCaptureMessageFilter; | |
| 63 session_id_ = 1; | |
| 64 | |
| 65 video_capture_impl_ = new VideoCaptureImpl(session_id_, message_loop_proxy_, | |
| 66 message_filter_); | |
| 67 | |
| 68 video_capture_impl_->device_id_ = 2; | |
| 69 } | |
| 70 | |
| 71 virtual ~VideoCaptureImplTest() { | |
| 72 delete video_capture_impl_; | |
| 73 } | |
| 74 | |
| 75 protected: | |
| 76 scoped_ptr<MessageLoop> message_loop_; | |
| 77 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 78 scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; | |
| 79 media::VideoCaptureSessionId session_id_; | |
| 80 VideoCaptureImpl* video_capture_impl_; | |
| 81 | |
| 82 private: | |
| 83 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); | |
| 84 }; | |
| 85 | |
| 86 TEST_F(VideoCaptureImplTest, Simple) { | |
| 87 // Execute SetCapture() and StopCapture(). | |
| 88 | |
| 89 scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); | |
| 90 media::VideoCapture::VideoCaptureCapability capability = DEFAULT_CAPABILITY; | |
| 91 | |
| 92 EXPECT_CALL(*message_filter_, Send(_)) | |
| 93 .WillRepeatedly(DeleteMessage(true)); | |
| 94 | |
| 95 EXPECT_CALL(*message_filter_, ReadyToSend()) | |
| 96 .WillRepeatedly(Return(true)); | |
| 97 | |
| 98 EXPECT_CALL(*client, OnStarted(_)) | |
| 99 .WillOnce(Return()); | |
| 100 | |
| 101 video_capture_impl_->StartCapture(client.get(), capability); | |
| 102 | |
| 103 EXPECT_CALL(*client, OnStopped(_)) | |
| 104 .WillOnce(Return()); | |
| 105 | |
| 106 video_capture_impl_->StopCapture(client.get()); | |
| 107 } | |
| OLD | NEW |