| 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 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SurfaceHitTestTest) { |
| 459 if (!UseSurfacesEnabled()) |
| 460 return; |
| 461 |
| 462 GURL main_url(embedded_test_server()->GetURL( |
| 463 "/frame_tree/page_with_positioned_frame.html")); |
| 464 NavigateToURL(shell(), main_url); |
| 465 |
| 466 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 467 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 468 ->GetFrameTree() |
| 469 ->root(); |
| 470 ASSERT_EQ(1U, root->child_count()); |
| 471 |
| 472 FrameTreeNode* child_node = root->child_at(0); |
| 473 GURL site_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); |
| 474 EXPECT_EQ(site_url, child_node->current_url()); |
| 475 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 476 child_node->current_frame_host()->GetSiteInstance()); |
| 477 |
| 478 // Create listeners for mouse events. |
| 479 RenderWidgetHostMouseEventMonitor main_frame_monitor( |
| 480 root->current_frame_host()->GetRenderWidgetHost()); |
| 481 RenderWidgetHostMouseEventMonitor child_frame_monitor( |
| 482 child_node->current_frame_host()->GetRenderWidgetHost()); |
| 483 |
| 484 RenderWidgetHostInputEventRouter* router = |
| 485 static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 486 ->GetInputEventRouter(); |
| 487 |
| 488 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 489 root->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 490 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>( |
| 491 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 492 |
| 493 // We need to wait for a compositor frame from the child frame, at which |
| 494 // point its surface will be created. |
| 495 while (rwhv_child->RendererFrameNumber() <= 0) { |
| 496 // TODO(lazyboy): Find a better way to avoid sleeping like this. See |
| 497 // http://crbug.com/405282 for details. |
| 498 base::RunLoop run_loop; |
| 499 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 500 FROM_HERE, run_loop.QuitClosure(), |
| 501 base::TimeDelta::FromMilliseconds(10)); |
| 502 run_loop.Run(); |
| 503 } |
| 504 |
| 505 uint32_t cur_render_frame_number = root_view->RendererFrameNumber(); |
| 506 |
| 507 // Target input event to child frame. |
| 508 blink::WebMouseEvent child_event; |
| 509 child_event.type = blink::WebInputEvent::MouseDown; |
| 510 child_event.button = blink::WebPointerProperties::ButtonLeft; |
| 511 child_event.x = 75; |
| 512 child_event.y = 75; |
| 513 child_event.clickCount = 1; |
| 514 router->RouteMouseEvent(root_view, &child_event); |
| 515 |
| 516 if (!child_frame_monitor.EventWasReceived()) { |
| 517 main_frame_monitor.ResetEventReceived(); |
| 518 // This is working around a big synchronization problem. It is very |
| 519 // difficult to know if we have received a compositor frame from the |
| 520 // main frame renderer *after* it received the child frame's surface |
| 521 // ID. Hit testing won't work until this happens. So if the hit test |
| 522 // fails then we wait for another frame to arrive and try again. |
| 523 // TODO(kenrb): We need a better way to do all of this, possibly coming |
| 524 // from http://crbug.com/405282. |
| 525 while (root_view->RendererFrameNumber() <= cur_render_frame_number) { |
| 526 base::RunLoop run_loop; |
| 527 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 528 FROM_HERE, run_loop.QuitClosure(), |
| 529 base::TimeDelta::FromMilliseconds(10)); |
| 530 run_loop.Run(); |
| 531 } |
| 532 router->RouteMouseEvent(root_view, &child_event); |
| 533 } |
| 534 |
| 535 EXPECT_TRUE(child_frame_monitor.EventWasReceived()); |
| 536 EXPECT_FALSE(main_frame_monitor.EventWasReceived()); |
| 537 |
| 538 child_frame_monitor.ResetEventReceived(); |
| 539 main_frame_monitor.ResetEventReceived(); |
| 540 |
| 541 // Target input event to main frame. |
| 542 blink::WebMouseEvent main_event; |
| 543 main_event.type = blink::WebInputEvent::MouseDown; |
| 544 main_event.button = blink::WebPointerProperties::ButtonLeft; |
| 545 main_event.x = 1; |
| 546 main_event.y = 1; |
| 547 main_event.clickCount = 1; |
| 548 // Ladies and gentlemen, THIS is the main_event! |
| 549 router->RouteMouseEvent(root_view, &main_event); |
| 550 |
| 551 EXPECT_FALSE(child_frame_monitor.EventWasReceived()); |
| 552 EXPECT_TRUE(main_frame_monitor.EventWasReceived()); |
| 553 } |
| 554 |
| 428 // Tests OOPIF rendering by checking that the RWH of the iframe generates | 555 // Tests OOPIF rendering by checking that the RWH of the iframe generates |
| 429 // OnSwapCompositorFrame message. | 556 // OnSwapCompositorFrame message. |
| 430 #if defined(OS_ANDROID) | 557 #if defined(OS_ANDROID) |
| 431 // http://crbug.com/471850 | 558 // http://crbug.com/471850 |
| 432 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped | 559 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped |
| 433 #else | 560 #else |
| 434 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped | 561 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped |
| 435 #endif | 562 #endif |
| 436 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 563 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 437 MAYBE_CompositorFrameSwapped) { | 564 MAYBE_CompositorFrameSwapped) { |
| (...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3032 success = false; | 3159 success = false; |
| 3033 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3160 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3034 popup_root->child_at(1)->current_frame_host(), | 3161 popup_root->child_at(1)->current_frame_host(), |
| 3035 "window.domAutomationController.send(" | 3162 "window.domAutomationController.send(" |
| 3036 " window.opener === window.opener.parent.frames['frame1']);", | 3163 " window.opener === window.opener.parent.frames['frame1']);", |
| 3037 &success)); | 3164 &success)); |
| 3038 EXPECT_TRUE(success); | 3165 EXPECT_TRUE(success); |
| 3039 } | 3166 } |
| 3040 | 3167 |
| 3041 } // namespace content | 3168 } // namespace content |
| OLD | NEW |