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

COVERAGE SUMMARY FOR SOURCE FILE [DelayedSyncControllerTest.java]

nameclass, %method, %block, %line, %
DelayedSyncControllerTest.java100% (3/3)100% (16/16)99%  (176/177)100% (42.8/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DelayedSyncControllerTest$1100% (1/1)100% (2/2)89%  (8/9)92%  (1.8/2)
isSatisfied (): boolean 100% (1/1)83%  (5/6)83%  (0.8/1)
DelayedSyncControllerTest$1 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class DelayedSyncControllerTest100% (1/1)100% (10/10)100% (155/155)100% (38/38)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
DelayedSyncControllerTest (): void 100% (1/1)100% (3/3)100% (2/2)
access$200 (): boolean 100% (1/1)100% (2/2)100% (1/1)
isActivityResumed (): boolean 100% (1/1)100% (7/7)100% (1/1)
sendChromeToBackground (Activity): void 100% (1/1)100% (21/21)100% (5/5)
setUp (): void 100% (1/1)100% (12/12)100% (4/4)
testDelayedSyncRequestsShouldBeTriggeredOnResume (): void 100% (1/1)100% (41/41)100% (9/9)
testManualSyncRequestsShouldAlwaysTriggerSync (): void 100% (1/1)100% (34/34)100% (8/8)
testSyncRequestsShouldTriggerSyncWhenChromeIsInForeground (): void 100% (1/1)100% (15/15)100% (4/4)
testSyncRequestsWhenChromeIsInBackgroundShouldBeDelayed (): void 100% (1/1)100% (16/16)100% (4/4)
     
class DelayedSyncControllerTest$TestDelayedSyncController100% (1/1)100% (4/4)100% (13/13)100% (4/4)
DelayedSyncControllerTest$TestDelayedSyncController (): void 100% (1/1)100% (3/3)100% (1/1)
DelayedSyncControllerTest$TestDelayedSyncController (DelayedSyncControllerTes... 100% (1/1)100% (3/3)100% (1/1)
access$100 (DelayedSyncControllerTest$TestDelayedSyncController): boolean 100% (1/1)100% (3/3)100% (1/1)
requestSyncOnBackgroundThread (Context, Account): void 100% (1/1)100% (4/4)100% (2/2)

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.sync;
6 
7import android.accounts.Account;
8import android.app.Activity;
9import android.content.ContentResolver;
10import android.content.Context;
11import android.content.Intent;
12import android.os.Bundle;
13import android.test.suitebuilder.annotation.SmallTest;
14 
15import com.google.common.annotations.VisibleForTesting;
16 
17import org.chromium.base.ActivityStatus;
18import org.chromium.base.test.util.Feature;
19import org.chromium.chrome.testshell.ChromiumTestShellTestBase;
20import org.chromium.content.browser.test.util.Criteria;
21import org.chromium.content.browser.test.util.CriteriaHelper;
22import org.chromium.sync.signin.AccountManagerHelper;
23 
24public class DelayedSyncControllerTest extends ChromiumTestShellTestBase {
25    private static final Account TEST_ACCOUNT =
26            AccountManagerHelper.createAccountFromName("something@gmail.com");
27    private static final long WAIT_FOR_LAUNCHER_MS = 10 * 1000;
28    private static final long POLL_INTERVAL_MS = 100;
29    private TestDelayedSyncController mController;
30 
31    private static class TestDelayedSyncController extends DelayedSyncController {
32        private boolean mSyncRequested;
33 
34        private TestDelayedSyncController() {}
35 
36        @Override
37        void requestSyncOnBackgroundThread(Context context, Account account) {
38            mSyncRequested = true;
39        }
40    }
41 
42    @Override
43    protected void setUp() throws Exception {
44        super.setUp();
45        mController = new TestDelayedSyncController();
46        launchChromiumTestShellWithBlankPage();
47    }
48 
49    @SmallTest
50    @Feature({"Sync"})
51    public void testManualSyncRequestsShouldAlwaysTriggerSync() throws InterruptedException {
52        // Sync should trigger for manual requests when Chrome is in the foreground.
53        assertTrue(isActivityResumed());
54        Bundle extras = new Bundle();
55        extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
56        assertTrue(mController.shouldPerformSync(getActivity(), extras, TEST_ACCOUNT));
57 
58        // Sync should trigger for manual requests when Chrome is in the background.
59        sendChromeToBackground(getActivity());
60        extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
61        assertTrue(mController.shouldPerformSync(getActivity(), extras, TEST_ACCOUNT));
62    }
63 
64    @SmallTest
65    @Feature({"Sync"})
66    public void testSyncRequestsShouldTriggerSyncWhenChromeIsInForeground() {
67        assertTrue(isActivityResumed());
68        Bundle extras = new Bundle();
69        assertTrue(mController.shouldPerformSync(getActivity(), extras, TEST_ACCOUNT));
70    }
71 
72    @SmallTest
73    @Feature({"Sync"})
74    public void testSyncRequestsWhenChromeIsInBackgroundShouldBeDelayed()
75            throws InterruptedException {
76        sendChromeToBackground(getActivity());
77        Bundle extras = new Bundle();
78        assertFalse(mController.shouldPerformSync(getActivity(), extras, TEST_ACCOUNT));
79    }
80 
81    @SmallTest
82    @Feature({"Sync"})
83    public void testDelayedSyncRequestsShouldBeTriggeredOnResume() throws InterruptedException {
84        // First make sure there are no delayed syncs.
85        mController.clearDelayedSyncs(getActivity());
86        assertFalse(mController.resumeDelayedSyncs(getActivity()));
87        assertFalse(mController.mSyncRequested);
88 
89        // Trying to perform sync when Chrome is in the background should create a delayed sync.
90        sendChromeToBackground(getActivity());
91        Bundle extras = new Bundle();
92        assertFalse(mController.shouldPerformSync(getActivity(), extras, TEST_ACCOUNT));
93 
94        // Make sure the delayed sync can be resumed.
95        assertTrue(mController.resumeDelayedSyncs(getActivity()));
96        assertTrue(mController.mSyncRequested);
97    }
98 
99    @VisibleForTesting
100    static void sendChromeToBackground(Activity activity) throws InterruptedException {
101        Intent intent = new Intent(Intent.ACTION_MAIN);
102        intent.addCategory(Intent.CATEGORY_HOME);
103        activity.startActivity(intent);
104 
105        assertTrue("Activity should have been resumed",
106                CriteriaHelper.pollForCriteria(new Criteria() {
107                    @Override
108                    public boolean isSatisfied() {
109                        return !isActivityResumed();
110                    }
111                }, WAIT_FOR_LAUNCHER_MS, POLL_INTERVAL_MS));
112    }
113 
114    private static boolean isActivityResumed() {
115        return ActivityStatus.getState() == ActivityStatus.RESUMED;
116    }
117}

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