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

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

Issue 2580523002: Reland "Android: Switch to thread pool executor" (Closed)
Patch Set: Fix creation task. Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
index f26d62d3c819f5fc37b987a914be77e7748e3917..d54d6462de7699caad2a69285584a3f4737ae079 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/BackgroundSyncLauncherTest.java
@@ -13,6 +13,7 @@ import org.chromium.base.test.util.AdvancedMockContext;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
/**
@@ -29,6 +30,8 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
BackgroundSyncLauncher.setGCMEnabled(false);
RecordHistogram.disableForTests();
mLauncher = BackgroundSyncLauncher.create(mContext);
+ // Ensure that the initial task is given enough time to complete.
+ waitForLaunchBrowserTask();
}
private void deleteLauncherInstance() {
@@ -51,7 +54,7 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
}
};
- BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(mContext, callback);
+ BackgroundSyncLauncher.shouldLaunchBrowserIfStopped(callback);
try {
// Wait on the callback to be called.
semaphore.acquire();
@@ -61,6 +64,16 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
return mShouldLaunchResult;
}
+ private void waitForLaunchBrowserTask() {
+ try {
+ mLauncher.mLaunchBrowserIfStoppedTask.get();
+ } catch (InterruptedException e) {
+ fail("Launch task was interrupted");
+ } catch (ExecutionException e) {
+ fail("Launch task had execution exception");
+ }
+ }
+
@SmallTest
@Feature({"BackgroundSync"})
@RetryOnFailure
@@ -81,9 +94,11 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
@RetryOnFailure
public void testSetLaunchWhenNextOnline() {
assertFalse(shouldLaunchBrowserIfStoppedSync());
- mLauncher.launchBrowserIfStopped(mContext, true, 0);
+ mLauncher.launchBrowserIfStopped(true, 0);
+ waitForLaunchBrowserTask();
assertTrue(shouldLaunchBrowserIfStoppedSync());
- mLauncher.launchBrowserIfStopped(mContext, false, 0);
+ mLauncher.launchBrowserIfStopped(false, 0);
+ waitForLaunchBrowserTask();
assertFalse(shouldLaunchBrowserIfStoppedSync());
}
@@ -91,12 +106,14 @@ public class BackgroundSyncLauncherTest extends InstrumentationTestCase {
@Feature({"BackgroundSync"})
@RetryOnFailure
public void testNewLauncherDisablesNextOnline() {
- mLauncher.launchBrowserIfStopped(mContext, true, 0);
+ mLauncher.launchBrowserIfStopped(true, 0);
+ waitForLaunchBrowserTask();
assertTrue(shouldLaunchBrowserIfStoppedSync());
// Simulate restarting the browser by deleting the launcher and creating a new one.
deleteLauncherInstance();
mLauncher = BackgroundSyncLauncher.create(mContext);
+ waitForLaunchBrowserTask();
assertFalse(shouldLaunchBrowserIfStoppedSync());
}
}

Powered by Google App Engine
This is Rietveld 408576698