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 @@
package org.chromium.chrome.browser.webapps;
import static org.junit.Assert.assertEquals;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -33,6 +35,7 @@ import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.browser.webapps.WebApkIntentDataProviderBuilder;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.BrowserControlsState;
import org.chromium.webapk.lib.common.WebApkConstants;
/** Tests for WebAPK {@link WebappActivity}. */
......@@ -70,7 +73,8 @@ public final class WebApkActivityTest {
WebappActivity webApkActivity =
mActivityTestRule.startWebApkActivity(createIntentDataProvider(
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.
String outOfScopeUrl = getTestServerUrl("manifest_test_page.html");
......@@ -78,7 +82,7 @@ public final class WebApkActivityTest {
"window.top.location = '" + outOfScopeUrl + "'");
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), outOfScopeUrl);
WebappActivityTestRule.assertToolbarShowState(webApkActivity, true);
WebappActivityTestRule.assertToolbarShownMaybeHideable(webApkActivity);
}
/**
......
......@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.webapps;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.content.Intent;
import android.net.Uri;
import android.support.test.InstrumentationRegistry;
......@@ -13,7 +16,6 @@ import android.view.ViewGroup;
import androidx.browser.customtabs.TrustedWebUtils;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
......@@ -166,14 +168,17 @@ public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit
waitUntilSplashscreenHides();
}
public static void assertToolbarShowState(ChromeActivity activity, boolean showState) {
public static void assertToolbarShownMaybeHideable(ChromeActivity activity) {
@BrowserControlsState
int expectedState = showState ? BrowserControlsState.SHOWN : BrowserControlsState.HIDDEN;
Assert.assertEquals(expectedState,
(int) TestThreadUtils.runOnUiThreadBlockingNoException(
()
-> TabBrowserControlsConstraintsHelper.getConstraints(
activity.getActivityTab())));
int state = getToolbarShowState(activity);
assertTrue(state == BrowserControlsState.SHOWN || state == BrowserControlsState.BOTH);
}
public static @BrowserControlsState int getToolbarShowState(ChromeActivity activity) {
return TestThreadUtils.runOnUiThreadBlockingNoException(
()
-> TabBrowserControlsConstraintsHelper.getConstraints(
activity.getActivityTab()));
}
/**
......@@ -229,7 +234,7 @@ public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
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.
// (crbug.com/958288)
......
......@@ -4,6 +4,9 @@
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_PAUSED_ACTIVITIES;
import static org.chromium.base.ApplicationState.HAS_STOPPED_ACTIVITIES;
......@@ -20,7 +23,6 @@ import androidx.test.filters.LargeTest;
import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
......@@ -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.DOMUtils;
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.net.test.EmbeddedTestServer;
import org.chromium.ui.base.PageTransition;
......@@ -77,9 +80,8 @@ public class WebappNavigationTest {
new MockCertVerifierRuleAndroid(0 /* net::OK */);
@Rule
public RuleChain mRuleChain = RuleChain.emptyRuleChain()
.around(mActivityTestRule)
.around(mCertVerifierRule);
public RuleChain mRuleChain =
RuleChain.emptyRuleChain().around(mActivityTestRule).around(mCertVerifierRule);
@Before
public void setUp() {
......@@ -104,14 +106,14 @@ public class WebappNavigationTest {
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testRegularLinkOffOriginNoWebappThemeColor() throws Exception {
WebappActivity activity = runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent());
WebappActivityTestRule.assertToolbarShowState(activity, false);
assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
addAnchorAndClick(offOriginUrl(), "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true);
Assert.assertEquals(
getDefaultPrimaryColor(), activity.getToolbarManager().getPrimaryColor());
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
assertEquals(getDefaultPrimaryColor(), activity.getToolbarManager().getPrimaryColor());
}
/**
......@@ -128,13 +130,14 @@ public class WebappNavigationTest {
WebappActivity activity =
runWebappActivityAndWaitForIdle(mActivityTestRule.createIntent().putExtra(
ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN));
WebappActivityTestRule.assertToolbarShowState(activity, false);
assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
addAnchorAndClick(offOriginUrl(), "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true);
Assert.assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
}
/**
......@@ -155,11 +158,12 @@ public class WebappNavigationTest {
ChromeSwitches.DISABLE_DIGITAL_ASSET_LINK_VERIFICATION, url);
mActivityTestRule.startWebappActivity(launchIntent.putExtra(ShortcutHelper.EXTRA_URL, url));
WebappActivity activity = mActivityTestRule.getActivity();
WebappActivityTestRule.assertToolbarShowState(activity, false);
assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
addAnchorAndClick(offOriginUrl(), "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true);
Assert.assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
}
/**
......@@ -184,7 +188,7 @@ public class WebappNavigationTest {
clickNodeWithId("post_button");
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 {
});
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
WebappActivityTestRule.assertToolbarShowState(activity, true);
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
}
/**
......@@ -228,7 +232,7 @@ public class WebappNavigationTest {
});
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), inScopeUrl);
WebappActivityTestRule.assertToolbarShowState(activity, true);
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
}
/**
......@@ -246,7 +250,8 @@ public class WebappNavigationTest {
addAnchorAndClick(otherPageUrl, "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), otherPageUrl);
WebappActivityTestRule.assertToolbarShowState(activity, false);
assertEquals(
BrowserControlsState.HIDDEN, WebappActivityTestRule.getToolbarShowState(activity));
}
@Test
......@@ -306,7 +311,7 @@ public class WebappNavigationTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
activity.getComponent().resolveNavigationController().openCurrentUrlInBrowser(true);
Assert.assertNull(activity.getActivityTab());
assertNull(activity.getActivityTab());
});
ChromeTabbedActivity tabbedChrome =
......@@ -331,7 +336,7 @@ public class WebappNavigationTest {
.getComponent()
.resolveNavigationController()
.openCurrentUrlInBrowser(true);
Assert.assertNull(mActivityTestRule.getActivity().getActivityTab());
assertNull(mActivityTestRule.getActivity().getActivityTab());
});
ChromeTabbedActivity tabbedChrome =
......@@ -351,7 +356,7 @@ public class WebappNavigationTest {
String otherInScopeUrl =
WebappTestPage.getNonServiceWorkerUrl(mActivityTestRule.getTestServer());
mActivityTestRule.loadUrlInTab(otherInScopeUrl, PageTransition.LINK, tab);
Assert.assertEquals(otherInScopeUrl, tab.getUrlString());
assertEquals(otherInScopeUrl, tab.getUrlString());
mActivityTestRule.loadUrlInTab(
offOriginUrl(), PageTransition.LINK, tab, 10 /* secondsToWait */);
......@@ -361,7 +366,7 @@ public class WebappNavigationTest {
mozillaUrl, PageTransition.LINK, tab, 10 /* secondsToWait */);
// Toolbar with the close button should be visible.
WebappActivityTestRule.assertToolbarShowState(activity, true);
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
// Navigate back to in-scope through a close button.
TestThreadUtils.runOnUiThreadBlocking(()
......@@ -394,16 +399,16 @@ public class WebappNavigationTest {
testServer.getURL("/chrome/test/data/android/redirect/js_redirect.html"
+ "?replace_text="
+ Base64.encodeToString(
ApiCompatibilityUtils.getBytesUtf8("PARAM_URL"), Base64.URL_SAFE)
ApiCompatibilityUtils.getBytesUtf8("PARAM_URL"), Base64.URL_SAFE)
+ ":"
+ Base64.encodeToString(ApiCompatibilityUtils.getBytesUtf8(offOriginUrl()),
Base64.URL_SAFE));
Base64.URL_SAFE));
addAnchorAndClick(redirectingUrl, "_self");
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), offOriginUrl());
// Close the Minimal UI.
WebappActivityTestRule.assertToolbarShowState(activity, true);
WebappActivityTestRule.assertToolbarShownMaybeHideable(activity);
TestThreadUtils.runOnUiThreadBlocking(()
-> activity.getToolbarManager()
.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