| 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 9046e22250a85ec21a41082eed1921272f877630..ecddfcd408349634ebf4e817f1bba0ecf8a6eae8 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,10 +7,12 @@ package org.chromium.chrome.browser.infobar;
|
| import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
|
|
|
| import android.os.Environment;
|
| +import android.test.UiThreadTest;
|
| import android.test.suitebuilder.annotation.MediumTest;
|
| import android.test.suitebuilder.annotation.Smoke;
|
|
|
| import org.chromium.base.CommandLine;
|
| +import org.chromium.base.ContextUtils;
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.DisabledTest;
|
| import org.chromium.base.test.util.Feature;
|
| @@ -18,6 +20,8 @@ import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.chrome.browser.ChromeActivity;
|
| import org.chromium.chrome.browser.ChromeSwitches;
|
| 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.ChromeActivityTestCaseBase;
|
| import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
|
| import org.chromium.chrome.test.util.InfoBarUtil;
|
| @@ -27,6 +31,7 @@ import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content_public.browser.WebContents;
|
| import org.chromium.net.test.EmbeddedTestServer;
|
|
|
| +import java.net.HttpURLConnection;
|
| import java.util.List;
|
|
|
| /** Tests for the InfoBars. */
|
| @@ -42,6 +47,9 @@ public class InfoBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| + "<head><title>Hello, World!</title></head>"
|
| + "<body>Hello, World!</body>"
|
| + "</html>");
|
| + private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSION =
|
| + "displayed_data_reduction_promo_version";
|
| + private static final String M51_VERSION = "Chrome 51.0.2704.0";
|
|
|
| private EmbeddedTestServer mTestServer;
|
| private InfoBarTestAnimationListener mListener;
|
| @@ -162,6 +170,187 @@ public class InfoBarTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }
|
|
|
| /**
|
| + * Verify the Data Reduction Promo infobar is shown and clicking the primary button dismisses
|
| + * it.
|
| + */
|
| + @MediumTest
|
| + @Feature({"Browser", "Main"})
|
| + public void testDataReductionPromoInfoBar() throws InterruptedException {
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + assertFalse("Data Reduction Proxy enabled",
|
| + DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| + // Fake the FRE 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();
|
| + // Add an infobar.
|
| + DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK);
|
| + }
|
| + });
|
| +
|
| + assertTrue("InfoBar not added", mListener.addInfoBarAnimationFinished());
|
| + final List<InfoBar> infoBars = getInfoBars();
|
| + assertEquals("Wrong infobar count", 1, infoBars.size());
|
| + assertTrue("InfoBar does not have primary button",
|
| + InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| + assertTrue("InfoBar does not have secondary button",
|
| + InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| +
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + InfoBarUtil.clickPrimaryButton(infoBars.get(0));
|
| + }
|
| + });
|
| +
|
| + // The renderer should have been killed and the infobar removed.
|
| + assertTrue("InfoBar not removed.", mListener.removeInfoBarAnimationFinished());
|
| + assertTrue("Wrong infobar count", getInfoBars().isEmpty());
|
| +
|
| + ThreadUtils.runOnUiThread(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(getActivity(),
|
| + false);
|
| + // Try to add an infobar. Infobar should not be added since it has already been
|
| + // shown.
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Verify the Data Reduction Promo infobar is shown and clicking the secondary button dismisses
|
| + * it.
|
| + */
|
| + @MediumTest
|
| + @Feature({"Browser", "Main"})
|
| + public void testDataReductionPromoInfoBarDismissed() throws InterruptedException {
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + assertFalse("Data Reduction Proxy enabled",
|
| + DataReductionProxySettings.getInstance().isDataReductionProxyEnabled());
|
| + // 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();
|
| + // Add an infobar.
|
| + DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK);
|
| + }
|
| + });
|
| +
|
| + assertTrue("InfoBar not added", mListener.addInfoBarAnimationFinished());
|
| + final List<InfoBar> infoBars = getInfoBars();
|
| + assertEquals("Wrong infobar count", 1, infoBars.size());
|
| + assertTrue("InfoBar does not have primary button",
|
| + InfoBarUtil.hasPrimaryButton(infoBars.get(0)));
|
| + assertTrue("InfoBar does not have secondary button",
|
| + InfoBarUtil.hasSecondaryButton(infoBars.get(0)));
|
| +
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + InfoBarUtil.clickSecondaryButton(infoBars.get(0));
|
| + }
|
| + });
|
| +
|
| + // The renderer should have been killed and the infobar removed.
|
| + assertTrue("InfoBar not removed.", mListener.removeInfoBarAnimationFinished());
|
| + assertTrue("Wrong infobar count", getInfoBars().isEmpty());
|
| +
|
| + ThreadUtils.runOnUiThread(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.
|
| + assertFalse(DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
|
| + getActivity(), getActivity().getActivityTab().getWebContents(),
|
| + "http://google.com", false, false, HttpURLConnection.HTTP_OK));
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * 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.
|
| + */
|
| + @UiThreadTest
|
| + @MediumTest
|
| + @Feature({"Browser", "Main"})
|
| + 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.
|
| + */
|
| + @UiThreadTest
|
| + @MediumTest
|
| + @Feature({"Browser", "Main"})
|
| + 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.
|
| */
|
| @Smoke
|
|
|