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

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

Issue 1988783003: Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 using ::testing::_; 26 using ::testing::_;
27 using ::testing::AnyNumber; 27 using ::testing::AnyNumber;
28 using ::testing::Return; 28 using ::testing::Return;
29 29
30 namespace webrtc { 30 namespace webrtc {
31 31
32 class ScreenCapturerMacTest : public testing::Test { 32 class ScreenCapturerMacTest : public testing::Test {
33 public: 33 public:
34 // Verifies that the whole screen is initially dirty. 34 // Verifies that the whole screen is initially dirty.
35 void CaptureDoneCallback1(DesktopFrame* frame); 35 void CaptureDoneCallback1(std::unique_ptr<DesktopFrame>* frame);
36 36
37 // Verifies that a rectangle explicitly marked as dirty is propagated 37 // Verifies that a rectangle explicitly marked as dirty is propagated
38 // correctly. 38 // correctly.
39 void CaptureDoneCallback2(DesktopFrame* frame); 39 void CaptureDoneCallback2(std::unique_ptr<DesktopFrame>* frame);
40 40
41 protected: 41 protected:
42 void SetUp() override { 42 void SetUp() override {
43 capturer_.reset( 43 capturer_.reset(
44 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault())); 44 ScreenCapturer::Create(DesktopCaptureOptions::CreateDefault()));
45 } 45 }
46 46
47 std::unique_ptr<ScreenCapturer> capturer_; 47 std::unique_ptr<ScreenCapturer> capturer_;
48 MockScreenCapturerCallback callback_; 48 MockScreenCapturerCallback callback_;
49 }; 49 };
50 50
51 void ScreenCapturerMacTest::CaptureDoneCallback1( 51 void ScreenCapturerMacTest::CaptureDoneCallback1(
52 DesktopFrame* frame) { 52 std::unique_ptr<DesktopFrame>* frame) {
53 std::unique_ptr<DesktopFrame> owned_frame(frame);
54
55 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( 53 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
56 MacDesktopConfiguration::BottomLeftOrigin); 54 MacDesktopConfiguration::BottomLeftOrigin);
57 55
58 // Verify that the region contains full frame. 56 // Verify that the region contains full frame.
59 DesktopRegion::Iterator it(frame->updated_region()); 57 DesktopRegion::Iterator it((*frame)->updated_region());
60 EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds)); 58 EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds));
61 } 59 }
62 60
63 void ScreenCapturerMacTest::CaptureDoneCallback2( 61 void ScreenCapturerMacTest::CaptureDoneCallback2(
64 DesktopFrame* frame) { 62 std::unique_ptr<DesktopFrame>* frame) {
65 std::unique_ptr<DesktopFrame> owned_frame(frame);
66
67 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( 63 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
68 MacDesktopConfiguration::BottomLeftOrigin); 64 MacDesktopConfiguration::BottomLeftOrigin);
69 int width = config.pixel_bounds.width(); 65 int width = config.pixel_bounds.width();
70 int height = config.pixel_bounds.height(); 66 int height = config.pixel_bounds.height();
71 67
72 EXPECT_EQ(width, frame->size().width()); 68 EXPECT_EQ(width, (*frame)->size().width());
73 EXPECT_EQ(height, frame->size().height()); 69 EXPECT_EQ(height, (*frame)->size().height());
74 EXPECT_TRUE(frame->data() != NULL); 70 EXPECT_TRUE((*frame)->data() != NULL);
75 // Depending on the capture method, the screen may be flipped or not, so 71 // Depending on the capture method, the screen may be flipped or not, so
76 // the stride may be positive or negative. 72 // the stride may be positive or negative.
77 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), 73 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
78 abs(frame->stride())); 74 abs((*frame)->stride()));
79 } 75 }
80 76
81 TEST_F(ScreenCapturerMacTest, Capture) { 77 TEST_F(ScreenCapturerMacTest, Capture) {
82 EXPECT_CALL(callback_, OnCaptureCompleted(_)) 78 EXPECT_CALL(callback_, OnCaptureCompletedPtr(_))
83 .Times(2) 79 .Times(2)
84 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1)) 80 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1))
85 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2)); 81 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2));
86 82
87 SCOPED_TRACE(""); 83 SCOPED_TRACE("");
88 capturer_->Start(&callback_); 84 capturer_->Start(&callback_);
89 85
90 // Check that we get an initial full-screen updated. 86 // Check that we get an initial full-screen updated.
91 capturer_->Capture(DesktopRegion()); 87 capturer_->Capture(DesktopRegion());
92 88
93 // Check that subsequent dirty rects are propagated correctly. 89 // Check that subsequent dirty rects are propagated correctly.
94 capturer_->Capture(DesktopRegion()); 90 capturer_->Capture(DesktopRegion());
95 } 91 }
96 92
97 } // namespace webrtc 93 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698