#include "content/browser/site_per_process_browsertest.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/cross_process_frame_connector.h"
#include "content/browser/renderer_host/frame_tree.h"
#include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
#include "content/browser/renderer_host/render_frame_proxy_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/test/render_document_feature.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/native_theme/native_theme_features.h"
namespace content {
class ScrollingIntegrationTest : public SitePerProcessBrowserTest {
public:
ScrollingIntegrationTest() = default;
~ScrollingIntegrationTest() override = default;
void DoScroll(const gfx::Point& point,
const gfx::Vector2d& distance,
content::mojom::GestureSourceType source) {
SyntheticSmoothScrollGestureParams params;
params.gesture_source_type = source;
params.anchor = gfx::PointF(point);
params.distances.push_back(-distance);
params.granularity = ui::ScrollGranularity::kScrollByPrecisePixel;
auto gesture = std::make_unique<SyntheticSmoothScrollGesture>(params);
base::RunLoop run_loop;
GetRenderWidgetHostImpl()->QueueSyntheticGesture(
std::move(gesture),
base::BindLambdaForTesting([&](SyntheticGesture::Result result) {
EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result);
run_loop.Quit();
}));
run_loop.Run();
}
double GetScrollTop() {
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetPrimaryFrameTree()
.root();
return EvalJs(root, "window.scrollY").ExtractDouble();
}
void WaitForVerticalScroll() {
RenderFrameSubmissionObserver frame_observer(shell()->web_contents());
gfx::PointF default_scroll_offset;
while (frame_observer.LastRenderFrameMetadata()
.root_scroll_offset.value_or(default_scroll_offset)
.y() <= 0) {
frame_observer.WaitForMetadataChange();
}
}
RenderWidgetHostImpl* GetRenderWidgetHostImpl() {
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetPrimaryFrameTree()
.root();
return root->current_frame_host()->GetRenderWidgetHost();
}
};
IN_PROC_BROWSER_TEST_P(ScrollingIntegrationTest,
ScrollAfterCrossOriginNavigation) {
GURL url_domain_a(
embedded_test_server()->GetURL("a.com", "/simple_page.html"));
EXPECT_TRUE(NavigateToURL(shell(), url_domain_a));
GURL url_domain_b(embedded_test_server()->GetURL(
"baz.com", "/scrollable_page_with_iframe.html"));
EXPECT_TRUE(NavigateToURL(shell(), url_domain_b));
ASSERT_TRUE(WaitForLoadStop(shell()->web_contents()));
{
base::RunLoop run_loop;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), base::Milliseconds(3000));
run_loop.Run();
}
content::mojom::GestureSourceType source;
#if BUILDFLAG(IS_ANDROID)
source = content::mojom::GestureSourceType::kTouchInput;
#else
source = content::mojom::GestureSourceType::kTouchpadInput;
#endif
DoScroll(gfx::Point(100, 110), gfx::Vector2d(0, 500), source);
WaitForVerticalScroll();
EXPECT_GT(GetScrollTop(), 0);
}
class SitePerProcessScrollAnchorTest : public SitePerProcessBrowserTest {
public:
SitePerProcessScrollAnchorTest() = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
SitePerProcessBrowserTestBase::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures,
"ScrollAnchorSerialization");
}
};
IN_PROC_BROWSER_TEST_P(SitePerProcessScrollAnchorTest,
RemoteToLocalScrollAnchorRestore) {
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/page_with_samesite_iframe.html"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = web_contents()->GetPrimaryFrameTree().root();
FrameTreeNode* child = root->child_at(0);
GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html"));
EXPECT_TRUE(NavigateToURLFromRenderer(child, frame_url));
EXPECT_NE(child->current_frame_host()->GetSiteInstance(),
root->current_frame_host()->GetSiteInstance());
TestFrameNavigationObserver frame_observer2(child);
EXPECT_TRUE(ExecJs(root, "window.history.back()"));
frame_observer2.Wait();
EXPECT_EQ(child->current_frame_host()->GetSiteInstance(),
root->current_frame_host()->GetSiteInstance());
}
class SitePerProcessProgrammaticScrollTest : public SitePerProcessBrowserTest {
public:
SitePerProcessProgrammaticScrollTest()
: kPositiveXYPlane(0, 0, kInfinity, kInfinity) {}
SitePerProcessProgrammaticScrollTest(
const SitePerProcessProgrammaticScrollTest&) = delete;
SitePerProcessProgrammaticScrollTest& operator=(
const SitePerProcessProgrammaticScrollTest&) = delete;
protected:
const size_t kInfinity = 1000000u;
const std::string kIframeOutOfViewHTML = "/iframe_out_of_view.html";
const std::string kIframeClippedHTML = "/iframe_clipped.html";
const std::string kInputBoxHTML = "/input_box.html";
const std::string kIframeSelector = "iframe";
const std::string kInputSelector = "input";
const gfx::Rect kPositiveXYPlane;
void WaitForOnLoad(FrameTreeNode* node) {
RunCommandAndWaitForResponse(node, "notifyWhenLoaded();", "LOADED");
}
void WaitForElementVisible(FrameTreeNode* node, const std::string& sel) {
RunCommandAndWaitForResponse(
node,
base::StringPrintf("notifyWhenVisible(document.querySelector('%s'));",
sel.c_str()),
"VISIBLE");
}
void WaitForViewportToStabilize(FrameTreeNode* node) {
RunCommandAndWaitForResponse(node, "notifyWhenViewportStable(0);",
"VIEWPORT_STABLE");
}
void AddFocusedInputField(FrameTreeNode* node) {
ASSERT_TRUE(ExecJs(node, "addFocusedInputField();"));
}
void SetWindowScroll(FrameTreeNode* node, int x, int y) {
ASSERT_TRUE(
ExecJs(node, base::StringPrintf("window.scrollTo(%d, %d);", x, y)));
}
gfx::Rect GetBoundingClientRect(RenderFrameHostImpl* rfh,
const std::string& sel) {
return GetRectFromString(
EvalJs(rfh, JsReplace("rectAsString(document.querySelector($1)."
"getBoundingClientRect());",
sel))
.ExtractString());
}
gfx::Rect GetVisualViewport(FrameTreeNode* node) {
return GetRectFromString(
EvalJs(node, "rectAsString(visualViewportAsRect());").ExtractString());
}
float GetVisualViewportScale(FrameTreeNode* node) {
return EvalJs(node, "visualViewport.scale;").ExtractDouble();
}
private:
void RunCommandAndWaitForResponse(FrameTreeNode* node,
const std::string& command,
const std::string& response) {
ASSERT_EQ(response, EvalJs(node, command));
}
gfx::Rect GetRectFromString(const std::string& str) {
std::vector<std::string> tokens = base::SplitString(
str, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
EXPECT_EQ(4U, tokens.size());
double x = 0.0, y = 0.0, width = 0.0, height = 0.0;
EXPECT_TRUE(base::StringToDouble(tokens[0], &x));
EXPECT_TRUE(base::StringToDouble(tokens[1], &y));
EXPECT_TRUE(base::StringToDouble(tokens[2], &width));
EXPECT_TRUE(base::StringToDouble(tokens[3], &height));
return {static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height)};
}
};
IN_PROC_BROWSER_TEST_P(SitePerProcessProgrammaticScrollTest,
ScrolledOutOfView) {
GURL main_frame(
embedded_test_server()->GetURL("a.com", kIframeOutOfViewHTML));
GURL child_url_b(
embedded_test_server()->GetURL("b.com", kIframeOutOfViewHTML));
ASSERT_TRUE(NavigateToURL(shell(), main_frame));
FrameTreeNode* root = web_contents()->GetPrimaryFrameTree().root();
WaitForOnLoad(root);
EXPECT_TRUE(NavigateToURLFromRenderer(root->child_at(0), child_url_b));
WaitForOnLoad(root->child_at(0));
FrameTreeNode* nested_iframe_node = root->child_at(0);
RenderFrameProxyHost* proxy_to_parent =
nested_iframe_node->render_manager()->GetProxyToParent();
CrossProcessFrameConnector* connector =
proxy_to_parent->cross_process_frame_connector();
while (blink::mojom::FrameVisibility::kRenderedOutOfViewport !=
connector->visibility()) {
base::RunLoop run_loop;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
run_loop.Run();
}
}
IN_PROC_BROWSER_TEST_P(SitePerProcessProgrammaticScrollTest,
SmoothScrollInNestedSameProcessOOPIF) {
GURL main_frame(
embedded_test_server()->GetURL("a.com", kIframeOutOfViewHTML));
GURL child_url_b(
embedded_test_server()->GetURL("b.com", kIframeOutOfViewHTML));
GURL same_origin(
embedded_test_server()->GetURL("a.com", kIframeOutOfViewHTML));
ASSERT_TRUE(NavigateToURL(shell(), main_frame));
FrameTreeNode* root = web_contents()->GetPrimaryFrameTree().root();
WaitForOnLoad(root);
EXPECT_TRUE(NavigateToURLFromRenderer(root->child_at(0), child_url_b));
WaitForOnLoad(root->child_at(0));
auto* nested_ftn = root->child_at(0)->child_at(0);
EXPECT_TRUE(NavigateToURLFromRenderer(nested_ftn, same_origin));
WaitForOnLoad(nested_ftn);
ASSERT_TRUE(ExecJs(
nested_ftn,
"document.querySelector('iframe').scrollIntoView({behavior: 'smooth'})"));
WaitForElementVisible(root, kIframeSelector);
WaitForElementVisible(root->child_at(0), kIframeSelector);
WaitForElementVisible(nested_ftn, kIframeSelector);
}
class ScrollObserver : public RenderWidgetHost::InputEventObserver {
public:
ScrollObserver(double delta_x, double delta_y) { Reset(delta_x, delta_y); }
~ScrollObserver() override = default;
ScrollObserver(const ScrollObserver&) = delete;
ScrollObserver& operator=(const ScrollObserver&) = delete;
void OnInputEvent(const blink::WebInputEvent& event) override {
if (event.GetType() == blink::WebInputEvent::Type::kGestureScrollUpdate) {
blink::WebGestureEvent received_update =
*static_cast<const blink::WebGestureEvent*>(&event);
remaining_delta_x_ -= received_update.data.scroll_update.delta_x;
remaining_delta_y_ -= received_update.data.scroll_update.delta_y;
} else if (event.GetType() ==
blink::WebInputEvent::Type::kGestureScrollEnd) {
if (run_loop_->running())
run_loop_->Quit();
DCHECK_EQ(0, remaining_delta_x_);
DCHECK_EQ(0, remaining_delta_y_);
scroll_end_received_ = true;
}
}
void Wait() {
if (!scroll_end_received_)
run_loop_->Run();
}
void Reset(double delta_x, double delta_y) {
run_loop_ = std::make_unique<base::RunLoop>();
remaining_delta_x_ = delta_x;
remaining_delta_y_ = delta_y;
scroll_end_received_ = false;
}
private:
std::unique_ptr<base::RunLoop> run_loop_;
double remaining_delta_x_;
double remaining_delta_y_;
bool scroll_end_received_;
};
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest,
DISABLED_ScrollBubblingFromNestedOOPIFTest) {
ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
0);
GURL main_url(embedded_test_server()->GetURL(
"/frame_tree/page_with_positioned_nested_frames.html"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
RenderFrameSubmissionObserver frame_observer(shell()->web_contents());
FrameTreeNode* root = web_contents()->GetPrimaryFrameTree().root();
ASSERT_EQ(1U, root->child_count());
FrameTreeNode* parent_iframe_node = root->child_at(0);
GURL site_url(embedded_test_server()->GetURL(
"a.com", "/frame_tree/page_with_positioned_frame.html"));
EXPECT_EQ(site_url, parent_iframe_node->current_url());
FrameTreeNode* nested_iframe_node = parent_iframe_node->child_at(0);
GURL nested_site_url(
embedded_test_server()->GetURL("baz.com", "/title1.html"));
EXPECT_EQ(nested_site_url, nested_iframe_node->current_url());
RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
root->current_frame_host()->GetRenderWidgetHost()->GetView());
RenderWidgetHostViewBase* rwhv_nested =
static_cast<RenderWidgetHostViewBase*>(
nested_iframe_node->current_frame_host()
->GetRenderWidgetHost()
->GetView());
WaitForHitTestData(nested_iframe_node->current_frame_host());
InputEventAckWaiter ack_observer(
root->current_frame_host()->GetRenderWidgetHost(),
blink::WebInputEvent::Type::kGestureScrollBegin);
std::unique_ptr<ScrollObserver> scroll_observer;
scroll_observer = std::make_unique<ScrollObserver>(0, 15);
root->current_frame_host()->GetRenderWidgetHost()->AddInputEventObserver(
scroll_observer.get());
blink::WebMouseWheelEvent scroll_event(
blink::WebInputEvent::Type::kMouseWheel,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests());
gfx::Rect bounds = rwhv_nested->GetViewBounds();
float scale_factor =
frame_observer.LastRenderFrameMetadata().page_scale_factor;
scroll_event.SetPositionInWidget(
std::ceil((bounds.x() - root_view->GetViewBounds().x() + 10) *
scale_factor),
std::ceil((bounds.y() - root_view->GetViewBounds().y() + 10) *
scale_factor));
scroll_event.delta_units = ui::ScrollGranularity::kScrollByPrecisePixel;
scroll_event.delta_x = 0.0f;
scroll_event.delta_y = 5.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
rwhv_nested->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
ack_observer.Wait();
scroll_event.delta_y = 1.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseChanged;
for (int i = 0; i < 10; i++)
rwhv_nested->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
scroll_event.delta_y = 0.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
rwhv_nested->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
scroll_observer->Wait();
root->current_frame_host()->GetRenderWidgetHost()->RemoveInputEventObserver(
scroll_observer.get());
}
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest,
ScrollBubblingFromOOPIFWithBodyOverflowHidden) {
GURL url_domain_a(embedded_test_server()->GetURL(
"a.com", "/scrollable_page_with_iframe.html"));
EXPECT_TRUE(NavigateToURL(shell(), url_domain_a));
RenderFrameSubmissionObserver frame_observer(shell()->web_contents());
FrameTreeNode* root = web_contents()->GetPrimaryFrameTree().root();
FrameTreeNode* iframe_node = root->child_at(0);
GURL url_domain_b(
embedded_test_server()->GetURL("b.com", "/body_overflow_hidden.html"));
EXPECT_TRUE(NavigateToURLFromRenderer(iframe_node, url_domain_b));
WaitForHitTestData(iframe_node->current_frame_host());
RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
root->current_frame_host()->GetRenderWidgetHost()->GetView());
RenderWidgetHostViewBase* child_view = static_cast<RenderWidgetHostViewBase*>(
iframe_node->current_frame_host()->GetRenderWidgetHost()->GetView());
ScrollObserver scroll_observer(0, -5);
base::ScopedObservation<RenderWidgetHostImpl,
RenderWidgetHost::InputEventObserver>
scroll_observation_(&scroll_observer);
scroll_observation_.Observe(
root->current_frame_host()->GetRenderWidgetHost());
blink::WebMouseWheelEvent scroll_event(
blink::WebInputEvent::Type::kMouseWheel,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests());
gfx::Rect bounds = child_view->GetViewBounds();
float scale_factor =
frame_observer.LastRenderFrameMetadata().page_scale_factor;
scroll_event.SetPositionInWidget(
std::ceil((bounds.x() - root_view->GetViewBounds().x() + 10) *
scale_factor),
std::ceil((bounds.y() - root_view->GetViewBounds().y() + 10) *
scale_factor));
scroll_event.delta_units = ui::ScrollGranularity::kScrollByPrecisePixel;
scroll_event.delta_x = 0.0f;
scroll_event.delta_y = -5.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
child_view->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
scroll_event.delta_y = 0.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
child_view->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
scroll_observer.Wait();
}
class ScrollBubblingProxyObserver : RenderFrameProxyHost::TestObserver {
public:
ScrollBubblingProxyObserver() {
RenderFrameProxyHost::SetObserverForTesting(this);
}
~ScrollBubblingProxyObserver() override {
RenderFrameProxyHost::SetObserverForTesting(nullptr);
}
SynchronizeVisualPropertiesInterceptor* interceptor(
RenderFrameProxyHost* proxy) {
return interceptors_.find(proxy)->second.get();
}
private:
void OnCreated(RenderFrameProxyHost* proxy_host) override {
interceptors_.emplace(
proxy_host,
std::make_unique<SynchronizeVisualPropertiesInterceptor>(proxy_host));
}
void OnDeleted(RenderFrameProxyHost* proxy_host) override {
interceptors_.erase(proxy_host);
}
std::map<RenderFrameProxyHost*,
std::unique_ptr<SynchronizeVisualPropertiesInterceptor>>
interceptors_;
};
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest,
DISABLED_ScrollBubblingFromOOPIFTest) {
ScrollBubblingProxyObserver scroll_bubbling_proxy_observer;
ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
0);
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b)"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetPrimaryFrameTree()
.root();
ASSERT_EQ(1U, root->child_count());
FrameTreeNode* parent_iframe_node = root->child_at(0);
GURL site_url(embedded_test_server()->GetURL(
"b.com", "/frame_tree/page_with_positioned_frame.html"));
EXPECT_TRUE(NavigateToURLFromRenderer(parent_iframe_node, site_url));
InputEventAckWaiter ack_observer(
parent_iframe_node->current_frame_host()->GetRenderWidgetHost(),
blink::WebInputEvent::Type::kGestureScrollEnd);
FrameTreeNode* nested_iframe_node = parent_iframe_node->child_at(0);
GURL nested_site_url(
embedded_test_server()->GetURL("baz.com", "/tall_page.html"));
EXPECT_TRUE(NavigateToURLFromRenderer(nested_iframe_node, nested_site_url));
RenderFrameProxyHost* parent_iframe_proxy =
nested_iframe_node->render_manager()->GetProxyToParent();
NavigateFrameToURL(nested_iframe_node, nested_site_url);
EXPECT_EQ(
" Site A ------------ proxies for B C\n"
" +--Site B ------- proxies for A C\n"
" +--Site C -- proxies for A B\n"
"Where A = http://a.com/\n"
" B = http://b.com/\n"
" C = http://baz.com/",
DepictFrameTree(root));
RenderWidgetHostViewBase* rwhv_parent =
static_cast<RenderWidgetHostViewBase*>(
parent_iframe_node->current_frame_host()
->GetRenderWidgetHost()
->GetView());
RenderWidgetHostViewBase* rwhv_nested =
static_cast<RenderWidgetHostViewBase*>(
nested_iframe_node->current_frame_host()
->GetRenderWidgetHost()
->GetView());
WaitForHitTestData(parent_iframe_node->current_frame_host());
auto* interceptor =
scroll_bubbling_proxy_observer.interceptor(parent_iframe_proxy);
interceptor->WaitForRect();
gfx::Rect update_rect = interceptor->last_rect();
int initial_y = update_rect.y();
interceptor->ResetRectRunLoop();
blink::WebMouseWheelEvent scroll_event(
blink::WebInputEvent::Type::kMouseWheel,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests());
scroll_event.SetPositionInWidget(1, 1);
scroll_event.delta_units = ui::ScrollGranularity::kScrollByPrecisePixel;
scroll_event.delta_x = 0.0f;
scroll_event.delta_y = -5.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
rwhv_parent->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
scroll_event.delta_y = 0.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
scroll_event.dispatch_type =
blink::WebInputEvent::DispatchType::kEventNonBlocking;
rwhv_parent->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
interceptor->WaitForRect();
update_rect = interceptor->last_rect();
EXPECT_LT(update_rect.y(), initial_y);
interceptor->ResetRectRunLoop();
ack_observer.Reset();
scroll_event.delta_y = 6.0f;
scroll_event.dispatch_type = blink::WebInputEvent::DispatchType::kBlocking;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
rwhv_nested->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
interceptor->WaitForRect();
update_rect = interceptor->last_rect();
while (update_rect.y() > initial_y) {
base::RunLoop run_loop;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
run_loop.Run();
update_rect = interceptor->last_rect();
}
scroll_event.delta_y = 0.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
scroll_event.dispatch_type =
blink::WebInputEvent::DispatchType::kEventNonBlocking;
rwhv_nested->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
interceptor->ResetRectRunLoop();
ack_observer.Wait();
scroll_event.delta_y = -5.0f;
scroll_event.dispatch_type = blink::WebInputEvent::DispatchType::kBlocking;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
rwhv_parent->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
scroll_event.delta_y = 0.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
scroll_event.dispatch_type =
blink::WebInputEvent::DispatchType::kEventNonBlocking;
rwhv_parent->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
interceptor->WaitForRect();
interceptor->ResetRectRunLoop();
blink::WebGestureEvent gesture_event(
blink::WebGestureEvent::Type::kGestureScrollBegin,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests(),
blink::WebGestureDevice::kTouchpad);
gesture_event.SetPositionInWidget(gfx::PointF(1, 1));
gesture_event.data.scroll_begin.delta_x_hint = 0.0f;
gesture_event.data.scroll_begin.delta_y_hint = 6.0f;
rwhv_nested->GetRenderWidgetHost()->ForwardGestureEvent(gesture_event);
gesture_event =
blink::WebGestureEvent(blink::WebGestureEvent::Type::kGestureScrollUpdate,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests(),
blink::WebGestureDevice::kTouchpad);
gesture_event.SetPositionInWidget(gfx::PointF(1, 1));
gesture_event.data.scroll_update.delta_x = 0.0f;
gesture_event.data.scroll_update.delta_y = 6.0f;
gesture_event.data.scroll_update.velocity_x = 0;
gesture_event.data.scroll_update.velocity_y = 0;
rwhv_nested->GetRenderWidgetHost()->ForwardGestureEvent(gesture_event);
gesture_event =
blink::WebGestureEvent(blink::WebGestureEvent::Type::kGestureScrollEnd,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests(),
blink::WebGestureDevice::kTouchpad);
gesture_event.SetPositionInWidget(gfx::PointF(1, 1));
rwhv_nested->GetRenderWidgetHost()->ForwardGestureEvent(gesture_event);
interceptor->WaitForRect();
update_rect = interceptor->last_rect();
while (update_rect.y() > initial_y) {
base::RunLoop run_loop;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
run_loop.Run();
update_rect = interceptor->last_rect();
}
interceptor->ResetRectRunLoop();
scroll_event.delta_y = -5.0f;
scroll_event.dispatch_type = blink::WebInputEvent::DispatchType::kBlocking;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
rwhv_nested->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
{
base::RunLoop run_loop;
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, run_loop.QuitClosure(), TestTimeouts::action_timeout());
run_loop.Run();
}
DCHECK_EQ(interceptor->last_rect().x(), 0);
DCHECK_EQ(interceptor->last_rect().y(), 0);
}
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest,
KeyboardScrollBubblingFromOOPIF) {
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/frame_tree/page_with_iframe_in_scrollable_div.html"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetPrimaryFrameTree()
.root();
ASSERT_EQ(1U, root->child_count());
FrameTreeNode* iframe_node = root->child_at(0);
EXPECT_EQ(
" Site A ------------ proxies for B\n"
" +--Site B ------- proxies for A\n"
"Where A = http://a.com/\n"
" B = http://b.com/",
DepictFrameTree(root));
RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>(
iframe_node->current_frame_host()->GetRenderWidgetHost()->GetView());
WaitForHitTestData(iframe_node->current_frame_host());
EXPECT_DOUBLE_EQ(
0.0,
EvalJs(root,
"var wrapperDiv = document.getElementById('wrapper-div');"
"var initial_y = wrapperDiv.scrollTop;"
"var waitForScrollDownPromise = new Promise(function(resolve) {"
" wrapperDiv.addEventListener('scroll', () => {"
" if (wrapperDiv.scrollTop > initial_y)"
" resolve(wrapperDiv.scrollTop);"
" });"
"});"
"initial_y;")
.ExtractDouble());
NativeWebKeyboardEvent key_event(
blink::WebKeyboardEvent::Type::kRawKeyDown,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests());
key_event.windows_key_code = ui::VKEY_DOWN;
key_event.native_key_code =
ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::ARROW_DOWN);
key_event.dom_code = static_cast<int>(ui::DomCode::ARROW_DOWN);
key_event.dom_key = ui::DomKey::ARROW_DOWN;
rwhv_child->GetRenderWidgetHost()->ForwardKeyboardEvent(key_event);
key_event.SetType(blink::WebKeyboardEvent::Type::kKeyUp);
rwhv_child->GetRenderWidgetHost()->ForwardKeyboardEvent(key_event);
double scrolled_y = EvalJs(root, "waitForScrollDownPromise").ExtractDouble();
EXPECT_GT(scrolled_y, 0.0);
}
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest, ScrollLocalSubframeInOOPIF) {
ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
0);
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/frame_tree/page_with_tall_positioned_frame.html"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = web_contents()->GetPrimaryFrameTree().root();
ASSERT_EQ(1U, root->child_count());
FrameTreeNode* parent_iframe_node = root->child_at(0);
GURL outer_frame_url(embedded_test_server()->GetURL(
"baz.com", "/frame_tree/page_with_positioned_frame.html"));
EXPECT_TRUE(NavigateToURLFromRenderer(parent_iframe_node, outer_frame_url));
FrameTreeNode* nested_iframe_node = parent_iframe_node->child_at(0);
GURL inner_frame_url(
embedded_test_server()->GetURL("baz.com", "/tall_page.html"));
EXPECT_TRUE(NavigateToURLFromRenderer(nested_iframe_node, inner_frame_url));
ASSERT_EQ(
" Site A ------------ proxies for B\n"
" +--Site B ------- proxies for A\n"
" +--Site B -- proxies for A\n"
"Where A = http://a.com/\n"
" B = http://baz.com/",
DepictFrameTree(root));
RenderWidgetHostViewBase* rwhv_child = static_cast<RenderWidgetHostViewBase*>(
nested_iframe_node->current_frame_host()
->GetRenderWidgetHost()
->GetView());
WaitForHitTestData(parent_iframe_node->current_frame_host());
InputEventAckWaiter ack_observer(
parent_iframe_node->current_frame_host()->GetRenderWidgetHost(),
base::BindRepeating([](blink::mojom::InputEventResultSource,
blink::mojom::InputEventResultState state,
const blink::WebInputEvent& event) {
return event.GetType() ==
blink::WebGestureEvent::Type::kGestureScrollBegin &&
state == blink::mojom::InputEventResultState::kConsumed;
}));
MainThreadFrameObserver observer(rwhv_child->GetRenderWidgetHost());
observer.Wait();
blink::WebMouseWheelEvent scroll_event(
blink::WebInputEvent::Type::kMouseWheel,
blink::WebInputEvent::kNoModifiers,
blink::WebInputEvent::GetStaticTimeStampForTests());
scroll_event.SetPositionInWidget(90, 110);
scroll_event.delta_units = ui::ScrollGranularity::kScrollByPrecisePixel;
scroll_event.delta_x = 0.0f;
scroll_event.delta_y = -50.0f;
scroll_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
rwhv_child->ProcessMouseWheelEvent(scroll_event, ui::LatencyInfo());
ack_observer.Wait();
}
INSTANTIATE_TEST_SUITE_P(All,
ScrollingIntegrationTest,
testing::ValuesIn(RenderDocumentFeatureLevelValues()));
INSTANTIATE_TEST_SUITE_P(All,
SitePerProcessScrollAnchorTest,
testing::ValuesIn(RenderDocumentFeatureLevelValues()));
INSTANTIATE_TEST_SUITE_P(All,
SitePerProcessProgrammaticScrollTest,
testing::ValuesIn(RenderDocumentFeatureLevelValues()));
}