EMMA Coverage Report (generated Tue Aug 20 10:07:21 PDT 2013)
[all classes][org.chromium.android_webview.test]

COVERAGE SUMMARY FOR SOURCE FILE [AwContentsClientOnFormResubmissionTest.java]

nameclass, %method, %block, %line, %
AwContentsClientOnFormResubmissionTest.java100% (3/3)93%  (13/14)55%  (99/181)62%  (29.1/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AwContentsClientOnFormResubmissionTest100% (1/1)86%  (6/7)41%  (56/135)51%  (18/35)
testResend (): void 0%   (0/1)0%   (0/18)0%   (0/5)
doReload (): void 100% (1/1)3%   (2/63)14%  (2/14)
AwContentsClientOnFormResubmissionTest (): void 100% (1/1)100% (3/3)100% (2/2)
access$100 (AwContentsClientOnFormResubmissionTest): AwContents 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (24/24)100% (6/6)
tearDown (): void 100% (1/1)100% (6/6)100% (3/3)
testDontResend (): void 100% (1/1)100% (18/18)100% (5/5)
     
class AwContentsClientOnFormResubmissionTest$TestAwContentsClient100% (1/1)100% (5/5)91%  (31/34)91%  (10/11)
onFormResubmission (Message, Message): void 100% (1/1)80%  (12/15)80%  (4/5)
AwContentsClientOnFormResubmissionTest$TestAwContentsClient (): void 100% (1/1)100% (9/9)100% (3/3)
AwContentsClientOnFormResubmissionTest$TestAwContentsClient (AwContentsClient... 100% (1/1)100% (3/3)100% (1/1)
getResubmissions (): int 100% (1/1)100% (3/3)100% (1/1)
setResubmit (boolean): void 100% (1/1)100% (4/4)100% (2/2)
     
class AwContentsClientOnFormResubmissionTest$1100% (1/1)100% (2/2)100% (12/12)100% (3/3)
AwContentsClientOnFormResubmissionTest$1 (AwContentsClientOnFormResubmissionT... 100% (1/1)100% (6/6)100% (1/1)
run (): void 100% (1/1)100% (6/6)100% (2/2)

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.android_webview.test;
6 
7import android.content.Context;
8import android.os.Message;
9import android.test.suitebuilder.annotation.SmallTest;
10 
11import org.apache.http.util.EncodingUtils;
12import org.chromium.android_webview.AwContents;
13import org.chromium.base.test.util.DisabledTest;
14import org.chromium.base.test.util.Feature;
15import org.chromium.content.browser.ContentViewCore;
16import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
17import org.chromium.net.test.util.TestWebServer;
18 
19import java.util.concurrent.atomic.AtomicReference;
20import java.util.concurrent.TimeUnit;
21import java.util.concurrent.TimeoutException;
22 
23/**
24 * Tests if resubmission of post data is handled properly.
25 */
26public class AwContentsClientOnFormResubmissionTest extends AwTestBase {
27 
28    private static class TestAwContentsClient
29            extends org.chromium.android_webview.test.TestAwContentsClient {
30 
31        // Number of times onFormResubmit is called.
32        private int mResubmissions = 0;
33        // Whether to resubmit Post data on reload.
34        private boolean mResubmit = false;
35 
36        public int getResubmissions() {
37            return mResubmissions;
38        }
39        public void setResubmit(boolean resubmit) {
40            mResubmit = resubmit;
41        }
42        @Override
43        public void onFormResubmission(Message dontResend, Message resend) {
44            mResubmissions++;
45            if (mResubmit) {
46                resend.sendToTarget();
47            } else {
48                dontResend.sendToTarget();
49            }
50        }
51    }
52 
53    // Server responses for load and reload of posts.
54    private static final String LOAD_RESPONSE =
55            "<html><head><title>Load</title></head><body>HELLO</body></html>";
56    private static final String RELOAD_RESPONSE =
57            "<html><head><title>Reload</title></head><body>HELLO</body></html>";
58 
59    // Server timeout in seconds. Used to detect dontResend case.
60    private static final int TIMEOUT = 3;
61 
62    // The web server.
63    private TestWebServer mServer;
64    // The mock client.
65    private TestAwContentsClient mContentsClient;
66    private AwContents mAwContents;
67 
68    @Override
69    public void setUp() throws Exception {
70        super.setUp();
71        mServer = new TestWebServer(false);
72        mContentsClient = new TestAwContentsClient();
73        final AwTestContainerView testContainerView =
74                createAwTestContainerViewOnMainSync(mContentsClient);
75        mAwContents = testContainerView.getAwContents();
76    }
77 
78    @Override
79    public void tearDown() throws Exception {
80        mServer.shutdown();
81        super.tearDown();
82    }
83 
84/*
85    @SmallTest
86    @Feature({"AndroidWebView", "Navigation"})
87*/
88    @DisabledTest
89    public void testResend() throws Throwable {
90        mContentsClient.setResubmit(true);
91        doReload();
92        assertEquals(1, mContentsClient.getResubmissions());
93        assertEquals("Reload", getTitleOnUiThread(mAwContents));
94    }
95 
96    @SmallTest
97    @Feature({"AndroidWebView", "Navigation"})
98    public void testDontResend() throws Throwable {
99        mContentsClient.setResubmit(false);
100        doReload();
101        assertEquals(1, mContentsClient.getResubmissions());
102        assertEquals("Load", getTitleOnUiThread(mAwContents));
103    }
104 
105    protected void doReload() throws Throwable {
106        String url = mServer.setResponse("/form", LOAD_RESPONSE, null);
107        String postData = "content=blabla";
108        byte[] data = EncodingUtils.getBytes(postData, "BASE64");
109        postUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url, data);
110        assertEquals(0, mContentsClient.getResubmissions());
111        assertEquals("Load", getTitleOnUiThread(mAwContents));
112        // Verify reload works as expected.
113        mServer.setResponse("/form", RELOAD_RESPONSE, null);
114        TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
115                mContentsClient.getOnPageFinishedHelper();
116        int callCount = onPageFinishedHelper.getCallCount();
117        // Run reload on UI thread.
118        getInstrumentation().runOnMainSync(new Runnable() {
119            @Override
120            public void run() {
121                mAwContents.getContentViewCore().reload();
122            }
123        });
124        try {
125            // Wait for page finished callback, or a timeout. A timeout is necessary
126            // to detect a dontResend response.
127            onPageFinishedHelper.waitForCallback(callCount, 1, TIMEOUT, TimeUnit.SECONDS);
128        } catch (TimeoutException e) {
129        }
130    }
131}

[all classes][org.chromium.android_webview.test]
EMMA 2.0.5312 (C) Vladimir Roubtsov