Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(); } |
|
Charlie Reis
2016/07/28 17:23:02
Let's be consistent with naming convention (vs eve
wjmaclean
2016/07/29 14:28:31
Perhaps this can also be done in a separate CL, as
Charlie Reis
2016/08/01 20:19:43
Sure, that's fine.
| |
| 193 void ResetEventReceived() { event_received_ = false; } | 190 void ResetEventReceived() { events_received_.clear(); } |
|
Charlie Reis
2016/07/28 17:23:02
nit: Events should be plural.
wjmaclean
2016/07/29 14:28:31
Done.
| |
| 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 Loading... | |
| 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) | |
|
Charlie Reis
2016/07/28 17:23:02
There's a lot of Aura-specific blocks in this file
wjmaclean
2016/07/29 14:28:31
Acknowledged.
| |
| 7532 class SitePerProcessGestureBrowserTest : public SitePerProcessBrowserTest { | |
| 7533 public: | |
| 7534 SitePerProcessGestureBrowserTest() {} | |
| 7535 | |
| 7536 void SendPinchBeginEndSequence(RenderWidgetHostViewAura* rwhva, | |
|
Charlie Reis
2016/07/28 17:23:02
Please add an explanatory comment here, since ther
| |
| 7537 const gfx::Point& position) { | |
| 7538 DCHECK(rwhva); | |
| 7539 // Use full version of constructor with radius, angle and force since it | |
| 7540 // will | |
|
Charlie Reis
2016/07/28 17:23:02
nit: Fix wrapping.
wjmaclean
2016/07/29 14:28:31
Done.
| |
| 7541 // crash in the renderer otherwise. | |
| 7542 ui::TouchEvent touch_pressed(ui::ET_TOUCH_PRESSED, position, 0, 0, | |
| 7543 ui::EventTimeForNow(), 1.f, 1.f, 0.f, 1.f); | |
| 7544 rwhva->OnTouchEvent(&touch_pressed); | |
| 7545 ui::TouchEvent touch_released(ui::ET_TOUCH_RELEASED, position, 0, 0, | |
| 7546 ui::EventTimeForNow(), 1.f, 1.f, 0.f, 1.f); | |
| 7547 rwhva->OnTouchEvent(&touch_released); | |
| 7548 | |
| 7549 ui::GestureEventDetails gesture_tap_down_details(ui::ET_GESTURE_TAP_DOWN); | |
| 7550 gesture_tap_down_details.set_device_type( | |
| 7551 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); | |
| 7552 ui::GestureEvent gesture_tap_down(position.x(), position.y(), 0, | |
| 7553 ui::EventTimeForNow(), | |
| 7554 gesture_tap_down_details); | |
| 7555 rwhva->OnGestureEvent(&gesture_tap_down); | |
| 7556 | |
| 7557 ui::GestureEventDetails gesture_scroll_begin_details( | |
| 7558 ui::ET_GESTURE_SCROLL_BEGIN); | |
| 7559 gesture_scroll_begin_details.set_device_type( | |
| 7560 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); | |
| 7561 ui::GestureEvent gesture_scroll_begin(position.x(), position.y(), 0, | |
| 7562 ui::EventTimeForNow(), | |
| 7563 gesture_scroll_begin_details); | |
| 7564 rwhva->OnGestureEvent(&gesture_scroll_begin); | |
| 7565 | |
| 7566 ui::GestureEventDetails gesture_pinch_begin_details( | |
| 7567 ui::ET_GESTURE_PINCH_BEGIN); | |
| 7568 gesture_pinch_begin_details.set_device_type( | |
| 7569 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); | |
| 7570 ui::GestureEvent gesture_pinch_begin(position.x(), position.y(), 0, | |
| 7571 ui::EventTimeForNow(), | |
| 7572 gesture_pinch_begin_details); | |
| 7573 rwhva->OnGestureEvent(&gesture_pinch_begin); | |
| 7574 | |
| 7575 ui::GestureEventDetails gesture_pinch_end_details(ui::ET_GESTURE_PINCH_END); | |
| 7576 gesture_pinch_end_details.set_device_type( | |
| 7577 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); | |
| 7578 ui::GestureEvent gesture_pinch_end(position.x(), position.y(), 0, | |
| 7579 ui::EventTimeForNow(), | |
| 7580 gesture_pinch_end_details); | |
| 7581 rwhva->OnGestureEvent(&gesture_pinch_end); | |
| 7582 | |
| 7583 ui::GestureEventDetails gesture_scroll_end_details( | |
| 7584 ui::ET_GESTURE_SCROLL_END); | |
| 7585 gesture_scroll_end_details.set_device_type( | |
| 7586 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); | |
| 7587 ui::GestureEvent gesture_scroll_end(position.x(), position.y(), 0, | |
| 7588 ui::EventTimeForNow(), | |
| 7589 gesture_scroll_end_details); | |
| 7590 rwhva->OnGestureEvent(&gesture_scroll_end); | |
| 7591 } | |
| 7592 | |
| 7593 void SetupRootAndChild() { | |
| 7594 GURL main_url(embedded_test_server()->GetURL( | |
| 7595 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
| 7596 NavigateToURL(shell(), main_url); | |
| 7597 | |
| 7598 FrameTreeNode* root_node = | |
| 7599 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 7600 ->GetFrameTree() | |
| 7601 ->root(); | |
| 7602 FrameTreeNode* child_node = root_node->child_at(0); | |
| 7603 | |
| 7604 rwhv_child_ = static_cast<RenderWidgetHostViewBase*>( | |
| 7605 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); | |
| 7606 | |
| 7607 rwhva_root_ = static_cast<RenderWidgetHostViewAura*>( | |
| 7608 shell()->web_contents()->GetRenderWidgetHostView()); | |
| 7609 | |
| 7610 SurfaceHitTestReadyNotifier notifier( | |
| 7611 static_cast<RenderWidgetHostViewChildFrame*>(rwhv_child_)); | |
| 7612 notifier.WaitForSurfaceReady(); | |
| 7613 | |
| 7614 rwhi_child_ = child_node->current_frame_host()->GetRenderWidgetHost(); | |
| 7615 rwhi_root_ = root_node->current_frame_host()->GetRenderWidgetHost(); | |
| 7616 } | |
| 7617 | |
| 7618 protected: | |
| 7619 RenderWidgetHostViewBase* rwhv_child_; | |
| 7620 RenderWidgetHostViewAura* rwhva_root_; | |
| 7621 RenderWidgetHostImpl* rwhi_child_; | |
| 7622 RenderWidgetHostImpl* rwhi_root_; | |
| 7623 | |
| 7624 private: | |
| 7625 DISALLOW_COPY_AND_ASSIGN(SitePerProcessGestureBrowserTest); | |
| 7626 }; | |
| 7627 | |
| 7628 IN_PROC_BROWSER_TEST_F(SitePerProcessGestureBrowserTest, | |
| 7629 SubframeGesturePinchGoesToMainFrame) { | |
| 7630 SetupRootAndChild(); | |
| 7631 | |
| 7632 TestInputEventObserver root_frame_monitor(rwhi_root_); | |
| 7633 TestInputEventObserver child_frame_monitor(rwhi_child_); | |
| 7634 | |
| 7635 // Need child rect in main frame coords. | |
| 7636 gfx::Rect bounds = rwhv_child_->GetViewBounds(); | |
| 7637 bounds.Offset(gfx::Point() - rwhva_root_->GetViewBounds().origin()); | |
| 7638 SendPinchBeginEndSequence(rwhva_root_, bounds.CenterPoint()); | |
| 7639 | |
| 7640 // Verify root-RWHI gets GSB/GPB/GPE/GSE. | |
| 7641 EXPECT_TRUE(root_frame_monitor.EventWasReceived()); | |
| 7642 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin, | |
| 7643 root_frame_monitor.events_received()[0]); | |
| 7644 EXPECT_EQ(blink::WebInputEvent::GesturePinchBegin, | |
| 7645 root_frame_monitor.events_received()[1]); | |
| 7646 EXPECT_EQ(blink::WebInputEvent::GesturePinchEnd, | |
| 7647 root_frame_monitor.events_received()[2]); | |
| 7648 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd, | |
| 7649 root_frame_monitor.events_received()[3]); | |
| 7650 | |
| 7651 // Verify child-RWHI gets TS/TE, GTD/GSB/GSE. | |
| 7652 EXPECT_TRUE(child_frame_monitor.EventWasReceived()); | |
| 7653 EXPECT_EQ(blink::WebInputEvent::TouchStart, | |
| 7654 child_frame_monitor.events_received()[0]); | |
| 7655 EXPECT_EQ(blink::WebInputEvent::TouchEnd, | |
| 7656 child_frame_monitor.events_received()[1]); | |
| 7657 EXPECT_EQ(blink::WebInputEvent::GestureTapDown, | |
| 7658 child_frame_monitor.events_received()[2]); | |
| 7659 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin, | |
| 7660 child_frame_monitor.events_received()[3]); | |
| 7661 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd, | |
| 7662 child_frame_monitor.events_received()[4]); | |
| 7663 } | |
| 7664 | |
| 7665 IN_PROC_BROWSER_TEST_F(SitePerProcessGestureBrowserTest, | |
| 7666 MainframeGesturePinchGoesToMainFrame) { | |
| 7667 SetupRootAndChild(); | |
| 7668 | |
| 7669 TestInputEventObserver root_frame_monitor(rwhi_root_); | |
| 7670 TestInputEventObserver child_frame_monitor(rwhi_child_); | |
| 7671 | |
| 7672 // Need child rect in main frame coords. | |
| 7673 gfx::Rect bounds = rwhv_child_->GetViewBounds(); | |
| 7674 bounds.Offset(gfx::Point() - rwhva_root_->GetViewBounds().origin()); | |
| 7675 | |
| 7676 gfx::Point main_frame_point(bounds.origin()); | |
| 7677 main_frame_point += gfx::Vector2d(-5, -5); | |
| 7678 SendPinchBeginEndSequence(rwhva_root_, main_frame_point); | |
| 7679 | |
| 7680 // Verify root-RWHI gets TS/TE/GTD/GSB/GPB/GPE/GSE. | |
| 7681 EXPECT_TRUE(root_frame_monitor.EventWasReceived()); | |
| 7682 EXPECT_EQ(blink::WebInputEvent::TouchStart, | |
| 7683 root_frame_monitor.events_received()[0]); | |
| 7684 EXPECT_EQ(blink::WebInputEvent::TouchEnd, | |
| 7685 root_frame_monitor.events_received()[1]); | |
| 7686 EXPECT_EQ(blink::WebInputEvent::GestureTapDown, | |
| 7687 root_frame_monitor.events_received()[2]); | |
| 7688 EXPECT_EQ(blink::WebInputEvent::GestureScrollBegin, | |
| 7689 root_frame_monitor.events_received()[3]); | |
| 7690 EXPECT_EQ(blink::WebInputEvent::GesturePinchBegin, | |
| 7691 root_frame_monitor.events_received()[4]); | |
| 7692 EXPECT_EQ(blink::WebInputEvent::GesturePinchEnd, | |
| 7693 root_frame_monitor.events_received()[5]); | |
| 7694 EXPECT_EQ(blink::WebInputEvent::GestureScrollEnd, | |
| 7695 root_frame_monitor.events_received()[6]); | |
| 7696 | |
| 7697 // Verify child-RWHI gets no events. | |
| 7698 EXPECT_FALSE(child_frame_monitor.EventWasReceived()); | |
| 7699 } | |
| 7700 #endif | |
| 7701 | |
| 7529 } // namespace content | 7702 } // namespace content |
| OLD | NEW |