Commit 2a7a4fdc authored by Siddhartha's avatar Siddhartha Committed by Commit Bot

Fix ClearBrowsingDataPreferencesBasicTest

The test fails at shutdown because of
contextual_suggestions.EnabledStateMonitor trying to access the
ProfileSyncService at shutdown. So, restore the original service at
tearDown.

Change-Id: I02e7f14caf44ed9c0d4dc5a70d0f353a4428e34f
Reviewed-on: https://chromium-review.googlesource.com/1170311
Commit-Queue: Siddhartha S <ssid@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583300}
parent ab2d8581
......@@ -111,12 +111,25 @@ public class ProfileSyncService {
return sProfileSyncService;
}
/**
* Overrides the initialization for tests. The tests should call resetForTests() at shutdown.
*/
@VisibleForTesting
public static void overrideForTests(ProfileSyncService profileSyncService) {
sProfileSyncService = profileSyncService;
sInitialized = true;
}
/**
* Resets the ProfileSyncService instance. Calling get() next time will initialize with a new
* instance.
*/
@VisibleForTesting
public static void resetForTests() {
sInitialized = false;
sProfileSyncService = null;
}
protected ProfileSyncService() {
init();
}
......
......@@ -82,6 +82,8 @@ public class EnabledStateMonitorTest implements EnabledStateMonitor.Observer {
public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> {
ChromeSigninController.get().setSignedInAccountName(mOriginalSignedInAccountName);
// Clear ProfileSyncService in case it was mocked.
ProfileSyncService.resetForTests();
});
}
......
......@@ -12,6 +12,7 @@ import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -75,6 +76,11 @@ public class PasswordViewingTypeTest {
mAccountManager.addAccountHolderBlocking(accountHolder.build());
}
@After
public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
}
/**
* Launches the main preferences.
*/
......
......@@ -59,7 +59,7 @@ public class ClearBrowsingDataPreferencesBasicTest {
@After
public void tearDown() throws Exception {
ProfileSyncService.overrideForTests(null);
ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
}
private static class StubProfileSyncService extends ProfileSyncService {
......
......@@ -50,7 +50,7 @@ public class PassphraseActivityTest {
@After
public void tearDown() throws Exception {
// Clear ProfileSyncService in case it was mocked.
ProfileSyncService.overrideForTests(null);
ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
}
/**
......
......@@ -142,6 +142,7 @@ public class InvalidationControllerTest {
@After
public void tearDown() {
AccountManagerFacade.resetAccountManagerFacadeForTests();
ProfileSyncService.resetForTests();
}
/**
......
......@@ -18,6 +18,7 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -112,6 +113,11 @@ public class SyncCustomizationFragmentTest {
mPreferences = null;
}
@After
public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
}
@Test
@SmallTest
@Feature({"Sync"})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment