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

COVERAGE SUMMARY FOR SOURCE FILE [AndroidProfileOAuth2TokenServiceHelperTest.java]

nameclass, %method, %block, %line, %
AndroidProfileOAuth2TokenServiceHelperTest.java100% (1/1)100% (5/5)100% (86/86)100% (20/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AndroidProfileOAuth2TokenServiceHelperTest100% (1/1)100% (5/5)100% (86/86)100% (20/20)
AndroidProfileOAuth2TokenServiceHelperTest (): void 100% (1/1)100% (3/3)100% (1/1)
runTestOfGetOAuth2AccessTokenWithTimeout (String): void 100% (1/1)100% (43/43)100% (8/8)
setUp (): void 100% (1/1)100% (28/28)100% (5/5)
testGetOAuth2AccessTokenWithTimeoutOnError (): void 100% (1/1)100% (6/6)100% (3/3)
testGetOAuth2AccessTokenWithTimeoutOnSuccess (): void 100% (1/1)100% (6/6)100% (3/3)

1// Copyright 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.chrome.browser.signin;
6 
7import android.accounts.Account;
8import android.test.InstrumentationTestCase;
9import android.test.suitebuilder.annotation.SmallTest;
10 
11import org.chromium.base.test.util.AdvancedMockContext;
12import org.chromium.base.test.util.Feature;
13import org.chromium.sync.signin.AccountManagerHelper;
14import org.chromium.sync.test.util.AccountHolder;
15import org.chromium.sync.test.util.MockAccountManager;
16 
17import java.util.concurrent.TimeUnit;
18 
19public class AndroidProfileOAuth2TokenServiceHelperTest extends InstrumentationTestCase {
20 
21    private AdvancedMockContext mContext;
22    private MockAccountManager mAccountManager;
23 
24    @Override
25    protected void setUp() throws Exception {
26        super.setUp();
27 
28        // Mock out the account manager on the device.
29        mContext = new AdvancedMockContext(getInstrumentation().getTargetContext());
30        mAccountManager = new MockAccountManager(mContext, getInstrumentation().getContext());
31        AccountManagerHelper.overrideAccountManagerHelperForTests(mContext, mAccountManager);
32    }
33 
34    @SmallTest
35    @Feature({"Sync"})
36    public void testGetOAuth2AccessTokenWithTimeoutOnSuccess() {
37        String authToken = "someToken";
38        // Auth token should be successfully received.
39        runTestOfGetOAuth2AccessTokenWithTimeout(authToken);
40    }
41 
42    @SmallTest
43    @Feature({"Sync"})
44    public void testGetOAuth2AccessTokenWithTimeoutOnError() {
45        String authToken = null;
46        // Should not crash when auth token is null.
47        runTestOfGetOAuth2AccessTokenWithTimeout(authToken);
48    }
49 
50    private void runTestOfGetOAuth2AccessTokenWithTimeout(String expectedToken) {
51        String scope = "http://example.com/scope";
52        Account account = AccountManagerHelper.createAccountFromName("test@gmail.com");
53        String oauth2Scope = "oauth2:" + scope;
54 
55        // Add an account with given auth token for the given scope, already accepted auth popup.
56        AccountHolder accountHolder =
57                AccountHolder.create()
58                        .account(account)
59                        .hasBeenAccepted(oauth2Scope, true)
60                        .authToken(oauth2Scope, expectedToken).build();
61        mAccountManager.addAccountHolderExplicitly(accountHolder);
62 
63        String accessToken =
64                AndroidProfileOAuth2TokenServiceHelper.getOAuth2AccessTokenWithTimeout(
65                        mContext, null, account, scope, 5, TimeUnit.SECONDS);
66        assertEquals(expectedToken, accessToken);
67    }
68}

[all classes][org.chromium.chrome.browser.signin]
EMMA 2.0.5312 (C) Vladimir Roubtsov