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

Side by Side Diff: media/video/capture/screen/screen_capturer_mac_unittest.cc

Issue 13983010: Use webrtc::DesktopCapturer for screen capturer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/video/capture/screen/screen_capturer.h" 5 #include "media/video/capture/screen/screen_capturer.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "media/video/capture/screen/mac/desktop_configuration.h" 14 #include "media/video/capture/screen/mac/desktop_configuration.h"
15 #include "media/video/capture/screen/screen_capture_data.h" 15 #include "media/video/capture/screen/screen_capture_data.h"
16 #include "media/video/capture/screen/screen_capturer_mock_objects.h" 16 #include "media/video/capture/screen/screen_capturer_mock_objects.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
19 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
20 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
18 21
19 using ::testing::_; 22 using ::testing::_;
20 using ::testing::AnyNumber; 23 using ::testing::AnyNumber;
21 using ::testing::Return; 24 using ::testing::Return;
22 25
23 namespace media { 26 namespace media {
24 27
25 class ScreenCapturerMacTest : public testing::Test { 28 class ScreenCapturerMacTest : public testing::Test {
26 public: 29 public:
27 // Verifies that the whole screen is initially dirty. 30 // Verifies that the whole screen is initially dirty.
28 void CaptureDoneCallback1(scoped_refptr<ScreenCaptureData> capture_data); 31 void CaptureDoneCallback1(webrtc::DesktopFrame* frame);
29 32
30 // Verifies that a rectangle explicitly marked as dirty is propagated 33 // Verifies that a rectangle explicitly marked as dirty is propagated
31 // correctly. 34 // correctly.
32 void CaptureDoneCallback2(scoped_refptr<ScreenCaptureData> capture_data); 35 void CaptureDoneCallback2(webrtc::DesktopFrame* frame);
33 36
34 protected: 37 protected:
35 virtual void SetUp() OVERRIDE { 38 virtual void SetUp() OVERRIDE {
36 capturer_ = ScreenCapturer::Create(); 39 capturer_ = ScreenCapturer::Create();
37 } 40 }
38 41
39 scoped_ptr<ScreenCapturer> capturer_; 42 scoped_ptr<ScreenCapturer> capturer_;
40 MockScreenCapturerDelegate delegate_; 43 MockScreenCapturerCallback callback_;
41 }; 44 };
42 45
43 void ScreenCapturerMacTest::CaptureDoneCallback1( 46 void ScreenCapturerMacTest::CaptureDoneCallback1(
44 scoped_refptr<ScreenCaptureData> capture_data) { 47 webrtc::DesktopFrame* frame) {
45 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( 48 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
46 MacDesktopConfiguration::BottomLeftOrigin); 49 MacDesktopConfiguration::BottomLeftOrigin);
47 int width = config.pixel_bounds.width();
48 int height = config.pixel_bounds.height();
49 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height));
50 50
51 EXPECT_EQ(initial_region, capture_data->dirty_region()); 51 // Verify that the region contains full frame.
52 webrtc::DesktopRegion::Iterator it(frame->updated_region());
53 EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds));
54
55 delete frame;
alexeypa (please no reviews) 2013/05/13 17:02:00 nit: Use a scoper instead.
Sergey Ulanov 2013/05/13 21:16:52 Done.
52 } 56 }
53 57
54 void ScreenCapturerMacTest::CaptureDoneCallback2( 58 void ScreenCapturerMacTest::CaptureDoneCallback2(
55 scoped_refptr<ScreenCaptureData> capture_data) { 59 webrtc::DesktopFrame* frame) {
56 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( 60 MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent(
57 MacDesktopConfiguration::BottomLeftOrigin); 61 MacDesktopConfiguration::BottomLeftOrigin);
58 int width = config.pixel_bounds.width(); 62 int width = config.pixel_bounds.width();
59 int height = config.pixel_bounds.height(); 63 int height = config.pixel_bounds.height();
60 64
61 EXPECT_EQ(width, capture_data->size().width()); 65 EXPECT_EQ(width, frame->size().width());
62 EXPECT_EQ(height, capture_data->size().height()); 66 EXPECT_EQ(height, frame->size().height());
63 EXPECT_TRUE(capture_data->data() != NULL); 67 EXPECT_TRUE(frame->data() != NULL);
64 // Depending on the capture method, the screen may be flipped or not, so 68 // Depending on the capture method, the screen may be flipped or not, so
65 // the stride may be positive or negative. 69 // the stride may be positive or negative.
66 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width), 70 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
67 abs(capture_data->stride())); 71 abs(frame->stride()));
72
73 delete frame;
alexeypa (please no reviews) 2013/05/13 17:02:00 nit: Use a scoper instead.
Sergey Ulanov 2013/05/13 21:16:52 Done.
68 } 74 }
69 75
70 TEST_F(ScreenCapturerMacTest, Capture) { 76 TEST_F(ScreenCapturerMacTest, Capture) {
71 EXPECT_CALL(delegate_, OnCaptureCompleted(_)) 77 EXPECT_CALL(callback_, OnCaptureCompleted(_))
72 .Times(2) 78 .Times(2)
73 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1)) 79 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback1))
74 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2)); 80 .WillOnce(Invoke(this, &ScreenCapturerMacTest::CaptureDoneCallback2));
75 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
76 .Times(AnyNumber());
77 81
78 EXPECT_CALL(delegate_, CreateSharedBuffer(_)) 82 EXPECT_CALL(callback_, CreateSharedMemory(_))
79 .Times(AnyNumber()) 83 .Times(AnyNumber())
80 .WillRepeatedly(Return(scoped_refptr<SharedBuffer>())); 84 .WillRepeatedly(Return(static_cast<webrtc::SharedMemory*>(NULL)));
81 85
82 SCOPED_TRACE(""); 86 SCOPED_TRACE("");
83 capturer_->Start(&delegate_); 87 capturer_->Start(&callback_);
84 88
85 // Check that we get an initial full-screen updated. 89 // Check that we get an initial full-screen updated.
86 capturer_->CaptureFrame(); 90 capturer_->Capture(webrtc::DesktopRegion());
87 91
88 // Check that subsequent dirty rects are propagated correctly. 92 // Check that subsequent dirty rects are propagated correctly.
89 capturer_->CaptureFrame(); 93 capturer_->Capture(webrtc::DesktopRegion());
90 } 94 }
91 95
92 } // namespace media 96 } // namespace media
93
94 namespace gfx {
95
96 std::ostream& operator<<(std::ostream& out, const SkRegion& region) {
97 out << "SkRegion(";
98 for (SkRegion::Iterator i(region); !i.done(); i.next()) {
99 const SkIRect& r = i.rect();
100 out << "(" << r.fLeft << "," << r.fTop << ","
101 << r.fRight << "," << r.fBottom << ")";
102 }
103 out << ")";
104 return out;
105 }
106
107 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698