Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java |
| index 80cef4a5d1bba99c3f779c8a4cec1a2ee316fa56..7827f85b9158c2eef1b143d456e878389e1f3ccf 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java |
| @@ -10,6 +10,7 @@ import android.app.Instrumentation.ActivityResult; |
| import android.content.Intent; |
| import android.content.IntentFilter; |
| import android.content.pm.PackageInfo; |
| +import android.graphics.Bitmap; |
| import android.net.Uri; |
| import android.test.mock.MockPackageManager; |
| import android.test.suitebuilder.annotation.MediumTest; |
| @@ -29,6 +30,7 @@ import org.chromium.chrome.browser.infobar.AppBannerInfoBarAndroid; |
| import org.chromium.chrome.browser.infobar.AppBannerInfoBarDelegateAndroid; |
| import org.chromium.chrome.browser.infobar.InfoBar; |
| import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| +import org.chromium.chrome.browser.webapps.WebappDataStorage; |
| import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| import org.chromium.chrome.test.util.TestHttpServerClient; |
| import org.chromium.chrome.test.util.browser.TabLoadObserver; |
| @@ -118,6 +120,15 @@ public class AppBannerManagerTest extends ChromeTabbedActivityTestBase { |
| } |
| } |
| + private static class TestDataStorageObserver extends WebappDataStorage.Observer { |
| + public Bitmap mSplashImage; |
| + |
| + @Override |
| + public void onUpdateSplashScreenImage(Bitmap image) { |
| + mSplashImage = image; |
| + } |
| + } |
| + |
| private static class InfobarListener implements InfoBarContainer.InfoBarAnimationListener { |
| private boolean mDoneAnimating; |
| @@ -129,6 +140,7 @@ public class AppBannerManagerTest extends ChromeTabbedActivityTestBase { |
| private MockAppDetailsDelegate mDetailsDelegate; |
| private TestPackageManager mPackageManager; |
| + private TestDataStorageObserver mDataStorageObserver; |
| @Override |
| public void startMainActivity() throws InterruptedException { |
| @@ -138,8 +150,10 @@ public class AppBannerManagerTest extends ChromeTabbedActivityTestBase { |
| @Override |
| protected void setUp() throws Exception { |
| mPackageManager = new TestPackageManager(); |
| + mDataStorageObserver = new TestDataStorageObserver(); |
| AppBannerManager.setIsEnabledForTesting(true); |
| AppBannerInfoBarDelegateAndroid.setPackageManagerForTesting(mPackageManager); |
| + WebappDataStorage.setObserverForTests(mDataStorageObserver); |
| super.setUp(); |
| @@ -399,6 +413,64 @@ public class AppBannerManagerTest extends ChromeTabbedActivityTestBase { |
| @SmallTest |
| @Feature({"AppBanners"}) |
| public void testWebAppBannerAppears() throws Exception { |
| + loadWebappPageForTesting(); |
| + assertTrue(waitUntilNoInfoBarsExist()); |
| + |
| + // Indicate a day has passed, then revisit the page to show the banner. |
| + AppBannerManager.setTimeDeltaForTesting(1); |
| + assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| + new TabLoadObserver(getActivity().getActivityTab(), WEB_APP_URL))); |
| + assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + AppBannerManager manager = |
| + getActivity().getActivityTab().getAppBannerManagerForTesting(); |
| + return !manager.isFetcherActiveForTesting(); |
| + } |
| + })); |
| + assertTrue(waitUntilAppBannerInfoBarAppears(WEB_APP_TITLE)); |
| + } |
| + |
| + @SmallTest |
| + @Feature({"AppBanners"}) |
| + public void testWebAppSplashscreen() throws Exception { |
|
gone
2015/09/01 18:33:51
testWebAppSplashImageIsDownloaded
Lalit Maganti
2015/09/01 19:45:52
Done. As well as this I've moved the observer from
|
| + // Set weights such that the banner is shown on the first try. |
| + AppBannerManager.setEngagementWeights(2, 2); |
| + loadWebappPageForTesting(); |
| + |
| + InfoBarContainer container = getActivity().getActivityTab().getInfoBarContainer(); |
|
gone
2015/09/01 18:33:51
This is broken. The InfoBarContainer listener nee
Lalit Maganti
2015/09/01 19:45:52
Theorized on chat that the reason this test was pa
|
| + final InfobarListener listener = new InfobarListener(); |
| + container.setAnimationListener(listener); |
| + assertTrue(waitUntilAppBannerInfoBarAppears(WEB_APP_TITLE)); |
| + assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return listener.mDoneAnimating; |
| + } |
| + })); |
| + |
| + // Click the button to trigger the adding of the shortcut. |
| + InfoBar infobar = container.getInfoBars().get(0); |
| + final Button button = |
| + (Button) infobar.getContentWrapper().findViewById(R.id.button_primary); |
| + TouchCommon.singleClickView(button); |
| + |
| + // Make sure that the splash screen icon was downloaded. |
| + assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return mDataStorageObserver.mSplashImage != null; |
| + } |
| + })); |
| + |
| + // Test the bitmap sizes |
|
gone
2015/09/01 18:33:51
nit: comments are sentences. add a period
Lalit Maganti
2015/09/01 19:45:52
Done.
|
| + int ideal = getActivity().getResources().getDimensionPixelSize( |
|
gone
2015/09/01 18:33:51
nit: idealSize
Lalit Maganti
2015/09/01 19:45:52
Done.
|
| + R.dimen.webapp_splash_image_size); |
| + assertEquals(ideal, mDataStorageObserver.mSplashImage.getWidth()); |
| + assertEquals(ideal, mDataStorageObserver.mSplashImage.getHeight()); |
| + } |
| + |
| + private void loadWebappPageForTesting() throws Exception { |
| // Create a Tab that doesn't have the AppBannerManager enabled. This prevents race |
| // conditions between service worker activation and AppBannerManager getting triggered. |
| // This race condition is a known problem, which is why the specs include wiggle room for |
| @@ -432,20 +504,5 @@ public class AppBannerManagerTest extends ChromeTabbedActivityTestBase { |
| return !manager.isFetcherActiveForTesting(); |
| } |
| })); |
| - assertTrue(waitUntilNoInfoBarsExist()); |
| - |
| - // Indicate a day has passed, then revisit the page to show the banner. |
| - AppBannerManager.setTimeDeltaForTesting(1); |
| - assertTrue(CriteriaHelper.pollForUIThreadCriteria( |
| - new TabLoadObserver(getActivity().getActivityTab(), WEB_APP_URL))); |
| - assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| - @Override |
| - public boolean isSatisfied() { |
| - AppBannerManager manager = |
| - getActivity().getActivityTab().getAppBannerManagerForTesting(); |
| - return !manager.isFetcherActiveForTesting(); |
| - } |
| - })); |
| - assertTrue(waitUntilAppBannerInfoBarAppears(WEB_APP_TITLE)); |
| } |
| } |