Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java

Issue 2784353002: Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Fix tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
9 import android.support.test.filters.SmallTest; 7 import android.support.test.filters.SmallTest;
10 8
11 import org.junit.After; 9 import org.junit.After;
12 import org.junit.Assert; 10 import org.junit.Assert;
13 import org.junit.Before; 11 import org.junit.Before;
14 import org.junit.Test; 12 import org.junit.Test;
15 import org.junit.runner.RunWith; 13 import org.junit.runner.RunWith;
16 14
17 import org.chromium.base.metrics.RecordHistogram; 15 import org.chromium.base.metrics.RecordHistogram;
18 import org.chromium.base.test.util.AdvancedMockContext;
19 import org.chromium.base.test.util.Feature; 16 import org.chromium.base.test.util.Feature;
20 import org.chromium.base.test.util.RetryOnFailure; 17 import org.chromium.base.test.util.RetryOnFailure;
21 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; 18 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
22 19
23 import java.util.concurrent.ExecutionException; 20 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.Semaphore; 21 import java.util.concurrent.Semaphore;
25 22
26 /** 23 /**
27 * Tests {@link BackgroundSyncLauncher}. 24 * Tests {@link BackgroundSyncLauncher}.
28 */ 25 */
29 @RunWith(ChromeJUnit4ClassRunner.class) 26 @RunWith(ChromeJUnit4ClassRunner.class)
30 public class BackgroundSyncLauncherTest { 27 public class BackgroundSyncLauncherTest {
31 private Context mContext;
32 private BackgroundSyncLauncher mLauncher; 28 private BackgroundSyncLauncher mLauncher;
33 private Boolean mShouldLaunchResult; 29 private Boolean mShouldLaunchResult;
34 30
35 @Before 31 @Before
36 public void setUp() throws Exception { 32 public void setUp() throws Exception {
37 mContext = new AdvancedMockContext(
38 InstrumentationRegistry.getInstrumentation().getTargetContext()) ;
39 BackgroundSyncLauncher.setGCMEnabled(false); 33 BackgroundSyncLauncher.setGCMEnabled(false);
40 RecordHistogram.setDisabledForTests(true); 34 RecordHistogram.setDisabledForTests(true);
41 mLauncher = BackgroundSyncLauncher.create(mContext); 35 mLauncher = BackgroundSyncLauncher.create();
42 // Ensure that the initial task is given enough time to complete. 36 // Ensure that the initial task is given enough time to complete.
43 waitForLaunchBrowserTask(); 37 waitForLaunchBrowserTask();
44 } 38 }
45 39
46 @After 40 @After
47 public void tearDown() throws Exception { 41 public void tearDown() throws Exception {
48 RecordHistogram.setDisabledForTests(false); 42 RecordHistogram.setDisabledForTests(false);
49 } 43 }
50 44
51 private void deleteLauncherInstance() { 45 private void deleteLauncherInstance() {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 @SmallTest 117 @SmallTest
124 @Feature({"BackgroundSync"}) 118 @Feature({"BackgroundSync"})
125 @RetryOnFailure 119 @RetryOnFailure
126 public void testNewLauncherDisablesNextOnline() { 120 public void testNewLauncherDisablesNextOnline() {
127 mLauncher.launchBrowserIfStopped(true, 0); 121 mLauncher.launchBrowserIfStopped(true, 0);
128 waitForLaunchBrowserTask(); 122 waitForLaunchBrowserTask();
129 Assert.assertTrue(shouldLaunchBrowserIfStoppedSync()); 123 Assert.assertTrue(shouldLaunchBrowserIfStoppedSync());
130 124
131 // Simulate restarting the browser by deleting the launcher and creating a new one. 125 // Simulate restarting the browser by deleting the launcher and creating a new one.
132 deleteLauncherInstance(); 126 deleteLauncherInstance();
133 mLauncher = BackgroundSyncLauncher.create(mContext); 127 mLauncher = BackgroundSyncLauncher.create();
134 waitForLaunchBrowserTask(); 128 waitForLaunchBrowserTask();
135 Assert.assertFalse(shouldLaunchBrowserIfStoppedSync()); 129 Assert.assertFalse(shouldLaunchBrowserIfStoppedSync());
136 } 130 }
137 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698