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

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

Issue 2743223003: Mark sub-frame root layer non-fast scrollable when wheel handlers present. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | content/renderer/gpu/render_widget_compositor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 5362 matching lines...) Expand 10 before | Expand all | Expand 10 after
5373 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); 5373 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url);
5374 5374
5375 // Use new window to navigate main window. 5375 // Use new window to navigate main window.
5376 std::string script = 5376 std::string script =
5377 "window.opener.location.href = '" + cross_url.spec() + "'"; 5377 "window.opener.location.href = '" + cross_url.spec() + "'";
5378 EXPECT_TRUE(ExecuteScript(popup, script)); 5378 EXPECT_TRUE(ExecuteScript(popup, script));
5379 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 5379 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
5380 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); 5380 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url);
5381 } 5381 }
5382 5382
5383 #if defined(USE_AURA)
5384 // Browser process hit testing is not implemented on Android, and these tests
5385 // require Aura for RenderWidgetHostViewAura::OnTouchEvent().
5386 // https://crbug.com/491334
5387
5388 // Ensure that scroll events can be cancelled with a wheel handler.
5389 // https://crbug.com/698195
5390
5391 class SitePerProcessMouseWheelBrowserTest : public SitePerProcessBrowserTest {
5392 public:
5393 SitePerProcessMouseWheelBrowserTest() : rwhv_root_(nullptr) {}
5394
5395 void SetupWheelAndScrollHandlers(content::RenderFrameHostImpl* rfh) {
5396 // Set up event handlers. The wheel event handler calls prevent default on
5397 // alternate events, so only every other wheel generates a scroll. The fact
5398 // that any scroll events fire is dependent on the event going to the main
5399 // thread, which requires the nonFastScrollableRegion be set correctly
5400 // on the compositor.
5401 std::string script =
5402 "wheel_count = 0;"
5403 "function wheel_handler(e) {"
5404 " wheel_count++;"
5405 " if (wheel_count % 2 == 0)"
5406 " e.preventDefault();\n"
5407 " domAutomationController.setAutomationId(0);"
5408 " domAutomationController.send('wheel: ' + wheel_count);"
5409 "}"
5410 "function scroll_handler(e) {"
5411 " domAutomationController.setAutomationId(0);"
5412 " domAutomationController.send('scroll: ' + wheel_count);"
5413 "}"
5414 "scroll_div = document.getElementById('scrollable_div');"
5415 "scroll_div.addEventListener('wheel', wheel_handler);"
5416 "scroll_div.addEventListener('scroll', scroll_handler);"
5417 "domAutomationController.setAutomationId(0);"
5418 "domAutomationController.send('wheel handler installed');"
5419 "document.body.style.background = 'black';";
5420
5421 content::DOMMessageQueue msg_queue;
5422 std::string reply;
5423 EXPECT_TRUE(ExecuteScript(rfh, script));
5424
5425 // Wait until renderer's compositor thread is synced. Otherwise the event
5426 // handler won't be installed when the event arrives.
5427 {
5428 MainThreadFrameObserver observer(rfh->GetRenderWidgetHost());
5429 observer.Wait();
5430 }
5431 }
5432
5433 void SendMouseWheel(gfx::Point location) {
5434 DCHECK(rwhv_root_);
5435 ui::ScrollEvent scroll_event(ui::ET_SCROLL, location, ui::EventTimeForNow(),
5436 0, 0, -ui::MouseWheelEvent::kWheelDelta, 0,
5437 ui::MouseWheelEvent::kWheelDelta,
5438 2); // This must be '2' or it gets silently
5439 // dropped.
5440 rwhv_root_->OnScrollEvent(&scroll_event);
5441 }
5442
5443 void set_rwhv_root(RenderWidgetHostViewAura* rwhv_root) {
5444 rwhv_root_ = rwhv_root;
5445 }
5446
5447 void RunTest(gfx::Point pos) {
5448 content::DOMMessageQueue msg_queue;
5449 std::string reply;
5450
5451 auto* rwhv_root = static_cast<RenderWidgetHostViewAura*>(
5452 web_contents()->GetRenderWidgetHostView());
5453 set_rwhv_root(rwhv_root);
5454
5455 SendMouseWheel(pos);
5456
5457 // Expect both wheel and scroll handlers to fire.
5458 EXPECT_TRUE(msg_queue.WaitForMessage(&reply));
5459 EXPECT_EQ("\"wheel: 1\"", reply);
5460 EXPECT_TRUE(msg_queue.WaitForMessage(&reply));
5461 EXPECT_EQ("\"scroll: 1\"", reply);
5462
5463 SendMouseWheel(pos);
5464
5465 // This time only the wheel handler fires, since it prevent defaults on
5466 // even numbered scrolls.
5467 EXPECT_TRUE(msg_queue.WaitForMessage(&reply));
5468 EXPECT_EQ("\"wheel: 2\"", reply);
5469
5470 SendMouseWheel(pos);
5471
5472 // Odd number of wheels, expect both wheel and scroll handlers to fire
5473 // again.
5474 EXPECT_TRUE(msg_queue.WaitForMessage(&reply));
5475 EXPECT_EQ("\"wheel: 3\"", reply);
5476 EXPECT_TRUE(msg_queue.WaitForMessage(&reply));
5477 EXPECT_EQ("\"scroll: 3\"", reply);
5478 }
5479
5480 private:
5481 RenderWidgetHostViewAura* rwhv_root_;
5482 };
5483
5484 IN_PROC_BROWSER_TEST_F(SitePerProcessMouseWheelBrowserTest,
5485 SubframeWheelEventsOnMainThread) {
5486 GURL main_url(embedded_test_server()->GetURL(
5487 "/frame_tree/page_with_positioned_nested_frames.html"));
5488 EXPECT_TRUE(NavigateToURL(shell(), main_url));
5489
5490 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
5491 ASSERT_EQ(1U, root->child_count());
5492
5493 GURL frame_url(embedded_test_server()->GetURL(
5494 "b.com", "/page_with_scrollable_div.html"));
5495 NavigateFrameToURL(root->child_at(0), frame_url);
5496
5497 // Synchronize with the child and parent renderers to guarantee that the
5498 // surface information required for event hit testing is ready.
5499 RenderWidgetHostViewBase* child_rwhv = static_cast<RenderWidgetHostViewBase*>(
5500 root->child_at(0)->current_frame_host()->GetView());
5501 SurfaceHitTestReadyNotifier notifier(
5502 static_cast<RenderWidgetHostViewChildFrame*>(child_rwhv));
5503 notifier.WaitForSurfaceReady();
5504
5505 content::RenderFrameHostImpl* child = root->child_at(0)->current_frame_host();
5506 SetupWheelAndScrollHandlers(child);
5507
5508 gfx::Rect bounds = child_rwhv->GetViewBounds();
5509 gfx::Point pos(bounds.x() + 10, bounds.y() + 10);
5510
5511 RunTest(pos);
5512 }
5513
5514 // Verifies that test in SubframeWheelEventsOnMainThread also makes sense for
5515 // the same page loaded in the mainframe.
5516 IN_PROC_BROWSER_TEST_F(SitePerProcessMouseWheelBrowserTest,
5517 MainframeWheelEventsOnMainThread) {
5518 GURL main_url(
5519 embedded_test_server()->GetURL("/page_with_scrollable_div.html"));
5520 EXPECT_TRUE(NavigateToURL(shell(), main_url));
5521
5522 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
5523 content::RenderFrameHostImpl* rfhi = root->current_frame_host();
5524 SetupWheelAndScrollHandlers(rfhi);
5525
5526 gfx::Point pos(10, 10);
5527
5528 RunTest(pos);
5529 }
5530
5383 // Ensure that a cross-process subframe with a touch-handler can receive touch 5531 // Ensure that a cross-process subframe with a touch-handler can receive touch
5384 // events. 5532 // events.
5385 #if defined(USE_AURA)
5386 // Browser process hit testing is not implemented on Android, and this test
5387 // requires Aura for RenderWidgetHostViewAura::OnTouchEvent().
5388 // https://crbug.com/491334
5389 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 5533 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
5390 SubframeTouchEventRouting) { 5534 SubframeTouchEventRouting) {
5391 GURL main_url(embedded_test_server()->GetURL( 5535 GURL main_url(embedded_test_server()->GetURL(
5392 "/frame_tree/page_with_positioned_nested_frames.html")); 5536 "/frame_tree/page_with_positioned_nested_frames.html"));
5393 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 5537 EXPECT_TRUE(NavigateToURL(shell(), main_url));
5394 5538
5395 WebContentsImpl* contents = web_contents(); 5539 WebContentsImpl* contents = web_contents();
5396 FrameTreeNode* root = contents->GetFrameTree()->root(); 5540 FrameTreeNode* root = contents->GetFrameTree()->root();
5397 ASSERT_EQ(1U, root->child_count()); 5541 ASSERT_EQ(1U, root->child_count());
5398 5542
(...skipping 4177 matching lines...) Expand 10 before | Expand all | Expand 10 after
9576 9720
9577 // Try the same navigation, but use the browser-initiated path. 9721 // Try the same navigation, but use the browser-initiated path.
9578 NavigateFrameToURL(root->child_at(0), frame_url); 9722 NavigateFrameToURL(root->child_at(0), frame_url);
9579 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host()); 9723 EXPECT_FALSE(root->child_at(0)->render_manager()->pending_frame_host());
9580 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url); 9724 EXPECT_EQ(root->child_at(0)->current_url(), redirected_url);
9581 EXPECT_EQ(b_site_instance, 9725 EXPECT_EQ(b_site_instance,
9582 root->child_at(0)->current_frame_host()->GetSiteInstance()); 9726 root->child_at(0)->current_frame_host()->GetSiteInstance());
9583 } 9727 }
9584 9728
9585 } // namespace content 9729 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/gpu/render_widget_compositor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698