| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 " |--Site C ------- proxies for A\n" | 421 " |--Site C ------- proxies for A\n" |
| 419 " +--Site A ------- proxies for C\n" | 422 " +--Site A ------- proxies for C\n" |
| 420 " |--Site A -- proxies for C\n" | 423 " |--Site A -- proxies for C\n" |
| 421 " +--Site A -- proxies for C\n" | 424 " +--Site A -- proxies for C\n" |
| 422 " +--Site A -- proxies for C\n" | 425 " +--Site A -- proxies for C\n" |
| 423 "Where A = http://a.com/\n" | 426 "Where A = http://a.com/\n" |
| 424 " C = http://bar.com/", | 427 " C = http://bar.com/", |
| 425 DepictFrameTree(root)); | 428 DepictFrameTree(root)); |
| 426 } | 429 } |
| 427 | 430 |
| 431 class RenderWidgetHostMouseEventMonitor { |
| 432 public: |
| 433 RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host) |
| 434 : host_(host), event_received(false) { |
| 435 host_->AddMouseEventCallback( |
| 436 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| 437 base::Unretained(this))); |
| 438 } |
| 439 ~RenderWidgetHostMouseEventMonitor() { |
| 440 host_->RemoveMouseEventCallback( |
| 441 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| 442 base::Unretained(this))); |
| 443 } |
| 444 bool EventWasReceived() { return event_received; } |
| 445 void ResetEventReceived() { event_received = false; } |
| 446 |
| 447 private: |
| 448 bool MouseEventCallback(const blink::WebMouseEvent& /* event */) { |
| 449 event_received = true; |
| 450 return false; |
| 451 } |
| 452 RenderWidgetHost* host_; |
| 453 bool event_received; |
| 454 }; |
| 455 |
| 456 // Test that mouse events are being routed to the correct RenderWidgetHostView |
| 457 // based on coordinates. |
| 458 #if defined(OS_ANDROID) |
| 459 // Browser process hit testing is not implemented on Android. |
| 460 // https://crbug.com/491334 |
| 461 #define MAYBE_SurfaceHitTestTest DISABLED_SurfaceHitTestTest |
| 462 #else |
| 463 #define MAYBE_SurfaceHitTestTest SurfaceHitTestTest |
| 464 #endif |
| 465 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_SurfaceHitTestTest) { |
| 466 if (!UseSurfacesEnabled()) |
| 467 return; |
| 468 |
| 469 GURL main_url(embedded_test_server()->GetURL( |
| 470 "/frame_tree/page_with_positioned_frame.html")); |
| 471 NavigateToURL(shell(), main_url); |
| 472 |
| 473 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 474 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 475 ->GetFrameTree() |
| 476 ->root(); |
| 477 ASSERT_EQ(1U, root->child_count()); |
| 478 |
| 479 FrameTreeNode* child_node = root->child_at(0); |
| 480 GURL site_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); |
| 481 EXPECT_EQ(site_url, child_node->current_url()); |
| 482 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 483 child_node->current_frame_host()->GetSiteInstance()); |
| 484 |
| 485 // Create listeners for mouse events. |
| 486 RenderWidgetHostMouseEventMonitor main_frame_monitor( |
| 487 root->current_frame_host()->GetRenderWidgetHost()); |
| 488 RenderWidgetHostMouseEventMonitor child_frame_monitor( |
| 489 child_node->current_frame_host()->GetRenderWidgetHost()); |
| 490 |
| 491 RenderWidgetHostInputEventRouter* router = |
| 492 static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 493 ->GetInputEventRouter(); |
| 494 |
| 495 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 496 root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 497 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| 498 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 499 |
| 500 // We need to wait for a compositor frame from the child frame, at which |
| 501 // point its surface will be created. |
| 502 while (rwhv_child->RendererFrameNumber() <= 0) { |
| 503 // TODO(lazyboy): Find a better way to avoid sleeping like this. See |
| 504 // http://crbug.com/405282 for details. |
| 505 base::RunLoop run_loop; |
| 506 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 507 FROM_HERE, run_loop.QuitClosure(), |
| 508 base::TimeDelta::FromMilliseconds(10)); |
| 509 run_loop.Run(); |
| 510 } |
| 511 |
| 512 uint32_t cur_render_frame_number = root_view->RendererFrameNumber(); |
| 513 |
| 514 // Target input event to child frame. |
| 515 blink::WebMouseEvent child_event; |
| 516 child_event.type = blink::WebInputEvent::MouseDown; |
| 517 child_event.button = blink::WebPointerProperties::ButtonLeft; |
| 518 child_event.x = 75; |
| 519 child_event.y = 75; |
| 520 child_event.clickCount = 1; |
| 521 router->RouteMouseEvent(root_view, &child_event); |
| 522 |
| 523 if (!child_frame_monitor.EventWasReceived()) { |
| 524 main_frame_monitor.ResetEventReceived(); |
| 525 // This is working around a big synchronization problem. It is very |
| 526 // difficult to know if we have received a compositor frame from the |
| 527 // main frame renderer *after* it received the child frame's surface |
| 528 // ID. Hit testing won't work until this happens. So if the hit test |
| 529 // fails then we wait for another frame to arrive and try again. |
| 530 // TODO(kenrb): We need a better way to do all of this, possibly coming |
| 531 // from http://crbug.com/405282. |
| 532 while (root_view->RendererFrameNumber() <= cur_render_frame_number) { |
| 533 base::RunLoop run_loop; |
| 534 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 535 FROM_HERE, run_loop.QuitClosure(), |
| 536 base::TimeDelta::FromMilliseconds(10)); |
| 537 run_loop.Run(); |
| 538 } |
| 539 router->RouteMouseEvent(root_view, &child_event); |
| 540 } |
| 541 |
| 542 EXPECT_TRUE(child_frame_monitor.EventWasReceived()); |
| 543 EXPECT_FALSE(main_frame_monitor.EventWasReceived()); |
| 544 |
| 545 child_frame_monitor.ResetEventReceived(); |
| 546 main_frame_monitor.ResetEventReceived(); |
| 547 |
| 548 // Target input event to main frame. |
| 549 blink::WebMouseEvent main_event; |
| 550 main_event.type = blink::WebInputEvent::MouseDown; |
| 551 main_event.button = blink::WebPointerProperties::ButtonLeft; |
| 552 main_event.x = 1; |
| 553 main_event.y = 1; |
| 554 main_event.clickCount = 1; |
| 555 // Ladies and gentlemen, THIS is the main_event! |
| 556 router->RouteMouseEvent(root_view, &main_event); |
| 557 |
| 558 EXPECT_FALSE(child_frame_monitor.EventWasReceived()); |
| 559 EXPECT_TRUE(main_frame_monitor.EventWasReceived()); |
| 560 } |
| 561 |
| 428 // Tests OOPIF rendering by checking that the RWH of the iframe generates | 562 // Tests OOPIF rendering by checking that the RWH of the iframe generates |
| 429 // OnSwapCompositorFrame message. | 563 // OnSwapCompositorFrame message. |
| 430 #if defined(OS_ANDROID) | 564 #if defined(OS_ANDROID) |
| 431 // http://crbug.com/471850 | 565 // http://crbug.com/471850 |
| 432 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped | 566 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped |
| 433 #else | 567 #else |
| 434 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped | 568 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped |
| 435 #endif | 569 #endif |
| 436 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 570 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 437 MAYBE_CompositorFrameSwapped) { | 571 MAYBE_CompositorFrameSwapped) { |
| (...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3032 success = false; | 3166 success = false; |
| 3033 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3167 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3034 popup_root->child_at(1)->current_frame_host(), | 3168 popup_root->child_at(1)->current_frame_host(), |
| 3035 "window.domAutomationController.send(" | 3169 "window.domAutomationController.send(" |
| 3036 " window.opener === window.opener.parent.frames['frame1']);", | 3170 " window.opener === window.opener.parent.frames['frame1']);", |
| 3037 &success)); | 3171 &success)); |
| 3038 EXPECT_TRUE(success); | 3172 EXPECT_TRUE(success); |
| 3039 } | 3173 } |
| 3040 | 3174 |
| 3041 } // namespace content | 3175 } // namespace content |
| OLD | NEW |