| 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..a22c0166af63afe522eaa130744d7bbeafa46356
|
| --- /dev/null
|
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnFormResubmissionTest.java
|
| @@ -0,0 +1,109 @@
|
| +// 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.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 TestAwContentsClient mContentsClient;
|
| + private ContentViewCore mContentViewCore;
|
| + private AwContents mAwContents;
|
| +
|
| + @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 TestAwContentsClient createContentsClientOnMainSync() throws
|
| + Exception {
|
| + final AtomicReference<TestAwContentsClient> contentsClient =
|
| + new AtomicReference<TestAwContentsClient>();
|
| + final Context context = getActivity();
|
| + getInstrumentation().runOnMainSync(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + contentsClient.set(new TestAwContentsClient());
|
| + }
|
| + });
|
| + return contentsClient.get();
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Android-WebView", "Navigation"})
|
| + public void testResend() throws Throwable {
|
| + mContentsClient.setResubmit(true);
|
| + doReload();
|
| + assertEquals(1, mContentsClient.getResubmissions());
|
| + assertEquals("Reload", getTitleOnUiThread(mAwContents));
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Android-WebView", "Navigation"})
|
| + public void testDontResend() throws Throwable {
|
| + mContentsClient.setResubmit(false);
|
| + doReload();
|
| + assertEquals(1, mContentsClient.getResubmissions());
|
| + 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.getResubmissions());
|
| + 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) {
|
| + }
|
| + }
|
| +}
|
|
|