1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/renderer_host/input/touch_selection_controller_client_aura.h"
#include "base/command_line.h"
#include "base/json/json_reader.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/test/test_timeouts.h"
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "content/browser/renderer_host/render_widget_host_view_child_frame.h"
#include "content/browser/renderer_host/render_widget_host_view_event_handler.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/frame_messages.h"
#include "content/public/browser/overscroll_configuration.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/public/test/scoped_overscroll_modes.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/display_switches.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/touch_selection/touch_selection_controller_test_api.h"
namespace content {
namespace {
bool JSONToPoint(const std::string& str, gfx::PointF* point) {
std::unique_ptr<base::Value> value = base::JSONReader::Read(str);
if (!value)
return false;
base::DictionaryValue* root;
if (!value->GetAsDictionary(&root))
return false;
double x, y;
if (!root->GetDouble("x", &x))
return false;
if (!root->GetDouble("y", &y))
return false;
point->set_x(x);
point->set_y(y);
return true;
}
// A mock touch selection menu runner to use whenever a default one is not
// installed.
class TestTouchSelectionMenuRunner : public ui::TouchSelectionMenuRunner {
public:
TestTouchSelectionMenuRunner() : menu_opened_(false) {}
~TestTouchSelectionMenuRunner() override {}
private:
bool IsMenuAvailable(
const ui::TouchSelectionMenuClient* client) const override {
return true;
}
void OpenMenu(ui::TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect,
const gfx::Size& handle_image_size,
aura::Window* context) override {
menu_opened_ = true;
}
void CloseMenu() override { menu_opened_ = false; }
bool IsRunning() const override { return menu_opened_; }
bool menu_opened_;
DISALLOW_COPY_AND_ASSIGN(TestTouchSelectionMenuRunner);
};
} // namespace
class TestTouchSelectionControllerClientAura
: public TouchSelectionControllerClientAura {
public:
explicit TestTouchSelectionControllerClientAura(
RenderWidgetHostViewAura* rwhva)
: TouchSelectionControllerClientAura(rwhva),
expected_event_(ui::SELECTION_HANDLES_SHOWN) {
show_quick_menu_immediately_for_test_ = true;
}
~TestTouchSelectionControllerClientAura() override {}
void InitWaitForSelectionEvent(ui::SelectionEventType expected_event) {
DCHECK(!run_loop_);
expected_event_ = expected_event;
run_loop_.reset(new base::RunLoop());
}
void Wait() {
DCHECK(run_loop_);
run_loop_->Run();
run_loop_.reset();
}
private:
// TouchSelectionControllerClientAura:
void OnSelectionEvent(ui::SelectionEventType event) override {
TouchSelectionControllerClientAura::OnSelectionEvent(event);
if (run_loop_ && event == expected_event_)
run_loop_->Quit();
}
bool IsCommandIdEnabled(int command_id) const override {
// Return true so that quick menu has something to show.
return true;
}
ui::SelectionEventType expected_event_;
std::unique_ptr<base::RunLoop> run_loop_;
DISALLOW_COPY_AND_ASSIGN(TestTouchSelectionControllerClientAura);
};
class TouchSelectionControllerClientAuraTest : public ContentBrowserTest {
public:
TouchSelectionControllerClientAuraTest() {}
~TouchSelectionControllerClientAuraTest() override {}
protected:
// Starts the test server and navigates to the given url. Sets a large enough
// size to the root window. Returns after the navigation to the url is
// complete.
void StartTestWithPage(const std::string& url) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL test_url(embedded_test_server()->GetURL(url));
NavigateToURL(shell(), test_url);
aura::Window* content = shell()->web_contents()->GetContentNativeView();
content->GetHost()->SetBoundsInPixels(gfx::Rect(800, 600));
}
bool GetPointInsideText(gfx::PointF* point) {
std::string str;
if (ExecuteScriptAndExtractString(shell(), "get_point_inside_text()",
&str)) {
return JSONToPoint(str, point);
}
return false;
}
bool GetPointInsideTextfield(gfx::PointF* point) {
std::string str;
if (ExecuteScriptAndExtractString(shell(), "get_point_inside_textfield()",
&str)) {
return JSONToPoint(str, point);
}
return false;
}
RenderWidgetHostViewAura* GetRenderWidgetHostViewAura() {
return static_cast<RenderWidgetHostViewAura*>(
shell()->web_contents()->GetRenderWidgetHostView());
}
TestTouchSelectionControllerClientAura* selection_controller_client() {
return selection_controller_client_;
}
void InitSelectionController() {
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
selection_controller_client_ =
new TestTouchSelectionControllerClientAura(rwhva);
rwhva->SetSelectionControllerClientForTest(
base::WrapUnique(selection_controller_client_));
rwhva->event_handler()->disable_input_event_router_for_testing();
}
protected:
void SetUpOnMainThread() override {
ContentBrowserTest::SetUpOnMainThread();
if (!ui::TouchSelectionMenuRunner::GetInstance())
menu_runner_.reset(new TestTouchSelectionMenuRunner);
}
private:
void TearDownOnMainThread() override {
menu_runner_ = nullptr;
selection_controller_client_ = nullptr;
ContentBrowserTest::TearDownOnMainThread();
}
std::unique_ptr<TestTouchSelectionMenuRunner> menu_runner_;
TestTouchSelectionControllerClientAura* selection_controller_client_ =
nullptr;
DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAuraTest);
};
// Tests that long-pressing on a text brings up selection handles and the quick
// menu properly.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, BasicSelection) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Long-press on the text and wait for handles to appear.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideText(&point));
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
long_press_details);
rwhva->OnGestureEvent(&long_press);
selection_controller_client()->Wait();
// Check that selection is active and the quick menu is showing.
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
class GestureLongPressWaiter : public RenderWidgetHost::InputEventObserver {
public:
GestureLongPressWaiter(RenderWidgetHost* rwh)
: rwh_(static_cast<RenderWidgetHostImpl*>(rwh)->GetWeakPtr()),
gesture_long_press_seen_(false) {
rwh->AddInputEventObserver(this);
}
~GestureLongPressWaiter() override {
if (rwh_)
rwh_->RemoveInputEventObserver(this);
}
void OnInputEventAck(InputEventAckSource,
InputEventAckState,
const blink::WebInputEvent& event) override {
if (event.GetType() == blink::WebInputEvent::kGestureLongPress) {
gesture_long_press_seen_ = true;
if (run_loop_)
run_loop_->Quit();
}
}
void Wait() {
if (gesture_long_press_seen_)
return;
run_loop_.reset(new base::RunLoop);
run_loop_->Run();
run_loop_.reset();
}
private:
base::WeakPtr<RenderWidgetHostImpl> rwh_;
std::unique_ptr<base::RunLoop> run_loop_;
bool gesture_long_press_seen_;
};
class TouchSelectionControllerClientAuraSiteIsolationTest
: public TouchSelectionControllerClientAuraTest,
public testing::WithParamInterface<bool> {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
IsolateAllSitesForTesting(command_line);
}
void SetUpOnMainThread() override {
TouchSelectionControllerClientAuraTest::SetUpOnMainThread();
host_resolver()->AddRule("*", "127.0.0.1");
SetupCrossSiteRedirector(embedded_test_server());
ASSERT_TRUE(embedded_test_server()->Start());
}
void SelectWithLongPress(gfx::Point point,
RenderWidgetHostViewBase* expected_target) {
// Get main frame view for event insertion.
RenderWidgetHostViewAura* main_view = GetRenderWidgetHostViewAura();
SendTouch(main_view, ui::ET_TOUCH_PRESSED, point);
SendTouch(main_view, ui::ET_TOUCH_RELEASED, point);
SendGestureTap(main_view, point);
// Since our hit-testing is now asynchronous, wait for the Ack to come
// back before proceeding.
GestureLongPressWaiter long_press_waiter(
expected_target->GetRenderWidgetHost());
SendGestureLongPress(main_view, point);
long_press_waiter.Wait();
}
void SimpleTap(gfx::Point point) {
// Get main frame view for event insertion.
RenderWidgetHostViewAura* main_view = GetRenderWidgetHostViewAura();
SendTouch(main_view, ui::ET_TOUCH_PRESSED, point);
SendTouch(main_view, ui::ET_TOUCH_RELEASED, point);
SendGestureTap(main_view, point);
}
private:
void SendTouch(RenderWidgetHostViewAura* view,
ui::EventType type,
gfx::Point point) {
DCHECK(type >= ui::ET_TOUCH_RELEASED && type << ui::ET_TOUCH_CANCELLED);
ui::TouchEvent touch(
type, point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
view->OnTouchEvent(&touch);
}
void SendGestureTap(RenderWidgetHostViewAura* view, gfx::Point point) {
ui::GestureEventDetails tap_down_details(ui::ET_GESTURE_TAP_DOWN);
tap_down_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent gesture_tap_down(point.x(), point.y(), 0,
ui::EventTimeForNow(), tap_down_details);
view->OnGestureEvent(&gesture_tap_down);
ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
tap_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
tap_details.set_tap_count(1);
ui::GestureEvent gesture_tap(point.x(), point.y(), 0, ui::EventTimeForNow(),
tap_details);
view->OnGestureEvent(&gesture_tap);
}
void SendGestureLongPress(RenderWidgetHostViewAura* view, gfx::Point point) {
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent gesture_long_press(
point.x(), point.y(), 0, ui::EventTimeForNow(), long_press_details);
view->OnGestureEvent(&gesture_long_press);
}
};
class FrameStableObserver {
public:
FrameStableObserver(RenderWidgetHostViewBase* view, base::TimeDelta delta)
: view_(view), delta_(delta) {}
virtual ~FrameStableObserver() {}
void WaitUntilStable() {
uint32_t current_frame_number = view_->RendererFrameNumber();
uint32_t previous_frame_number;
do {
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), delta_);
run_loop.Run();
previous_frame_number = current_frame_number;
current_frame_number = view_->RendererFrameNumber();
} while (current_frame_number != previous_frame_number);
}
private:
RenderWidgetHostViewBase* view_;
base::TimeDelta delta_;
DISALLOW_COPY_AND_ASSIGN(FrameStableObserver);
};
INSTANTIATE_TEST_CASE_P(TouchSelectionForCrossProcessFramesTests,
TouchSelectionControllerClientAuraSiteIsolationTest,
testing::Bool());
IN_PROC_BROWSER_TEST_P(TouchSelectionControllerClientAuraSiteIsolationTest,
BasicSelectionIsolatedIframe) {
GURL test_url(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(a)"));
EXPECT_TRUE(NavigateToURL(shell(), test_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root();
EXPECT_EQ(
" Site A\n"
" +--Site A\n"
"Where A = http://a.com/",
FrameTreeVisualizer().DepictFrameTree(root));
TestNavigationObserver observer(shell()->web_contents());
EXPECT_EQ(1u, root->child_count());
FrameTreeNode* child = root->child_at(0);
RenderWidgetHostViewAura* parent_view =
static_cast<RenderWidgetHostViewAura*>(
root->current_frame_host()->GetRenderWidgetHost()->GetView());
TestTouchSelectionControllerClientAura* parent_selection_controller_client =
new TestTouchSelectionControllerClientAura(parent_view);
parent_view->SetSelectionControllerClientForTest(
base::WrapUnique(parent_selection_controller_client));
// We need to load the desired subframe and then wait until it's stable, i.e.
// generates no new frames for some reasonable time period: a stray frame
// between touch selection's pre-handling of GestureLongPress and the
// expected frame containing the selected region can confuse the
// TouchSelectionController, causing it to fail to show selection handles.
// Note this is an issue with the TouchSelectionController in general, and
// not a property of this test.
GURL child_url(
embedded_test_server()->GetURL("b.com", "/touch_selection.html"));
NavigateFrameToURL(child, child_url);
EXPECT_EQ(
" Site A ------------ proxies for B\n"
" +--Site B ------- proxies for A\n"
"Where A = http://a.com/\n"
" B = http://b.com/",
FrameTreeVisualizer().DepictFrameTree(root));
// The child will change with the cross-site navigation. It shouldn't change
// after this.
child = root->child_at(0);
WaitForHitTestDataOrChildSurfaceReady(child->current_frame_host());
RenderWidgetHostViewChildFrame* child_view =
static_cast<RenderWidgetHostViewChildFrame*>(
child->current_frame_host()->GetRenderWidgetHost()->GetView());
EXPECT_EQ(child_url, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded());
FrameStableObserver child_frame_stable_observer(child_view,
TestTimeouts::tiny_timeout());
child_frame_stable_observer.WaitUntilStable();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
parent_view->selection_controller()->active_status());
// Find the location of some text to select.
gfx::PointF point_f;
std::string str;
EXPECT_TRUE(ExecuteScriptAndExtractString(child->current_frame_host(),
"get_point_inside_text()", &str));
JSONToPoint(str, &point_f);
point_f = child_view->TransformPointToRootCoordSpaceF(point_f);
// Initiate selection with a sequence of events that go through the targeting
// system.
parent_selection_controller_client->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
SelectWithLongPress(gfx::Point(point_f.x(), point_f.y()), child_view);
parent_selection_controller_client->Wait();
// Check that selection is active and the quick menu is showing.
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
parent_view->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Tap inside/outside the iframe and make sure the selection handles go away.
parent_selection_controller_client->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_CLEARED);
if (GetParam()) {
gfx::PointF point_outside_iframe =
child_view->TransformPointToRootCoordSpaceF(gfx::PointF(-1.f, -1.f));
SimpleTap(gfx::Point(point_outside_iframe.x(), point_outside_iframe.y()));
} else {
gfx::PointF point_inside_iframe =
child_view->TransformPointToRootCoordSpaceF(gfx::PointF(+1.f, +1.f));
SimpleTap(gfx::Point(point_inside_iframe.x(), point_inside_iframe.y()));
}
parent_selection_controller_client->Wait();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
parent_view->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
IN_PROC_BROWSER_TEST_P(TouchSelectionControllerClientAuraSiteIsolationTest,
BasicSelectionIsolatedScrollMainframe) {
GURL test_url(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(a)"));
EXPECT_TRUE(NavigateToURL(shell(), test_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetFrameTree()
->root();
EXPECT_EQ(
" Site A\n"
" +--Site A\n"
"Where A = http://a.com/",
FrameTreeVisualizer().DepictFrameTree(root));
TestNavigationObserver observer(shell()->web_contents());
EXPECT_EQ(1u, root->child_count());
FrameTreeNode* child = root->child_at(0);
// Make sure mainframe can scroll.
EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
"document.body.style.height = '900px'; "
"document.body.style.overFlowY = 'scroll';"));
RenderWidgetHostViewAura* parent_view =
static_cast<RenderWidgetHostViewAura*>(
root->current_frame_host()->GetRenderWidgetHost()->GetView());
TestTouchSelectionControllerClientAura* parent_selection_controller_client =
new TestTouchSelectionControllerClientAura(parent_view);
parent_view->SetSelectionControllerClientForTest(
base::WrapUnique(parent_selection_controller_client));
// We need to load the desired subframe and then wait until it's stable, i.e.
// generates no new frames for some reasonable time period: a stray frame
// between touch selection's pre-handling of GestureLongPress and the
// expected frame containing the selected region can confuse the
// TouchSelectionController, causing it to fail to show selection handles.
// Note this is an issue with the TouchSelectionController in general, and
// not a property of this test.
GURL child_url(
embedded_test_server()->GetURL("b.com", "/touch_selection.html"));
NavigateFrameToURL(child, child_url);
EXPECT_EQ(
" Site A ------------ proxies for B\n"
" +--Site B ------- proxies for A\n"
"Where A = http://a.com/\n"
" B = http://b.com/",
FrameTreeVisualizer().DepictFrameTree(root));
// The child will change with the cross-site navigation. It shouldn't change
// after this.
child = root->child_at(0);
WaitForHitTestDataOrChildSurfaceReady(child->current_frame_host());
RenderWidgetHostViewChildFrame* child_view =
static_cast<RenderWidgetHostViewChildFrame*>(
child->current_frame_host()->GetRenderWidgetHost()->GetView());
EXPECT_EQ(child_url, observer.last_navigation_url());
EXPECT_TRUE(observer.last_navigation_succeeded());
FrameStableObserver child_frame_stable_observer(child_view,
TestTimeouts::tiny_timeout());
child_frame_stable_observer.WaitUntilStable();
ui::TouchSelectionController* selection_controller =
parent_view->selection_controller();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
selection_controller->active_status());
ui::TouchSelectionControllerTestApi selection_controller_test_api(
selection_controller);
scoped_refptr<SynchronizeVisualPropertiesMessageFilter> filter =
new SynchronizeVisualPropertiesMessageFilter();
root->current_frame_host()->GetProcess()->AddFilter(filter.get());
// Find the location of some text to select.
gfx::PointF point_f;
std::string str;
EXPECT_TRUE(ExecuteScriptAndExtractString(child->current_frame_host(),
"get_point_inside_text()", &str));
JSONToPoint(str, &point_f);
point_f = child_view->TransformPointToRootCoordSpaceF(point_f);
// Initiate selection with a sequence of events that go through the targeting
// system.
parent_selection_controller_client->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
SelectWithLongPress(gfx::Point(point_f.x(), point_f.y()), child_view);
parent_selection_controller_client->Wait();
// Check that selection is active and the quick menu is showing.
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
selection_controller->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
gfx::Point scroll_start_position(10, 10);
gfx::Point scroll_end_position(10, 0);
// Initiate a touch scroll of the main frame, and make sure when the selection
// handles re-appear make sure they have the correct location.
// 1) Send touch-down.
ui::TouchEvent touch_down(
ui::ET_TOUCH_PRESSED, scroll_start_position, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
parent_view->OnTouchEvent(&touch_down);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
selection_controller->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
gfx::PointF initial_start_handle_position =
selection_controller->GetStartPosition();
// 2) Send touch-move.
ui::TouchEvent touch_move(
ui::ET_TOUCH_MOVED, scroll_end_position, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
parent_view->OnTouchEvent(&touch_move);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
selection_controller->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Start scrolling: touch handles should get hidden, while touch selection is
// still active.
ui::GestureEventDetails scroll_begin_details(ui::ET_GESTURE_SCROLL_BEGIN);
scroll_begin_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_begin(scroll_start_position.x(),
scroll_start_position.y(), 0,
ui::EventTimeForNow(), scroll_begin_details);
parent_view->OnGestureEvent(&scroll_begin);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
parent_view->selection_controller()->active_status());
EXPECT_TRUE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// GestureScrollUpdate
gfx::Vector2dF scroll_delta = scroll_end_position - scroll_start_position;
ui::GestureEventDetails scroll_update_details(
ui::ET_GESTURE_SCROLL_UPDATE, scroll_delta.x(), scroll_delta.y());
scroll_update_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_update(scroll_start_position.x(),
scroll_start_position.y(), 0,
ui::EventTimeForNow(), scroll_update_details);
parent_view->OnGestureEvent(&scroll_update);
EXPECT_TRUE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Make sure we wait for the scroll to actually happen.
filter->WaitForRect();
// Since the check below that compares the scroll_delta to the actual handle
// movement requires use of TransformPointToRootCoordSpaceF() in
// TouchSelectionControllerClientChildFrame::DidScroll(), we need to
// make sure the post-scroll frames have rendered before the transform
// can be trusted. This may point out a general concern with the timing
// of the main-frame's did-stop-flinging IPC and the rendering of the
// child frame's compositor frame.
child_frame_stable_observer.WaitUntilStable();
// End scrolling: touch handles should re-appear.
ui::GestureEventDetails scroll_end_details(ui::ET_GESTURE_SCROLL_END);
scroll_end_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_end(scroll_end_position.x(), scroll_end_position.y(),
0, ui::EventTimeForNow(), scroll_end_details);
parent_view->OnGestureEvent(&scroll_end);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
parent_view->selection_controller()->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// 3) Send touch-end.
ui::TouchEvent touch_up(
ui::ET_TOUCH_RELEASED, scroll_end_position, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
parent_view->OnTouchEvent(&touch_up);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
selection_controller->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Make sure handles have moved.
gfx::PointF final_start_handle_position =
selection_controller->GetStartPosition();
EXPECT_EQ(scroll_delta,
final_start_handle_position - initial_start_handle_position);
}
// Tests that tapping in a textfield brings up the insertion handle, but not the
// quick menu, initially. Then, successive taps on the insertion handle toggle
// the quick menu visibility.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
BasicInsertionFollowedByTapsOnHandle) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
gfx::NativeView native_view = rwhva->GetNativeView();
ui::test::EventGenerator generator(native_view->GetRootWindow());
// Tap inside the textfield and wait for the insertion handle to appear.
selection_controller_client()->InitWaitForSelectionEvent(
ui::INSERTION_HANDLE_SHOWN);
gfx::PointF point_f;
ASSERT_TRUE(GetPointInsideTextfield(&point_f));
gfx::Point point = gfx::ToRoundedPoint(point_f);
generator.delegate()->ConvertPointFromTarget(native_view, &point);
generator.GestureTapAt(point);
selection_controller_client()->Wait();
// Check that insertion is active, but the quick menu is not showing.
EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Tap on the insertion handle; the quick menu should appear.
gfx::Point handle_center = gfx::ToRoundedPoint(
rwhva->selection_controller()->GetStartHandleRect().CenterPoint());
generator.delegate()->ConvertPointFromTarget(native_view, &handle_center);
generator.GestureTapAt(handle_center);
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Tap once more on the insertion handle; the quick menu should disappear.
generator.GestureTapAt(handle_center);
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
// Tests that the quick menu is hidden whenever a touch point is active.
// Flaky: https://crbug.com/803576
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
DISABLED_QuickMenuHiddenOnTouch) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Long-press on the text and wait for selection handles to appear.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideText(&point));
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
long_press_details);
rwhva->OnGestureEvent(&long_press);
selection_controller_client()->Wait();
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
ui::test::EventGenerator generator(rwhva->GetNativeView()->GetRootWindow(),
rwhva->GetNativeView());
// Put the first finger down: the quick menu should get hidden.
generator.PressTouchId(0);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Put a second finger down: the quick menu should remain hidden.
generator.PressTouchId(1);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Lift the first finger up: the quick menu should still remain hidden.
generator.ReleaseTouchId(0);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Lift the second finger up: the quick menu should re-appear.
generator.ReleaseTouchId(1);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
// Tests that the quick menu and touch handles are hidden during an scroll.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, HiddenOnScroll) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
ui::TouchSelectionControllerTestApi selection_controller_test_api(
rwhva->selection_controller());
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Long-press on the text and wait for selection handles to appear.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideText(&point));
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
long_press_details);
rwhva->OnGestureEvent(&long_press);
selection_controller_client()->Wait();
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Put a finger down: the quick menu should go away, while touch handles stay
// there.
ui::TouchEvent touch_down(
ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_down);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Start scrolling: touch handles should get hidden, while touch selection is
// still active.
ui::GestureEventDetails scroll_begin_details(ui::ET_GESTURE_SCROLL_BEGIN);
scroll_begin_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_begin(10, 10, 0, ui::EventTimeForNow(),
scroll_begin_details);
rwhva->OnGestureEvent(&scroll_begin);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// End scrolling: touch handles should re-appear.
ui::GestureEventDetails scroll_end_details(ui::ET_GESTURE_SCROLL_END);
scroll_end_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_end(10, 10, 0, ui::EventTimeForNow(),
scroll_end_details);
rwhva->OnGestureEvent(&scroll_end);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Lift the finger up: the quick menu should re-appear.
ui::TouchEvent touch_up(
ui::ET_TOUCH_RELEASED, gfx::Point(10, 10), ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_up);
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(selection_controller_test_api.temporarily_hidden());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
// Tests that touch selection gets deactivated after an overscroll completes.
// This only happens in the gesture nav with parallax effect.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
HiddenAfterOverscroll) {
ScopedHistoryNavigationMode scoped_mode(
OverscrollConfig::HistoryNavigationMode::kParallaxUi);
// Set the page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Long-press on the text and wait for touch handles to appear.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideText(&point));
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
long_press_details);
rwhva->OnGestureEvent(&long_press);
selection_controller_client()->Wait();
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Scroll such that an overscroll is initiated and wait for it to complete:
// touch selection should not be active at the end.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_CLEARED);
float event_x = 10.f;
const float event_y = 10.f;
ui::GestureEventDetails scroll_begin_details(ui::ET_GESTURE_SCROLL_BEGIN);
scroll_begin_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_begin(event_x, event_y, 0, ui::EventTimeForNow(),
scroll_begin_details);
rwhva->OnGestureEvent(&scroll_begin);
const int window_width = rwhva->GetNativeView()->bounds().width();
const float overscroll_threshold = OverscrollConfig::GetThreshold(
OverscrollConfig::Threshold::kStartTouchscreen);
const float scroll_amount = window_width * overscroll_threshold + 1;
event_x += scroll_amount;
ui::GestureEventDetails scroll_update_details(ui::ET_GESTURE_SCROLL_UPDATE,
scroll_amount, 0);
scroll_update_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_update(event_x, event_y, 0, ui::EventTimeForNow(),
scroll_update_details);
rwhva->OnGestureEvent(&scroll_update);
ui::GestureEventDetails scroll_end_details(ui::ET_GESTURE_SCROLL_END);
scroll_end_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent scroll_end(event_x, event_y, 0, ui::EventTimeForNow(),
scroll_end_details);
rwhva->OnGestureEvent(&scroll_end);
selection_controller_client()->Wait();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
}
class TouchSelectionControllerClientAuraScaleFactorTest
: public TouchSelectionControllerClientAuraTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2");
}
};
#if defined(OS_WIN)
// High DPI tests are disabled on Windows due to crbug.com/545547.
#define MAYBE_SelectionHandleCoordinates DISABLED_SelectionHandleCoordinates
#define MAYBE_InsertionHandleCoordinates DISABLED_InsertionHandleCoordinates
#else
#define MAYBE_SelectionHandleCoordinates SelectionHandleCoordinates
#define MAYBE_InsertionHandleCoordinates InsertionHandleCoordinates
#endif
// Tests that selection handles are properly positioned at 2x DSF.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraScaleFactorTest,
MAYBE_SelectionHandleCoordinates) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
EXPECT_EQ(2.f, rwhva->current_device_scale_factor());
// Long-press on the text and wait for handles to appear.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideText(&point));
ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
long_press_details);
rwhva->OnGestureEvent(&long_press);
selection_controller_client()->Wait();
// Check that selection is active and the quick menu is showing.
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
const ui::TouchSelectionController* controller =
GetRenderWidgetHostViewAura()->selection_controller();
gfx::PointF start_top = controller->start().edge_top();
// The selection start should be uppper left, and selection end should be
// upper right.
EXPECT_LT(controller->start().edge_top().x(), point.x());
EXPECT_LT(controller->start().edge_bottom().x(), point.x());
EXPECT_LT(point.x(), controller->end().edge_top().x());
EXPECT_LT(point.x(), controller->end().edge_bottom().x());
// Handles are created below the selection. The top position should roughly
// be within the handle size from the touch position.
float handle_size = controller->start().edge_bottom().y() -
controller->start().edge_top().y();
float handle_max_bottom = point.y() + handle_size;
EXPECT_GT(handle_max_bottom, controller->start().edge_top().y());
EXPECT_GT(handle_max_bottom, controller->end().edge_top().y());
gfx::Point handle_point = gfx::ToRoundedPoint(
rwhva->selection_controller()->GetStartHandleRect().CenterPoint());
// Move the selection handle. Touch the handle first.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLE_DRAG_STARTED);
ui::TouchEvent touch_down(
ui::ET_TOUCH_PRESSED, handle_point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_down);
selection_controller_client()->Wait();
// Move it.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLES_MOVED);
handle_point.Offset(10, 0);
ui::TouchEvent touch_move(
ui::ET_TOUCH_MOVED, handle_point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_move);
selection_controller_client()->Wait();
// Then release.
selection_controller_client()->InitWaitForSelectionEvent(
ui::SELECTION_HANDLE_DRAG_STOPPED);
ui::TouchEvent touch_up(
ui::ET_TOUCH_RELEASED, handle_point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_up);
selection_controller_client()->Wait();
// The handle should have moved to right.
EXPECT_EQ(start_top.y(), controller->start().edge_top().y());
EXPECT_LT(start_top.x(), controller->start().edge_top().x());
EXPECT_EQ(ui::TouchSelectionController::SELECTION_ACTIVE,
rwhva->selection_controller()->active_status());
}
// Tests that insertion handles are properly positioned at 2x DSF.
IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraScaleFactorTest,
MAYBE_InsertionHandleCoordinates) {
// Set the test page up.
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
InitSelectionController();
RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
// Tap inside the textfield and wait for the insertion cursor.
selection_controller_client()->InitWaitForSelectionEvent(
ui::INSERTION_HANDLE_SHOWN);
gfx::PointF point;
ASSERT_TRUE(GetPointInsideTextfield(&point));
ui::GestureEventDetails gesture_tap_down_details(ui::ET_GESTURE_TAP_DOWN);
gesture_tap_down_details.set_device_type(
ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
ui::GestureEvent gesture_tap_down(2, 2, 0, ui::EventTimeForNow(),
gesture_tap_down_details);
rwhva->OnGestureEvent(&gesture_tap_down);
ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
tap_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
tap_details.set_tap_count(1);
ui::GestureEvent tap(point.x(), point.y(), 0, ui::EventTimeForNow(),
tap_details);
rwhva->OnGestureEvent(&tap);
selection_controller_client()->Wait();
EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
rwhva->selection_controller()->active_status());
gfx::RectF initial_handle_rect =
rwhva->selection_controller()->GetStartHandleRect();
// Move the insertion handle. Touch the handle first.
gfx::Point handle_point =
gfx::ToRoundedPoint(initial_handle_rect.CenterPoint());
selection_controller_client()->InitWaitForSelectionEvent(
ui::INSERTION_HANDLE_DRAG_STARTED);
ui::TouchEvent touch_down(
ui::ET_TOUCH_PRESSED, handle_point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_down);
selection_controller_client()->Wait();
// Move it.
selection_controller_client()->InitWaitForSelectionEvent(
ui::INSERTION_HANDLE_MOVED);
handle_point.Offset(10, 0);
ui::TouchEvent touch_move(
ui::ET_TOUCH_MOVED, handle_point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_move);
selection_controller_client()->Wait();
// Then release.
selection_controller_client()->InitWaitForSelectionEvent(
ui::INSERTION_HANDLE_DRAG_STOPPED);
ui::TouchEvent touch_up(
ui::ET_TOUCH_RELEASED, handle_point, ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
rwhva->OnTouchEvent(&touch_up);
selection_controller_client()->Wait();
gfx::RectF moved_handle_rect =
rwhva->selection_controller()->GetStartHandleRect();
// The handle should have moved to right.
EXPECT_EQ(initial_handle_rect.y(), moved_handle_rect.y());
EXPECT_LT(initial_handle_rect.x(), moved_handle_rect.x());
EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
rwhva->selection_controller()->active_status());
}
} // namespace content
|