Commit a0d1c153 authored by lizeb's avatar lizeb Committed by Commit Bot

customtabs: Remove unnecessary Context plumbing.

Also removes Context -> Application downcasts in callers.

Review-Url: https://codereview.chromium.org/2966193002
Cr-Commit-Position: refs/heads/master@{#485909}
parent ad6d8a9b
...@@ -120,7 +120,7 @@ public abstract class AppHooks { ...@@ -120,7 +120,7 @@ public abstract class AppHooks {
* outside of {@link CustomTabsConnection#getInstance()}. * outside of {@link CustomTabsConnection#getInstance()}.
*/ */
public CustomTabsConnection createCustomTabsConnection() { public CustomTabsConnection createCustomTabsConnection() {
return new CustomTabsConnection(((ChromeApplication) ContextUtils.getApplicationContext())); return new CustomTabsConnection();
} }
/** /**
......
...@@ -51,7 +51,7 @@ class CustomTabObserver extends EmptyTabObserver { ...@@ -51,7 +51,7 @@ class CustomTabObserver extends EmptyTabObserver {
if (openedByChrome) { if (openedByChrome) {
mCustomTabsConnection = null; mCustomTabsConnection = null;
} else { } else {
mCustomTabsConnection = CustomTabsConnection.getInstance(application); mCustomTabsConnection = CustomTabsConnection.getInstance();
} }
mSession = session; mSession = session;
if (!openedByChrome && mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) { if (!openedByChrome && mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) {
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.customtabs; package org.chromium.chrome.browser.customtabs;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Application;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -27,6 +26,7 @@ import android.text.TextUtils; ...@@ -27,6 +26,7 @@ import android.text.TextUtils;
import android.util.Pair; import android.util.Pair;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -180,7 +180,7 @@ public class CustomTabsConnection { ...@@ -180,7 +180,7 @@ public class CustomTabsConnection {
@VisibleForTesting @VisibleForTesting
SpeculationParams mSpeculation; SpeculationParams mSpeculation;
protected final Application mApplication; protected final Context mContext;
protected final ClientManager mClientManager; protected final ClientManager mClientManager;
private final boolean mLogRequests; private final boolean mLogRequests;
private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean(); private final AtomicBoolean mWarmupHasBeenCalled = new AtomicBoolean();
...@@ -197,21 +197,20 @@ public class CustomTabsConnection { ...@@ -197,21 +197,20 @@ public class CustomTabsConnection {
* Public to be instanciable from {@link ChromeApplication}. This is however * Public to be instanciable from {@link ChromeApplication}. This is however
* intended to be private. * intended to be private.
*/ */
public CustomTabsConnection(Application application) { public CustomTabsConnection() {
super(); super();
mApplication = application; mContext = ContextUtils.getApplicationContext();
mClientManager = new ClientManager(mApplication); // Command line switch values are used below.
BaseChromiumApplication.initCommandLine(mContext);
mClientManager = new ClientManager(mContext);
mLogRequests = CommandLine.getInstance().hasSwitch(LOG_SERVICE_REQUESTS); mLogRequests = CommandLine.getInstance().hasSwitch(LOG_SERVICE_REQUESTS);
} }
/** /**
* @return The unique instance of ChromeCustomTabsConnection. * @return The unique instance of ChromeCustomTabsConnection.
* TODO(estevenson): Remove Application param.
*/ */
@SuppressFBWarnings("BC_UNCONFIRMED_CAST") public static CustomTabsConnection getInstance() {
public static CustomTabsConnection getInstance(Application application) {
if (sInstance.get() == null) { if (sInstance.get() == null) {
((ChromeApplication) application).initCommandLine();
sInstance.compareAndSet(null, AppHooks.get().createCustomTabsConnection()); sInstance.compareAndSet(null, AppHooks.get().createCustomTabsConnection());
} }
return sInstance.get(); return sInstance.get();
...@@ -264,17 +263,16 @@ public class CustomTabsConnection { ...@@ -264,17 +263,16 @@ public class CustomTabsConnection {
/** Warmup activities that should only happen once. */ /** Warmup activities that should only happen once. */
@SuppressFBWarnings("DM_EXIT") @SuppressFBWarnings("DM_EXIT")
private static void initializeBrowser(final Application app) { private static void initializeBrowser(final Context context) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
try { try {
ChromeBrowserInitializer.getInstance(app).handleSynchronousStartupWithGpuWarmUp(); ChromeBrowserInitializer.getInstance(context).handleSynchronousStartupWithGpuWarmUp();
} catch (ProcessInitException e) { } catch (ProcessInitException e) {
Log.e(TAG, "ProcessInitException while starting the browser process."); Log.e(TAG, "ProcessInitException while starting the browser process.");
// Cannot do anything without the native library, and cannot show a // Cannot do anything without the native library, and cannot show a
// dialog to the user. // dialog to the user.
System.exit(-1); System.exit(-1);
} }
final Context context = app.getApplicationContext();
ChildProcessLauncherHelper.warmUp(context); ChildProcessLauncherHelper.warmUp(context);
ChromeBrowserInitializer.initNetworkChangeNotifier(context); ChromeBrowserInitializer.initNetworkChangeNotifier(context);
WarmupManager.getInstance().initializeViewHierarchy( WarmupManager.getInstance().initializeViewHierarchy(
...@@ -295,8 +293,8 @@ public class CustomTabsConnection { ...@@ -295,8 +293,8 @@ public class CustomTabsConnection {
/** /**
* @return Whether {@link CustomTabsConnection#warmup(long)} has been called. * @return Whether {@link CustomTabsConnection#warmup(long)} has been called.
*/ */
public static boolean hasWarmUpBeenFinished(Application application) { public static boolean hasWarmUpBeenFinished() {
return getInstance(application).mWarmupHasBeenFinished.get(); return getInstance().mWarmupHasBeenFinished.get();
} }
/** /**
...@@ -325,7 +323,7 @@ public class CustomTabsConnection { ...@@ -325,7 +323,7 @@ public class CustomTabsConnection {
// 4. RequestThrottler first access has to be done only once. // 4. RequestThrottler first access has to be done only once.
// (1) // (1)
if (!initialized) initializeBrowser(mApplication); if (!initialized) initializeBrowser(mContext);
// (2) // (2)
if (mayCreateSpareWebContents && mSpeculation == null) { if (mayCreateSpareWebContents && mSpeculation == null) {
...@@ -341,7 +339,7 @@ public class CustomTabsConnection { ...@@ -341,7 +339,7 @@ public class CustomTabsConnection {
// The throttling database uses shared preferences, that can cause a // The throttling database uses shared preferences, that can cause a
// StrictMode violation on the first access. Make sure that this access is // StrictMode violation on the first access. Make sure that this access is
// not in mayLauchUrl. // not in mayLauchUrl.
RequestThrottler.loadInBackground(mApplication); RequestThrottler.loadInBackground(mContext);
} }
} finally { } finally {
TraceEvent.end("CustomTabsConnection.warmupInternal"); TraceEvent.end("CustomTabsConnection.warmupInternal");
...@@ -1009,7 +1007,7 @@ public class CustomTabsConnection { ...@@ -1009,7 +1007,7 @@ public class CustomTabsConnection {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
do { do {
ActivityManager am = ActivityManager am =
(ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE); (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
// Extra paranoia here and below, some L 5.0.x devices seem to throw NPE somewhere // Extra paranoia here and below, some L 5.0.x devices seem to throw NPE somewhere
// in this code. // in this code.
// See https://crbug.com/654705. // See https://crbug.com/654705.
...@@ -1068,8 +1066,7 @@ public class CustomTabsConnection { ...@@ -1068,8 +1066,7 @@ public class CustomTabsConnection {
return SPECULATION_STATUS_ON_START_NOT_ALLOWED_DATA_REDUCTION_ENABLED; return SPECULATION_STATUS_ON_START_NOT_ALLOWED_DATA_REDUCTION_ENABLED;
} }
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager) mApplication.getApplicationContext().getSystemService( (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
Context.CONNECTIVITY_SERVICE);
if (cm.isActiveNetworkMetered() && !shouldPrerenderOnCellularForSession(session)) { if (cm.isActiveNetworkMetered() && !shouldPrerenderOnCellularForSession(session)) {
return SPECULATION_STATUS_ON_START_NOT_ALLOWED_NETWORK_METERED; return SPECULATION_STATUS_ON_START_NOT_ALLOWED_NETWORK_METERED;
} }
...@@ -1165,7 +1162,7 @@ public class CustomTabsConnection { ...@@ -1165,7 +1162,7 @@ public class CustomTabsConnection {
if (mExternalPrerenderHandler == null) { if (mExternalPrerenderHandler == null) {
mExternalPrerenderHandler = new ExternalPrerenderHandler(); mExternalPrerenderHandler = new ExternalPrerenderHandler();
} }
Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mApplication, true); Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mContext, true);
String referrer = getReferrer(session, extrasIntent); String referrer = getReferrer(session, extrasIntent);
boolean forced = shouldPrerenderOnCellularForSession(session); boolean forced = shouldPrerenderOnCellularForSession(session);
...@@ -1220,12 +1217,12 @@ public class CustomTabsConnection { ...@@ -1220,12 +1217,12 @@ public class CustomTabsConnection {
} }
@VisibleForTesting @VisibleForTesting
void resetThrottling(Context context, int uid) { void resetThrottling(int uid) {
mClientManager.resetThrottling(uid); mClientManager.resetThrottling(uid);
} }
@VisibleForTesting @VisibleForTesting
void ban(Context context, int uid) { void ban(int uid) {
mClientManager.ban(uid); mClientManager.ban(uid);
} }
......
...@@ -36,7 +36,7 @@ public class CustomTabsConnectionService extends CustomTabsService { ...@@ -36,7 +36,7 @@ public class CustomTabsConnectionService extends CustomTabsService {
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
mBindIntent = intent; mBindIntent = intent;
mConnection = CustomTabsConnection.getInstance(getApplication()); mConnection = CustomTabsConnection.getInstance();
mConnection.logCall("Service#onBind()", true); mConnection.logCall("Service#onBind()", true);
return super.onBind(intent); return super.onBind(intent);
} }
......
...@@ -585,8 +585,8 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir ...@@ -585,8 +585,8 @@ public class FirstRunActivity extends AsyncInitializationActivity implements Fir
public void onSendFinished(PendingIntent pendingIntent, Intent intent, public void onSendFinished(PendingIntent pendingIntent, Intent intent,
int resultCode, String resultData, Bundle resultExtras) { int resultCode, String resultData, Bundle resultExtras) {
if (ChromeLauncherActivity.isCustomTabIntent(intent)) { if (ChromeLauncherActivity.isCustomTabIntent(intent)) {
CustomTabsConnection.getInstance( CustomTabsConnection.getInstance().sendFirstRunCallbackIfNecessary(
getApplication()).sendFirstRunCallbackIfNecessary(intent, complete); intent, complete);
} }
} }
}; };
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.prerender; package org.chromium.chrome.browser.prerender;
import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Point; import android.graphics.Point;
...@@ -121,20 +120,20 @@ public class ExternalPrerenderHandler { ...@@ -121,20 +120,20 @@ public class ExternalPrerenderHandler {
* The estimate is likely to be incorrect. This is not a problem, as the aim * The estimate is likely to be incorrect. This is not a problem, as the aim
* is to avoid getting a different layout and resources than needed at * is to avoid getting a different layout and resources than needed at
* render time. * render time.
* @param application The application to use for getting resources. * @param context The application context.
* @param convertToDp Whether the value should be converted to dp from pixels. * @param convertToDp Whether the value should be converted to dp from pixels.
* @return The estimated prerender size in pixels or dp. * @return The estimated prerender size in pixels or dp.
*/ */
public static Rect estimateContentSize(Application application, boolean convertToDp) { public static Rect estimateContentSize(Context context, boolean convertToDp) {
// The size is estimated as: // The size is estimated as:
// X = screenSizeX // X = screenSizeX
// Y = screenSizeY - top bar - bottom bar - custom tabs bar // Y = screenSizeY - top bar - bottom bar - custom tabs bar
// The bounds rectangle includes the bottom bar and the custom tabs bar as well. // The bounds rectangle includes the bottom bar and the custom tabs bar as well.
Rect screenBounds = new Rect(); Rect screenBounds = new Rect();
Point screenSize = new Point(); Point screenSize = new Point();
WindowManager wm = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getSize(screenSize); wm.getDefaultDisplay().getSize(screenSize);
Resources resources = application.getResources(); Resources resources = context.getResources();
int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android"); int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android");
try { try {
screenSize.y -= resources.getDimensionPixelSize(statusBarId); screenSize.y -= resources.getDimensionPixelSize(statusBarId);
......
...@@ -189,7 +189,7 @@ public class SearchActivity extends AsyncInitializationActivity ...@@ -189,7 +189,7 @@ public class SearchActivity extends AsyncInitializationActivity
if (mQueuedUrl != null) loadUrl(mQueuedUrl); if (mQueuedUrl != null) loadUrl(mQueuedUrl);
AutocompleteController.nativePrefetchZeroSuggestResults(); AutocompleteController.nativePrefetchZeroSuggestResults();
CustomTabsConnection.getInstance(getApplication()).warmup(0); CustomTabsConnection.getInstance().warmup(0);
mSearchBox.onDeferredStartup(isVoiceSearchIntent()); mSearchBox.onDeferredStartup(isVoiceSearchIntent());
RecordUserAction.record("SearchWidget.WidgetSelected"); RecordUserAction.record("SearchWidget.WidgetSelected");
......
...@@ -8,7 +8,6 @@ import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ...@@ -8,7 +8,6 @@ import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
import static org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule.LONG_TIMEOUT_MS; import static org.chromium.chrome.browser.customtabs.CustomTabActivityTestRule.LONG_TIMEOUT_MS;
import android.app.Activity; import android.app.Activity;
import android.app.Application;
import android.app.Instrumentation; import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor; import android.app.Instrumentation.ActivityMonitor;
import android.app.Instrumentation.ActivityResult; import android.app.Instrumentation.ActivityResult;
...@@ -205,18 +204,13 @@ public class CustomTabActivityTest { ...@@ -205,18 +204,13 @@ public class CustomTabActivityTest {
LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(); LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
mWebServer = TestWebServer.start(); mWebServer = TestWebServer.start();
CustomTabsConnection connection = CustomTabsConnection connection = CustomTabsConnection.getInstance();
CustomTabsConnection.getInstance((Application) appContext);
connection.setForcePrerender(true); connection.setForcePrerender(true);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
Context appContext = InstrumentationRegistry.getInstrumentation() CustomTabsConnection connection = CustomTabsConnection.getInstance();
.getTargetContext()
.getApplicationContext();
CustomTabsConnection connection =
CustomTabsConnection.getInstance((Application) appContext);
connection.setForcePrerender(false); connection.setForcePrerender(false);
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
...@@ -1012,7 +1006,7 @@ public class CustomTabActivityTest { ...@@ -1012,7 +1006,7 @@ public class CustomTabActivityTest {
final Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context, mTestPage2); final Intent intent = CustomTabsTestUtils.createMinimalCustomTabIntent(context, mTestPage2);
final CustomTabsSessionToken session = warmUpAndLaunchUrlWithSession(intent); final CustomTabsSessionToken session = warmUpAndLaunchUrlWithSession(intent);
Assert.assertEquals(getActivity().getIntentDataProvider().getSession(), session); Assert.assertEquals(getActivity().getIntentDataProvider().getSession(), session);
CustomTabsConnection connection = CustomTabsConnection.getInstance((Application) context); CustomTabsConnection connection = CustomTabsConnection.getInstance();
String packageName = context.getPackageName(); String packageName = context.getPackageName();
final String referrer = final String referrer =
IntentHandler.constructValidReferrerForAuthority(packageName).getUrl(); IntentHandler.constructValidReferrerForAuthority(packageName).getUrl();
...@@ -2191,8 +2185,7 @@ public class CustomTabActivityTest { ...@@ -2191,8 +2185,7 @@ public class CustomTabActivityTest {
Context context = InstrumentationRegistry.getInstrumentation() Context context = InstrumentationRegistry.getInstrumentation()
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
final CustomTabsConnection connection = final CustomTabsConnection connection = CustomTabsConnection.getInstance();
CustomTabsConnection.getInstance((Application) context);
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
...@@ -2681,8 +2674,7 @@ public class CustomTabActivityTest { ...@@ -2681,8 +2674,7 @@ public class CustomTabActivityTest {
Context context = InstrumentationRegistry.getInstrumentation() Context context = InstrumentationRegistry.getInstrumentation()
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
CustomTabsConnection connection = CustomTabsConnection connection = CustomTabsTestUtils.setUpConnection();
CustomTabsTestUtils.setUpConnection((Application) context);
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
Bundle extras = null; Bundle extras = null;
...@@ -2704,11 +2696,7 @@ public class CustomTabActivityTest { ...@@ -2704,11 +2696,7 @@ public class CustomTabActivityTest {
} }
private CustomTabsConnection warmUpAndWait() { private CustomTabsConnection warmUpAndWait() {
final Context context = InstrumentationRegistry.getInstrumentation() CustomTabsConnection connection = CustomTabsTestUtils.setUpConnection();
.getTargetContext()
.getApplicationContext();
CustomTabsConnection connection =
CustomTabsTestUtils.setUpConnection((Application) context);
final CallbackHelper startupCallbackHelper = new CallbackHelper(); final CallbackHelper startupCallbackHelper = new CallbackHelper();
Assert.assertTrue(connection.warmup(0)); Assert.assertTrue(connection.warmup(0));
ThreadUtils.runOnUiThread(new Runnable() { ThreadUtils.runOnUiThread(new Runnable() {
......
...@@ -66,6 +66,9 @@ public class CustomTabTabPersistencePolicyTest { ...@@ -66,6 +66,9 @@ public class CustomTabTabPersistencePolicyTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// CustomTabsConnection needs a true context, not the mock context set below.
CustomTabsConnection.getInstance();
mAppContext = new AdvancedMockContext(InstrumentationRegistry.getInstrumentation() mAppContext = new AdvancedMockContext(InstrumentationRegistry.getInstrumentation()
.getTargetContext() .getTargetContext()
.getApplicationContext()); .getApplicationContext());
......
...@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.customtabs; ...@@ -6,8 +6,6 @@ package org.chromium.chrome.browser.customtabs;
import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE; import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_END_DEVICE;
import android.app.Application;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
...@@ -15,7 +13,6 @@ import android.os.Bundle; ...@@ -15,7 +13,6 @@ import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.support.customtabs.CustomTabsService; import android.support.customtabs.CustomTabsService;
import android.support.customtabs.CustomTabsSessionToken; import android.support.customtabs.CustomTabsSessionToken;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import org.junit.After; import org.junit.After;
...@@ -49,17 +46,12 @@ public class CustomTabsConnectionTest { ...@@ -49,17 +46,12 @@ public class CustomTabsConnectionTest {
private static final String INVALID_SCHEME_URL = "intent://www.google.com"; private static final String INVALID_SCHEME_URL = "intent://www.google.com";
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome"; private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome";
private Context mAppContext;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mAppContext = InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getApplicationContext();
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(); LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
mCustomTabsConnection = CustomTabsTestUtils.setUpConnection((Application) mAppContext); mCustomTabsConnection = CustomTabsTestUtils.setUpConnection();
mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid()); mCustomTabsConnection.resetThrottling(Process.myUid());
} }
@After @After
...@@ -155,7 +147,7 @@ public class CustomTabsConnectionTest { ...@@ -155,7 +147,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testPrerenderDestroysSpareRenderer() { public void testPrerenderDestroysSpareRenderer() {
CustomTabsConnection.getInstance((Application) mAppContext).setForcePrerender(true); CustomTabsConnection.getInstance().setForcePrerender(true);
final CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true); final CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
...@@ -305,7 +297,7 @@ public class CustomTabsConnectionTest { ...@@ -305,7 +297,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testStillHighConfidenceMayLaunchUrlWithSeveralUrls() { public void testStillHighConfidenceMayLaunchUrlWithSeveralUrls() {
CustomTabsConnection.getInstance((Application) mAppContext).setForcePrerender(true); CustomTabsConnection.getInstance().setForcePrerender(true);
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
...@@ -352,7 +344,7 @@ public class CustomTabsConnectionTest { ...@@ -352,7 +344,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
@RetryOnFailure @RetryOnFailure
public void testCanCancelPrerender() { public void testCanCancelPrerender() {
CustomTabsConnection.getInstance((Application) mAppContext).setForcePrerender(true); CustomTabsConnection.getInstance().setForcePrerender(true);
final CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true); final CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
...@@ -439,9 +431,9 @@ public class CustomTabsConnectionTest { ...@@ -439,9 +431,9 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
public void testMultipleMayLaunchUrl() { public void testMultipleMayLaunchUrl() {
CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true); CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid()); mCustomTabsConnection.resetThrottling(Process.myUid());
assertWarmupAndMayLaunchUrl(token, URL, true); assertWarmupAndMayLaunchUrl(token, URL, true);
mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid()); mCustomTabsConnection.resetThrottling(Process.myUid());
assertWarmupAndMayLaunchUrl(token, URL2, true); assertWarmupAndMayLaunchUrl(token, URL2, true);
} }
...@@ -545,9 +537,9 @@ public class CustomTabsConnectionTest { ...@@ -545,9 +537,9 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
public void testThrottlingAcrossSessions() { public void testThrottlingAcrossSessions() {
CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true); CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, true);
mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid()); mCustomTabsConnection.resetThrottling(Process.myUid());
CustomTabsSessionToken token2 = assertWarmupAndMayLaunchUrl(null, URL, true); CustomTabsSessionToken token2 = assertWarmupAndMayLaunchUrl(null, URL, true);
mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid()); mCustomTabsConnection.resetThrottling(Process.myUid());
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null); mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null);
} }
...@@ -558,7 +550,7 @@ public class CustomTabsConnectionTest { ...@@ -558,7 +550,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testBanningWorks() { public void testBanningWorks() {
mCustomTabsConnection.ban(mAppContext, Process.myUid()); mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
...@@ -578,7 +570,7 @@ public class CustomTabsConnectionTest { ...@@ -578,7 +570,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testBanningDisabledForCellular() { public void testBanningDisabledForCellular() {
mCustomTabsConnection.ban(mAppContext, Process.myUid()); mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.customtabs; package org.chromium.chrome.browser.customtabs;
import android.app.Application;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -38,9 +37,9 @@ public class CustomTabsTestUtils { ...@@ -38,9 +37,9 @@ public class CustomTabsTestUtils {
return intent; return intent;
} }
public static CustomTabsConnection setUpConnection(Application application) { public static CustomTabsConnection setUpConnection() {
CustomTabsConnection connection = CustomTabsConnection.getInstance(application); CustomTabsConnection connection = CustomTabsConnection.getInstance();
connection.resetThrottling(application, Process.myUid()); connection.resetThrottling(Process.myUid());
return connection; return connection;
} }
......
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