OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
| 7 import android.content.Context; |
| 8 import android.support.test.InstrumentationRegistry; |
7 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
8 | 10 |
9 import org.junit.After; | 11 import org.junit.After; |
10 import org.junit.Assert; | 12 import org.junit.Assert; |
11 import org.junit.Before; | 13 import org.junit.Before; |
12 import org.junit.Test; | 14 import org.junit.Test; |
13 import org.junit.runner.RunWith; | 15 import org.junit.runner.RunWith; |
14 | 16 |
15 import org.chromium.base.metrics.RecordHistogram; | 17 import org.chromium.base.metrics.RecordHistogram; |
| 18 import org.chromium.base.test.util.AdvancedMockContext; |
16 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
17 import org.chromium.base.test.util.RetryOnFailure; | 20 import org.chromium.base.test.util.RetryOnFailure; |
18 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | 21 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
19 | 22 |
20 import java.util.concurrent.ExecutionException; | 23 import java.util.concurrent.ExecutionException; |
21 import java.util.concurrent.Semaphore; | 24 import java.util.concurrent.Semaphore; |
22 | 25 |
23 /** | 26 /** |
24 * Tests {@link BackgroundSyncLauncher}. | 27 * Tests {@link BackgroundSyncLauncher}. |
25 */ | 28 */ |
26 @RunWith(ChromeJUnit4ClassRunner.class) | 29 @RunWith(ChromeJUnit4ClassRunner.class) |
27 public class BackgroundSyncLauncherTest { | 30 public class BackgroundSyncLauncherTest { |
| 31 private Context mContext; |
28 private BackgroundSyncLauncher mLauncher; | 32 private BackgroundSyncLauncher mLauncher; |
29 private Boolean mShouldLaunchResult; | 33 private Boolean mShouldLaunchResult; |
30 | 34 |
31 @Before | 35 @Before |
32 public void setUp() throws Exception { | 36 public void setUp() throws Exception { |
| 37 mContext = new AdvancedMockContext( |
| 38 InstrumentationRegistry.getInstrumentation().getTargetContext())
; |
33 BackgroundSyncLauncher.setGCMEnabled(false); | 39 BackgroundSyncLauncher.setGCMEnabled(false); |
34 RecordHistogram.setDisabledForTests(true); | 40 RecordHistogram.setDisabledForTests(true); |
35 mLauncher = BackgroundSyncLauncher.create(); | 41 mLauncher = BackgroundSyncLauncher.create(mContext); |
36 // Ensure that the initial task is given enough time to complete. | 42 // Ensure that the initial task is given enough time to complete. |
37 waitForLaunchBrowserTask(); | 43 waitForLaunchBrowserTask(); |
38 } | 44 } |
39 | 45 |
40 @After | 46 @After |
41 public void tearDown() throws Exception { | 47 public void tearDown() throws Exception { |
42 RecordHistogram.setDisabledForTests(false); | 48 RecordHistogram.setDisabledForTests(false); |
43 } | 49 } |
44 | 50 |
45 private void deleteLauncherInstance() { | 51 private void deleteLauncherInstance() { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 @SmallTest | 123 @SmallTest |
118 @Feature({"BackgroundSync"}) | 124 @Feature({"BackgroundSync"}) |
119 @RetryOnFailure | 125 @RetryOnFailure |
120 public void testNewLauncherDisablesNextOnline() { | 126 public void testNewLauncherDisablesNextOnline() { |
121 mLauncher.launchBrowserIfStopped(true, 0); | 127 mLauncher.launchBrowserIfStopped(true, 0); |
122 waitForLaunchBrowserTask(); | 128 waitForLaunchBrowserTask(); |
123 Assert.assertTrue(shouldLaunchBrowserIfStoppedSync()); | 129 Assert.assertTrue(shouldLaunchBrowserIfStoppedSync()); |
124 | 130 |
125 // Simulate restarting the browser by deleting the launcher and creating
a new one. | 131 // Simulate restarting the browser by deleting the launcher and creating
a new one. |
126 deleteLauncherInstance(); | 132 deleteLauncherInstance(); |
127 mLauncher = BackgroundSyncLauncher.create(); | 133 mLauncher = BackgroundSyncLauncher.create(mContext); |
128 waitForLaunchBrowserTask(); | 134 waitForLaunchBrowserTask(); |
129 Assert.assertFalse(shouldLaunchBrowserIfStoppedSync()); | 135 Assert.assertFalse(shouldLaunchBrowserIfStoppedSync()); |
130 } | 136 } |
131 } | 137 } |
OLD | NEW |