Index: remoting/protocol/connection_unittest.cc |
diff --git a/remoting/protocol/connection_unittest.cc b/remoting/protocol/connection_unittest.cc |
index 4f7b3627e5f660c6abc1385ea6559569cd3931ba..380bba3adc1630b841627737566fa7ed00235c3c 100644 |
--- a/remoting/protocol/connection_unittest.cc |
+++ b/remoting/protocol/connection_unittest.cc |
@@ -223,15 +223,38 @@ class ConnectionTest : public testing::Test, |
1U); |
EXPECT_EQ( |
client_video_renderer_.GetVideoStub()->received_packets().size(), 0U); |
+ client_video_renderer_.GetFrameConsumer()->set_on_frame_callback( |
+ base::Closure()); |
} else { |
EXPECT_EQ( |
client_video_renderer_.GetFrameConsumer()->received_frames().size(), |
0U); |
EXPECT_EQ( |
client_video_renderer_.GetVideoStub()->received_packets().size(), 1U); |
+ client_video_renderer_.GetVideoStub()->set_on_frame_callback( |
+ base::Closure()); |
} |
} |
+ void WaitFirstFrameStats() { |
+ if (!client_video_renderer_.GetFrameStatsConsumer() |
+ ->received_stats() |
+ .empty()) { |
+ return; |
+ } |
+ |
+ base::RunLoop run_loop; |
+ client_video_renderer_.GetFrameStatsConsumer()->set_on_stats_callback( |
+ base::Bind(&base::RunLoop::Quit, base::Unretained(&run_loop))); |
+ run_loop.Run(); |
+ client_video_renderer_.GetFrameStatsConsumer()->set_on_stats_callback( |
+ base::Closure()); |
+ |
+ EXPECT_FALSE(client_video_renderer_.GetFrameStatsConsumer() |
+ ->received_stats() |
+ .empty()); |
+ } |
+ |
base::MessageLoopForIO message_loop_; |
std::unique_ptr<base::RunLoop> run_loop_; |
@@ -369,5 +392,58 @@ TEST_P(ConnectionTest, DestroyOnIncomingMessage) { |
run_loop.Run(); |
} |
+TEST_P(ConnectionTest, VideoStats) { |
+ // Currently this test only works for WebRTC because for ICE connections stats |
+ // are reported by SoftwareVideoRenderer which is not used in this test. |
+ // TODO(sergeyu): Fix this. |
+ if (!is_using_webrtc()) |
+ return; |
+ |
+ Connect(); |
+ |
+ base::TimeTicks start_time = base::TimeTicks::Now(); |
+ |
+ std::unique_ptr<VideoStream> video_stream = |
+ host_connection_->StartVideoStream( |
+ base::WrapUnique(new TestScreenCapturer())); |
+ |
+ // Simulate an input invent injected at the start. |
+ video_stream->OnInputEventReceived(start_time.ToInternalValue()); |
+ |
+ WaitFirstVideoFrame(); |
+ |
+ base::TimeTicks finish_time = base::TimeTicks::Now(); |
+ |
+ WaitFirstFrameStats(); |
+ |
+ const FrameStats& stats = |
+ client_video_renderer_.GetFrameStatsConsumer()->received_stats().front(); |
+ |
+ EXPECT_TRUE(stats.host_stats.frame_size > 0); |
+ |
+ EXPECT_TRUE(stats.host_stats.latest_event_timestamp == start_time); |
+ EXPECT_TRUE(stats.host_stats.capture_delay != base::TimeDelta::Max()); |
+ EXPECT_TRUE(stats.host_stats.capture_overhead_delay != |
+ base::TimeDelta::Max()); |
+ EXPECT_TRUE(stats.host_stats.encode_delay != base::TimeDelta::Max()); |
+ EXPECT_TRUE(stats.host_stats.send_pending_delay != base::TimeDelta::Max()); |
+ |
+ EXPECT_FALSE(stats.client_stats.time_received.is_null()); |
+ EXPECT_FALSE(stats.client_stats.time_decoded.is_null()); |
+ EXPECT_FALSE(stats.client_stats.time_rendered.is_null()); |
+ |
+ EXPECT_TRUE(start_time + stats.host_stats.capture_pending_delay + |
+ stats.host_stats.capture_delay + |
+ stats.host_stats.capture_overhead_delay + |
+ stats.host_stats.encode_delay + |
+ stats.host_stats.send_pending_delay <= |
+ stats.client_stats.time_received); |
+ EXPECT_TRUE(stats.client_stats.time_received <= |
+ stats.client_stats.time_decoded); |
+ EXPECT_TRUE(stats.client_stats.time_decoded <= |
+ stats.client_stats.time_rendered); |
+ EXPECT_TRUE(stats.client_stats.time_rendered <= finish_time); |
+} |
+ |
} // namespace protocol |
} // namespace remoting |