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

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

Issue 2337073007: Deflaky ScreenCapturerTest (Closed)
Patch Set: Still disable real screen capturer tests Created 4 years, 2 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
« no previous file with comments | « webrtc/modules/BUILD.gn ('k') | webrtc/modules/desktop_capture/screen_drawer.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 /* 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 namespace { 45 namespace {
46 46
47 ACTION_P(SaveUniquePtrArg, dest) { 47 ACTION_P(SaveUniquePtrArg, dest) {
48 *dest = std::move(*arg1); 48 *dest = std::move(*arg1);
49 } 49 }
50 50
51 // Returns true if color in |rect| of |frame| is |color|. 51 // Returns true if color in |rect| of |frame| is |color|.
52 bool ArePixelsColoredBy(const DesktopFrame& frame, 52 bool ArePixelsColoredBy(const DesktopFrame& frame,
53 DesktopRect rect, 53 DesktopRect rect,
54 RgbaColor color) { 54 RgbaColor color,
55 // updated_region() should cover the painted area. 55 bool may_partially_draw) {
56 DesktopRegion updated_region(frame.updated_region()); 56 if (!may_partially_draw) {
57 updated_region.IntersectWith(rect); 57 // updated_region() should cover the painted area.
58 if (!updated_region.Equals(DesktopRegion(rect))) { 58 DesktopRegion updated_region(frame.updated_region());
59 return false; 59 updated_region.IntersectWith(rect);
60 if (!updated_region.Equals(DesktopRegion(rect))) {
61 return false;
62 }
60 } 63 }
61 64
62 // Color in the |rect| should be |color|. 65 // Color in the |rect| should be |color|.
63 uint8_t* row = frame.GetFrameDataAtPos(rect.top_left()); 66 uint8_t* row = frame.GetFrameDataAtPos(rect.top_left());
64 for (int i = 0; i < rect.height(); i++) { 67 for (int i = 0; i < rect.height(); i++) {
65 uint8_t* column = row; 68 uint8_t* column = row;
66 for (int j = 0; j < rect.width(); j++) { 69 for (int j = 0; j < rect.width(); j++) {
67 if (color != RgbaColor(column)) { 70 if (color != RgbaColor(column)) {
68 return false; 71 return false;
69 } 72 }
(...skipping 30 matching lines...) Expand all
100 drawer->DrawableRegion().height() < kTestArea) { 103 drawer->DrawableRegion().height() < kTestArea) {
101 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the " 104 LOG(LS_WARNING) << "ScreenDrawer::DrawableRegion() is too small for the "
102 "CaptureUpdatedRegion tests."; 105 "CaptureUpdatedRegion tests.";
103 return; 106 return;
104 } 107 }
105 108
106 for (ScreenCapturer* capturer : capturers) { 109 for (ScreenCapturer* capturer : capturers) {
107 capturer->Start(&callback_); 110 capturer->Start(&callback_);
108 } 111 }
109 112
110 // Draw a set of |kRectSize| by |kRectSize| rectangles at (|i|, |i|). One of 113 // Draw a set of |kRectSize| by |kRectSize| rectangles at (|i|, |i|), or
111 // (controlled by |c|) its primary colors is |i|, and the other two are 114 // |i| by |i| rectangles at (|kRectSize|, |kRectSize|). One of (controlled
112 // 0xff. So we won't draw a white rectangle. 115 // by |c|) its primary colors is |i|, and the other two are 0x7f. So we
116 // won't draw a black or white rectangle.
113 for (int c = 0; c < 3; c++) { 117 for (int c = 0; c < 3; c++) {
118 // A fixed size rectangle.
114 for (int i = 0; i < kTestArea - kRectSize; i += 16) { 119 for (int i = 0; i < kTestArea - kRectSize; i += 16) {
115 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize); 120 DesktopRect rect = DesktopRect::MakeXYWH(i, i, kRectSize, kRectSize);
116 rect.Translate(drawer->DrawableRegion().top_left()); 121 rect.Translate(drawer->DrawableRegion().top_left());
117 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f), 122 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f),
118 (c == 1 ? (i & 0xff) : 0x7f), 123 (c == 1 ? (i & 0xff) : 0x7f),
119 (c == 2 ? (i & 0xff) : 0x7f)); 124 (c == 2 ? (i & 0xff) : 0x7f));
120 drawer->Clear(); 125 TestCaptureOneFrame(capturers, drawer.get(), rect, color);
121 drawer->DrawRectangle(rect, color); 126 }
127
128 // A variable-size rectangle.
129 for (int i = 0; i < kTestArea - kRectSize; i += 16) {
130 DesktopRect rect = DesktopRect::MakeXYWH(kRectSize, kRectSize, i, i);
131 rect.Translate(drawer->DrawableRegion().top_left());
132 RgbaColor color((c == 0 ? (i & 0xff) : 0x7f),
133 (c == 1 ? (i & 0xff) : 0x7f),
134 (c == 2 ? (i & 0xff) : 0x7f));
122 TestCaptureOneFrame(capturers, drawer.get(), rect, color); 135 TestCaptureOneFrame(capturers, drawer.get(), rect, color);
123 } 136 }
124 } 137 }
125 } 138 }
126 139
127 void TestCaptureUpdatedRegion() { 140 void TestCaptureUpdatedRegion() {
128 TestCaptureUpdatedRegion({capturer_.get()}); 141 TestCaptureUpdatedRegion({capturer_.get()});
129 } 142 }
130 143
131 #if defined(WEBRTC_WIN) 144 #if defined(WEBRTC_WIN)
(...skipping 27 matching lines...) Expand all
159 172
160 private: 173 private:
161 // Repeats capturing the frame by using |capturers| one-by-one for 600 times, 174 // Repeats capturing the frame by using |capturers| one-by-one for 600 times,
162 // typically 30 seconds, until they succeeded captured a |color| rectangle at 175 // typically 30 seconds, until they succeeded captured a |color| rectangle at
163 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two 176 // |rect|. This function uses |drawer|->WaitForPendingDraws() between two
164 // attempts to wait for the screen to update. 177 // attempts to wait for the screen to update.
165 void TestCaptureOneFrame(std::vector<ScreenCapturer*> capturers, 178 void TestCaptureOneFrame(std::vector<ScreenCapturer*> capturers,
166 ScreenDrawer* drawer, 179 ScreenDrawer* drawer,
167 DesktopRect rect, 180 DesktopRect rect,
168 RgbaColor color) { 181 RgbaColor color) {
182 const int wait_capture_round = 600;
183 drawer->Clear();
169 size_t succeeded_capturers = 0; 184 size_t succeeded_capturers = 0;
170 const int wait_capture_round = 600;
171 for (int i = 0; i < wait_capture_round; i++) { 185 for (int i = 0; i < wait_capture_round; i++) {
186 drawer->DrawRectangle(rect, color);
172 drawer->WaitForPendingDraws(); 187 drawer->WaitForPendingDraws();
173 for (size_t j = 0; j < capturers.size(); j++) { 188 for (size_t j = 0; j < capturers.size(); j++) {
174 if (capturers[j] == nullptr) { 189 if (capturers[j] == nullptr) {
175 // ScreenCapturer should return an empty updated_region() if no 190 // ScreenCapturer should return an empty updated_region() if no
176 // update detected. So we won't test it again if it has captured 191 // update detected. So we won't test it again if it has captured
177 // the rectangle we drew. 192 // the rectangle we drew.
178 continue; 193 continue;
179 } 194 }
180 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]); 195 std::unique_ptr<DesktopFrame> frame = CaptureFrame(capturers[j]);
181 if (!frame) { 196 if (!frame) {
182 // CaptureFrame() has triggered an assertion failure already, we 197 // CaptureFrame() has triggered an assertion failure already, we
183 // only need to return here. 198 // only need to return here.
184 return; 199 return;
185 } 200 }
186 201
187 if (ArePixelsColoredBy(*frame, rect, color)) { 202 if (ArePixelsColoredBy(
203 *frame, rect, color, drawer->MayDrawIncompleteShapes())) {
188 capturers[j] = nullptr; 204 capturers[j] = nullptr;
189 succeeded_capturers++; 205 succeeded_capturers++;
190 } 206 }
191 } 207 }
192 208
193 if (succeeded_capturers == capturers.size()) { 209 if (succeeded_capturers == capturers.size()) {
194 break; 210 break;
195 } 211 }
196 } 212 }
197 213
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) { 416 DISABLED_MaybeCaptureUpdatedRegionWithDirectxCapturer) {
401 // Even DirectX capturer is not supported in current system, we should be able 417 // Even DirectX capturer is not supported in current system, we should be able
402 // to select a usable capturer. 418 // to select a usable capturer.
403 MaybeCreateDirectxCapturer(); 419 MaybeCreateDirectxCapturer();
404 TestCaptureUpdatedRegion(); 420 TestCaptureUpdatedRegion();
405 } 421 }
406 422
407 #endif // defined(WEBRTC_WIN) 423 #endif // defined(WEBRTC_WIN)
408 424
409 } // namespace webrtc 425 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/BUILD.gn ('k') | webrtc/modules/desktop_capture/screen_drawer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698