| 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/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/browser/frame_host/navigation_controller_impl.h" | 21 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 22 #include "content/browser/frame_host/navigation_entry_impl.h" | 22 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 23 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 23 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
| 24 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 24 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 25 #include "content/browser/web_contents/web_contents_impl.h" | 25 #include "content/browser/web_contents/web_contents_impl.h" |
| 26 #include "content/browser/web_contents/web_contents_view.h" | 26 #include "content/browser/web_contents/web_contents_view.h" |
| 27 #include "content/common/input/synthetic_web_input_event_builders.h" | 27 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 28 #include "content/common/input_messages.h" | 28 #include "content/common/input_messages.h" |
| 29 #include "content/common/view_messages.h" | 29 #include "content/common/view_messages.h" |
| 30 #include "content/public/browser/browser_message_filter.h" | 30 #include "content/public/browser/browser_message_filter.h" |
| 31 #include "content/public/browser/overscroll_configuration.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 32 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
| 33 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
| 34 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
| 35 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 37 #include "content/public/test/browser_test_utils.h" |
| 37 #include "content/public/test/content_browser_test.h" | 38 #include "content/public/test/content_browser_test.h" |
| 38 #include "content/public/test/content_browser_test_utils.h" | 39 #include "content/public/test/content_browser_test_utils.h" |
| 39 #include "content/public/test/test_renderer_host.h" | 40 #include "content/public/test/test_renderer_host.h" |
| 40 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 DISABLED_OverscrollNavigationWithTouchHandler | 423 DISABLED_OverscrollNavigationWithTouchHandler |
| 423 #else | 424 #else |
| 424 #define MAYBE_OverscrollNavigationWithTouchHandler \ | 425 #define MAYBE_OverscrollNavigationWithTouchHandler \ |
| 425 OverscrollNavigationWithTouchHandler | 426 OverscrollNavigationWithTouchHandler |
| 426 #endif | 427 #endif |
| 427 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, | 428 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, |
| 428 MAYBE_OverscrollNavigationWithTouchHandler) { | 429 MAYBE_OverscrollNavigationWithTouchHandler) { |
| 429 TestOverscrollNavigation(true); | 430 TestOverscrollNavigation(true); |
| 430 } | 431 } |
| 431 | 432 |
| 433 namespace { |
| 434 // This fails the test if it sees any mouse events. |
| 435 class SpuriousMouseEventObserver : public RenderWidgetHost::InputEventObserver { |
| 436 public: |
| 437 explicit SpuriousMouseEventObserver(RenderWidgetHost* host) : host_(host) { |
| 438 host_->AddInputEventObserver(this); |
| 439 } |
| 440 |
| 441 ~SpuriousMouseEventObserver() override { |
| 442 host_->RemoveInputEventObserver(this); |
| 443 } |
| 444 |
| 445 void OnInputEvent(const blink::WebInputEvent& event) override { |
| 446 EXPECT_FALSE(blink::WebInputEvent::IsMouseEventType(event.GetType())) |
| 447 << "Unexpected mouse event."; |
| 448 } |
| 449 |
| 450 private: |
| 451 RenderWidgetHost* host_; |
| 452 |
| 453 DISALLOW_COPY_AND_ASSIGN(SpuriousMouseEventObserver); |
| 454 }; |
| 455 } // namespace |
| 456 |
| 457 // Start an overscroll gesture and then check if the gesture is interrupted by |
| 458 // a spurious mouse event. Overscrolling may trigger mouse-move events, but |
| 459 // these should all be marked as synthesized and get dropped while the |
| 460 // overscroll gesture is in progress. |
| 461 // See crbug.com/731914 |
| 462 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, |
| 463 OverscrollNotInterruptedBySpuriousMouseEvents) { |
| 464 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); |
| 465 WebContentsImpl* web_contents = |
| 466 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 467 NavigationController& controller = web_contents->GetController(); |
| 468 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 469 |
| 470 EXPECT_FALSE(controller.CanGoBack()); |
| 471 EXPECT_FALSE(controller.CanGoForward()); |
| 472 int index = -1; |
| 473 std::unique_ptr<base::Value> value = |
| 474 content::ExecuteScriptAndGetValue(main_frame, "get_current()"); |
| 475 ASSERT_TRUE(value->GetAsInteger(&index)); |
| 476 EXPECT_EQ(0, index); |
| 477 |
| 478 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 479 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); |
| 480 ASSERT_TRUE(value->GetAsInteger(&index)); |
| 481 EXPECT_EQ(1, index); |
| 482 EXPECT_TRUE(controller.CanGoBack()); |
| 483 EXPECT_FALSE(controller.CanGoForward()); |
| 484 |
| 485 // We start an overscroll gesture, but pause mid-gesture. |
| 486 |
| 487 // Fail the test if the following gesture produces mouse-moves that don't get |
| 488 // dropped. |
| 489 SpuriousMouseEventObserver mouse_observer(GetRenderWidgetHost()); |
| 490 |
| 491 blink::WebGestureEvent gesture_scroll_begin( |
| 492 blink::WebGestureEvent::kGestureScrollBegin, |
| 493 blink::WebInputEvent::kNoModifiers, |
| 494 blink::WebInputEvent::kTimeStampForTesting); |
| 495 gesture_scroll_begin.source_device = blink::kWebGestureDeviceTouchscreen; |
| 496 gesture_scroll_begin.data.scroll_begin.delta_hint_units = |
| 497 blink::WebGestureEvent::ScrollUnits::kPrecisePixels; |
| 498 gesture_scroll_begin.data.scroll_begin.delta_x_hint = 0.f; |
| 499 gesture_scroll_begin.data.scroll_begin.delta_y_hint = 0.f; |
| 500 GetRenderWidgetHost()->ForwardGestureEvent(gesture_scroll_begin); |
| 501 |
| 502 blink::WebGestureEvent gesture_scroll_update( |
| 503 blink::WebGestureEvent::kGestureScrollUpdate, |
| 504 blink::WebInputEvent::kNoModifiers, |
| 505 blink::WebInputEvent::kTimeStampForTesting); |
| 506 gesture_scroll_update.source_device = blink::kWebGestureDeviceTouchscreen; |
| 507 gesture_scroll_update.data.scroll_update.delta_units = |
| 508 blink::WebGestureEvent::ScrollUnits::kPrecisePixels; |
| 509 gesture_scroll_update.data.scroll_update.delta_y = 0.f; |
| 510 float horiz_threshold = |
| 511 GetOverscrollConfig(OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN); |
| 512 gesture_scroll_update.data.scroll_update.delta_x = horiz_threshold + 1; |
| 513 GetRenderWidgetHost()->ForwardGestureEvent(gesture_scroll_update); |
| 514 |
| 515 // Wait for the overscroll gesture to start and then allow some time for the |
| 516 // spurious mouse event. Since we're testing that an event does not happen, |
| 517 // we just have a timeout. This could potentially result in the event |
| 518 // happening after the timeout, which would cause the test to succeed |
| 519 // incorrectly. That said, the event we're worried about happens almost |
| 520 // instantly after the start of the overscroll gesture. |
| 521 base::RunLoop run_loop; |
| 522 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 523 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); |
| 524 run_loop.Run(); |
| 525 |
| 526 // Check that the overscroll gesture was not reset. |
| 527 OverscrollController* overscroll_controller = |
| 528 static_cast<RenderWidgetHostViewAura*>(GetRenderWidgetHostView()) |
| 529 ->overscroll_controller(); |
| 530 EXPECT_NE(OVERSCROLL_NONE, overscroll_controller->overscroll_mode()); |
| 531 } |
| 532 |
| 432 // Disabled because the test always fails the first time it runs on the Win Aura | 533 // Disabled because the test always fails the first time it runs on the Win Aura |
| 433 // bots, and usually but not always passes second-try (See crbug.com/179532). | 534 // bots, and usually but not always passes second-try (See crbug.com/179532). |
| 434 // On Linux, the test frequently times out. (See crbug.com/440043). | 535 // On Linux, the test frequently times out. (See crbug.com/440043). |
| 435 #if defined(OS_WIN) || defined(OS_LINUX) | 536 #if defined(OS_WIN) || defined(OS_LINUX) |
| 436 #define MAYBE_QuickOverscrollDirectionChange \ | 537 #define MAYBE_QuickOverscrollDirectionChange \ |
| 437 DISABLED_QuickOverscrollDirectionChange | 538 DISABLED_QuickOverscrollDirectionChange |
| 438 #else | 539 #else |
| 439 #define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange | 540 #define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange |
| 440 #endif | 541 #endif |
| 441 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, | 542 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); | 964 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); |
| 864 window->Init(ui::LAYER_NOT_DRAWN); | 965 window->Init(ui::LAYER_NOT_DRAWN); |
| 865 | 966 |
| 866 RenderWidgetHostViewAura* rwhva = | 967 RenderWidgetHostViewAura* rwhva = |
| 867 static_cast<RenderWidgetHostViewAura*>( | 968 static_cast<RenderWidgetHostViewAura*>( |
| 868 shell()->web_contents()->GetRenderWidgetHostView()); | 969 shell()->web_contents()->GetRenderWidgetHostView()); |
| 869 rwhva->ResetHasSnappedToBoundary(); | 970 rwhva->ResetHasSnappedToBoundary(); |
| 870 EXPECT_FALSE(rwhva->has_snapped_to_boundary()); | 971 EXPECT_FALSE(rwhva->has_snapped_to_boundary()); |
| 871 window->AddChild(shell()->web_contents()->GetNativeView()); | 972 window->AddChild(shell()->web_contents()->GetNativeView()); |
| 872 EXPECT_TRUE(rwhva->has_snapped_to_boundary()); | 973 EXPECT_TRUE(rwhva->has_snapped_to_boundary()); |
| 974 ADD_FAILURE(); |
| 873 } | 975 } |
| 874 | 976 |
| 875 // Flaky on some platforms, likely for the same reason as other flaky overscroll | 977 // Flaky on some platforms, likely for the same reason as other flaky overscroll |
| 876 // tests. http://crbug.com/305722 | 978 // tests. http://crbug.com/305722 |
| 877 // TODO(tdresser): Re-enable this once eager GR is back on. See | 979 // TODO(tdresser): Re-enable this once eager GR is back on. See |
| 878 // crbug.com/410280. | 980 // crbug.com/410280. |
| 879 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 981 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 880 #define MAYBE_OverscrollNavigationTouchThrottling \ | 982 #define MAYBE_OverscrollNavigationTouchThrottling \ |
| 881 DISABLED_OverscrollNavigationTouchThrottling | 983 DISABLED_OverscrollNavigationTouchThrottling |
| 882 #else | 984 #else |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 details = sink->OnEventFromSource(&release); | 1223 details = sink->OnEventFromSource(&release); |
| 1122 ASSERT_FALSE(details.dispatcher_destroyed); | 1224 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1123 WaitAFrame(); | 1225 WaitAFrame(); |
| 1124 | 1226 |
| 1125 EXPECT_LT(0, tracker.num_overscroll_updates()); | 1227 EXPECT_LT(0, tracker.num_overscroll_updates()); |
| 1126 EXPECT_FALSE(tracker.overscroll_completed()); | 1228 EXPECT_FALSE(tracker.overscroll_completed()); |
| 1127 } | 1229 } |
| 1128 } | 1230 } |
| 1129 | 1231 |
| 1130 } // namespace content | 1232 } // namespace content |
| OLD | NEW |