Commit bb76c8ae authored by John Budorick's avatar John Budorick Committed by Commit Bot

Switch AppBannerManagerTest from MockPackageManager to mockito.

Bug: 807764
Change-Id: I0758c2939049e22b60d653f69ce7537cb283487a
Reviewed-on: https://chromium-review.googlesource.com/1103598
Commit-Queue: John Budorick <jbudorick@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569792}
parent 744cf4d7
......@@ -659,8 +659,11 @@ class LocalDeviceInstrumentationTestRun(
dir=dev.GetExternalStoragePath()) as dev_test_list_json:
junit4_runner_class = self._test_instance.junit4_runner_class
test_package = self._test_instance.test_package
extras = {}
extras['log'] = 'true'
extras = {
'log': 'true',
# Workaround for https://github.com/mockito/mockito/issues/922
'notPackage': 'net.bytebuddy',
}
extras[_EXTRA_TEST_LIST] = dev_test_list_json.name
target = '%s/%s' % (test_package, junit4_runner_class)
timeout = 120
......
......@@ -611,6 +611,8 @@ android_library("chrome_test_java") {
"//third_party/hamcrest:hamcrest_java",
"//third_party/jsr-305:jsr_305_javalib",
"//third_party/junit",
"//third_party/mockito:mockito_android_java",
"//third_party/mockito:mockito_java",
"//third_party/protobuf:protobuf_lite_javalib",
"//third_party/ub-uiautomator:ub_uiautomator_java",
"//ui/android:ui_java",
......
......@@ -18,7 +18,6 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.support.v7.app.AlertDialog;
import android.test.mock.MockPackageManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
......@@ -30,6 +29,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram;
......@@ -83,6 +88,9 @@ public class AppBannerManagerTest {
@Rule
public CustomTabActivityTestRule mCustomTabActivityTestRule = new CustomTabActivityTestRule();
@Rule
public MockitoRule mMockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
private static final String NATIVE_APP_MANIFEST_WITH_ID =
"/chrome/test/data/banners/play_app_manifest.json";
......@@ -138,22 +146,6 @@ public class AppBannerManagerTest {
public void destroy() {}
}
private static class TestPackageManager extends MockPackageManager {
public boolean isInstalled = false;
@Override
public PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException {
if (isInstalled) {
PackageInfo info = new PackageInfo();
info.packageName = NATIVE_APP_PACKAGE;
return info;
} else {
throw new PackageManager.NameNotFoundException();
}
}
}
private static class TestDataStorageFactory extends WebappDataStorage.Factory {
public String mSplashImage;
......@@ -190,12 +182,12 @@ public class AppBannerManagerTest {
}
private MockAppDetailsDelegate mDetailsDelegate;
private TestPackageManager mPackageManager;
@Mock
private PackageManager mPackageManager;
private EmbeddedTestServer mTestServer;
@Before
public void setUp() throws Exception {
mPackageManager = new TestPackageManager();
AppBannerManager.setIsSupported(true);
InstallerDelegate.setPackageManagerForTesting(mPackageManager);
ShortcutHelper.setDelegateForTests(new ShortcutHelper.Delegate() {
......@@ -287,6 +279,11 @@ public class AppBannerManagerTest {
private void runFullNativeInstallPathway(
String url, String expectedReferrer, String expectedTitle) throws Exception {
// Say that the package isn't installed.
Mockito.when(mPackageManager.getPackageInfo(
ArgumentMatchers.anyString(), ArgumentMatchers.anyInt()))
.thenThrow(new PackageManager.NameNotFoundException());
// Visit a site that requests a banner.
Tab tab = mTabbedActivityTestRule.getActivity().getActivityTab();
resetEngagementForUrl(url, 0);
......@@ -339,7 +336,13 @@ public class AppBannerManagerTest {
}
// Say that the package is installed. Infobar should say that the app is ready to open.
mPackageManager.isInstalled = true;
Mockito.reset(mPackageManager);
PackageInfo info = new PackageInfo();
info.packageName = NATIVE_APP_PACKAGE;
Mockito.when(mPackageManager.getPackageInfo(
ArgumentMatchers.anyString(), ArgumentMatchers.anyInt()))
.thenReturn(info);
final String openText =
InstrumentationRegistry.getTargetContext().getString(R.string.app_banner_open);
CriteriaHelper.pollInstrumentationThread(new Criteria() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment