Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / protocol / monitored_video_stub_unittest.cc
blob6aad087ab4f69fa2250937fa7e6fb7e669efbe61
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/run_loop.h"
9 #include "base/test/test_timeouts.h"
10 #include "remoting/protocol/protocol_mock_objects.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using ::testing::_;
15 using ::testing::AnyNumber;
16 using ::testing::AtMost;
17 using ::testing::InvokeWithoutArgs;
19 namespace remoting {
20 namespace protocol {
22 static const int64 kTestOverrideDelayMilliseconds = 1;
24 class MonitoredVideoStubTest : public testing::Test {
25 protected:
26 void SetUp() override {
27 packet_.reset(new VideoPacket());
28 monitor_.reset(new MonitoredVideoStub(
29 &video_stub_,
30 base::TimeDelta::FromMilliseconds(kTestOverrideDelayMilliseconds),
31 base::Bind(
32 &MonitoredVideoStubTest::OnVideoChannelStatus,
33 base::Unretained(this))));
34 EXPECT_CALL(video_stub_, ProcessVideoPacketPtr(_, _)).Times(AnyNumber());
37 MOCK_METHOD1(OnVideoChannelStatus, void(bool connected));
39 base::MessageLoop message_loop_;
40 MockVideoStub video_stub_;
42 scoped_ptr<MonitoredVideoStub> monitor_;
43 scoped_ptr<VideoPacket> packet_;
44 base::OneShotTimer<MonitoredVideoStubTest> timer_end_test_;
47 TEST_F(MonitoredVideoStubTest, OnChannelConnected) {
48 EXPECT_CALL(*this, OnVideoChannelStatus(true));
49 // On slow machines, the connectivity check timer may fire before the test
50 // finishes, so we expect to see at most one transition to not ready.
51 EXPECT_CALL(*this, OnVideoChannelStatus(false)).Times(AtMost(1));
53 monitor_->ProcessVideoPacket(packet_.Pass(), base::Closure());
54 base::RunLoop().RunUntilIdle();
57 TEST_F(MonitoredVideoStubTest, OnChannelDisconnected) {
58 EXPECT_CALL(*this, OnVideoChannelStatus(true));
59 monitor_->ProcessVideoPacket(packet_.Pass(), base::Closure());
61 EXPECT_CALL(*this, OnVideoChannelStatus(false)).WillOnce(
62 InvokeWithoutArgs(
63 &message_loop_,
64 &base::MessageLoop::Quit));
65 message_loop_.Run();
68 TEST_F(MonitoredVideoStubTest, OnChannelStayConnected) {
69 // Verify no extra connected events are fired when packets are received
70 // frequently
71 EXPECT_CALL(*this, OnVideoChannelStatus(true));
72 // On slow machines, the connectivity check timer may fire before the test
73 // finishes, so we expect to see at most one transition to not ready.
74 EXPECT_CALL(*this, OnVideoChannelStatus(false)).Times(AtMost(1));
76 monitor_->ProcessVideoPacket(packet_.Pass(), base::Closure());
77 monitor_->ProcessVideoPacket(packet_.Pass(), base::Closure());
78 base::RunLoop().RunUntilIdle();
81 TEST_F(MonitoredVideoStubTest, OnChannelStayDisconnected) {
82 // Verify no extra disconnected events are fired.
83 EXPECT_CALL(*this, OnVideoChannelStatus(true)).Times(1);
84 EXPECT_CALL(*this, OnVideoChannelStatus(false)).Times(1);
86 monitor_->ProcessVideoPacket(packet_.Pass(), base::Closure());
88 message_loop_.PostDelayedTask(
89 FROM_HERE,
90 base::MessageLoop::QuitClosure(),
91 // The delay should be much greater than |kTestOverrideDelayMilliseconds|.
92 TestTimeouts::tiny_timeout());
93 message_loop_.Run();
96 } // namespace protocol
97 } // namespace remoting