Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2625)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnFormResubmissionTest.java

Issue 11187032: Handle resubmission of HTTP Posts. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnFormResubmissionTest.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnFormResubmissionTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnFormResubmissionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..91d30907f633e73e1ffa65b40d26cd087b5fabf0
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnFormResubmissionTest.java
@@ -0,0 +1,128 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview.test;
+
+import android.content.Context;
+import android.os.Message;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.apache.http.util.EncodingUtils;
+import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.test.util.TestWebServer;
+import org.chromium.base.test.util.Feature;
+import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
+
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * Tests if resubmission of post data is handled properly.
+ */
+public class AwContentsClientOnFormResubmissionTest extends AndroidWebViewTestBase {
+
+ // Server responses for load and reload of posts.
+ private final String LOAD_RESPONSE =
+ "<html><head><title>Load</title></head><body>HELLO</body></html>";
+ private final String RELOAD_RESPONSE =
+ "<html><head><title>Reload</title></head><body>HELLO</body></html>";
+
+ // Server timeout in seconds. Used to detect dontResend case.
+ private final int TIMEOUT = 3;
+
+ // The web server.
+ private TestWebServer mServer;
+ // The mock client.
+ private MockContentsClient mContentsClient;
+ private ContentViewCore mContentViewCore;
+ private AwContents mAwContents;
+
+ class MockContentsClient extends TestAwContentsClient {
joth 2012/10/17 20:35:53 rather than subclass again, add the new methods di
sgurun-gerrit only 2012/10/17 22:08:18 Done.
+ public int resubmissions = 0;
+ private boolean mResubmit = false;
+
+ void setResubmit(boolean resubmit) {
+ mResubmit = resubmit;
+ }
+
+ @Override
+ public void onFormResubmission(Message dontResend, Message resend) {
+ resubmissions++;
+ if (mResubmit) {
+ resend.sendToTarget();
+ } else {
+ dontResend.sendToTarget();
+ }
+ }
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mServer = new TestWebServer(false);
+ mContentsClient = createContentsClientOnMainSync();
+ final AwTestContainerView testContainerView =
+ createAwTestContainerViewOnMainSync(mContentsClient);
+ mContentViewCore = testContainerView.getContentViewCore();
+ mAwContents = testContainerView.getAwContents();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ mServer.shutdown();
+ super.tearDown();
+ }
+
+ protected MockContentsClient createContentsClientOnMainSync() throws Exception {
+ final AtomicReference<MockContentsClient> contentsClient =
+ new AtomicReference<MockContentsClient>();
+ final Context context = getActivity();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ contentsClient.set(new MockContentsClient());
+ }
+ });
+ return contentsClient.get();
+ }
+
+ @SmallTest
+ @Feature({"Android-WebViewClient", "OnFormResubmission"})
joth 2012/10/17 20:35:53 the feature tags are more coarse gained - we're pu
sgurun-gerrit only 2012/10/17 22:08:18 Done.
+ public void testResend() throws Throwable {
+ mContentsClient.setResubmit(true);
+ doReload();
+ assertEquals(1, mContentsClient.resubmissions);
+ assertEquals("Reload", getTitleOnUiThread(mAwContents));
+ }
+
+ @SmallTest
+ @Feature({"Android-WebViewClient", "OnFormResubmission"})
+ public void testDontResend() throws Throwable {
+ mContentsClient.setResubmit(false);
+ doReload();
+ assertEquals(1, mContentsClient.resubmissions);
+ assertEquals("Load", getTitleOnUiThread(mAwContents));
+ }
+
+ protected void doReload() throws Throwable {
+ String url = mServer.setResponse("/form", LOAD_RESPONSE, null);
+ String postData = "content=blabla";
+ byte[] data = EncodingUtils.getBytes(postData, "BASE64");
+ postUrlSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper(), url, data);
+ assertEquals(0, mContentsClient.resubmissions);
+ assertEquals("Load", getTitleOnUiThread(mAwContents));
+ // Verify reload works as expected.
+ mServer.setResponse("/form", RELOAD_RESPONSE, null);
+ TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
+ mContentsClient.getOnPageFinishedHelper();
+ int callCount = onPageFinishedHelper.getCallCount();
+ mContentViewCore.reload();
+ try {
+ onPageFinishedHelper.waitForCallback(callCount, 1, TIMEOUT, TimeUnit.SECONDS);
+ } catch (TimeoutException e) {
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698