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

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

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: rebase and convert newly added test 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 756b9d7338b95e4c73a04555aa6102c81552a5f0..1e0d71425f73ec4f265733011765c994116671c5 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,20 +12,38 @@ import android.content.SharedPreferences;
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.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.WebContents;
/**
* Unit tests for {@link InstantAppsHandler}.
*/
-public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+@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);
+
private TestInstantAppsHandler mHandler;
private Context mContext;
@@ -33,19 +51,15 @@ public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeAct
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);
}
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
+ mActivityTestRule.startMainActivityOnBlankPage();
- mContext = getInstrumentation().getTargetContext();
+ mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
mHandler = new TestInstantAppsHandler();
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
@@ -55,56 +69,60 @@ public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeAct
editor.apply();
}
- @Override
+ @After
public void tearDown() throws Exception {
ContextUtils.getAppSharedPreferences().edit().clear().apply();
- super.tearDown();
}
+ @Test
@SmallTest
public void testInstantAppsDisabled_incognito() {
Intent i = createViewIntent();
i.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
- assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
}
-
+ @Test
@SmallTest
public void testInstantAppsDisabled_doNotLaunch() {
Intent i = createViewIntent();
i.putExtra("com.google.android.gms.instantapps.DO_NOT_LAUNCH_INSTANT_APP", true);
- assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
}
+ @Test
@SmallTest
public void testInstantAppsDisabled_mainIntent() {
Intent i = new Intent(Intent.ACTION_MAIN);
- assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
}
+ @Test
@SmallTest
public void testInstantAppsDisabled_intentOriginatingFromChrome() {
Intent i = createViewIntent();
i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
- assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
Intent signedIntent = createViewIntent();
signedIntent.setPackage(mContext.getPackageName());
IntentHandler.addTrustedIntentExtras(signedIntent);
- assertFalse(mHandler.handleIncomingIntent(mContext, signedIntent, false, true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(mContext, signedIntent, false, true));
}
+ @Test
@SmallTest
public void testInstantAppsDisabled_launchFromShortcut() {
Intent i = createViewIntent();
i.putExtra(ShortcutHelper.EXTRA_SOURCE, 1);
- assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(mContext, i, false, true));
}
+ @Test
@SmallTest
public void testChromeNotDefault() {
SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
@@ -112,77 +130,91 @@ public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeAct
editor.putBoolean("applink.chrome_default_browser", false);
editor.apply();
- assertFalse(mHandler.handleIncomingIntent(mContext, createViewIntent(), false, true));
+ Assert.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);
- assertTrue(mHandler.handleIncomingIntent(mContext, cti, true, true));
+ Assert.assertTrue(mHandler.handleIncomingIntent(mContext, cti, true, true));
}
+ @Test
@SmallTest
public void testInstantAppsEnabled() {
Intent i = createViewIntent();
- assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, false,
- true));
+ Assert.assertTrue(mHandler.handleIncomingIntent(
+ InstrumentationRegistry.getInstrumentation().getContext(), i, false, true));
// Check that identical intent wouldn't be enabled for CustomTab flow.
- assertFalse(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, true,
- true));
+ Assert.assertFalse(mHandler.handleIncomingIntent(
+ InstrumentationRegistry.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);
- assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, true,
- true));
+ Assert.assertTrue(mHandler.handleIncomingIntent(
+ InstrumentationRegistry.getInstrumentation().getContext(), i, true, true));
}
+ @Test
@SmallTest
public void testNfcIntent() {
Intent i = new Intent(NfcAdapter.ACTION_NDEF_DISCOVERED);
i.setData(Uri.parse("http://instantapp.com/"));
- assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, false,
- true));
+ Assert.assertTrue(mHandler.handleIncomingIntent(
+ InstrumentationRegistry.getInstrumentation().getContext(), i, false, true));
}
+ @Test
@SmallTest
public void testHandleNavigation_startAsyncCheck() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- assertFalse(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
- getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
+ Assert.assertFalse(
+ mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
+ mActivityTestRule.getActivity()
+ .getTabModelSelector()
+ .getCurrentTab()
+ .getWebContents()));
}
});
- assertFalse(mHandler.mLaunchInstantApp);
- assertTrue(mHandler.mStartedAsyncCall);
+ Assert.assertFalse(mHandler.mLaunchInstantApp);
+ Assert.assertTrue(mHandler.mStartedAsyncCall);
}
+ @Test
@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 = getInstrumentation().addMonitor(
- new IntentFilter(Intent.ACTION_MAIN), null, true);
+ Instrumentation.ActivityMonitor monitor =
+ InstrumentationRegistry.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",
- getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
+ mHandler.launchFromBanner(new InstantAppsBannerData("App", null, INSTANT_APP_URL,
+ REFERRER_URI, i, "Launch",
+ mActivityTestRule.getActivity()
+ .getTabModelSelector()
+ .getCurrentTab()
+ .getWebContents()));
}
});
// Started instant apps intent
- assertEquals(1, monitor.getHits());
+ Assert.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(),
+ 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(),
i.getStringExtra(InstantAppsHandler.TRUSTED_REFERRER_PKG_EXTRA));
// After a banner launch, test that the next launch happens automatically
@@ -190,17 +222,15 @@ public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeAct
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- assertTrue(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
- getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
+ Assert.assertTrue(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
+ mActivityTestRule.getActivity()
+ .getTabModelSelector()
+ .getCurrentTab()
+ .getWebContents()));
}
});
- assertFalse(mHandler.mStartedAsyncCall);
- assertTrue(mHandler.mLaunchInstantApp);
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
+ Assert.assertFalse(mHandler.mStartedAsyncCall);
+ Assert.assertTrue(mHandler.mLaunchInstantApp);
}
static class TestInstantAppsHandler extends InstantAppsHandler {

Powered by Google App Engine
This is Rietveld 408576698