| Index: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
|
| index c21c597060dadc6b1c6c1be566f429735c13cec7..fefdb83c8ae7fcc68559b0518777cb245702183d 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
|
| @@ -18,6 +18,7 @@ import android.content.res.Resources;
|
| import android.graphics.Bitmap;
|
| import android.graphics.Color;
|
| import android.graphics.drawable.BitmapDrawable;
|
| +import android.graphics.drawable.ColorDrawable;
|
| import android.net.Uri;
|
| import android.os.Build;
|
| import android.os.Bundle;
|
| @@ -29,6 +30,7 @@ import android.test.suitebuilder.annotation.SmallTest;
|
| import android.view.Menu;
|
| import android.view.MenuItem;
|
| import android.view.View;
|
| +import android.view.ViewGroup;
|
| import android.widget.ImageButton;
|
|
|
| import org.chromium.base.ThreadUtils;
|
| @@ -99,6 +101,8 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
|
| "chrome/test/data/android/test.html");
|
| private static final String TEST_MENU_TITLE = "testMenuTitle";
|
|
|
| + private static int sIdToIncrement = 0;
|
| +
|
| private CustomTabActivity mActivity;
|
|
|
| @Override
|
| @@ -161,6 +165,21 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
|
| return pi;
|
| }
|
|
|
| + private Bundle makeBottombarBundle(int id, Bitmap icon, String description) {
|
| + Bundle bundle = new Bundle();
|
| + Intent testIntent = new Intent();
|
| + testIntent.setClass(getInstrumentation().getContext(), DummyBroadcastReceiver.class);
|
| + testIntent.setAction(TEST_ACTION);
|
| + PendingIntent pi = PendingIntent.getBroadcast(getInstrumentation().getTargetContext(), 0,
|
| + testIntent, 0);
|
| +
|
| + bundle.putInt(CustomTabsIntent.KEY_ID, sIdToIncrement++);
|
| + bundle.putString(CustomTabsIntent.KEY_DESCRIPTION, description);
|
| + bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pi);
|
| + bundle.putParcelable(CustomTabsIntent.KEY_ICON, icon);
|
| + return bundle;
|
| + }
|
| +
|
| private void openAppMenuAndAssertMenuShown() throws InterruptedException {
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @Override
|
| @@ -189,6 +208,13 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
|
| return actualMenuSize;
|
| }
|
|
|
| + private Bitmap createTestBitmap(int widthDp, int heightDp) {
|
| + Resources testRes = getInstrumentation().getTargetContext().getResources();
|
| + float density = testRes.getDisplayMetrics().density;
|
| + return Bitmap.createBitmap((int) (widthDp * density),
|
| + (int) (heightDp * density), Bitmap.Config.ARGB_8888);
|
| + }
|
| +
|
| /**
|
| * Test the entries in the context menu shown when long clicking an image.
|
| */
|
| @@ -412,13 +438,7 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
|
| */
|
| @SmallTest
|
| public void testActionButton() throws InterruptedException {
|
| - final int iconHeightDp = 48;
|
| - final int iconWidthDp = 96;
|
| - Resources testRes = getInstrumentation().getTargetContext().getResources();
|
| - float density = testRes.getDisplayMetrics().density;
|
| - Bitmap expectedIcon = Bitmap.createBitmap((int) (iconWidthDp * density),
|
| - (int) (iconHeightDp * density), Bitmap.Config.ARGB_8888);
|
| -
|
| + Bitmap expectedIcon = createTestBitmap(96, 48);
|
| Intent intent = createMinimalCustomTabIntent();
|
| final PendingIntent pi = addActionButtonToIntent(intent, expectedIcon, "Good test");
|
| startCustomTabActivityWithIntent(intent);
|
| @@ -460,13 +480,7 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
|
| */
|
| @SmallTest
|
| public void testActionButtonBadRatio() throws InterruptedException {
|
| - final int iconHeightDp = 20;
|
| - final int iconWidthDp = 60;
|
| - Resources testRes = getInstrumentation().getTargetContext().getResources();
|
| - float density = testRes.getDisplayMetrics().density;
|
| - Bitmap expectedIcon = Bitmap.createBitmap((int) (iconWidthDp * density),
|
| - (int) (iconHeightDp * density), Bitmap.Config.ARGB_8888);
|
| -
|
| + Bitmap expectedIcon = createTestBitmap(60, 20);
|
| Intent intent = createMinimalCustomTabIntent();
|
| addActionButtonToIntent(intent, expectedIcon, "Good test");
|
| startCustomTabActivityWithIntent(intent);
|
| @@ -485,6 +499,38 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase {
|
| }
|
|
|
| @SmallTest
|
| + public void testBottombar() throws InterruptedException {
|
| + final int expectedColor = Color.RED;
|
| + final int itemNum = 3;
|
| + final Bitmap expectedIcon = createTestBitmap(48, 24);
|
| +
|
| + Intent intent = createMinimalCustomTabIntent();
|
| + intent.putExtra(CustomTabsIntent.EXTRA_BOTTOM_BAR_COLOR, expectedColor);
|
| +
|
| + ArrayList<Bundle> bundles = new ArrayList<>();
|
| + for (int i = 0; i < itemNum; i++) {
|
| + Bundle bundle = makeBottombarBundle(i, expectedIcon, Integer.valueOf(i).toString());
|
| + bundles.add(bundle);
|
| + }
|
| + intent.putExtra(CustomTabsIntent.EXTRA_BOTTOM_BAR_ITEMS, bundles);
|
| + startCustomTabActivityWithIntent(intent);
|
| +
|
| + ViewGroup bottombar = (ViewGroup) getActivity().findViewById(R.id.bottombar);
|
| + assertNotNull(bottombar);
|
| + assertEquals("Bottombar not showing customized color.",
|
| + expectedColor, ((ColorDrawable) bottombar.getBackground()).getColor());
|
| + assertEquals("Bottombar showing incorrect number of buttons.",
|
| + itemNum, bottombar.getChildCount());
|
| + for (int i = 0; i < itemNum; i++) {
|
| + ImageButton button = (ImageButton) bottombar.getChildAt(i);
|
| + assertTrue("Bottombar button does not have the correct bitmap.",
|
| + expectedIcon.sameAs(((BitmapDrawable) button.getDrawable()).getBitmap()));
|
| + assertEquals("Bottombar button does not have correct content description",
|
| + Integer.valueOf(i).toString(), button.getContentDescription());
|
| + }
|
| + }
|
| +
|
| + @SmallTest
|
| public void testLaunchWithSession() throws InterruptedException {
|
| IBinder session = warmUpAndLaunchUrlWithSession();
|
| assertEquals(mActivity.getIntentDataProvider().getSession(), session);
|
|
|