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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 132123004: Target touches to the correct display. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/aura/test/aura_test_helper.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 "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 2151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 windows[i] = CreateTestWindowWithDelegate( 2162 windows[i] = CreateTestWindowWithDelegate(
2163 delegates[i], i, window_bounds[i], root_window()); 2163 delegates[i], i, window_bounds[i], root_window());
2164 windows[i]->set_id(i); 2164 windows[i]->set_id(i);
2165 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(), 2165 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(),
2166 i, tes.Now()); 2166 i, tes.Now());
2167 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 2167 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press);
2168 } 2168 }
2169 2169
2170 // Touches should now be associated with the closest touch within 2170 // Touches should now be associated with the closest touch within
2171 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels 2171 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels
2172 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); 2172 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11), -1);
2173 EXPECT_EQ("0", WindowIDAsString(target)); 2173 EXPECT_EQ("0", WindowIDAsString(target));
2174 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); 2174 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11), -1);
2175 EXPECT_EQ("1", WindowIDAsString(target)); 2175 EXPECT_EQ("1", WindowIDAsString(target));
2176 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); 2176 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511), -1);
2177 EXPECT_EQ("2", WindowIDAsString(target)); 2177 EXPECT_EQ("2", WindowIDAsString(target));
2178 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); 2178 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511), -1);
2179 EXPECT_EQ("3", WindowIDAsString(target)); 2179 EXPECT_EQ("3", WindowIDAsString(target));
2180 2180
2181 // Add a touch in the middle associated with windows[2] 2181 // Add a touch in the middle associated with windows[2]
2182 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), 2182 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500),
2183 kNumWindows, tes.Now()); 2183 kNumWindows, tes.Now());
2184 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 2184 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press);
2185 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), 2185 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250),
2186 kNumWindows, tes.Now()); 2186 kNumWindows, tes.Now());
2187 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move); 2187 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move);
2188 2188
2189 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); 2189 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250), -1);
2190 EXPECT_EQ("2", WindowIDAsString(target)); 2190 EXPECT_EQ("2", WindowIDAsString(target));
2191 2191
2192 // Make sure that ties are broken by distance to a current touch 2192 // Make sure that ties are broken by distance to a current touch
2193 // Closer to the point in the bottom right. 2193 // Closer to the point in the bottom right.
2194 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); 2194 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380), -1);
2195 EXPECT_EQ("3", WindowIDAsString(target)); 2195 EXPECT_EQ("3", WindowIDAsString(target));
2196 2196
2197 // This touch is closer to the point in the middle 2197 // This touch is closer to the point in the middle
2198 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); 2198 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300), -1);
2199 EXPECT_EQ("2", WindowIDAsString(target)); 2199 EXPECT_EQ("2", WindowIDAsString(target));
2200 2200
2201 // A touch too far from other touches won't be locked to anything 2201 // A touch too far from other touches won't be locked to anything
2202 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 2202 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2203 EXPECT_TRUE(target == NULL); 2203 EXPECT_TRUE(target == NULL);
2204 2204
2205 // Move a touch associated with windows[2] to 1000, 1000 2205 // Move a touch associated with windows[2] to 1000, 1000
2206 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), 2206 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000),
2207 kNumWindows, tes.Now()); 2207 kNumWindows, tes.Now());
2208 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move2); 2208 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move2);
2209 2209
2210 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 2210 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000), -1);
2211 EXPECT_EQ("2", WindowIDAsString(target)); 2211 EXPECT_EQ("2", WindowIDAsString(target));
2212 2212
2213 for (int i = 0; i < kNumWindows; ++i) { 2213 for (int i = 0; i < kNumWindows; ++i) {
2214 // Delete windows before deleting delegates. 2214 // Delete windows before deleting delegates.
2215 delete windows[i]; 2215 delete windows[i];
2216 delete delegates[i]; 2216 delete delegates[i];
2217 } 2217 }
2218 } 2218 }
2219 2219
2220 // Check that a touch's target will not be effected by a touch on a different
2221 // screen.
2222 TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) {
2223 scoped_ptr<GestureEventConsumeDelegate> delegate(
2224 new GestureEventConsumeDelegate());
2225 gfx::Rect bounds(0, 0, 10, 10);
2226 scoped_ptr<aura::Window> window(
2227 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window()));
2228
2229 const int kTouchId1 = 8;
2230 const int kTouchId2 = 2;
2231 TimedEvents tes;
2232
2233 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(5, 5),
2234 kTouchId1, tes.Now());
2235 press1.set_source_device_id(1);
2236 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press1);
2237
2238 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2239 kTouchId2, tes.Now());
2240 press2.set_source_device_id(2);
2241 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press2);
2242
2243 // The second press should not have been locked to the same target as the
2244 // first, as they occured on different displays.
2245 EXPECT_NE(
2246 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1),
2247 ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
2248 }
2249
2220 // Check that touch events outside the root window are still handled 2250 // Check that touch events outside the root window are still handled
2221 // by the root window's gesture sequence. 2251 // by the root window's gesture sequence.
2222 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 2252 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
2223 TestGestureRecognizer* gesture_recognizer = 2253 TestGestureRecognizer* gesture_recognizer =
2224 new TestGestureRecognizer(); 2254 new TestGestureRecognizer();
2225 TimedEvents tes; 2255 TimedEvents tes;
2226 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2256 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2227 2257
2228 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 2258 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
2229 gfx::Rect(-100, -100, 2000, 2000), root_window())); 2259 gfx::Rect(-100, -100, 2000, 2000), root_window()));
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
3706 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3736 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
3707 kTouchId, tes.LeapForward(50)); 3737 kTouchId, tes.LeapForward(50));
3708 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release1); 3738 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release1);
3709 EXPECT_TRUE(delegate->show_press()); 3739 EXPECT_TRUE(delegate->show_press());
3710 EXPECT_FALSE(delegate->tap_cancel()); 3740 EXPECT_FALSE(delegate->tap_cancel());
3711 EXPECT_TRUE(delegate->tap()); 3741 EXPECT_TRUE(delegate->tap());
3712 } 3742 }
3713 3743
3714 } // namespace test 3744 } // namespace test
3715 } // namespace aura 3745 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/aura/test/aura_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698