This source file includes following definitions.
- setUp
- Feature
- testFormFirstNavigation
- Feature
- testFormResubmissionContinue
- Feature
- testFormResubmissionCancel
- postNavigation
- reload
- clickButton
package org.chromium.chrome.browser;
import android.app.AlertDialog;
import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.test.util.EnormousTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.shell.ChromeShellTab;
import org.chromium.chrome.shell.ChromeShellTestBase;
import org.chromium.chrome.test.util.TabUtils;
import org.chromium.chrome.test.util.TestHttpServerClient;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import java.util.concurrent.TimeoutException;
public class RepostFormWarningTest extends ChromeShellTestBase {
private ChromeShellTab mTab;
private TestCallbackHelperContainer mCallbackHelper;
@Override
public void setUp() throws Exception {
super.setUp();
mTab = launchChromeShellWithBlankPage().getActiveTab();
mCallbackHelper = TabUtils.getTestCallbackHelperContainer(mTab);
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(0);
}
@MediumTest
@Feature({"Navigation"})
public void testFormFirstNavigation() throws Throwable {
postNavigation();
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1);
getInstrumentation().waitForIdleSync();
assertNull("Form resubmission warning shown upon first load.",
RepostFormWarningDialog.getCurrentDialog());
}
@MediumTest
@Feature({"Navigation"})
public void testFormResubmissionContinue() throws Throwable {
postNavigation();
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1);
reload();
getInstrumentation().waitForIdleSync();
AlertDialog dialog = (AlertDialog)RepostFormWarningDialog.getCurrentDialog();
assertNotNull("Form resubmission warning not shown upon reload.", dialog);
clickButton(dialog, AlertDialog.BUTTON_POSITIVE);
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(2);
assertNull("Form resubmission warning dialog was not dismissed correctly.",
RepostFormWarningDialog.getCurrentDialog());
}
@EnormousTest
@Feature({"Navigation"})
public void testFormResubmissionCancel() throws Throwable {
postNavigation();
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(1);
reload();
getInstrumentation().waitForIdleSync();
AlertDialog dialog = (AlertDialog)RepostFormWarningDialog.getCurrentDialog();
assertNotNull("Form resubmission warning not shown upon reload.", dialog);
clickButton(dialog, AlertDialog.BUTTON_NEGATIVE);
boolean timedOut = false;
try {
mCallbackHelper.getOnPageFinishedHelper().waitForCallback(2);
} catch (TimeoutException ex) {
timedOut = true;
}
assertTrue("Page was reloaded despite selecting Cancel.", timedOut);
assertNull("Form resubmission warning dialog was not dismissed correctly.",
RepostFormWarningDialog.getCurrentDialog());
}
private void postNavigation() throws Throwable {
final String url = "chrome/test/data/empty.html";
final byte[] postData = new byte[] { 42 };
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mTab.loadUrlWithSanitization(TestHttpServerClient.getUrl(url), postData);
}
});
}
private void reload() throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
mTab.reload();
}
});
}
private void clickButton(final AlertDialog dialog, final int buttonId) throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
dialog.getButton(buttonId).performClick();
}
});
}
}