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

WebLayer: Add test coverage for willAutomaticallyReloadAfterCrash

Bug: 1146058
Change-Id: I1a1edd86cc077816f233fc9a9abde2399800009f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526734
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826501}
parent 253ad44a
...@@ -12,12 +12,14 @@ import android.view.ViewGroup; ...@@ -12,12 +12,14 @@ import android.view.ViewGroup;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
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.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.Criteria;
import org.chromium.base.test.util.CriteriaHelper; import org.chromium.base.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.ActionModeCallback; import org.chromium.weblayer.ActionModeCallback;
...@@ -306,4 +308,52 @@ public class TabTest { ...@@ -306,4 +308,52 @@ public class TabTest {
// Smoke test. It's not possible to trigger an action mode click in a test. // Smoke test. It's not possible to trigger an action mode click in a test.
} }
@Test
@SmallTest
@MinWebLayerVersion(88) // New API added in 88.
public void testWillAutomaticallyReloadAfterCrash() throws Exception {
mActivity = mActivityTestRule.launchShellWithUrl("about:blank");
Browser browser2 = TestThreadUtils.runOnUiThreadBlocking(() -> {
Browser browser = mActivity.getBrowser();
// Initial tab is foreground, so it won't automatically reload.
Tab initialTab = browser.getActiveTab();
Assert.assertFalse(initialTab.willAutomaticallyReloadAfterCrash());
// New tab is background, so it will automatically reload.
Tab newTab = browser.createTab();
Assert.assertEquals(browser.getTabs().size(), 2);
Assert.assertNotEquals(newTab, mActivity.getTab());
Assert.assertNotEquals(newTab, browser.getActiveTab());
Assert.assertTrue(newTab.willAutomaticallyReloadAfterCrash());
// New tab is foreground after being made active.
browser.setActiveTab(newTab);
Assert.assertEquals(newTab, browser.getActiveTab());
Assert.assertFalse(newTab.willAutomaticallyReloadAfterCrash());
Assert.assertTrue(initialTab.willAutomaticallyReloadAfterCrash());
// Add a second browser; both browsers can have tabs that think they're foreground.
Browser newBrowser =
Browser.fromFragment(mActivity.createBrowserFragment(android.R.id.content));
Assert.assertTrue(initialTab.willAutomaticallyReloadAfterCrash());
Assert.assertFalse(newTab.willAutomaticallyReloadAfterCrash());
Assert.assertFalse(newBrowser.getActiveTab().willAutomaticallyReloadAfterCrash());
// Moving the activity to the background causes all tabs to be not foreground.
mActivity.moveTaskToBack(true);
return newBrowser;
});
CriteriaHelper.pollUiThread(
()
-> Criteria.checkThat(mActivity.getBrowser()
.getActiveTab()
.willAutomaticallyReloadAfterCrash(),
Matchers.is(true)));
TestThreadUtils.runOnUiThreadBlocking(
()
-> Assert.assertTrue(
browser2.getActiveTab().willAutomaticallyReloadAfterCrash()));
}
} }
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