Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4008)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarTest.java

Issue 2022313002: UI for the Data Saver InfoBar Promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@infobarPromo
Patch Set: dismiss on navigation Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1773ac2b7bea227c06174e4279ac9651ad3637e5 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
@@ -11,6 +11,7 @@ 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 +19,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 +30,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 +46,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.0.0";
private EmbeddedTestServer mTestServer;
private InfoBarTestAnimationListener mListener;
@@ -162,6 +169,219 @@ 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, 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.
+ DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
+ getActivity(), getActivity().getActivityTab().getWebContents(),
+ "http://google.com", false, HttpURLConnection.HTTP_OK);
+ }
+ });
+
+ // InfoBar should not be added since it has already been shown.
+ assertTrue("Wrong infobar count", getInfoBars().isEmpty());
+ }
+
+ /**
+ * 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.
+ // 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, 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.
+ DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
+ getActivity(), getActivity().getActivityTab().getWebContents(),
+ "http://google.com", false, HttpURLConnection.HTTP_OK);
+ }
+ });
+
+ // InfoBar should not be added since the user clicked dismiss.
+ assertTrue("Wrong infobar count", getInfoBars().isEmpty());
+ }
+
+ /**
+ * 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.
+ */
+ @MediumTest
+ @Feature({"Browser", "Main"})
+ public void testDataReductionPromoInfoBarPostM48Install() {
+ 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.
+ 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.
+ DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
+ getActivity(), getActivity().getActivityTab().getWebContents(),
+ "http://google.com", false, HttpURLConnection.HTTP_OK);
+ }
+ });
+
+ // InfoBar should not be added since the fre or second run promo version was not stored and
+ // the package was installed after M48..
+ assertTrue("Wrong infobar count", getInfoBars().isEmpty());
+ }
+
+ /**
+ * 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.
+ */
+ @MediumTest
+ @Feature({"Browser", "Main"})
+ public void testDataReductionPromoInfoBarFreOptOut() {
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // Try to add an infobar.
+ DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
+ getActivity(), getActivity().getActivityTab().getWebContents(),
+ "http://google.com", false, HttpURLConnection.HTTP_OK);
+ }
+ });
+
+ // InfoBar should not be added since the First Run Experience or InfoBar promo hasn't been
+ // shown.
+ assertTrue("Wrong infobar count", getInfoBars().isEmpty());
+
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
+ // Try to add an infobar.
+ DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
+ getActivity(), getActivity().getActivityTab().getWebContents(),
+ "http://google.com", false, HttpURLConnection.HTTP_OK);
+ }
+ });
+
+ // InfoBar should not be added since the First Run Experience or InfoBar promo was just
+ // shown.
+ assertTrue("Wrong infobar count", getInfoBars().isEmpty());
+
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // Fake the First Run Experience or second run promo being shown in the past.
+ // 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();
+ DataReductionPromoUtils.saveFrePromoOptOut(true);
+ // Try to add an infobar.
+ DataReductionPromoInfoBar.maybeLaunchPromoInfoBar(
+ getActivity(), getActivity().getActivityTab().getWebContents(),
+ "http://google.com", false, HttpURLConnection.HTTP_OK);
+ }
+ });
+
+ // InfoBar should not be added since the user opted out on the First Run Experience.
+ assertTrue("Wrong infobar count", getInfoBars().isEmpty());
+ }
+
+ /**
* Verifies the unresponsive renderer notification creates an InfoBar.
*/
@Smoke

Powered by Google App Engine
This is Rietveld 408576698