EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.android_webview.test]

COVERAGE SUMMARY FOR SOURCE FILE [ArchiveTest.java]

nameclass, %method, %block, %line, %
ArchiveTest.java100% (3/3)100% (12/12)100% (308/309)100% (55.9/56)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ArchiveTest100% (1/1)100% (8/8)100% (260/261)100% (50.9/51)
doArchiveTest (AwContents, String, boolean, String): void 100% (1/1)99%  (73/74)100% (16.9/17)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
ArchiveTest (): void 100% (1/1)100% (8/8)100% (2/2)
setUp (): void 100% (1/1)100% (9/9)100% (3/3)
testAutoBadPath (): void 100% (1/1)100% (35/35)100% (7/7)
testAutoGoodPath (): void 100% (1/1)100% (57/57)100% (7/7)
testExplicitBadPath (): void 100% (1/1)100% (35/35)100% (7/7)
testExplicitGoodPath (): void 100% (1/1)100% (39/39)100% (7/7)
     
class ArchiveTest$1100% (1/1)100% (2/2)100% (20/20)100% (4/4)
ArchiveTest$1 (ArchiveTest, AtomicReference, Semaphore): void 100% (1/1)100% (12/12)100% (1/1)
onReceiveValue (String): void 100% (1/1)100% (8/8)100% (3/3)
     
class ArchiveTest$2100% (1/1)100% (2/2)100% (28/28)100% (3/3)
ArchiveTest$2 (ArchiveTest, AwContents, String, boolean, ValueCallback): void 100% (1/1)100% (18/18)100% (1/1)
run (): void 100% (1/1)100% (10/10)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.test.suitebuilder.annotation.SmallTest;
8import android.webkit.ValueCallback;
9 
10import org.chromium.android_webview.AwContents;
11import org.chromium.base.ThreadUtils;
12import org.chromium.base.test.util.Feature;
13import org.chromium.base.test.util.UrlUtils;
14 
15import java.io.File;
16import java.util.concurrent.Semaphore;
17import java.util.concurrent.TimeUnit;
18import java.util.concurrent.atomic.AtomicReference;
19 
20public class ArchiveTest extends AwTestBase {
21 
22    private static final long TEST_TIMEOUT = 20000L;
23 
24    private static final String TEST_PAGE = UrlUtils.encodeHtmlDataUri(
25            "<html><head></head><body>test</body></html>");
26 
27    private TestAwContentsClient mContentsClient = new TestAwContentsClient();
28    private AwTestContainerView mTestContainerView;
29 
30    @Override
31    protected void setUp() throws Exception {
32        super.setUp();
33        mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient);
34    }
35 
36    private void doArchiveTest(final AwContents contents, final String path,
37            final boolean autoName, String expectedPath) throws InterruptedException {
38        if (expectedPath != null) {
39            File file = new File(expectedPath);
40            file.delete();
41        }
42 
43        // Set up a handler to handle the completion callback
44        final Semaphore s = new Semaphore(0);
45        final AtomicReference<String> msgPath = new AtomicReference<String>();
46        final ValueCallback<String> callback = new ValueCallback<String>() {
47            @Override
48            public void onReceiveValue(String path) {
49                msgPath.set(path);
50                s.release();
51            }
52        };
53 
54        // Generate MHTML and wait for completion
55        ThreadUtils.runOnUiThread(new Runnable() {
56            @Override
57            public void run() {
58                contents.saveWebArchive(path, autoName, callback);
59            }
60        });
61        assertTrue(s.tryAcquire(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
62 
63        assertEquals(expectedPath, msgPath.get());
64        if (expectedPath != null) {
65            File file = new File(expectedPath);
66            assertTrue(file.exists());
67            assertTrue(file.length() > 0);
68        } else {
69            // A path was provided, but the expected path was null. This means the save should have
70            // failed, and so there shouldn't be a file path path.
71            if (path != null) {
72                assertFalse(new File(path).exists());
73            }
74        }
75    }
76 
77    @SmallTest
78    @Feature({"AndroidWebView"})
79    public void testExplicitGoodPath() throws Throwable {
80        final String path = new File(getActivity().getFilesDir(), "test.mht").getAbsolutePath();
81        File file = new File(path);
82        file.delete();
83        assertFalse(file.exists());
84 
85        loadUrlSync(mTestContainerView.getAwContents(),
86                mContentsClient.getOnPageFinishedHelper(), TEST_PAGE);
87 
88        doArchiveTest(mTestContainerView.getAwContents(), path, false, path);
89    }
90 
91    @SmallTest
92    @Feature({"AndroidWebView"})
93    public void testAutoGoodPath() throws Throwable {
94        final String path = getActivity().getFilesDir().getAbsolutePath() + "/";
95 
96        loadUrlSync(mTestContainerView.getAwContents(),
97                mContentsClient.getOnPageFinishedHelper(), TEST_PAGE);
98 
99        // Create the first archive
100        {
101            String expectedPath = path + "index.mht";
102            doArchiveTest(mTestContainerView.getAwContents(), path, true, expectedPath);
103        }
104 
105        // Create a second archive, making sure that the second archive's name is auto incremented.
106        {
107            String expectedPath = path + "index-1.mht";
108            doArchiveTest(mTestContainerView.getAwContents(), path, true, expectedPath);
109        }
110    }
111 
112    @SmallTest
113    @Feature({"AndroidWebView"})
114    public void testExplicitBadPath() throws Throwable {
115        final String path = new File("/foo/bar/baz.mht").getAbsolutePath();
116        File file = new File(path);
117        file.delete();
118        assertFalse(file.exists());
119 
120        loadUrlSync(mTestContainerView.getAwContents(),
121                mContentsClient.getOnPageFinishedHelper(), TEST_PAGE);
122 
123        doArchiveTest(mTestContainerView.getAwContents(), path, false, null);
124    }
125 
126    @SmallTest
127    @Feature({"AndroidWebView"})
128    public void testAutoBadPath() throws Throwable {
129        final String path = new File("/foo/bar/").getAbsolutePath();
130        File file = new File(path);
131        file.delete();
132        assertFalse(file.exists());
133 
134        loadUrlSync(mTestContainerView.getAwContents(),
135                mContentsClient.getOnPageFinishedHelper(), TEST_PAGE);
136 
137        doArchiveTest(mTestContainerView.getAwContents(), path, true, null);
138    }
139 
140}

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