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

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

Issue 7491070: Switch over to using SkRegions to calculate dirty areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up shared lib compile Created 9 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/screen_recorder.cc ('k') | remoting/host/x_server_pixel_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/task.h" 6 #include "base/task.h"
7 #include "remoting/base/base_mock_objects.h" 7 #include "remoting/base/base_mock_objects.h"
8 #include "remoting/host/host_mock_objects.h" 8 #include "remoting/host/host_mock_objects.h"
9 #include "remoting/host/screen_recorder.h" 9 #include "remoting/host/screen_recorder.h"
10 #include "remoting/proto/video.pb.h" 10 #include "remoting/proto/video.pb.h"
(...skipping 13 matching lines...) Expand all
24 using ::testing::InSequence; 24 using ::testing::InSequence;
25 using ::testing::InvokeWithoutArgs; 25 using ::testing::InvokeWithoutArgs;
26 using ::testing::NotNull; 26 using ::testing::NotNull;
27 using ::testing::Return; 27 using ::testing::Return;
28 using ::testing::SaveArg; 28 using ::testing::SaveArg;
29 29
30 namespace remoting { 30 namespace remoting {
31 31
32 namespace { 32 namespace {
33 33
34 ACTION_P2(RunCallback, rects, data) { 34 ACTION_P2(RunCallback, region, data) {
35 InvalidRects& dirty_rects = data->mutable_dirty_rects(); 35 SkRegion& dirty_region = data->mutable_dirty_region();
36 InvalidRects temp_rects; 36 dirty_region.op(region, SkRegion::kUnion_Op);
37 std::set_union(dirty_rects.begin(), dirty_rects.end(),
38 rects.begin(), rects.end(),
39 std::inserter(temp_rects, temp_rects.begin()));
40 dirty_rects.swap(temp_rects);
41 arg0->Run(data); 37 arg0->Run(data);
42 delete arg0; 38 delete arg0;
43 } 39 }
44 40
45 ACTION(FinishEncode) { 41 ACTION(FinishEncode) {
46 scoped_ptr<VideoPacket> packet(new VideoPacket()); 42 scoped_ptr<VideoPacket> packet(new VideoPacket());
47 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION); 43 packet->set_flags(VideoPacket::LAST_PACKET | VideoPacket::LAST_PARTITION);
48 arg2->Run(packet.release()); 44 arg2->Run(packet.release());
49 delete arg2; 45 delete arg2;
50 } 46 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 MockCapturer capturer_; 96 MockCapturer capturer_;
101 MockEncoder* encoder_; 97 MockEncoder* encoder_;
102 MessageLoop message_loop_; 98 MessageLoop message_loop_;
103 private: 99 private:
104 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest); 100 DISALLOW_COPY_AND_ASSIGN(ScreenRecorderTest);
105 }; 101 };
106 102
107 // This test mocks capturer, encoder and network layer to operate one recording 103 // This test mocks capturer, encoder and network layer to operate one recording
108 // cycle. 104 // cycle.
109 TEST_F(ScreenRecorderTest, OneRecordCycle) { 105 TEST_F(ScreenRecorderTest, OneRecordCycle) {
110 InvalidRects update_rects; 106 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10));
111 update_rects.insert(gfx::Rect(0, 0, 10, 10));
112 DataPlanes planes; 107 DataPlanes planes;
113 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { 108 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) {
114 planes.data[i] = reinterpret_cast<uint8*>(i); 109 planes.data[i] = reinterpret_cast<uint8*>(i);
115 planes.strides[i] = kWidth * 4; 110 planes.strides[i] = kWidth * 4;
116 } 111 }
117 gfx::Size size(kWidth, kHeight); 112 gfx::Size size(kWidth, kHeight);
118 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat)); 113 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat));
119 EXPECT_CALL(capturer_, InvalidateFullScreen()); 114 EXPECT_CALL(capturer_, InvalidateFullScreen());
120 115
121 // First the capturer is called. 116 // First the capturer is called.
122 EXPECT_CALL(capturer_, CaptureInvalidRects(NotNull())) 117 EXPECT_CALL(capturer_, CaptureInvalidRegion(NotNull()))
123 .WillOnce(RunCallback(update_rects, data)); 118 .WillOnce(RunCallback(update_region, data));
124 119
125 // Expect the encoder be called. 120 // Expect the encoder be called.
126 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) 121 EXPECT_CALL(*encoder_, Encode(data, false, NotNull()))
127 .WillOnce(FinishEncode()); 122 .WillOnce(FinishEncode());
128 123
129 MockVideoStub video_stub; 124 MockVideoStub video_stub;
130 EXPECT_CALL(*connection_, video_stub()) 125 EXPECT_CALL(*connection_, video_stub())
131 .WillRepeatedly(Return(&video_stub)); 126 .WillRepeatedly(Return(&video_stub));
132 127
133 // Expect the client be notified. 128 // Expect the client be notified.
(...skipping 15 matching lines...) Expand all
149 144
150 // Make sure all tasks are completed. 145 // Make sure all tasks are completed.
151 message_loop_.RunAllPending(); 146 message_loop_.RunAllPending();
152 } 147 }
153 148
154 // This test mocks capturer, encoder and network layer to simulate one recording 149 // This test mocks capturer, encoder and network layer to simulate one recording
155 // cycle. When the first encoded packet is submitted to the network 150 // cycle. When the first encoded packet is submitted to the network
156 // ScreenRecorder is instructed to come to a complete stop. We expect the stop 151 // ScreenRecorder is instructed to come to a complete stop. We expect the stop
157 // sequence to be executed successfully. 152 // sequence to be executed successfully.
158 TEST_F(ScreenRecorderTest, StartAndStop) { 153 TEST_F(ScreenRecorderTest, StartAndStop) {
159 InvalidRects update_rects; 154 SkRegion update_region(SkIRect::MakeXYWH(0, 0, 10, 10));
160 update_rects.insert(gfx::Rect(0, 0, 10, 10));
161 DataPlanes planes; 155 DataPlanes planes;
162 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { 156 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) {
163 planes.data[i] = reinterpret_cast<uint8*>(i); 157 planes.data[i] = reinterpret_cast<uint8*>(i);
164 planes.strides[i] = kWidth * 4; 158 planes.strides[i] = kWidth * 4;
165 } 159 }
166 160
167 gfx::Size size(kWidth, kHeight); 161 gfx::Size size(kWidth, kHeight);
168 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat)); 162 scoped_refptr<CaptureData> data(new CaptureData(planes, size, kFormat));
169 EXPECT_CALL(capturer_, InvalidateFullScreen()); 163 EXPECT_CALL(capturer_, InvalidateFullScreen());
170 164
171 // First the capturer is called. 165 // First the capturer is called.
172 EXPECT_CALL(capturer_, CaptureInvalidRects(NotNull())) 166 EXPECT_CALL(capturer_, CaptureInvalidRegion(NotNull()))
173 .WillRepeatedly(RunCallback(update_rects, data)); 167 .WillRepeatedly(RunCallback(update_region, data));
174 168
175 // Expect the encoder be called. 169 // Expect the encoder be called.
176 EXPECT_CALL(*encoder_, Encode(data, false, NotNull())) 170 EXPECT_CALL(*encoder_, Encode(data, false, NotNull()))
177 .WillRepeatedly(FinishEncode()); 171 .WillRepeatedly(FinishEncode());
178 172
179 MockVideoStub video_stub; 173 MockVideoStub video_stub;
180 EXPECT_CALL(*connection_, video_stub()) 174 EXPECT_CALL(*connection_, video_stub())
181 .WillRepeatedly(Return(&video_stub)); 175 .WillRepeatedly(Return(&video_stub));
182 176
183 // By default delete the arguments when ProcessVideoPacket is received. 177 // By default delete the arguments when ProcessVideoPacket is received.
(...skipping 17 matching lines...) Expand all
201 record_->Start(); 195 record_->Start();
202 message_loop_.Run(); 196 message_loop_.Run();
203 } 197 }
204 198
205 TEST_F(ScreenRecorderTest, StopWithoutStart) { 199 TEST_F(ScreenRecorderTest, StopWithoutStart) {
206 record_->Stop(NewRunnableFunction(&QuitMessageLoop, &message_loop_)); 200 record_->Stop(NewRunnableFunction(&QuitMessageLoop, &message_loop_));
207 message_loop_.Run(); 201 message_loop_.Run();
208 } 202 }
209 203
210 } // namespace remoting 204 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/screen_recorder.cc ('k') | remoting/host/x_server_pixel_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698