Commit fe753fd9 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

Fix WebappNavigationTest flakiness

The flakiness is due to the timing-dependent value of
TabStateBrowserControlsVisibilityDelegate#calculateVisibilityConstraints()
the badly-named #mIsFullscreenWaitingForLoad in particular

This CL also switches to using static imports for org.junit.Assert

BUG=1108587

Change-Id: I6d87f7b2c0bd4e2402b49f43a2d9a96162f7c4da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314993
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarGlenn Hartmann <hartmanng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791357}
parent 8764d28d
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import static org.junit.Assert.assertEquals;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
...@@ -33,6 +35,7 @@ import org.chromium.chrome.test.util.ApplicationTestUtils; ...@@ -33,6 +35,7 @@ import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.webapps.WebApkIntentDataProviderBuilder; import org.chromium.chrome.test.util.browser.webapps.WebApkIntentDataProviderBuilder;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.BrowserControlsState;
import org.chromium.webapk.lib.common.WebApkConstants; import org.chromium.webapk.lib.common.WebApkConstants;
/** Tests for WebAPK {@link WebappActivity}. */ /** Tests for WebAPK {@link WebappActivity}. */
...@@ -70,7 +73,8 @@ public final class WebApkActivityTest { ...@@ -70,7 +73,8 @@ public final class WebApkActivityTest {
WebappActivity webApkActivity = WebappActivity webApkActivity =
mActivityTestRule.startWebApkActivity(createIntentDataProvider( mActivityTestRule.startWebApkActivity(createIntentDataProvider(
getTestServerUrl("scope_a/page_1.html"), getTestServerUrl("scope_a/"))); getTestServerUrl("scope_a/page_1.html"), getTestServerUrl("scope_a/")));
WebappActivityTestRule.assertToolbarShowState(webApkActivity, false); assertEquals(BrowserControlsState.HIDDEN,
WebappActivityTestRule.getToolbarShowState(webApkActivity));
// We navigate outside scope and expect CCT toolbar to show on top of WebAPK Activity. // We navigate outside scope and expect CCT toolbar to show on top of WebAPK Activity.
String outOfScopeUrl = getTestServerUrl("manifest_test_page.html"); String outOfScopeUrl = getTestServerUrl("manifest_test_page.html");
...@@ -78,7 +82,7 @@ public final class WebApkActivityTest { ...@@ -78,7 +82,7 @@ public final class WebApkActivityTest {
"window.top.location = '" + outOfScopeUrl + "'"); "window.top.location = '" + outOfScopeUrl + "'");
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), outOfScopeUrl); ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), outOfScopeUrl);
WebappActivityTestRule.assertToolbarShowState(webApkActivity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(webApkActivity);
} }
/** /**
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
...@@ -13,7 +16,6 @@ import android.view.ViewGroup; ...@@ -13,7 +16,6 @@ import android.view.ViewGroup;
import androidx.browser.customtabs.TrustedWebUtils; import androidx.browser.customtabs.TrustedWebUtils;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
...@@ -166,14 +168,17 @@ public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit ...@@ -166,14 +168,17 @@ public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit
waitUntilSplashscreenHides(); waitUntilSplashscreenHides();
} }
public static void assertToolbarShowState(ChromeActivity activity, boolean showState) { public static void assertToolbarShownMaybeHideable(ChromeActivity activity) {
@BrowserControlsState @BrowserControlsState
int expectedState = showState ? BrowserControlsState.SHOWN : BrowserControlsState.HIDDEN; int state = getToolbarShowState(activity);
Assert.assertEquals(expectedState, assertTrue(state == BrowserControlsState.SHOWN || state == BrowserControlsState.BOTH);
(int) TestThreadUtils.runOnUiThreadBlockingNoException( }
()
-> TabBrowserControlsConstraintsHelper.getConstraints( public static @BrowserControlsState int getToolbarShowState(ChromeActivity activity) {
activity.getActivityTab()))); return TestThreadUtils.runOnUiThreadBlockingNoException(
()
-> TabBrowserControlsConstraintsHelper.getConstraints(
activity.getActivityTab()));
} }
/** /**
...@@ -229,7 +234,7 @@ public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit ...@@ -229,7 +234,7 @@ public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit
InstrumentationRegistry.getInstrumentation().waitForIdleSync(); InstrumentationRegistry.getInstrumentation().waitForIdleSync();
View splashScreen = getSplashController(getActivity()).getSplashScreenForTests(); View splashScreen = getSplashController(getActivity()).getSplashScreenForTests();
Assert.assertNotNull("No splash screen available.", splashScreen); assertNotNull("No splash screen available.", splashScreen);
// TODO(pkotwicz): Change return type in order to accommodate new-style WebAPKs. // TODO(pkotwicz): Change return type in order to accommodate new-style WebAPKs.
// (crbug.com/958288) // (crbug.com/958288)
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.webapps; package org.chromium.chrome.browser.webapps;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.chromium.base.ApplicationState.HAS_DESTROYED_ACTIVITIES; import static org.chromium.base.ApplicationState.HAS_DESTROYED_ACTIVITIES;
import static org.chromium.base.ApplicationState.HAS_PAUSED_ACTIVITIES; import static org.chromium.base.ApplicationState.HAS_PAUSED_ACTIVITIES;
import static org.chromium.base.ApplicationState.HAS_STOPPED_ACTIVITIES; import static org.chromium.base.ApplicationState.HAS_STOPPED_ACTIVITIES;
...@@ -20,7 +23,6 @@ import androidx.test.filters.LargeTest; ...@@ -20,7 +23,6 @@ import androidx.test.filters.LargeTest;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -60,6 +62,7 @@ import org.chromium.content_public.browser.test.util.Criteria; ...@@ -60,6 +62,7 @@ import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.DOMUtils; import org.chromium.content_public.browser.test.util.DOMUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.BrowserControlsState;
import org.chromium.content_public.common.ContentSwitches; import org.chromium.content_public.common.ContentSwitches;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
...@@ -77,9 +80,8 @@ public class WebappNavigationTest { ...@@ -77,9 +80,8 @@ public class WebappNavigationTest {
new MockCertVerifierRuleAndroid(0 /* net::OK */); new MockCertVerifierRuleAndroid(0 /* net::OK */);
@Rule @Rule
public RuleChain mRuleChain = RuleChain.emptyRuleChain() public RuleChain mRuleChain =
.around(mActivityTestRule) RuleChain.emptyRuleChain().around(mActivityTestRule).around(mCertVerifierRule);
.around(mCertVerifierRule);
@Before @Before
public void setUp() { public void setUp() {
...@@ -104,14 +106,14 @@ public class WebappNavigationTest { ...@@ -104,14 +106,14 @@ public class WebappNavigationTest {
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) @Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testRegularLinkOffOriginNoWebappThemeColor() throws Exception { public void testRegularLinkOffOriginNoWebappThemeColor() throws Exception {
WebappActivity activity = runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent()); WebappActivity activity = runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
WebappActivityTestRule.assertToolbarShowState(activity, false); assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
addAnchorAndClick(offOriginUrl(), "_self"); addAnchorAndClick(offOriginUrl(), "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl()); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
Assert.assertEquals( assertEquals(getDefaultPrimaryColor(), activity.getToolbarManager().getPrimaryColor());
getDefaultPrimaryColor(), activity.getToolbarManager().getPrimaryColor());
} }
/** /**
...@@ -128,13 +130,14 @@ public class WebappNavigationTest { ...@@ -128,13 +130,14 @@ public class WebappNavigationTest {
WebappActivity activity = WebappActivity activity =
runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent().putExtra( runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent().putExtra(
ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN)); ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN));
WebappActivityTestRule.assertToolbarShowState(activity, false); assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
addAnchorAndClick(offOriginUrl(), "_self"); addAnchorAndClick(offOriginUrl(), "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl()); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
Assert.assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor()); assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
} }
/** /**
...@@ -155,11 +158,12 @@ public class WebappNavigationTest { ...@@ -155,11 +158,12 @@ public class WebappNavigationTest {
ChromeSwitches.DISABLE_DIGITAL_ASSET_LINK_VERIFICATION, url); ChromeSwitches.DISABLE_DIGITAL_ASSET_LINK_VERIFICATION, url);
mActivityTestRule.startWebappActivity(launchIntent.putExtra(ShortcutHelper.EXTRA_URL, url)); mActivityTestRule.startWebappActivity(launchIntent.putExtra(ShortcutHelper.EXTRA_URL, url));
WebappActivity activity = mActivityTestRule.getActivity(); WebappActivity activity = mActivityTestRule.getActivity();
WebappActivityTestRule.assertToolbarShowState(activity, false); assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
addAnchorAndClick(offOriginUrl(), "_self"); addAnchorAndClick(offOriginUrl(), "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl()); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
Assert.assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor()); assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
} }
/** /**
...@@ -184,7 +188,7 @@ public class WebappNavigationTest { ...@@ -184,7 +188,7 @@ public class WebappNavigationTest {
clickNodeWithId("post_button"); clickNodeWithId("post_button");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl()); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
Assert.assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor()); assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
} }
/** /**
...@@ -205,7 +209,7 @@ public class WebappNavigationTest { ...@@ -205,7 +209,7 @@ public class WebappNavigationTest {
}); });
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl()); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
} }
/** /**
...@@ -228,7 +232,7 @@ public class WebappNavigationTest { ...@@ -228,7 +232,7 @@ public class WebappNavigationTest {
}); });
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), inScopeUrl); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), inScopeUrl);
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
} }
/** /**
...@@ -246,7 +250,8 @@ public class WebappNavigationTest { ...@@ -246,7 +250,8 @@ public class WebappNavigationTest {
addAnchorAndClick(otherPageUrl, "_self"); addAnchorAndClick(otherPageUrl, "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), otherPageUrl); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), otherPageUrl);
WebappActivityTestRule.assertToolbarShowState(activity, false); assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
} }
@Test @Test
...@@ -306,7 +311,7 @@ public class WebappNavigationTest { ...@@ -306,7 +311,7 @@ public class WebappNavigationTest {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
activity.getComponent().resolveNavigationController().openCurrentUrlInBrowser(true); activity.getComponent().resolveNavigationController().openCurrentUrlInBrowser(true);
Assert.assertNull(activity.getActivityTab()); assertNull(activity.getActivityTab());
}); });
ChromeTabbedActivity tabbedChrome = ChromeTabbedActivity tabbedChrome =
...@@ -331,7 +336,7 @@ public class WebappNavigationTest { ...@@ -331,7 +336,7 @@ public class WebappNavigationTest {
.getComponent() .getComponent()
.resolveNavigationController() .resolveNavigationController()
.openCurrentUrlInBrowser(true); .openCurrentUrlInBrowser(true);
Assert.assertNull(mActivityTestRule.getActivity().getActivityTab()); assertNull(mActivityTestRule.getActivity().getActivityTab());
}); });
ChromeTabbedActivity tabbedChrome = ChromeTabbedActivity tabbedChrome =
...@@ -351,7 +356,7 @@ public class WebappNavigationTest { ...@@ -351,7 +356,7 @@ public class WebappNavigationTest {
String otherInScopeUrl = String otherInScopeUrl =
WebappTestPage.getNonServiceWorkerUrl(mActivityTestRule.getTestServer()); WebappTestPage.getNonServiceWorkerUrl(mActivityTestRule.getTestServer());
mActivityTestRule.loadUrlInTab(otherInScopeUrl, PageTransition.LINK, tab); mActivityTestRule.loadUrlInTab(otherInScopeUrl, PageTransition.LINK, tab);
Assert.assertEquals(otherInScopeUrl, tab.getUrlString()); assertEquals(otherInScopeUrl, tab.getUrlString());
mActivityTestRule.loadUrlInTab( mActivityTestRule.loadUrlInTab(
offOriginUrl(), PageTransition.LINK, tab, 10 /* secondsToWait */); offOriginUrl(), PageTransition.LINK, tab, 10 /* secondsToWait */);
...@@ -361,7 +366,7 @@ public class WebappNavigationTest { ...@@ -361,7 +366,7 @@ public class WebappNavigationTest {
mozillaUrl, PageTransition.LINK, tab, 10 /* secondsToWait */); mozillaUrl, PageTransition.LINK, tab, 10 /* secondsToWait */);
// Toolbar with the close button should be visible. // Toolbar with the close button should be visible.
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
// Navigate back to in-scope through a close button. // Navigate back to in-scope through a close button.
TestThreadUtils.runOnUiThreadBlocking(() TestThreadUtils.runOnUiThreadBlocking(()
...@@ -394,16 +399,16 @@ public class WebappNavigationTest { ...@@ -394,16 +399,16 @@ public class WebappNavigationTest {
testServer.getURL("/chrome/test/data/android/redirect/js_redirect.html" testServer.getURL("/chrome/test/data/android/redirect/js_redirect.html"
+ "?replace_text=" + "?replace_text="
+ Base64.encodeToString( + Base64.encodeToString(
ApiCompatibilityUtils.getBytesUtf8("PARAM_URL"), Base64.URL_SAFE) ApiCompatibilityUtils.getBytesUtf8("PARAM_URL"), Base64.URL_SAFE)
+ ":" + ":"
+ Base64.encodeToString(ApiCompatibilityUtils.getBytesUtf8(offOriginUrl()), + Base64.encodeToString(ApiCompatibilityUtils.getBytesUtf8(offOriginUrl()),
Base64.URL_SAFE)); Base64.URL_SAFE));
addAnchorAndClick(redirectingUrl, "_self"); addAnchorAndClick(redirectingUrl, "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl()); ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
// Close the Minimal UI. // Close the Minimal UI.
WebappActivityTestRule.assertToolbarShowState(activity, true); WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
TestThreadUtils.runOnUiThreadBlocking(() TestThreadUtils.runOnUiThreadBlocking(()
-> activity.getToolbarManager() -> activity.getToolbarManager()
.getToolbarLayoutForTesting() .getToolbarLayoutForTesting()
......
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