Commit 6f5cbd5e authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Signin][Android] Use AccountManagerTestRule in background sync tests

This CL replaces the static class SigninTestUtil with
AccountManagerTestRule to mock the AccountManagerFacade in
background_sync tests. The latter is simpler and less flaky.

Bug: 1078342
Change-Id: I4754df741cf27b92b0c99fa19f7377d762050396
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2185009Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768867}
parent 799677fb
...@@ -26,7 +26,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -26,7 +26,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.TabTitleObserver; import org.chromium.chrome.test.util.browser.TabTitleObserver;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; import org.chromium.components.signin.test.util.AccountManagerTestRule;
import org.chromium.content_public.browser.test.NativeLibraryTestRule; import org.chromium.content_public.browser.test.NativeLibraryTestRule;
import org.chromium.content_public.browser.test.util.BackgroundSyncNetworkUtils; import org.chromium.content_public.browser.test.util.BackgroundSyncNetworkUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
...@@ -45,13 +45,17 @@ import java.util.concurrent.TimeoutException; ...@@ -45,13 +45,17 @@ import java.util.concurrent.TimeoutException;
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public final class BackgroundSyncTest { public final class BackgroundSyncTest {
@Rule @Rule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule @Rule
public NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule(); public final NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule();
// loadNativeLibraryNoBrowserProcess will access AccountManagerFacade, so we need
// to mock AccountManagerFacade
@Rule
public final AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule();
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
private String mTestPage;
private static final String BACKGROUND_SYNC_TEST_PAGE = private static final String BACKGROUND_SYNC_TEST_PAGE =
"/chrome/test/data/background_sync/background_sync_test.html"; "/chrome/test/data/background_sync/background_sync_test.html";
private static final int TITLE_UPDATE_TIMEOUT_SECONDS = (int) scaleTimeout(10); private static final int TITLE_UPDATE_TIMEOUT_SECONDS = (int) scaleTimeout(10);
...@@ -63,13 +67,9 @@ public final class BackgroundSyncTest { ...@@ -63,13 +67,9 @@ public final class BackgroundSyncTest {
private BackgroundSyncBackgroundTaskScheduler.Observer mSchedulerObserver; private BackgroundSyncBackgroundTaskScheduler.Observer mSchedulerObserver;
@Before @Before
public void setUp() throws InterruptedException { public void setUp() {
addSchedulerObserver(); addSchedulerObserver();
// loadNativeLibraryNoBrowserProcess will access AccountManagerFacade, so it should
// be initialized beforehand.
SigninTestUtil.setUpAuthForTesting();
// This is necessary because our test devices don't have Google Play Services up to date, // This is necessary because our test devices don't have Google Play Services up to date,
// and BackgroundSync requires that. Remove this once https://crbug.com/514449 has been // and BackgroundSync requires that. Remove this once https://crbug.com/514449 has been
// fixed. // fixed.
...@@ -91,7 +91,6 @@ public final class BackgroundSyncTest { ...@@ -91,7 +91,6 @@ public final class BackgroundSyncTest {
@After @After
public void tearDown() { public void tearDown() {
if (mTestServer != null) mTestServer.stopAndDestroyServer(); if (mTestServer != null) mTestServer.stopAndDestroyServer();
SigninTestUtil.tearDownAuthForTesting();
BackgroundSyncBackgroundTaskScheduler.getInstance().removeObserver(mSchedulerObserver); BackgroundSyncBackgroundTaskScheduler.getInstance().removeObserver(mSchedulerObserver);
} }
......
...@@ -28,7 +28,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -28,7 +28,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.TabTitleObserver; import org.chromium.chrome.test.util.browser.TabTitleObserver;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; import org.chromium.components.signin.test.util.AccountManagerTestRule;
import org.chromium.content_public.browser.test.NativeLibraryTestRule; import org.chromium.content_public.browser.test.NativeLibraryTestRule;
import org.chromium.content_public.browser.test.util.BackgroundSyncNetworkUtils; import org.chromium.content_public.browser.test.util.BackgroundSyncNetworkUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
...@@ -53,10 +53,15 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -53,10 +53,15 @@ import java.util.concurrent.atomic.AtomicInteger;
+ "skip_permissions_check_for_testing/true"}) + "skip_permissions_check_for_testing/true"})
public final class PeriodicBackgroundSyncTest { public final class PeriodicBackgroundSyncTest {
@Rule @Rule
public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = public final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
@Rule @Rule
public NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule(); public final NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestRule();
// loadNativeLibraryNoBrowserProcess will access AccountManagerFacade, so we need
// to mock AccountManagerFacade
@Rule
public final AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule();
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
private String mTestPage; private String mTestPage;
...@@ -74,10 +79,6 @@ public final class PeriodicBackgroundSyncTest { ...@@ -74,10 +79,6 @@ public final class PeriodicBackgroundSyncTest {
@Before @Before
public void setUp() throws InterruptedException, TimeoutException { public void setUp() throws InterruptedException, TimeoutException {
// loadNativeLibraryNoBrowserProcess will access AccountManagerFacade, so it should
// be initialized beforehand.
SigninTestUtil.setUpAuthForTesting();
// This is necessary because our test devices don't have Google Play Services up to date, // This is necessary because our test devices don't have Google Play Services up to date,
// and Periodic Background Sync requires that. Remove this once https://crbug.com/514449 has // and Periodic Background Sync requires that. Remove this once https://crbug.com/514449 has
// been fixed. // been fixed.
...@@ -102,7 +103,6 @@ public final class PeriodicBackgroundSyncTest { ...@@ -102,7 +103,6 @@ public final class PeriodicBackgroundSyncTest {
@After @After
public void tearDown() throws TimeoutException { public void tearDown() throws TimeoutException {
if (mTestServer != null) mTestServer.stopAndDestroyServer(); if (mTestServer != null) mTestServer.stopAndDestroyServer();
SigninTestUtil.tearDownAuthForTesting();
BackgroundSyncBackgroundTaskScheduler.getInstance().removeObserver(mSchedulerObserver); BackgroundSyncBackgroundTaskScheduler.getInstance().removeObserver(mSchedulerObserver);
} }
......
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