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

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: 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
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 ResetEventReceived() { 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 7287 matching lines...) Expand 10 before | Expand all | Expand 10 after
7501 EXPECT_EQ(1, event_fired); 7503 EXPECT_EQ(1, event_fired);
7502 7504
7503 shell()->web_contents()->WasShown(); 7505 shell()->web_contents()->WasShown();
7504 7506
7505 EXPECT_TRUE(ExecuteScriptAndExtractInt( 7507 EXPECT_TRUE(ExecuteScriptAndExtractInt(
7506 root->child_at(0)->current_frame_host(), 7508 root->child_at(0)->current_frame_host(),
7507 "window.domAutomationController.send(event_fired);", &event_fired)); 7509 "window.domAutomationController.send(event_fired);", &event_fired));
7508 EXPECT_EQ(2, event_fired); 7510 EXPECT_EQ(2, event_fired);
7509 } 7511 }
7510 7512
7513 #if defined(USE_AURA)
7514 class SitePerProcessGestureBrowserTest : public SitePerProcessBrowserTest {
7515 public:
7516 SitePerProcessGestureBrowserTest() {}
7517
7518 void SendPinchBeginEndSequence(RenderWidgetHostViewAura* rwhva,
7519 const gfx::Point& position) {
7520 DCHECK(rwhva);
7521 // Use full version of constructor with radius, angle and force since it
7522 // will
7523 // 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 SetupRootAdnChild() {
kenrb 2016/07/27 21:49:49 nit: Typo.
wjmaclean 2016/07/28 13:22:11 Done.
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 SetupRootAdnChild();
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 SetupRootAdnChild();
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
7511 } // namespace content 7684 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698