Add CroppedDesktopFrameTest

CroppedDesktopFrame was broken by recent changes unexpectedly, it should be
covered by test cases to avoid this kind of accident.

Bug: chromium:761703
Change-Id: Ib95e4fe19a8bb9799db24fefd3ad154ddd15e53e
Reviewed-on: https://chromium-review.googlesource.com/651448
Commit-Queue: Zijie He <zijiehe@chromium.org>
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#19725}
This commit is contained in:
Zijie He 2017-09-06 14:09:20 -07:00 committed by Commit Bot
parent ae8aef7664
commit 05ec178808
2 changed files with 67 additions and 0 deletions

View File

@ -74,6 +74,7 @@ if (rtc_include_tests) {
}
sources = [
"blank_detector_desktop_capturer_wrapper_unittest.cc",
"cropped_desktop_frame_unittest.cc",
"desktop_and_cursor_composer_unittest.cc",
"desktop_capturer_differ_wrapper_unittest.cc",
"desktop_frame_rotation_unittest.cc",

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#include <utility>
#include "webrtc/modules/desktop_capture/cropped_desktop_frame.h"
#include "webrtc/modules/desktop_capture/desktop_frame.h"
#include "webrtc/rtc_base/ptr_util.h"
#include "webrtc/test/gtest.h"
namespace webrtc {
std::unique_ptr<DesktopFrame> CreateTestFrame() {
return rtc::MakeUnique<BasicDesktopFrame>(DesktopSize(10, 20));
}
TEST(CroppedDesktopFrameTest, DoNotCreateWrapperIfSizeIsNotChanged) {
std::unique_ptr<DesktopFrame> original = CreateTestFrame();
// owned by |original| and CroppedDesktopFrame.
DesktopFrame* raw_original = original.get();
std::unique_ptr<DesktopFrame> cropped = CreateCroppedDesktopFrame(
std::move(original), DesktopRect::MakeWH(10, 20));
ASSERT_EQ(cropped.get(), raw_original);
}
TEST(CroppedDesktopFrameTest, ReturnNullptrIfSizeIsNotSufficient) {
ASSERT_EQ(nullptr, CreateCroppedDesktopFrame(
CreateTestFrame(), DesktopRect::MakeWH(11, 10)));
}
TEST(CroppedDesktopFrameTest, ReturnNullIfCropRegionIsOutOfBounds) {
std::unique_ptr<DesktopFrame> frame = CreateTestFrame();
frame->set_top_left(DesktopVector(100, 200));
ASSERT_EQ(nullptr, CreateCroppedDesktopFrame(std::move(frame),
DesktopRect::MakeLTRB(101, 203, 109, 218)));
}
TEST(CroppedDesktopFrameTest, CropASubArea) {
std::unique_ptr<DesktopFrame> cropped = CreateCroppedDesktopFrame(
CreateTestFrame(), DesktopRect::MakeLTRB(1, 2, 9, 19));
ASSERT_EQ(cropped->size().width(), 8);
ASSERT_EQ(cropped->size().height(), 17);
ASSERT_EQ(cropped->top_left().x(), 1);
ASSERT_EQ(cropped->top_left().y(), 2);
}
TEST(CroppedDesktopFrameTest, SetTopLeft) {
std::unique_ptr<DesktopFrame> frame = CreateTestFrame();
frame->set_top_left(DesktopVector(100, 200));
frame = CreateCroppedDesktopFrame(std::move(frame),
DesktopRect::MakeLTRB(1, 3, 9, 18));
ASSERT_EQ(frame->size().width(), 8);
ASSERT_EQ(frame->size().height(), 15);
ASSERT_EQ(frame->top_left().x(), 101);
ASSERT_EQ(frame->top_left().y(), 203);
}
} // namespace webrtc