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

Side by Side Diff: remoting/capturer/video_frame_capturer_mac_unittest.cc

Issue 12047101: Move screen capturers from remoting/capturer to media/video/capturer/screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/capturer/video_frame_capturer.h"
6
7 #include <ApplicationServices/ApplicationServices.h>
8
9 #include <ostream>
10
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "remoting/capturer/capture_data.h"
15 #include "remoting/capturer/video_capturer_mock_objects.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 using ::testing::_;
19 using ::testing::AnyNumber;
20
21 namespace remoting {
22
23 // Verify that the OS is at least Snow Leopard (10.6).
24 // Chromoting doesn't support 10.5 or earlier.
25 bool CheckSnowLeopard() {
26 long minorVersion, majorVersion;
27 Gestalt(gestaltSystemVersionMajor, &majorVersion);
28 Gestalt(gestaltSystemVersionMinor, &minorVersion);
29 return majorVersion == 10 && minorVersion > 5;
30 }
31
32 class VideoFrameCapturerMacTest : public testing::Test {
33 public:
34 // Verifies that the whole screen is initially dirty.
35 void CaptureDoneCallback1(scoped_refptr<CaptureData> capture_data);
36
37 // Verifies that a rectangle explicitly marked as dirty is propagated
38 // correctly.
39 void CaptureDoneCallback2(scoped_refptr<CaptureData> capture_data);
40
41 protected:
42 virtual void SetUp() OVERRIDE {
43 capturer_ = VideoFrameCapturer::Create();
44 }
45
46 void AddDirtyRect() {
47 SkIRect rect = SkIRect::MakeXYWH(0, 0, 10, 10);
48 region_.op(rect, SkRegion::kUnion_Op);
49 }
50
51 scoped_ptr<VideoFrameCapturer> capturer_;
52 MockVideoFrameCapturerDelegate delegate_;
53 SkRegion region_;
54 };
55
56 void VideoFrameCapturerMacTest::CaptureDoneCallback1(
57 scoped_refptr<CaptureData> capture_data) {
58 CGDirectDisplayID mainDevice = CGMainDisplayID();
59 int width = CGDisplayPixelsWide(mainDevice);
60 int height = CGDisplayPixelsHigh(mainDevice);
61 SkRegion initial_region(SkIRect::MakeXYWH(0, 0, width, height));
62 EXPECT_EQ(initial_region, capture_data->dirty_region());
63 }
64
65 void VideoFrameCapturerMacTest::CaptureDoneCallback2(
66 scoped_refptr<CaptureData> capture_data) {
67 CGDirectDisplayID mainDevice = CGMainDisplayID();
68 int width = CGDisplayPixelsWide(mainDevice);
69 int height = CGDisplayPixelsHigh(mainDevice);
70
71 EXPECT_EQ(region_, capture_data->dirty_region());
72 EXPECT_EQ(width, capture_data->size().width());
73 EXPECT_EQ(height, capture_data->size().height());
74 EXPECT_TRUE(capture_data->data() != NULL);
75 // Depending on the capture method, the screen may be flipped or not, so
76 // the stride may be positive or negative.
77 EXPECT_EQ(static_cast<int>(sizeof(uint32_t) * width),
78 abs(capture_data->stride()));
79 }
80
81 TEST_F(VideoFrameCapturerMacTest, Capture) {
82 if (!CheckSnowLeopard()) {
83 return;
84 }
85
86 EXPECT_CALL(delegate_, OnCaptureCompleted(_))
87 .Times(2)
88 .WillOnce(Invoke(this, &VideoFrameCapturerMacTest::CaptureDoneCallback1))
89 .WillOnce(Invoke(this, &VideoFrameCapturerMacTest::CaptureDoneCallback2));
90 EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
91 .Times(AnyNumber());
92
93 SCOPED_TRACE("");
94 capturer_->Start(&delegate_);
95
96 // Check that we get an initial full-screen updated.
97 capturer_->CaptureFrame();
98
99 // Check that subsequent dirty rects are propagated correctly.
100 AddDirtyRect();
101 capturer_->InvalidateRegion(region_);
102 capturer_->CaptureFrame();
103 capturer_->Stop();
104 }
105
106 } // namespace remoting
107
108 namespace gfx {
109
110 std::ostream& operator<<(std::ostream& out, const SkRegion& region) {
111 out << "SkRegion(";
112 for (SkRegion::Iterator i(region); !i.done(); i.next()) {
113 const SkIRect& r = i.rect();
114 out << "(" << r.fLeft << "," << r.fTop << ","
115 << r.fRight << "," << r.fBottom << ")";
116 }
117 out << ")";
118 return out;
119 }
120
121 } // namespace gfx
OLDNEW
« no previous file with comments | « remoting/capturer/video_frame_capturer_mac.mm ('k') | remoting/capturer/video_frame_capturer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698