| OLD | NEW |
| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 2137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 windows[i] = CreateTestWindowWithDelegate( | 2148 windows[i] = CreateTestWindowWithDelegate( |
| 2149 delegates[i], i, window_bounds[i], root_window()); | 2149 delegates[i], i, window_bounds[i], root_window()); |
| 2150 windows[i]->set_id(i); | 2150 windows[i]->set_id(i); |
| 2151 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(), | 2151 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(), |
| 2152 i, tes.Now()); | 2152 i, tes.Now()); |
| 2153 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 2153 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
| 2154 } | 2154 } |
| 2155 | 2155 |
| 2156 // Touches should now be associated with the closest touch within | 2156 // Touches should now be associated with the closest touch within |
| 2157 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels | 2157 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels |
| 2158 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); | 2158 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11), -1); |
| 2159 EXPECT_EQ("0", WindowIDAsString(target)); | 2159 EXPECT_EQ("0", WindowIDAsString(target)); |
| 2160 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); | 2160 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11), -1); |
| 2161 EXPECT_EQ("1", WindowIDAsString(target)); | 2161 EXPECT_EQ("1", WindowIDAsString(target)); |
| 2162 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); | 2162 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511), -1); |
| 2163 EXPECT_EQ("2", WindowIDAsString(target)); | 2163 EXPECT_EQ("2", WindowIDAsString(target)); |
| 2164 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); | 2164 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511), -1); |
| 2165 EXPECT_EQ("3", WindowIDAsString(target)); | 2165 EXPECT_EQ("3", WindowIDAsString(target)); |
| 2166 | 2166 |
| 2167 // Add a touch in the middle associated with windows[2] | 2167 // Add a touch in the middle associated with windows[2] |
| 2168 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), | 2168 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), |
| 2169 kNumWindows, tes.Now()); | 2169 kNumWindows, tes.Now()); |
| 2170 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 2170 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
| 2171 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), | 2171 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), |
| 2172 kNumWindows, tes.Now()); | 2172 kNumWindows, tes.Now()); |
| 2173 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); | 2173 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
| 2174 | 2174 |
| 2175 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); | 2175 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250), -1); |
| 2176 EXPECT_EQ("2", WindowIDAsString(target)); | 2176 EXPECT_EQ("2", WindowIDAsString(target)); |
| 2177 | 2177 |
| 2178 // Make sure that ties are broken by distance to a current touch | 2178 // Make sure that ties are broken by distance to a current touch |
| 2179 // Closer to the point in the bottom right. | 2179 // Closer to the point in the bottom right. |
| 2180 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); | 2180 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380), -1); |
| 2181 EXPECT_EQ("3", WindowIDAsString(target)); | 2181 EXPECT_EQ("3", WindowIDAsString(target)); |
| 2182 | 2182 |
| 2183 // This touch is closer to the point in the middle | 2183 // This touch is closer to the point in the middle |
| 2184 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); | 2184 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300), -1); |
| 2185 EXPECT_EQ("2", WindowIDAsString(target)); | 2185 EXPECT_EQ("2", WindowIDAsString(target)); |
| 2186 | 2186 |
| 2187 // A touch too far from other touches won't be locked to anything | 2187 // A touch too far from other touches won't be locked to anything |
| 2188 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); | 2188 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000), -1); |
| 2189 EXPECT_TRUE(target == NULL); | 2189 EXPECT_TRUE(target == NULL); |
| 2190 | 2190 |
| 2191 // Move a touch associated with windows[2] to 1000, 1000 | 2191 // Move a touch associated with windows[2] to 1000, 1000 |
| 2192 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), | 2192 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), |
| 2193 kNumWindows, tes.Now()); | 2193 kNumWindows, tes.Now()); |
| 2194 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); | 2194 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
| 2195 | 2195 |
| 2196 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); | 2196 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000), -1); |
| 2197 EXPECT_EQ("2", WindowIDAsString(target)); | 2197 EXPECT_EQ("2", WindowIDAsString(target)); |
| 2198 | 2198 |
| 2199 for (int i = 0; i < kNumWindows; ++i) { | 2199 for (int i = 0; i < kNumWindows; ++i) { |
| 2200 // Delete windows before deleting delegates. | 2200 // Delete windows before deleting delegates. |
| 2201 delete windows[i]; | 2201 delete windows[i]; |
| 2202 delete delegates[i]; | 2202 delete delegates[i]; |
| 2203 } | 2203 } |
| 2204 } | 2204 } |
| 2205 | 2205 |
| 2206 // Check that a touch's target will not be effected by a touch on a different |
| 2207 // screen. |
| 2208 TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) { |
| 2209 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 2210 new GestureEventConsumeDelegate()); |
| 2211 gfx::Rect bounds(0, 0, 10, 10); |
| 2212 scoped_ptr<aura::Window> window( |
| 2213 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); |
| 2214 |
| 2215 const int kTouchId1 = 8; |
| 2216 const int kTouchId2 = 2; |
| 2217 TimedEvents tes; |
| 2218 |
| 2219 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5), |
| 2220 kTouchId1, tes.Now()); |
| 2221 press1.set_source_device_id(1); |
| 2222 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
| 2223 |
| 2224 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), |
| 2225 kTouchId2, tes.Now()); |
| 2226 press2.set_source_device_id(2); |
| 2227 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
| 2228 |
| 2229 // The second press should not have been locked to the same target as the |
| 2230 // first, as they occured on different displays. |
| 2231 EXPECT_NE( |
| 2232 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1), |
| 2233 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)); |
| 2234 } |
| 2235 |
| 2206 // Check that touch events outside the root window are still handled | 2236 // Check that touch events outside the root window are still handled |
| 2207 // by the root window's gesture sequence. | 2237 // by the root window's gesture sequence. |
| 2208 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { | 2238 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { |
| 2209 TestGestureRecognizer* gesture_recognizer = | 2239 TestGestureRecognizer* gesture_recognizer = |
| 2210 new TestGestureRecognizer(); | 2240 new TestGestureRecognizer(); |
| 2211 TimedEvents tes; | 2241 TimedEvents tes; |
| 2212 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); | 2242 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); |
| 2213 | 2243 |
| 2214 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( | 2244 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( |
| 2215 gfx::Rect(-100, -100, 2000, 2000), root_window())); | 2245 gfx::Rect(-100, -100, 2000, 2000), root_window())); |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3691 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 3721 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
| 3692 kTouchId, tes.LeapForward(50)); | 3722 kTouchId, tes.LeapForward(50)); |
| 3693 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); | 3723 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
| 3694 EXPECT_TRUE(delegate->show_press()); | 3724 EXPECT_TRUE(delegate->show_press()); |
| 3695 EXPECT_FALSE(delegate->tap_cancel()); | 3725 EXPECT_FALSE(delegate->tap_cancel()); |
| 3696 EXPECT_TRUE(delegate->tap()); | 3726 EXPECT_TRUE(delegate->tap()); |
| 3697 } | 3727 } |
| 3698 | 3728 |
| 3699 } // namespace test | 3729 } // namespace test |
| 3700 } // namespace aura | 3730 } // namespace aura |
| OLD | NEW |