Commit b3f673c7 authored by Mario Bianucci's avatar Mario Bianucci Committed by Commit Bot

Enable PrecisionTouchpadBrowserTest.* browser tests

These tests started being flaky as soon as they were initially landed.
It seems to be a timing issue, so I added in two pieces to ensure
timing is correct:

1. MainThreadFrameObserver - I was seeing that occasionally, the frame
  wouldn't have been produced by the time the test was sending the first
  scroll or zoom, resulting in the scroll or zoom bailing early and not
  happening. The MainThreadFrameObserver will make sure that execution
  waits until a frame is produced and everything is in sync before
  continuing.

2. InputMsgWatcher - This ensures that the test receives an ACK back from
  the expected event type each time a scroll or zoom is performed. The
  ACK can technically be a few different things based on different
  conditions but it doesn't really matter what it is, just that an ACK
  is received. This allows us to be certain that we are waiting long
  enough before checking the zoom or scroll amounts.

Bug: 1010911
Change-Id: Ieb1c3993cdc17afacd8aecb5e823881c539a1e12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837892Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Commit-Queue: Ken Buchanan <kenrb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707141}
parent cff91b98
......@@ -350,8 +350,7 @@ class PrecisionTouchpadBrowserTest : public DirectManipulationBrowserTestBase {
// Confirm that preventDefault correctly prevents pinch zoom on precision
// touchpad.
IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
DISABLED_PreventDefaultPinchZoom) {
IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest, PreventDefaultPinchZoom) {
if (base::win::GetVersion() < base::win::Version::WIN10)
return;
......@@ -364,6 +363,12 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderWidgetHostImpl* rwhi = web_contents->GetRenderWidgetHostWithPageFocus();
// Wait for a frame to be produced or else the test will sometimes try to
// zoom too early and be unable to, causing flakiness.
MainThreadFrameObserver observer(
web_contents->GetRenderViewHost()->GetWidget());
observer.Wait();
UseCenterPointAsMockCursorPosition(web_contents);
EXPECT_EQ(1, EvalJs(web_contents, "window.visualViewport.scale"));
......@@ -371,8 +376,15 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
// Initial amount to try zooming by.
const int kInitialZoom = 2;
// Used to confirm the gesture is ACK'd before checking the zoom state. The
// ACK result itself isn't relevant in this test.
auto input_msg_watcher = std::make_unique<InputMsgWatcher>(
web_contents->GetRenderViewHost()->GetWidget(),
blink::WebInputEvent::kGesturePinchUpdate);
// First, test a standard zoom.
UpdateContents(kInitialZoom, 0, 0);
EXPECT_TRUE(input_msg_watcher->WaitForAck());
RunUntilInputProcessed(rwhi);
EXPECT_EQ(kInitialZoom, EvalJs(web_contents, "window.visualViewport.scale"));
......@@ -389,6 +401,7 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
// Arbitrary zoom amount chosen here to make the test fail if it does zoom.
UpdateContents(3.5, 0, 0);
EXPECT_TRUE(input_msg_watcher->WaitForAck());
RunUntilInputProcessed(rwhi);
EXPECT_EQ(kInitialZoom, EvalJs(web_contents, "window.visualViewport.scale"));
......@@ -404,6 +417,7 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
const float kEndZoom = 0.5;
UpdateContents(kEndZoom, 0, 0);
EXPECT_TRUE(input_msg_watcher->WaitForAck());
RunUntilInputProcessed(rwhi);
EXPECT_EQ(static_cast<int>(kInitialZoom * kEndZoom),
......@@ -412,8 +426,7 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
// Confirm that preventDefault correctly prevents scrolling on precision
// touchpad.
IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
DISABLED_PreventDefaultScroll) {
IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest, PreventDefaultScroll) {
if (base::win::GetVersion() < base::win::Version::WIN10)
return;
......@@ -428,6 +441,12 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
static_cast<WebContentsImpl*>(shell()->web_contents());
RenderWidgetHostImpl* rwhi = web_contents->GetRenderWidgetHostWithPageFocus();
// Wait for a frame to be produced or else the test will sometimes try to
// scroll too early and be unable to, causing flakiness.
MainThreadFrameObserver observer(
web_contents->GetRenderViewHost()->GetWidget());
observer.Wait();
UseCenterPointAsMockCursorPosition(web_contents);
EXPECT_EQ(0, EvalJs(web_contents, "document.documentElement.scrollLeft"));
......@@ -438,8 +457,15 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
// passed to UpdateContents.
const int kInitialScrollDistance = 200;
// Used to confirm the gesture is ACK'd before checking the scroll state. The
// ACK result itself isn't relevant in this test.
auto input_msg_watcher = std::make_unique<InputMsgWatcher>(
web_contents->GetRenderViewHost()->GetWidget(),
blink::WebInputEvent::kMouseWheel);
// First, test scrolling vertically
UpdateContents(1, 0, -kInitialScrollDistance);
EXPECT_TRUE(input_msg_watcher->WaitForAck());
RunUntilInputProcessed(rwhi);
EXPECT_EQ(0, EvalJs(web_contents, "document.documentElement.scrollLeft"));
......@@ -469,6 +495,7 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
// Updating with arbitrarily chosen numbers that should make it obvious where
// values are coming from when this test fails.
UpdateContents(1, 354, 291);
EXPECT_TRUE(input_msg_watcher->WaitForAck());
RunUntilInputProcessed(rwhi);
EXPECT_EQ(kInitialScrollDistance,
......@@ -489,6 +516,7 @@ IN_PROC_BROWSER_TEST_F(PrecisionTouchpadBrowserTest,
const int kScrollXDistance = 120;
const int kScrollYDistance = 150;
UpdateContents(1, kScrollXDistance, kScrollYDistance);
EXPECT_TRUE(input_msg_watcher->WaitForAck());
RunUntilInputProcessed(rwhi);
EXPECT_EQ(kInitialScrollDistance - kScrollXDistance,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment