| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/pattern.h" | 13 #include "base/strings/pattern.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "content/browser/frame_host/cross_process_frame_connector.h" | 17 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 18 #include "content/browser/frame_host/frame_tree.h" | 18 #include "content/browser/frame_host/frame_tree.h" |
| 19 #include "content/browser/frame_host/navigator.h" | 19 #include "content/browser/frame_host/navigator.h" |
| 20 #include "content/browser/frame_host/render_frame_proxy_host.h" | 20 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 21 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 21 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 22 #include "content/browser/gpu/compositor_util.h" |
| 22 #include "content/browser/renderer_host/render_view_host_impl.h" | 23 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 24 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 23 #include "content/browser/web_contents/web_contents_impl.h" | 25 #include "content/browser/web_contents/web_contents_impl.h" |
| 24 #include "content/common/frame_messages.h" | 26 #include "content/common/frame_messages.h" |
| 25 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 28 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
| 30 #include "content/public/test/content_browser_test_utils.h" | 32 #include "content/public/test/content_browser_test_utils.h" |
| 31 #include "content/public/test/test_navigation_observer.h" | 33 #include "content/public/test/test_navigation_observer.h" |
| 32 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
| 33 #include "content/shell/browser/shell.h" | 35 #include "content/shell/browser/shell.h" |
| 34 #include "content/test/content_browser_test_utils_internal.h" | 36 #include "content/test/content_browser_test_utils_internal.h" |
| 35 #include "content/test/test_frame_navigation_observer.h" | 37 #include "content/test/test_frame_navigation_observer.h" |
| 36 #include "ipc/ipc_security_test_util.h" | 38 #include "ipc/ipc_security_test_util.h" |
| 37 #include "net/dns/mock_host_resolver.h" | 39 #include "net/dns/mock_host_resolver.h" |
| 38 #include "net/test/embedded_test_server/embedded_test_server.h" | 40 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 41 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 39 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 42 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 40 | 43 |
| 41 namespace content { | 44 namespace content { |
| 42 | 45 |
| 43 namespace { | 46 namespace { |
| 44 | 47 |
| 45 // Helper function to send a postMessage and wait for a reply message. The | 48 // Helper function to send a postMessage and wait for a reply message. The |
| 46 // |post_message_script| is executed on the |sender_ftn| frame, and the sender | 49 // |post_message_script| is executed on the |sender_ftn| frame, and the sender |
| 47 // frame is expected to post |reply_status| from the DOMAutomationController | 50 // frame is expected to post |reply_status| from the DOMAutomationController |
| 48 // when it receives a reply. | 51 // when it receives a reply. |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 " |--Site C ------- proxies for A\n" | 427 " |--Site C ------- proxies for A\n" |
| 425 " +--Site A ------- proxies for C\n" | 428 " +--Site A ------- proxies for C\n" |
| 426 " |--Site A -- proxies for C\n" | 429 " |--Site A -- proxies for C\n" |
| 427 " +--Site A -- proxies for C\n" | 430 " +--Site A -- proxies for C\n" |
| 428 " +--Site A -- proxies for C\n" | 431 " +--Site A -- proxies for C\n" |
| 429 "Where A = http://127.0.0.1/\n" | 432 "Where A = http://127.0.0.1/\n" |
| 430 " C = http://bar.com/", | 433 " C = http://bar.com/", |
| 431 DepictFrameTree(root)); | 434 DepictFrameTree(root)); |
| 432 } | 435 } |
| 433 | 436 |
| 437 class RenderWidgetHostMouseEventMonitor { |
| 438 public: |
| 439 RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host) |
| 440 : host_(host), event_received(false) { |
| 441 host_->AddMouseEventCallback( |
| 442 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| 443 base::Unretained(this))); |
| 444 } |
| 445 ~RenderWidgetHostMouseEventMonitor() { |
| 446 host_->RemoveMouseEventCallback( |
| 447 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| 448 base::Unretained(this))); |
| 449 } |
| 450 bool EventWasReceived() { return event_received; } |
| 451 void ResetEventReceived() { event_received = false; } |
| 452 |
| 453 private: |
| 454 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) { |
| 455 event_received = true; |
| 456 return false; |
| 457 } |
| 458 RenderWidgetHost* host_; |
| 459 bool event_received; |
| 460 }; |
| 461 |
| 462 // Test that mouse events are being routed to the correct RenderWidgetHostView |
| 463 // based on coordinates. |
| 464 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SurfaceHitTestTest) { |
| 465 if (!UseSurfacesEnabled()) |
| 466 return; |
| 467 |
| 468 GURL main_url(embedded_test_server()->GetURL( |
| 469 "/frame_tree/page_with_positioned_frame.html")); |
| 470 NavigateToURL(shell(), main_url); |
| 471 |
| 472 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 473 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 474 ->GetFrameTree() |
| 475 ->root(); |
| 476 ASSERT_EQ(1U, root->child_count()); |
| 477 |
| 478 FrameTreeNode* child_node = root->child_at(0); |
| 479 GURL site_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); |
| 480 EXPECT_EQ(site_url, child_node->current_url()); |
| 481 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 482 child_node->current_frame_host()->GetSiteInstance()); |
| 483 |
| 484 // Create listeners for mouse events. |
| 485 RenderWidgetHostMouseEventMonitor main_frame_monitor( |
| 486 root->current_frame_host()->GetRenderWidgetHost()); |
| 487 RenderWidgetHostMouseEventMonitor child_frame_monitor( |
| 488 child_node->current_frame_host()->GetRenderWidgetHost()); |
| 489 |
| 490 RenderWidgetHostInputEventRouter* router = |
| 491 static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 492 ->GetInputEventRouter(); |
| 493 |
| 494 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 495 root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 496 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| 497 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 498 |
| 499 // We need to wait for a compositor frame from the child frame, at which |
| 500 // point its surface will be created. |
| 501 while (rwhv_child->RendererFrameNumber() <= 0) { |
| 502 // TODO(lazyboy): Find a better way to avoid sleeping like this. See |
| 503 // http://crbug.com/405282 for details. |
| 504 base::RunLoop run_loop; |
| 505 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 506 FROM_HERE, run_loop.QuitClosure(), |
| 507 base::TimeDelta::FromMilliseconds(10)); |
| 508 run_loop.Run(); |
| 509 } |
| 510 |
| 511 uint32_t cur_render_frame_number = root_view->RendererFrameNumber(); |
| 512 |
| 513 // Target input event to child frame. |
| 514 blink::WebMouseEvent child_event; |
| 515 child_event.type = blink::WebInputEvent::MouseDown; |
| 516 child_event.button = blink::WebPointerProperties::ButtonLeft; |
| 517 child_event.x = 75; |
| 518 child_event.y = 75; |
| 519 child_event.clickCount = 1; |
| 520 router->RouteMouseEvent(root_view, &child_event); |
| 521 |
| 522 if (!child_frame_monitor.EventWasReceived()) { |
| 523 main_frame_monitor.ResetEventReceived(); |
| 524 // This is working around a big synchronization problem. It is very |
| 525 // difficult to know if we have received a compositor frame from the |
| 526 // main frame renderer *after* it received the child frame's surface |
| 527 // ID. Hit testing won't work until this happens. So if the hit test |
| 528 // fails then we wait for another frame to arrive and try again. |
| 529 // TODO(kenrb): We need a better way to do all of this, possibly coming |
| 530 // from http://crbug.com/405282. |
| 531 while (root_view->RendererFrameNumber() <= cur_render_frame_number) { |
| 532 base::RunLoop run_loop; |
| 533 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 534 FROM_HERE, run_loop.QuitClosure(), |
| 535 base::TimeDelta::FromMilliseconds(10)); |
| 536 run_loop.Run(); |
| 537 } |
| 538 router->RouteMouseEvent(root_view, &child_event); |
| 539 } |
| 540 |
| 541 EXPECT_TRUE(child_frame_monitor.EventWasReceived()); |
| 542 EXPECT_FALSE(main_frame_monitor.EventWasReceived()); |
| 543 |
| 544 child_frame_monitor.ResetEventReceived(); |
| 545 main_frame_monitor.ResetEventReceived(); |
| 546 |
| 547 // Target input event to main frame. |
| 548 blink::WebMouseEvent main_event; |
| 549 main_event.type = blink::WebInputEvent::MouseDown; |
| 550 main_event.button = blink::WebPointerProperties::ButtonLeft; |
| 551 main_event.x = 1; |
| 552 main_event.y = 1; |
| 553 main_event.clickCount = 1; |
| 554 // Ladies and gentlemen, THIS is the main_event! |
| 555 router->RouteMouseEvent(root_view, &main_event); |
| 556 |
| 557 EXPECT_FALSE(child_frame_monitor.EventWasReceived()); |
| 558 EXPECT_TRUE(main_frame_monitor.EventWasReceived()); |
| 559 } |
| 560 |
| 434 // Tests OOPIF rendering by checking that the RWH of the iframe generates | 561 // Tests OOPIF rendering by checking that the RWH of the iframe generates |
| 435 // OnSwapCompositorFrame message. | 562 // OnSwapCompositorFrame message. |
| 436 #if defined(OS_ANDROID) | 563 #if defined(OS_ANDROID) |
| 437 // http://crbug.com/471850 | 564 // http://crbug.com/471850 |
| 438 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped | 565 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped |
| 439 #else | 566 #else |
| 440 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped | 567 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped |
| 441 #endif | 568 #endif |
| 442 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 569 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 443 MAYBE_CompositorFrameSwapped) { | 570 MAYBE_CompositorFrameSwapped) { |
| (...skipping 2544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2988 success = false; | 3115 success = false; |
| 2989 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3116 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2990 popup_root->child_at(1)->current_frame_host(), | 3117 popup_root->child_at(1)->current_frame_host(), |
| 2991 "window.domAutomationController.send(" | 3118 "window.domAutomationController.send(" |
| 2992 " window.opener === window.opener.parent.frames['frame1']);", | 3119 " window.opener === window.opener.parent.frames['frame1']);", |
| 2993 &success)); | 3120 &success)); |
| 2994 EXPECT_TRUE(success); | 3121 EXPECT_TRUE(success); |
| 2995 } | 3122 } |
| 2996 | 3123 |
| 2997 } // namespace content | 3124 } // namespace content |
| OLD | NEW |