| 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 "content/browser/web_contents/touch_editable_impl_aura.h" | 5 #include "content/browser/web_contents/touch_editable_impl_aura.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 10, | 287 10, |
| 288 0, | 288 0, |
| 289 ui::EventTimeForNow(), | 289 ui::EventTimeForNow(), |
| 290 ui::GestureEventDetails( | 290 ui::GestureEventDetails( |
| 291 ui::ET_GESTURE_LONG_PRESS, 0, 0), | 291 ui::ET_GESTURE_LONG_PRESS, 0, 0), |
| 292 1); | 292 1); |
| 293 rwhva->OnGestureEvent(&scroll_end); | 293 rwhva->OnGestureEvent(&scroll_end); |
| 294 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); | 294 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // TODO(mohsen): Remove logs if the test showed no flakiness anymore. | |
| 298 void TestTouchCursorInTextfield() { | 297 void TestTouchCursorInTextfield() { |
| 299 ASSERT_NO_FATAL_FAILURE( | 298 ASSERT_NO_FATAL_FAILURE( |
| 300 StartTestWithPage("files/touch_selection.html")); | 299 StartTestWithPage("files/touch_selection.html")); |
| 301 WebContentsImpl* web_contents = | 300 WebContentsImpl* web_contents = |
| 302 static_cast<WebContentsImpl*>(shell()->web_contents()); | 301 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 303 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 302 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
| 304 web_contents->GetRenderViewHost()); | 303 web_contents->GetRenderViewHost()); |
| 305 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( | 304 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( |
| 306 web_contents->GetView()); | 305 web_contents->GetView()); |
| 307 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; | 306 TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; |
| 308 view_aura->SetTouchEditableForTest(touch_editable); | 307 view_aura->SetTouchEditableForTest(touch_editable); |
| 309 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 308 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 310 web_contents->GetRenderWidgetHostView()); | 309 web_contents->GetRenderWidgetHostView()); |
| 311 aura::Window* content = web_contents->GetView()->GetContentNativeView(); | 310 aura::Window* content = web_contents->GetView()->GetContentNativeView(); |
| 312 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 311 aura::test::EventGenerator generator(content->GetRootWindow(), content); |
| 313 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 312 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
| 314 EXPECT_EQ(touch_editable->rwhva_, rwhva); | 313 EXPECT_EQ(touch_editable->rwhva_, rwhva); |
| 315 | |
| 316 LOG(INFO) << "Focus the textfield."; | |
| 317 ExecuteSyncJSFunction(view_host, "focus_textfield()"); | 314 ExecuteSyncJSFunction(view_host, "focus_textfield()"); |
| 318 | 315 |
| 319 // Tap textfield | 316 // Tap textfield |
| 320 touch_editable->Reset(); | 317 touch_editable->Reset(); |
| 321 LOG(INFO) << "Tap in the textfield."; | |
| 322 generator.GestureTapAt(gfx::Point(bounds.x() + 50, bounds.y() + 40)); | 318 generator.GestureTapAt(gfx::Point(bounds.x() + 50, bounds.y() + 40)); |
| 323 LOG(INFO) << "Wait for tap-down ACK."; | |
| 324 touch_editable->WaitForGestureAck(); // Wait for Tap Down Ack | 319 touch_editable->WaitForGestureAck(); // Wait for Tap Down Ack |
| 325 touch_editable->Reset(); | 320 touch_editable->Reset(); |
| 326 LOG(INFO) << "Wait for tap ACK."; | |
| 327 touch_editable->WaitForGestureAck(); // Wait for Tap Ack. | 321 touch_editable->WaitForGestureAck(); // Wait for Tap Ack. |
| 328 | 322 |
| 329 LOG(INFO) << "Test the touch selection handle."; | |
| 330 // Check if cursor handle is showing. | 323 // Check if cursor handle is showing. |
| 331 ui::TouchSelectionController* controller = | 324 ui::TouchSelectionController* controller = |
| 332 touch_editable->touch_selection_controller_.get(); | 325 touch_editable->touch_selection_controller_.get(); |
| 333 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, touch_editable->text_input_type_); | 326 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, touch_editable->text_input_type_); |
| 334 EXPECT_TRUE(controller); | 327 EXPECT_TRUE(controller); |
| 335 | 328 |
| 336 LOG(INFO) << "Test cursor position."; | |
| 337 scoped_ptr<base::Value> value = | 329 scoped_ptr<base::Value> value = |
| 338 content::ExecuteScriptAndGetValue(view_host, "get_cursor_position()"); | 330 content::ExecuteScriptAndGetValue(view_host, "get_cursor_position()"); |
| 339 int cursor_pos = -1; | 331 int cursor_pos = -1; |
| 340 value->GetAsInteger(&cursor_pos); | 332 value->GetAsInteger(&cursor_pos); |
| 341 EXPECT_NE(-1, cursor_pos); | 333 EXPECT_NE(-1, cursor_pos); |
| 342 | 334 |
| 343 // Move the cursor handle. | 335 // Move the cursor handle. |
| 344 LOG(INFO) << "Drag the touch selection handle to change its position."; | |
| 345 generator.GestureScrollSequence( | 336 generator.GestureScrollSequence( |
| 346 gfx::Point(50, 59), | 337 gfx::Point(50, 59), |
| 347 gfx::Point(10, 59), | 338 gfx::Point(10, 59), |
| 348 base::TimeDelta::FromMilliseconds(20), | 339 base::TimeDelta::FromMilliseconds(20), |
| 349 1); | 340 1); |
| 350 LOG(INFO) << "Wait for cursor position to change."; | |
| 351 touch_editable->WaitForSelectionChangeCallback(); | |
| 352 LOG(INFO) << "Check cursor position is changed."; | |
| 353 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); | 341 EXPECT_TRUE(touch_editable->touch_selection_controller_.get()); |
| 354 value = content::ExecuteScriptAndGetValue(view_host, | 342 value = content::ExecuteScriptAndGetValue( |
| 355 "get_cursor_position()"); | 343 view_host, "get_cursor_position()"); |
| 356 int new_cursor_pos = -1; | 344 int new_cursor_pos = -1; |
| 357 value->GetAsInteger(&new_cursor_pos); | 345 value->GetAsInteger(&new_cursor_pos); |
| 358 EXPECT_NE(-1, new_cursor_pos); | 346 EXPECT_NE(-1, new_cursor_pos); |
| 359 // Cursor should have moved. | 347 // Cursor should have moved. |
| 360 EXPECT_NE(new_cursor_pos, cursor_pos); | 348 EXPECT_NE(new_cursor_pos, cursor_pos); |
| 361 } | 349 } |
| 362 | 350 |
| 363 private: | 351 private: |
| 364 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); | 352 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); |
| 365 }; | 353 }; |
| 366 | 354 |
| 367 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 355 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
| 368 TouchSelectionOriginatingFromWebpageTest) { | 356 TouchSelectionOriginatingFromWebpageTest) { |
| 369 TestTouchSelectionOriginatingFromWebpage(); | 357 TestTouchSelectionOriginatingFromWebpage(); |
| 370 } | 358 } |
| 371 | 359 |
| 372 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 360 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
| 373 TestTouchSelectionHiddenWhenScrolling) { | 361 TestTouchSelectionHiddenWhenScrolling) { |
| 374 TestTouchSelectionHiddenWhenScrolling(); | 362 TestTouchSelectionHiddenWhenScrolling(); |
| 375 } | 363 } |
| 376 | 364 |
| 377 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 365 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
| 378 TouchSelectionOnLongPressTest) { | 366 TouchSelectionOnLongPressTest) { |
| 379 TestTouchSelectionOnLongPress(); | 367 TestTouchSelectionOnLongPress(); |
| 380 } | 368 } |
| 381 | 369 |
| 370 // TODO(miu): Disabled test due to flakiness. http://crbug.com/235991 |
| 382 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, | 371 IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, |
| 383 TouchCursorInTextfieldTest) { | 372 DISABLED_TouchCursorInTextfieldTest) { |
| 384 TestTouchCursorInTextfield(); | 373 TestTouchCursorInTextfield(); |
| 385 } | 374 } |
| 386 | 375 |
| 387 } // namespace content | 376 } // namespace content |
| OLD | NEW |