From b1956f27b080c012784f9ee5ba3a0fa1d257fab3 Mon Sep 17 00:00:00 2001 From: tedchoc Date: Wed, 6 May 2015 15:40:11 -0700 Subject: [PATCH] Re-enable repost warning tests. De-flaking change landed in: https://codereview.chromium.org/1112373003 Could not see the original flaking causes on the bug, so attempting to re-enable to verify the fix above (or catch the other causes of flakes). BUG=454834 Review URL: https://codereview.chromium.org/1122563003 Cr-Commit-Position: refs/heads/master@{#328636} --- .../chrome/browser/RepostFormWarningDialog.java | 53 ++++++++++++++++------ .../chrome/browser/RepostFormWarningTest.java | 44 ++++++++++-------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java index 1ffb74f42cdb..0af541ede05f 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java @@ -16,36 +16,59 @@ import org.chromium.chrome.R; * Form resubmission warning dialog. Presents the cancel/continue choice and fires one of two * callbacks accordingly. */ -class RepostFormWarningDialog extends DialogFragment { +public class RepostFormWarningDialog extends DialogFragment { // Warning dialog currently being shown, stored for testing. private static Dialog sCurrentDialog; private final Runnable mCancelCallback; private final Runnable mContinueCallback; + /** Empty constructor required for DialogFragments. */ + public RepostFormWarningDialog() { + mCancelCallback = null; + mContinueCallback = null; + } + public RepostFormWarningDialog(Runnable cancelCallback, Runnable continueCallback) { mCancelCallback = cancelCallback; mContinueCallback = continueCallback; } @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // If there is savedInstanceState, then the dialog is being recreated by android + // and will lack the necessary callbacks. Dismiss immediately as the tab will + // need to be recreated anyway. + if (savedInstanceState != null) { + dismiss(); + } + } + + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme) - .setMessage(R.string.http_post_warning) - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - mCancelCallback.run(); - } - }) - .setPositiveButton(R.string.http_post_warning_resend, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - mContinueCallback.run(); - } - }); + .setMessage(R.string.http_post_warning); + + if (savedInstanceState == null) { + assert mCancelCallback != null; + assert mContinueCallback != null; + builder.setNegativeButton(R.string.cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + mCancelCallback.run(); + } + }); + builder.setPositiveButton(R.string.http_post_warning_resend, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + mContinueCallback.run(); + } + }); + } assert getCurrentDialog() == null; Dialog dialog = builder.create(); 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 8cc8870bf943..088bff672518 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java @@ -5,13 +5,19 @@ package org.chromium.chrome.browser; import android.support.v7.app.AlertDialog; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.SmallTest; -import org.chromium.base.test.util.DisabledTest; +import org.chromium.base.ThreadUtils; +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.TestHttpServerClient; +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 java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; /** @@ -35,12 +41,8 @@ public class RepostFormWarningTest extends ChromeShellTestBase { } /** Verifies that the form resubmission warning is not displayed upon first POST navigation. */ - /* @MediumTest @Feature({"Navigation"}) - crbug.com/454834 - */ - @DisabledTest public void testFormFirstNavigation() throws Throwable { // Load the url posting data for the first time. postNavigation(); @@ -53,12 +55,8 @@ public class RepostFormWarningTest extends ChromeShellTestBase { } /** Verifies that confirming the form reload performs the reload. */ - /* @MediumTest @Feature({"Navigation"}) - crbug.com/454834 - */ - @DisabledTest public void testFormResubmissionContinue() throws Throwable { // Load the url posting data for the first time. postNavigation(); @@ -66,9 +64,7 @@ public class RepostFormWarningTest extends ChromeShellTestBase { // Trigger a reload and wait for the warning to be displayed. reload(); - getInstrumentation().waitForIdleSync(); - AlertDialog dialog = (AlertDialog) RepostFormWarningDialog.getCurrentDialog(); - assertNotNull("Form resubmission warning not shown upon reload.", dialog); + AlertDialog dialog = waitForRepostFormWarningDialog(); // Click "Continue" and verify that the page is reloaded. clickButton(dialog, AlertDialog.BUTTON_POSITIVE); @@ -84,12 +80,8 @@ public class RepostFormWarningTest extends ChromeShellTestBase { * after the "Cancel" button is clicked to verify that the load was not triggered, which blocks * for CallbackHelper's default timeout upon each execution. */ - /* @SmallTest @Feature({"Navigation"}) - crbug.com/454834 - */ - @DisabledTest public void testFormResubmissionCancel() throws Throwable { // Load the url posting data for the first time. postNavigation(); @@ -97,9 +89,7 @@ public class RepostFormWarningTest extends ChromeShellTestBase { // Trigger a reload and wait for the warning to be displayed. reload(); - getInstrumentation().waitForIdleSync(); - AlertDialog dialog = (AlertDialog) RepostFormWarningDialog.getCurrentDialog(); - assertNotNull("Form resubmission warning not shown upon reload.", dialog); + AlertDialog dialog = waitForRepostFormWarningDialog(); // Click "Cancel" and verify that the page is not reloaded. clickButton(dialog, AlertDialog.BUTTON_NEGATIVE); @@ -116,6 +106,22 @@ public class RepostFormWarningTest extends ChromeShellTestBase { RepostFormWarningDialog.getCurrentDialog()); } + private AlertDialog waitForRepostFormWarningDialog() throws InterruptedException { + assertTrue("Form resubmission warning not shown", CriteriaHelper.pollForUIThreadCriteria( + new Criteria() { + @Override + public boolean isSatisfied() { + return RepostFormWarningDialog.getCurrentDialog() != null; + } + })); + return ThreadUtils.runOnUiThreadBlockingNoException(new Callable() { + @Override + public AlertDialog call() throws Exception { + return (AlertDialog) RepostFormWarningDialog.getCurrentDialog(); + } + }); + } + /** Performs a POST navigation in mTab. */ private void postNavigation() throws Throwable { final String url = "chrome/test/data/empty.html"; -- 2.11.4.GIT