Commit ddfa8eb2 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: De-flake and re-enable FindInPageTest#testHideOnNewTab

The flake seems to occur when the touch is handled by selecting text on
the page, so switch to a page that doesn't have text in the way of the
touch.

This also puts a timeout on each CountDownLatch since an unbounded
await() leads to very unhelpful (i.e. non-existent) error output.

Bug: 1052802
Change-Id: I44393c4a821413e626eb3a5ef4c2e16609022040
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074812
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744793}
parent c30f409c
...@@ -8,24 +8,25 @@ import android.net.Uri; ...@@ -8,24 +8,25 @@ import android.net.Uri;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.FindInPageCallback; import org.chromium.weblayer.FindInPageCallback;
import org.chromium.weblayer.Tab; import org.chromium.weblayer.Tab;
import org.chromium.weblayer.shell.InstrumentationActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/** /**
* Tests the behavior of FindInPageController and FindInPageCallback. * Tests the behavior of FindInPageController and FindInPageCallback.
*/ */
@RunWith(WebLayerJUnit4ClassRunner.class) @RunWith(WebLayerJUnit4ClassRunner.class)
public class FindInPageTest { public class FindInPageTest {
private static final int COUNTDOWN_TIMEOUT_SECONDS = 6;
@Rule @Rule
public InstrumentationActivityTestRule mActivityTestRule = public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule(); new InstrumentationActivityTestRule();
...@@ -57,7 +58,7 @@ public class FindInPageTest { ...@@ -57,7 +58,7 @@ public class FindInPageTest {
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> { mActivity.getTab().getFindInPageController().find(text, forward); }); () -> { mActivity.getTab().getFindInPageController().find(text, forward); });
try { try {
mCallback.mResultCountDown.await(); mCallback.mResultCountDown.await(COUNTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
Assert.fail(e.toString()); Assert.fail(e.toString());
} }
...@@ -84,9 +85,8 @@ public class FindInPageTest { ...@@ -84,9 +85,8 @@ public class FindInPageTest {
})); }));
} }
@Before public void setUp(String testPage) {
public void setUp() { String url = mActivityTestRule.getTestDataURL(testPage);
String url = mActivityTestRule.getTestDataURL("shakespeare.html");
mActivity = mActivityTestRule.launchShellWithUrl(url); mActivity = mActivityTestRule.launchShellWithUrl(url);
Assert.assertNotNull(mActivity); Assert.assertNotNull(mActivity);
mCallback = new CallbackImpl(); mCallback = new CallbackImpl();
...@@ -98,6 +98,8 @@ public class FindInPageTest { ...@@ -98,6 +98,8 @@ public class FindInPageTest {
@Test @Test
@SmallTest @SmallTest
public void testBasic() { public void testBasic() {
setUp("shakespeare.html");
// Search. // Search.
searchFor("de"); searchFor("de");
Assert.assertEquals(mCallback.mNumberOfMatches, 5); Assert.assertEquals(mCallback.mNumberOfMatches, 5);
...@@ -135,20 +137,23 @@ public class FindInPageTest { ...@@ -135,20 +137,23 @@ public class FindInPageTest {
@Test @Test
@SmallTest @SmallTest
public void testHideOnNavigate() throws InterruptedException { public void testHideOnNavigate() throws InterruptedException {
setUp("shakespeare.html");
mCallback.mEndedCountDown = new CountDownLatch(1); mCallback.mEndedCountDown = new CountDownLatch(1);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
mActivity.getTab().getNavigationController().navigate(Uri.parse("simple_page.html")); mActivity.getTab().getNavigationController().navigate(Uri.parse("simple_page.html"));
}); });
mCallback.mEndedCountDown.await(); mCallback.mEndedCountDown.await(COUNTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
verifyFindSessionInactive(); verifyFindSessionInactive();
} }
@Test @Test
@SmallTest @SmallTest
@DisabledTest(message = "Timeout flaky crbug.com/1052802")
public void testHideOnNewTab() throws InterruptedException { public void testHideOnNewTab() throws InterruptedException {
setUp("new_tab.html");
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
mActivity.getBrowser().getActiveTab().setNewTabCallback(new NewTabCallbackImpl()); mActivity.getBrowser().getActiveTab().setNewTabCallback(new NewTabCallbackImpl());
}); });
...@@ -158,6 +163,6 @@ public class FindInPageTest { ...@@ -158,6 +163,6 @@ public class FindInPageTest {
// This touch creates a new tab. // This touch creates a new tab.
EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView()); EventUtils.simulateTouchCenterOfView(mActivity.getWindow().getDecorView());
mCallback.mEndedCountDown.await(); mCallback.mEndedCountDown.await(COUNTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} }
} }
...@@ -2,5 +2,9 @@ ...@@ -2,5 +2,9 @@
<body> <body>
<p id='x'>XXXX</p> <p id='x'>XXXX</p>
</body> </body>
<script src='new_browser_on_touch.js'></script> <script>
document.addEventListener('touchend', function(e) {
window.open('about:blank', '');
}, false);
</script>
</html> </html>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
document.addEventListener('touchend', function(e) {
window.open('about:blank', '');
}, false);
...@@ -17,5 +17,4 @@ ...@@ -17,5 +17,4 @@
I will be true, despite thy scythe and thee. I will be true, despite thy scythe and thee.
</p> </p>
</body> </body>
<script src='new_browser_on_touch.js'></script>
</html> </html>
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