| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ModalDialogTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ModalDialogTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ModalDialogTest.java
|
| index b2272818d283707b068fc127f57e2bb20b449991..db3903be6b3dfa20e7a2718c9f715bd33998cc00 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ModalDialogTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ModalDialogTest.java
|
| @@ -13,17 +13,26 @@ import android.widget.Button;
|
| import android.widget.CheckBox;
|
| import android.widget.EditText;
|
|
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.CallbackHelper;
|
| +import org.chromium.base.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.chrome.R;
|
| -import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
|
| +import org.chromium.content.browser.test.util.TouchCommon;
|
| import org.chromium.content_public.browser.GestureStateListener;
|
|
|
| import java.util.concurrent.Callable;
|
| @@ -33,8 +42,15 @@ import java.util.concurrent.TimeoutException;
|
| /**
|
| * Test suite for displaying and functioning of modal dialogs.
|
| */
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| @RetryOnFailure
|
| -public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class ModalDialogTest {
|
| + @Rule
|
| + public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| + new ChromeActivityTestRule<>(ChromeActivity.class);
|
| +
|
| private static final String TAG = "ModalDialogTest";
|
| private static final String EMPTY_PAGE = UrlUtils.encodeHtmlDataUri(
|
| "<html><title>Modal Dialog Test</title><p>Testcase.</p></title></html>");
|
| @@ -43,19 +59,16 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| + "return 'Are you sure?';"
|
| + "};</script></head></html>");
|
|
|
| - public ModalDialogTest() {
|
| - super(ChromeActivity.class);
|
| - }
|
| -
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityWithURL(EMPTY_PAGE);
|
| + @Before
|
| + public void setUp() throws InterruptedException {
|
| + mActivityTestRule.startMainActivityWithURL(EMPTY_PAGE);
|
| }
|
|
|
| /**
|
| * Verifies modal alert-dialog appearance and that JavaScript execution is
|
| * able to continue after dismissal.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testAlertModalDialog()
|
| @@ -64,16 +77,17 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| executeJavaScriptAndWaitForDialog("alert('Hello Android!');");
|
|
|
| JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| clickOk(jsDialog);
|
| - assertTrue("JavaScript execution should continue after closing prompt.",
|
| + Assert.assertTrue("JavaScript execution should continue after closing prompt.",
|
| scriptEvent.waitUntilHasValue());
|
| }
|
|
|
| /**
|
| * Verifies that clicking on a button twice doesn't crash.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testAlertModalDialogWithTwoClicks()
|
| @@ -81,12 +95,12 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| OnEvaluateJavaScriptResultHelper scriptEvent =
|
| executeJavaScriptAndWaitForDialog("alert('Hello Android');");
|
| JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| clickOk(jsDialog);
|
| clickOk(jsDialog);
|
|
|
| - assertTrue("JavaScript execution should continue after closing prompt.",
|
| + Assert.assertTrue("JavaScript execution should continue after closing prompt.",
|
| scriptEvent.waitUntilHasValue());
|
| }
|
|
|
| @@ -94,6 +108,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| * Verifies that modal confirm-dialogs display, two buttons are visible and
|
| * the return value of [Ok] equals true, [Cancel] equals false.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testConfirmModalDialog()
|
| @@ -102,41 +117,43 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| executeJavaScriptAndWaitForDialog("confirm('Android');");
|
|
|
| JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| Button[] buttons = getAlertDialogButtons(jsDialog.getDialogForTest());
|
| - assertNotNull("No cancel button in confirm dialog.", buttons[0]);
|
| - assertEquals("Cancel button is not visible.", View.VISIBLE, buttons[0].getVisibility());
|
| + Assert.assertNotNull("No cancel button in confirm dialog.", buttons[0]);
|
| + Assert.assertEquals(
|
| + "Cancel button is not visible.", View.VISIBLE, buttons[0].getVisibility());
|
| if (buttons[1] != null) {
|
| - assertNotSame("Neutral button visible when it should not.",
|
| - View.VISIBLE, buttons[1].getVisibility());
|
| + Assert.assertNotSame("Neutral button visible when it should not.", View.VISIBLE,
|
| + buttons[1].getVisibility());
|
| }
|
| - assertNotNull("No OK button in confirm dialog.", buttons[2]);
|
| - assertEquals("OK button is not visible.", View.VISIBLE, buttons[2].getVisibility());
|
| + Assert.assertNotNull("No OK button in confirm dialog.", buttons[2]);
|
| + Assert.assertEquals("OK button is not visible.", View.VISIBLE, buttons[2].getVisibility());
|
|
|
| clickOk(jsDialog);
|
| - assertTrue("JavaScript execution should continue after closing dialog.",
|
| + Assert.assertTrue("JavaScript execution should continue after closing dialog.",
|
| scriptEvent.waitUntilHasValue());
|
|
|
| String resultString = scriptEvent.getJsonResultAndClear();
|
| - assertEquals("Invalid return value.", "true", resultString);
|
| + Assert.assertEquals("Invalid return value.", "true", resultString);
|
|
|
| // Try again, pressing cancel this time.
|
| scriptEvent = executeJavaScriptAndWaitForDialog("confirm('Android');");
|
| jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| clickCancel(jsDialog);
|
| - assertTrue("JavaScript execution should continue after closing dialog.",
|
| + Assert.assertTrue("JavaScript execution should continue after closing dialog.",
|
| scriptEvent.waitUntilHasValue());
|
|
|
| resultString = scriptEvent.getJsonResultAndClear();
|
| - assertEquals("Invalid return value.", "false", resultString);
|
| + Assert.assertEquals("Invalid return value.", "false", resultString);
|
| }
|
|
|
| /**
|
| * Verifies that modal prompt-dialogs display and the result is returned.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testPromptModalDialog()
|
| @@ -146,7 +163,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| executeJavaScriptAndWaitForDialog("prompt('Android', 'default');");
|
|
|
| final JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| // Set the text in the prompt field of the dialog.
|
| boolean result = ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
|
| @@ -159,14 +176,14 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| return true;
|
| }
|
| });
|
| - assertTrue("Failed to find prompt view in prompt dialog.", result);
|
| + Assert.assertTrue("Failed to find prompt view in prompt dialog.", result);
|
|
|
| clickOk(jsDialog);
|
| - assertTrue("JavaScript execution should continue after closing prompt.",
|
| + Assert.assertTrue("JavaScript execution should continue after closing prompt.",
|
| scriptEvent.waitUntilHasValue());
|
|
|
| String resultString = scriptEvent.getJsonResultAndClear();
|
| - assertEquals("Invalid return value.", '"' + promptText + '"', resultString);
|
| + Assert.assertEquals("Invalid return value.", '"' + promptText + '"', resultString);
|
| }
|
|
|
| private static class TapGestureStateListener extends GestureStateListener {
|
| @@ -192,9 +209,10 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| private void tapViewAndWait() throws InterruptedException, TimeoutException {
|
| final TapGestureStateListener tapGestureStateListener = new TapGestureStateListener();
|
| int callCount = tapGestureStateListener.getCallCount();
|
| - getActivity().getCurrentContentViewCore().addGestureStateListener(tapGestureStateListener);
|
| + mActivityTestRule.getActivity().getCurrentContentViewCore().addGestureStateListener(
|
| + tapGestureStateListener);
|
|
|
| - singleClickView(getActivity().getActivityTab().getView());
|
| + TouchCommon.singleClickView(mActivityTestRule.getActivity().getActivityTab().getView());
|
| tapGestureStateListener.waitForTap(callCount);
|
| }
|
|
|
| @@ -202,26 +220,30 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| * Verifies beforeunload dialogs are shown and they block/allow navigation
|
| * as appropriate.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testBeforeUnloadDialog()
|
| throws InterruptedException, TimeoutException, ExecutionException {
|
| - loadUrl(BEFORE_UNLOAD_URL);
|
| + mActivityTestRule.loadUrl(BEFORE_UNLOAD_URL);
|
| // JavaScript onbeforeunload dialogs require a user gesture.
|
| tapViewAndWait();
|
| executeJavaScriptAndWaitForDialog("history.back();");
|
|
|
| JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
| checkButtonPresenceVisibilityText(jsDialog, 0, R.string.cancel, "Cancel");
|
| clickCancel(jsDialog);
|
|
|
| - assertEquals(BEFORE_UNLOAD_URL, getActivity().getCurrentContentViewCore()
|
| - .getWebContents().getUrl());
|
| + Assert.assertEquals(BEFORE_UNLOAD_URL,
|
| + mActivityTestRule.getActivity()
|
| + .getCurrentContentViewCore()
|
| + .getWebContents()
|
| + .getUrl());
|
| executeJavaScriptAndWaitForDialog("history.back();");
|
|
|
| jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
| checkButtonPresenceVisibilityText(jsDialog, 2, R.string.leave, "Leave");
|
|
|
| final TestCallbackHelperContainer.OnPageFinishedHelper onPageLoaded =
|
| @@ -229,25 +251,29 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| int callCount = onPageLoaded.getCallCount();
|
| clickOk(jsDialog);
|
| onPageLoaded.waitForCallback(callCount);
|
| - assertEquals(EMPTY_PAGE, getActivity().getCurrentContentViewCore()
|
| - .getWebContents().getUrl());
|
| + Assert.assertEquals(EMPTY_PAGE,
|
| + mActivityTestRule.getActivity()
|
| + .getCurrentContentViewCore()
|
| + .getWebContents()
|
| + .getUrl());
|
| }
|
|
|
| /**
|
| * Verifies that when showing a beforeunload dialogs as a result of a page
|
| * reload, the correct UI strings are used.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testBeforeUnloadOnReloadDialog()
|
| throws InterruptedException, TimeoutException, ExecutionException {
|
| - loadUrl(BEFORE_UNLOAD_URL);
|
| + mActivityTestRule.loadUrl(BEFORE_UNLOAD_URL);
|
| // JavaScript onbeforeunload dialogs require a user gesture.
|
| tapViewAndWait();
|
| executeJavaScriptAndWaitForDialog("window.location.reload();");
|
|
|
| JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| checkButtonPresenceVisibilityText(jsDialog, 0, R.string.cancel, "Cancel");
|
| checkButtonPresenceVisibilityText(jsDialog, 2, R.string.reload, "Reload");
|
| @@ -257,6 +283,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| * Verifies that repeated dialogs give the option to disable dialogs
|
| * altogether and then that disabling them works.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testDisableRepeatedDialogs()
|
| @@ -266,7 +293,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
|
|
| // Show a dialog once.
|
| JavascriptAppModalDialog jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
|
|
| clickCancel(jsDialog);
|
| scriptEvent.waitUntilHasValue();
|
| @@ -274,7 +301,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| // Show it again, it should have the option to suppress subsequent dialogs.
|
| scriptEvent = executeJavaScriptAndWaitForDialog("alert('Android');");
|
| jsDialog = getCurrentDialog();
|
| - assertNotNull("No dialog showing.", jsDialog);
|
| + Assert.assertNotNull("No dialog showing.", jsDialog);
|
| final AlertDialog dialog = jsDialog.getDialogForTest();
|
| String errorMessage = ThreadUtils.runOnUiThreadBlocking(new Callable<String>() {
|
| @Override
|
| @@ -289,14 +316,15 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| return null;
|
| }
|
| });
|
| - assertNull(errorMessage, errorMessage);
|
| + Assert.assertNull(errorMessage, errorMessage);
|
| clickCancel(jsDialog);
|
| scriptEvent.waitUntilHasValue();
|
|
|
| scriptEvent.evaluateJavaScriptForTests(
|
| - getActivity().getCurrentContentViewCore().getWebContents(),
|
| + mActivityTestRule.getActivity().getCurrentContentViewCore().getWebContents(),
|
| "alert('Android');");
|
| - assertTrue("No further dialog boxes should be shown.", scriptEvent.waitUntilHasValue());
|
| + Assert.assertTrue(
|
| + "No further dialog boxes should be shown.", scriptEvent.waitUntilHasValue());
|
| }
|
|
|
| /**
|
| @@ -304,6 +332,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| * to accept the dialog. Verifies that the dialog is dismissed when the tab
|
| * is closed.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| public void testDialogDismissedAfterClosingTab() {
|
| @@ -312,7 +341,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - ChromeActivity activity = getActivity();
|
| + ChromeActivity activity = mActivityTestRule.getActivity();
|
| activity.getCurrentTabModel().closeTab(activity.getActivityTab());
|
| }
|
| });
|
| @@ -337,7 +366,7 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| private OnEvaluateJavaScriptResultHelper executeJavaScriptAndWaitForDialog(
|
| final OnEvaluateJavaScriptResultHelper helper, String script) {
|
| helper.evaluateJavaScriptForTests(
|
| - getActivity().getCurrentContentViewCore().getWebContents(),
|
| + mActivityTestRule.getActivity().getCurrentContentViewCore().getWebContents(),
|
| script);
|
| CriteriaHelper.pollInstrumentationThread(new JavascriptAppModalDialogShownCriteria(
|
| "Could not spawn or locate a modal dialog.", true));
|
| @@ -429,16 +458,16 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
| int expectedTextResourceId, String readableName) throws ExecutionException {
|
| final Button[] buttons = getAlertDialogButtons(jsDialog.getDialogForTest());
|
| final Button button = buttons[buttonIndex];
|
| - assertNotNull("No '" + readableName + "' button in confirm dialog.", button);
|
| - assertEquals("'" + readableName + "' button is not visible.",
|
| - View.VISIBLE,
|
| + Assert.assertNotNull("No '" + readableName + "' button in confirm dialog.", button);
|
| + Assert.assertEquals("'" + readableName + "' button is not visible.", View.VISIBLE,
|
| button.getVisibility());
|
| - assertEquals("'" + readableName + "' button has wrong text",
|
| - getActivity().getResources().getString(expectedTextResourceId),
|
| + Assert.assertEquals("'" + readableName + "' button has wrong text",
|
| + mActivityTestRule.getActivity().getResources().getString(expectedTextResourceId),
|
| button.getText().toString());
|
| }
|
|
|
| private TestCallbackHelperContainer getActiveTabTestCallbackHelperContainer() {
|
| - return new TestCallbackHelperContainer(getActivity().getCurrentContentViewCore());
|
| + return new TestCallbackHelperContainer(
|
| + mActivityTestRule.getActivity().getCurrentContentViewCore());
|
| }
|
| }
|
|
|