Commit c9e59fd5 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

Add render tests for SyncErrorInfoBar

This cl adds render tests for the 3 types of SyncErrorInfoBar currently
available.

Bug: 1031632
Change-Id: Idf8ad0d7856f10f6701207789db518a5aa68b99a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083307Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748206}
parent bfa8dd87
...@@ -37,10 +37,10 @@ public class SyncErrorInfoBar ...@@ -37,10 +37,10 @@ public class SyncErrorInfoBar
extends ConfirmInfoBar implements ProfileSyncService.SyncStateChangedListener { extends ConfirmInfoBar implements ProfileSyncService.SyncStateChangedListener {
// Preference key to save the latest time this infobar is viewed. // Preference key to save the latest time this infobar is viewed.
@VisibleForTesting @VisibleForTesting
public static final String PREF_SYNC_ERROR_INFOBAR_SHOWN_AT_TIME = static final String PREF_SYNC_ERROR_INFOBAR_SHOWN_AT_TIME =
"sync_error_infobar_shown_shown_at_time"; "sync_error_infobar_shown_shown_at_time";
@VisibleForTesting @VisibleForTesting
public static final long MINIMAL_DURATION_BETWEEN_INFOBARS_MS = static final long MINIMAL_DURATION_BETWEEN_INFOBARS_MS =
TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS); TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
@IntDef({SyncErrorInfoBarType.NOT_SHOWN, SyncErrorInfoBarType.AUTH_ERROR, @IntDef({SyncErrorInfoBarType.NOT_SHOWN, SyncErrorInfoBarType.AUTH_ERROR,
......
...@@ -14,21 +14,25 @@ import org.junit.runner.RunWith; ...@@ -14,21 +14,25 @@ import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.SyncFirstSetupCompleteSource; import org.chromium.chrome.browser.SyncFirstSetupCompleteSource;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.sync.FakeProfileSyncService; import org.chromium.chrome.browser.sync.FakeProfileSyncService;
import org.chromium.chrome.browser.sync.GoogleServiceAuthError; import org.chromium.chrome.browser.sync.GoogleServiceAuthError;
import org.chromium.chrome.browser.sync.SyncTestRule; import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils; import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils;
import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils.SyncError; import org.chromium.chrome.browser.sync.settings.SyncSettingsUtils.SyncError;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.InfoBarUtil; import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import java.io.IOException;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags @CommandLineFlags
.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) .Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
...@@ -37,13 +41,16 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -37,13 +41,16 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
private FakeProfileSyncService mFakeProfileSyncService; private FakeProfileSyncService mFakeProfileSyncService;
@Rule @Rule
public SyncTestRule mSyncTestRule = new SyncTestRule() { public final SyncTestRule mSyncTestRule = new SyncTestRule() {
@Override @Override
protected FakeProfileSyncService createProfileSyncService() { protected FakeProfileSyncService createProfileSyncService() {
return new FakeProfileSyncService(); return new FakeProfileSyncService();
} }
}; };
@Rule
public final ChromeRenderTestRule mRenderTestRule = new ChromeRenderTestRule();
@Before @Before
public void setUp() { public void setUp() {
deleteSyncErrorInfoBarShowTimePref(); deleteSyncErrorInfoBarShowTimePref();
...@@ -56,12 +63,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -56,12 +63,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
public void testSyncErrorInfoBarShownForAuthError() throws Exception { public void testSyncErrorInfoBarShownForAuthError() throws Exception {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mSyncTestRule.getInfoBars().size());
mSyncTestRule.setUpTestAccountAndSignIn(); showSyncErrorInfoBarForAuthError();
TestThreadUtils.runOnUiThreadBlocking(() -> {
mFakeProfileSyncService.setAuthError(
GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
});
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size());
// Resolving the error should not show the infobar again. // Resolving the error should not show the infobar again.
...@@ -76,8 +78,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -76,8 +78,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
public void testSyncErrorInfoBarShownForSyncSetupIncomplete() { public void testSyncErrorInfoBarShownForSyncSetupIncomplete() {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mSyncTestRule.getInfoBars().size());
mSyncTestRule.setUpTestAccountAndSignInWithSyncSetupAsIncomplete(); showSyncErrorInfoBarForSyncSetupIncomplete();
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size());
// Resolving the error should not show the infobar again. // Resolving the error should not show the infobar again.
...@@ -94,15 +95,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -94,15 +95,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
public void testSyncErrorInfoBarShownForPassphraseRequired() { public void testSyncErrorInfoBarShownForPassphraseRequired() {
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mSyncTestRule.getInfoBars().size());
mSyncTestRule.setUpTestAccountAndSignIn(); showSyncErrorInfoBarForPassphraseRequired();
TestThreadUtils.runOnUiThreadBlocking(() -> {
// TODO(https://crbug.com/1056677): call syncStateChanged inside
// setPassphraseRequiredForPreferredDataTypes
mFakeProfileSyncService.setEngineInitialized(true);
mFakeProfileSyncService.setPassphraseRequiredForPreferredDataTypes(true);
mFakeProfileSyncService.syncStateChanged();
});
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size());
// Resolving the error should not show the infobar again. // Resolving the error should not show the infobar again.
...@@ -146,12 +139,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -146,12 +139,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
// Initiate auth error to show the infobar. // Initiate auth error to show the infobar.
Assert.assertEquals("InfoBar should not be shown before signing in", 0, Assert.assertEquals("InfoBar should not be shown before signing in", 0,
mSyncTestRule.getInfoBars().size()); mSyncTestRule.getInfoBars().size());
mSyncTestRule.setUpTestAccountAndSignIn(); showSyncErrorInfoBarForAuthError();
TestThreadUtils.runOnUiThreadBlocking(() -> {
mFakeProfileSyncService.setAuthError(
GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
});
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size()); Assert.assertEquals("InfoBar should be shown", 1, mSyncTestRule.getInfoBars().size());
// Create another new tab. // Create another new tab.
...@@ -171,6 +159,59 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -171,6 +159,59 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
mSyncTestRule.getInfoBars().size()); mSyncTestRule.getInfoBars().size());
} }
@Test
@LargeTest
@Feature("RenderTest")
public void testSyncErrorInfoBarForAuthErrorView() throws IOException {
showSyncErrorInfoBarForAuthError();
mRenderTestRule.render(mSyncTestRule.getInfoBarContainer().getContainerViewForTesting(),
"sync_error_infobar_auth_error");
}
@Test
@LargeTest
@Feature("RenderTest")
public void testSyncErrorInfoBarForSyncSetupIncompleteView() throws IOException {
showSyncErrorInfoBarForSyncSetupIncomplete();
mRenderTestRule.render(mSyncTestRule.getInfoBarContainer().getContainerViewForTesting(),
"sync_error_infobar_sync_setup_incomplete");
}
@Test
@LargeTest
@Feature("RenderTest")
public void testSyncErrorInfoBarForPassphraseRequiredView() throws IOException {
showSyncErrorInfoBarForPassphraseRequired();
mRenderTestRule.render(mSyncTestRule.getInfoBarContainer().getContainerViewForTesting(),
"sync_error_infobar_passphrase_required");
}
private void showSyncErrorInfoBarForAuthError() {
mSyncTestRule.setUpTestAccountAndSignIn();
TestThreadUtils.runOnUiThreadBlocking(() -> {
mFakeProfileSyncService.setAuthError(
GoogleServiceAuthError.State.INVALID_GAIA_CREDENTIALS);
});
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
}
private void showSyncErrorInfoBarForPassphraseRequired() {
mSyncTestRule.setUpTestAccountAndSignIn();
TestThreadUtils.runOnUiThreadBlocking(() -> {
// TODO(https://crbug.com/1056677): call syncStateChanged inside
// setPassphraseRequiredForPreferredDataTypes
mFakeProfileSyncService.setEngineInitialized(true);
mFakeProfileSyncService.setPassphraseRequiredForPreferredDataTypes(true);
mFakeProfileSyncService.syncStateChanged();
});
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
}
private void showSyncErrorInfoBarForSyncSetupIncomplete() {
mSyncTestRule.setUpTestAccountAndSignInWithSyncSetupAsIncomplete();
mSyncTestRule.loadUrlInNewTab(UrlConstants.CHROME_BLANK_URL);
}
private void deleteSyncErrorInfoBarShowTimePref() { private void deleteSyncErrorInfoBarShowTimePref() {
ContextUtils.getAppSharedPreferences() ContextUtils.getAppSharedPreferences()
.edit() .edit()
......
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