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

Side by Side Diff: ash/magnifier/partial_magnification_controller_unittest.cc

Issue 2269383002: Magnifier border is now more visible on light backgrounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/display/display_manager.h"
6 #include "ash/magnifier/magnification_controller.h"
7 #include "ash/magnifier/partial_magnification_controller.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ui/events/test/event_generator.h"
11 #include "ui/views/widget/widget.h"
12
13 namespace ash {
14
15 // Wrapper for PartialMagnificationController that exposes internal state to
16 // test functions.
17 class PartialMagnificationControllerTestApi {
18 public:
19 explicit PartialMagnificationControllerTestApi(
20 PartialMagnificationController* controller)
21 : controller_(controller) {}
22 ~PartialMagnificationControllerTestApi() {}
23
24 bool is_enabled() const { return controller_->is_enabled_; }
25 bool is_active() const { return controller_->is_active_; }
26 views::Widget* host_widget() const { return controller_->host_widget_; }
27
28 gfx::Point GetWidgetOrigin() const {
29 return host_widget()->GetWindowBoundsInScreen().origin();
30 }
31
32 private:
33 PartialMagnificationController* controller_;
34
35 DISALLOW_ASSIGN(PartialMagnificationControllerTestApi);
36 };
37
38 class PartialMagnificationControllerTest : public test::AshTestBase {
39 public:
40 PartialMagnificationControllerTest() {}
41 ~PartialMagnificationControllerTest() override {}
42
43 void SetUp() override {
44 AshTestBase::SetUp();
45 Shell::GetInstance()->display_manager()->UpdateDisplays();
46 }
47
48 protected:
49 PartialMagnificationController* GetController() const {
50 return Shell::GetInstance()->partial_magnification_controller();
51 }
52
53 PartialMagnificationControllerTestApi GetTestApi() const {
54 return PartialMagnificationControllerTestApi(
55 Shell::GetInstance()->partial_magnification_controller());
56 }
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(PartialMagnificationControllerTest);
60 };
61
62 // The magnifier should not show up immediately after being enabled.
63 TEST_F(PartialMagnificationControllerTest, InactiveByDefault) {
64 GetController()->SetEnabled(true);
65 EXPECT_FALSE(GetTestApi().is_active());
66 EXPECT_FALSE(GetTestApi().host_widget());
67 }
68
69 // The magnifier should show up only after a pointer is pressed while enabled.
70 TEST_F(PartialMagnificationControllerTest, ActiveOnPointerDown) {
71 GetEventGenerator().EnterPenPointerMode();
72
73 // While disabled no magnifier shows up.
74 GetEventGenerator().PressLeftButton();
75 EXPECT_FALSE(GetTestApi().is_active());
76 EXPECT_FALSE(GetTestApi().host_widget());
77 GetEventGenerator().ReleaseLeftButton();
78
79 // While enabled the magnifier is only active while the pointer is down.
80 GetController()->SetEnabled(true);
81 GetEventGenerator().PressLeftButton();
82 EXPECT_TRUE(GetTestApi().is_active());
83 EXPECT_TRUE(GetTestApi().host_widget());
84 GetEventGenerator().ReleaseLeftButton();
85 EXPECT_FALSE(GetTestApi().is_active());
86 EXPECT_FALSE(GetTestApi().host_widget());
87 }
88
89 // Verifies that nothing bad happens if a second display is disconnected while
90 // the magnifier is active.
91 TEST_F(PartialMagnificationControllerTest, MultipleDisplays) {
92 if (!SupportsMultipleDisplays())
93 return;
94 GetEventGenerator().EnterPenPointerMode();
95
96 // Active magnifier with two displays, move it to the second display.
97 UpdateDisplay("800x600,800x600");
98 GetController()->SetEnabled(true);
99 GetEventGenerator().PressLeftButton();
100 GetEventGenerator().MoveMouseTo(gfx::Point(1200, 300));
101 EXPECT_TRUE(GetTestApi().is_active());
102 EXPECT_TRUE(GetTestApi().host_widget());
103
104 // Disconnect the second display, verify that magnifier is still active.
105 UpdateDisplay("800x600");
106 GetController()->SwitchTargetRootWindowIfNeeded(nullptr);
107 EXPECT_TRUE(GetTestApi().is_active());
108 EXPECT_TRUE(GetTestApi().host_widget());
109 }
110
111 // Turning the magnifier off while it is active destroys the window.
112 TEST_F(PartialMagnificationControllerTest, DisablingDisablesActive) {
113 GetEventGenerator().EnterPenPointerMode();
114
115 GetController()->SetEnabled(true);
116 GetEventGenerator().PressLeftButton();
117 EXPECT_TRUE(GetTestApi().is_active());
118
119 GetController()->SetEnabled(false);
120 EXPECT_FALSE(GetTestApi().is_active());
121 EXPECT_FALSE(GetTestApi().host_widget());
122 }
123
124 // The magnifier only activates for pointer events.
125 TEST_F(PartialMagnificationControllerTest, ActivatesOnlyForPointer) {
126 GetController()->SetEnabled(true);
127 GetEventGenerator().PressRightButton();
128 GetEventGenerator().PressTouch();
129 EXPECT_FALSE(GetTestApi().is_active());
130 }
131
132 // The magnifier is always located at pointer.
133 TEST_F(PartialMagnificationControllerTest, MagnifierFollowsPointer) {
134 GetEventGenerator().EnterPenPointerMode();
135 GetController()->SetEnabled(true);
136
137 // The window does not have to be centered on the press; compute the initial
138 // window placement offset. Use a Vector2d for the + operator overload.
139 GetEventGenerator().PressLeftButton();
140 gfx::Vector2d offset(GetTestApi().GetWidgetOrigin().x(),
141 GetTestApi().GetWidgetOrigin().y());
142
143 // Move the pointer around, make sure the window follows it.
144 GetEventGenerator().MoveMouseTo(gfx::Point(32, 32));
145 EXPECT_EQ(GetEventGenerator().current_location() + offset,
146 GetTestApi().GetWidgetOrigin());
147
148 GetEventGenerator().MoveMouseTo(gfx::Point(0, 10));
149 EXPECT_EQ(GetEventGenerator().current_location() + offset,
150 GetTestApi().GetWidgetOrigin());
151
152 GetEventGenerator().MoveMouseTo(gfx::Point(10, 0));
153 EXPECT_EQ(GetEventGenerator().current_location() + offset,
154 GetTestApi().GetWidgetOrigin());
155
156 GetEventGenerator().ReleaseLeftButton();
157
158 // Make sure the window is initially placed correctly.
159 GetEventGenerator().set_current_location(gfx::Point(50, 20));
160 EXPECT_FALSE(GetTestApi().is_active());
161 GetEventGenerator().PressLeftButton();
162 EXPECT_EQ(GetEventGenerator().current_location() + offset,
163 GetTestApi().GetWidgetOrigin());
164 }
165
166 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698