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..73c23f3387e392e9e050a85c272f98a32b9dc620 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 |
@@ -18,6 +18,10 @@ 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.PrefServiceBridge; |
+import org.chromium.chrome.browser.preferences.PrefServiceBridge.AboutVersionStrings; |
+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; |
@@ -162,6 +166,177 @@ 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. |
+ DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed("Chrome 51.0.0.0"); |
+ // Add an infobar. |
+ DataReductionPromoInfoBar.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ 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.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ // 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. |
+ DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed("Chrome 51.0.0.0"); |
+ // Add an infobar. |
+ DataReductionPromoInfoBar.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ 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.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ // InfoBar should not be added since the user clicked dismiss. |
+ 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 testDataReductionPromoInfoBarNotDisplayed() { |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ // Try to add an infobar. |
+ DataReductionPromoInfoBar.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ // 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() { |
+ AboutVersionStrings versionStrings = PrefServiceBridge.getInstance() |
+ .getAboutVersionStrings(); |
+ DataReductionPromoUtils |
+ .saveFreOrSecondRunPromoDisplayed(versionStrings.getApplicationVersion()); |
+ // Try to add an infobar. |
+ DataReductionPromoInfoBar.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ // 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. |
+ DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed("Chrome 51.0.0.0"); |
+ DataReductionPromoUtils.saveFrePromoOptOut(true); |
+ // Try to add an infobar. |
+ DataReductionPromoInfoBar.maybeLaunchDataReductionPromoInfoBar( |
+ getActivity(), getActivity().getActivityTab().getWebContents(), |
+ "http://google.com"); |
+ } |
+ }); |
+ |
+ // 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 |