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

Side by Side Diff: ash/display/display_controller_unittest.cc

Issue 13594009: Correct scale for touch radius & scroll offset ordinal (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: tests added Created 7 years, 8 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 | ui/aura/test/event_generator.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/display_controller.h" 5 #include "ash/display/display_controller.h"
6 6
7 #include "ash/display/display_info.h" 7 #include "ash/display/display_info.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/launcher/launcher.h" 9 #include "ash/launcher/launcher.h"
10 #include "ash/screen_ash.h" 10 #include "ash/screen_ash.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 test::AshTestBase::TearDown(); 91 test::AshTestBase::TearDown();
92 // Make sure that primary display is accessible after shutdown. 92 // Make sure that primary display is accessible after shutdown.
93 gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay(); 93 gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay();
94 EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); 94 EXPECT_EQ("0,0 444x333", primary.bounds().ToString());
95 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 95 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
96 } 96 }
97 }; 97 };
98 98
99 class TestEventHandler : public ui::EventHandler { 99 class TestEventHandler : public ui::EventHandler {
100 public: 100 public:
101 TestEventHandler() : target_root_(NULL) {} 101 TestEventHandler() : target_root_(NULL),
102 touch_radius_x_(0.0),
103 touch_radius_y_(0.0),
104 scroll_x_offset_(0.0),
105 scroll_y_offset_(0.0),
106 scroll_x_offset_ordinal_(0.0),
107 scroll_y_offset_ordinal_(0.0) {}
102 virtual ~TestEventHandler() {} 108 virtual ~TestEventHandler() {}
103 109
104 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 110 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
105 aura::Window* target = static_cast<aura::Window*>(event->target()); 111 aura::Window* target = static_cast<aura::Window*>(event->target());
106 // Only record when the target is the background which covers 112 // Only record when the target is the background which covers
107 // entire root window. 113 // entire root window.
108 if (target->name() != "DesktopBackgroundView") 114 if (target->name() != "DesktopBackgroundView")
109 return; 115 return;
110 mouse_location_ = event->location(); 116 mouse_location_ = event->location();
111 target_root_ = target->GetRootWindow(); 117 target_root_ = target->GetRootWindow();
112 event->StopPropagation(); 118 event->StopPropagation();
113 } 119 }
114 120
121 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
122 aura::Window* target = static_cast<aura::Window*>(event->target());
123 // Only record when the target is the background which covers
124 // entire root window.
125 if (target->name() != "DesktopBackgroundView")
oshima 2013/04/04 17:57:08 since this is now used in 3 places, can you define
Yufeng Shen (Slow to review) 2013/04/04 18:13:12 Done.
126 return;
127 touch_radius_x_ = event->radius_x();
128 touch_radius_y_ = event->radius_y();
129 event->StopPropagation();
130 }
131
132 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE {
133 aura::Window* target = static_cast<aura::Window*>(event->target());
134 // Only record when the target is the background which covers
135 // entire root window.
136 if (target->name() != "DesktopBackgroundView")
137 return;
138
139 if (event->type() == ui::ET_SCROLL) {
140 scroll_x_offset_ = event->x_offset();
141 scroll_y_offset_ = event->y_offset();
142 scroll_x_offset_ordinal_ = event->x_offset_ordinal();
143 scroll_y_offset_ordinal_ = event->y_offset_ordinal();
144 }
145 event->StopPropagation();
146 }
147
115 std::string GetLocationAndReset() { 148 std::string GetLocationAndReset() {
116 std::string result = mouse_location_.ToString(); 149 std::string result = mouse_location_.ToString();
117 mouse_location_.SetPoint(0, 0); 150 mouse_location_.SetPoint(0, 0);
118 target_root_ = NULL; 151 target_root_ = NULL;
119 return result; 152 return result;
120 } 153 }
121 154
155 float touch_radius_x() { return touch_radius_x_; }
156 float touch_radius_y() { return touch_radius_y_; }
157 float scroll_x_offset() { return scroll_x_offset_; }
158 float scroll_y_offset() { return scroll_y_offset_; }
159 float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; }
160 float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; }
161
122 private: 162 private:
123 gfx::Point mouse_location_; 163 gfx::Point mouse_location_;
124 aura::RootWindow* target_root_; 164 aura::RootWindow* target_root_;
125 165
166 float touch_radius_x_;
167 float touch_radius_y_;
168 float scroll_x_offset_;
169 float scroll_y_offset_;
170 float scroll_x_offset_ordinal_;
171 float scroll_y_offset_ordinal_;
172
126 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 173 DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
127 }; 174 };
128 175
129 gfx::Display::Rotation GetStoredRotation(int64 id) { 176 gfx::Display::Rotation GetStoredRotation(int64 id) {
130 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); 177 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation();
131 } 178 }
132 179
133 float GetStoredUIScale(int64 id) { 180 float GetStoredUIScale(int64 id) {
134 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); 181 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale();
135 } 182 }
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 display2 = ScreenAsh::GetSecondaryDisplay(); 831 display2 = ScreenAsh::GetSecondaryDisplay();
785 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); 832 EXPECT_EQ("0,0 375x250", display1.bounds().ToString());
786 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); 833 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString());
787 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); 834 EXPECT_EQ("375,0 500x300", display2.bounds().ToString());
788 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); 835 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id()));
789 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 836 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
790 837
791 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 838 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
792 } 839 }
793 840
841
842 #if defined(OS_WIN)
843 // On Win8 bots, the host window can't be resized and
844 // SetTransform updates the window using the orignal host window
845 // size.
846 #define MAYBE_TouchScale DISABLED_TouchScale
847 #else
848 #define MAYBE_TouchScale TouchScale
849 #endif
850
851 TEST_F(DisplayControllerTest, MAYBE_TouchScale) {
852 TestEventHandler event_handler;
853 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
854
855 UpdateDisplay("200x200*2");
856 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
857 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
858 aura::RootWindow* root_window = root_windows[0];
859 aura::test::EventGenerator generator(root_window);
860
861 generator.PressMoveAndReleaseTouchTo(50, 50);
862 // Default test touches have radius_x/y = 1.0, with device scale
863 // factor = 2, the scaled radius_x/y should be 0.5.
864 EXPECT_EQ(0.5, event_handler.touch_radius_x());
865 EXPECT_EQ(0.5, event_handler.touch_radius_y());
866
867 generator.ScrollSequence(gfx::Point(0,0),
868 base::TimeDelta::FromMilliseconds(100),
869 10.0, 1.0, 5, 1);
870
871 // With device scale factor = 2, ordinal_offset * 2 = offset.
872 EXPECT_EQ(event_handler.scroll_x_offset(),
873 event_handler.scroll_x_offset_ordinal() * 2);
874 EXPECT_EQ(event_handler.scroll_y_offset(),
875 event_handler.scroll_y_offset_ordinal() * 2);
876
877 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
878 }
879
794 } // namespace test 880 } // namespace test
795 } // namespace ash 881 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/aura/test/event_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698