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

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: Address creis@ comments. 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 RenderWidgetHost* host_; 174 RenderWidgetHost* host_;
175 bool event_received_; 175 bool event_received_;
176 blink::WebMouseEvent event_; 176 blink::WebMouseEvent event_;
177 177
178 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostMouseEventMonitor); 178 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostMouseEventMonitor);
179 }; 179 };
180 180
181 class TestInputEventObserver : public RenderWidgetHost::InputEventObserver { 181 class TestInputEventObserver : public RenderWidgetHost::InputEventObserver {
182 public: 182 public:
183 explicit TestInputEventObserver(RenderWidgetHost* host) 183 explicit TestInputEventObserver(RenderWidgetHost* host) : host_(host) {
184 : host_(host),
185 event_received_(false),
186 last_event_type_(blink::WebInputEvent::Undefined) {
187 host_->AddInputEventObserver(this); 184 host_->AddInputEventObserver(this);
188 } 185 }
189 186
190 ~TestInputEventObserver() override { host_->RemoveInputEventObserver(this); } 187 ~TestInputEventObserver() override { host_->RemoveInputEventObserver(this); }
191 188
192 bool EventWasReceived() const { return event_received_; } 189 bool EventWasReceived() const { return !events_received_.empty(); }
193 void ResetEventReceived() { event_received_ = false; } 190 void ResetEventsReceived() { events_received_.clear(); }
194 blink::WebInputEvent::Type EventType() const { return last_event_type_; } 191 blink::WebInputEvent::Type EventType() const {
192 DCHECK(EventWasReceived());
193 return events_received_.front();
194 }
195 const std::vector<blink::WebInputEvent::Type>& events_received() {
196 return events_received_;
197 }
195 198
196 void OnInputEvent(const blink::WebInputEvent& event) override { 199 void OnInputEvent(const blink::WebInputEvent& event) override {
197 event_received_ = true; 200 events_received_.push_back(event.type);
198 last_event_type_ = event.type;
199 }; 201 };
200 202
203 private:
201 RenderWidgetHost* host_; 204 RenderWidgetHost* host_;
202 bool event_received_; 205 std::vector<blink::WebInputEvent::Type> events_received_;
203 blink::WebInputEvent::Type last_event_type_;
204 206
205 DISALLOW_COPY_AND_ASSIGN(TestInputEventObserver); 207 DISALLOW_COPY_AND_ASSIGN(TestInputEventObserver);
206 }; 208 };
207 209
208 // Helper function that performs a surface hittest. 210 // Helper function that performs a surface hittest.
209 void SurfaceHitTestTestHelper( 211 void SurfaceHitTestTestHelper(
210 Shell* shell, 212 Shell* shell,
211 net::test_server::EmbeddedTestServer* embedded_test_server) { 213 net::test_server::EmbeddedTestServer* embedded_test_server) {
212 GURL main_url(embedded_test_server->GetURL( 214 GURL main_url(embedded_test_server->GetURL(
213 "/frame_tree/page_with_positioned_frame.html")); 215 "/frame_tree/page_with_positioned_frame.html"));
(...skipping 7305 matching lines...) Expand 10 before | Expand all | Expand 10 after
7519 EXPECT_EQ(1, event_fired); 7521 EXPECT_EQ(1, event_fired);
7520 7522
7521 shell()->web_contents()->WasShown(); 7523 shell()->web_contents()->WasShown();
7522 7524
7523 EXPECT_TRUE(ExecuteScriptAndExtractInt( 7525 EXPECT_TRUE(ExecuteScriptAndExtractInt(
7524 root->child_at(0)->current_frame_host(), 7526 root->child_at(0)->current_frame_host(),
7525 "window.domAutomationController.send(event_fired);", &event_fired)); 7527 "window.domAutomationController.send(event_fired);", &event_fired));
7526 EXPECT_EQ(2, event_fired); 7528 EXPECT_EQ(2, event_fired);
7527 } 7529 }
7528 7530
7531 #if defined(USE_AURA)
7532 class SitePerProcessGestureBrowserTest : public SitePerProcessBrowserTest {
7533 public:
7534 SitePerProcessGestureBrowserTest() {}
7535
7536 // This functions simulates a sequence of events that are typical of a
7537 // gesture pinch at |position|. We need this since machinery in the event
7538 // codepath will require GesturePinch* to be encolsed in
Charlie Reis 2016/08/01 20:19:43 nit: enclosed
7539 // GestureScrollBegin/End, and since RenderWidgetHostInputEventRouter needs
7540 // both the preceding touch events, as well as GestureTapDown, in order to
7541 // correctly target the subsequent gesture event stream. The minimum stream
7542 // required to trigger the correct behaviours is represented here, but could
7543 // be expanded to include additional events such as one or more
7544 // GestureScrollUpdate and GesturePinchUpdate events.
7545 void SendPinchBeginEndSequence(RenderWidgetHostViewAura* rwhva,
7546 const gfx::Point& position) {
7547 DCHECK(rwhva);
7548 // Use full version of constructor with radius, angle and force since it
7549 // will crash in the renderer otherwise.
7550 ui::TouchEvent touch_pressed(ui::ET_TOUCH_PRESSED, position, 0, 0,
7551 ui::EventTimeForNow(), 1.f, 1.f, 0.f, 1.f);
7552 rwhva->OnTouchEvent(&touch_pressed);
7553 ui::TouchEvent touch_released(ui::ET_TOUCH_RELEASED, position, 0, 0,
7554 ui::EventTimeForNow(), 1.f, 1.f, 0.f, 1.f);
7555 rwhva->OnTouchEvent(&touch_released);
7556
7557 ui::GestureEventDetails gesture_tap_down_details(ui::ET_GESTURE_TAP_DOWN);
7558 gesture_tap_down_details.set_device_type(
7559 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7560 ui::GestureEvent gesture_tap_down(position.x(), position.y(), 0,
7561 ui::EventTimeForNow(),
7562 gesture_tap_down_details);
7563 rwhva->OnGestureEvent(&gesture_tap_down);
7564
7565 ui::GestureEventDetails gesture_scroll_begin_details(
7566 ui::ET_GESTURE_SCROLL_BEGIN);
7567 gesture_scroll_begin_details.set_device_type(
7568 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7569 ui::GestureEvent gesture_scroll_begin(position.x(), position.y(), 0,
7570 ui::EventTimeForNow(),
7571 gesture_scroll_begin_details);
7572 rwhva->OnGestureEvent(&gesture_scroll_begin);
7573
7574 ui::GestureEventDetails gesture_pinch_begin_details(
7575 ui::ET_GESTURE_PINCH_BEGIN);
7576 gesture_pinch_begin_details.set_device_type(
7577 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7578 ui::GestureEvent gesture_pinch_begin(position.x(), position.y(), 0,
7579 ui::EventTimeForNow(),
7580 gesture_pinch_begin_details);
7581 rwhva->OnGestureEvent(&gesture_pinch_begin);
7582
7583 ui::GestureEventDetails gesture_pinch_end_details(ui::ET_GESTURE_PINCH_END);
7584 gesture_pinch_end_details.set_device_type(
7585 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7586 ui::GestureEvent gesture_pinch_end(position.x(), position.y(), 0,
7587 ui::EventTimeForNow(),
7588 gesture_pinch_end_details);
7589 rwhva->OnGestureEvent(&gesture_pinch_end);
7590
7591 ui::GestureEventDetails gesture_scroll_end_details(
7592 ui::ET_GESTURE_SCROLL_END);
7593 gesture_scroll_end_details.set_device_type(
7594 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
7595 ui::GestureEvent gesture_scroll_end(position.x(), position.y(), 0,
7596 ui::EventTimeForNow(),
7597 gesture_scroll_end_details);
7598 rwhva->OnGestureEvent(&gesture_scroll_end);
7599 }
7600
7601 void SetupRootAndChild() {
7602 GURL main_url(embedded_test_server()->GetURL(
7603 "a.com", "/cross_site_iframe_factory.html?a(b)"));
7604 NavigateToURL(shell(), main_url);
7605
7606 FrameTreeNode* root_node =
7607 static_cast<WebContentsImpl*>(shell()->web_contents())
7608 ->GetFrameTree()
7609 ->root();
7610 FrameTreeNode* child_node = root_node->child_at(0);
7611
7612 rwhv_child_ = static_cast<RenderWidgetHostViewBase*>(
7613 child_node->current_frame_host()->GetRenderWidgetHost()->GetView());
7614
7615 rwhva_root_ = static_cast<RenderWidgetHostViewAura*>(
7616 shell()->web_contents()->GetRenderWidgetHostView());
7617
7618 SurfaceHitTestReadyNotifier notifier(
7619 static_cast<RenderWidgetHostViewChildFrame*>(rwhv_child_));
7620 notifier.WaitForSurfaceReady();
7621
7622 rwhi_child_ = child_node->current_frame_host()->GetRenderWidgetHost();
7623 rwhi_root_ = root_node->current_frame_host()->GetRenderWidgetHost();
7624 }
7625
7626 protected:
7627 RenderWidgetHostViewBase* rwhv_child_;
7628 RenderWidgetHostViewAura* rwhva_root_;
7629 RenderWidgetHostImpl* rwhi_child_;
7630 RenderWidgetHostImpl* rwhi_root_;
7631
7632 private:
7633 DISALLOW_COPY_AND_ASSIGN(SitePerProcessGestureBrowserTest);
7634 };
7635
7636 IN_PROC_BROWSER_TEST_F(SitePerProcessGestureBrowserTest,
7637 SubframeGesturePinchGoesToMainFrame) {
7638 SetupRootAndChild();
7639
7640 TestInputEventObserver root_frame_monitor(rwhi_root_);
7641 TestInputEventObserver child_frame_monitor(rwhi_child_);
7642
7643 // Need child rect in main frame coords.
7644 gfx::Rect bounds = rwhv_child_->GetViewBounds();
7645 bounds.Offset(gfx::Point() - rwhva_root_->GetViewBounds().origin());
7646 SendPinchBeginEndSequence(rwhva_root_, bounds.CenterPoint());
7647
7648 // Verify root-RWHI gets GSB/GPB/GPE/GSE.
7649 EXPECT_TRUE(root_frame_monitor.EventWasReceived());
7650 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin,
7651 root_frame_monitor.events_received()[0]);
7652 EXPECT_EQ(blink::WebInputEvent::GesturePinchBegin,
7653 root_frame_monitor.events_received()[1]);
7654 EXPECT_EQ(blink::WebInputEvent::GesturePinchEnd,
7655 root_frame_monitor.events_received()[2]);
7656 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd,
7657 root_frame_monitor.events_received()[3]);
7658
7659 // Verify child-RWHI gets TS/TE, GTD/GSB/GSE.
7660 EXPECT_TRUE(child_frame_monitor.EventWasReceived());
7661 EXPECT_EQ(blink::WebInputEvent::TouchStart,
7662 child_frame_monitor.events_received()[0]);
7663 EXPECT_EQ(blink::WebInputEvent::TouchEnd,
7664 child_frame_monitor.events_received()[1]);
7665 EXPECT_EQ(blink::WebInputEvent::GestureTapDown,
7666 child_frame_monitor.events_received()[2]);
7667 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin,
7668 child_frame_monitor.events_received()[3]);
7669 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd,
7670 child_frame_monitor.events_received()[4]);
7671 }
7672
7673 IN_PROC_BROWSER_TEST_F(SitePerProcessGestureBrowserTest,
7674 MainframeGesturePinchGoesToMainFrame) {
7675 SetupRootAndChild();
7676
7677 TestInputEventObserver root_frame_monitor(rwhi_root_);
7678 TestInputEventObserver child_frame_monitor(rwhi_child_);
7679
7680 // Need child rect in main frame coords.
7681 gfx::Rect bounds = rwhv_child_->GetViewBounds();
7682 bounds.Offset(gfx::Point() - rwhva_root_->GetViewBounds().origin());
7683
7684 gfx::Point main_frame_point(bounds.origin());
7685 main_frame_point += gfx::Vector2d(-5, -5);
7686 SendPinchBeginEndSequence(rwhva_root_, main_frame_point);
7687
7688 // Verify root-RWHI gets TS/TE/GTD/GSB/GPB/GPE/GSE.
7689 EXPECT_TRUE(root_frame_monitor.EventWasReceived());
7690 EXPECT_EQ(blink::WebInputEvent::TouchStart,
7691 root_frame_monitor.events_received()[0]);
7692 EXPECT_EQ(blink::WebInputEvent::TouchEnd,
7693 root_frame_monitor.events_received()[1]);
7694 EXPECT_EQ(blink::WebInputEvent::GestureTapDown,
7695 root_frame_monitor.events_received()[2]);
7696 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin,
7697 root_frame_monitor.events_received()[3]);
7698 EXPECT_EQ(blink::WebInputEvent::GesturePinchBegin,
7699 root_frame_monitor.events_received()[4]);
7700 EXPECT_EQ(blink::WebInputEvent::GesturePinchEnd,
7701 root_frame_monitor.events_received()[5]);
7702 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd,
7703 root_frame_monitor.events_received()[6]);
7704
7705 // Verify child-RWHI gets no events.
7706 EXPECT_FALSE(child_frame_monitor.EventWasReceived());
7707 }
7708 #endif
7709
7529 } // namespace content 7710 } // 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