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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller_client_aura_browsertest.cc

Issue 1740193002: Fix the coordinates for touch selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | content/browser/renderer_host/render_widget_host_view_aura.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" 5 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h"
6 6
7 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 11 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
11 #include "content/browser/web_contents/web_contents_impl.h" 12 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h" 15 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h" 16 #include "content/shell/browser/shell.h"
16 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
17 #include "ui/aura/window_tree_host.h" 18 #include "ui/aura/window_tree_host.h"
18 #include "ui/events/event_utils.h" 19 #include "ui/events/event_utils.h"
19 #include "ui/events/test/event_generator.h" 20 #include "ui/events/test/event_generator.h"
21 #include "ui/gfx/switches.h"
20 #include "ui/touch_selection/touch_selection_controller_test_api.h" 22 #include "ui/touch_selection/touch_selection_controller_test_api.h"
21 23
22 namespace content { 24 namespace content {
23 namespace { 25 namespace {
24 26
25 bool JSONToPoint(const std::string& str, gfx::PointF* point) { 27 bool JSONToPoint(const std::string& str, gfx::PointF* point) {
26 scoped_ptr<base::Value> value = base::JSONReader::Read(str); 28 scoped_ptr<base::Value> value = base::JSONReader::Read(str);
27 if (!value) 29 if (!value)
28 return false; 30 return false;
29 base::DictionaryValue* root; 31 base::DictionaryValue* root;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return JSONToPoint(str, point); 148 return JSONToPoint(str, point);
147 } 149 }
148 return false; 150 return false;
149 } 151 }
150 152
151 bool EmptyTextfield() { 153 bool EmptyTextfield() {
152 return ExecuteScript(shell()->web_contents()->GetMainFrame(), 154 return ExecuteScript(shell()->web_contents()->GetMainFrame(),
153 "empty_textfield()"); 155 "empty_textfield()");
154 } 156 }
155 157
158 RenderWidgetHostViewAura* GetRenderWidgetHostViewAura() {
159 return static_cast<RenderWidgetHostViewAura*>(
160 shell()->web_contents()->GetRenderWidgetHostView());
161 }
162
163 TestTouchSelectionControllerClientAura* selection_controller_client() {
164 return selection_controller_client_;
165 }
166
167 void InitSelectionController() {
168 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
169 selection_controller_client_ =
170 new TestTouchSelectionControllerClientAura(rwhva);
171 rwhva->SetSelectionControllerClientForTest(
172 make_scoped_ptr(selection_controller_client_));
173 }
174
156 private: 175 private:
157 void SetUpOnMainThread() override { 176 void SetUpOnMainThread() override {
158 ContentBrowserTest::SetUpOnMainThread(); 177 ContentBrowserTest::SetUpOnMainThread();
159 if (!ui::TouchSelectionMenuRunner::GetInstance()) 178 if (!ui::TouchSelectionMenuRunner::GetInstance())
160 menu_runner_.reset(new TestTouchSelectionMenuRunner); 179 menu_runner_.reset(new TestTouchSelectionMenuRunner);
161 } 180 }
162 181
163 void TearDownOnMainThread() override { 182 void TearDownOnMainThread() override {
164 menu_runner_ = nullptr; 183 menu_runner_ = nullptr;
184 selection_controller_client_ = nullptr;
165 ContentBrowserTest::TearDownOnMainThread(); 185 ContentBrowserTest::TearDownOnMainThread();
166 } 186 }
167 187
168 scoped_ptr<TestTouchSelectionMenuRunner> menu_runner_; 188 scoped_ptr<TestTouchSelectionMenuRunner> menu_runner_;
169 189
190 TestTouchSelectionControllerClientAura* selection_controller_client_ =
191 nullptr;
192
170 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAuraTest); 193 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAuraTest);
171 }; 194 };
172 195
173 // Tests that long-pressing on a text brings up selection handles and the quick 196 // Tests that long-pressing on a text brings up selection handles and the quick
174 // menu properly. 197 // menu properly.
175 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, BasicSelection) { 198 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, BasicSelection) {
176 // Set the test page up. 199 // Set the test page up.
177 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 200 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
178 WebContents* web_contents = 201 InitSelectionController();
179 static_cast<WebContentsImpl*>(shell()->web_contents());
180 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
181 web_contents->GetRenderWidgetHostView());
182 TestTouchSelectionControllerClientAura* selection_controller_client =
183 new TestTouchSelectionControllerClientAura(rwhva);
184 rwhva->SetSelectionControllerClientForTest(
185 make_scoped_ptr(selection_controller_client));
186 202
203 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
187 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 204 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
188 rwhva->selection_controller()->active_status()); 205 rwhva->selection_controller()->active_status());
189 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 206 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
190 207
191 // Long-press on the text and wait for handles to appear. 208 // Long-press on the text and wait for handles to appear.
192 selection_controller_client->InitWaitForSelectionEvent( 209 selection_controller_client()->InitWaitForSelectionEvent(
193 ui::SELECTION_HANDLES_SHOWN); 210 ui::SELECTION_HANDLES_SHOWN);
194 211
195 gfx::PointF point; 212 gfx::PointF point;
196 ASSERT_TRUE(GetPointInsideText(&point)); 213 ASSERT_TRUE(GetPointInsideText(&point));
197 ui::GestureEvent long_press( 214 ui::GestureEvent long_press(
198 point.x(), point.y(), 0, ui::EventTimeForNow(), 215 point.x(), point.y(), 0, ui::EventTimeForNow(),
199 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 216 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
200 rwhva->OnGestureEvent(&long_press); 217 rwhva->OnGestureEvent(&long_press);
201 218
202 selection_controller_client->Wait(); 219 selection_controller_client()->Wait();
203 220
204 // Check that selection is active and the quick menu is showing. 221 // Check that selection is active and the quick menu is showing.
205 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 222 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
206 rwhva->selection_controller()->active_status()); 223 rwhva->selection_controller()->active_status());
207 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 224 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
208 } 225 }
209 226
210 // Tests that tapping in a textfield brings up the insertion handle, but not the 227 // Tests that tapping in a textfield brings up the insertion handle, but not the
211 // quick menu, initially. Then, successive taps on the insertion handle toggle 228 // quick menu, initially. Then, successive taps on the insertion handle toggle
212 // the quick menu visibility. 229 // the quick menu visibility.
213 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, 230 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
214 BasicInsertionFollowedByTapsOnHandle) { 231 BasicInsertionFollowedByTapsOnHandle) {
215 // Set the test page up. 232 // Set the test page up.
216 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 233 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
217 WebContents* web_contents = 234 InitSelectionController();
218 static_cast<WebContentsImpl*>(shell()->web_contents());
219 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
220 web_contents->GetRenderWidgetHostView());
221 TestTouchSelectionControllerClientAura* selection_controller_client =
222 new TestTouchSelectionControllerClientAura(rwhva);
223 rwhva->SetSelectionControllerClientForTest(
224 make_scoped_ptr(selection_controller_client));
225 235
236 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
226 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 237 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
227 rwhva->selection_controller()->active_status()); 238 rwhva->selection_controller()->active_status());
228 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 239 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
229 240
230 ui::test::EventGeneratorDelegate* generator_delegate = 241 ui::test::EventGeneratorDelegate* generator_delegate =
231 ui::test::EventGenerator::default_delegate; 242 ui::test::EventGenerator::default_delegate;
232 ui::test::EventGenerator generator( 243 gfx::NativeView native_view = rwhva->GetNativeView();
233 web_contents->GetContentNativeView()->GetRootWindow()); 244 ui::test::EventGenerator generator(native_view->GetRootWindow());
234 245
235 // Tap inside the textfield and wait for the insertion handle to appear. 246 // Tap inside the textfield and wait for the insertion handle to appear.
236 selection_controller_client->InitWaitForSelectionEvent( 247 selection_controller_client()->InitWaitForSelectionEvent(
237 ui::INSERTION_HANDLE_SHOWN); 248 ui::INSERTION_HANDLE_SHOWN);
238 249
239 gfx::PointF point_f; 250 gfx::PointF point_f;
240 ASSERT_TRUE(GetPointInsideTextfield(&point_f)); 251 ASSERT_TRUE(GetPointInsideTextfield(&point_f));
241 gfx::Point point = gfx::ToRoundedPoint(point_f); 252 gfx::Point point = gfx::ToRoundedPoint(point_f);
242 generator_delegate->ConvertPointFromTarget( 253 generator_delegate->ConvertPointFromTarget(native_view, &point);
243 web_contents->GetContentNativeView(), &point);
244 generator.GestureTapAt(point); 254 generator.GestureTapAt(point);
245 255
246 selection_controller_client->Wait(); 256 selection_controller_client()->Wait();
247 257
248 // Check that insertion is active, but the quick menu is not showing. 258 // Check that insertion is active, but the quick menu is not showing.
249 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE, 259 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
250 rwhva->selection_controller()->active_status()); 260 rwhva->selection_controller()->active_status());
251 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 261 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
252 262
253 // Tap on the insertion handle; the quick menu should appear. 263 // Tap on the insertion handle; the quick menu should appear.
254 gfx::Point handle_center = gfx::ToRoundedPoint( 264 gfx::Point handle_center = gfx::ToRoundedPoint(
255 rwhva->selection_controller()->GetStartHandleRect().CenterPoint()); 265 rwhva->selection_controller()->GetStartHandleRect().CenterPoint());
256 generator_delegate->ConvertPointFromTarget( 266 generator_delegate->ConvertPointFromTarget(native_view, &handle_center);
257 web_contents->GetContentNativeView(), &handle_center);
258 generator.GestureTapAt(handle_center); 267 generator.GestureTapAt(handle_center);
259 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 268 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
260 269
261 // Tap once more on the insertion handle; the quick menu should disappear. 270 // Tap once more on the insertion handle; the quick menu should disappear.
262 generator.GestureTapAt(handle_center); 271 generator.GestureTapAt(handle_center);
263 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 272 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
264 } 273 }
265 274
266 // Tests that tapping in an empty textfield does not bring up the insertion 275 // Tests that tapping in an empty textfield does not bring up the insertion
267 // handle. 276 // handle.
268 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, 277 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
269 EmptyTextfieldInsertionOnTap) { 278 EmptyTextfieldInsertionOnTap) {
270 // Set the test page up. 279 // Set the test page up.
271 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 280 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
272 WebContents* web_contents = 281 InitSelectionController();
273 static_cast<WebContentsImpl*>(shell()->web_contents()); 282
274 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( 283 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
275 web_contents->GetRenderWidgetHostView());
276 TestTouchSelectionControllerClientAura* selection_controller_client =
277 new TestTouchSelectionControllerClientAura(rwhva);
278 rwhva->SetSelectionControllerClientForTest(
279 make_scoped_ptr(selection_controller_client));
280 284
281 // Clear textfield contents. 285 // Clear textfield contents.
282 ASSERT_TRUE(EmptyTextfield()); 286 ASSERT_TRUE(EmptyTextfield());
283 287
284 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 288 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
285 rwhva->selection_controller()->active_status()); 289 rwhva->selection_controller()->active_status());
286 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 290 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
287 291
288 // Tap inside the textfield and wait for the insertion cursor. 292 // Tap inside the textfield and wait for the insertion cursor.
289 selection_controller_client->InitWaitForSelectionEvent( 293 selection_controller_client()->InitWaitForSelectionEvent(
290 ui::SELECTION_ESTABLISHED); 294 ui::SELECTION_ESTABLISHED);
291 295
292 gfx::PointF point; 296 gfx::PointF point;
293 ASSERT_TRUE(GetPointInsideTextfield(&point)); 297 ASSERT_TRUE(GetPointInsideTextfield(&point));
294 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP); 298 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
295 tap_details.set_tap_count(1); 299 tap_details.set_tap_count(1);
296 ui::GestureEvent tap(point.x(), point.y(), 0, ui::EventTimeForNow(), 300 ui::GestureEvent tap(point.x(), point.y(), 0, ui::EventTimeForNow(),
297 tap_details); 301 tap_details);
298 rwhva->OnGestureEvent(&tap); 302 rwhva->OnGestureEvent(&tap);
299 303
300 selection_controller_client->Wait(); 304 selection_controller_client()->Wait();
301 305
302 // Check that insertion is not active and the quick menu is not showing. 306 // Check that insertion is not active and the quick menu is not showing.
303 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 307 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
304 rwhva->selection_controller()->active_status()); 308 rwhva->selection_controller()->active_status());
305 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 309 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
306 } 310 }
307 311
308 // Tests that the quick menu is hidden whenever a touch point is active. 312 // Tests that the quick menu is hidden whenever a touch point is active.
309 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, 313 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
310 QuickMenuHiddenOnTouch) { 314 QuickMenuHiddenOnTouch) {
311 // Set the test page up. 315 // Set the test page up.
312 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 316 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
313 WebContents* web_contents = 317 InitSelectionController();
314 static_cast<WebContentsImpl*>(shell()->web_contents());
315 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
316 web_contents->GetRenderWidgetHostView());
317 TestTouchSelectionControllerClientAura* selection_controller_client =
318 new TestTouchSelectionControllerClientAura(rwhva);
319 rwhva->SetSelectionControllerClientForTest(
320 make_scoped_ptr(selection_controller_client));
321 318
319 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
322 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 320 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
323 rwhva->selection_controller()->active_status()); 321 rwhva->selection_controller()->active_status());
324 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 322 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
325 323
326 // Long-press on the text and wait for selection handles to appear. 324 // Long-press on the text and wait for selection handles to appear.
327 selection_controller_client->InitWaitForSelectionEvent( 325 selection_controller_client()->InitWaitForSelectionEvent(
328 ui::SELECTION_HANDLES_SHOWN); 326 ui::SELECTION_HANDLES_SHOWN);
329 327
330 gfx::PointF point; 328 gfx::PointF point;
331 ASSERT_TRUE(GetPointInsideText(&point)); 329 ASSERT_TRUE(GetPointInsideText(&point));
332 ui::GestureEvent long_press( 330 ui::GestureEvent long_press(
333 point.x(), point.y(), 0, ui::EventTimeForNow(), 331 point.x(), point.y(), 0, ui::EventTimeForNow(),
334 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 332 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
335 rwhva->OnGestureEvent(&long_press); 333 rwhva->OnGestureEvent(&long_press);
336 334
337 selection_controller_client->Wait(); 335 selection_controller_client()->Wait();
338 336
339 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 337 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
340 rwhva->selection_controller()->active_status()); 338 rwhva->selection_controller()->active_status());
341 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 339 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
342 340
343 ui::test::EventGenerator generator( 341 ui::test::EventGenerator generator(rwhva->GetNativeView()->GetRootWindow(),
344 web_contents->GetContentNativeView()->GetRootWindow(), 342 rwhva->GetNativeView());
345 web_contents->GetContentNativeView());
346 343
347 // Put the first finger down: the quick menu should get hidden. 344 // Put the first finger down: the quick menu should get hidden.
348 generator.PressTouchId(0); 345 generator.PressTouchId(0);
349 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 346 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
350 rwhva->selection_controller()->active_status()); 347 rwhva->selection_controller()->active_status());
351 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 348 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
352 349
353 // Put a second finger down: the quick menu should remain hidden. 350 // Put a second finger down: the quick menu should remain hidden.
354 generator.PressTouchId(1); 351 generator.PressTouchId(1);
355 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 352 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
(...skipping 10 matching lines...) Expand all
366 generator.ReleaseTouchId(1); 363 generator.ReleaseTouchId(1);
367 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 364 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
368 rwhva->selection_controller()->active_status()); 365 rwhva->selection_controller()->active_status());
369 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 366 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
370 } 367 }
371 368
372 // Tests that the quick menu and touch handles are hidden during an scroll. 369 // Tests that the quick menu and touch handles are hidden during an scroll.
373 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, HiddenOnScroll) { 370 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, HiddenOnScroll) {
374 // Set the test page up. 371 // Set the test page up.
375 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 372 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
376 WebContents* web_contents = 373 InitSelectionController();
377 static_cast<WebContentsImpl*>(shell()->web_contents()); 374
378 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( 375 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
379 web_contents->GetRenderWidgetHostView());
380 TestTouchSelectionControllerClientAura* selection_controller_client =
381 new TestTouchSelectionControllerClientAura(rwhva);
382 rwhva->SetSelectionControllerClientForTest(
383 make_scoped_ptr(selection_controller_client));
384 ui::TouchSelectionControllerTestApi selection_controller_test_api( 376 ui::TouchSelectionControllerTestApi selection_controller_test_api(
385 rwhva->selection_controller()); 377 rwhva->selection_controller());
386 378
387 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 379 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
388 rwhva->selection_controller()->active_status()); 380 rwhva->selection_controller()->active_status());
389 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 381 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
390 382
391 // Long-press on the text and wait for selection handles to appear. 383 // Long-press on the text and wait for selection handles to appear.
392 selection_controller_client->InitWaitForSelectionEvent( 384 selection_controller_client()->InitWaitForSelectionEvent(
393 ui::SELECTION_HANDLES_SHOWN); 385 ui::SELECTION_HANDLES_SHOWN);
394 386
395 gfx::PointF point; 387 gfx::PointF point;
396 ASSERT_TRUE(GetPointInsideText(&point)); 388 ASSERT_TRUE(GetPointInsideText(&point));
397 ui::GestureEvent long_press( 389 ui::GestureEvent long_press(
398 point.x(), point.y(), 0, ui::EventTimeForNow(), 390 point.x(), point.y(), 0, ui::EventTimeForNow(),
399 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 391 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
400 rwhva->OnGestureEvent(&long_press); 392 rwhva->OnGestureEvent(&long_press);
401 393
402 selection_controller_client->Wait(); 394 selection_controller_client()->Wait();
403 395
404 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 396 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
405 rwhva->selection_controller()->active_status()); 397 rwhva->selection_controller()->active_status());
406 EXPECT_FALSE(selection_controller_test_api.temporarily_hidden()); 398 EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
407 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 399 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
408 400
409 // Put a finger down: the quick menu should go away, while touch handles stay 401 // Put a finger down: the quick menu should go away, while touch handles stay
410 // there. 402 // there.
411 ui::TouchEvent touch_down(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, 403 ui::TouchEvent touch_down(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0,
412 ui::EventTimeForNow()); 404 ui::EventTimeForNow());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 rwhva->selection_controller()->active_status()); 437 rwhva->selection_controller()->active_status());
446 EXPECT_FALSE(selection_controller_test_api.temporarily_hidden()); 438 EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
447 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 439 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
448 } 440 }
449 441
450 // Tests that touch selection gets deactivated after an overscroll completes. 442 // Tests that touch selection gets deactivated after an overscroll completes.
451 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, 443 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
452 HiddenAfterOverscroll) { 444 HiddenAfterOverscroll) {
453 // Set the page up. 445 // Set the page up.
454 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 446 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
455 WebContents* web_contents = 447 InitSelectionController();
456 static_cast<WebContentsImpl*>(shell()->web_contents());
457 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
458 web_contents->GetRenderWidgetHostView());
459 TestTouchSelectionControllerClientAura* selection_controller_client =
460 new TestTouchSelectionControllerClientAura(rwhva);
461 rwhva->SetSelectionControllerClientForTest(
462 make_scoped_ptr(selection_controller_client));
463 448
449 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
464 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 450 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
465 rwhva->selection_controller()->active_status()); 451 rwhva->selection_controller()->active_status());
466 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 452 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
467 453
468 // Long-press on the text and wait for touch handles to appear. 454 // Long-press on the text and wait for touch handles to appear.
469 selection_controller_client->InitWaitForSelectionEvent( 455 selection_controller_client()->InitWaitForSelectionEvent(
470 ui::SELECTION_HANDLES_SHOWN); 456 ui::SELECTION_HANDLES_SHOWN);
471 457
472 gfx::PointF point; 458 gfx::PointF point;
473 ASSERT_TRUE(GetPointInsideText(&point)); 459 ASSERT_TRUE(GetPointInsideText(&point));
474 ui::GestureEvent long_press( 460 ui::GestureEvent long_press(
475 point.x(), point.y(), 0, ui::EventTimeForNow(), 461 point.x(), point.y(), 0, ui::EventTimeForNow(),
476 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 462 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
477 rwhva->OnGestureEvent(&long_press); 463 rwhva->OnGestureEvent(&long_press);
478 464
479 selection_controller_client->Wait(); 465 selection_controller_client()->Wait();
480 466
481 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, 467 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
482 rwhva->selection_controller()->active_status()); 468 rwhva->selection_controller()->active_status());
483 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 469 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
484 470
485 // Scroll such that an overscroll is initiated and wait for it to complete: 471 // Scroll such that an overscroll is initiated and wait for it to complete:
486 // touch selection should not be active at the end. 472 // touch selection should not be active at the end.
487 selection_controller_client->InitWaitForSelectionEvent( 473 selection_controller_client()->InitWaitForSelectionEvent(
488 ui::SELECTION_HANDLES_CLEARED); 474 ui::SELECTION_HANDLES_CLEARED);
489 475
490 ui::GestureEvent scroll_begin( 476 ui::GestureEvent scroll_begin(
491 10, 10, 0, ui::EventTimeForNow(), 477 10, 10, 0, ui::EventTimeForNow(),
492 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); 478 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN));
493 rwhva->OnGestureEvent(&scroll_begin); 479 rwhva->OnGestureEvent(&scroll_begin);
494 480
495 ui::GestureEvent scroll_update( 481 ui::GestureEvent scroll_update(
496 210, 10, 0, ui::EventTimeForNow(), 482 210, 10, 0, ui::EventTimeForNow(),
497 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 200, 0)); 483 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 200, 0));
498 rwhva->OnGestureEvent(&scroll_update); 484 rwhva->OnGestureEvent(&scroll_update);
499 485
500 ui::GestureEvent scroll_end( 486 ui::GestureEvent scroll_end(
501 210, 10, 0, ui::EventTimeForNow(), 487 210, 10, 0, ui::EventTimeForNow(),
502 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); 488 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END));
503 rwhva->OnGestureEvent(&scroll_end); 489 rwhva->OnGestureEvent(&scroll_end);
504 490
505 selection_controller_client->Wait(); 491 selection_controller_client()->Wait();
506 492
507 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 493 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
508 rwhva->selection_controller()->active_status()); 494 rwhva->selection_controller()->active_status());
509 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 495 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
510 } 496 }
511 497
498 class TouchSelectionControllerClientAuraScaleFactorTest
499 : public TouchSelectionControllerClientAuraTest {
500 public:
501 void SetUpCommandLine(base::CommandLine* command_line) override {
502 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2");
503 }
504 };
505
506 #if defined(OS_WIN)
507 // High DPI tests are disabled on Windows due to crbug.com/545547.
508 #define MAYBE_SelectionHandleCoordinates DISABLED_SelectionHandleCoordinates
509 #define MAYBE_InsertionHandleCoordinates DISABLED_InsertionHandleCoordinates
510 #else
511 #define MAYBE_SelectionHandleCoordinates SelectionHandleCoordinates
512 #define MAYBE_InsertionHandleCoordinates InsertionHandleCoordinates
513 #endif
514
515 // Tests that selection handles are properly positioned at 2x DSF.
516 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraScaleFactorTest,
517 MAYBE_SelectionHandleCoordinates) {
518 // Set the test page up.
519 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
520 InitSelectionController();
521
522 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
523
524 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
525 rwhva->selection_controller()->active_status());
526 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
527 EXPECT_EQ(2.f, rwhva->current_device_scale_factor());
528
529 // Long-press on the text and wait for handles to appear.
530 selection_controller_client()->InitWaitForSelectionEvent(
531 ui::SELECTION_HANDLES_SHOWN);
532 gfx::PointF point;
533 ASSERT_TRUE(GetPointInsideText(&point));
534 ui::GestureEvent long_press(
535 point.x(), point.y(), 0, ui::EventTimeForNow(),
536 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
537 rwhva->OnGestureEvent(&long_press);
538 selection_controller_client()->Wait();
539
540 // Check that selection is active and the quick menu is showing.
541 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
542 rwhva->selection_controller()->active_status());
543 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
544 const ui::TouchSelectionController* controller =
545 GetRenderWidgetHostViewAura()->selection_controller();
546
547 gfx::PointF start_top = controller->start().edge_top();
548
549 // The selection start should be uppper left, and selection end should be
550 // upper right.
551 EXPECT_LT(controller->start().edge_top().x(), point.x());
552 EXPECT_LT(controller->start().edge_bottom().x(), point.x());
553
554 EXPECT_LT(point.x(), controller->end().edge_top().x());
555 EXPECT_LT(point.x(), controller->end().edge_bottom().x());
556
557 // Handles are created below the selection. The top position should roughly
558 // be within the handle size from the touch position.
559 float handle_size = controller->start().edge_bottom().y() -
560 controller->start().edge_top().y();
561 float handle_max_bottom = point.y() + handle_size;
562 EXPECT_GT(handle_max_bottom, controller->start().edge_top().y());
563 EXPECT_GT(handle_max_bottom, controller->end().edge_top().y());
564
565 gfx::Point handle_point = gfx::ToRoundedPoint(
566 rwhva->selection_controller()->GetStartHandleRect().CenterPoint());
567
568 // Move the selection handle. Touch the handle first.
569 selection_controller_client()->InitWaitForSelectionEvent(
570 ui::SELECTION_HANDLE_DRAG_STARTED);
571 ui::TouchEvent touch_down(ui::ET_TOUCH_PRESSED, handle_point, 0,
572 ui::EventTimeForNow());
573 rwhva->OnTouchEvent(&touch_down);
574 selection_controller_client()->Wait();
575
576 // Move it.
577 selection_controller_client()->InitWaitForSelectionEvent(
578 ui::SELECTION_HANDLES_MOVED);
579 handle_point.Offset(10, 0);
580 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, handle_point, 0,
581 ui::EventTimeForNow());
582 rwhva->OnTouchEvent(&touch_move);
583 selection_controller_client()->Wait();
584
585 // Then release.
586 selection_controller_client()->InitWaitForSelectionEvent(
587 ui::SELECTION_HANDLE_DRAG_STOPPED);
588 ui::TouchEvent touch_up(ui::ET_TOUCH_RELEASED, handle_point, 0,
589 ui::EventTimeForNow());
590 rwhva->OnTouchEvent(&touch_up);
591 selection_controller_client()->Wait();
592
593 // The handle should have moved to right.
594 EXPECT_EQ(start_top.y(), controller->start().edge_top().y());
595 EXPECT_LT(start_top.x(), controller->start().edge_top().x());
596
597 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
598 rwhva->selection_controller()->active_status());
599 }
600
601 // Tests that insertion handles are properly positioned at 2x DSF.
602 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraScaleFactorTest,
603 MAYBE_InsertionHandleCoordinates) {
604 // Set the test page up.
605 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
606 InitSelectionController();
607
608 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
609
610 // Tap inside the textfield and wait for the insertion cursor.
611 selection_controller_client()->InitWaitForSelectionEvent(
612 ui::INSERTION_HANDLE_SHOWN);
613
614 gfx::PointF point;
615 ASSERT_TRUE(GetPointInsideTextfield(&point));
616 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
617 tap_details.set_tap_count(1);
618 ui::GestureEvent tap(point.x(), point.y(), 0, ui::EventTimeForNow(),
619 tap_details);
620 rwhva->OnGestureEvent(&tap);
621
622 selection_controller_client()->Wait();
623
624 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
625 rwhva->selection_controller()->active_status());
626
627 gfx::RectF initial_handle_rect =
628 rwhva->selection_controller()->GetStartHandleRect();
629
630 // Move the insertion handle. Touch the handle first.
631 gfx::Point handle_point =
632 gfx::ToRoundedPoint(initial_handle_rect.CenterPoint());
633
634 selection_controller_client()->InitWaitForSelectionEvent(
635 ui::INSERTION_HANDLE_DRAG_STARTED);
636 ui::TouchEvent touch_down(ui::ET_TOUCH_PRESSED, handle_point, 0,
637 ui::EventTimeForNow());
638 rwhva->OnTouchEvent(&touch_down);
639 selection_controller_client()->Wait();
640
641 // Move it.
642 selection_controller_client()->InitWaitForSelectionEvent(
643 ui::INSERTION_HANDLE_MOVED);
644 handle_point.Offset(10, 0);
645 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, handle_point, 0,
646 ui::EventTimeForNow());
647 rwhva->OnTouchEvent(&touch_move);
648 selection_controller_client()->Wait();
649
650 // Then release.
651 selection_controller_client()->InitWaitForSelectionEvent(
652 ui::INSERTION_HANDLE_DRAG_STOPPED);
653 ui::TouchEvent touch_up(ui::ET_TOUCH_RELEASED, handle_point, 0,
654 ui::EventTimeForNow());
655 rwhva->OnTouchEvent(&touch_up);
656 selection_controller_client()->Wait();
657
658 gfx::RectF moved_handle_rect =
659 rwhva->selection_controller()->GetStartHandleRect();
660
661 // The handle should have moved to right.
662 EXPECT_EQ(initial_handle_rect.y(), moved_handle_rect.y());
663 EXPECT_LT(initial_handle_rect.x(), moved_handle_rect.x());
664
665 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
666 rwhva->selection_controller()->active_status());
667 }
668
512 } // namespace content 669 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_view_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698