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

Add test for onBeforeUnload with no history stack.

Bug: 1055540
Change-Id: I03621fa68a0606b210e31e0d45a8b0e78228c355
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134573Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756830}
parent c64eec2c
...@@ -27,10 +27,11 @@ import org.chromium.base.test.util.Feature; ...@@ -27,10 +27,11 @@ import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.components.javascript_dialogs.JavascriptAppModalDialog; import org.chromium.components.javascript_dialogs.JavascriptAppModalDialog;
import org.chromium.content_public.browser.GestureStateListener; import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
...@@ -52,8 +53,7 @@ import java.util.concurrent.TimeoutException; ...@@ -52,8 +53,7 @@ import java.util.concurrent.TimeoutException;
@Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class JavascriptAppModalDialogTest { public class JavascriptAppModalDialogTest {
@Rule @Rule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
new ChromeActivityTestRule<>(ChromeActivity.class);
private static final String TAG = "JSAppModalDialogTest"; private static final String TAG = "JSAppModalDialogTest";
private static final String EMPTY_PAGE = UrlUtils.encodeHtmlDataUri( private static final String EMPTY_PAGE = UrlUtils.encodeHtmlDataUri(
...@@ -103,6 +103,33 @@ public class JavascriptAppModalDialogTest { ...@@ -103,6 +103,33 @@ public class JavascriptAppModalDialogTest {
mActivityTestRule.getActivity().getCurrentWebContents().getLastCommittedUrl()); mActivityTestRule.getActivity().getCurrentWebContents().getLastCommittedUrl());
} }
/**
* Verifies behavior when the tab that has an onBeforeUnload handler has no history stack
* (pressing back should still show the dialog).
*
* Regression test for https://crbug.com/1055540
*/
@Test
@MediumTest
@Feature({"Browser", "Main"})
public void testBeforeUnloadDialogWithNoHistory() throws TimeoutException, ExecutionException {
ChromeTabbedActivity activity = mActivityTestRule.getActivity();
TabUiTestHelper.verifyTabModelTabCount(activity, 1, 0);
mActivityTestRule.loadUrlInNewTab(BEFORE_UNLOAD_URL);
TabUiTestHelper.verifyTabModelTabCount(activity, 2, 0);
// JavaScript onbeforeunload dialogs require a user gesture.
tapViewAndWait();
TestThreadUtils.runOnUiThreadBlocking(() -> { activity.onBackPressed(); });
CriteriaHelper.pollInstrumentationThread(new JavascriptAppModalDialogShownCriteria(
"Could not spawn or locate a modal dialog.", true));
// Click leave and verify that the tab is closed.
JavascriptAppModalDialog jsDialog = getCurrentDialog();
Assert.assertNotNull("No dialog showing.", jsDialog);
onView(withText(R.string.leave)).perform(click());
TabUiTestHelper.verifyTabModelTabCount(activity, 1, 0);
}
/** /**
* Verifies that when showing a beforeunload dialogs as a result of a page * Verifies that when showing a beforeunload dialogs as a result of a page
* reload, the correct UI strings are used. * reload, the correct UI strings are used.
...@@ -178,7 +205,7 @@ public class JavascriptAppModalDialogTest { ...@@ -178,7 +205,7 @@ public class JavascriptAppModalDialogTest {
executeJavaScriptAndWaitForDialog("history.back();"); executeJavaScriptAndWaitForDialog("history.back();");
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
ChromeActivity activity = mActivityTestRule.getActivity(); ChromeTabbedActivity activity = mActivityTestRule.getActivity();
activity.getCurrentTabModel().closeTab(activity.getActivityTab()); activity.getCurrentTabModel().closeTab(activity.getActivityTab());
}); });
......
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