| Index: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarTest.java
|
| index df4de8145ea5f51f6fba83acecca71b01aec881e..780be40864ba431614a836d5c905bc48033cd26b 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarTest.java
|
| @@ -7,15 +7,8 @@
|
| import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
|
|
|
| import android.content.Context;
|
| -import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.MediumTest;
|
| -
|
| -import org.junit.After;
|
| -import org.junit.Assert;
|
| -import org.junit.Before;
|
| -import org.junit.Rule;
|
| -import org.junit.Test;
|
| -import org.junit.runner.RunWith;
|
| +import android.test.UiThreadTest;
|
|
|
| import org.chromium.base.CommandLine;
|
| import org.chromium.base.ContextUtils;
|
| @@ -31,8 +24,7 @@
|
| import org.chromium.chrome.browser.WebContentsFactory;
|
| import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
|
| import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils;
|
| -import org.chromium.chrome.test.ChromeActivityTestRule;
|
| -import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
|
| import org.chromium.chrome.test.util.InfoBarUtil;
|
| import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil;
|
| @@ -46,14 +38,7 @@
|
| import java.util.concurrent.TimeoutException;
|
|
|
| /** Tests for the InfoBars. */
|
| -@RunWith(ChromeJUnit4ClassRunner.class)
|
| -@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| - ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| -public class InfoBarTest {
|
| - @Rule
|
| - public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| - new ChromeActivityTestRule<>(ChromeActivity.class);
|
| -
|
| +public class InfoBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| private static final long MAX_TIMEOUT = scaleTimeout(2000);
|
| private static final int CHECK_INTERVAL = 500;
|
| private static final String GEOLOCATION_PAGE =
|
| @@ -76,123 +61,123 @@
|
| CriteriaHelper.pollUiThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - List<InfoBar> infobars = mActivityTestRule.getInfoBars();
|
| + List<InfoBar> infobars = getInfoBars();
|
| if (infobars.size() != 1) return false;
|
| return infobars.get(0) instanceof DataReductionPromoInfoBar;
|
| }
|
| });
|
| }
|
|
|
| - @Before
|
| - public void setUp() throws Exception {
|
| - mActivityTestRule.startMainActivityOnBlankPage();
|
| + public InfoBarTest() {
|
| + super(ChromeActivity.class);
|
| + }
|
| +
|
| + @Override
|
| + public void startMainActivity() throws InterruptedException {
|
| + startMainActivityOnBlankPage();
|
| + }
|
| +
|
| + @Override
|
| + protected void setUp() throws Exception {
|
| + super.setUp();
|
|
|
| // Register for animation notifications
|
| CriteriaHelper.pollInstrumentationThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - if (mActivityTestRule.getActivity().getActivityTab() == null) return false;
|
| - if (mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer()
|
| - == null) {
|
| - return false;
|
| - }
|
| + if (getActivity().getActivityTab() == null) return false;
|
| + if (getActivity().getActivityTab().getInfoBarContainer() == null) return false;
|
| return true;
|
| }
|
| });
|
| - InfoBarContainer container =
|
| - mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer();
|
| + InfoBarContainer container = getActivity().getActivityTab().getInfoBarContainer();
|
| mListener = new InfoBarTestAnimationListener();
|
| container.addAnimationListener(mListener);
|
|
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(
|
| - InstrumentationRegistry.getInstrumentation().getContext());
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
|
|
| // Using an AdvancedMockContext allows us to use a fresh in-memory SharedPreference.
|
| - Context context = new AdvancedMockContext(InstrumentationRegistry.getInstrumentation()
|
| - .getTargetContext()
|
| - .getApplicationContext());
|
| + Context context = new AdvancedMockContext(
|
| + getInstrumentation().getTargetContext().getApplicationContext());
|
| ContextUtils.initApplicationContextForTests(context);
|
| }
|
|
|
| - @After
|
| - public void tearDown() throws Exception {
|
| - if (mTestServer != null) {
|
| - mTestServer.stopAndDestroyServer();
|
| - }
|
| + @Override
|
| + protected void tearDown() throws Exception {
|
| + mTestServer.stopAndDestroyServer();
|
| + super.tearDown();
|
| }
|
|
|
| /**
|
| * Verify PopUp InfoBar.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| @DisabledTest(message = "crbug.com/593003")
|
| public void testInfoBarForPopUp() throws InterruptedException, TimeoutException {
|
| - mActivityTestRule.loadUrl(mTestServer.getURL(POPUP_PAGE));
|
| + loadUrl(mTestServer.getURL(POPUP_PAGE));
|
| mListener.addInfoBarAnimationFinished("InfoBar not added");
|
|
|
| - List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| - Assert.assertEquals("Wrong infobar count", 1, infoBars.size());
|
| - Assert.assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| - Assert.assertFalse(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| + List<InfoBar> infoBars = getInfoBars();
|
| + assertEquals("Wrong infobar count", 1, infoBars.size());
|
| + assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| + assertFalse(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| InfoBarUtil.clickPrimaryButton(infoBars.get(0));
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| - Assert.assertEquals("Wrong infobar count", 0, infoBars.size());
|
| + assertEquals("Wrong infobar count", 0, infoBars.size());
|
|
|
| // A second load should not show the infobar.
|
| - mActivityTestRule.loadUrl(mTestServer.getURL(POPUP_PAGE));
|
| + loadUrl(mTestServer.getURL(POPUP_PAGE));
|
| mListener.addInfoBarAnimationFinished("InfoBar added when it should not");
|
| }
|
|
|
| /**
|
| * Verify Geolocation creates an InfoBar.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| @RetryOnFailure
|
| public void testInfoBarForGeolocation() throws InterruptedException, TimeoutException {
|
| LocationSettingsTestUtil.setSystemLocationSettingEnabled(true);
|
| - mActivityTestRule.loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| + loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| mListener.addInfoBarAnimationFinished("InfoBar not added");
|
|
|
| // Make sure it has OK/Cancel buttons.
|
| - List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| - Assert.assertEquals("Wrong infobar count", 1, infoBars.size());
|
| - Assert.assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| - Assert.assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| -
|
| - mActivityTestRule.loadUrl(HELLO_WORLD_URL);
|
| + List<InfoBar> infoBars = getInfoBars();
|
| + assertEquals("Wrong infobar count", 1, infoBars.size());
|
| + assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| + assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| +
|
| + loadUrl(HELLO_WORLD_URL);
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| - Assert.assertTrue("Wrong infobar count", mActivityTestRule.getInfoBars().isEmpty());
|
| + assertTrue("Wrong infobar count", getInfoBars().isEmpty());
|
| }
|
|
|
|
|
| /**
|
| * Verify Geolocation creates an InfoBar and that it's destroyed when navigating back.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Browser"})
|
| @RetryOnFailure
|
| public void testInfoBarForGeolocationDisappearsOnBack()
|
| throws InterruptedException, TimeoutException {
|
| LocationSettingsTestUtil.setSystemLocationSettingEnabled(true);
|
| - mActivityTestRule.loadUrl(HELLO_WORLD_URL);
|
| - mActivityTestRule.loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| + loadUrl(HELLO_WORLD_URL);
|
| + loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| mListener.addInfoBarAnimationFinished("InfoBar not added.");
|
|
|
| - Assert.assertEquals("Wrong infobar count", 1, mActivityTestRule.getInfoBars().size());
|
| + assertEquals("Wrong infobar count", 1, getInfoBars().size());
|
|
|
| // Navigate back and ensure the InfoBar has been removed.
|
| - InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - mActivityTestRule.getActivity().getActivityTab().goBack();
|
| - }
|
| - });
|
| - InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars());
|
| + getInstrumentation().runOnMainSync(
|
| + new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + getActivity().getActivityTab().goBack();
|
| + }
|
| + });
|
| + InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars());
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| }
|
|
|
| @@ -200,7 +185,6 @@
|
| * Verify the Data Reduction Promo infobar is shown and clicking the primary button dismisses
|
| * it.
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("force-fieldtrials=DataCompressionProxyPromoVisibility/Enabled")
|
| @Feature({"Browser", "Main"})
|
| @@ -209,7 +193,7 @@
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - Assert.assertFalse("Data Reduction Proxy enabled",
|
| + assertFalse("Data Reduction Proxy enabled",
|
| DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| // Fake the FRE or second run promo being shown in M51.
|
| DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| @@ -218,18 +202,17 @@
|
| .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION, M51_VERSION)
|
| .apply();
|
| // Add an infobar.
|
| - Assert.assertTrue(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| + assertTrue(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| }
|
| });
|
|
|
| waitUntilDataReductionPromoInfoBarAppears();
|
| - final List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| - Assert.assertTrue("InfoBar does not have primary button",
|
| + final List<InfoBar> infoBars = getInfoBars();
|
| + assertTrue("InfoBar does not have primary button",
|
| InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| - Assert.assertTrue("InfoBar does not have secondary button",
|
| + assertTrue("InfoBar does not have secondary button",
|
| InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
|
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @@ -240,21 +223,20 @@
|
| });
|
|
|
| // The renderer should have been killed and the infobar removed.
|
| - InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars());
|
| -
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - Assert.assertTrue("Data Reduction Proxy not enabled",
|
| + InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars());
|
| +
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + assertTrue("Data Reduction Proxy not enabled",
|
| DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| // Turn Data Saver off so the promo can be reshown.
|
| - DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
|
| - mActivityTestRule.getActivity(), false);
|
| + DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(getActivity(),
|
| + false);
|
| // Try to add an infobar. Infobar should not be added since it has already been
|
| // shown.
|
| - Assert.assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| }
|
| });
|
| @@ -264,7 +246,6 @@
|
| * Verify the Data Reduction Promo infobar is shown and clicking the secondary button dismisses
|
| * it.
|
| */
|
| - @Test
|
| @MediumTest
|
| @CommandLineFlags.Add("force-fieldtrials=DataCompressionProxyPromoVisibility/Enabled")
|
| @Feature({"Browser", "Main"})
|
| @@ -273,7 +254,7 @@
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - Assert.assertFalse("Data Reduction Proxy enabled",
|
| + assertFalse("Data Reduction Proxy enabled",
|
| DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| // Fake the first run experience or second run promo being shown in M51.
|
| DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| @@ -282,18 +263,17 @@
|
| .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION, M51_VERSION)
|
| .apply();
|
| // Add an infobar.
|
| - Assert.assertTrue(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| + assertTrue(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| }
|
| });
|
|
|
| waitUntilDataReductionPromoInfoBarAppears();
|
| - final List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| - Assert.assertTrue("InfoBar does not have primary button",
|
| + final List<InfoBar> infoBars = getInfoBars();
|
| + assertTrue("InfoBar does not have primary button",
|
| InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| - Assert.assertTrue("InfoBar does not have secondary button",
|
| + assertTrue("InfoBar does not have secondary button",
|
| InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
|
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @@ -304,18 +284,17 @@
|
| });
|
|
|
| // The renderer should have been killed and the infobar removed.
|
| - InfoBarUtil.waitUntilNoInfoBarsExist(mActivityTestRule.getInfoBars());
|
| -
|
| - ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - Assert.assertFalse("Data Reduction Proxy enabled",
|
| + InfoBarUtil.waitUntilNoInfoBarsExist(getInfoBars());
|
| +
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + assertFalse("Data Reduction Proxy enabled",
|
| DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| // Try to add an infobar. Infobar should not be added since the user clicked
|
| // dismiss.
|
| - Assert.assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| }
|
| });
|
| @@ -325,98 +304,82 @@
|
| * Verify the Data Reduction Promo infobar is not shown when the fre or second run promo version
|
| * was not stored and the package was installed after M48.
|
| */
|
| - @Test
|
| + @UiThreadTest
|
| @MediumTest
|
| @CommandLineFlags.Add("force-fieldtrials=DataCompressionProxyPromoVisibility/Enabled")
|
| @Feature({"Browser", "Main"})
|
| - public void testDataReductionPromoInfoBarPostM48Install() throws Throwable {
|
| - mActivityTestRule.runOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - Assert.assertFalse("Data Reduction Proxy enabled",
|
| - DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| - // Fake the first run experience or second run promo being shown.
|
| - DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| - // Remove the version. Versions prior to M51 will not have the version pref.
|
| - ContextUtils.getAppSharedPreferences()
|
| - .edit()
|
| - .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION, "")
|
| - .apply();
|
| - // Add an infobar. Infobar should not be added since the first run experience
|
| - // or second run promo version was not shown and the package was installed
|
| - // after M48.
|
| - Assert.assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| - "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| - }
|
| - });
|
| + public void testDataReductionPromoInfoBarPostM48Install() {
|
| + assertFalse("Data Reduction Proxy enabled",
|
| + DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| + // Fake the first run experience or second run promo being shown.
|
| + DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| + // Remove the version. Versions prior to M51 will not have the version pref.
|
| + ContextUtils.getAppSharedPreferences()
|
| + .edit()
|
| + .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION, "")
|
| + .apply();
|
| + // Add an infobar. Infobar should not be added since the first run experience or second run
|
| + // promo version was not shown and the package was installed after M48.
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| }
|
|
|
| /**
|
| * Verify that the Data Reduction Promo infobar is not shown if the first run experience or
|
| * Infobar promo hasn't been shown or if it hasn't been two versions since the promo was shown.
|
| */
|
| - @Test
|
| + @UiThreadTest
|
| @MediumTest
|
| @CommandLineFlags.Add("force-fieldtrials=DataCompressionProxyPromoVisibility/Enabled")
|
| @Feature({"Browser", "Main"})
|
| @RetryOnFailure
|
| - public void testDataReductionPromoInfoBarFreOptOut() throws Throwable {
|
| - mActivityTestRule.runOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - // Try to add an infobar. Infobar should not be added since the first run
|
| - // experience or second run promo hasn't been shown.
|
| - Assert.assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| - "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| -
|
| - // Fake showing the FRE.
|
| - DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| -
|
| - // Try to add an infobar. Infobar should not be added since the
|
| - // first run experience was just shown.
|
| - Assert.assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| - "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| -
|
| - // Fake the first run experience or second run promo being shown in M51.
|
| - DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| - ContextUtils.getAppSharedPreferences()
|
| - .edit()
|
| - .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION, M51_VERSION)
|
| - .apply();
|
| - DataReductionPromoUtils.saveFrePromoOptOut(true);
|
| -
|
| - // Try to add an infobar. Infobar should not be added since the user opted
|
| - // out on the first run experience.
|
| - Assert.assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| - mActivityTestRule.getActivity(),
|
| - mActivityTestRule.getActivity().getActivityTab().getWebContents(),
|
| - "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| - }
|
| - });
|
| + public void testDataReductionPromoInfoBarFreOptOut() {
|
| + // Try to add an infobar. Infobar should not be added since the first run experience or
|
| + // second run promo hasn't been shown.
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| +
|
| + // Fake showing the FRE.
|
| + DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| +
|
| + // Try to add an infobar. Infobar should not be added since the first run experience was
|
| + // just shown.
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| +
|
| + // Fake the first run experience or second run promo being shown in M51.
|
| + DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
|
| + ContextUtils.getAppSharedPreferences()
|
| + .edit()
|
| + .putString(SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION, M51_VERSION)
|
| + .apply();
|
| + DataReductionPromoUtils.saveFrePromoOptOut(true);
|
| +
|
| + // Try to add an infobar. Infobar should not be added since the user opted out on the
|
| + // first run experience.
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| }
|
|
|
| /**
|
| * Verifies the unresponsive renderer notification creates an InfoBar.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| @RetryOnFailure
|
| public void testInfoBarForHungRenderer() throws InterruptedException, TimeoutException {
|
| - mActivityTestRule.loadUrl(HELLO_WORLD_URL);
|
| + loadUrl(HELLO_WORLD_URL);
|
|
|
| // Fake an unresponsive renderer signal.
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_HUNG_RENDERER_INFOBAR);
|
| - mActivityTestRule.getActivity()
|
| + getActivity()
|
| .getActivityTab()
|
| .getTabWebContentsDelegateAndroid()
|
| .rendererUnresponsive();
|
| @@ -425,42 +388,41 @@
|
| mListener.addInfoBarAnimationFinished("InfoBar not added");
|
|
|
| // Make sure it has Kill/Wait buttons.
|
| - List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| - Assert.assertEquals("Wrong infobar count", 1, infoBars.size());
|
| - Assert.assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| - Assert.assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| + List<InfoBar> infoBars = getInfoBars();
|
| + assertEquals("Wrong infobar count", 1, infoBars.size());
|
| + assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| + assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
|
|
| // Fake a responsive renderer signal.
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - mActivityTestRule.getActivity()
|
| + getActivity()
|
| .getActivityTab()
|
| .getTabWebContentsDelegateAndroid()
|
| .rendererResponsive();
|
| }
|
| });
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| - Assert.assertTrue("Wrong infobar count", mActivityTestRule.getInfoBars().isEmpty());
|
| + assertTrue("Wrong infobar count", getInfoBars().isEmpty());
|
| }
|
|
|
| /**
|
| * Verifies the hung renderer InfoBar can kill the hung renderer.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| @RetryOnFailure
|
| public void testInfoBarForHungRendererCanKillRenderer()
|
| throws InterruptedException, TimeoutException {
|
| - mActivityTestRule.loadUrl(HELLO_WORLD_URL);
|
| + loadUrl(HELLO_WORLD_URL);
|
|
|
| // Fake an unresponsive renderer signal.
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_HUNG_RENDERER_INFOBAR);
|
| - mActivityTestRule.getActivity()
|
| + getActivity()
|
| .getActivityTab()
|
| .getTabWebContentsDelegateAndroid()
|
| .rendererUnresponsive();
|
| @@ -469,10 +431,10 @@
|
| mListener.addInfoBarAnimationFinished("InfoBar not added");
|
|
|
| // Make sure it has Kill/Wait buttons.
|
| - final List<InfoBar> infoBars = mActivityTestRule.getInfoBars();
|
| - Assert.assertEquals("Wrong infobar count", 1, infoBars.size());
|
| - Assert.assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| - Assert.assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| + final List<InfoBar> infoBars = getInfoBars();
|
| + assertEquals("Wrong infobar count", 1, infoBars.size());
|
| + assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| + assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
|
|
| // Activite the Kill button.
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @@ -484,11 +446,11 @@
|
|
|
| // The renderer should have been killed and the InfoBar removed.
|
| mListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| - Assert.assertTrue("Wrong infobar count", mActivityTestRule.getInfoBars().isEmpty());
|
| + assertTrue("Wrong infobar count", getInfoBars().isEmpty());
|
| CriteriaHelper.pollInstrumentationThread(new Criteria() {
|
| @Override
|
| public boolean isSatisfied() {
|
| - return mActivityTestRule.getActivity().getActivityTab().isShowingSadTab();
|
| + return getActivity().getActivityTab().isShowingSadTab();
|
| }
|
| }, MAX_TIMEOUT, CHECK_INTERVAL);
|
| }
|
| @@ -496,7 +458,6 @@
|
| /**
|
| * Verify InfoBarContainers swap the WebContents they are monitoring properly.
|
| */
|
| - @Test
|
| @MediumTest
|
| @Feature({"Browser", "Main"})
|
| @RetryOnFailure
|
| @@ -504,32 +465,29 @@
|
| throws InterruptedException, TimeoutException {
|
| // Add an infobar.
|
| LocationSettingsTestUtil.setSystemLocationSettingEnabled(true);
|
| - mActivityTestRule.loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| + loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| mListener.addInfoBarAnimationFinished("InfoBar not added");
|
| - Assert.assertEquals("Wrong infobar count", 1, mActivityTestRule.getInfoBars().size());
|
| + assertEquals("Wrong infobar count", 1, getInfoBars().size());
|
|
|
| // Swap out the WebContents and send the user somewhere so that the InfoBar gets removed.
|
| InfoBarTestAnimationListener removeListener = new InfoBarTestAnimationListener();
|
| - mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer().addAnimationListener(
|
| - removeListener);
|
| + getActivity().getActivityTab().getInfoBarContainer().addAnimationListener(removeListener);
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| WebContents newContents = WebContentsFactory.createWebContents(false, false);
|
| - mActivityTestRule.getActivity().getActivityTab().swapWebContents(
|
| - newContents, false, false);
|
| - }
|
| - });
|
| - mActivityTestRule.loadUrl(HELLO_WORLD_URL);
|
| + getActivity().getActivityTab().swapWebContents(newContents, false, false);
|
| + }
|
| + });
|
| + loadUrl(HELLO_WORLD_URL);
|
| removeListener.removeInfoBarAnimationFinished("InfoBar not removed.");
|
| - Assert.assertEquals("Wrong infobar count", 0, mActivityTestRule.getInfoBars().size());
|
| + assertEquals("Wrong infobar count", 0, getInfoBars().size());
|
|
|
| // Revisiting the original page should make the InfoBar reappear.
|
| InfoBarTestAnimationListener addListener = new InfoBarTestAnimationListener();
|
| - mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer().addAnimationListener(
|
| - addListener);
|
| - mActivityTestRule.loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| + getActivity().getActivityTab().getInfoBarContainer().addAnimationListener(addListener);
|
| + loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
|
| addListener.addInfoBarAnimationFinished("InfoBar not added");
|
| - Assert.assertEquals("Wrong infobar count", 1, mActivityTestRule.getInfoBars().size());
|
| + assertEquals("Wrong infobar count", 1, getInfoBars().size());
|
| }
|
| }
|
|
|