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 = { ...@@ -303,7 +303,7 @@ deps = {
}, },
'src/third_party/custom_tabs_client/src': { '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', 'condition': 'checkout_android',
}, },
......
...@@ -731,7 +731,7 @@ by a child template that "extends" this file. ...@@ -731,7 +731,7 @@ by a child template that "extends" this file.
android:exported="true" android:exported="true"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize"> android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize">
<intent-filter> <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" /> <category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" /> <data android:scheme="http" />
<data android:scheme="https" /> <data android:scheme="https" />
......
...@@ -40,10 +40,8 @@ public class BrowserActionActivity extends AsyncInitializationActivity { ...@@ -40,10 +40,8 @@ public class BrowserActionActivity extends AsyncInitializationActivity {
private int mType; private int mType;
private Uri mUri; private Uri mUri;
@VisibleForTesting private String mCreatorPackageName;
String mCreatorPackageName; private List<BrowserActionItem> mActions = new ArrayList<>();
@VisibleForTesting
List<BrowserActionItem> mActions = new ArrayList<>();
private PendingIntent mOnBrowserActionSelectedCallback; private PendingIntent mOnBrowserActionSelectedCallback;
private BrowserActionsContextMenuHelper mHelper; private BrowserActionsContextMenuHelper mHelper;
......
...@@ -9,11 +9,6 @@ import android.app.PendingIntent; ...@@ -9,11 +9,6 @@ import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException; import android.app.PendingIntent.CanceledException;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent; 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.net.Uri;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.customtabs.browseractions.BrowserActionItem; import android.support.customtabs.browseractions.BrowserActionItem;
...@@ -27,9 +22,7 @@ import android.view.View; ...@@ -27,9 +22,7 @@ import android.view.View;
import android.view.View.OnAttachStateChangeListener; import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnCreateContextMenuListener; import android.view.View.OnCreateContextMenuListener;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
...@@ -173,7 +166,7 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe ...@@ -173,7 +166,7 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback; mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback;
mProgressDialog = new ProgressDialog(mActivity); mProgressDialog = new ProgressDialog(mActivity);
mItems = buildContextMenuItems(customItems, sourcePackageName); mItems = buildContextMenuItems(customItems);
} }
/** /**
...@@ -190,11 +183,11 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe ...@@ -190,11 +183,11 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
* Builds items for Browser Actions context menu. * Builds items for Browser Actions context menu.
*/ */
private List<Pair<Integer, List<ContextMenuItem>>> buildContextMenuItems( private List<Pair<Integer, List<ContextMenuItem>>> buildContextMenuItems(
List<BrowserActionItem> customItems, String sourcePackageName) { List<BrowserActionItem> customItems) {
List<Pair<Integer, List<ContextMenuItem>>> menuItems = new ArrayList<>(); List<Pair<Integer, List<ContextMenuItem>>> menuItems = new ArrayList<>();
List<ContextMenuItem> items = new ArrayList<>(); List<ContextMenuItem> items = new ArrayList<>();
items.addAll(mBrowserActionsLinkGroup); items.addAll(mBrowserActionsLinkGroup);
addBrowserActionItems(items, customItems, sourcePackageName); addBrowserActionItems(items, customItems);
menuItems.add(new Pair<>(R.string.contextmenu_link_title, items)); menuItems.add(new Pair<>(R.string.contextmenu_link_title, items));
return menuItems; return menuItems;
...@@ -204,30 +197,12 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe ...@@ -204,30 +197,12 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
* Adds custom items to the context menu list and populates custom item action map. * 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 items List of {@link ContextMenuItem} to display the context menu.
* @param customItems List of {@link BrowserActionItem} for custom items. * @param customItems List of {@link BrowserActionItem} for custom items.
* @param sourcePackageName The package name of the requested app.
*/ */
private void addBrowserActionItems(List<ContextMenuItem> items, private void addBrowserActionItems(
List<BrowserActionItem> customItems, String sourcePackageName) { List<ContextMenuItem> items, List<BrowserActionItem> customItems) {
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++) { for (int i = 0; i < customItems.size() && i < BrowserActionsIntent.MAX_CUSTOM_ITEMS; i++) {
Drawable drawable = null; items.add(new BrowserActionsCustomContextMenuItem(
if (resources != null && customItems.get(i).getIconId() != 0) { CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i)));
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( mCustomItemActionMap.put(
CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i).getAction()); CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(i), customItems.get(i).getAction());
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
package org.chromium.chrome.browser.browseractions; package org.chromium.chrome.browser.browseractions;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.customtabs.browseractions.BrowserActionItem; import android.support.customtabs.browseractions.BrowserActionItem;
...@@ -18,18 +20,17 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem { ...@@ -18,18 +20,17 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem {
@IdRes @IdRes
private final int mMenuId; private final int mMenuId;
private final String mTitle; private final String mTitle;
private final Drawable mIcon; private final Bitmap mIcon;
/** /**
* Constructor to build a custom context menu item from {@link BrowserActionItem}. * Constructor to build a custom context menu item from {@link BrowserActionItem}.
* @param id The {@link IdRes} of the custom context menu item. * @param id The {@link IdRes} of the custom context menu item.
* @param title The title of the custom context menu item. * @param item The {@link BrowserActionItem} specifies the title and action of the menu item.
* @param icon The icon of the custom context menu item.
*/ */
BrowserActionsCustomContextMenuItem(@IdRes int id, String title, Drawable icon) { BrowserActionsCustomContextMenuItem(@IdRes int id, BrowserActionItem item) {
mMenuId = id; mMenuId = id;
mTitle = title; mTitle = item.getTitle();
mIcon = icon; mIcon = item.getIcon();
} }
@Override @Override
...@@ -44,6 +45,6 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem { ...@@ -44,6 +45,6 @@ public class BrowserActionsCustomContextMenuItem implements ContextMenuItem {
@Override @Override
public Drawable getDrawable(Context context) { 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; ...@@ -16,8 +16,6 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.support.annotation.DrawableRes;
import android.support.customtabs.browseractions.BrowserActionItem;
import android.support.customtabs.browseractions.BrowserActionsIntent; import android.support.customtabs.browseractions.BrowserActionsIntent;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
...@@ -78,16 +76,7 @@ public class BrowserActionActivityTest { ...@@ -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 = "/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_2 = "/chrome/test/data/android/test.html";
private static final String TEST_PAGE_3 = "/chrome/test/data/android/simple.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 = "Custom item";
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 mOnBrowserActionsMenuShownCallback = new CallbackHelper();
private final CallbackHelper mOnFinishNativeInitializationCallback = new CallbackHelper(); private final CallbackHelper mOnFinishNativeInitializationCallback = new CallbackHelper();
...@@ -105,6 +94,7 @@ public class BrowserActionActivityTest { ...@@ -105,6 +94,7 @@ public class BrowserActionActivityTest {
private String mTestPage; private String mTestPage;
private String mTestPage2; private String mTestPage2;
private String mTestPage3; private String mTestPage3;
private PendingIntent mCustomPendingItent;
@Rule @Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule(); public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule @Rule
...@@ -178,13 +168,8 @@ public class BrowserActionActivityTest { ...@@ -178,13 +168,8 @@ public class BrowserActionActivityTest {
@Test @Test
@SmallTest @SmallTest
/**
* TODO(ltian): move this to a separate test class only for {@link
* BrowserActionsContextMenuHelper}.
*/
public void testMenuShownCorrectly() throws Exception { public void testMenuShownCorrectly() throws Exception {
List<BrowserActionItem> items = createCustomItems(); startBrowserActionActivity(mTestPage);
BrowserActionActivity activity = startBrowserActionActivity(mTestPage, items, 0);
// Menu should be shown before native finish loading. // Menu should be shown before native finish loading.
mOnBrowserActionsMenuShownCallback.waitForCallback(0); mOnBrowserActionsMenuShownCallback.waitForCallback(0);
...@@ -196,37 +181,19 @@ public class BrowserActionActivityTest { ...@@ -196,37 +181,19 @@ public class BrowserActionActivityTest {
Assert.assertEquals(1, mOnBrowserActionsMenuShownCallback.getCallCount()); Assert.assertEquals(1, mOnBrowserActionsMenuShownCallback.getCallCount());
Assert.assertEquals(1, mOnFinishNativeInitializationCallback.getCallCount()); Assert.assertEquals(1, mOnFinishNativeInitializationCallback.getCallCount());
Context context = InstrumentationRegistry.getTargetContext();
Assert.assertEquals(context.getPackageName(), activity.mCreatorPackageName);
// Check menu populated correctly. // Check menu populated correctly.
List<Pair<Integer, List<ContextMenuItem>>> menus = mItems; List<Pair<Integer, List<ContextMenuItem>>> menus = mItems;
Assert.assertEquals(1, menus.size()); Assert.assertEquals(1, menus.size());
List<ContextMenuItem> contextMenuItems = menus.get(0).second; List<ContextMenuItem> items = menus.get(0).second;
Assert.assertEquals(5 + items.size(), contextMenuItems.size()); Assert.assertEquals(6, items.size());
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
Assert.assertTrue(contextMenuItems.get(i) instanceof ChromeContextMenuItem); Assert.assertTrue(items.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.assertNull(contextMenuItems.get(7).getDrawable(context)); Assert.assertTrue(items.get(4) instanceof ShareContextMenuItem);
Assert.assertNull(contextMenuItems.get(8).getDrawable(context)); Assert.assertTrue(items.get(5) instanceof BrowserActionsCustomContextMenuItem);
Assert.assertEquals(mCustomPendingItent,
mCustomActions.get(
BrowserActionsContextMenuHelper.CUSTOM_BROWSER_ACTIONS_ID_GROUP.get(0)));
} }
@Test @Test
...@@ -606,12 +573,6 @@ public class BrowserActionActivityTest { ...@@ -606,12 +573,6 @@ public class BrowserActionActivityTest {
private BrowserActionActivity startBrowserActionActivity(String url, int expectedCallCount) private BrowserActionActivity startBrowserActionActivity(String url, int expectedCallCount)
throws Exception { 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(); final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
ActivityMonitor browserActionMonitor = ActivityMonitor browserActionMonitor =
new ActivityMonitor(BrowserActionActivity.class.getName(), null, false); new ActivityMonitor(BrowserActionActivity.class.getName(), null, false);
...@@ -624,7 +585,7 @@ public class BrowserActionActivityTest { ...@@ -624,7 +585,7 @@ public class BrowserActionActivityTest {
Assert.assertEquals(expectedCallCount, mOnOpenTabInBackgroundStartCallback.getCallCount()); Assert.assertEquals(expectedCallCount, mOnOpenTabInBackgroundStartCallback.getCallCount());
// Fire an Intent to start the BrowserActionActivity. // Fire an Intent to start the BrowserActionActivity.
sendBrowserActionIntent(url, items); sendBrowserActionIntent(instrumentation, url);
Activity activity = instrumentation.waitForMonitorWithTimeout( Activity activity = instrumentation.waitForMonitorWithTimeout(
browserActionMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); browserActionMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
...@@ -637,24 +598,23 @@ public class BrowserActionActivityTest { ...@@ -637,24 +598,23 @@ public class BrowserActionActivityTest {
return (BrowserActionActivity) activity; return (BrowserActionActivity) activity;
} }
private void sendBrowserActionIntent(String url, List<BrowserActionItem> items) { private void sendBrowserActionIntent(Instrumentation instrumentation, String url) {
Context context = InstrumentationRegistry.getTargetContext(); Context context = instrumentation.getTargetContext();
Intent intent = new Intent(BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN); Intent intent = new Intent(BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
intent.putExtra(BrowserActionsIntent.EXTRA_TYPE, BrowserActionsIntent.URL_TYPE_NONE); intent.putExtra(BrowserActionsIntent.EXTRA_TYPE, BrowserActionsIntent.URL_TYPE_NONE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
intent.putExtra(BrowserActionsIntent.EXTRA_APP_ID, pendingIntent); intent.putExtra(BrowserActionsIntent.EXTRA_APP_ID, pendingIntent);
ArrayList<Bundle> customItemBundles = new ArrayList<>(); // Add a custom item.
for (BrowserActionItem item : items) { Intent customIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Bundle customItemBundle = new Bundle(); mCustomPendingItent = PendingIntent.getActivity(context, 0, customIntent, 0);
customItemBundle.putString(BrowserActionsIntent.KEY_TITLE, item.getTitle()); Bundle item = new Bundle();
customItemBundle.putInt(BrowserActionsIntent.KEY_ICON_ID, item.getIconId()); item.putString(BrowserActionsIntent.KEY_TITLE, CUSTOM_ITEM_TITLE);
customItemBundle.putParcelable(BrowserActionsIntent.KEY_ACTION, item.getAction()); item.putParcelable(BrowserActionsIntent.KEY_ACTION, mCustomPendingItent);
customItemBundles.add(customItemBundle); ArrayList<Bundle> items = new ArrayList<>();
} items.add(item);
intent.putParcelableArrayListExtra( intent.putParcelableArrayListExtra(BrowserActionsIntent.EXTRA_MENU_ITEMS, items);
BrowserActionsIntent.EXTRA_MENU_ITEMS, customItemBundles);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(context, BrowserActionActivity.class); intent.setClass(context, BrowserActionActivity.class);
...@@ -663,30 +623,4 @@ public class BrowserActionActivityTest { ...@@ -663,30 +623,4 @@ public class BrowserActionActivityTest {
// for test. // for test.
IntentUtils.safeStartActivity(context, intent); 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 { ...@@ -42,7 +42,7 @@ public class ClientManagerTest {
private ClientManager mClientManager; private ClientManager mClientManager;
private CustomTabsSessionToken mSession = private CustomTabsSessionToken mSession =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
private int mUid = Process.myUid(); private int mUid = Process.myUid();
@Before @Before
...@@ -123,7 +123,7 @@ public class ClientManagerTest { ...@@ -123,7 +123,7 @@ public class ClientManagerTest {
mClientManager.newSession(mSession, mUid, null, null); mClientManager.newSession(mSession, mUid, null, null);
Assert.assertEquals(ClientManager.SESSION_WARMUP, mClientManager.getWarmupState(mSession)); Assert.assertEquals(ClientManager.SESSION_WARMUP, mClientManager.getWarmupState(mSession));
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
mClientManager.newSession(token, mUid, null, null); mClientManager.newSession(token, mUid, null, null);
Assert.assertEquals(ClientManager.SESSION_WARMUP, mClientManager.getWarmupState(token)); Assert.assertEquals(ClientManager.SESSION_WARMUP, mClientManager.getWarmupState(token));
} }
......
...@@ -2197,7 +2197,7 @@ public class CustomTabActivityTest { ...@@ -2197,7 +2197,7 @@ public class CustomTabActivityTest {
public void testHiddenTabThirdPartyCookiesBlocked() throws Exception { public void testHiddenTabThirdPartyCookiesBlocked() throws Exception {
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait(); final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
connection.setSpeculationModeForSession( connection.setSpeculationModeForSession(
token, CustomTabsConnection.SpeculationParams.HIDDEN_TAB); token, CustomTabsConnection.SpeculationParams.HIDDEN_TAB);
...@@ -2228,7 +2228,7 @@ public class CustomTabActivityTest { ...@@ -2228,7 +2228,7 @@ public class CustomTabActivityTest {
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait(); final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
connection.setSpeculationModeForSession(token, requestedSpeculationMode); connection.setSpeculationModeForSession(token, requestedSpeculationMode);
Assert.assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, null)); Assert.assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, null));
...@@ -2268,7 +2268,7 @@ public class CustomTabActivityTest { ...@@ -2268,7 +2268,7 @@ public class CustomTabActivityTest {
private void testSpeculateInvalidUrl(int speculationMode) throws Exception { private void testSpeculateInvalidUrl(int speculationMode) throws Exception {
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait(); final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
connection.setSpeculationModeForSession(token, speculationMode); connection.setSpeculationModeForSession(token, speculationMode);
Assert.assertFalse( Assert.assertFalse(
...@@ -2287,7 +2287,7 @@ public class CustomTabActivityTest { ...@@ -2287,7 +2287,7 @@ public class CustomTabActivityTest {
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait(); final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
try { try {
mCustomTabActivityTestRule.startCustomTabActivityWithIntent( mCustomTabActivityTestRule.startCustomTabActivityWithIntent(
...@@ -2316,7 +2316,7 @@ public class CustomTabActivityTest { ...@@ -2316,7 +2316,7 @@ public class CustomTabActivityTest {
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
final CustomTabsConnection connection = CustomTabsConnection.getInstance(); final CustomTabsConnection connection = CustomTabsConnection.getInstance();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
try { try {
...@@ -2352,7 +2352,7 @@ public class CustomTabActivityTest { ...@@ -2352,7 +2352,7 @@ public class CustomTabActivityTest {
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait(); final CustomTabsConnection connection = CustomTabsTestUtils.warmUpAndWait();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
connection.setSpeculationModeForSession(token, speculationMode); connection.setSpeculationModeForSession(token, speculationMode);
Assert.assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, null)); Assert.assertTrue(connection.mayLaunchUrl(token, Uri.parse(mTestPage), null, null));
...@@ -2808,7 +2808,7 @@ public class CustomTabActivityTest { ...@@ -2808,7 +2808,7 @@ public class CustomTabActivityTest {
.getTargetContext() .getTargetContext()
.getApplicationContext(); .getApplicationContext();
CustomTabsConnection connection = CustomTabsTestUtils.setUpConnection(); CustomTabsConnection connection = CustomTabsTestUtils.setUpConnection();
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
connection.newSession(token); connection.newSession(token);
Bundle extras = null; Bundle extras = null;
if (speculationMode == CustomTabsConnection.SpeculationParams.NO_SPECULATION) { if (speculationMode == CustomTabsConnection.SpeculationParams.NO_SPECULATION) {
......
...@@ -79,7 +79,7 @@ public class CustomTabsConnectionTest { ...@@ -79,7 +79,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
public void testNewSession() { public void testNewSession() {
Assert.assertEquals(false, mCustomTabsConnection.newSession(null)); Assert.assertEquals(false, mCustomTabsConnection.newSession(null));
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token)); Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
Assert.assertEquals(false, mCustomTabsConnection.newSession(token)); Assert.assertEquals(false, mCustomTabsConnection.newSession(token));
} }
...@@ -90,9 +90,9 @@ public class CustomTabsConnectionTest { ...@@ -90,9 +90,9 @@ public class CustomTabsConnectionTest {
@Test @Test
@SmallTest @SmallTest
public void testSeveralSessions() { public void testSeveralSessions() {
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token)); Assert.assertEquals(true, mCustomTabsConnection.newSession(token));
CustomTabsSessionToken token2 = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token2 = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertEquals(true, mCustomTabsConnection.newSession(token2)); Assert.assertEquals(true, mCustomTabsConnection.newSession(token2));
} }
...@@ -200,7 +200,7 @@ public class CustomTabsConnectionTest { ...@@ -200,7 +200,7 @@ public class CustomTabsConnectionTest {
public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() { public void testMayLaunchUrlKeepsSpareRendererWithoutPrerendering() {
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
Bundle extras = new Bundle(); Bundle extras = new Bundle();
...@@ -235,7 +235,7 @@ public class CustomTabsConnectionTest { ...@@ -235,7 +235,7 @@ public class CustomTabsConnectionTest {
@RetryOnFailure @RetryOnFailure
public void testOnlyOneHiddenTab() throws Exception { public void testOnlyOneHiddenTab() throws Exception {
Assert.assertTrue("Failed warmup()", mCustomTabsConnection.warmup(0)); Assert.assertTrue("Failed warmup()", mCustomTabsConnection.warmup(0));
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue("Failed newSession()", mCustomTabsConnection.newSession(token)); Assert.assertTrue("Failed newSession()", mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setSpeculationModeForSession( mCustomTabsConnection.setSpeculationModeForSession(
token, CustomTabsConnection.SpeculationParams.HIDDEN_TAB); token, CustomTabsConnection.SpeculationParams.HIDDEN_TAB);
...@@ -288,7 +288,7 @@ public class CustomTabsConnectionTest { ...@@ -288,7 +288,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testUnderstandsLowConfidenceMayLaunchUrl() { public void testUnderstandsLowConfidenceMayLaunchUrl() {
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
List<Bundle> urls = new ArrayList<>(); List<Bundle> urls = new ArrayList<>();
Bundle urlBundle = new Bundle(); Bundle urlBundle = new Bundle();
...@@ -310,7 +310,7 @@ public class CustomTabsConnectionTest { ...@@ -310,7 +310,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
public void testLowConfidenceMayLaunchUrlOnlyAcceptUris() { public void testLowConfidenceMayLaunchUrlOnlyAcceptUris() {
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
...@@ -337,7 +337,7 @@ public class CustomTabsConnectionTest { ...@@ -337,7 +337,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
public void testLowConfidenceMayLaunchUrlDoesntCrash() { public void testLowConfidenceMayLaunchUrlDoesntCrash() {
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
...@@ -364,7 +364,7 @@ public class CustomTabsConnectionTest { ...@@ -364,7 +364,7 @@ public class CustomTabsConnectionTest {
public void testStillHighConfidenceMayLaunchUrlWithSeveralUrls() { public void testStillHighConfidenceMayLaunchUrlWithSeveralUrls() {
CustomTabsConnection.getInstance().setForcePrerender(true); CustomTabsConnection.getInstance().setForcePrerender(true);
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
List<Bundle> urls = new ArrayList<>(); List<Bundle> urls = new ArrayList<>();
Bundle urlBundle = new Bundle(); Bundle urlBundle = new Bundle();
...@@ -389,7 +389,7 @@ public class CustomTabsConnectionTest { ...@@ -389,7 +389,7 @@ public class CustomTabsConnectionTest {
public void testPrefetchOnlyNoPrerenderHasSpareWebContents() { public void testPrefetchOnlyNoPrerenderHasSpareWebContents() {
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
Bundle extras = new Bundle(); Bundle extras = new Bundle();
...@@ -446,7 +446,7 @@ public class CustomTabsConnectionTest { ...@@ -446,7 +446,7 @@ public class CustomTabsConnectionTest {
CustomTabsSessionToken token, String url, boolean shouldSucceed) { CustomTabsSessionToken token, String url, boolean shouldSucceed) {
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
if (token == null) { if (token == null) {
token = CustomTabsSessionToken.createMockSessionTokenForTesting(); token = CustomTabsSessionToken.createDummySessionTokenForTesting();
mCustomTabsConnection.newSession(token); mCustomTabsConnection.newSession(token);
} }
Uri uri = url == null ? null : Uri.parse(url); Uri uri = url == null ? null : Uri.parse(url);
...@@ -465,7 +465,7 @@ public class CustomTabsConnectionTest { ...@@ -465,7 +465,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
public void testNoMayLaunchUrlWithInvalidSessionId() { public void testNoMayLaunchUrlWithInvalidSessionId() {
assertWarmupAndMayLaunchUrl( assertWarmupAndMayLaunchUrl(
CustomTabsSessionToken.createMockSessionTokenForTesting(), URL, false); CustomTabsSessionToken.createDummySessionTokenForTesting(), URL, false);
} }
/** /**
...@@ -621,7 +621,7 @@ public class CustomTabsConnectionTest { ...@@ -621,7 +621,7 @@ public class CustomTabsConnectionTest {
public void testBanningWorks() { public void testBanningWorks() {
mCustomTabsConnection.ban(Process.myUid()); mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null)); Assert.assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
...@@ -641,7 +641,7 @@ public class CustomTabsConnectionTest { ...@@ -641,7 +641,7 @@ public class CustomTabsConnectionTest {
public void testBanningDisabledForCellular() { public void testBanningDisabledForCellular() {
mCustomTabsConnection.ban(Process.myUid()); mCustomTabsConnection.ban(Process.myUid());
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true); mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
...@@ -663,7 +663,7 @@ public class CustomTabsConnectionTest { ...@@ -663,7 +663,7 @@ public class CustomTabsConnectionTest {
@SmallTest @SmallTest
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testCellularPrerenderingDoesntOverrideSettings() throws Exception { public void testCellularPrerenderingDoesntOverrideSettings() throws Exception {
CustomTabsSessionToken token = CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken token = CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true); mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
...@@ -703,7 +703,7 @@ public class CustomTabsConnectionTest { ...@@ -703,7 +703,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testCellularPrerenderingDoesntKillSpareRenderer() throws Exception { public void testCellularPrerenderingDoesntKillSpareRenderer() throws Exception {
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true); mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
...@@ -729,7 +729,7 @@ public class CustomTabsConnectionTest { ...@@ -729,7 +729,7 @@ public class CustomTabsConnectionTest {
@Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
public void testUnmatchedCellularPrerenderingDoesntKillSpareRenderer() throws Exception { public void testUnmatchedCellularPrerenderingDoesntKillSpareRenderer() throws Exception {
final CustomTabsSessionToken token = final CustomTabsSessionToken token =
CustomTabsSessionToken.createMockSessionTokenForTesting(); CustomTabsSessionToken.createDummySessionTokenForTesting();
Assert.assertTrue(mCustomTabsConnection.newSession(token)); Assert.assertTrue(mCustomTabsConnection.newSession(token));
mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true); mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true);
CustomTabsTestUtils.warmUpAndWait(); CustomTabsTestUtils.warmUpAndWait();
......
...@@ -32,7 +32,7 @@ public class CustomTabsTestUtils { ...@@ -32,7 +32,7 @@ public class CustomTabsTestUtils {
public static Intent createMinimalCustomTabIntent( public static Intent createMinimalCustomTabIntent(
Context context, String url) { Context context, String url) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder( CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(
CustomTabsSession.createMockSessionForTesting( CustomTabsSession.createDummySessionForTesting(
new ComponentName(context, ChromeLauncherActivity.class))); new ComponentName(context, ChromeLauncherActivity.class)));
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
Intent intent = customTabsIntent.intent; Intent intent = customTabsIntent.intent;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.browseractions; package org.chromium.chrome.browser.browseractions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
...@@ -14,8 +13,6 @@ import android.app.PendingIntent; ...@@ -14,8 +13,6 @@ import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.DrawableRes;
import android.support.customtabs.browseractions.BrowserActionItem;
import android.support.customtabs.browseractions.BrowserActionsIntent; import android.support.customtabs.browseractions.BrowserActionsIntent;
import org.junit.Before; import org.junit.Before;
...@@ -30,9 +27,6 @@ import org.robolectric.annotation.Config; ...@@ -30,9 +27,6 @@ import org.robolectric.annotation.Config;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.testing.local.LocalRobolectricTestRunner; import org.chromium.testing.local.LocalRobolectricTestRunner;
import java.util.ArrayList;
import java.util.List;
/** /**
* Unit tests for BrowserActionsIntent. * Unit tests for BrowserActionsIntent.
*/ */
...@@ -45,10 +39,6 @@ public class BrowserActionsIntentTest { ...@@ -45,10 +39,6 @@ public class BrowserActionsIntentTest {
private static final String CONTENT_SCHEME_TEST_URL = "content://example"; 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 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 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; private Context mContext;
@Mock @Mock
...@@ -95,57 +85,18 @@ public class BrowserActionsIntentTest { ...@@ -95,57 +85,18 @@ public class BrowserActionsIntentTest {
mIntent = createBaseBrowserActionsIntent(HTTP_SCHEME_TEST_URL); mIntent = createBaseBrowserActionsIntent(HTTP_SCHEME_TEST_URL);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
assertFalse(mActivity.isStartedUpCorrectly(mIntent)); 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. * @param url The url for the data of the Intent.
* @return The simple Intent for Browser Actions. * @return The simple Intent for Browser Actions.
*/ */
private Intent createBaseBrowserActionsIntent(String url) { 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)) return new BrowserActionsIntent.Builder(mContext, Uri.parse(url))
.setCustomItems(items)
.build() .build()
.getIntent() .getIntent()
.putExtra(BrowserActionsIntent.EXTRA_APP_ID, mPendingIntent); .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);
ArrayList<BrowserActionItem> items = new ArrayList<>();
items.add(item1);
items.add(item2);
return items;
}
private void testParseCustomItems(List<BrowserActionItem> items) {
assertEquals(2, mActivity.mActions.size());
assertEquals(CUSTOM_ITEM_WITHOUT_ICON_TITLE, mActivity.mActions.get(0).getTitle());
assertEquals(0, mActivity.mActions.get(0).getIconId());
assertEquals(mPendingIntent, mActivity.mActions.get(0).getAction());
assertEquals(CUSTOM_ITEM_WITH_ICON_TITLE, mActivity.mActions.get(1).getTitle());
assertEquals(CUSTOM_ITEM_WITH_ICON_ICONID, mActivity.mActions.get(1).getIconId());
assertEquals(mPendingIntent, mActivity.mActions.get(1).getAction());
}
} }
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