Commit fa849f85 authored by Lei Tian's avatar Lei Tian Committed by Commit Bot

Chrome retrieves Browser Actions' custom item icons through resource ids

Browser Actions will pass only the resource ids of the custom items'
icons through the Intent, instead of passing the whole Bitmaps. Then
with the source package name, Chrome can retrieve the client app's
Resources by PackageManager.getResourcesForApplication() and use it to
get the icons.

Bug: 775798
Change-Id: Ia63f07a6245673df63e71b550ffff2f63753964f
Reviewed-on: https://chromium-review.googlesource.com/758745
Commit-Queue: Lei Tian <ltian@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516036}
parent a317bd1a
......@@ -303,7 +303,7 @@ deps = {
},
'src/third_party/custom_tabs_client/src': {
'url': Var('chromium_git') + '/external/github.com/GoogleChrome/custom-tabs-client.git' + '@' + 'cff061038b852d647f7044d828a9df78aa135f38',
'url': Var('chromium_git') + '/external/github.com/GoogleChrome/custom-tabs-client.git' + '@' + 'afe8a13457103292fb1ba49877a0b0e5abdc2f36',
'condition': 'checkout_android',
},
......
......@@ -731,7 +731,7 @@ by a child template that "extends" this file.
android:exported="true"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize">
<intent-filter>
<action android:name="android.support.customtabs.browseractions.browser_action_open" />
<action android:name="androidx.browser.browseractions.browser_action_open" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
......
......@@ -40,8 +40,10 @@ public class BrowserActionActivity extends AsyncInitializationActivity {
private int mType;
private Uri mUri;
private String mCreatorPackageName;
private List<BrowserActionItem> mActions = new ArrayList<>();
@VisibleForTesting
String mCreatorPackageName;
@VisibleForTesting
List<BrowserActionItem> mActions = new ArrayList<>();
private PendingIntent mOnBrowserActionSelectedCallback;
private BrowserActionsContextMenuHelper mHelper;
......
......@@ -9,6 +9,11 @@ import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.annotation.IntDef;
import android.support.customtabs.browseractions.BrowserActionItem;
......@@ -22,7 +27,9 @@ import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnCreateContextMenuListener;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram;
......@@ -166,7 +173,7 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback;
mProgressDialog = new ProgressDialog(mActivity);
mItems = buildContextMenuItems(customItems);
mItems = buildContextMenuItems(customItems, sourcePackageName);
}
/**
......@@ -183,11 +190,11 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
* Builds items for Browser Actions context menu.
*/
private List<Pair<Integer, List<ContextMenuItem>>> buildContextMenuItems(
List<BrowserActionItem> customItems) {
List<BrowserActionItem> customItems, String sourcePackageName) {
List<Pair<Integer, List<ContextMenuItem>>> menuItems = new ArrayList<>();
List<ContextMenuItem> items = new ArrayList<>();
items.addAll(mBrowserActionsLinkGroup);
addBrowserActionItems(items, customItems);
addBrowserActionItems(items, customItems, sourcePackageName);
menuItems.add(new Pair<>(R.string.contextmenu_link_title, items));
return menuItems;
......@@ -197,12 +204,30 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
* Adds custom items to the context menu list and populates custom item action map.
* @param items List of {@link ContextMenuItem} to display the context menu.
* @param customItems List of {@link BrowserActionItem} for custom items.
* @param sourcePackageName The package name of the requested app.
*/
private void addBrowserActionItems(
List<ContextMenuItem> items, List<BrowserActionItem> customItems) {
private void addBrowserActionItems(List<ContextMenuItem> items,
List<BrowserActionItem> customItems, String sourcePackageName) {
PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
Resources resources = null;
try {
resources = pm.getResourcesForApplication(sourcePackageName);
} catch (NameNotFoundException e) {
Log.e(TAG, "Fail to find the resources", e);
}
for (int i = 0; i < customItems.size() && i < BrowserActionsIntent.MAX_CUSTOM_ITEMS; i++) {
items.add(new BrowserActionsCustomContextMenuItem(
CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i)));
Drawable drawable = null;
if (resources != null && customItems.get(i).getIconId() != 0) {
try {
drawable = ApiCompatibilityUtils.getDrawable(
resources, customItems.get(i).getIconId());
} catch (NotFoundException e) {
Log.e(TAG, "Cannot get Drawable for %s", customItems.get(i).getTitle(), e);
}
}
items.add(
new BrowserActionsCustomContextMenuItem(CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i),
customItems.get(i).getTitle(), drawable));
mCustomItemActionMap.put(
CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i).getAction());
}
......
......@@ -5,8 +5,6 @@
package org.chromium.chrome.browser.browseractions;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.IdRes;
import android.support.customtabs.browseractions.BrowserActionItem;
......@@ -20,17 +18,18 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem {
@IdRes
private final int mMenuId;
private final String mTitle;
private final Bitmap mIcon;
private final Drawable mIcon;
/**
* Constructor to build a custom context menu item from {@link BrowserActionItem}.
* @param id The {@link IdRes} of the custom context menu item.
* @param item The {@link BrowserActionItem} specifies the title and action of the menu item.
* @param title The title of the custom context menu item.
* @param icon The icon of the custom context menu item.
*/
BrowserActionsCustomContextMenuItem(@IdRes int id, BrowserActionItem item) {
BrowserActionsCustomContextMenuItem(@IdRes int id, String title, Drawable icon) {
mMenuId = id;
mTitle = item.getTitle();
mIcon = item.getIcon();
mTitle = title;
mIcon = icon;
}
@Override
......@@ -45,6 +44,6 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem {
@Override
public Drawable getDrawable(Context context) {
return new BitmapDrawable(context.getResources(), mIcon);
return mIcon;
}
}
\ No newline at end of file
......@@ -16,6 +16,8 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.annotation.DrawableRes;
import android.support.customtabs.browseractions.BrowserActionItem;
import android.support.customtabs.browseractions.BrowserActionsIntent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
......@@ -76,7 +78,16 @@ public class BrowserActionActivityTest {
private static final String TEST_PAGE = "/chrome/test/data/android/google.html";
private static final String TEST_PAGE_2 = "/chrome/test/data/android/test.html";
private static final String TEST_PAGE_3 = "/chrome/test/data/android/simple.html";
private static final String CUSTOM_ITEM_TITLE = "Custom item";
private static final String CUSTOM_ITEM_TITLE_1 = "Custom item with drawable icon";
private static final String CUSTOM_ITEM_TITLE_2 = "Custom item with vector drawable icon";
private static final String CUSTOM_ITEM_TITLE_3 = "Custom item wit invalid icon id";
private static final String CUSTOM_ITEM_TITLE_4 = "Custom item without icon";
@DrawableRes
private static final int CUSTOM_ITEM_ICON_BITMAP_DRAWABLE_ID = R.drawable.star_green;
@DrawableRes
private static final int CUSTOM_ITEM_ICON_VECTOR_DRAWABLE_ID = R.drawable.ic_add;
@DrawableRes
private static final int CUSTOM_ITEM_ICON_INVALID_DRAWABLE_ID = -1;
private final CallbackHelper mOnBrowserActionsMenuShownCallback = new CallbackHelper();
private final CallbackHelper mOnFinishNativeInitializationCallback = new CallbackHelper();
......@@ -94,7 +105,6 @@ public class BrowserActionActivityTest {
private String mTestPage;
private String mTestPage2;
private String mTestPage3;
private PendingIntent mCustomPendingItent;
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
......@@ -168,8 +178,13 @@ public class BrowserActionActivityTest {
@Test
@SmallTest
/**
* TODO(ltian): move this to a separate test class only for {@link
* BrowserActionsContextMenuHelper}.
*/
public void testMenuShownCorrectly() throws Exception {
startBrowserActionActivity(mTestPage);
List<BrowserActionItem> items = createCustomItems();
BrowserActionActivity activity = startBrowserActionActivity(mTestPage, items, 0);
// Menu should be shown before native finish loading.
mOnBrowserActionsMenuShownCallback.waitForCallback(0);
......@@ -181,19 +196,37 @@ public class BrowserActionActivityTest {
Assert.assertEquals(1, mOnBrowserActionsMenuShownCallback.getCallCount());
Assert.assertEquals(1, mOnFinishNativeInitializationCallback.getCallCount());
Context context = InstrumentationRegistry.getTargetContext();
Assert.assertEquals(context.getPackageName(), activity.mCreatorPackageName);
// Check menu populated correctly.
List<Pair<Integer, List<ContextMenuItem>>> menus = mItems;
Assert.assertEquals(1, menus.size());
List<ContextMenuItem> items = menus.get(0).second;
Assert.assertEquals(6, items.size());
List<ContextMenuItem> contextMenuItems = menus.get(0).second;
Assert.assertEquals(5 + items.size(), contextMenuItems.size());
for (int i = 0; i < 4; i++) {
Assert.assertTrue(items.get(i) instanceof ChromeContextMenuItem);
Assert.assertTrue(contextMenuItems.get(i) instanceof ChromeContextMenuItem);
}
Assert.assertTrue(contextMenuItems.get(4) instanceof ShareContextMenuItem);
Assert.assertTrue(contextMenuItems.get(5) instanceof BrowserActionsCustomContextMenuItem);
// Load custom items correctly.
for (int i = 0; i < items.size(); i++) {
Assert.assertEquals(
items.get(i).getTitle(), contextMenuItems.get(5 + i).getTitle(context));
Assert.assertEquals(items.get(i).getAction(),
mCustomActions.get(
BrowserActionsContextMenuHelper.CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(
i)));
}
Assert.assertNotNull(contextMenuItems.get(5).getDrawable(context));
// Vector Drawable is not supported on pre-L so the icon will be null.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Assert.assertNotNull(contextMenuItems.get(6).getDrawable(context));
} else {
Assert.assertNull(contextMenuItems.get(6).getDrawable(context));
}
Assert.assertTrue(items.get(4) instanceof ShareContextMenuItem);
Assert.assertTrue(items.get(5) instanceof BrowserActionsCustomContextMenuItem);
Assert.assertEquals(mCustomPendingItent,
mCustomActions.get(
BrowserActionsContextMenuHelper.CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(0)));
Assert.assertNull(contextMenuItems.get(7).getDrawable(context));
Assert.assertNull(contextMenuItems.get(8).getDrawable(context));
}
@Test
......@@ -573,6 +606,12 @@ public class BrowserActionActivityTest {
private BrowserActionActivity startBrowserActionActivity(String url, int expectedCallCount)
throws Exception {
Context context = InstrumentationRegistry.getTargetContext();
return startBrowserActionActivity(url, new ArrayList<>(), expectedCallCount);
}
private BrowserActionActivity startBrowserActionActivity(
String url, List<BrowserActionItem> items, int expectedCallCount) throws Exception {
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
ActivityMonitor browserActionMonitor =
new ActivityMonitor(BrowserActionActivity.class.getName(), null, false);
......@@ -585,7 +624,7 @@ public class BrowserActionActivityTest {
Assert.assertEquals(expectedCallCount, mOnOpenTabInBackgroundStartCallback.getCallCount());
// Fire an Intent to start the BrowserActionActivity.
sendBrowserActionIntent(instrumentation, url);
sendBrowserActionIntent(url, items);
Activity activity = instrumentation.waitForMonitorWithTimeout(
browserActionMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
......@@ -598,23 +637,24 @@ public class BrowserActionActivityTest {
return (BrowserActionActivity) activity;
}
private void sendBrowserActionIntent(Instrumentation instrumentation, String url) {
Context context = instrumentation.getTargetContext();
private void sendBrowserActionIntent(String url, List<BrowserActionItem> items) {
Context context = InstrumentationRegistry.getTargetContext();
Intent intent = new Intent(BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN);
intent.setData(Uri.parse(url));
intent.putExtra(BrowserActionsIntent.EXTRA_TYPE, BrowserActionsIntent.URL_TYPE_NONE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
intent.putExtra(BrowserActionsIntent.EXTRA_APP_ID, pendingIntent);
// Add a custom item.
Intent customIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
mCustomPendingItent = PendingIntent.getActivity(context, 0, customIntent, 0);
Bundle item = new Bundle();
item.putString(BrowserActionsIntent.KEY_TITLE, CUSTOM_ITEM_TITLE);
item.putParcelable(BrowserActionsIntent.KEY_ACTION, mCustomPendingItent);
ArrayList<Bundle> items = new ArrayList<>();
items.add(item);
intent.putParcelableArrayListExtra(BrowserActionsIntent.EXTRA_MENU_ITEMS, items);
ArrayList<Bundle> customItemBundles = new ArrayList<>();
for (BrowserActionItem item : items) {
Bundle customItemBundle = new Bundle();
customItemBundle.putString(BrowserActionsIntent.KEY_TITLE, item.getTitle());
customItemBundle.putInt(BrowserActionsIntent.KEY_ICON_ID, item.getIconId());
customItemBundle.putParcelable(BrowserActionsIntent.KEY_ACTION, item.getAction());
customItemBundles.add(customItemBundle);
}
intent.putParcelableArrayListExtra(
BrowserActionsIntent.EXTRA_MENU_ITEMS, customItemBundles);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, BrowserActionActivity.class);
......@@ -623,4 +663,30 @@ public class BrowserActionActivityTest {
// for test.
IntentUtils.safeStartActivity(context, intent);
}
private PendingIntent createCustomItemAction(String url) {
Context context = InstrumentationRegistry.getTargetContext();
Intent customIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
return PendingIntent.getActivity(context, 0, customIntent, 0);
}
private List<BrowserActionItem> createCustomItems() {
List<BrowserActionItem> items = new ArrayList<>();
PendingIntent action1 = createCustomItemAction(mTestPage);
BrowserActionItem item1 = new BrowserActionItem(
CUSTOM_ITEM_TITLE_1, action1, CUSTOM_ITEM_ICON_BITMAP_DRAWABLE_ID);
PendingIntent action2 = createCustomItemAction(mTestPage);
BrowserActionItem item2 = new BrowserActionItem(
CUSTOM_ITEM_TITLE_2, action2, CUSTOM_ITEM_ICON_VECTOR_DRAWABLE_ID);
PendingIntent action3 = createCustomItemAction(mTestPage);
BrowserActionItem item3 = new BrowserActionItem(
CUSTOM_ITEM_TITLE_3, action3, CUSTOM_ITEM_ICON_INVALID_DRAWABLE_ID);
PendingIntent action4 = createCustomItemAction(mTestPage);
BrowserActionItem item4 = new BrowserActionItem(CUSTOM_ITEM_TITLE_4, action4);
items.add(item1);
items.add(item2);
items.add(item3);
items.add(item4);
return items;
}
}
......@@ -42,7 +42,7 @@ public class ClientManagerTest {
private ClientManager mClientManager;
private CustomTabsSessionToken mSession =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
private int mUid = Process.myUid();
@Before
......@@ -123,7 +123,7 @@ public class ClientManagerTest {
mClientManager.newSession(mSession, mUid, null, null);
Assert.assertEquals(ClientManager.SESSION_WARMUP, mClientManager.getWarmupState(mSession));
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
mClientManager.newSession(token, mUid, null, null);
Assert.assertEquals(ClientManager.SESSION_WARMUP, mClientManager.getWarmupState(token));
}
......
......@@ -2197,7 +2197,7 @@ public class CustomTabActivityTest {
public void testHiddenTabThirdPartyCookiesBlocked() throws Exception {
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
connection.setSpeculationModeForSession(
token, CustomTabsConnection.SpeculationParams.HIDDEN_TAB);
......@@ -2228,7 +2228,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
connection.setSpeculationModeForSession(token, requestedSpeculationMode);
Assert.assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, null));
......@@ -2268,7 +2268,7 @@ public class CustomTabActivityTest {
private void testSpeculateInvalidUrl(int speculationMode) throws Exception {
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
connection.setSpeculationModeForSession(token, speculationMode);
Assert.assertFalse(
......@@ -2287,7 +2287,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
try {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
......@@ -2316,7 +2316,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
final CustomTabsConnection connection = CustomTabsConnection.getInstance();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
try {
......@@ -2352,7 +2352,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
connection.setSpeculationModeForSession(token, speculationMode);
Assert.assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, null));
......@@ -2808,7 +2808,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
CustomTabsConnection connection = CustomTabsTestUtils.setUpConnection();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
connection.newSession(token);
Bundle extras = null;
if (speculationMode == CustomTabsConnection.SpeculationParams.NO_SPECULATION) {
......
......@@ -79,7 +79,7 @@ public class CustomTabsConnectionTest {
@SmallTest
public void testNewSession() {
Assert.assertEquals(false, mCustomTabsConnection.newSession(null));
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
Assert.assertEquals(false, mCustomTabsConnection.newSession(token));
}
......@@ -90,9 +90,9 @@ public class CustomTabsConnectionTest {
@Test
@SmallTest
public void testSeveralSessions() {
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
CustomTabsSessionToken token2 = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token2 = CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token2));
}
......@@ -200,7 +200,7 @@ public class CustomTabsConnectionTest {
public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() {
CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
Bundle extras = new Bundle();
......@@ -235,7 +235,7 @@ public class CustomTabsConnectionTest {
@RetryOnFailure
public void testOnlyOneHiddenTab() throws Exception {
Assert.assertTrue("Failed warmup()", mCustomTabsConnection.warmup(0));
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue("Failed newSession()", mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setSpeculationModeForSession(
token, CustomTabsConnection.SpeculationParams.HIDDEN_TAB);
......@@ -288,7 +288,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testUnderstandsLowConfidenceMayLaunchUrl() {
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
List<Bundle> urls = new ArrayList<>();
Bundle urlBundle = new Bundle();
......@@ -310,7 +310,7 @@ public class CustomTabsConnectionTest {
@SmallTest
public void testLowConfidenceMayLaunchUrlOnlyAcceptUris() {
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
CustomTabsTestUtils.warmUpAndWait();
......@@ -337,7 +337,7 @@ public class CustomTabsConnectionTest {
@SmallTest
public void testLowConfidenceMayLaunchUrlDoesntCrash() {
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
CustomTabsTestUtils.warmUpAndWait();
......@@ -364,7 +364,7 @@ public class CustomTabsConnectionTest {
public void testStillHighConfidenceMayLaunchUrlWithSeveralUrls() {
CustomTabsConnection.getInstance().setForcePrerender(true);
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
List<Bundle> urls = new ArrayList<>();
Bundle urlBundle = new Bundle();
......@@ -389,7 +389,7 @@ public class CustomTabsConnectionTest {
public void testPrefetchOnlyNoPrerenderHasSpareWebContents() {
CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
Bundle extras = new Bundle();
......@@ -446,7 +446,7 @@ public class CustomTabsConnectionTest {
CustomTabsSessionToken token, String url, boolean shouldSucceed) {
CustomTabsTestUtils.warmUpAndWait();
if (token == null) {
token = CustomTabsSessionToken.createDummySessionTokenForTesting();
token = CustomTabsSessionToken.createMockSessionTokenForTesting();
mCustomTabsConnection.newSession(token);
}
Uri uri = url == null ? null : Uri.parse(url);
......@@ -465,7 +465,7 @@ public class CustomTabsConnectionTest {
@SmallTest
public void testNoMayLaunchUrlWithInvalidSessionId() {
assertWarmupAndMayLaunchUrl(
CustomTabsSessionToken.createDummySessionTokenForTesting(), URL, false);
CustomTabsSessionToken.createMockSessionTokenForTesting(), URL, false);
}
/**
......@@ -621,7 +621,7 @@ public class CustomTabsConnectionTest {
public void testBanningWorks() {
mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
......@@ -641,7 +641,7 @@ public class CustomTabsConnectionTest {
public void testBanningDisabledForCellular() {
mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
......@@ -663,7 +663,7 @@ public class CustomTabsConnectionTest {
@SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testCellularPrerenderingDoesntOverrideSettings() throws Exception {
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
CustomTabsTestUtils.warmUpAndWait();
......@@ -703,7 +703,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testCellularPrerenderingDoesntKillSpareRenderer() throws Exception {
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
CustomTabsTestUtils.warmUpAndWait();
......@@ -729,7 +729,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testUnmatchedCellularPrerenderingDoesntKillSpareRenderer() throws Exception {
final CustomTabsSessionToken token =
CustomTabsSessionToken.createDummySessionTokenForTesting();
CustomTabsSessionToken.createMockSessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
CustomTabsTestUtils.warmUpAndWait();
......
......@@ -32,7 +32,7 @@ public class CustomTabsTestUtils {
public static Intent createMinimalCustomTabIntent(
Context context, String url) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(
CustomTabsSession.createDummySessionForTesting(
CustomTabsSession.createMockSessionForTesting(
new ComponentName(context, ChromeLauncherActivity.class)));
CustomTabsIntent customTabsIntent = builder.build();
Intent intent = customTabsIntent.intent;
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.browseractions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
......@@ -13,6 +14,8 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.DrawableRes;
import android.support.customtabs.browseractions.BrowserActionItem;
import android.support.customtabs.browseractions.BrowserActionsIntent;
import org.junit.Before;
......@@ -27,6 +30,9 @@ import org.robolectric.annotation.Config;
import org.chromium.base.test.util.Feature;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import java.util.ArrayList;