Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / remoting / codec / video_encoder_helper_unittest.cc
blobe464802ce53d6e2544fc028c1f1f52f6a96088d1
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/codec/video_encoder_helper.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "remoting/proto/video.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
12 using webrtc::BasicDesktopFrame;
13 using webrtc::DesktopRect;
14 using webrtc::DesktopRegion;
15 using webrtc::DesktopSize;
16 using webrtc::DesktopVector;
18 namespace remoting {
20 TEST(VideoEncoderHelperTest, PropagatesCommonFields) {
21 BasicDesktopFrame frame(DesktopSize(32, 32));
22 frame.set_dpi(DesktopVector(96, 97));
23 frame.set_capture_time_ms(20);
24 frame.mutable_updated_region()->SetRect(DesktopRect::MakeLTRB(0, 0, 16, 16));
25 scoped_ptr<DesktopRegion> shape(
26 new DesktopRegion(DesktopRect::MakeLTRB(16, 0, 32, 16)));
27 frame.set_shape(shape.release());
29 VideoEncoderHelper helper;
30 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
32 ASSERT_TRUE(packet->has_format());
33 EXPECT_FALSE(packet->format().has_encoding());
34 EXPECT_TRUE(packet->format().has_screen_width());
35 EXPECT_TRUE(packet->format().has_screen_height());
36 EXPECT_TRUE(packet->format().has_x_dpi());
37 EXPECT_TRUE(packet->format().has_y_dpi());
39 EXPECT_TRUE(packet->has_capture_time_ms());
40 EXPECT_EQ(1, packet->dirty_rects().size());
42 ASSERT_TRUE(packet->has_use_desktop_shape());
43 EXPECT_TRUE(packet->use_desktop_shape());
45 EXPECT_EQ(1, packet->desktop_shape_rects().size());
48 TEST(VideoEncoderHelperTest, ZeroDpi) {
49 BasicDesktopFrame frame(DesktopSize(32, 32));
50 // DPI is zero unless explicitly set.
52 VideoEncoderHelper helper;
53 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
55 // Packet should have a format containing the screen dimensions only.
56 ASSERT_TRUE(packet->has_format());
57 EXPECT_TRUE(packet->format().has_screen_width());
58 EXPECT_TRUE(packet->format().has_screen_height());
59 EXPECT_FALSE(packet->format().has_x_dpi());
60 EXPECT_FALSE(packet->format().has_y_dpi());
63 TEST(VideoEncoderHelperTest, NoShape) {
64 BasicDesktopFrame frame(DesktopSize(32, 32));
66 VideoEncoderHelper helper;
67 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
69 EXPECT_FALSE(packet->use_desktop_shape());
70 EXPECT_EQ(0, packet->desktop_shape_rects().size());
73 TEST(VideoEncoderHelperTest, NoScreenSizeIfUnchanged) {
74 BasicDesktopFrame frame(DesktopSize(32, 32));
75 // Set DPI so that the packet will have a format, with DPI but no size.
76 frame.set_dpi(DesktopVector(96, 97));
78 VideoEncoderHelper helper;
79 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame));
80 packet = helper.CreateVideoPacket(frame);
82 ASSERT_TRUE(packet->has_format());
83 EXPECT_FALSE(packet->format().has_screen_width());
84 EXPECT_FALSE(packet->format().has_screen_height());
85 EXPECT_TRUE(packet->format().has_x_dpi());
86 EXPECT_TRUE(packet->format().has_y_dpi());
89 TEST(VideoEncoderHelperTest, ScreenSizeWhenChanged) {
90 VideoEncoderHelper helper;
92 // Process the same frame twice, so the helper knows the current size, and
93 // to trigger suppression of the size field due to the size not changing.
94 BasicDesktopFrame frame1(DesktopSize(32, 32));
95 scoped_ptr<VideoPacket> packet(helper.CreateVideoPacket(frame1));
96 packet = helper.CreateVideoPacket(frame1);
98 // Process a different-sized frame to trigger size to be emitted.
99 BasicDesktopFrame frame2(DesktopSize(48, 48));
100 packet = helper.CreateVideoPacket(frame2);
102 ASSERT_TRUE(packet->has_format());
103 EXPECT_TRUE(packet->format().has_screen_width());
104 EXPECT_TRUE(packet->format().has_screen_height());
107 } // namespace remoting