| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/ui/accessibility_focus_ring_controller.h" |
| 5 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 6 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 7 #include "chrome/browser/chromeos/accessibility/accessibility_highlight_manager.
h" | 8 #include "chrome/browser/chromeos/accessibility/accessibility_highlight_manager.
h" |
| 8 #include "chrome/browser/chromeos/ui/accessibility_cursor_ring_layer.h" | 9 #include "chrome/browser/chromeos/ui/accessibility_cursor_ring_layer.h" |
| 9 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/base/ime/dummy_text_input_client.h" |
| 11 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 12 #include "ui/events/event_utils.h" | 13 #include "ui/events/event_utils.h" |
| 14 #include "ui/wm/public/activation_client.h" |
| 13 | 15 |
| 14 namespace chromeos { | 16 namespace chromeos { |
| 15 | 17 |
| 16 class TestableAccessibilityFocusRingController | 18 class TestableAccessibilityFocusRingController |
| 17 : public AccessibilityFocusRingController { | 19 : public AccessibilityFocusRingController { |
| 18 public: | 20 public: |
| 19 TestableAccessibilityFocusRingController() { | 21 TestableAccessibilityFocusRingController() { |
| 20 // By default use an easy round number for testing. | 22 // By default use an easy round number for testing. |
| 21 margin_ = 10; | 23 margin_ = 10; |
| 22 } | 24 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 highlight_manager.OnMouseEvent(&event1); | 165 highlight_manager.OnMouseEvent(&event1); |
| 164 | 166 |
| 165 cursor_layer = controller->cursor_layer_.get(); | 167 cursor_layer = controller->cursor_layer_.get(); |
| 166 EXPECT_EQ(root_windows[1], cursor_layer->root_window()); | 168 EXPECT_EQ(root_windows[1], cursor_layer->root_window()); |
| 167 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().x() - location.x()), | 169 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().x() - location.x()), |
| 168 50); | 170 50); |
| 169 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().y() - location.y()), | 171 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().y() - location.y()), |
| 170 50); | 172 50); |
| 171 } | 173 } |
| 172 | 174 |
| 175 class MockTextInputClient : public ui::DummyTextInputClient { |
| 176 public: |
| 177 MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {} |
| 178 |
| 179 void SetCaretBounds(gfx::Rect& caret_bounds) { caret_bounds_ = caret_bounds; } |
| 180 |
| 181 private: |
| 182 gfx::Rect GetCaretBounds() const override { return caret_bounds_; } |
| 183 gfx::Rect caret_bounds_; |
| 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(MockTextInputClient); |
| 186 }; |
| 187 |
| 188 TEST_F(AccessibilityFocusRingControllerTest, CaretRingDrawnOnlyWithinBounds) { |
| 189 // Given caret bounds that are not within the active window, expect that |
| 190 // the caret ring highlight is not drawn. |
| 191 UpdateDisplay("400x400"); |
| 192 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 193 gfx::Rect window_bounds(5, 5, 300, 300); |
| 194 root_window->SetBounds(window_bounds); |
| 195 ::wm::GetActivationClient(root_window)->ActivateWindow(root_window); |
| 196 |
| 197 AccessibilityHighlightManager highlight_manager; |
| 198 MockTextInputClient text_input_client; |
| 199 highlight_manager.HighlightCaret(true); |
| 200 gfx::Rect caret_bounds(10, 10, 40, 40); |
| 201 text_input_client.SetCaretBounds(caret_bounds); |
| 202 highlight_manager.OnCaretBoundsChanged(&text_input_client); |
| 203 |
| 204 AccessibilityFocusRingController* controller = |
| 205 AccessibilityFocusRingController::GetInstance(); |
| 206 AccessibilityCursorRingLayer* caret_layer = controller->caret_layer_.get(); |
| 207 EXPECT_EQ(root_window, caret_layer->root_window()); |
| 208 EXPECT_EQ(abs(caret_layer->layer()->GetTargetBounds().x() - caret_bounds.x()), |
| 209 20); |
| 210 EXPECT_EQ(abs(caret_layer->layer()->GetTargetBounds().y() - caret_bounds.y()), |
| 211 20); |
| 212 |
| 213 gfx::Rect not_visible_bounds(299, 299, 10, 10); |
| 214 text_input_client.SetCaretBounds(not_visible_bounds); |
| 215 highlight_manager.OnCaretBoundsChanged(&text_input_client); |
| 216 |
| 217 EXPECT_FALSE(controller->caret_layer_); |
| 218 } |
| 173 } // namespace chromeos | 219 } // namespace chromeos |
| OLD | NEW |