| OLD | NEW |
| 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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 9 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 class TouchSelectionControllerClientAuraTest : public ContentBrowserTest { | 110 class TouchSelectionControllerClientAuraTest : public ContentBrowserTest { |
| 111 public: | 111 public: |
| 112 TouchSelectionControllerClientAuraTest() {} | 112 TouchSelectionControllerClientAuraTest() {} |
| 113 ~TouchSelectionControllerClientAuraTest() override {} | 113 ~TouchSelectionControllerClientAuraTest() override {} |
| 114 | 114 |
| 115 protected: | 115 protected: |
| 116 // Starts the test server and navigates to the given url. Sets a large enough | 116 // Starts the test server and navigates to the given url. Sets a large enough |
| 117 // size to the root window. Returns after the navigation to the url is | 117 // size to the root window. Returns after the navigation to the url is |
| 118 // complete. | 118 // complete. |
| 119 void StartTestWithPage(const std::string& url) { | 119 void StartTestWithPage(const std::string& url) { |
| 120 ASSERT_TRUE(test_server()->Start()); | 120 ASSERT_TRUE(embedded_test_server()->Start()); |
| 121 GURL test_url(test_server()->GetURL(url)); | 121 GURL test_url(embedded_test_server()->GetURL(url)); |
| 122 NavigateToURL(shell(), test_url); | 122 NavigateToURL(shell(), test_url); |
| 123 aura::Window* content = shell()->web_contents()->GetContentNativeView(); | 123 aura::Window* content = shell()->web_contents()->GetContentNativeView(); |
| 124 content->GetHost()->SetBounds(gfx::Rect(800, 600)); | 124 content->GetHost()->SetBounds(gfx::Rect(800, 600)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool GetPointInsideText(gfx::PointF* point) { | 127 bool GetPointInsideText(gfx::PointF* point) { |
| 128 std::string str; | 128 std::string str; |
| 129 if (ExecuteScriptAndExtractString(shell()->web_contents()->GetMainFrame(), | 129 if (ExecuteScriptAndExtractString(shell()->web_contents()->GetMainFrame(), |
| 130 "get_point_inside_text()", &str)) { | 130 "get_point_inside_text()", &str)) { |
| 131 return JSONToPoint(str, point); | 131 return JSONToPoint(str, point); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 156 | 156 |
| 157 scoped_ptr<TestTouchSelectionMenuRunner> menu_runner_; | 157 scoped_ptr<TestTouchSelectionMenuRunner> menu_runner_; |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAuraTest); | 159 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAuraTest); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 // Tests that long-pressing on a text brings up selection handles and the quick | 162 // Tests that long-pressing on a text brings up selection handles and the quick |
| 163 // menu properly. | 163 // menu properly. |
| 164 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, BasicSelection) { | 164 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, BasicSelection) { |
| 165 // Set the test page up. | 165 // Set the test page up. |
| 166 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 166 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); |
| 167 WebContents* web_contents = | 167 WebContents* web_contents = |
| 168 static_cast<WebContentsImpl*>(shell()->web_contents()); | 168 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 169 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 169 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 170 web_contents->GetRenderWidgetHostView()); | 170 web_contents->GetRenderWidgetHostView()); |
| 171 TestTouchSelectionControllerClientAura* selection_controller_client = | 171 TestTouchSelectionControllerClientAura* selection_controller_client = |
| 172 new TestTouchSelectionControllerClientAura(rwhva); | 172 new TestTouchSelectionControllerClientAura(rwhva); |
| 173 rwhva->SetSelectionControllerClientForTest( | 173 rwhva->SetSelectionControllerClientForTest( |
| 174 make_scoped_ptr(selection_controller_client)); | 174 make_scoped_ptr(selection_controller_client)); |
| 175 | 175 |
| 176 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, | 176 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 195 rwhva->selection_controller()->active_status()); | 195 rwhva->selection_controller()->active_status()); |
| 196 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); | 196 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Tests that tapping in a textfield brings up the insertion handle, but not the | 199 // Tests that tapping in a textfield brings up the insertion handle, but not the |
| 200 // quick menu, initially. Then, successive taps on the insertion handle toggle | 200 // quick menu, initially. Then, successive taps on the insertion handle toggle |
| 201 // the quick menu visibility. | 201 // the quick menu visibility. |
| 202 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, | 202 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, |
| 203 BasicInsertionFollowedByTapsOnHandle) { | 203 BasicInsertionFollowedByTapsOnHandle) { |
| 204 // Set the test page up. | 204 // Set the test page up. |
| 205 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 205 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); |
| 206 WebContents* web_contents = | 206 WebContents* web_contents = |
| 207 static_cast<WebContentsImpl*>(shell()->web_contents()); | 207 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 208 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 208 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 209 web_contents->GetRenderWidgetHostView()); | 209 web_contents->GetRenderWidgetHostView()); |
| 210 TestTouchSelectionControllerClientAura* selection_controller_client = | 210 TestTouchSelectionControllerClientAura* selection_controller_client = |
| 211 new TestTouchSelectionControllerClientAura(rwhva); | 211 new TestTouchSelectionControllerClientAura(rwhva); |
| 212 rwhva->SetSelectionControllerClientForTest( | 212 rwhva->SetSelectionControllerClientForTest( |
| 213 make_scoped_ptr(selection_controller_client)); | 213 make_scoped_ptr(selection_controller_client)); |
| 214 | 214 |
| 215 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, | 215 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 // Tap once more on the insertion handle; the quick menu should disappear. | 250 // Tap once more on the insertion handle; the quick menu should disappear. |
| 251 generator.GestureTapAt(handle_center); | 251 generator.GestureTapAt(handle_center); |
| 252 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); | 252 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Tests that the quick menu is hidden whenever a touch point is active. | 255 // Tests that the quick menu is hidden whenever a touch point is active. |
| 256 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, | 256 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, |
| 257 QuickMenuHiddenOnTouch) { | 257 QuickMenuHiddenOnTouch) { |
| 258 // Set the test page up. | 258 // Set the test page up. |
| 259 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 259 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); |
| 260 WebContents* web_contents = | 260 WebContents* web_contents = |
| 261 static_cast<WebContentsImpl*>(shell()->web_contents()); | 261 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 262 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 262 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 263 web_contents->GetRenderWidgetHostView()); | 263 web_contents->GetRenderWidgetHostView()); |
| 264 TestTouchSelectionControllerClientAura* selection_controller_client = | 264 TestTouchSelectionControllerClientAura* selection_controller_client = |
| 265 new TestTouchSelectionControllerClientAura(rwhva); | 265 new TestTouchSelectionControllerClientAura(rwhva); |
| 266 rwhva->SetSelectionControllerClientForTest( | 266 rwhva->SetSelectionControllerClientForTest( |
| 267 make_scoped_ptr(selection_controller_client)); | 267 make_scoped_ptr(selection_controller_client)); |
| 268 | 268 |
| 269 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, | 269 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Lift the second finger up: the quick menu should re-appear. | 312 // Lift the second finger up: the quick menu should re-appear. |
| 313 generator.ReleaseTouchId(1); | 313 generator.ReleaseTouchId(1); |
| 314 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, | 314 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, |
| 315 rwhva->selection_controller()->active_status()); | 315 rwhva->selection_controller()->active_status()); |
| 316 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); | 316 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Tests that the quick menu and touch handles are hidden during an scroll. | 319 // Tests that the quick menu and touch handles are hidden during an scroll. |
| 320 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, HiddenOnScroll) { | 320 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, HiddenOnScroll) { |
| 321 // Set the test page up. | 321 // Set the test page up. |
| 322 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 322 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); |
| 323 WebContents* web_contents = | 323 WebContents* web_contents = |
| 324 static_cast<WebContentsImpl*>(shell()->web_contents()); | 324 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 325 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 325 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 326 web_contents->GetRenderWidgetHostView()); | 326 web_contents->GetRenderWidgetHostView()); |
| 327 TestTouchSelectionControllerClientAura* selection_controller_client = | 327 TestTouchSelectionControllerClientAura* selection_controller_client = |
| 328 new TestTouchSelectionControllerClientAura(rwhva); | 328 new TestTouchSelectionControllerClientAura(rwhva); |
| 329 rwhva->SetSelectionControllerClientForTest( | 329 rwhva->SetSelectionControllerClientForTest( |
| 330 make_scoped_ptr(selection_controller_client)); | 330 make_scoped_ptr(selection_controller_client)); |
| 331 ui::TouchSelectionControllerTestApi selection_controller_test_api( | 331 ui::TouchSelectionControllerTestApi selection_controller_test_api( |
| 332 rwhva->selection_controller()); | 332 rwhva->selection_controller()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, | 391 EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE, |
| 392 rwhva->selection_controller()->active_status()); | 392 rwhva->selection_controller()->active_status()); |
| 393 EXPECT_FALSE(selection_controller_test_api.temporarily_hidden()); | 393 EXPECT_FALSE(selection_controller_test_api.temporarily_hidden()); |
| 394 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); | 394 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // Tests that touch selection gets deactivated after an overscroll completes. | 397 // Tests that touch selection gets deactivated after an overscroll completes. |
| 398 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, | 398 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, |
| 399 HiddenAfterOverscroll) { | 399 HiddenAfterOverscroll) { |
| 400 // Set the page up. | 400 // Set the page up. |
| 401 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/touch_selection.html")); | 401 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); |
| 402 WebContents* web_contents = | 402 WebContents* web_contents = |
| 403 static_cast<WebContentsImpl*>(shell()->web_contents()); | 403 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 404 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( | 404 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 405 web_contents->GetRenderWidgetHostView()); | 405 web_contents->GetRenderWidgetHostView()); |
| 406 TestTouchSelectionControllerClientAura* selection_controller_client = | 406 TestTouchSelectionControllerClientAura* selection_controller_client = |
| 407 new TestTouchSelectionControllerClientAura(rwhva); | 407 new TestTouchSelectionControllerClientAura(rwhva); |
| 408 rwhva->SetSelectionControllerClientForTest( | 408 rwhva->SetSelectionControllerClientForTest( |
| 409 make_scoped_ptr(selection_controller_client)); | 409 make_scoped_ptr(selection_controller_client)); |
| 410 | 410 |
| 411 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, | 411 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 rwhva->OnGestureEvent(&scroll_end); | 450 rwhva->OnGestureEvent(&scroll_end); |
| 451 | 451 |
| 452 selection_controller_client->Wait(); | 452 selection_controller_client->Wait(); |
| 453 | 453 |
| 454 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, | 454 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, |
| 455 rwhva->selection_controller()->active_status()); | 455 rwhva->selection_controller()->active_status()); |
| 456 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); | 456 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 } // namespace content | 459 } // namespace content |
| OLD | NEW |