1 // Copyright 2014 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.
5 #include "remoting/protocol/monitored_video_stub.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h"
11 #include "remoting/protocol/protocol_mock_objects.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
16 using ::testing::AnyNumber
;
17 using ::testing::AtMost
;
18 using ::testing::InvokeWithoutArgs
;
23 static const int64 kTestOverrideDelayMilliseconds
= 1;
25 class MonitoredVideoStubTest
: public testing::Test
{
27 virtual void SetUp() override
{
28 packet_
.reset(new VideoPacket());
29 monitor_
.reset(new MonitoredVideoStub(
31 base::TimeDelta::FromMilliseconds(kTestOverrideDelayMilliseconds
),
33 &MonitoredVideoStubTest::OnVideoChannelStatus
,
34 base::Unretained(this))));
35 EXPECT_CALL(video_stub_
, ProcessVideoPacketPtr(_
, _
)).Times(AnyNumber());
38 MOCK_METHOD1(OnVideoChannelStatus
, void(bool connected
));
40 base::MessageLoop message_loop_
;
41 MockVideoStub video_stub_
;
43 scoped_ptr
<MonitoredVideoStub
> monitor_
;
44 scoped_ptr
<VideoPacket
> packet_
;
45 base::OneShotTimer
<MonitoredVideoStubTest
> timer_end_test_
;
48 TEST_F(MonitoredVideoStubTest
, OnChannelConnected
) {
49 EXPECT_CALL(*this, OnVideoChannelStatus(true));
50 // On slow machines, the connectivity check timer may fire before the test
51 // finishes, so we expect to see at most one transition to not ready.
52 EXPECT_CALL(*this, OnVideoChannelStatus(false)).Times(AtMost(1));
54 monitor_
->ProcessVideoPacket(packet_
.Pass(), base::Closure());
55 base::RunLoop().RunUntilIdle();
58 TEST_F(MonitoredVideoStubTest
, OnChannelDisconnected
) {
59 EXPECT_CALL(*this, OnVideoChannelStatus(true));
60 monitor_
->ProcessVideoPacket(packet_
.Pass(), base::Closure());
62 EXPECT_CALL(*this, OnVideoChannelStatus(false)).WillOnce(
65 &base::MessageLoop::Quit
));
69 TEST_F(MonitoredVideoStubTest
, OnChannelStayConnected
) {
70 // Verify no extra connected events are fired when packets are received
72 EXPECT_CALL(*this, OnVideoChannelStatus(true));
73 // On slow machines, the connectivity check timer may fire before the test
74 // finishes, so we expect to see at most one transition to not ready.
75 EXPECT_CALL(*this, OnVideoChannelStatus(false)).Times(AtMost(1));
77 monitor_
->ProcessVideoPacket(packet_
.Pass(), base::Closure());
78 monitor_
->ProcessVideoPacket(packet_
.Pass(), base::Closure());
79 base::RunLoop().RunUntilIdle();
82 TEST_F(MonitoredVideoStubTest
, OnChannelStayDisconnected
) {
83 // Verify no extra disconnected events are fired.
84 EXPECT_CALL(*this, OnVideoChannelStatus(true)).Times(1);
85 EXPECT_CALL(*this, OnVideoChannelStatus(false)).Times(1);
87 monitor_
->ProcessVideoPacket(packet_
.Pass(), base::Closure());
89 message_loop_
.PostDelayedTask(
91 base::MessageLoop::QuitClosure(),
92 // The delay should be much greater than |kTestOverrideDelayMilliseconds|.
93 TestTimeouts::tiny_timeout());
97 } // namespace protocol
98 } // namespace remoting