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

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

Issue 1137313005: [App banner] Add unit test for installing native app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | chrome/android/javatests_shell/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java
index c76db8c5389efa737609bd3efd1dd9c5b0000b1d..686fe8f19b9039e3bab4c0353f551d3f77d1aa48 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AppBannerInfoBarDelegate.java
@@ -14,6 +14,7 @@ import android.os.Looper;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
+import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.Tab;
import org.chromium.chrome.browser.banners.AppData;
import org.chromium.chrome.browser.banners.InstallerDelegate;
@@ -25,6 +26,9 @@ import org.chromium.ui.base.WindowAndroid;
*/
@JNINamespace("banners")
public class AppBannerInfoBarDelegate {
+ /** PackageManager to use in place of the real one. */
+ private static PackageManager sPackageManagerForTests;
+
/** Weak pointer to the native AppBannerInfoBarDelegate. */
private long mNativePointer;
@@ -34,6 +38,12 @@ public class AppBannerInfoBarDelegate {
/** Monitors for application state changes. */
private final ApplicationStatus.ApplicationStateListener mListener;
+ /** Overrides the PackageManager for testing. */
+ @VisibleForTesting
+ public static void setPackageManagerForTesting(PackageManager manager) {
+ sPackageManagerForTests = manager;
+ }
+
private AppBannerInfoBarDelegate(long nativePtr) {
mNativePointer = nativePtr;
mListener = createApplicationStateListener();
@@ -64,7 +74,7 @@ public class AppBannerInfoBarDelegate {
private boolean installOrOpenNativeApp(Tab tab, AppData appData) {
Context context = ApplicationStatus.getApplicationContext();
String packageName = appData.packageName();
- PackageManager packageManager = context.getPackageManager();
+ PackageManager packageManager = getPackageManager(context);
if (InstallerDelegate.isInstalled(packageManager, packageName)) {
// Open the app.
@@ -89,7 +99,7 @@ public class AppBannerInfoBarDelegate {
if (isInstalling) {
// Start monitoring the install.
PackageManager pm =
- ApplicationStatus.getApplicationContext().getPackageManager();
+ getPackageManager(ApplicationStatus.getApplicationContext());
mInstallTask = new InstallerDelegate(
Looper.getMainLooper(), pm, createInstallerDelegateObserver(),
appData.packageName());
@@ -121,12 +131,17 @@ public class AppBannerInfoBarDelegate {
private int determineInstallState(AppData data) {
if (mInstallTask != null) return AppBannerInfoBar.INSTALL_STATE_INSTALLING;
- PackageManager pm = ApplicationStatus.getApplicationContext().getPackageManager();
+ PackageManager pm = getPackageManager(ApplicationStatus.getApplicationContext());
boolean isInstalled = InstallerDelegate.isInstalled(pm, data.packageName());
return isInstalled ? AppBannerInfoBar.INSTALL_STATE_INSTALLED
: AppBannerInfoBar.INSTALL_STATE_NOT_INSTALLED;
}
+ private PackageManager getPackageManager(Context context) {
+ if (sPackageManagerForTests != null) return sPackageManagerForTests;
+ return context.getPackageManager();
+ }
+
@CalledByNative
private static AppBannerInfoBarDelegate create(long nativePtr) {
return new AppBannerInfoBarDelegate(nativePtr);
« no previous file with comments | « no previous file | chrome/android/javatests_shell/src/org/chromium/chrome/browser/banners/AppBannerManagerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698