Process Alt-Svc headers.
[chromium-blink-merge.git] / content / renderer / media / webrtc / webrtc_video_capturer_adapter_unittest.cc
blob9603d7109e7d4f7962364e778f4fc2e98f34b3d6
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 <algorithm>
7 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
8 #include "media/base/video_frame.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace content {
13 class WebRtcVideoCapturerAdapterTest
14 : public sigslot::has_slots<>,
15 public ::testing::Test {
16 public:
17 WebRtcVideoCapturerAdapterTest()
18 : adapter_(false),
19 output_frame_width_(0),
20 output_frame_height_(0) {
21 adapter_.SignalFrameCaptured.connect(
22 this, &WebRtcVideoCapturerAdapterTest::OnFrameCaptured);
24 ~WebRtcVideoCapturerAdapterTest() override {}
26 void TestSourceCropFrame(int capture_width,
27 int capture_height,
28 int cropped_width,
29 int cropped_height,
30 int natural_width,
31 int natural_height) {
32 const int horiz_crop = ((capture_width - cropped_width) / 2);
33 const int vert_crop = ((capture_height - cropped_height) / 2);
35 gfx::Size coded_size(capture_width, capture_height);
36 gfx::Size natural_size(natural_width, natural_height);
37 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height);
38 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame(
39 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size,
40 base::TimeDelta());
41 adapter_.OnFrameCaptured(frame);
42 EXPECT_EQ(natural_width, output_frame_width_);
43 EXPECT_EQ(natural_height, output_frame_height_);
45 protected:
46 void OnFrameCaptured(cricket::VideoCapturer* capturer,
47 const cricket::CapturedFrame* frame) {
48 output_frame_width_ = frame->width;
49 output_frame_height_ = frame->height;
52 private:
53 WebRtcVideoCapturerAdapter adapter_;
54 int output_frame_width_;
55 int output_frame_height_;
58 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) {
59 TestSourceCropFrame(640, 480, 640, 360, 640, 360);
62 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) {
63 TestSourceCropFrame(640, 480, 480, 480, 320, 320);
66 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) {
67 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360);
70 } // namespace content