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

Side by Side Diff: chrome/browser/chromeos/accessibility/accessibility_highlight_manager_interactive_uitest.cc

Issue 2088903002: Fix flakiness in AccessibilityHighlightManagerTest and re-enable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: AsBitmap Created 4 years, 6 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 | « no previous file | no next file » | 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "chrome/browser/chromeos/accessibility/accessibility_highlight_manager. h" 5 #include "chrome/browser/chromeos/accessibility/accessibility_highlight_manager. h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 SkColor average_diff_color() { return average_diff_color_; } 117 SkColor average_diff_color() { return average_diff_color_; }
118 118
119 private: 119 private:
120 void GotSnapshot(const gfx::Image& image) { 120 void GotSnapshot(const gfx::Image& image) {
121 image_ = image; 121 image_ = image;
122 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 122 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
123 run_loop_quitter_); 123 run_loop_quitter_);
124 } 124 }
125 125
126 void Capture(const gfx::Rect& bounds) { 126 void Capture(const gfx::Rect& bounds) {
127 aura::Window* window = ash::Shell::GetPrimaryRootWindow(); 127 // Occasionally we don't get any pixels the first try.
128 ui::GrabWindowSnapshotAndScaleAsync( 128 // Keep trying until we get the correct size bitmap and
129 window, bounds, bounds.size(), 129 // the first pixel is not transparent.
130 content::BrowserThread::GetBlockingPool(), 130 while (true) {
131 base::Bind(&AccessibilityHighlightManagerTest::GotSnapshot, this)); 131 aura::Window* window = ash::Shell::GetPrimaryRootWindow();
132 base::RunLoop run_loop; 132 ui::GrabWindowSnapshotAndScaleAsync(
133 run_loop_quitter_ = run_loop.QuitClosure(); 133 window, bounds, bounds.size(),
134 run_loop.Run(); 134 content::BrowserThread::GetBlockingPool(),
135 base::Bind(&AccessibilityHighlightManagerTest::GotSnapshot, this));
136 base::RunLoop run_loop;
137 run_loop_quitter_ = run_loop.QuitClosure();
138 run_loop.Run();
139 SkBitmap bitmap = image_.AsBitmap();
140 SkAutoLockPixels lock(bitmap);
141 if (bitmap.width() != bounds.width() ||
142 bitmap.height() != bounds.height()) {
143 LOG(INFO) << "Bitmap not correct size, trying to capture again";
144 continue;
145 }
146 if (255 == SkColorGetA(bitmap.getColor(0, 0))) {
147 LOG(INFO) << "Bitmap is transparent, trying to capture again";
148 break;
149 }
150 }
135 } 151 }
136 152
137 base::Closure run_loop_quitter_; 153 base::Closure run_loop_quitter_;
138 gfx::Image image_; 154 gfx::Image image_;
139 SkBitmap before_bmp_; 155 SkBitmap before_bmp_;
140 SkBitmap after_bmp_; 156 SkBitmap after_bmp_;
141 int diff_count_ = 0; 157 int diff_count_ = 0;
142 SkColor average_diff_color_ = 0; 158 SkColor average_diff_color_ = 0;
143 159
144 DISALLOW_COPY_AND_ASSIGN(AccessibilityHighlightManagerTest); 160 DISALLOW_COPY_AND_ASSIGN(AccessibilityHighlightManagerTest);
145 }; 161 };
146 162
147 // Flaky. http://crbug.com/621306
148 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, 163 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest,
149 DISABLED_TestCaretRingDrawsBluePixels) { 164 TestCaretRingDrawsBluePixels) {
150 gfx::Rect capture_bounds(200, 300, 100, 100); 165 gfx::Rect capture_bounds(200, 300, 100, 100);
151 gfx::Rect caret_bounds(230, 330, 1, 25); 166 gfx::Rect caret_bounds(230, 330, 1, 25);
152 167
153 CaptureBeforeImage(capture_bounds); 168 CaptureBeforeImage(capture_bounds);
154 169
155 TestAccessibilityHighlightManager manager; 170 TestAccessibilityHighlightManager manager;
156 manager.HighlightCaret(true); 171 manager.HighlightCaret(true);
157 MockTextInputClient text_input_client; 172 MockTextInputClient text_input_client;
158 text_input_client.SetCaretBounds(caret_bounds); 173 text_input_client.SetCaretBounds(caret_bounds);
159 manager.OnCaretBoundsChanged(&text_input_client); 174 manager.OnCaretBoundsChanged(&text_input_client);
160 175
161 CaptureAfterImage(capture_bounds); 176 CaptureAfterImage(capture_bounds);
162 ComputeImageStats(); 177 ComputeImageStats();
163 178
164 // This is a smoke test to assert that something is drawn in the right 179 // This is a smoke test to assert that something is drawn in the right
165 // part of the screen of approximately the right size and color. 180 // part of the screen of approximately the right size and color.
166 // There's deliberately some tolerance for tiny errors. 181 // There's deliberately some tolerance for tiny errors.
167 EXPECT_NEAR(1487, diff_count(), 50); 182 EXPECT_NEAR(1487, diff_count(), 50);
168 EXPECT_NEAR(175, SkColorGetR(average_diff_color()), 5); 183 EXPECT_NEAR(175, SkColorGetR(average_diff_color()), 5);
169 EXPECT_NEAR(175, SkColorGetG(average_diff_color()), 5); 184 EXPECT_NEAR(175, SkColorGetG(average_diff_color()), 5);
170 EXPECT_NEAR(255, SkColorGetB(average_diff_color()), 5); 185 EXPECT_NEAR(255, SkColorGetB(average_diff_color()), 5);
171 } 186 }
172 187
173 // Flaky. http://crbug.com/621306
174 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, 188 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest,
175 DISABLED_TestCursorRingDrawsRedPixels) { 189 TestCursorRingDrawsRedPixels) {
176 gfx::Rect capture_bounds(200, 300, 100, 100); 190 gfx::Rect capture_bounds(200, 300, 100, 100);
177 gfx::Point cursor_point(250, 350); 191 gfx::Point cursor_point(250, 350);
178 192
179 CaptureBeforeImage(capture_bounds); 193 CaptureBeforeImage(capture_bounds);
180 194
181 TestAccessibilityHighlightManager manager; 195 TestAccessibilityHighlightManager manager;
182 manager.HighlightCursor(true); 196 manager.HighlightCursor(true);
183 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, cursor_point, cursor_point, 197 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, cursor_point, cursor_point,
184 ui::EventTimeForNow(), 0, 0); 198 ui::EventTimeForNow(), 0, 0);
185 manager.OnMouseEvent(&mouse_move); 199 manager.OnMouseEvent(&mouse_move);
186 CaptureAfterImage(capture_bounds); 200 CaptureAfterImage(capture_bounds);
187 ComputeImageStats(); 201 ComputeImageStats();
188 202
189 // This is a smoke test to assert that something is drawn in the right 203 // This is a smoke test to assert that something is drawn in the right
190 // part of the screen of approximately the right size and color. 204 // part of the screen of approximately the right size and color.
191 // There's deliberately some tolerance for tiny errors. 205 // There's deliberately some tolerance for tiny errors.
192 EXPECT_NEAR(1521, diff_count(), 50); 206 EXPECT_NEAR(1521, diff_count(), 50);
193 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5); 207 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5);
194 EXPECT_NEAR(176, SkColorGetG(average_diff_color()), 5); 208 EXPECT_NEAR(176, SkColorGetG(average_diff_color()), 5);
195 EXPECT_NEAR(176, SkColorGetB(average_diff_color()), 5); 209 EXPECT_NEAR(176, SkColorGetB(average_diff_color()), 5);
196 } 210 }
197 211
198 // Flaky. http://crbug.com/621306
199 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, 212 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest,
200 DISABLED_TestFocusRingDrawsOrangePixels) { 213 TestFocusRingDrawsOrangePixels) {
201 gfx::Rect capture_bounds(200, 300, 100, 100); 214 gfx::Rect capture_bounds(200, 300, 100, 100);
202 gfx::Rect focus_bounds(230, 330, 40, 40); 215 gfx::Rect focus_bounds(230, 330, 40, 40);
203 216
204 CaptureBeforeImage(capture_bounds); 217 CaptureBeforeImage(capture_bounds);
205 218
206 TestAccessibilityHighlightManager manager; 219 TestAccessibilityHighlightManager manager;
207 manager.HighlightFocus(true); 220 manager.HighlightFocus(true);
208 content::FocusedNodeDetails details{false, focus_bounds}; 221 content::FocusedNodeDetails details{false, focus_bounds};
209 manager.Observe(content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, 222 manager.Observe(content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
210 content::Source<AccessibilityHighlightManagerTest>(this), 223 content::Source<AccessibilityHighlightManagerTest>(this),
211 content::Details<content::FocusedNodeDetails>(&details)); 224 content::Details<content::FocusedNodeDetails>(&details));
212 CaptureAfterImage(capture_bounds); 225 CaptureAfterImage(capture_bounds);
213 ComputeImageStats(); 226 ComputeImageStats();
214 227
215 // This is a smoke test to assert that something is drawn in the right 228 // This is a smoke test to assert that something is drawn in the right
216 // part of the screen of approximately the right size and color. 229 // part of the screen of approximately the right size and color.
217 // There's deliberately some tolerance for tiny errors. 230 // There's deliberately some tolerance for tiny errors.
218 EXPECT_NEAR(1608, diff_count(), 50); 231 EXPECT_NEAR(1608, diff_count(), 50);
219 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5); 232 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5);
220 EXPECT_NEAR(201, SkColorGetG(average_diff_color()), 5); 233 EXPECT_NEAR(201, SkColorGetG(average_diff_color()), 5);
221 EXPECT_NEAR(152, SkColorGetB(average_diff_color()), 5); 234 EXPECT_NEAR(152, SkColorGetB(average_diff_color()), 5);
222 } 235 }
223 236
224 } // namespace chromeos 237 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698