EMMA Coverage Report (generated Tue Aug 20 10:07:21 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%  (179/180)100% (42.8/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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