Chromium Code Reviews| 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 "ash/display/window_tree_host_manager.h" | |
| 6 #include "ash/shell.h" | |
| 7 #include "ash/test/ash_test_base.h" | |
| 8 #include "chrome/browser/chromeos/accessibility/accessibility_highlight_manager. h" | |
| 9 #include "chrome/browser/chromeos/ui/accessibility_cursor_ring_layer.h" | |
| 5 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" | 10 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/display/screen.h" | |
| 13 #include "ui/events/event.h" | |
| 14 #include "ui/events/event_utils.h" | |
| 8 | 15 |
| 9 namespace chromeos { | 16 namespace chromeos { |
| 10 | 17 |
| 11 class TestableAccessibilityFocusRingController | 18 class TestableAccessibilityFocusRingController |
| 12 : public AccessibilityFocusRingController { | 19 : public AccessibilityFocusRingController { |
| 13 public: | 20 public: |
| 14 TestableAccessibilityFocusRingController() { | 21 TestableAccessibilityFocusRingController() { |
| 15 // By default use an easy round number for testing. | 22 // By default use an easy round number for testing. |
| 16 margin_ = 10; | 23 margin_ = 10; |
| 17 } | 24 } |
| 18 ~TestableAccessibilityFocusRingController() override {} | 25 ~TestableAccessibilityFocusRingController() override {} |
| 19 | 26 |
| 20 void RectsToRings(const std::vector<gfx::Rect>& rects, | 27 void RectsToRings(const std::vector<gfx::Rect>& rects, |
| 21 std::vector<AccessibilityFocusRing>* rings) const { | 28 std::vector<AccessibilityFocusRing>* rings) const { |
| 22 AccessibilityFocusRingController::RectsToRings(rects, rings); | 29 AccessibilityFocusRingController::RectsToRings(rects, rings); |
| 23 } | 30 } |
| 24 | 31 |
| 25 int GetMargin() const override { return margin_; } | 32 int GetMargin() const override { return margin_; } |
| 26 | 33 |
| 27 private: | 34 private: |
| 28 int margin_; | 35 int margin_; |
| 29 }; | 36 }; |
| 30 | 37 |
| 31 class AccessibilityFocusRingControllerTest : public testing::Test { | 38 class AccessibilityFocusRingControllerTest : public ash::test::AshTestBase { |
| 32 public: | 39 public: |
| 33 AccessibilityFocusRingControllerTest() {} | 40 AccessibilityFocusRingControllerTest() {} |
| 34 ~AccessibilityFocusRingControllerTest() override {} | 41 ~AccessibilityFocusRingControllerTest() override {} |
| 35 | 42 |
| 36 protected: | 43 protected: |
| 37 gfx::Rect AddMargin(gfx::Rect r) { | 44 gfx::Rect AddMargin(gfx::Rect r) { |
| 38 r.Inset(-controller_.GetMargin(), -controller_.GetMargin()); | 45 r.Inset(-controller_.GetMargin(), -controller_.GetMargin()); |
| 39 return r; | 46 return r; |
| 40 } | 47 } |
| 41 | 48 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 EXPECT_EQ(gfx::Point(10, 400), points[28]); | 128 EXPECT_EQ(gfx::Point(10, 400), points[28]); |
| 122 EXPECT_EQ(gfx::Point(0, 400), points[29]); | 129 EXPECT_EQ(gfx::Point(0, 400), points[29]); |
| 123 EXPECT_EQ(gfx::Point(0, 390), points[30]); | 130 EXPECT_EQ(gfx::Point(0, 390), points[30]); |
| 124 EXPECT_EQ(gfx::Point(0, 110), points[31]); | 131 EXPECT_EQ(gfx::Point(0, 110), points[31]); |
| 125 EXPECT_EQ(gfx::Point(0, 100), points[32]); | 132 EXPECT_EQ(gfx::Point(0, 100), points[32]); |
| 126 EXPECT_EQ(gfx::Point(0, 100), points[33]); | 133 EXPECT_EQ(gfx::Point(0, 100), points[33]); |
| 127 EXPECT_EQ(gfx::Point(0, 100), points[34]); | 134 EXPECT_EQ(gfx::Point(0, 100), points[34]); |
| 128 EXPECT_EQ(gfx::Point(0, 100), points[35]); | 135 EXPECT_EQ(gfx::Point(0, 100), points[35]); |
| 129 } | 136 } |
| 130 | 137 |
| 138 TEST_F(AccessibilityFocusRingControllerTest, CursorWorksOnMultipleDisplays) { | |
| 139 if (!SupportsMultipleDisplays()) | |
| 140 return; | |
| 141 UpdateDisplay("400x400,500x500"); | |
| 142 std::vector<display::Display> displays = | |
| 143 display::Screen::GetScreen()->GetAllDisplays(); | |
| 144 ASSERT_EQ(2u, displays.size()); | |
| 145 auto* manager = ash::Shell::GetInstance()->window_tree_host_manager(); | |
| 146 aura::Window* root_window0 = | |
| 147 manager->GetRootWindowForDisplayId(displays[0].id()); | |
| 148 aura::Window* root_window1 = | |
| 149 manager->GetRootWindowForDisplayId(displays[1].id()); | |
|
oshima
2016/10/19 21:13:51
you can use Shell::GetAllRootWindows()
dmazzoni
2016/10/19 22:36:49
Thanks, that's simpler.
| |
| 150 LOG(ERROR) << root_window0; | |
| 151 LOG(ERROR) << root_window1; | |
|
oshima
2016/10/19 21:13:51
nit: remove debug logs.
dmazzoni
2016/10/19 22:36:49
Done.
| |
| 152 | |
| 153 AccessibilityHighlightManager highlight_manager; | |
| 154 highlight_manager.HighlightCursor(true); | |
| 155 gfx::Point location(90, 90); | |
| 156 std::unique_ptr<ui::MouseEvent> event(new ui::MouseEvent( | |
| 157 ui::ET_MOUSE_MOVED, location, location, ui::EventTimeForNow(), 0, 0)); | |
|
oshima
2016/10/19 21:13:51
you can just create a instance on a stack.
dmazzoni
2016/10/19 22:36:49
Done.
| |
| 158 ui::Event::DispatcherApi event_mod(event.get()); | |
| 159 event_mod.set_target(root_window0); | |
| 160 highlight_manager.OnMouseEvent(event.get()); | |
| 161 | |
| 162 AccessibilityFocusRingController* controller = | |
| 163 AccessibilityFocusRingController::GetInstance(); | |
| 164 AccessibilityCursorRingLayer* cursor_layer = controller->cursor_layer_.get(); | |
| 165 EXPECT_EQ(root_window0, cursor_layer->root_window()); | |
| 166 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().x() - location.x()), | |
| 167 50); | |
| 168 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().y() - location.y()), | |
| 169 50); | |
| 170 | |
| 171 std::unique_ptr<ui::MouseEvent> event1(new ui::MouseEvent( | |
| 172 ui::ET_MOUSE_MOVED, location, location, ui::EventTimeForNow(), 0, 0)); | |
| 173 ui::Event::DispatcherApi event_mod1(event.get()); | |
| 174 event_mod1.set_target(root_window1); | |
| 175 highlight_manager.OnMouseEvent(event.get()); | |
| 176 | |
| 177 cursor_layer = controller->cursor_layer_.get(); | |
| 178 EXPECT_EQ(root_window1, cursor_layer->root_window()); | |
| 179 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().x() - location.x()), | |
| 180 50); | |
| 181 EXPECT_LT(abs(cursor_layer->layer()->GetTargetBounds().y() - location.y()), | |
| 182 50); | |
| 183 } | |
| 184 | |
| 131 } // namespace chromeos | 185 } // namespace chromeos |
| OLD | NEW |