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

COVERAGE SUMMARY FOR SOURCE FILE [AwContentsClientAutoLoginTest.java]

nameclass, %method, %block, %line, %
AwContentsClientAutoLoginTest.java100% (3/3)100% (14/14)89%  (171/192)96%  (42.4/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AwContentsClientAutoLoginTest$OnReceivedLoginRequestHelper100% (1/1)100% (6/6)76%  (45/59)87%  (10.5/12)
getAccount (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
getArgs (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
getRealm (): String 100% (1/1)67%  (8/12)78%  (1.6/2)
<static initializer> 100% (1/1)75%  (6/8)75%  (0.8/1)
AwContentsClientAutoLoginTest$OnReceivedLoginRequestHelper (): void 100% (1/1)100% (3/3)100% (1/1)
notifyCalled (String, String, String): void 100% (1/1)100% (12/12)100% (5/5)
     
class AwContentsClientAutoLoginTest100% (1/1)100% (5/5)94%  (108/115)100% (25.9/26)
autoLoginTestHelper (String, String, String, String, String): void 100% (1/1)92%  (76/83)100% (17.9/18)
AwContentsClientAutoLoginTest (): void 100% (1/1)100% (8/8)100% (2/2)
testAutoLoginOnGoogleCom (): void 100% (1/1)100% (8/8)100% (2/2)
testAutoLoginOnNonGoogle (): void 100% (1/1)100% (8/8)100% (2/2)
testAutoLoginWithNullAccount (): void 100% (1/1)100% (8/8)100% (2/2)
     
class AwContentsClientAutoLoginTest$TestAwContentsClient100% (1/1)100% (3/3)100% (18/18)100% (6/6)
AwContentsClientAutoLoginTest$TestAwContentsClient (): void 100% (1/1)100% (8/8)100% (3/3)
getOnReceivedLoginRequestHelper (): AwContentsClientAutoLoginTest$OnReceivedL... 100% (1/1)100% (3/3)100% (1/1)
onReceivedLoginRequest (String, String, String): void 100% (1/1)100% (7/7)100% (2/2)

1// Copyright (c) 2013 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.util.Pair;
9 
10import org.chromium.base.test.util.Feature;
11import org.chromium.content.browser.test.util.CallbackHelper;
12import org.chromium.android_webview.AwContents;
13import org.chromium.net.test.util.TestWebServer;
14 
15import java.util.ArrayList;
16import java.util.List;
17 
18/**
19 * Tests for the AwContentsClient.onReceivedLoginRequest callback.
20 */
21public class AwContentsClientAutoLoginTest extends AwTestBase {
22    public static class OnReceivedLoginRequestHelper extends CallbackHelper {
23        String mRealm;
24        String mAccount;
25        String mArgs;
26 
27        public String getRealm() {
28            assert getCallCount() > 0;
29            return mRealm;
30        }
31 
32        public String getAccount() {
33            assert getCallCount() > 0;
34            return mAccount;
35        }
36 
37        public String getArgs() {
38            assert getCallCount() > 0;
39            return mArgs;
40        }
41 
42        public void notifyCalled(String realm, String account, String args) {
43            mRealm = realm;
44            mAccount = account;
45            mArgs = args;
46            notifyCalled();
47        }
48    }
49 
50    private static class TestAwContentsClient
51            extends org.chromium.android_webview.test.TestAwContentsClient {
52 
53        private OnReceivedLoginRequestHelper mOnReceivedLoginRequestHelper;
54 
55        public TestAwContentsClient() {
56            mOnReceivedLoginRequestHelper = new OnReceivedLoginRequestHelper();
57        }
58 
59        public OnReceivedLoginRequestHelper getOnReceivedLoginRequestHelper() {
60            return mOnReceivedLoginRequestHelper;
61        }
62 
63        @Override
64        public void onReceivedLoginRequest(String realm, String account, String args) {
65            getOnReceivedLoginRequestHelper().notifyCalled(realm, account, args);
66        }
67    }
68 
69    private TestAwContentsClient mContentsClient = new TestAwContentsClient();
70 
71    private void autoLoginTestHelper(final String testName, final String xAutoLoginHeader,
72            final String expectedRealm, final String expectedAccount, final String expectedArgs)
73            throws Throwable {
74        AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
75        AwContents awContents = testView.getAwContents();
76        final OnReceivedLoginRequestHelper loginRequestHelper =
77            mContentsClient.getOnReceivedLoginRequestHelper();
78 
79        final String path = "/" + testName + ".html";
80        final String html = testName;
81        List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>();
82        headers.add(Pair.create("x-auto-login", xAutoLoginHeader));
83 
84        TestWebServer webServer = null;
85        try {
86            webServer = new TestWebServer(false);
87            final String pageUrl = webServer.setResponse(path, html, headers);
88            final int callCount = loginRequestHelper.getCallCount();
89            loadUrlAsync(awContents, pageUrl);
90            loginRequestHelper.waitForCallback(callCount);
91 
92            assertEquals(expectedRealm, loginRequestHelper.getRealm());
93            assertEquals(expectedAccount, loginRequestHelper.getAccount());
94            assertEquals(expectedArgs, loginRequestHelper.getArgs());
95        } finally {
96            if (webServer != null) webServer.shutdown();
97        }
98    }
99 
100    @Feature({"AndroidWebView"})
101    @SmallTest
102    public void testAutoLoginOnGoogleCom() throws Throwable {
103        autoLoginTestHelper(
104                "testAutoLoginOnGoogleCom",  /* testName */
105                "realm=com.google&account=foo%40bar.com&args=random_string", /* xAutoLoginHeader */
106                "com.google",  /* expectedRealm */
107                "foo@bar.com",  /* expectedAccount */
108                "random_string"  /* expectedArgs */);
109 
110    }
111 
112    @Feature({"AndroidWebView"})
113    @SmallTest
114    public void testAutoLoginWithNullAccount() throws Throwable {
115        autoLoginTestHelper(
116                "testAutoLoginOnGoogleCom",  /* testName */
117                "realm=com.google&args=not.very.inventive", /* xAutoLoginHeader */
118                "com.google",  /* expectedRealm */
119                null,  /* expectedAccount */
120                "not.very.inventive"  /* expectedArgs */);
121    }
122 
123    @Feature({"AndroidWebView"})
124    @SmallTest
125    public void testAutoLoginOnNonGoogle() throws Throwable {
126        autoLoginTestHelper(
127                "testAutoLoginOnGoogleCom",  /* testName */
128                "realm=com.bar&account=foo%40bar.com&args=args", /* xAutoLoginHeader */
129                "com.bar",  /* expectedRealm */
130                "foo@bar.com",  /* expectedAccount */
131                "args"  /* expectedArgs */);
132    }
133}

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