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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/instantapps/InstantAppsHandlerTest.java

Issue 2860843002: Revert of Reland: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/instantapps/InstantAppsHandlerTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/instantapps/InstantAppsHandlerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/instantapps/InstantAppsHandlerTest.java
index 1e0d71425f73ec4f265733011765c994116671c5..756b9d7338b95e4c73a04555aa6102c81552a5f0 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/instantapps/InstantAppsHandlerTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/instantapps/InstantAppsHandlerTest.java
@@ -12,38 +12,20 @@
import android.net.Uri;
import android.nfc.NfcAdapter;
import android.provider.Browser;
-import android.support.test.InstrumentationRegistry;
import android.test.suitebuilder.annotation.SmallTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
-import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.browser.ChromeActivity;
-import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.ShortcutHelper;
-import org.chromium.chrome.test.ChromeActivityTestRule;
-import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
+import org.chromium.chrome.test.ChromeActivityTestCaseBase;
import org.chromium.content_public.browser.WebContents;
/**
* Unit tests for {@link InstantAppsHandler}.
*/
-@RunWith(ChromeJUnit4ClassRunner.class)
-@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
- ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
-public class InstantAppsHandlerTest {
- @Rule
- public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
- new ChromeActivityTestRule<>(ChromeActivity.class);
-
+public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeActivity> {
private TestInstantAppsHandler mHandler;
private Context mContext;
@@ -51,15 +33,19 @@
private static final String INSTANT_APP_URL = "http://sampleapp.com/boo";
private static final Uri REFERRER_URI = Uri.parse("http://www.wikipedia.org/");
+ public InstantAppsHandlerTest() {
+ super(ChromeActivity.class);
+ }
+
private Intent createViewIntent() {
return new Intent(Intent.ACTION_VIEW, URI);
}
- @Before
+ @Override
public void setUp() throws Exception {
- mActivityTestRule.startMainActivityOnBlankPage();
-
- mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ super.setUp();
+
+ mContext = getInstrumentation().getTargetContext();
mHandler = new TestInstantAppsHandler();
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
@@ -69,60 +55,56 @@
editor.apply();
}
- @After
+ @Override
public void tearDown() throws Exception {
ContextUtils.getAppSharedPreferences().edit().clear().apply();
- }
-
- @Test
+ super.tearDown();
+ }
+
@SmallTest
public void testInstantAppsDisabled_incognito() {
Intent i = createViewIntent();
i.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
- Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
- }
-
- @Test
+ assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ }
+
+
@SmallTest
public void testInstantAppsDisabled_doNotLaunch() {
Intent i = createViewIntent();
i.putExtra("com.google.android.gms.instantapps.DO_NOT_LAUNCH_INSTANT_APP", true);
- Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
- }
-
- @Test
+ assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ }
+
@SmallTest
public void testInstantAppsDisabled_mainIntent() {
Intent i = new Intent(Intent.ACTION_MAIN);
- Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
- }
-
- @Test
+ assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ }
+
@SmallTest
public void testInstantAppsDisabled_intentOriginatingFromChrome() {
Intent i = createViewIntent();
i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
- Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
Intent signedIntent = createViewIntent();
signedIntent.setPackage(mContext.getPackageName());
IntentHandler.addTrustedIntentExtras(signedIntent);
- Assert.assertFalse(mHandler.handleIncomingIntent(mContext, signedIntent, false, true));
- }
-
- @Test
+ assertFalse(mHandler.handleIncomingIntent(mContext, signedIntent, false, true));
+ }
+
@SmallTest
public void testInstantAppsDisabled_launchFromShortcut() {
Intent i = createViewIntent();
i.putExtra(ShortcutHelper.EXTRA_SOURCE, 1);
- Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
- }
-
- @Test
+ assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ }
+
@SmallTest
public void testChromeNotDefault() {
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
@@ -130,91 +112,77 @@
editor.putBoolean("applink.chrome_default_browser", false);
editor.apply();
- Assert.assertFalse(
- mHandler.handleIncomingIntent(mContext, createViewIntent(), false, true));
+ assertFalse(mHandler.handleIncomingIntent(mContext, createViewIntent(), false, true));
// Even if Chrome is not default, launch Instant Apps for CustomTabs since those never
// show disambiguation dialogs.
Intent cti = createViewIntent()
.putExtra("android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS", true);
- Assert.assertTrue(mHandler.handleIncomingIntent(mContext, cti, true, true));
- }
-
- @Test
+ assertTrue(mHandler.handleIncomingIntent(mContext, cti, true, true));
+ }
+
@SmallTest
public void testInstantAppsEnabled() {
Intent i = createViewIntent();
- Assert.assertTrue(mHandler.handleIncomingIntent(
- InstrumentationRegistry.getInstrumentation().getContext(), i, false, true));
+ assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, false,
+ true));
// Check that identical intent wouldn't be enabled for CustomTab flow.
- Assert.assertFalse(mHandler.handleIncomingIntent(
- InstrumentationRegistry.getInstrumentation().getContext(), i, true, true));
+ assertFalse(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, true,
+ true));
// Add CustomTab specific extra and check it's now enabled.
i.putExtra("android.support.customtabs.extra.EXTRA_ENABLE_INSTANT_APPS", true);
- Assert.assertTrue(mHandler.handleIncomingIntent(
- InstrumentationRegistry.getInstrumentation().getContext(), i, true, true));
- }
-
- @Test
+ assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, true,
+ true));
+ }
+
@SmallTest
public void testNfcIntent() {
Intent i = new Intent(NfcAdapter.ACTION_NDEF_DISCOVERED);
i.setData(Uri.parse("http://instantapp.com/"));
- Assert.assertTrue(mHandler.handleIncomingIntent(
- InstrumentationRegistry.getInstrumentation().getContext(), i, false, true));
- }
-
- @Test
+ assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, false,
+ true));
+ }
+
@SmallTest
public void testHandleNavigation_startAsyncCheck() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- Assert.assertFalse(
- mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
- mActivityTestRule.getActivity()
- .getTabModelSelector()
- .getCurrentTab()
- .getWebContents()));
+ assertFalse(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
+ getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
}
});
- Assert.assertFalse(mHandler.mLaunchInstantApp);
- Assert.assertTrue(mHandler.mStartedAsyncCall);
- }
-
- @Test
+ assertFalse(mHandler.mLaunchInstantApp);
+ assertTrue(mHandler.mStartedAsyncCall);
+ }
+
@SmallTest
public void testLaunchFromBanner() {
// Intent to supervisor
final Intent i = new Intent(Intent.ACTION_MAIN);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- Instrumentation.ActivityMonitor monitor =
- InstrumentationRegistry.getInstrumentation().addMonitor(
- new IntentFilter(Intent.ACTION_MAIN), null, true);
+ Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(
+ new IntentFilter(Intent.ACTION_MAIN), null, true);
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- mHandler.launchFromBanner(new InstantAppsBannerData("App", null, INSTANT_APP_URL,
- REFERRER_URI, i, "Launch",
- mActivityTestRule.getActivity()
- .getTabModelSelector()
- .getCurrentTab()
- .getWebContents()));
+ mHandler.launchFromBanner(new InstantAppsBannerData(
+ "App", null, INSTANT_APP_URL, REFERRER_URI, i, "Launch",
+ getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
}
});
// Started instant apps intent
- Assert.assertEquals(1, monitor.getHits());
-
- Assert.assertEquals(REFERRER_URI, i.getParcelableExtra(Intent.EXTRA_REFERRER));
- Assert.assertTrue(i.getBooleanExtra(InstantAppsHandler.IS_REFERRER_TRUSTED_EXTRA, false));
- Assert.assertTrue(
- i.getBooleanExtra(InstantAppsHandler.IS_USER_CONFIRMED_LAUNCH_EXTRA, false));
- Assert.assertEquals(mContext.getPackageName(),
+ assertEquals(1, monitor.getHits());
+
+ assertEquals(REFERRER_URI, i.getParcelableExtra(Intent.EXTRA_REFERRER));
+ assertTrue(i.getBooleanExtra(InstantAppsHandler.IS_REFERRER_TRUSTED_EXTRA, false));
+ assertTrue(i.getBooleanExtra(InstantAppsHandler.IS_USER_CONFIRMED_LAUNCH_EXTRA, false));
+ assertEquals(mContext.getPackageName(),
i.getStringExtra(InstantAppsHandler.TRUSTED_REFERRER_PKG_EXTRA));
// After a banner launch, test that the next launch happens automatically
@@ -222,15 +190,17 @@
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- Assert.assertTrue(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
- mActivityTestRule.getActivity()
- .getTabModelSelector()
- .getCurrentTab()
- .getWebContents()));
+ assertTrue(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
+ getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
}
});
- Assert.assertFalse(mHandler.mStartedAsyncCall);
- Assert.assertTrue(mHandler.mLaunchInstantApp);
+ assertFalse(mHandler.mStartedAsyncCall);
+ assertTrue(mHandler.mLaunchInstantApp);
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ startMainActivityOnBlankPage();
}
static class TestInstantAppsHandler extends InstantAppsHandler {

Powered by Google App Engine
This is Rietveld 408576698