| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
|
| index 366b10dccc823f2de83ba843fea74e5cf8c48888..6b11db39af85668ba7f50033243c50fbafbb4bec 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
|
| @@ -5,11 +5,15 @@
|
| package org.chromium.chrome.browser;
|
|
|
| import android.app.Dialog;
|
| +import android.graphics.drawable.Drawable;
|
| +import android.support.graphics.drawable.VectorDrawableCompat;
|
| import android.support.test.filters.LargeTest;
|
| +import android.test.MoreAsserts;
|
| import android.test.UiThreadTest;
|
| import android.text.SpannableString;
|
| import android.view.View;
|
| import android.widget.Button;
|
| +import android.widget.ImageView;
|
| import android.widget.ListView;
|
|
|
| import org.chromium.base.ThreadUtils;
|
| @@ -34,6 +38,16 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
|
|
|
| String mLastSelectedId = "None";
|
|
|
| + Drawable mTestDrawable1;
|
| + Drawable mTestDrawableSelected1;
|
| + String mTestDrawableDescription1;
|
| + ItemChooserDialog.ItemChooserRowIcon mTestIcon1;
|
| +
|
| + Drawable mTestDrawable2;
|
| + Drawable mTestDrawableSelected2;
|
| + String mTestDrawableDescription2;
|
| + ItemChooserDialog.ItemChooserRowIcon mTestIcon2;
|
| +
|
| public ItemChooserDialogTest() {
|
| super(ChromeActivity.class);
|
| }
|
| @@ -44,6 +58,24 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
|
| protected void setUp() throws Exception {
|
| super.setUp();
|
| mChooserDialog = createDialog();
|
| +
|
| + mTestDrawable1 = getNewTestDrawable();
|
| + mTestDrawableSelected1 = getNewTestDrawable();
|
| + MoreAsserts.assertNotEqual(
|
| + mTestDrawable1.getConstantState(), mTestDrawableSelected1.getConstantState());
|
| + mTestDrawableDescription1 = "icon1 description";
|
| + mTestIcon1 = new ItemChooserDialog.ItemChooserRowIcon(
|
| + mTestDrawable1, mTestDrawableSelected1, mTestDrawableDescription1);
|
| +
|
| + mTestDrawable2 = getNewTestDrawable();
|
| + mTestDrawableSelected2 = getNewTestDrawable();
|
| + MoreAsserts.assertNotEqual(
|
| + mTestDrawable2.getConstantState(), mTestDrawableSelected2.getConstantState());
|
| + mTestDrawableDescription2 = "icon2 description";
|
| + mTestIcon2 = new ItemChooserDialog.ItemChooserRowIcon(
|
| + mTestDrawable2, mTestDrawableSelected2, mTestDrawableDescription2);
|
| +
|
| + assertFalse(ItemChooserDialog.ItemChooserRowIcon.equals(mTestIcon1, mTestIcon2));
|
| }
|
|
|
| @Override
|
| @@ -58,6 +90,14 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
|
| mLastSelectedId = id;
|
| }
|
|
|
| + private Drawable getNewTestDrawable() {
|
| + Drawable drawable = VectorDrawableCompat.create(
|
| + getActivity().getResources(), R.drawable.ic_bluetooth_connected, null);
|
| + // Calling mutate() on a Drawable should typically create a new ConstantState
|
| + // for that Drawable.
|
| + return drawable.mutate();
|
| + }
|
| +
|
| private ItemChooserDialog createDialog() {
|
| SpannableString title = new SpannableString("title");
|
| SpannableString searching = new SpannableString("searching");
|
| @@ -117,6 +157,340 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
|
| }));
|
| }
|
|
|
| + private ImageView getIconImageView(ListView items, int pos) {
|
| + final int first = items.getFirstVisiblePosition();
|
| + final int last = items.getLastVisiblePosition();
|
| + View item;
|
| + if (pos < first || pos > last) {
|
| + item = items.getAdapter().getView(pos, null, items);
|
| + } else {
|
| + final int visiblePos = pos - first;
|
| + item = items.getChildAt(visiblePos);
|
| + }
|
| + return (ImageView) item.findViewById(R.id.icon);
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testAddItemsWithNoIcons() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.GONE, icon1.getVisibility());
|
| + assertEquals(null, icon1.getDrawable());
|
| + }
|
| +
|
| + {
|
| + // Add item 2 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key2", "desc2");
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + assertEquals(View.GONE, icon2.getVisibility());
|
| + assertEquals(null, icon2.getDrawable());
|
| + }
|
| +
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testAddItemsWithIcons() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
|
| + }
|
| +
|
| + {
|
| + // Add item 2 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key2", "desc2", mTestIcon2);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + assertEquals(View.VISIBLE, icon2.getVisibility());
|
| + assertEquals(mTestDrawable2, icon2.getDrawable());
|
| + assertEquals(mTestDrawableDescription2, icon2.getContentDescription());
|
| + }
|
| +
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testAddItemWithIconAfterItemWithNoIcon() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.GONE, icon1.getVisibility());
|
| + assertEquals(null, icon1.getDrawable());
|
| + }
|
| +
|
| + {
|
| + // Add item 2 with icon.
|
| + mChooserDialog.addOrUpdateItem("key2", "desc2", mTestIcon2);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + assertEquals(View.INVISIBLE, icon1.getVisibility());
|
| + assertEquals(View.VISIBLE, icon2.getVisibility());
|
| + assertEquals(mTestDrawable2, icon2.getDrawable());
|
| + }
|
| +
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testAddItemWithNoIconAfterItemWithIcon() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 with icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + }
|
| +
|
| + {
|
| + // Add item 2 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key2", "desc2");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + assertEquals(View.INVISIBLE, icon2.getVisibility());
|
| + }
|
| +
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testRemoveItemWithIconNoItemsWithIconsLeft() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 with icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + }
|
| + {
|
| + // Add item 2 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key2", "desc2");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(View.INVISIBLE, icon2.getVisibility());
|
| + }
|
| + {
|
| + // Remove item 1 with icon. No items with icons left.
|
| + mChooserDialog.removeItemFromList("key1");
|
| + ImageView icon2 = getIconImageView(items, 0);
|
| + assertEquals(View.GONE, icon2.getVisibility());
|
| + }
|
| +
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testRemoveItemWithIconOneItemWithIconLeft() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| + {
|
| + // Add item 1 with icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + }
|
| + {
|
| + // Add item 2 with icon.
|
| + mChooserDialog.addOrUpdateItem("key2", "desc2", mTestIcon2);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(View.VISIBLE, icon2.getVisibility());
|
| + }
|
| + {
|
| + // Add item 3 with no icon.
|
| + mChooserDialog.addOrUpdateItem("key3", "desc3");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + ImageView icon2 = getIconImageView(items, 1);
|
| + ImageView icon3 = getIconImageView(items, 2);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(View.VISIBLE, icon2.getVisibility());
|
| + assertEquals(View.INVISIBLE, icon3.getVisibility());
|
| + }
|
| + {
|
| + mChooserDialog.removeItemFromList("key1");
|
| + ImageView icon2 = getIconImageView(items, 0);
|
| + ImageView icon3 = getIconImageView(items, 1);
|
| + assertEquals(View.VISIBLE, icon2.getVisibility());
|
| + assertEquals(mTestDrawable2, icon2.getDrawable());
|
| + assertEquals(View.INVISIBLE, icon3.getVisibility());
|
| + }
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testUpdateItemWithIconToNoIcon() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 with icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
|
| + assertTrue(itemAdapter.getItem(0).hasSameContents("key1", "desc1", mTestIcon1));
|
| + }
|
| + {
|
| + // Update item 1 to no icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.GONE, icon1.getVisibility());
|
| + assertEquals(null, icon1.getContentDescription());
|
| + assertTrue(itemAdapter.getItem(0).hasSameContents("key1", "desc1", null));
|
| + }
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testUpdateItemWithNoIconToIcon() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Add item 1 to no icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1");
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.GONE, icon1.getVisibility());
|
| + assertTrue(itemAdapter.getItem(0).hasSameContents("key1", "desc1"));
|
| + }
|
| + {
|
| + // Update item 1 with icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
|
| + assertTrue(itemAdapter.getItem(0).hasSameContents("key1", "desc1", mTestIcon1));
|
| + }
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| + @LargeTest
|
| + @UiThreadTest
|
| + public void testUpdateItemIcon() throws InterruptedException {
|
| + Dialog dialog = mChooserDialog.getDialogForTesting();
|
| + assertTrue(dialog.isShowing());
|
| +
|
| + ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
|
| + final ListView items = (ListView) dialog.findViewById(R.id.items);
|
| +
|
| + // Initially the itemAdapter is empty.
|
| + assertTrue(itemAdapter.isEmpty());
|
| +
|
| + {
|
| + // Update item 1 with icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon1);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable1, icon1.getDrawable());
|
| + assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
|
| + assertTrue(itemAdapter.getItem(0).hasSameContents("key1", "desc1", mTestIcon1));
|
| + }
|
| + {
|
| + // Update item 1 with different icon.
|
| + mChooserDialog.addOrUpdateItem("key1", "desc1", mTestIcon2);
|
| + ImageView icon1 = getIconImageView(items, 0);
|
| + assertEquals(View.VISIBLE, icon1.getVisibility());
|
| + assertEquals(mTestDrawable2, icon1.getDrawable());
|
| + assertEquals(mTestDrawableDescription2, icon1.getContentDescription());
|
| + assertTrue(itemAdapter.getItem(0).hasSameContents("key1", "desc1", mTestIcon2));
|
| + }
|
| + mChooserDialog.setIdleState();
|
| + mChooserDialog.dismiss();
|
| + }
|
| +
|
| @LargeTest
|
| public void testSimpleItemSelection() {
|
| Dialog dialog = mChooserDialog.getDialogForTesting();
|
|
|