Commit c5ced107 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Revert "Chrome retrieves Browser Actions' custom item icons through resource ids"

This reverts commit fa849f85.

Reason for revert: downstream CL is not ready yet.

Original change's description:
> 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: Ted Choc <tedchoc@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#516036}

TBR=tedchoc@chromium.org,yusufo@chromium.org,ltian@chromium.org

Change-Id: Ief3ca089894435000d493ff2af37d35a8003d24e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 775798
Reviewed-on: https://chromium-review.googlesource.com/767807Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516110}
parent 643f77a8
......@@ -303,7 +303,7 @@ deps = {
},
'src/third_party/custom_tabs_client/src': {
'url': Var('chromium_git') + '/external/github.com/GoogleChrome/custom-tabs-client.git' + '@' + 'afe8a13457103292fb1ba49877a0b0e5abdc2f36',
'url': Var('chromium_git') + '/external/github.com/GoogleChrome/custom-tabs-client.git' + '@' + 'cff061038b852d647f7044d828a9df78aa135f38',
'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="androidx.browser.browseractions.browser_action_open" />
<action android:name="android.support.customtabs.browseractions.browser_action_open" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
......
......@@ -40,10 +40,8 @@ public class BrowserActionActivity extends AsyncInitializationActivity {
private int mType;
private Uri mUri;
@VisibleForTesting
String mCreatorPackageName;
@VisibleForTesting
List<BrowserActionItem> mActions = new ArrayList<>();
private String mCreatorPackageName;
private List<BrowserActionItem> mActions = new ArrayList<>();
private PendingIntent mOnBrowserActionSelectedCallback;
private BrowserActionsContextMenuHelper mHelper;
......
......@@ -9,11 +9,6 @@ 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;
......@@ -27,9 +22,7 @@ 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;
......@@ -173,7 +166,7 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback;
mProgressDialog = new ProgressDialog(mActivity);
mItems = buildContextMenuItems(customItems, sourcePackageName);
mItems = buildContextMenuItems(customItems);
}
/**
......@@ -190,11 +183,11 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
* Builds items for Browser Actions context menu.
*/
private List<Pair<Integer, List<ContextMenuItem>>> buildContextMenuItems(
List<BrowserActionItem> customItems, String sourcePackageName) {
List<BrowserActionItem> customItems) {
List<Pair<Integer, List<ContextMenuItem>>> menuItems = new ArrayList<>();
List<ContextMenuItem> items = new ArrayList<>();
items.addAll(mBrowserActionsLinkGroup);
addBrowserActionItems(items, customItems, sourcePackageName);
addBrowserActionItems(items, customItems);
menuItems.add(new Pair<>(R.string.contextmenu_link_title, items));
return menuItems;
......@@ -204,30 +197,12 @@ 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, 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);
}
private void addBrowserActionItems(
List<ContextMenuItem> items, List<BrowserActionItem> customItems) {
for (int i = 0; i < customItems.size() && i < BrowserActionsIntent.MAX_CUSTOM_ITEMS; 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));
items.add(new BrowserActionsCustomContextMenuItem(
CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i)));
mCustomItemActionMap.put(
CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i).getAction());
}
......
......@@ -5,6 +5,8 @@
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;
......@@ -18,18 +20,17 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem {
@IdRes
private final int mMenuId;
private final String mTitle;
private final Drawable mIcon;
private final Bitmap mIcon;
/**
* Constructor to build a custom context menu item from {@link BrowserActionItem}.
* @param id The {@link IdRes} of the custom context menu item.
* @param title The title of the custom context menu item.
* @param icon The icon of the custom context menu item.
* @param item The {@link BrowserActionItem} specifies the title and action of the menu item.
*/
BrowserActionsCustomContextMenuItem(@IdRes int id, String title, Drawable icon) {
BrowserActionsCustomContextMenuItem(@IdRes int id, BrowserActionItem item) {
mMenuId = id;
mTitle = title;
mIcon = icon;
mTitle = item.getTitle();
mIcon = item.getIcon();
}
@Override
......@@ -44,6 +45,6 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem {
@Override
public Drawable getDrawable(Context context) {
return mIcon;
return new BitmapDrawable(context.getResources(), mIcon);
}
}
\ No newline at end of file
......@@ -16,8 +16,6 @@ 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;
......@@ -78,16 +76,7 @@ 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_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 static final String CUSTOM_ITEM_TITLE = "Custom item";
private final CallbackHelper mOnBrowserActionsMenuShownCallback = new CallbackHelper();
private final CallbackHelper mOnFinishNativeInitializationCallback = new CallbackHelper();
......@@ -105,6 +94,7 @@ public class BrowserActionActivityTest {
private String mTestPage;
private String mTestPage2;
private String mTestPage3;
private PendingIntent mCustomPendingItent;
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
......@@ -178,13 +168,8 @@ public class BrowserActionActivityTest {
@Test
@SmallTest
/**
* TODO(ltian): move this to a separate test class only for {@link
* BrowserActionsContextMenuHelper}.
*/
public void testMenuShownCorrectly() throws Exception {
List<BrowserActionItem> items = createCustomItems();
BrowserActionActivity activity = startBrowserActionActivity(mTestPage, items, 0);
startBrowserActionActivity(mTestPage);
// Menu should be shown before native finish loading.
mOnBrowserActionsMenuShownCallback.waitForCallback(0);
......@@ -196,37 +181,19 @@ 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> contextMenuItems = menus.get(0).second;
Assert.assertEquals(5 + items.size(), contextMenuItems.size());
List<ContextMenuItem> items = menus.get(0).second;
Assert.assertEquals(6, items.size());
for (int i = 0; i < 4; i++) {
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(i) instanceof ChromeContextMenuItem);
}
Assert.assertNull(contextMenuItems.get(7).getDrawable(context));
Assert.assertNull(contextMenuItems.get(8).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)));
}
@Test
......@@ -606,12 +573,6 @@ 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);
......@@ -624,7 +585,7 @@ public class BrowserActionActivityTest {
Assert.assertEquals(expectedCallCount, mOnOpenTabInBackgroundStartCallback.getCallCount());
// Fire an Intent to start the BrowserActionActivity.
sendBrowserActionIntent(url, items);
sendBrowserActionIntent(instrumentation, url);
Activity activity = instrumentation.waitForMonitorWithTimeout(
browserActionMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
......@@ -637,24 +598,23 @@ public class BrowserActionActivityTest {
return (BrowserActionActivity) activity;
}
private void sendBrowserActionIntent(String url, List<BrowserActionItem> items) {
Context context = InstrumentationRegistry.getTargetContext();
private void sendBrowserActionIntent(Instrumentation instrumentation, String url) {
Context context = instrumentation.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);
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);
// 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);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, BrowserActionActivity.class);
......@@ -663,30 +623,4 @@ 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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token);
try {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
......@@ -2316,7 +2316,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
final CustomTabsConnection connection = CustomTabsConnection.getInstance();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token);
try {
......@@ -2352,7 +2352,7 @@ public class CustomTabActivityTest {
.getTargetContext()
.getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
CustomTabsSessionToken token2 = CustomTabsSessionToken.createMockSessionTokenForTesting();
CustomTabsSessionToken token2 = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token2));
}
......@@ -200,7 +200,7 @@ public class CustomTabsConnectionTest {
public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() {
CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token));
CustomTabsTestUtils.warmUpAndWait();
......@@ -337,7 +337,7 @@ public class CustomTabsConnectionTest {
@SmallTest
public void testLowConfidenceMayLaunchUrlDoesntCrash() {
final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
token = CustomTabsSessionToken.createDummySessionTokenForTesting();
mCustomTabsConnection.newSession(token);
}
Uri uri = url == null ? null : Uri.parse(url);
......@@ -465,7 +465,7 @@ public class CustomTabsConnectionTest {
@SmallTest
public void testNoMayLaunchUrlWithInvalidSessionId() {
assertWarmupAndMayLaunchUrl(
CustomTabsSessionToken.createMockSessionTokenForTesting(), URL, false);
CustomTabsSessionToken.createDummySessionTokenForTesting(), URL, false);
}
/**
......@@ -621,7 +621,7 @@ public class CustomTabsConnectionTest {
public void testBanningWorks() {
mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionTokenForTesting();
CustomTabsSessionToken.createDummySessionTokenForTesting();
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.createMockSessionForTesting(
CustomTabsSession.createDummySessionForTesting(
new ComponentName(context, ChromeLauncherActivity.class)));
CustomTabsIntent customTabsIntent = builder.build();
Intent intent = customTabsIntent.intent;
......
......@@ -4,7 +4,6 @@
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;
......@@ -14,8 +13,6 @@ 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;
......@@ -30,9 +27,6 @@ import org.robolectric.annotation.Config;
import org.chromium.base.test.util.Feature;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import java.util.ArrayList;
import java.util.List;
/**
* Unit tests for BrowserActionsIntent.
*/
......@@ -45,10 +39,6 @@ public class BrowserActionsIntentTest {
private static final String CONTENT_SCHEME_TEST_URL = "content://example";
private static final String SENDER_PACKAGE_NAME = "some.other.app.package.sender_name";
private static final String RECEIVER_PACKAGE_NAME = "some.other.app.package.receiver_name";
private static final String CUSTOM_ITEM_WITHOUT_ICON_TITLE = "Custom item without icon";
private static final String CUSTOM_ITEM_WITH_ICON_TITLE = "Custom item with icon";
@DrawableRes
private static final int CUSTOM_ITEM_WITH_ICON_ICONID = 1;
private Context mContext;
@Mock
......@@ -95,57 +85,18 @@ public class BrowserActionsIntentTest {
mIntent = createBaseBrowserActionsIntent(HTTP_SCHEME_TEST_URL);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
assertFalse(mActivity.isStartedUpCorrectly(mIntent));
mIntent = createBrowserActionsIntentWithCustomItems(
HTTP_SCHEME_TEST_URL, createCustomItems());
assertTrue(mActivity.isStartedUpCorrectly(mIntent));
testParseCustomItems(mActivity.mActions);
}
/**
* A convenient method to create a simple Intent for Browser Actions without custom item.
* Creates a simple Intent for Browser Actions which contains a url, the {@link
* BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN} action and source package name.
* @param url The url for the data of the Intent.
* @return The simple Intent for Browser Actions.
*/
private Intent createBaseBrowserActionsIntent(String url) {
return createBrowserActionsIntentWithCustomItems(url, new ArrayList<>());
}
/**
* Creates an Intent for Browser Actions which contains a url and a list of custom items.
* @param url The url for the data of the Intent.
* @param items A List of custom items for Browser Actions menu.
* @return The Intent for Browser Actions.
*/
private Intent createBrowserActionsIntentWithCustomItems(
String url, ArrayList<BrowserActionItem> items) {
return new BrowserActionsIntent.Builder(mContext, Uri.parse(url))
.setCustomItems(items)
.build()
.getIntent()
.putExtra(BrowserActionsIntent.EXTRA_APP_ID, mPendingIntent);
}
private ArrayList<BrowserActionItem> createCustomItems() {
BrowserActionItem item1 =
new BrowserActionItem(CUSTOM_ITEM_WITHOUT_ICON_TITLE, mPendingIntent);
BrowserActionItem item2 = new BrowserActionItem(
CUSTOM_ITEM_WITH_ICON_TITLE, mPendingIntent, CUSTOM_ITEM_WITH_ICON_ICONID);