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

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

Issue 1308553007: Convert MouseEvents from DIPS to Pixels before passing it to surfaces for hittesting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleaning up 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"
(...skipping 23 matching lines...) Expand all
34 #include "content/public/test/test_navigation_observer.h" 34 #include "content/public/test/test_navigation_observer.h"
35 #include "content/public/test/test_utils.h" 35 #include "content/public/test/test_utils.h"
36 #include "content/shell/browser/shell.h" 36 #include "content/shell/browser/shell.h"
37 #include "content/test/content_browser_test_utils_internal.h" 37 #include "content/test/content_browser_test_utils_internal.h"
38 #include "content/test/test_frame_navigation_observer.h" 38 #include "content/test/test_frame_navigation_observer.h"
39 #include "ipc/ipc_security_test_util.h" 39 #include "ipc/ipc_security_test_util.h"
40 #include "net/dns/mock_host_resolver.h" 40 #include "net/dns/mock_host_resolver.h"
41 #include "net/test/embedded_test_server/embedded_test_server.h" 41 #include "net/test/embedded_test_server/embedded_test_server.h"
42 #include "third_party/WebKit/public/web/WebInputEvent.h" 42 #include "third_party/WebKit/public/web/WebInputEvent.h"
43 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 43 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
44 #include "ui/gfx/switches.h"
44 45
45 namespace content { 46 namespace content {
46 47
47 namespace { 48 namespace {
48 49
49 // Helper function to send a postMessage and wait for a reply message. The 50 // Helper function to send a postMessage and wait for a reply message. The
50 // |post_message_script| is executed on the |sender_ftn| frame, and the sender 51 // |post_message_script| is executed on the |sender_ftn| frame, and the sender
51 // frame is expected to post |reply_status| from the DOMAutomationController 52 // frame is expected to post |reply_status| from the DOMAutomationController
52 // when it receives a reply. 53 // when it receives a reply.
53 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, 54 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 const std::string& name) { 91 const std::string& name) {
91 bool success = false; 92 bool success = false;
92 EXPECT_TRUE(ExecuteScriptAndExtractBool( 93 EXPECT_TRUE(ExecuteScriptAndExtractBool(
93 caller_frame, 94 caller_frame,
94 "window.domAutomationController.send(" 95 "window.domAutomationController.send("
95 " !!window.open('" + url.spec() + "', '" + name + "'));", 96 " !!window.open('" + url.spec() + "', '" + name + "'));",
96 &success)); 97 &success));
97 EXPECT_TRUE(success); 98 EXPECT_TRUE(success);
98 } 99 }
99 100
101 class RenderWidgetHostMouseEventMonitor {
102 public:
103 RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host)
104 : host_(host), event_received(false) {
105 host_->AddMouseEventCallback(
106 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback,
107 base::Unretained(this)));
108 }
109 ~RenderWidgetHostMouseEventMonitor() {
110 host_->RemoveMouseEventCallback(
111 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback,
112 base::Unretained(this)));
113 }
114 bool EventWasReceived() { return event_received; }
115 void ResetEventReceived() { event_received = false; }
116 const blink::WebMouseEvent& event() const { return event_; }
117
118 private:
119 bool MouseEventCallback(const blink::WebMouseEvent& event) {
120 event_received = true;
121 event_ = event;
122 return false;
123 }
124 RenderWidgetHost* host_;
125 bool event_received;
126 blink::WebMouseEvent event_;
127 };
128
129 // Helper function that performs a surface hittest.
130 void SurfaceHitTestTestHelper(
131 Shell* shell,
132 net::test_server::EmbeddedTestServer* embedded_test_server) {
133 if (!UseSurfacesEnabled())
134 return;
135
136 GURL main_url(embedded_test_server->GetURL(
137 "/frame_tree/page_with_positioned_frame.html"));
138 NavigateToURL(shell, main_url);
139
140 // It is safe to obtain the root frame tree node here, as it doesn't change.
141 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell->web_contents())
142 ->GetFrameTree()
143 ->root();
144 ASSERT_EQ(1U, root->child_count());
145
146 FrameTreeNode* child_node = root->child_at(0);
147 GURL site_url(embedded_test_server->GetURL("baz.com", "/title1.html"));
148 EXPECT_EQ(site_url, child_node->current_url());
149 EXPECT_NE(shell->web_contents()->GetSiteInstance(),
150 child_node->current_frame_host()->GetSiteInstance());
151
152 // Create listeners for mouse events.
153 RenderWidgetHostMouseEventMonitor main_frame_monitor(
154 root->current_frame_host()->GetRenderWidgetHost());
155 RenderWidgetHostMouseEventMonitor child_frame_monitor(
156 child_node->current_frame_host()->GetRenderWidgetHost());
157
158 RenderWidgetHostInputEventRouter* router =
159 static_cast<WebContentsImpl*>(shell->web_contents())
160 ->GetInputEventRouter();
161
162 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
163 root->current_frame_host()->GetRenderWidgetHost()->GetView());
164 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>(
165 child_node->current_frame_host()->GetRenderWidgetHost()->GetView());
166
167 // We need to wait for a compositor frame from the child frame, at which
168 // point its surface will be created.
169 while (rwhv_child->RendererFrameNumber() <= 0) {
170 // TODO(lazyboy): Find a better way to avoid sleeping like this. See
171 // http://crbug.com/405282 for details.
172 base::RunLoop run_loop;
173 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
174 FROM_HERE, run_loop.QuitClosure(),
175 base::TimeDelta::FromMilliseconds(10));
176 run_loop.Run();
177 }
178
179 uint32_t cur_render_frame_number = root_view->RendererFrameNumber();
180
181 // Target input event to child frame.
182 blink::WebMouseEvent child_event;
183 child_event.type = blink::WebInputEvent::MouseDown;
184 child_event.button = blink::WebPointerProperties::ButtonLeft;
185 child_event.x = 75;
186 child_event.y = 75;
187 child_event.clickCount = 1;
188 router->RouteMouseEvent(root_view, &child_event);
189
190 if (!child_frame_monitor.EventWasReceived()) {
191 main_frame_monitor.ResetEventReceived();
192 // This is working around a big synchronization problem. It is very
193 // difficult to know if we have received a compositor frame from the
194 // main frame renderer *after* it received the child frame's surface
195 // ID. Hit testing won't work until this happens. So if the hit test
196 // fails then we wait for another frame to arrive and try again.
197 // TODO(kenrb): We need a better way to do all of this, possibly coming
198 // from http://crbug.com/405282.
199 while (root_view->RendererFrameNumber() <= cur_render_frame_number) {
200 base::RunLoop run_loop;
201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
202 FROM_HERE, run_loop.QuitClosure(),
203 base::TimeDelta::FromMilliseconds(10));
204 run_loop.Run();
205 }
206 router->RouteMouseEvent(root_view, &child_event);
207 }
208
209 EXPECT_TRUE(child_frame_monitor.EventWasReceived());
210 EXPECT_EQ(23, child_frame_monitor.event().x);
211 EXPECT_EQ(23, child_frame_monitor.event().y);
212 EXPECT_FALSE(main_frame_monitor.EventWasReceived());
213
214 child_frame_monitor.ResetEventReceived();
215 main_frame_monitor.ResetEventReceived();
216
217 // Target input event to main frame.
218 blink::WebMouseEvent main_event;
219 main_event.type = blink::WebInputEvent::MouseDown;
220 main_event.button = blink::WebPointerProperties::ButtonLeft;
221 main_event.x = 1;
222 main_event.y = 1;
223 main_event.clickCount = 1;
224 // Ladies and gentlemen, THIS is the main_event!
225 router->RouteMouseEvent(root_view, &main_event);
226
227 EXPECT_FALSE(child_frame_monitor.EventWasReceived());
228 EXPECT_TRUE(main_frame_monitor.EventWasReceived());
229 EXPECT_EQ(1, main_frame_monitor.event().x);
230 EXPECT_EQ(1, main_frame_monitor.event().y);
231 }
232
100 class RedirectNotificationObserver : public NotificationObserver { 233 class RedirectNotificationObserver : public NotificationObserver {
101 public: 234 public:
102 // Register to listen for notifications of the given type from either a 235 // Register to listen for notifications of the given type from either a
103 // specific source, or from all sources if |source| is 236 // specific source, or from all sources if |source| is
104 // NotificationService::AllSources(). 237 // NotificationService::AllSources().
105 RedirectNotificationObserver(int notification_type, 238 RedirectNotificationObserver(int notification_type,
106 const NotificationSource& source); 239 const NotificationSource& source);
107 ~RedirectNotificationObserver() override; 240 ~RedirectNotificationObserver() override;
108 241
109 // Wait until the specified notification occurs. If the notification was 242 // Wait until the specified notification occurs. If the notification was
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 base::CommandLine* command_line) { 443 base::CommandLine* command_line) {
311 IsolateAllSitesForTesting(command_line); 444 IsolateAllSitesForTesting(command_line);
312 }; 445 };
313 446
314 void SitePerProcessBrowserTest::SetUpOnMainThread() { 447 void SitePerProcessBrowserTest::SetUpOnMainThread() {
315 host_resolver()->AddRule("*", "127.0.0.1"); 448 host_resolver()->AddRule("*", "127.0.0.1");
316 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 449 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
317 SetupCrossSiteRedirector(embedded_test_server()); 450 SetupCrossSiteRedirector(embedded_test_server());
318 } 451 }
319 452
453 //
454 // SitePerProcessHighDPIBrowserTest
455 //
456
457 SitePerProcessHighDPIBrowserTest::SitePerProcessHighDPIBrowserTest() {
458 };
459
460 void SitePerProcessHighDPIBrowserTest::SetUpCommandLine(
461 base::CommandLine* command_line) {
462 SitePerProcessBrowserTest::SetUpCommandLine(command_line);
463 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
464 base::StringPrintf("2"));
465 };
466
320 // Ensure that navigating subframes in --site-per-process mode works and the 467 // Ensure that navigating subframes in --site-per-process mode works and the
321 // correct documents are committed. 468 // correct documents are committed.
322 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { 469 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) {
323 GURL main_url(embedded_test_server()->GetURL( 470 GURL main_url(embedded_test_server()->GetURL(
324 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))")); 471 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))"));
325 NavigateToURL(shell(), main_url); 472 NavigateToURL(shell(), main_url);
326 473
327 // It is safe to obtain the root frame tree node here, as it doesn't change. 474 // It is safe to obtain the root frame tree node here, as it doesn't change.
328 FrameTreeNode* root = 475 FrameTreeNode* root =
329 static_cast<WebContentsImpl*>(shell()->web_contents())-> 476 static_cast<WebContentsImpl*>(shell()->web_contents())->
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 " |--Site C ------- proxies for A\n" 586 " |--Site C ------- proxies for A\n"
440 " +--Site A ------- proxies for C\n" 587 " +--Site A ------- proxies for C\n"
441 " |--Site A -- proxies for C\n" 588 " |--Site A -- proxies for C\n"
442 " +--Site A -- proxies for C\n" 589 " +--Site A -- proxies for C\n"
443 " +--Site A -- proxies for C\n" 590 " +--Site A -- proxies for C\n"
444 "Where A = http://a.com/\n" 591 "Where A = http://a.com/\n"
445 " C = http://bar.com/", 592 " C = http://bar.com/",
446 DepictFrameTree(root)); 593 DepictFrameTree(root));
447 } 594 }
448 595
449 class RenderWidgetHostMouseEventMonitor {
450 public:
451 RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host)
452 : host_(host), event_received(false) {
453 host_->AddMouseEventCallback(
454 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback,
455 base::Unretained(this)));
456 }
457 ~RenderWidgetHostMouseEventMonitor() {
458 host_->RemoveMouseEventCallback(
459 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback,
460 base::Unretained(this)));
461 }
462 bool EventWasReceived() { return event_received; }
463 void ResetEventReceived() { event_received = false; }
464 const blink::WebMouseEvent& event() const { return event_; }
465
466 private:
467 bool MouseEventCallback(const blink::WebMouseEvent& event) {
468 event_received = true;
469 event_ = event;
470 return false;
471 }
472 RenderWidgetHost* host_;
473 bool event_received;
474 blink::WebMouseEvent event_;
475 };
476
477 // Test that mouse events are being routed to the correct RenderWidgetHostView 596 // Test that mouse events are being routed to the correct RenderWidgetHostView
478 // based on coordinates. 597 // based on coordinates.
479 #if defined(OS_ANDROID) || defined(THREAD_SANITIZER) || defined(OS_LINUX) 598 #if defined(OS_ANDROID) || defined(THREAD_SANITIZER) || defined(OS_LINUX)
480 // Browser process hit testing is not implemented on Android. 599 // Browser process hit testing is not implemented on Android.
481 // https://crbug.com/491334 600 // https://crbug.com/491334
482 // Test fails under TSAN, see https://crbug.com/527618 601 // Test fails under TSAN, see https://crbug.com/527618
483 // Test is flaky under Linux, see https://crbug.com/528189 602 // Test is flaky under Linux, see https://crbug.com/528189
484 #define MAYBE_SurfaceHitTestTest DISABLED_SurfaceHitTestTest 603 #define MAYBE_SurfaceHitTestTest DISABLED_SurfaceHitTestTest
485 #else 604 #else
486 #define MAYBE_SurfaceHitTestTest SurfaceHitTestTest 605 #define MAYBE_SurfaceHitTestTest SurfaceHitTestTest
487 #endif 606 #endif
488 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_SurfaceHitTestTest) { 607 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, MAYBE_SurfaceHitTestTest) {
489 if (!UseSurfacesEnabled()) 608 SurfaceHitTestTestHelper(shell(), embedded_test_server());
490 return; 609 }
491 610
492 GURL main_url(embedded_test_server()->GetURL( 611 // Same test as above, but runs in high-dpi mode.
493 "/frame_tree/page_with_positioned_frame.html")); 612 IN_PROC_BROWSER_TEST_F(SitePerProcessHighDPIBrowserTest,
494 NavigateToURL(shell(), main_url); 613 MAYBE_SurfaceHitTestTest) {
495 614 SurfaceHitTestTestHelper(shell(), embedded_test_server());
496 // It is safe to obtain the root frame tree node here, as it doesn't change.
497 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
498 ->GetFrameTree()
499 ->root();
500 ASSERT_EQ(1U, root->child_count());
501
502 FrameTreeNode* child_node = root->child_at(0);
503 GURL site_url(embedded_test_server()->GetURL("baz.com", "/title1.html"));
504 EXPECT_EQ(site_url, child_node->current_url());
505 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
506 child_node->current_frame_host()->GetSiteInstance());
507
508 // Create listeners for mouse events.
509 RenderWidgetHostMouseEventMonitor main_frame_monitor(
510 root->current_frame_host()->GetRenderWidgetHost());
511 RenderWidgetHostMouseEventMonitor child_frame_monitor(
512 child_node->current_frame_host()->GetRenderWidgetHost());
513
514 RenderWidgetHostInputEventRouter* router =
515 static_cast<WebContentsImpl*>(shell()->web_contents())
516 ->GetInputEventRouter();
517
518 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
519 root->current_frame_host()->GetRenderWidgetHost()->GetView());
520 RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>(
521 child_node->current_frame_host()->GetRenderWidgetHost()->GetView());
522
523 // We need to wait for a compositor frame from the child frame, at which
524 // point its surface will be created.
525 while (rwhv_child->RendererFrameNumber() <= 0) {
526 // TODO(lazyboy): Find a better way to avoid sleeping like this. See
527 // http://crbug.com/405282 for details.
528 base::RunLoop run_loop;
529 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
530 FROM_HERE, run_loop.QuitClosure(),
531 base::TimeDelta::FromMilliseconds(10));
532 run_loop.Run();
533 }
534
535 uint32_t cur_render_frame_number = root_view->RendererFrameNumber();
536
537 // Target input event to child frame.
538 blink::WebMouseEvent child_event;
539 child_event.type = blink::WebInputEvent::MouseDown;
540 child_event.button = blink::WebPointerProperties::ButtonLeft;
541 child_event.x = 75;
542 child_event.y = 75;
543 child_event.clickCount = 1;
544 router->RouteMouseEvent(root_view, &child_event);
545
546 if (!child_frame_monitor.EventWasReceived()) {
547 main_frame_monitor.ResetEventReceived();
548 // This is working around a big synchronization problem. It is very
549 // difficult to know if we have received a compositor frame from the
550 // main frame renderer *after* it received the child frame's surface
551 // ID. Hit testing won't work until this happens. So if the hit test
552 // fails then we wait for another frame to arrive and try again.
553 // TODO(kenrb): We need a better way to do all of this, possibly coming
554 // from http://crbug.com/405282.
555 while (root_view->RendererFrameNumber() <= cur_render_frame_number) {
556 base::RunLoop run_loop;
557 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
558 FROM_HERE, run_loop.QuitClosure(),
559 base::TimeDelta::FromMilliseconds(10));
560 run_loop.Run();
561 }
562 router->RouteMouseEvent(root_view, &child_event);
563 }
564
565 EXPECT_TRUE(child_frame_monitor.EventWasReceived());
566 EXPECT_EQ(23, child_frame_monitor.event().x);
567 EXPECT_EQ(23, child_frame_monitor.event().y);
568 EXPECT_FALSE(main_frame_monitor.EventWasReceived());
569
570 child_frame_monitor.ResetEventReceived();
571 main_frame_monitor.ResetEventReceived();
572
573 // Target input event to main frame.
574 blink::WebMouseEvent main_event;
575 main_event.type = blink::WebInputEvent::MouseDown;
576 main_event.button = blink::WebPointerProperties::ButtonLeft;
577 main_event.x = 1;
578 main_event.y = 1;
579 main_event.clickCount = 1;
580 // Ladies and gentlemen, THIS is the main_event!
581 router->RouteMouseEvent(root_view, &main_event);
582
583 EXPECT_FALSE(child_frame_monitor.EventWasReceived());
584 EXPECT_TRUE(main_frame_monitor.EventWasReceived());
585 EXPECT_EQ(1, main_frame_monitor.event().x);
586 EXPECT_EQ(1, main_frame_monitor.event().y);
587 } 615 }
588 616
589 // Tests OOPIF rendering by checking that the RWH of the iframe generates 617 // Tests OOPIF rendering by checking that the RWH of the iframe generates
590 // OnSwapCompositorFrame message. 618 // OnSwapCompositorFrame message.
591 #if defined(OS_ANDROID) 619 #if defined(OS_ANDROID)
592 // http://crbug.com/471850 620 // http://crbug.com/471850
593 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped 621 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped
594 #else 622 #else
595 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped 623 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped
596 #endif 624 #endif
(...skipping 2994 matching lines...) Expand 10 before | Expand all | Expand 10 after
3591 3619
3592 // CursorMessageFilter::Wait() implicitly tests whether we receive a 3620 // CursorMessageFilter::Wait() implicitly tests whether we receive a
3593 // ViewHostMsg_SetCursor message from the renderer process, because it does 3621 // ViewHostMsg_SetCursor message from the renderer process, because it does
3594 // does not return otherwise. 3622 // does not return otherwise.
3595 filter->Wait(); 3623 filter->Wait();
3596 EXPECT_EQ(filter->last_set_cursor_routing_id(), rwh_child->GetRoutingID()); 3624 EXPECT_EQ(filter->last_set_cursor_routing_id(), rwh_child->GetRoutingID());
3597 } 3625 }
3598 #endif 3626 #endif
3599 3627
3600 } // namespace content 3628 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698