Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc

Issue 2202443002: [WebRTC] Add ScreenCapturerDifferWrapper to share Differ across ScreenCapturers (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h"
12
13 #include <initializer_list>
14 #include <memory>
15 #include <utility>
16
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
19 #include "webrtc/modules/desktop_capture/desktop_region.h"
20 #include "webrtc/modules/desktop_capture/differ_block.h"
21 #include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h"
22
23 namespace webrtc {
24
25 namespace {
26
27 // Compares and asserts |frame|.updated_region() equals to |rects|. This
28 // function does not care about the order of the |rects|.
29 void AssertUpdatedRegionAre(const DesktopFrame& frame,
Jamie 2016/08/03 23:52:26 s/Are/Is/
Hzj_jie 2016/08/04 02:28:07 Done.
30 std::initializer_list<DesktopRect> rects) {
31 for (const DesktopRect& rect : rects) {
32 // Note, Differ always use a 32 pixel block. So we normalize the |rects|.
33 DesktopRect block_size_rect = DesktopRect::MakeLTRB(
34 rect.left() / kBlockSize * kBlockSize,
35 rect.top() / kBlockSize * kBlockSize,
36 (rect.right() + kBlockSize - 1) / kBlockSize * kBlockSize,
37 (rect.bottom() + kBlockSize - 1) / kBlockSize * kBlockSize);
38 block_size_rect.IntersectWith(DesktopRect::MakeSize(frame.size()));
39 bool found = false;
40 for (DesktopRegion::Iterator it(frame.updated_region());
41 !it.IsAtEnd();
42 it.Advance()) {
43 if (it.rect().equals(block_size_rect)) {
44 found = true;
45 break;
46 }
47 }
48 ASSERT_TRUE(found);
49 }
50 }
51
52 void ExecuteDifferWrapperTest(bool with_hints, bool enlarge_dirty_region) {
53 std::unique_ptr<MockScreenCapturer> mock(new MockScreenCapturer());
54 MockScreenCapturer* mock_capturer = mock.get();
55 ScreenCapturerDifferWrapper capturer(std::move(mock));
56 MockScreenCapturerCallback callback;
57 *mock_capturer->provide_dirty_region_hints() = with_hints;
58 *mock_capturer->enlarge_dirty_region() = enlarge_dirty_region;
59
60 capturer.Start(&callback);
61
62 EXPECT_CALL(callback, OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS,
63 testing::_))
64 .Times(1)
65 .WillOnce(testing::Invoke([](DesktopCapturer::Result result,
66 std::unique_ptr<DesktopFrame>* frame) {
67 ASSERT_EQ(result, DesktopCapturer::Result::SUCCESS);
68 AssertUpdatedRegionAre(
69 **frame, { DesktopRect::MakeSize((*frame)->size()) });
70 }));
71 capturer.Capture(DesktopRegion());
72
73 std::initializer_list<DesktopRect> dirty_region {
74 DesktopRect::MakeLTRB(100, 100, 200, 200),
75 DesktopRect::MakeLTRB(300, 300, 400, 400)
76 };
77 EXPECT_CALL(callback, OnCaptureResultPtr(DesktopCapturer::Result::SUCCESS,
78 testing::_))
79 .Times(1)
80 .WillOnce(testing::Invoke(
81 [&dirty_region](DesktopCapturer::Result result,
82 std::unique_ptr<DesktopFrame>* frame) {
83 ASSERT_EQ(result, DesktopCapturer::Result::SUCCESS);
84 AssertUpdatedRegionAre(**frame, dirty_region);
85 }));
86 for (const auto& rect : dirty_region) {
87 mock_capturer->dirty_region()->AddRect(rect);
88 }
89 capturer.Capture(DesktopRegion());
90 }
91
92 } // namespace
93
94 TEST(ScreenCapturerDifferWrapperTest, FunctionForwarding) {
95 std::unique_ptr<MockScreenCapturer> mock(new MockScreenCapturer());
96 MockScreenCapturer* mock_capturer = mock.get();
97 ScreenCapturerDifferWrapper capturer(std::move(mock));
98 MockScreenCapturerCallback callback;
99
100 EXPECT_CALL(*mock_capturer, Start(testing::_)).Times(1);
101 capturer.Start(&callback);
102
103 EXPECT_CALL(*mock_capturer, Capture(testing::_)).Times(1);
104 capturer.Capture(DesktopRegion());
105
106 EXPECT_CALL(*mock_capturer, GetScreenList(testing::_)).Times(1);
107 ASSERT_TRUE(capturer.GetScreenList(nullptr));
108
109 EXPECT_CALL(*mock_capturer, SelectScreen(testing::_)).Times(2);
110 ASSERT_FALSE(capturer.SelectScreen(ScreenId{100}));
111 ASSERT_TRUE(capturer.SelectScreen(kFullDesktopScreenId));
112 }
113
114 TEST(ScreenCapturerDifferWrapperTest, CaptureWithoutHints) {
115 ExecuteDifferWrapperTest(false, false);
116 }
117
118 TEST(ScreenCapturerDifferWrapperTest, CaptureWithHints) {
119 ExecuteDifferWrapperTest(true, false);
120 }
121
122 TEST(ScreenCapturerDifferWrapperTest, CaptureWithEnlargedHints) {
123 ExecuteDifferWrapperTest(true, true);
124 }
125
126 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698