Index: ash/display/display_controller_unittest.cc |
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc |
index 815528713ce08f24c0f9cb96e6ce1822995f6d1b..7811a9682abae952c2db6b506f68eae19f7ca4c8 100644 |
--- a/ash/display/display_controller_unittest.cc |
+++ b/ash/display/display_controller_unittest.cc |
@@ -98,7 +98,13 @@ class DisplayControllerShutdownTest : public test::AshTestBase { |
class TestEventHandler : public ui::EventHandler { |
public: |
- TestEventHandler() : target_root_(NULL) {} |
+ TestEventHandler() : target_root_(NULL), |
+ touch_radius_x_(0.0), |
+ touch_radius_y_(0.0), |
+ scroll_x_offset_(0.0), |
+ scroll_y_offset_(0.0), |
+ scroll_x_offset_ordinal_(0.0), |
+ scroll_y_offset_ordinal_(0.0) {} |
virtual ~TestEventHandler() {} |
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
@@ -112,6 +118,33 @@ class TestEventHandler : public ui::EventHandler { |
event->StopPropagation(); |
} |
+ virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
+ aura::Window* target = static_cast<aura::Window*>(event->target()); |
+ // Only record when the target is the background which covers |
+ // entire root window. |
+ 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.
|
+ return; |
+ touch_radius_x_ = event->radius_x(); |
+ touch_radius_y_ = event->radius_y(); |
+ event->StopPropagation(); |
+ } |
+ |
+ virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { |
+ aura::Window* target = static_cast<aura::Window*>(event->target()); |
+ // Only record when the target is the background which covers |
+ // entire root window. |
+ if (target->name() != "DesktopBackgroundView") |
+ return; |
+ |
+ if (event->type() == ui::ET_SCROLL) { |
+ scroll_x_offset_ = event->x_offset(); |
+ scroll_y_offset_ = event->y_offset(); |
+ scroll_x_offset_ordinal_ = event->x_offset_ordinal(); |
+ scroll_y_offset_ordinal_ = event->y_offset_ordinal(); |
+ } |
+ event->StopPropagation(); |
+ } |
+ |
std::string GetLocationAndReset() { |
std::string result = mouse_location_.ToString(); |
mouse_location_.SetPoint(0, 0); |
@@ -119,10 +152,24 @@ class TestEventHandler : public ui::EventHandler { |
return result; |
} |
+ float touch_radius_x() { return touch_radius_x_; } |
+ float touch_radius_y() { return touch_radius_y_; } |
+ float scroll_x_offset() { return scroll_x_offset_; } |
+ float scroll_y_offset() { return scroll_y_offset_; } |
+ float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; } |
+ float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; } |
+ |
private: |
gfx::Point mouse_location_; |
aura::RootWindow* target_root_; |
+ float touch_radius_x_; |
+ float touch_radius_y_; |
+ float scroll_x_offset_; |
+ float scroll_y_offset_; |
+ float scroll_x_offset_ordinal_; |
+ float scroll_y_offset_ordinal_; |
+ |
DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
}; |
@@ -791,5 +838,44 @@ TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { |
Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
} |
+ |
+#if defined(OS_WIN) |
+// On Win8 bots, the host window can't be resized and |
+// SetTransform updates the window using the orignal host window |
+// size. |
+#define MAYBE_TouchScale DISABLED_TouchScale |
+#else |
+#define MAYBE_TouchScale TouchScale |
+#endif |
+ |
+TEST_F(DisplayControllerTest, MAYBE_TouchScale) { |
+ TestEventHandler event_handler; |
+ Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
+ |
+ UpdateDisplay("200x200*2"); |
+ gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); |
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
+ aura::RootWindow* root_window = root_windows[0]; |
+ aura::test::EventGenerator generator(root_window); |
+ |
+ generator.PressMoveAndReleaseTouchTo(50, 50); |
+ // Default test touches have radius_x/y = 1.0, with device scale |
+ // factor = 2, the scaled radius_x/y should be 0.5. |
+ EXPECT_EQ(0.5, event_handler.touch_radius_x()); |
+ EXPECT_EQ(0.5, event_handler.touch_radius_y()); |
+ |
+ generator.ScrollSequence(gfx::Point(0,0), |
+ base::TimeDelta::FromMilliseconds(100), |
+ 10.0, 1.0, 5, 1); |
+ |
+ // With device scale factor = 2, ordinal_offset * 2 = offset. |
+ EXPECT_EQ(event_handler.scroll_x_offset(), |
+ event_handler.scroll_x_offset_ordinal() * 2); |
+ EXPECT_EQ(event_handler.scroll_y_offset(), |
+ event_handler.scroll_y_offset_ordinal() * 2); |
+ |
+ Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
+} |
+ |
} // namespace test |
} // namespace ash |