Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/run_loop.h" | |
| 7 #include "components/video_capture/mock_stream_client.h" | |
| 8 #include "components/video_capture/mojo_video_frame.h" | |
| 9 #include "components/video_capture/stream_impl.h" | |
| 10 #include "mojo/public/c/system/buffer.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 using ::testing::_; | |
| 15 using ::testing::AllOf; | |
| 16 using ::testing::InSequence; | |
| 17 using ::testing::Field; | |
| 18 using ::testing::Property; | |
| 19 | |
| 20 namespace video_capture { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 ACTION_P(RunClosure, closure) { | |
| 25 closure.Run(); | |
| 26 } | |
| 27 | |
| 28 } // anonymous namespace | |
| 29 | |
| 30 class StreamImplTest : public testing::Test { | |
| 31 public: | |
| 32 StreamImplTest() | |
| 33 : stream_impl_(new StreamImpl( | |
| 34 mojo::GetProxy(&stream_ptr_), | |
| 35 base::Bind(&StreamImplTest::StartCallback, base::Unretained(this)), | |
| 36 base::Bind(&StreamImplTest::StopCallback, base::Unretained(this)), | |
| 37 base::Bind(&StreamImplTest::ErrorCallback, | |
| 38 base::Unretained(this)))) {} | |
| 39 | |
| 40 void SetUp() override {} | |
| 41 void TearDown() override {} | |
| 42 | |
| 43 MOCK_METHOD0(StartCallback, void()); | |
| 44 MOCK_METHOD0(StopCallback, void()); | |
| 45 MOCK_METHOD0(ErrorCallback, void()); | |
| 46 MOCK_METHOD0(OnRelease, void()); | |
| 47 | |
| 48 void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, | |
| 49 const base::TimeTicks& timestamp) { | |
| 50 stream_impl_->OnFrame(frame, timestamp); | |
| 51 } | |
| 52 void OnError(const std::string& reason) { stream_impl_->OnError(reason); } | |
| 53 | |
| 54 void StartAndExpectStartCallback() { | |
| 55 EXPECT_CALL(*this, StartCallback()).Times(1); | |
| 56 mojom::StreamClientPtr le_client = stream_client_impl_.CreateProxy(); | |
| 57 stream_impl_->Start(std::move(le_client)); | |
| 58 } | |
| 59 | |
| 60 protected: | |
| 61 // This is needed for the Binding's Router's HandleWatcher :) | |
| 62 const base::MessageLoop loop_; | |
| 63 | |
| 64 mojom::StreamPtr stream_ptr_; | |
| 65 // The class under test. | |
| 66 const scoped_ptr<StreamImpl> stream_impl_; | |
| 67 | |
| 68 // The mock of the (remote) video capture client. | |
| 69 MockStreamClient stream_client_impl_; | |
| 70 | |
| 71 private: | |
| 72 DISALLOW_COPY_AND_ASSIGN(StreamImplTest); | |
| 73 }; | |
| 74 | |
| 75 TEST_F(StreamImplTest, CreateAndStartAndDestroy) { | |
| 76 StartAndExpectStartCallback(); | |
| 77 } | |
| 78 | |
| 79 // Tests the connection | |
| 80 // OnFrame() --> (NotifyFrameAvailable()) --> client's FrameAvailable(). | |
| 81 TEST_F(StreamImplTest, OnFramePingsFrameAvailable) { | |
| 82 InSequence s; | |
| 83 StartAndExpectStartCallback(); | |
| 84 | |
| 85 const gfx::Size kFrameSize(10, 10); | |
| 86 const scoped_refptr<MojoVideoFrame> le_frame = | |
| 87 MojoVideoFrame::CreateMojoVideoFrame(kFrameSize, base::TimeDelta()); | |
| 88 le_frame->AddDestructionObserver( | |
| 89 base::Bind(&StreamImplTest::OnRelease, base::Unretained(this))); | |
| 90 const base::TimeTicks now = base::TimeTicks::Now(); | |
| 91 | |
| 92 base::RunLoop run_loop; | |
| 93 base::Closure quit_closure = run_loop.QuitClosure(); | |
| 94 EXPECT_CALL( | |
| 95 stream_client_impl_, | |
| 96 DoFrameAvailable( | |
| 97 AllOf(Field(&mojom::FrameInfo::buffer_id, 0), | |
| 98 Field(&mojom::FrameInfo::storage_size, le_frame->mapped_size()), | |
| 99 Field(&mojom::FrameInfo::pixel_format, | |
| 100 static_cast<media::interfaces::VideoFormat>( | |
| 101 le_frame->format())), | |
| 102 Field(&mojom::FrameInfo::timestamp, now.ToInternalValue())), | |
| 103 _)) | |
| 104 .Times(1) | |
| 105 .WillOnce(RunClosure(quit_closure)); | |
| 106 EXPECT_CALL(*this, OnRelease()).Times(1); | |
| 107 | |
| 108 OnFrame(le_frame, now); | |
| 109 run_loop.Run(); | |
| 110 } | |
| 111 | |
| 112 // Tests the connection | |
| 113 // OnError() --> (NotifyError()) --> client's and owners' Error(). | |
| 114 TEST_F(StreamImplTest, OnErrorPingsError) { | |
| 115 InSequence s; | |
| 116 StartAndExpectStartCallback(); | |
| 117 | |
| 118 const std::string kErrorMessage("big error!"); | |
| 119 base::RunLoop run_loop; | |
| 120 base::Closure quit_closure = run_loop.QuitClosure(); | |
| 121 | |
| 122 EXPECT_CALL(*this, ErrorCallback()).Times(1); | |
| 123 EXPECT_CALL( | |
| 124 stream_client_impl_, | |
| 125 DoError(Property(&mojo::String::To<std::string>, kErrorMessage.c_str()))) | |
| 126 .Times(1) | |
| 127 .WillOnce(RunClosure(quit_closure)); | |
| 128 OnError(kErrorMessage); | |
| 129 run_loop.Run(); | |
| 130 } | |
| 131 | |
| 132 // Tests the connection Stop() --> Stop Callback. | |
| 133 TEST_F(StreamImplTest, StopPingsStopCallback) { | |
|
Ken Rockot(use gerrit already)
2016/02/05 04:51:26
In your message to me you said you set the client
| |
| 134 stream_impl_->Pause(); | |
| 135 stream_impl_->Resume(); | |
| 136 | |
| 137 EXPECT_CALL(*this, ErrorCallback()).Times(0); | |
| 138 EXPECT_CALL(*this, StopCallback()).Times(1); | |
| 139 stream_impl_->Stop(); | |
|
mcasas
2016/02/05 17:35:18
Yeah, so the problem is:
StartAndExpectStartCallb
| |
| 140 base::RunLoop().RunUntilIdle(); | |
| 141 } | |
| 142 | |
| 143 } // namespace video_capture | |
| OLD | NEW |