Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; | |
| 140 image_.AsBitmap().deepCopyTo(&bitmap); | |
|
xiyuan
2016/06/21 19:19:37
nit: Is this copy necessary? Can we just use image
dmazzoni
2016/06/21 19:59:06
Good idea, done.
| |
| 141 SkAutoLockPixels lock(bitmap); | |
| 142 if (bitmap.width() != bounds.width() || | |
| 143 bitmap.height() != bounds.height()) { | |
| 144 LOG(INFO) << "Bitmap not correct size, trying to capture again"; | |
| 145 continue; | |
| 146 } | |
| 147 if (255 == SkColorGetA(bitmap.getColor(0, 0))) { | |
| 148 LOG(INFO) << "Bitmap is transparent, trying to capture again"; | |
| 149 break; | |
| 150 } | |
| 151 } | |
| 135 } | 152 } |
| 136 | 153 |
| 137 base::Closure run_loop_quitter_; | 154 base::Closure run_loop_quitter_; |
| 138 gfx::Image image_; | 155 gfx::Image image_; |
| 139 SkBitmap before_bmp_; | 156 SkBitmap before_bmp_; |
| 140 SkBitmap after_bmp_; | 157 SkBitmap after_bmp_; |
| 141 int diff_count_ = 0; | 158 int diff_count_ = 0; |
| 142 SkColor average_diff_color_ = 0; | 159 SkColor average_diff_color_ = 0; |
| 143 | 160 |
| 144 DISALLOW_COPY_AND_ASSIGN(AccessibilityHighlightManagerTest); | 161 DISALLOW_COPY_AND_ASSIGN(AccessibilityHighlightManagerTest); |
| 145 }; | 162 }; |
| 146 | 163 |
| 147 // Flaky. http://crbug.com/621306 | |
| 148 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, | 164 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, |
| 149 DISABLED_TestCaretRingDrawsBluePixels) { | 165 TestCaretRingDrawsBluePixels) { |
| 150 gfx::Rect capture_bounds(200, 300, 100, 100); | 166 gfx::Rect capture_bounds(200, 300, 100, 100); |
| 151 gfx::Rect caret_bounds(230, 330, 1, 25); | 167 gfx::Rect caret_bounds(230, 330, 1, 25); |
| 152 | 168 |
| 153 CaptureBeforeImage(capture_bounds); | 169 CaptureBeforeImage(capture_bounds); |
| 154 | 170 |
| 155 TestAccessibilityHighlightManager manager; | 171 TestAccessibilityHighlightManager manager; |
| 156 manager.HighlightCaret(true); | 172 manager.HighlightCaret(true); |
| 157 MockTextInputClient text_input_client; | 173 MockTextInputClient text_input_client; |
| 158 text_input_client.SetCaretBounds(caret_bounds); | 174 text_input_client.SetCaretBounds(caret_bounds); |
| 159 manager.OnCaretBoundsChanged(&text_input_client); | 175 manager.OnCaretBoundsChanged(&text_input_client); |
| 160 | 176 |
| 161 CaptureAfterImage(capture_bounds); | 177 CaptureAfterImage(capture_bounds); |
| 162 ComputeImageStats(); | 178 ComputeImageStats(); |
| 163 | 179 |
| 164 // This is a smoke test to assert that something is drawn in the right | 180 // 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. | 181 // part of the screen of approximately the right size and color. |
| 166 // There's deliberately some tolerance for tiny errors. | 182 // There's deliberately some tolerance for tiny errors. |
| 167 EXPECT_NEAR(1487, diff_count(), 50); | 183 EXPECT_NEAR(1487, diff_count(), 50); |
| 168 EXPECT_NEAR(175, SkColorGetR(average_diff_color()), 5); | 184 EXPECT_NEAR(175, SkColorGetR(average_diff_color()), 5); |
| 169 EXPECT_NEAR(175, SkColorGetG(average_diff_color()), 5); | 185 EXPECT_NEAR(175, SkColorGetG(average_diff_color()), 5); |
| 170 EXPECT_NEAR(255, SkColorGetB(average_diff_color()), 5); | 186 EXPECT_NEAR(255, SkColorGetB(average_diff_color()), 5); |
| 171 } | 187 } |
| 172 | 188 |
| 173 // Flaky. http://crbug.com/621306 | |
| 174 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, | 189 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, |
| 175 DISABLED_TestCursorRingDrawsRedPixels) { | 190 TestCursorRingDrawsRedPixels) { |
| 176 gfx::Rect capture_bounds(200, 300, 100, 100); | 191 gfx::Rect capture_bounds(200, 300, 100, 100); |
| 177 gfx::Point cursor_point(250, 350); | 192 gfx::Point cursor_point(250, 350); |
| 178 | 193 |
| 179 CaptureBeforeImage(capture_bounds); | 194 CaptureBeforeImage(capture_bounds); |
| 180 | 195 |
| 181 TestAccessibilityHighlightManager manager; | 196 TestAccessibilityHighlightManager manager; |
| 182 manager.HighlightCursor(true); | 197 manager.HighlightCursor(true); |
| 183 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, cursor_point, cursor_point, | 198 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, cursor_point, cursor_point, |
| 184 ui::EventTimeForNow(), 0, 0); | 199 ui::EventTimeForNow(), 0, 0); |
| 185 manager.OnMouseEvent(&mouse_move); | 200 manager.OnMouseEvent(&mouse_move); |
| 186 CaptureAfterImage(capture_bounds); | 201 CaptureAfterImage(capture_bounds); |
| 187 ComputeImageStats(); | 202 ComputeImageStats(); |
| 188 | 203 |
| 189 // This is a smoke test to assert that something is drawn in the right | 204 // 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. | 205 // part of the screen of approximately the right size and color. |
| 191 // There's deliberately some tolerance for tiny errors. | 206 // There's deliberately some tolerance for tiny errors. |
| 192 EXPECT_NEAR(1521, diff_count(), 50); | 207 EXPECT_NEAR(1521, diff_count(), 50); |
| 193 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5); | 208 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5); |
| 194 EXPECT_NEAR(176, SkColorGetG(average_diff_color()), 5); | 209 EXPECT_NEAR(176, SkColorGetG(average_diff_color()), 5); |
| 195 EXPECT_NEAR(176, SkColorGetB(average_diff_color()), 5); | 210 EXPECT_NEAR(176, SkColorGetB(average_diff_color()), 5); |
| 196 } | 211 } |
| 197 | 212 |
| 198 // Flaky. http://crbug.com/621306 | |
| 199 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, | 213 IN_PROC_BROWSER_TEST_F(AccessibilityHighlightManagerTest, |
| 200 DISABLED_TestFocusRingDrawsOrangePixels) { | 214 TestFocusRingDrawsOrangePixels) { |
| 201 gfx::Rect capture_bounds(200, 300, 100, 100); | 215 gfx::Rect capture_bounds(200, 300, 100, 100); |
| 202 gfx::Rect focus_bounds(230, 330, 40, 40); | 216 gfx::Rect focus_bounds(230, 330, 40, 40); |
| 203 | 217 |
| 204 CaptureBeforeImage(capture_bounds); | 218 CaptureBeforeImage(capture_bounds); |
| 205 | 219 |
| 206 TestAccessibilityHighlightManager manager; | 220 TestAccessibilityHighlightManager manager; |
| 207 manager.HighlightFocus(true); | 221 manager.HighlightFocus(true); |
| 208 content::FocusedNodeDetails details{false, focus_bounds}; | 222 content::FocusedNodeDetails details{false, focus_bounds}; |
| 209 manager.Observe(content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 223 manager.Observe(content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 210 content::Source<AccessibilityHighlightManagerTest>(this), | 224 content::Source<AccessibilityHighlightManagerTest>(this), |
| 211 content::Details<content::FocusedNodeDetails>(&details)); | 225 content::Details<content::FocusedNodeDetails>(&details)); |
| 212 CaptureAfterImage(capture_bounds); | 226 CaptureAfterImage(capture_bounds); |
| 213 ComputeImageStats(); | 227 ComputeImageStats(); |
| 214 | 228 |
| 215 // This is a smoke test to assert that something is drawn in the right | 229 // 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. | 230 // part of the screen of approximately the right size and color. |
| 217 // There's deliberately some tolerance for tiny errors. | 231 // There's deliberately some tolerance for tiny errors. |
| 218 EXPECT_NEAR(1608, diff_count(), 50); | 232 EXPECT_NEAR(1608, diff_count(), 50); |
| 219 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5); | 233 EXPECT_NEAR(255, SkColorGetR(average_diff_color()), 5); |
| 220 EXPECT_NEAR(201, SkColorGetG(average_diff_color()), 5); | 234 EXPECT_NEAR(201, SkColorGetG(average_diff_color()), 5); |
| 221 EXPECT_NEAR(152, SkColorGetB(average_diff_color()), 5); | 235 EXPECT_NEAR(152, SkColorGetB(average_diff_color()), 5); |
| 222 } | 236 } |
| 223 | 237 |
| 224 } // namespace chromeos | 238 } // namespace chromeos |
| OLD | NEW |