summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Choc <tedchoc@google.com>2016-03-18 13:16:32 -0700
committerTed Choc <tedchoc@google.com>2016-03-18 20:18:37 +0000
commit07f4e9d7c668104b08a852f72403e2ce30db8cf5 (patch)
tree3e5a5ebbd1bdf0be04200aa2e5ec5e3820af625e
parentcb284bea1e19bf52f6af898b7ced1211936325c0 (diff)
downloadchromium_src-07f4e9d7c668104b08a852f72403e2ce30db8cf5.zip
chromium_src-07f4e9d7c668104b08a852f72403e2ce30db8cf5.tar.gz
chromium_src-07f4e9d7c668104b08a852f72403e2ce30db8cf5.tar.bz2
Dismiss the repost form warning dialog on tab close.
TEST=RepostFormWarningTest#testFormResubmissionTabDestroyed BUG=580284 Review URL: https://codereview.chromium.org/1731703002 Cr-Commit-Position: refs/heads/master@{#377450} Review URL: https://codereview.chromium.org/1815323003 . Cr-Commit-Position: refs/branch-heads/2623@{#636} Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907}
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java51
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java3
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java13
-rw-r--r--chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java40
4 files changed, 73 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 0af541e..669a56f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/RepostFormWarningDialog.java
@@ -10,7 +10,11 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
+import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.tab.EmptyTabObserver;
+import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.browser.tab.TabObserver;
/**
* Form resubmission warning dialog. Presents the cancel/continue choice and fires one of two
@@ -20,18 +24,28 @@ 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;
+ private final Tab mTab;
+ private final TabObserver mTabObserver;
/** Empty constructor required for DialogFragments. */
public RepostFormWarningDialog() {
- mCancelCallback = null;
- mContinueCallback = null;
+ mTab = null;
+ mTabObserver = null;
}
- public RepostFormWarningDialog(Runnable cancelCallback, Runnable continueCallback) {
- mCancelCallback = cancelCallback;
- mContinueCallback = continueCallback;
+ /**
+ * Handles the repost form warning for the given Tab.
+ * @param tab The tab waiting for confirmation on a repost form warning.
+ */
+ public RepostFormWarningDialog(Tab tab) {
+ mTab = tab;
+ mTabObserver = new EmptyTabObserver() {
+ @Override
+ public void onDestroyed(Tab tab) {
+ dismiss();
+ }
+ };
+ mTab.addObserver(mTabObserver);
}
@Override
@@ -52,27 +66,27 @@ public class RepostFormWarningDialog extends DialogFragment {
.setMessage(R.string.http_post_warning);
if (savedInstanceState == null) {
- assert mCancelCallback != null;
- assert mContinueCallback != null;
+ assert mTab != null;
builder.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- mCancelCallback.run();
+ if (!mTab.isInitialized()) return;
+ mTab.getWebContents().getNavigationController().cancelPendingReload();
}
});
builder.setPositiveButton(R.string.http_post_warning_resend,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- mContinueCallback.run();
+ if (!mTab.isInitialized()) return;
+ mTab.getWebContents().getNavigationController().continuePendingReload();
}
});
}
- assert getCurrentDialog() == null;
Dialog dialog = builder.create();
- setCurrentDialog(dialog);
+ setCurrentDialogForTesting(dialog);
return dialog;
}
@@ -80,21 +94,26 @@ public class RepostFormWarningDialog extends DialogFragment {
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
- setCurrentDialog(null);
+ setCurrentDialogForTesting(null);
+
+ if (mTab != null && mTabObserver != null) {
+ mTab.removeObserver(mTabObserver);
+ }
}
/**
* Sets the currently displayed dialog in sCurrentDialog. This is required by findbugs, which
* allows static fields only to be set from static methods.
*/
- private static void setCurrentDialog(Dialog dialog) {
+ private static void setCurrentDialogForTesting(Dialog dialog) {
sCurrentDialog = dialog;
}
/**
* @return dialog currently being displayed.
*/
- public static Dialog getCurrentDialog() {
+ @VisibleForTesting
+ public static Dialog getCurrentDialogForTesting() {
return sCurrentDialog;
}
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
index 64259b7..bf5636f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
@@ -1757,7 +1757,8 @@ public final class Tab implements ViewGroup.OnHierarchyChangeListener,
}
/**
- * @return Whether or not this Tab has a live native component.
+ * @return Whether or not this Tab has a live native component. This will be true prior to
+ * {@link #initializeNative()} being called or after {@link #destroy()}.
*/
public boolean isInitialized() {
return mIsInitialized;
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java
index 4226a5f..caa0f53 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java
@@ -205,18 +205,7 @@ public class TabWebContentsDelegateAndroid extends WebContentsDelegateAndroid {
@Override
public void showRepostFormWarningDialog() {
mTab.resetSwipeRefreshHandler();
- RepostFormWarningDialog warningDialog = new RepostFormWarningDialog(
- new Runnable() {
- @Override
- public void run() {
- mTab.getWebContents().getNavigationController().cancelPendingReload();
- }
- }, new Runnable() {
- @Override
- public void run() {
- mTab.getWebContents().getNavigationController().continuePendingReload();
- }
- });
+ RepostFormWarningDialog warningDialog = new RepostFormWarningDialog(mTab);
warningDialog.show(mActivity.getFragmentManager(), null);
}
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 559ddf9..ff7b0545 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/RepostFormWarningTest.java
@@ -58,7 +58,7 @@ public class RepostFormWarningTest extends ChromeActivityTestCaseBase<ChromeActi
// Verify that the form resubmission warning was not shown.
assertNull("Form resubmission warning shown upon first load.",
- RepostFormWarningDialog.getCurrentDialog());
+ RepostFormWarningDialog.getCurrentDialogForTesting());
}
/** Verifies that confirming the form reload performs the reload. */
@@ -79,7 +79,7 @@ public class RepostFormWarningTest extends ChromeActivityTestCaseBase<ChromeActi
// Verify that the reference to the dialog in RepostFormWarningDialog was cleared.
assertNull("Form resubmission warning dialog was not dismissed correctly.",
- RepostFormWarningDialog.getCurrentDialog());
+ RepostFormWarningDialog.getCurrentDialogForTesting());
}
/**
@@ -110,7 +110,37 @@ public class RepostFormWarningTest extends ChromeActivityTestCaseBase<ChromeActi
// Verify that the reference to the dialog in RepostFormWarningDialog was cleared.
assertNull("Form resubmission warning dialog was not dismissed correctly.",
- RepostFormWarningDialog.getCurrentDialog());
+ RepostFormWarningDialog.getCurrentDialogForTesting());
+ }
+
+ /**
+ * Verifies that destroying the Tab dismisses the form resubmission dialog.
+ */
+ @SmallTest
+ @Feature({"Navigation"})
+ public void testFormResubmissionTabDestroyed() throws Throwable {
+ // Load the url posting data for the first time.
+ postNavigation();
+ mCallbackHelper.getOnPageFinishedHelper().waitForCallback(0);
+
+ // Trigger a reload and wait for the warning to be displayed.
+ reload();
+ waitForRepostFormWarningDialog();
+
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ getActivity().getCurrentTabModel().closeTab(mTab);
+ }
+ });
+
+ CriteriaHelper.pollForUIThreadCriteria(
+ new Criteria("Form resubmission dialog not dismissed correctly") {
+ @Override
+ public boolean isSatisfied() {
+ return RepostFormWarningDialog.getCurrentDialogForTesting() == null;
+ }
+ });
}
private AlertDialog waitForRepostFormWarningDialog() throws InterruptedException {
@@ -118,13 +148,13 @@ public class RepostFormWarningTest extends ChromeActivityTestCaseBase<ChromeActi
new Criteria("Form resubmission warning not shown") {
@Override
public boolean isSatisfied() {
- return RepostFormWarningDialog.getCurrentDialog() != null;
+ return RepostFormWarningDialog.getCurrentDialogForTesting() != null;
}
});
return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<AlertDialog>() {
@Override
public AlertDialog call() throws Exception {
- return (AlertDialog) RepostFormWarningDialog.getCurrentDialog();
+ return (AlertDialog) RepostFormWarningDialog.getCurrentDialogForTesting();
}
});
}