Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 2186983002: Re-route Touchscreen GesturePinch events to root view. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_input_event_router.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/site_per_process_browsertest.h" 5 #include "content/browser/site_per_process_browsertest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 172 }
173 RenderWidgetHost* host_; 173 RenderWidgetHost* host_;
174 bool event_received_; 174 bool event_received_;
175 blink::WebMouseEvent event_; 175 blink::WebMouseEvent event_;
176 176
177 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostMouseEventMonitor); 177 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostMouseEventMonitor);
178 }; 178 };
179 179
180 class TestInputEventObserver : public RenderWidgetHost::InputEventObserver { 180 class TestInputEventObserver : public RenderWidgetHost::InputEventObserver {
181 public: 181 public:
182 explicit TestInputEventObserver(RenderWidgetHost* host) 182 explicit TestInputEventObserver(RenderWidgetHost* host) : host_(host) {
183 : host_(host),
184 event_received_(false),
185 last_event_type_(blink::WebInputEvent::Undefined) {
186 host_->AddInputEventObserver(this); 183 host_->AddInputEventObserver(this);
187 } 184 }
188 185
189 ~TestInputEventObserver() override { host_->RemoveInputEventObserver(this); } 186 ~TestInputEventObserver() override { host_->RemoveInputEventObserver(this); }
190 187
191 bool EventWasReceived() const { return event_received_; } 188 bool EventWasReceived() const { return !events_received_.empty(); }
192 void ResetEventReceived() { event_received_ = false; } 189 void ResetEventsReceived() { events_received_.clear(); }
193 blink::WebInputEvent::Type EventType() const { return last_event_type_; } 190 blink::WebInputEvent::Type EventType() const {
191 DCHECK(EventWasReceived());
192 return events_received_.front();
193 }
194 const std::vector<blink::WebInputEvent::Type>& events_received() {
195 return events_received_;
196 }
194 197
195 void OnInputEvent(const blink::WebInputEvent& event) override { 198 void OnInputEvent(const blink::WebInputEvent& event) override {
196 event_received_ = true; 199 events_received_.push_back(event.type);
197 last_event_type_ = event.type;
198 }; 200 };
199 201
202 private:
200 RenderWidgetHost* host_; 203 RenderWidgetHost* host_;
201 bool event_received_; 204 std::vector<blink::WebInputEvent::Type> events_received_;
202 blink::WebInputEvent::Type last_event_type_;
203 205
204 DISALLOW_COPY_AND_ASSIGN(TestInputEventObserver); 206 DISALLOW_COPY_AND_ASSIGN(TestInputEventObserver);
205 }; 207 };
206 208
207 // Helper function that performs a surface hittest. 209 // Helper function that performs a surface hittest.
208 void SurfaceHitTestTestHelper( 210 void SurfaceHitTestTestHelper(
209 Shell* shell, 211 Shell* shell,
210 net::test_server::EmbeddedTestServer* embedded_test_server) { 212 net::test_server::EmbeddedTestServer* embedded_test_server) {
211 GURL main_url(embedded_test_server->GetURL( 213 GURL main_url(embedded_test_server->GetURL(
212 "/frame_tree/page_with_positioned_frame.html")); 214 "/frame_tree/page_with_positioned_frame.html"));
(...skipping 7280 matching lines...) Expand 10 before | Expand all | Expand 10 after
7493 EXPECT_EQ(1, event_fired); 7495 EXPECT_EQ(1, event_fired);
7494 7496
7495 shell()->web_contents()->WasShown(); 7497 shell()->web_contents()->WasShown();
7496 7498
7497 EXPECT_TRUE(ExecuteScriptAndExtractInt( 7499 EXPECT_TRUE(ExecuteScriptAndExtractInt(
7498 root->child_at(0)->current_frame_host(), 7500 root->child_at(0)->current_frame_host(),
7499 "window.domAutomationController.send(event_fired);", &event_fired)); 7501 "window.domAutomationController.send(event_fired);", &event_fired));
7500 EXPECT_EQ(2, event_fired); 7502 EXPECT_EQ(2, event_fired);
7501 } 7503 }
7502 7504
7505 #if defined(USE_AURA)
7506 class SitePerProcessGestureBrowserTest : public SitePerProcessBrowserTest {
7507 public:
7508 SitePerProcessGestureBrowserTest() {}
7509
7510 // This functions simulates a sequence of events that are typical of a
7511 // gesture pinch at |position|. We need this since machinery in the event
7512 // codepath will require GesturePinch* to be enclosed in
7513 // GestureScrollBegin/End, and since RenderWidgetHostInputEventRouter needs
7514 // both the preceding touch events, as well as GestureTapDown, in order to
7515 // correctly target the subsequent gesture event stream. The minimum stream
7516 // required to trigger the correct behaviours is represented here, but could
7517 // be expanded to include additional events such as one or more
7518 // GestureScrollUpdate and GesturePinchUpdate events.
7519 void SendPinchBeginEndSequence(RenderWidgetHostViewAura* rwhva,
7520 const gfx::Point& position) {
7521 DCHECK(rwhva);
7522 // Use full version of constructor with radius, angle and force since it
7523 // will crash in the renderer otherwise.
7524 ui::TouchEvent touch_pressed(ui::ET_TOUCH_PRESSED, position, 0, 0,
7525 ui::EventTimeForNow(), 1.f, 1.f, 0.f, 1.f);
7526 rwhva->OnTouchEvent(&touch_pressed);
7527 ui::TouchEvent touch_released(ui::ET_TOUCH_RELEASED, position, 0, 0,
7528 ui::EventTimeForNow(), 1.f, 1.f, 0.f, 1.f);
7529 rwhva->OnTouchEvent(&touch_released);
7530
7531 ui::GestureEventDetails gesture_tap_down_details(ui::ET_GESTURE_TAP_DOWN);
7532 gesture_tap_down_details.set_device_type(
7533 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7534 ui::GestureEvent gesture_tap_down(position.x(), position.y(), 0,
7535 ui::EventTimeForNow(),
7536 gesture_tap_down_details);
7537 rwhva->OnGestureEvent(&gesture_tap_down);
7538
7539 ui::GestureEventDetails gesture_scroll_begin_details(
7540 ui::ET_GESTURE_SCROLL_BEGIN);
7541 gesture_scroll_begin_details.set_device_type(
7542 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7543 ui::GestureEvent gesture_scroll_begin(position.x(), position.y(), 0,
7544 ui::EventTimeForNow(),
7545 gesture_scroll_begin_details);
7546 rwhva->OnGestureEvent(&gesture_scroll_begin);
7547
7548 ui::GestureEventDetails gesture_pinch_begin_details(
7549 ui::ET_GESTURE_PINCH_BEGIN);
7550 gesture_pinch_begin_details.set_device_type(
7551 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7552 ui::GestureEvent gesture_pinch_begin(position.x(), position.y(), 0,
7553 ui::EventTimeForNow(),
7554 gesture_pinch_begin_details);
7555 rwhva->OnGestureEvent(&gesture_pinch_begin);
7556
7557 ui::GestureEventDetails gesture_pinch_end_details(ui::ET_GESTURE_PINCH_END);
7558 gesture_pinch_end_details.set_device_type(
7559 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7560 ui::GestureEvent gesture_pinch_end(position.x(), position.y(), 0,
7561 ui::EventTimeForNow(),
7562 gesture_pinch_end_details);
7563 rwhva->OnGestureEvent(&gesture_pinch_end);
7564
7565 ui::GestureEventDetails gesture_scroll_end_details(
7566 ui::ET_GESTURE_SCROLL_END);
7567 gesture_scroll_end_details.set_device_type(
7568 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7569 ui::GestureEvent gesture_scroll_end(position.x(), position.y(), 0,
7570 ui::EventTimeForNow(),
7571 gesture_scroll_end_details);
7572 rwhva->OnGestureEvent(&gesture_scroll_end);
7573 }
7574
7575 void SetupRootAndChild() {
7576 GURL main_url(embedded_test_server()->GetURL(
7577 "a.com", "/cross_site_iframe_factory.html?a(b)"));
7578 NavigateToURL(shell(), main_url);
7579
7580 FrameTreeNode* root_node =
7581 static_cast<WebContentsImpl*>(shell()->web_contents())
7582 ->GetFrameTree()
7583 ->root();
7584 FrameTreeNode* child_node = root_node->child_at(0);
7585
7586 rwhv_child_ = static_cast<RenderWidgetHostViewBase*>(
7587 child_node->current_frame_host()->GetRenderWidgetHost()->GetView());
7588
7589 rwhva_root_ = static_cast<RenderWidgetHostViewAura*>(
7590 shell()->web_contents()->GetRenderWidgetHostView());
7591
7592 SurfaceHitTestReadyNotifier notifier(
7593 static_cast<RenderWidgetHostViewChildFrame*>(rwhv_child_));
7594 notifier.WaitForSurfaceReady();
7595
7596 rwhi_child_ = child_node->current_frame_host()->GetRenderWidgetHost();
7597 rwhi_root_ = root_node->current_frame_host()->GetRenderWidgetHost();
7598 }
7599
7600 protected:
7601 RenderWidgetHostViewBase* rwhv_child_;
7602 RenderWidgetHostViewAura* rwhva_root_;
7603 RenderWidgetHostImpl* rwhi_child_;
7604 RenderWidgetHostImpl* rwhi_root_;
7605
7606 private:
7607 DISALLOW_COPY_AND_ASSIGN(SitePerProcessGestureBrowserTest);
7608 };
7609
7610 IN_PROC_BROWSER_TEST_F(SitePerProcessGestureBrowserTest,
7611 SubframeGesturePinchGoesToMainFrame) {
7612 SetupRootAndChild();
7613
7614 TestInputEventObserver root_frame_monitor(rwhi_root_);
7615 TestInputEventObserver child_frame_monitor(rwhi_child_);
7616
7617 // Need child rect in main frame coords.
7618 gfx::Rect bounds = rwhv_child_->GetViewBounds();
7619 bounds.Offset(gfx::Point() - rwhva_root_->GetViewBounds().origin());
7620 SendPinchBeginEndSequence(rwhva_root_, bounds.CenterPoint());
7621
7622 // Verify root-RWHI gets GSB/GPB/GPE/GSE.
7623 EXPECT_TRUE(root_frame_monitor.EventWasReceived());
7624 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin,
7625 root_frame_monitor.events_received()[0]);
7626 EXPECT_EQ(blink::WebInputEvent::GesturePinchBegin,
7627 root_frame_monitor.events_received()[1]);
7628 EXPECT_EQ(blink::WebInputEvent::GesturePinchEnd,
7629 root_frame_monitor.events_received()[2]);
7630 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd,
7631 root_frame_monitor.events_received()[3]);
7632
7633 // Verify child-RWHI gets TS/TE, GTD/GSB/GSE.
7634 EXPECT_TRUE(child_frame_monitor.EventWasReceived());
7635 EXPECT_EQ(blink::WebInputEvent::TouchStart,
7636 child_frame_monitor.events_received()[0]);
7637 EXPECT_EQ(blink::WebInputEvent::TouchEnd,
7638 child_frame_monitor.events_received()[1]);
7639 EXPECT_EQ(blink::WebInputEvent::GestureTapDown,
7640 child_frame_monitor.events_received()[2]);
7641 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin,
7642 child_frame_monitor.events_received()[3]);
7643 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd,
7644 child_frame_monitor.events_received()[4]);
7645 }
7646
7647 IN_PROC_BROWSER_TEST_F(SitePerProcessGestureBrowserTest,
7648 MainframeGesturePinchGoesToMainFrame) {
7649 SetupRootAndChild();
7650
7651 TestInputEventObserver root_frame_monitor(rwhi_root_);
7652 TestInputEventObserver child_frame_monitor(rwhi_child_);
7653
7654 // Need child rect in main frame coords.
7655 gfx::Rect bounds = rwhv_child_->GetViewBounds();
7656 bounds.Offset(gfx::Point() - rwhva_root_->GetViewBounds().origin());
7657
7658 gfx::Point main_frame_point(bounds.origin());
7659 main_frame_point += gfx::Vector2d(-5, -5);
7660 SendPinchBeginEndSequence(rwhva_root_, main_frame_point);
7661
7662 // Verify root-RWHI gets TS/TE/GTD/GSB/GPB/GPE/GSE.
7663 EXPECT_TRUE(root_frame_monitor.EventWasReceived());
7664 EXPECT_EQ(blink::WebInputEvent::TouchStart,
7665 root_frame_monitor.events_received()[0]);
7666 EXPECT_EQ(blink::WebInputEvent::TouchEnd,
7667 root_frame_monitor.events_received()[1]);
7668 EXPECT_EQ(blink::WebInputEvent::GestureTapDown,
7669 root_frame_monitor.events_received()[2]);
7670 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin,
7671 root_frame_monitor.events_received()[3]);
7672 EXPECT_EQ(blink::WebInputEvent::GesturePinchBegin,
7673 root_frame_monitor.events_received()[4]);
7674 EXPECT_EQ(blink::WebInputEvent::GesturePinchEnd,
7675 root_frame_monitor.events_received()[5]);
7676 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd,
7677 root_frame_monitor.events_received()[6]);
7678
7679 // Verify child-RWHI gets no events.
7680 EXPECT_FALSE(child_frame_monitor.EventWasReceived());
7681 }
7682 #endif
7683
7503 } // namespace content 7684 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_input_event_router.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698