Index: webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc |
diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..345e944764b31f9cebd82bb0ce675481bb4deee5 |
--- /dev/null |
+++ b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc |
@@ -0,0 +1,126 @@ |
+/* |
+ * Copyright (c) 2016 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 "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" |
+ |
+#include <initializer_list> |
+#include <memory> |
+#include <utility> |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "webrtc/modules/desktop_capture/desktop_geometry.h" |
+#include "webrtc/modules/desktop_capture/desktop_region.h" |
+#include "webrtc/modules/desktop_capture/differ_block.h" |
+#include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" |
+ |
+namespace webrtc { |
+ |
+namespace { |
+ |
+// Compares and asserts |frame|.updated_region() equals to |rects|. This |
+// function does not care about the order of the |rects|. |
+void AssertUpdatedRegionAre(const DesktopFrame& frame, |
Jamie
2016/08/03 23:52:26
s/Are/Is/
Hzj_jie
2016/08/04 02:28:07
Done.
|
+ std::initializer_list<DesktopRect> rects) { |
+ for (const DesktopRect& rect : rects) { |
+ // Note, Differ always use a 32 pixel block. So we normalize the |rects|. |
+ DesktopRect block_size_rect = DesktopRect::MakeLTRB( |
+ rect.left() / kBlockSize * kBlockSize, |
+ rect.top() / kBlockSize * kBlockSize, |
+ (rect.right() + kBlockSize - 1) / kBlockSize * kBlockSize, |
+ (rect.bottom() + kBlockSize - 1) / kBlockSize * kBlockSize); |
+ block_size_rect.IntersectWith(DesktopRect::MakeSize(frame.size())); |
+ bool found = false; |
+ for (DesktopRegion::Iterator it(frame.updated_region()); |
+ !it.IsAtEnd(); |
+ it.Advance()) { |
+ if (it.rect().equals(block_size_rect)) { |
+ found = true; |
+ break; |
+ } |
+ } |
+ ASSERT_TRUE(found); |
+ } |
+} |
+ |
+void ExecuteDifferWrapperTest(bool with_hints, bool enlarge_dirty_region) { |
+ std::unique_ptr<MockScreenCapturer> mock(new MockScreenCapturer()); |
+ MockScreenCapturer* mock_capturer = mock.get(); |
+ ScreenCapturerDifferWrapper capturer(std::move(mock)); |
+ MockScreenCapturerCallback callback; |
+ *mock_capturer->provide_dirty_region_hints() = with_hints; |
+ *mock_capturer->enlarge_dirty_region() = enlarge_dirty_region; |
+ |
+ capturer.Start(&callback); |
+ |
+ EXPECT_CALL(callback, OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, |
+ testing::_)) |
+ .Times(1) |
+ .WillOnce(testing::Invoke([](DesktopCapturer::Result result, |
+ std::unique_ptr<DesktopFrame>* frame) { |
+ ASSERT_EQ(result, DesktopCapturer::Result::SUCCESS); |
+ AssertUpdatedRegionAre( |
+ **frame, { DesktopRect::MakeSize((*frame)->size()) }); |
+ })); |
+ capturer.Capture(DesktopRegion()); |
+ |
+ std::initializer_list<DesktopRect> dirty_region { |
+ DesktopRect::MakeLTRB(100, 100, 200, 200), |
+ DesktopRect::MakeLTRB(300, 300, 400, 400) |
+ }; |
+ EXPECT_CALL(callback, OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS, |
+ testing::_)) |
+ .Times(1) |
+ .WillOnce(testing::Invoke( |
+ [&dirty_region](DesktopCapturer::Result result, |
+ std::unique_ptr<DesktopFrame>* frame) { |
+ ASSERT_EQ(result, DesktopCapturer::Result::SUCCESS); |
+ AssertUpdatedRegionAre(**frame, dirty_region); |
+ })); |
+ for (const auto& rect : dirty_region) { |
+ mock_capturer->dirty_region()->AddRect(rect); |
+ } |
+ capturer.Capture(DesktopRegion()); |
+} |
+ |
+} // namespace |
+ |
+TEST(ScreenCapturerDifferWrapperTest, FunctionForwarding) { |
+ std::unique_ptr<MockScreenCapturer> mock(new MockScreenCapturer()); |
+ MockScreenCapturer* mock_capturer = mock.get(); |
+ ScreenCapturerDifferWrapper capturer(std::move(mock)); |
+ MockScreenCapturerCallback callback; |
+ |
+ EXPECT_CALL(*mock_capturer, Start(testing::_)).Times(1); |
+ capturer.Start(&callback); |
+ |
+ EXPECT_CALL(*mock_capturer, Capture(testing::_)).Times(1); |
+ capturer.Capture(DesktopRegion()); |
+ |
+ EXPECT_CALL(*mock_capturer, GetScreenList(testing::_)).Times(1); |
+ ASSERT_TRUE(capturer.GetScreenList(nullptr)); |
+ |
+ EXPECT_CALL(*mock_capturer, SelectScreen(testing::_)).Times(2); |
+ ASSERT_FALSE(capturer.SelectScreen(ScreenId{100})); |
+ ASSERT_TRUE(capturer.SelectScreen(kFullDesktopScreenId)); |
+} |
+ |
+TEST(ScreenCapturerDifferWrapperTest, CaptureWithoutHints) { |
+ ExecuteDifferWrapperTest(false, false); |
+} |
+ |
+TEST(ScreenCapturerDifferWrapperTest, CaptureWithHints) { |
+ ExecuteDifferWrapperTest(true, false); |
+} |
+ |
+TEST(ScreenCapturerDifferWrapperTest, CaptureWithEnlargedHints) { |
+ ExecuteDifferWrapperTest(true, true); |
+} |
+ |
+} // namespace webrtc |