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 { ...@@ -111,12 +111,25 @@ public class ProfileSyncService {
return sProfileSyncService; return sProfileSyncService;
} }
/**
* Overrides the initialization for tests. The tests should call resetForTests() at shutdown.
*/
@VisibleForTesting @VisibleForTesting
public static void overrideForTests(ProfileSyncService profileSyncService) { public static void overrideForTests(ProfileSyncService profileSyncService) {
sProfileSyncService = profileSyncService; sProfileSyncService = profileSyncService;
sInitialized = true; 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() { protected ProfileSyncService() {
init(); init();
} }
......
...@@ -82,6 +82,8 @@ public class EnabledStateMonitorTest implements EnabledStateMonitor.Observer { ...@@ -82,6 +82,8 @@ public class EnabledStateMonitorTest implements EnabledStateMonitor.Observer {
public void tearDown() throws Exception { public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
ChromeSigninController.get().setSignedInAccountName(mOriginalSignedInAccountName); ChromeSigninController.get().setSignedInAccountName(mOriginalSignedInAccountName);
// Clear ProfileSyncService in case it was mocked.
ProfileSyncService.resetForTests();
}); });
} }
......
...@@ -12,6 +12,7 @@ import android.content.Intent; ...@@ -12,6 +12,7 @@ import android.content.Intent;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -75,6 +76,11 @@ public class PasswordViewingTypeTest { ...@@ -75,6 +76,11 @@ public class PasswordViewingTypeTest {
mAccountManager.addAccountHolderBlocking(accountHolder.build()); mAccountManager.addAccountHolderBlocking(accountHolder.build());
} }
@After
public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
}
/** /**
* Launches the main preferences. * Launches the main preferences.
*/ */
......
...@@ -59,7 +59,7 @@ public class ClearBrowsingDataPreferencesBasicTest { ...@@ -59,7 +59,7 @@ public class ClearBrowsingDataPreferencesBasicTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
ProfileSyncService.overrideForTests(null); ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
} }
private static class StubProfileSyncService extends ProfileSyncService { private static class StubProfileSyncService extends ProfileSyncService {
......
...@@ -50,7 +50,7 @@ public class PassphraseActivityTest { ...@@ -50,7 +50,7 @@ public class PassphraseActivityTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Clear ProfileSyncService in case it was mocked. // Clear ProfileSyncService in case it was mocked.
ProfileSyncService.overrideForTests(null); ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
} }
/** /**
......
...@@ -142,6 +142,7 @@ public class InvalidationControllerTest { ...@@ -142,6 +142,7 @@ public class InvalidationControllerTest {
@After @After
public void tearDown() { public void tearDown() {
AccountManagerFacade.resetAccountManagerFacadeForTests(); AccountManagerFacade.resetAccountManagerFacadeForTests();
ProfileSyncService.resetForTests();
} }
/** /**
......
...@@ -18,6 +18,7 @@ import android.widget.Button; ...@@ -18,6 +18,7 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -112,6 +113,11 @@ public class SyncCustomizationFragmentTest { ...@@ -112,6 +113,11 @@ public class SyncCustomizationFragmentTest {
mPreferences = null; mPreferences = null;
} }
@After
public void tearDown() throws Exception {
ThreadUtils.runOnUiThreadBlocking(() -> ProfileSyncService.resetForTests());
}
@Test @Test
@SmallTest @SmallTest
@Feature({"Sync"}) @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