Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1382593004: Allow out-of-process iframes to update the mouse cursor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved feng shui Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gpu/compositor_util.h"
23 #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" 24 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
25 #include "content/browser/web_contents/web_contents_impl.h" 25 #include "content/browser/web_contents/web_contents_impl.h"
26 #include "content/common/frame_messages.h" 26 #include "content/common/frame_messages.h"
27 #include "content/common/view_messages.h"
27 #include "content/public/browser/notification_observer.h" 28 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
30 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
31 #include "content/public/test/browser_test_utils.h" 32 #include "content/public/test/browser_test_utils.h"
32 #include "content/public/test/content_browser_test_utils.h" 33 #include "content/public/test/content_browser_test_utils.h"
33 #include "content/public/test/test_navigation_observer.h" 34 #include "content/public/test/test_navigation_observer.h"
34 #include "content/public/test/test_utils.h" 35 #include "content/public/test/test_utils.h"
35 #include "content/shell/browser/shell.h" 36 #include "content/shell/browser/shell.h"
36 #include "content/test/content_browser_test_utils_internal.h" 37 #include "content/test/content_browser_test_utils_internal.h"
(...skipping 3470 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 // document's body. 3508 // document's body.
3508 while (msg_queue.WaitForMessage(&status)) { 3509 while (msg_queue.WaitForMessage(&status)) {
3509 if (status == "\"document-blur\"") 3510 if (status == "\"document-blur\"")
3510 break; 3511 break;
3511 } 3512 }
3512 3513
3513 // The root frame should be focused again. 3514 // The root frame should be focused again.
3514 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); 3515 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame());
3515 } 3516 }
3516 3517
3518 class CursorMessageFilter : public content::BrowserMessageFilter {
3519 public:
3520 explicit CursorMessageFilter()
dcheng 2015/10/05 06:48:24 No explicit.
kenrb 2015/10/06 17:39:19 Done.
3521 : content::BrowserMessageFilter(ViewMsgStart),
3522 message_loop_runner_(new content::MessageLoopRunner),
3523 last_set_cursor_routing_id_(MSG_ROUTING_NONE) {}
3524
3525 bool OnMessageReceived(const IPC::Message& message) override {
3526 if (message.type() == ViewHostMsg_SetCursor::ID) {
3527 content::BrowserThread::PostTask(
3528 content::BrowserThread::UI, FROM_HERE,
3529 base::Bind(&CursorMessageFilter::OnSetCursor, this,
3530 message.routing_id()));
3531 }
3532 return false;
3533 }
3534
3535 void OnSetCursor(int routing_id) {
3536 last_set_cursor_routing_id_ = routing_id;
3537 message_loop_runner_->Quit();
3538 }
3539
3540 int last_set_cursor_routing_id() { return last_set_cursor_routing_id_; }
dcheng 2015/10/05 06:48:24 Nit: const.
kenrb 2015/10/06 17:39:19 Done.
3541
3542 bool Wait() WARN_UNUSED_RESULT {
3543 last_set_cursor_routing_id_ = MSG_ROUTING_NONE;
3544 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
nasko 2015/10/05 18:18:46 Why do we need to post a task at all? If we never
kenrb 2015/10/06 17:39:19 When I tried locally without this, the test ran fo
3545 FROM_HERE, message_loop_runner_->QuitClosure(),
3546 base::TimeDelta::FromMilliseconds(2000));
dcheng 2015/10/05 06:48:24 Is there any significance to 2 seconds?
kenrb 2015/10/06 17:39:19 No, it's arbitrary. Just needed a value large enou
3547 message_loop_runner_->Run();
3548 if (last_set_cursor_routing_id_ == MSG_ROUTING_NONE)
3549 return false;
3550 return true;
3551 }
3552
3553 private:
3554 ~CursorMessageFilter() override {}
3555
3556 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
3557 int last_set_cursor_routing_id_;
3558
3559 DISALLOW_COPY_AND_ASSIGN(CursorMessageFilter);
3560 };
3561
3562 // Verify that we receive a mouse cursor update message when we mouse over
3563 // a text field contained in an out-of-process iframe.
3564 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
3565 CursorUpdateFromReceivedFromCrossSiteIframe) {
3566 GURL main_url(embedded_test_server()->GetURL(
3567 "/frame_tree/page_with_positioned_frame.html"));
3568 EXPECT_TRUE(NavigateToURL(shell(), main_url));
3569
3570 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
3571 ->GetFrameTree()
3572 ->root();
3573
3574 FrameTreeNode* child_node = root->child_at(0);
3575 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
3576 child_node->current_frame_host()->GetSiteInstance());
3577
3578 scoped_refptr<CursorMessageFilter> filter = new CursorMessageFilter();
3579 child_node->current_frame_host()->GetProcess()->AddFilter(filter.get());
3580
3581 // Send a MouseMove to the subframe. The frame contains text, and moving the
3582 // mouse over it should cause the renderer to send a mouse cursor update.
3583 blink::WebMouseEvent mouse_event;
3584 mouse_event.type = blink::WebInputEvent::MouseMove;
3585 mouse_event.x = 60;
3586 mouse_event.y = 60;
3587 RenderWidgetHost* rwh_child =
3588 root->child_at(0)->current_frame_host()->GetRenderWidgetHost();
3589 // rwh_child->ForwardMouseEvent(mouse_event);
3590 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
3591 root->current_frame_host()->GetRenderWidgetHost()->GetView());
3592 static_cast<WebContentsImpl*>(shell()->web_contents())
3593 ->GetInputEventRouter()
3594 ->RouteMouseEvent(root_view, &mouse_event);
3595
3596 EXPECT_TRUE(filter->Wait());
3597 EXPECT_EQ(filter->last_set_cursor_routing_id(), rwh_child->GetRoutingID());
3598 }
3599
3517 } // namespace content 3600 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698