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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java

Issue 2778983005: Allow the app banner installability check to run on page load. (Closed)
Patch Set: Address comments Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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.app.Activity; 7 import android.app.Activity;
8 import android.app.Instrumentation.ActivityMonitor; 8 import android.app.Instrumentation.ActivityMonitor;
9 import android.app.Instrumentation.ActivityResult; 9 import android.app.Instrumentation.ActivityResult;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.content.IntentFilter; 11 import android.content.IntentFilter;
12 import android.content.pm.PackageInfo; 12 import android.content.pm.PackageInfo;
13 import android.content.pm.PackageManager; 13 import android.content.pm.PackageManager;
14 import android.graphics.Bitmap; 14 import android.graphics.Bitmap;
15 import android.support.test.filters.MediumTest; 15 import android.support.test.filters.MediumTest;
16 import android.support.test.filters.SmallTest; 16 import android.support.test.filters.SmallTest;
17 import android.test.mock.MockPackageManager; 17 import android.test.mock.MockPackageManager;
18 import android.text.TextUtils; 18 import android.text.TextUtils;
19 import android.view.View; 19 import android.view.View;
20 import android.widget.Button; 20 import android.widget.Button;
21 import android.widget.TextView; 21 import android.widget.TextView;
22 22
23 import org.chromium.base.ThreadUtils; 23 import org.chromium.base.ThreadUtils;
24 import org.chromium.base.metrics.RecordHistogram;
24 import org.chromium.base.test.util.Feature; 25 import org.chromium.base.test.util.Feature;
25 import org.chromium.chrome.R; 26 import org.chromium.chrome.R;
26 import org.chromium.chrome.browser.ShortcutHelper; 27 import org.chromium.chrome.browser.ShortcutHelper;
27 import org.chromium.chrome.browser.engagement.SiteEngagementService; 28 import org.chromium.chrome.browser.engagement.SiteEngagementService;
28 import org.chromium.chrome.browser.infobar.AppBannerInfoBarAndroid; 29 import org.chromium.chrome.browser.infobar.AppBannerInfoBarAndroid;
29 import org.chromium.chrome.browser.infobar.AppBannerInfoBarDelegateAndroid; 30 import org.chromium.chrome.browser.infobar.AppBannerInfoBarDelegateAndroid;
30 import org.chromium.chrome.browser.infobar.InfoBar; 31 import org.chromium.chrome.browser.infobar.InfoBar;
31 import org.chromium.chrome.browser.infobar.InfoBarContainer; 32 import org.chromium.chrome.browser.infobar.InfoBarContainer;
32 import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarAnimationList ener; 33 import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarAnimationList ener;
33 import org.chromium.chrome.browser.profiles.Profile; 34 import org.chromium.chrome.browser.profiles.Profile;
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return mDetailsDelegate.mNumRetrieved; 530 return mDetailsDelegate.mNumRetrieved;
530 } 531 }
531 })); 532 }));
532 } 533 }
533 } 534 }
534 535
535 @SmallTest 536 @SmallTest
536 @Feature({"AppBanners"}) 537 @Feature({"AppBanners"})
537 public void testWebAppBannerAppears() throws Exception { 538 public void testWebAppBannerAppears() throws Exception {
538 triggerWebAppBanner(mWebAppUrl, WEB_APP_TITLE, false); 539 triggerWebAppBanner(mWebAppUrl, WEB_APP_TITLE, false);
540
541 // Verify metrics calling in the successful case.
542 ThreadUtils.runOnUiThread(new Runnable() {
543 @Override
544 public void run() {
545 AppBannerManager manager = getActivity().getActivityTab().getApp BannerManager();
546 manager.recordMenuItemAddToHomescreen();
547 assertEquals(1,
548 RecordHistogram.getHistogramValueCountForTesting(
549 "Webapp.InstallabilityCheckStatus.MenuItemAddToH omescreen", 5));
550
551 manager.recordMenuOpen();
552 assertEquals(1,
553 RecordHistogram.getHistogramValueCountForTesting(
554 "Webapp.InstallabilityCheckStatus.MenuOpen", 5)) ;
555 }
556 });
539 } 557 }
540 558
541 @SmallTest 559 @SmallTest
542 @Feature({"AppBanners"}) 560 @Feature({"AppBanners"})
543 public void testWebAppBannerDoesNotAppearAfterInstall() throws Exception { 561 public void testWebAppBannerDoesNotAppearAfterInstall() throws Exception {
544 triggerWebAppBanner(mWebAppUrl, WEB_APP_TITLE, true); 562 triggerWebAppBanner(mWebAppUrl, WEB_APP_TITLE, true);
545 563
546 // The banner should not reshow after the site has been installed. 564 // The banner should not reshow after the site has been installed.
547 AppBannerManager.setTimeDeltaForTesting(100); 565 AppBannerManager.setTimeDeltaForTesting(100);
548 new TabLoadObserver(getActivity().getActivityTab()) 566 new TabLoadObserver(getActivity().getActivityTab())
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 }); 644 });
627 645
628 // Test that bitmap sizes match expectations. 646 // Test that bitmap sizes match expectations.
629 int idealSize = getActivity().getResources().getDimensionPixelSize( 647 int idealSize = getActivity().getResources().getDimensionPixelSize(
630 R.dimen.webapp_splash_image_size_ideal); 648 R.dimen.webapp_splash_image_size_ideal);
631 Bitmap splashImage = ShortcutHelper.decodeBitmapFromString(dataStorageFa ctory.mSplashImage); 649 Bitmap splashImage = ShortcutHelper.decodeBitmapFromString(dataStorageFa ctory.mSplashImage);
632 assertEquals(idealSize, splashImage.getWidth()); 650 assertEquals(idealSize, splashImage.getWidth());
633 assertEquals(idealSize, splashImage.getHeight()); 651 assertEquals(idealSize, splashImage.getHeight());
634 } 652 }
635 } 653 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698