diff options
Diffstat (limited to 'chromium/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc')
-rw-r--r-- | chromium/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc | 219 |
1 files changed, 203 insertions, 16 deletions
diff --git a/chromium/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc b/chromium/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc index a35f28165b3..9ee1bbf7bf2 100644 --- a/chromium/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc +++ b/chromium/content/browser/web_contents/touch_editable_impl_aura_browsertest.cc @@ -25,6 +25,7 @@ #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/events/event_utils.h" #include "ui/events/test/event_generator.h" +#include "ui/wm/core/default_screen_position_client.h" using blink::WebInputEvent; @@ -33,7 +34,11 @@ namespace content { class TestTouchEditableImplAura : public TouchEditableImplAura { public: TestTouchEditableImplAura() - : selection_changed_callback_arrived_(false), + : overscroll_started_callback_arrived_(false), + waiting_for_overscroll_started_callback_(false), + overscroll_completed_callback_arrived_(false), + waiting_for_overscroll_completed_callback_(false), + selection_changed_callback_arrived_(false), waiting_for_selection_changed_callback_(false), waiting_for_gesture_ack_type_(WebInputEvent::Undefined), last_gesture_ack_type_(WebInputEvent::Undefined), @@ -41,6 +46,10 @@ class TestTouchEditableImplAura : public TouchEditableImplAura { waiting_for_fling_stop_callback_(false) {} virtual void Reset() { + overscroll_started_callback_arrived_ = false; + waiting_for_overscroll_started_callback_ = false; + overscroll_completed_callback_arrived_ = false; + waiting_for_overscroll_completed_callback_ = false; selection_changed_callback_arrived_ = false; waiting_for_selection_changed_callback_ = false; waiting_for_gesture_ack_type_ = WebInputEvent::Undefined; @@ -49,15 +58,49 @@ class TestTouchEditableImplAura : public TouchEditableImplAura { waiting_for_fling_stop_callback_ = false; } - virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor, - const gfx::Rect& focus) override { + void OverscrollStarted() override { + overscroll_started_callback_arrived_ = true; + TouchEditableImplAura::OverscrollStarted(); + if (waiting_for_overscroll_started_callback_) + overscroll_started_wait_run_loop_->Quit(); +} + + void WaitForOverscrollStartedCallback() { + // Doesn't make sense to call more that once without resetting. + CHECK(!waiting_for_overscroll_started_callback_); + waiting_for_overscroll_started_callback_ = true; + if (overscroll_started_callback_arrived_) + return; + overscroll_started_wait_run_loop_.reset(new base::RunLoop()); + overscroll_started_wait_run_loop_->Run(); + } + + void OverscrollCompleted() override { + overscroll_completed_callback_arrived_ = true; + TouchEditableImplAura::OverscrollCompleted(); + if (waiting_for_overscroll_completed_callback_) + overscroll_completed_wait_run_loop_->Quit(); + } + + void WaitForOverscrollCompletedCallback() { + // Doesn't make sense to call more that once without resetting. + CHECK(!waiting_for_overscroll_completed_callback_); + waiting_for_overscroll_completed_callback_ = true; + if (overscroll_completed_callback_arrived_) + return; + overscroll_completed_wait_run_loop_.reset(new base::RunLoop()); + overscroll_completed_wait_run_loop_->Run(); + } + + void OnSelectionOrCursorChanged(const ui::SelectionBound& anchor, + const ui::SelectionBound& focus) override { selection_changed_callback_arrived_ = true; TouchEditableImplAura::OnSelectionOrCursorChanged(anchor, focus); if (waiting_for_selection_changed_callback_) selection_changed_wait_run_loop_->Quit(); } - virtual void GestureEventAck(int gesture_event_type) override { + void GestureEventAck(int gesture_event_type) override { last_gesture_ack_type_ = static_cast<WebInputEvent::Type>(gesture_event_type); TouchEditableImplAura::GestureEventAck(gesture_event_type); @@ -65,47 +108,59 @@ class TestTouchEditableImplAura : public TouchEditableImplAura { gesture_ack_wait_run_loop_->Quit(); } - virtual void DidStopFlinging() override { + void DidStopFlinging() override { fling_stop_callback_arrived_ = true; TouchEditableImplAura::DidStopFlinging(); if (waiting_for_fling_stop_callback_) fling_stop_wait_run_loop_->Quit(); } - virtual void WaitForSelectionChangeCallback() { + void WaitForSelectionChangeCallback() { + // Doesn't make sense to call more that once without resetting. + CHECK(!waiting_for_selection_changed_callback_); + waiting_for_selection_changed_callback_ = true; if (selection_changed_callback_arrived_) return; - waiting_for_selection_changed_callback_ = true; selection_changed_wait_run_loop_.reset(new base::RunLoop()); selection_changed_wait_run_loop_->Run(); } - virtual void WaitForGestureAck(WebInputEvent::Type gesture_event_type) { + void WaitForGestureAck(WebInputEvent::Type gesture_event_type) { + // Doesn't make sense to call more that once without resetting. + CHECK_EQ(waiting_for_gesture_ack_type_, WebInputEvent::Undefined); + waiting_for_gesture_ack_type_ = gesture_event_type; if (last_gesture_ack_type_ == gesture_event_type) return; - waiting_for_gesture_ack_type_ = gesture_event_type; gesture_ack_wait_run_loop_.reset(new base::RunLoop()); gesture_ack_wait_run_loop_->Run(); } - virtual void WaitForFlingStopCallback() { + void WaitForFlingStopCallback() { + // Doesn't make sense to call more that once without resetting. + CHECK(!waiting_for_fling_stop_callback_); + waiting_for_fling_stop_callback_ = true; if (fling_stop_callback_arrived_) return; - waiting_for_fling_stop_callback_ = true; fling_stop_wait_run_loop_.reset(new base::RunLoop()); fling_stop_wait_run_loop_->Run(); } protected: - virtual ~TestTouchEditableImplAura() {} + ~TestTouchEditableImplAura() override {} private: + bool overscroll_started_callback_arrived_; + bool waiting_for_overscroll_started_callback_; + bool overscroll_completed_callback_arrived_; + bool waiting_for_overscroll_completed_callback_; bool selection_changed_callback_arrived_; bool waiting_for_selection_changed_callback_; WebInputEvent::Type waiting_for_gesture_ack_type_; WebInputEvent::Type last_gesture_ack_type_; bool fling_stop_callback_arrived_; bool waiting_for_fling_stop_callback_; + scoped_ptr<base::RunLoop> overscroll_started_wait_run_loop_; + scoped_ptr<base::RunLoop> overscroll_completed_wait_run_loop_; scoped_ptr<base::RunLoop> selection_changed_wait_run_loop_; scoped_ptr<base::RunLoop> gesture_ack_wait_run_loop_; scoped_ptr<base::RunLoop> fling_stop_wait_run_loop_; @@ -118,7 +173,13 @@ class TouchEditableImplAuraTest : public ContentBrowserTest { TouchEditableImplAuraTest() {} protected: - virtual void SetUpCommandLine(CommandLine* command_line) override { + void SetUpOnMainThread() override { + ContentBrowserTest::SetUpOnMainThread(); + aura::client::SetScreenPositionClient(shell()->window()->GetRootWindow(), + &screen_position_client_); + } + + void SetUpCommandLine(base::CommandLine* command_line) override { command_line->AppendSwitch(switches::kEnableTouchEditing); } @@ -145,7 +206,7 @@ class TouchEditableImplAuraTest : public ContentBrowserTest { return touch_editable->rwhva_; } - ui::TouchSelectionController* GetTouchSelectionController( + ui::TouchEditingControllerDeprecated* GetTouchSelectionController( TouchEditableImplAura* touch_editable) { return touch_editable->touch_selection_controller_.get(); } @@ -155,6 +216,8 @@ class TouchEditableImplAuraTest : public ContentBrowserTest { } private: + wm::DefaultScreenPositionClient screen_position_client_; + DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAuraTest); }; @@ -193,9 +256,17 @@ IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, // Lets move the handles a bit to modify the selection touch_editable->Reset(); + ui::SelectionBound anchor, focus; + touch_editable->GetSelectionEndPoints(&anchor, &focus); + // The distance by which a handle image is offset from the bottom of the + // selection/text baseline. + const int kSelectionHandleVerticalVisualOffset = 2; + int handle_grab_x = bounds.x() + anchor.edge_bottom_rounded().x(); + int handle_grab_y = bounds.y() + anchor.edge_bottom_rounded().y() + + kSelectionHandleVerticalVisualOffset + 1; generator.GestureScrollSequence( - gfx::Point(10, 47), - gfx::Point(30, 47), + gfx::Point(handle_grab_x, handle_grab_y), + gfx::Point(handle_grab_x + 20, handle_grab_y), base::TimeDelta::FromMilliseconds(20), 5); touch_editable->WaitForSelectionChangeCallback(); @@ -321,6 +392,122 @@ IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, } IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, + TestTouchSelectionWhenOverscrolling) { + ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); + WebContentsImpl* web_contents = + static_cast<WebContentsImpl*>(shell()->web_contents()); + RenderFrameHost* main_frame = web_contents->GetMainFrame(); + WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( + web_contents->GetView()); + TestTouchEditableImplAura* touch_editable = new TestTouchEditableImplAura; + view_aura->SetTouchEditableForTest(touch_editable); + RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( + web_contents->GetRenderWidgetHostView()); + EXPECT_EQ(GetRenderWidgetHostViewAura(touch_editable), rwhva); + + // Long press to select word. + ui::GestureEvent long_press( + 10, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); + touch_editable->Reset(); + rwhva->OnGestureEvent(&long_press); + touch_editable->WaitForSelectionChangeCallback(); + + // Check if selection handles are showing. + EXPECT_TRUE(GetTouchSelectionController(touch_editable)); + + scoped_ptr<base::Value> value = + content::ExecuteScriptAndGetValue(main_frame, "get_selection()"); + std::string selection; + value->GetAsString(&selection); + EXPECT_STREQ("Some", selection.c_str()); + + ui::GestureEvent scroll_begin( + 10, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0)); + rwhva->OnGestureEvent(&scroll_begin); + EXPECT_FALSE(GetTouchSelectionController(touch_editable)); + + // Then overscroll starts. OverscrollStarted callback should be called and + // handles should remain hidden. + ui::GestureEvent scroll_update( + 210, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 200, 0)); + rwhva->OnGestureEvent(&scroll_update); + touch_editable->WaitForOverscrollStartedCallback(); + EXPECT_FALSE(GetTouchSelectionController(touch_editable)); + + // We might have multiple overscroll-starts in one overscroll session. Handles + // should still remain hidden. + touch_editable->OverscrollStarted(); + EXPECT_FALSE(GetTouchSelectionController(touch_editable)); + + // And, finally a scroll-end. An OverscrollCompleted callback should be + // called and handles should come back. + ui::GestureEvent scroll_end( + 10, + 210, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); + rwhva->OnGestureEvent(&scroll_end); + touch_editable->WaitForOverscrollCompletedCallback(); + EXPECT_TRUE(GetTouchSelectionController(touch_editable)); + + // Now repeat the same sequence, but abort the overscroll by scrolling back + // before ending the scroll. + touch_editable->Reset(); + scroll_begin = ui::GestureEvent( + 10, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0)); + rwhva->OnGestureEvent(&scroll_begin); + + scroll_update = ui::GestureEvent( + 210, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 200, 0)); + rwhva->OnGestureEvent(&scroll_update); + touch_editable->WaitForOverscrollStartedCallback(); + + // Scroll back. + ui::GestureEvent scroll_update2( + 10, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, -200, 0)); + rwhva->OnGestureEvent(&scroll_update2); + // Handles should remain hidden. + EXPECT_FALSE(GetTouchSelectionController(touch_editable)); + + // End the scroll - the overscroll should be cancelled, and we should still + // receive OverscrollCompleted callback + scroll_end = ui::GestureEvent( + 10, + 10, + 0, + ui::EventTimeForNow(), + ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); + rwhva->OnGestureEvent(&scroll_end); + touch_editable->WaitForOverscrollCompletedCallback(); + EXPECT_TRUE(GetTouchSelectionController(touch_editable)); +} + +IN_PROC_BROWSER_TEST_F(TouchEditableImplAuraTest, TouchSelectionOnLongPressTest) { ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); WebContentsImpl* web_contents = |