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

COVERAGE SUMMARY FOR SOURCE FILE [ContentViewMiscTest.java]

nameclass, %method, %block, %line, %
ContentViewMiscTest.java100% (4/4)100% (10/10)100% (157/157)100% (37/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ContentViewMiscTest100% (1/1)100% (4/4)100% (116/116)100% (32/32)
ContentViewMiscTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (21/21)100% (6/6)
testEnableDisablePlatformNotifications (): void 100% (1/1)100% (82/82)100% (21/21)
testFindAddress (): void 100% (1/1)100% (10/10)100% (4/4)
     
class ContentViewMiscTest$1100% (1/1)100% (2/2)100% (15/15)100% (3/3)
ContentViewMiscTest$1 (ContentViewMiscTest, AtomicReference): void 100% (1/1)100% (9/9)100% (1/1)
registerReceiver (BroadcastReceiver, IntentFilter): Intent 100% (1/1)100% (6/6)100% (2/2)
     
class ContentViewMiscTest$2100% (1/1)100% (2/2)100% (12/12)100% (2/2)
ContentViewMiscTest$2 (ContentViewMiscTest, MockContext): void 100% (1/1)100% (9/9)100% (1/1)
getApplicationContext (): Context 100% (1/1)100% (3/3)100% (1/1)
     
class ContentViewMiscTest$3100% (1/1)100% (2/2)100% (14/14)100% (3/3)
ContentViewMiscTest$3 (ContentViewMiscTest, AtomicBoolean): void 100% (1/1)100% (9/9)100% (1/1)
proxySettingsChanged (): void 100% (1/1)100% (5/5)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.BroadcastReceiver;
8import android.content.Context;
9import android.content.Intent;
10import android.content.IntentFilter;
11import android.net.Proxy;
12import android.test.FlakyTest;
13import android.test.mock.MockContext;
14import android.test.suitebuilder.annotation.SmallTest;
15 
16import org.chromium.android_webview.AwContents;
17import org.chromium.base.test.util.DisabledTest;
18import org.chromium.base.test.util.Feature;
19import org.chromium.base.test.util.UrlUtils;
20import org.chromium.base.ThreadUtils;
21import org.chromium.content.browser.ContentViewCore;
22import org.chromium.content.browser.ContentViewStatics;
23import org.chromium.net.ProxyChangeListener;
24 
25import java.util.concurrent.atomic.AtomicBoolean;
26import java.util.concurrent.atomic.AtomicReference;
27import java.util.concurrent.Callable;
28 
29/**
30 *  Tests for ContentView methods that don't fall into any other category.
31 */
32public class ContentViewMiscTest extends AwTestBase {
33 
34    private TestAwContentsClient mContentsClient;
35    private AwContents mAwContents;
36    private ContentViewCore mContentViewCore;
37 
38    @Override
39    public void setUp() throws Exception {
40        super.setUp();
41        mContentsClient = new TestAwContentsClient();
42        final AwTestContainerView testContainerView =
43                createAwTestContainerViewOnMainSync(mContentsClient);
44        mAwContents = testContainerView.getAwContents();
45        mContentViewCore = testContainerView.getContentViewCore();
46    }
47 
48    @SmallTest
49    @Feature({"AndroidWebView"})
50    public void testFindAddress() {
51        assertNull(ContentViewStatics.findAddress("This is some random text"));
52 
53        String googleAddr = "1600 Amphitheatre Pkwy, Mountain View, CA 94043";
54        assertEquals(googleAddr, ContentViewStatics.findAddress(googleAddr));
55    }
56 
57    @SmallTest
58    @Feature({"AndroidWebView"})
59    public void testEnableDisablePlatformNotifications() {
60 
61        // Set up mock contexts to use with the listener
62        final AtomicReference<BroadcastReceiver> receiverRef =
63                new AtomicReference<BroadcastReceiver>();
64        final MockContext appContext = new MockContext() {
65            @Override
66            public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
67                receiverRef.set(receiver);
68                return null;
69            }
70        };
71        final MockContext context = new MockContext() {
72            @Override
73            public Context getApplicationContext() {
74                return appContext;
75            }
76        };
77 
78        // Set up a delegate so we know when native code is about to get
79        // informed of a proxy change.
80        final AtomicBoolean proxyChanged = new AtomicBoolean();
81        final ProxyChangeListener.Delegate delegate = new ProxyChangeListener.Delegate() {
82            @Override
83            public void proxySettingsChanged() {
84                proxyChanged.set(true);
85            }
86        };
87        Intent intent = new Intent();
88        intent.setAction(Proxy.PROXY_CHANGE_ACTION);
89 
90        // Create the listener that's going to be used for the test
91        ProxyChangeListener listener = ProxyChangeListener.create(context);
92        listener.setDelegateForTesting(delegate);
93        listener.start(0);
94 
95        // Start the actual tests
96 
97        // Make sure everything works by default
98        proxyChanged.set(false);
99        receiverRef.get().onReceive(context, intent);
100        assertEquals(true, proxyChanged.get());
101 
102        // Now disable platform notifications and make sure we don't notify
103        // native code.
104        proxyChanged.set(false);
105        ContentViewStatics.disablePlatformNotifications();
106        receiverRef.get().onReceive(context, intent);
107        assertEquals(false, proxyChanged.get());
108 
109        // Now re-enable notifications to make sure they work again.
110        ContentViewStatics.enablePlatformNotifications();
111        receiverRef.get().onReceive(context, intent);
112        assertEquals(true, proxyChanged.get());
113    }
114}

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