Index: chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java |
index ad010679b86048df388b3d898dc9feaa8ccc7a59..3865d5dfe39219a14f6fe1ca7eff22548bf6e24a 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java |
@@ -4,25 +4,15 @@ |
package org.chromium.chrome.browser; |
-import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.MediumTest; |
import android.support.test.filters.SmallTest; |
import android.support.v7.app.AlertDialog; |
-import org.junit.After; |
-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.CommandLineFlags; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.RetryOnFailure; |
import org.chromium.chrome.browser.tab.Tab; |
-import org.chromium.chrome.test.ChromeActivityTestRule; |
-import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
+import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
@@ -35,55 +25,54 @@ |
/** |
* Integration tests verifying that form resubmission dialogs are correctly displayed and handled. |
*/ |
-@RunWith(ChromeJUnit4ClassRunner.class) |
@RetryOnFailure |
-@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
- ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
-public class RepostFormWarningTest { |
+public class RepostFormWarningTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
// Active tab. |
- |
- @Rule |
- public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
- new ChromeActivityTestRule<>(ChromeActivity.class); |
- |
private Tab mTab; |
// Callback helper that manages waiting for pageloads to finish. |
private TestCallbackHelperContainer mCallbackHelper; |
private EmbeddedTestServer mTestServer; |
- @Before |
+ public RepostFormWarningTest() { |
+ super(ChromeActivity.class); |
+ } |
+ |
+ @Override |
+ public void startMainActivity() throws InterruptedException { |
+ startMainActivityOnBlankPage(); |
+ } |
+ |
+ @Override |
public void setUp() throws Exception { |
- mActivityTestRule.startMainActivityOnBlankPage(); |
- |
- mTab = mActivityTestRule.getActivity().getActivityTab(); |
+ super.setUp(); |
+ |
+ mTab = getActivity().getActivityTab(); |
mCallbackHelper = new TestCallbackHelperContainer(mTab.getContentViewCore()); |
- mTestServer = EmbeddedTestServer.createAndStartServer( |
- InstrumentationRegistry.getInstrumentation().getContext()); |
- } |
- |
- @After |
+ mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); |
+ } |
+ |
+ @Override |
public void tearDown() throws Exception { |
mTestServer.stopAndDestroyServer(); |
+ super.tearDown(); |
} |
/** Verifies that the form resubmission warning is not displayed upon first POST navigation. */ |
- @Test |
@MediumTest |
@Feature({"Navigation"}) |
public void testFormFirstNavigation() throws Throwable { |
// Load the url posting data for the first time. |
postNavigation(); |
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(0); |
- InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
+ getInstrumentation().waitForIdleSync(); |
// Verify that the form resubmission warning was not shown. |
- Assert.assertNull("Form resubmission warning shown upon first load.", |
+ assertNull("Form resubmission warning shown upon first load.", |
RepostFormWarningDialog.getCurrentDialogForTesting()); |
} |
/** Verifies that confirming the form reload performs the reload. */ |
- @Test |
@MediumTest |
@Feature({"Navigation"}) |
public void testFormResubmissionContinue() throws Throwable { |
@@ -100,7 +89,7 @@ |
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1); |
// Verify that the reference to the dialog in RepostFormWarningDialog was cleared. |
- Assert.assertNull("Form resubmission warning dialog was not dismissed correctly.", |
+ assertNull("Form resubmission warning dialog was not dismissed correctly.", |
RepostFormWarningDialog.getCurrentDialogForTesting()); |
} |
@@ -109,7 +98,6 @@ |
* after the "Cancel" button is clicked to verify that the load was not triggered, which blocks |
* for CallbackHelper's default timeout upon each execution. |
*/ |
- @Test |
@SmallTest |
@Feature({"Navigation"}) |
public void testFormResubmissionCancel() throws Throwable { |
@@ -129,17 +117,16 @@ |
} catch (TimeoutException ex) { |
timedOut = true; |
} |
- Assert.assertTrue("Page was reloaded despite selecting Cancel.", timedOut); |
+ assertTrue("Page was reloaded despite selecting Cancel.", timedOut); |
// Verify that the reference to the dialog in RepostFormWarningDialog was cleared. |
- Assert.assertNull("Form resubmission warning dialog was not dismissed correctly.", |
+ assertNull("Form resubmission warning dialog was not dismissed correctly.", |
RepostFormWarningDialog.getCurrentDialogForTesting()); |
} |
/** |
* Verifies that destroying the Tab dismisses the form resubmission dialog. |
*/ |
- @Test |
@SmallTest |
@Feature({"Navigation"}) |
public void testFormResubmissionTabDestroyed() throws Throwable { |
@@ -154,7 +141,7 @@ |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
- mActivityTestRule.getActivity().getCurrentTabModel().closeTab(mTab); |
+ getActivity().getCurrentTabModel().closeTab(mTab); |
} |
}); |
@@ -188,7 +175,7 @@ |
final String url = "/chrome/test/data/android/test.html"; |
final byte[] postData = new byte[] { 42 }; |
- InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { |
+ runTestOnUiThread(new Runnable() { |
@Override |
public void run() { |
mTab.loadUrl(LoadUrlParams.createLoadHttpPostParams( |
@@ -199,7 +186,7 @@ |
/** Reloads mTab. */ |
private void reload() throws Throwable { |
- InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { |
+ runTestOnUiThread(new Runnable() { |
@Override |
public void run() { |
mTab.reload(); |
@@ -209,7 +196,7 @@ |
/** Clicks the given button in the given dialog. */ |
private void clickButton(final AlertDialog dialog, final int buttonId) throws Throwable { |
- InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { |
+ runTestOnUiThread(new Runnable() { |
@Override |
public void run() { |
dialog.getButton(buttonId).performClick(); |