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 5411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5422 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); | 5422 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); |
5423 | 5423 |
5424 // Use new window to navigate main window. | 5424 // Use new window to navigate main window. |
5425 std::string script = | 5425 std::string script = |
5426 "window.opener.location.href = '" + cross_url.spec() + "'"; | 5426 "window.opener.location.href = '" + cross_url.spec() + "'"; |
5427 EXPECT_TRUE(ExecuteScript(popup, script)); | 5427 EXPECT_TRUE(ExecuteScript(popup, script)); |
5428 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5428 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
5429 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 5429 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
5430 } | 5430 } |
5431 | 5431 |
| 5432 #if defined(USE_AURA) |
| 5433 // Browser process hit testing is not implemented on Android, and these tests |
| 5434 // require Aura for RenderWidgetHostViewAura::OnTouchEvent(). |
| 5435 // https://crbug.com/491334 |
| 5436 |
| 5437 // Ensure that scroll events can be cancelled with a wheel handler. |
| 5438 // https://crbug.com/698195 |
| 5439 |
| 5440 class SitePerProcessMouseWheelBrowserTest : public SitePerProcessBrowserTest { |
| 5441 public: |
| 5442 SitePerProcessMouseWheelBrowserTest() : rwhv_root_(nullptr) {} |
| 5443 |
| 5444 void SetupWheelAndScrollHandlers(content::RenderFrameHostImpl* rfh) { |
| 5445 // Set up event handlers. The wheel event handler calls prevent default on |
| 5446 // alternate events, so only every other wheel generates a scroll. The fact |
| 5447 // that any scroll events fire is dependent on the event going to the main |
| 5448 // thread, which requires the nonFastScrollableRegion be set correctly |
| 5449 // on the compositor. |
| 5450 std::string script = |
| 5451 "wheel_count = 0;" |
| 5452 "function wheel_handler(e) {" |
| 5453 " wheel_count++;" |
| 5454 " if (wheel_count % 2 == 0)" |
| 5455 " e.preventDefault();\n" |
| 5456 " domAutomationController.setAutomationId(0);" |
| 5457 " domAutomationController.send('wheel: ' + wheel_count);" |
| 5458 "}" |
| 5459 "function scroll_handler(e) {" |
| 5460 " domAutomationController.setAutomationId(0);" |
| 5461 " domAutomationController.send('scroll: ' + wheel_count);" |
| 5462 "}" |
| 5463 "scroll_div = document.getElementById('scrollable_div');" |
| 5464 "scroll_div.addEventListener('wheel', wheel_handler);" |
| 5465 "scroll_div.addEventListener('scroll', scroll_handler);" |
| 5466 "domAutomationController.setAutomationId(0);" |
| 5467 "domAutomationController.send('wheel handler installed');" |
| 5468 "document.body.style.background = 'black';"; |
| 5469 |
| 5470 content::DOMMessageQueue msg_queue; |
| 5471 std::string reply; |
| 5472 EXPECT_TRUE(ExecuteScript(rfh, script)); |
| 5473 |
| 5474 // Wait until renderer's compositor thread is synced. Otherwise the event |
| 5475 // handler won't be installed when the event arrives. |
| 5476 { |
| 5477 MainThreadFrameObserver observer(rfh->GetRenderWidgetHost()); |
| 5478 observer.Wait(); |
| 5479 } |
| 5480 } |
| 5481 |
| 5482 void SendMouseWheel(gfx::Point location) { |
| 5483 DCHECK(rwhv_root_); |
| 5484 ui::ScrollEvent scroll_event(ui::ET_SCROLL, location, ui::EventTimeForNow(), |
| 5485 0, 0, -ui::MouseWheelEvent::kWheelDelta, 0, |
| 5486 ui::MouseWheelEvent::kWheelDelta, |
| 5487 2); // This must be '2' or it gets silently |
| 5488 // dropped. |
| 5489 rwhv_root_->OnScrollEvent(&scroll_event); |
| 5490 } |
| 5491 |
| 5492 void set_rwhv_root(RenderWidgetHostViewAura* rwhv_root) { |
| 5493 rwhv_root_ = rwhv_root; |
| 5494 } |
| 5495 |
| 5496 void RunTest(gfx::Point pos) { |
| 5497 content::DOMMessageQueue msg_queue; |
| 5498 std::string reply; |
| 5499 |
| 5500 auto* rwhv_root = static_cast<RenderWidgetHostViewAura*>( |
| 5501 web_contents()->GetRenderWidgetHostView()); |
| 5502 set_rwhv_root(rwhv_root); |
| 5503 |
| 5504 SendMouseWheel(pos); |
| 5505 |
| 5506 // Expect both wheel and scroll handlers to fire. |
| 5507 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 5508 EXPECT_EQ("\"wheel: 1\"", reply); |
| 5509 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 5510 EXPECT_EQ("\"scroll: 1\"", reply); |
| 5511 |
| 5512 SendMouseWheel(pos); |
| 5513 |
| 5514 // This time only the wheel handler fires, since it prevent defaults on |
| 5515 // even numbered scrolls. |
| 5516 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 5517 EXPECT_EQ("\"wheel: 2\"", reply); |
| 5518 |
| 5519 SendMouseWheel(pos); |
| 5520 |
| 5521 // Odd number of wheels, expect both wheel and scroll handlers to fire |
| 5522 // again. |
| 5523 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 5524 EXPECT_EQ("\"wheel: 3\"", reply); |
| 5525 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
| 5526 EXPECT_EQ("\"scroll: 3\"", reply); |
| 5527 } |
| 5528 |
| 5529 private: |
| 5530 RenderWidgetHostViewAura* rwhv_root_; |
| 5531 }; |
| 5532 |
| 5533 IN_PROC_BROWSER_TEST_F(SitePerProcessMouseWheelBrowserTest, |
| 5534 SubframeWheelEventsOnMainThread) { |
| 5535 GURL main_url(embedded_test_server()->GetURL( |
| 5536 "/frame_tree/page_with_positioned_nested_frames.html")); |
| 5537 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 5538 |
| 5539 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 5540 ASSERT_EQ(1U, root->child_count()); |
| 5541 |
| 5542 GURL frame_url(embedded_test_server()->GetURL( |
| 5543 "b.com", "/page_with_scrollable_div.html")); |
| 5544 NavigateFrameToURL(root->child_at(0), frame_url); |
| 5545 |
| 5546 // Synchronize with the child and parent renderers to guarantee that the |
| 5547 // surface information required for event hit testing is ready. |
| 5548 RenderWidgetHostViewBase* child_rwhv = static_cast<RenderWidgetHostViewBase*>( |
| 5549 root->child_at(0)->current_frame_host()->GetView()); |
| 5550 SurfaceHitTestReadyNotifier notifier( |
| 5551 static_cast<RenderWidgetHostViewChildFrame*>(child_rwhv)); |
| 5552 notifier.WaitForSurfaceReady(); |
| 5553 |
| 5554 content::RenderFrameHostImpl* child = root->child_at(0)->current_frame_host(); |
| 5555 SetupWheelAndScrollHandlers(child); |
| 5556 |
| 5557 gfx::Rect bounds = child_rwhv->GetViewBounds(); |
| 5558 gfx::Point pos(bounds.x() + 10, bounds.y() + 10); |
| 5559 |
| 5560 RunTest(pos); |
| 5561 } |
| 5562 |
| 5563 // Verifies that test in SubframeWheelEventsOnMainThread also makes sense for |
| 5564 // the same page loaded in the mainframe. |
| 5565 IN_PROC_BROWSER_TEST_F(SitePerProcessMouseWheelBrowserTest, |
| 5566 MainframeWheelEventsOnMainThread) { |
| 5567 GURL main_url( |
| 5568 embedded_test_server()->GetURL("/page_with_scrollable_div.html")); |
| 5569 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 5570 |
| 5571 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 5572 content::RenderFrameHostImpl* rfhi = root->current_frame_host(); |
| 5573 SetupWheelAndScrollHandlers(rfhi); |
| 5574 |
| 5575 gfx::Point pos(10, 10); |
| 5576 |
| 5577 RunTest(pos); |
| 5578 } |
| 5579 |
5432 // Ensure that a cross-process subframe with a touch-handler can receive touch | 5580 // Ensure that a cross-process subframe with a touch-handler can receive touch |
5433 // events. | 5581 // events. |
5434 #if defined(USE_AURA) | |
5435 // Browser process hit testing is not implemented on Android, and this test | |
5436 // requires Aura for RenderWidgetHostViewAura::OnTouchEvent(). | |
5437 // https://crbug.com/491334 | |
5438 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5582 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
5439 SubframeTouchEventRouting) { | 5583 SubframeTouchEventRouting) { |
5440 GURL main_url(embedded_test_server()->GetURL( | 5584 GURL main_url(embedded_test_server()->GetURL( |
5441 "/frame_tree/page_with_positioned_nested_frames.html")); | 5585 "/frame_tree/page_with_positioned_nested_frames.html")); |
5442 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 5586 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
5443 | 5587 |
5444 WebContentsImpl* contents = web_contents(); | 5588 WebContentsImpl* contents = web_contents(); |
5445 FrameTreeNode* root = contents->GetFrameTree()->root(); | 5589 FrameTreeNode* root = contents->GetFrameTree()->root(); |
5446 ASSERT_EQ(1U, root->child_count()); | 5590 ASSERT_EQ(1U, root->child_count()); |
5447 | 5591 |
(...skipping 4168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9616 | 9760 |
9617 // Try the same navigation, but use the browser-initiated path. | 9761 // Try the same navigation, but use the browser-initiated path. |
9618 NavigateFrameToURL(root->child_at(0), frame_url); | 9762 NavigateFrameToURL(root->child_at(0), frame_url); |
9619 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); | 9763 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); |
9620 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); | 9764 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); |
9621 EXPECT_EQ(b_site_instance, | 9765 EXPECT_EQ(b_site_instance, |
9622 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 9766 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
9623 } | 9767 } |
9624 | 9768 |
9625 } // namespace content | 9769 } // namespace content |
OLD | NEW |