| 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 ff77e92c9a68c939444daadc9a3698593692a3db..9705f8cc92601d8824e170279733b80968f88764 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
|
| @@ -4,27 +4,38 @@
|
|
|
| package org.chromium.chrome.browser.instantapps;
|
|
|
| +import android.app.Instrumentation;
|
| import android.content.Context;
|
| import android.content.Intent;
|
| +import android.content.IntentFilter;
|
| import android.content.SharedPreferences;
|
| import android.net.Uri;
|
| import android.nfc.NfcAdapter;
|
| import android.provider.Browser;
|
| -import android.test.InstrumentationTestCase;
|
| import android.test.suitebuilder.annotation.SmallTest;
|
|
|
| import org.chromium.base.ContextUtils;
|
| +import org.chromium.base.ThreadUtils;
|
| +import org.chromium.chrome.browser.ChromeActivity;
|
| import org.chromium.chrome.browser.IntentHandler;
|
| +import org.chromium.chrome.browser.ShortcutHelper;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.content_public.browser.WebContents;
|
|
|
| /**
|
| * Unit tests for {@link InstantAppsHandler}.
|
| */
|
| -public class InstantAppsHandlerTest extends InstrumentationTestCase {
|
| -
|
| +public class InstantAppsHandlerTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| private TestInstantAppsHandler mHandler;
|
| private Context mContext;
|
|
|
| private static final Uri URI = Uri.parse("http://sampleurl.com/foo");
|
| + 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);
|
| @@ -99,6 +110,13 @@ public class InstantAppsHandlerTest extends InstrumentationTestCase {
|
| }
|
|
|
| @SmallTest
|
| + public void testInstantAppsDisabled_launchFromShortcut() {
|
| + Intent i = createViewIntent();
|
| + i.putExtra(ShortcutHelper.EXTRA_SOURCE, 1);
|
| + assertFalse(mHandler.handleIncomingIntent(mContext, i, false));
|
| + }
|
| +
|
| + @SmallTest
|
| public void testChromeNotDefault() {
|
| SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
|
| SharedPreferences.Editor editor = prefs.edit();
|
| @@ -134,11 +152,99 @@ public class InstantAppsHandlerTest extends InstrumentationTestCase {
|
| assertTrue(mHandler.handleIncomingIntent(getInstrumentation().getContext(), i, false));
|
| }
|
|
|
| + @SmallTest
|
| + public void testHandleNavigation_noExperiment() {
|
| + SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
|
| + SharedPreferences.Editor editor = prefs.edit();
|
| + editor.putBoolean("applink.app_link_enabled", false);
|
| + editor.apply();
|
| +
|
| + assertFalse(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI, null));
|
| + assertFalse(mHandler.mLaunchInstantApp);
|
| + assertFalse(mHandler.mStartedAsyncCall);
|
| + }
|
| +
|
| + @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()));
|
| + }
|
| + });
|
| + 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 = 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()));
|
| + }
|
| + });
|
| +
|
| + // Started instant apps intent
|
| + 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
|
| +
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + assertTrue(mHandler.handleNavigation(mContext, INSTANT_APP_URL, REFERRER_URI,
|
| + getActivity().getTabModelSelector().getCurrentTab().getWebContents()));
|
| + }
|
| + });
|
| + assertFalse(mHandler.mStartedAsyncCall);
|
| + assertTrue(mHandler.mLaunchInstantApp);
|
| + }
|
| +
|
| + @Override
|
| + public void startMainActivity() throws InterruptedException {
|
| + startMainActivityOnBlankPage();
|
| + }
|
| +
|
| static class TestInstantAppsHandler extends InstantAppsHandler {
|
| + // Keeps track of whether startCheckForInstantApps() has been called.
|
| + public volatile boolean mStartedAsyncCall;
|
| + // Keeps track of whether launchInstantAppForNavigation() has been called.
|
| + public volatile boolean mLaunchInstantApp;
|
| +
|
| @Override
|
| protected boolean tryLaunchingInstantApp(Context context, Intent intent,
|
| boolean isCustomTabsIntent, Intent fallbackIntent) {
|
| return true;
|
| }
|
| +
|
| + @Override
|
| + protected boolean launchInstantAppForNavigation(Context context, String url, Uri referrer) {
|
| + mLaunchInstantApp = true;
|
| + return true;
|
| + }
|
| +
|
| + @Override
|
| + protected boolean startCheckForInstantApps(Context context, String url, Uri referrer,
|
| + WebContents webContents) {
|
| + mStartedAsyncCall = true;
|
| + return false;
|
| + }
|
| }
|
| }
|
|
|