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

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

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

Powered by Google App Engine
This is Rietveld 408576698