| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.banners; | 5 package org.chromium.chrome.browser.banners; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.MediumTest; | 7 import android.test.suitebuilder.annotation.MediumTest; |
| 8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
| 9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
| 10 import android.view.View; | 10 import android.view.View; |
| 11 import android.widget.TextView; | 11 import android.widget.TextView; |
| 12 | 12 |
| 13 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.base.test.util.CommandLineFlags; |
| 14 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
| 16 import org.chromium.chrome.ChromeSwitches; |
| 15 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 16 import org.chromium.chrome.browser.Tab; | 18 import org.chromium.chrome.browser.Tab; |
| 17 import org.chromium.chrome.browser.infobar.AnimationHelper; | 19 import org.chromium.chrome.browser.infobar.AnimationHelper; |
| 18 import org.chromium.chrome.browser.infobar.AppBannerInfoBar; | 20 import org.chromium.chrome.browser.infobar.AppBannerInfoBar; |
| 19 import org.chromium.chrome.browser.infobar.InfoBar; | 21 import org.chromium.chrome.browser.infobar.InfoBar; |
| 20 import org.chromium.chrome.browser.infobar.InfoBarContainer; | 22 import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| 21 import org.chromium.chrome.shell.ChromeShellTestBase; | 23 import org.chromium.chrome.shell.ChromeShellTestBase; |
| 22 import org.chromium.chrome.test.util.TestHttpServerClient; | 24 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 23 import org.chromium.chrome.test.util.browser.TabLoadObserver; | 25 import org.chromium.chrome.test.util.browser.TabLoadObserver; |
| 24 import org.chromium.content.browser.test.util.Criteria; | 26 import org.chromium.content.browser.test.util.Criteria; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (!(infobars.get(0) instanceof AppBannerInfoBar)) return false
; | 126 if (!(infobars.get(0) instanceof AppBannerInfoBar)) return false
; |
| 125 | 127 |
| 126 TextView textView = | 128 TextView textView = |
| 127 (TextView) infobars.get(0).getContentWrapper().findViewB
yId(R.id.app_name); | 129 (TextView) infobars.get(0).getContentWrapper().findViewB
yId(R.id.app_name); |
| 128 if (textView == null) return false; | 130 if (textView == null) return false; |
| 129 return TextUtils.equals(textView.getText(), APP_TITLE); | 131 return TextUtils.equals(textView.getText(), APP_TITLE); |
| 130 } | 132 } |
| 131 }); | 133 }); |
| 132 } | 134 } |
| 133 | 135 |
| 136 @CommandLineFlags.Add(ChromeSwitches.ENABLE_APP_INSTALL_ALERTS) |
| 134 @SmallTest | 137 @SmallTest |
| 135 @Feature({"AppBanners"}) | 138 @Feature({"AppBanners"}) |
| 136 public void testBannerAppears() throws Exception { | 139 public void testBannerAppears() throws Exception { |
| 137 // Visit a site that requests a banner. | 140 // Visit a site that requests a banner. |
| 138 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 141 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 139 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); | 142 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); |
| 140 assertTrue(waitUntilAppDetailsRetrieved(1)); | 143 assertTrue(waitUntilAppDetailsRetrieved(1)); |
| 141 assertTrue(waitUntilNoInfoBarsExist()); | 144 assertTrue(waitUntilNoInfoBarsExist()); |
| 142 | 145 |
| 143 // Indicate a day has passed, then revisit the page. | 146 // Indicate a day has passed, then revisit the page. |
| 144 AppBannerManager.setTimeDeltaForTesting(1); | 147 AppBannerManager.setTimeDeltaForTesting(1); |
| 145 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 148 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 146 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); | 149 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); |
| 147 assertTrue(waitUntilAppDetailsRetrieved(2)); | 150 assertTrue(waitUntilAppDetailsRetrieved(2)); |
| 148 assertTrue(waitUntilAppBannerInfoBarAppears()); | 151 assertTrue(waitUntilAppBannerInfoBarAppears()); |
| 149 } | 152 } |
| 150 | 153 |
| 154 @CommandLineFlags.Add(ChromeSwitches.ENABLE_APP_INSTALL_ALERTS) |
| 151 @MediumTest | 155 @MediumTest |
| 152 @Feature({"AppBanners"}) | 156 @Feature({"AppBanners"}) |
| 153 public void testBannerAppearsThenDoesNotAppearAgainForMonths() throws Except
ion { | 157 public void testBannerAppearsThenDoesNotAppearAgainForMonths() throws Except
ion { |
| 154 // Visit a site that requests a banner. | 158 // Visit a site that requests a banner. |
| 155 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 159 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 156 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); | 160 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); |
| 157 assertTrue(waitUntilAppDetailsRetrieved(1)); | 161 assertTrue(waitUntilAppDetailsRetrieved(1)); |
| 158 assertTrue(waitUntilNoInfoBarsExist()); | 162 assertTrue(waitUntilNoInfoBarsExist()); |
| 159 | 163 |
| 160 // Indicate a day has passed, then revisit the page. | 164 // Indicate a day has passed, then revisit the page. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 191 assertTrue(waitUntilAppDetailsRetrieved(6)); | 195 assertTrue(waitUntilAppDetailsRetrieved(6)); |
| 192 assertTrue(waitUntilNoInfoBarsExist()); | 196 assertTrue(waitUntilNoInfoBarsExist()); |
| 193 | 197 |
| 194 AppBannerManager.setTimeDeltaForTesting(62); | 198 AppBannerManager.setTimeDeltaForTesting(62); |
| 195 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 199 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 196 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); | 200 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); |
| 197 assertTrue(waitUntilAppDetailsRetrieved(7)); | 201 assertTrue(waitUntilAppDetailsRetrieved(7)); |
| 198 assertTrue(waitUntilAppBannerInfoBarAppears()); | 202 assertTrue(waitUntilAppBannerInfoBarAppears()); |
| 199 } | 203 } |
| 200 | 204 |
| 205 @CommandLineFlags.Add(ChromeSwitches.ENABLE_APP_INSTALL_ALERTS) |
| 201 @MediumTest | 206 @MediumTest |
| 202 @Feature({"AppBanners"}) | 207 @Feature({"AppBanners"}) |
| 203 public void testBlockedBannerDoesNotAppearAgainForMonths() throws Exception
{ | 208 public void testBlockedBannerDoesNotAppearAgainForMonths() throws Exception
{ |
| 204 // Visit a site that requests a banner. | 209 // Visit a site that requests a banner. |
| 205 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 210 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 206 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); | 211 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); |
| 207 assertTrue(waitUntilAppDetailsRetrieved(1)); | 212 assertTrue(waitUntilAppDetailsRetrieved(1)); |
| 208 assertTrue(waitUntilNoInfoBarsExist()); | 213 assertTrue(waitUntilNoInfoBarsExist()); |
| 209 | 214 |
| 210 // Indicate a day has passed, then revisit the page. | 215 // Indicate a day has passed, then revisit the page. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 assertTrue(waitUntilAppDetailsRetrieved(5)); | 253 assertTrue(waitUntilAppDetailsRetrieved(5)); |
| 249 assertTrue(waitUntilNoInfoBarsExist()); | 254 assertTrue(waitUntilNoInfoBarsExist()); |
| 250 | 255 |
| 251 AppBannerManager.setTimeDeltaForTesting(92); | 256 AppBannerManager.setTimeDeltaForTesting(92); |
| 252 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 257 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 253 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); | 258 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP_URL
))); |
| 254 assertTrue(waitUntilAppDetailsRetrieved(6)); | 259 assertTrue(waitUntilAppDetailsRetrieved(6)); |
| 255 assertTrue(waitUntilAppBannerInfoBarAppears()); | 260 assertTrue(waitUntilAppBannerInfoBarAppears()); |
| 256 } | 261 } |
| 257 | 262 |
| 263 @CommandLineFlags.Add(ChromeSwitches.ENABLE_APP_INSTALL_ALERTS) |
| 258 @MediumTest | 264 @MediumTest |
| 259 @Feature({"AppBanners"}) | 265 @Feature({"AppBanners"}) |
| 260 public void testBitmapFetchersCanOverlapWithoutCrashing() throws Exception { | 266 public void testBitmapFetchersCanOverlapWithoutCrashing() throws Exception { |
| 261 // Visit a site that requests a banner rapidly and repeatedly. | 267 // Visit a site that requests a banner rapidly and repeatedly. |
| 262 for (int i = 1; i <= 10; i++) { | 268 for (int i = 1; i <= 10; i++) { |
| 263 assertTrue(CriteriaHelper.pollForUIThreadCriteria( | 269 assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| 264 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP
_URL))); | 270 new TabLoadObserver(getActivity().getActiveTab(), NATIVE_APP
_URL))); |
| 265 | 271 |
| 266 final Integer iteration = Integer.valueOf(i); | 272 final Integer iteration = Integer.valueOf(i); |
| 267 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { | 273 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 268 @Override | 274 @Override |
| 269 public boolean isSatisfied() { | 275 public boolean isSatisfied() { |
| 270 return mDetailsDelegate.mNumRetrieved == iteration; | 276 return mDetailsDelegate.mNumRetrieved == iteration; |
| 271 } | 277 } |
| 272 })); | 278 })); |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 } | 281 } |
| OLD | NEW |