Chromium Code Reviews| 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 e469114c245c1dd6e11c062cb591dcf0ccebba09..9fe2c79afe780acfd1399685589226ce4969e9e9 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java |
| @@ -32,6 +32,15 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi |
| String mLastSelectedId = "None"; |
| + private static final ItemChooserDialog.ItemChooserRowIcon TEST_ICON1 = |
| + new ItemChooserDialog.ItemChooserRowIcon( |
| + R.drawable.ic_signal_cellular_0_bar_grey600_24dp, |
| + R.drawable.ic_signal_cellular_0_bar_white_24dp, "test icon1"); |
| + private static final ItemChooserDialog.ItemChooserRowIcon TEST_ICON2 = |
| + new ItemChooserDialog.ItemChooserRowIcon( |
| + R.drawable.ic_signal_cellular_1_bar_grey600_24dp, |
| + R.drawable.ic_signal_cellular_1_bar_white_24dp, "test icon2"); |
| + |
| public ItemChooserDialogTest() { |
| super(ChromeActivity.class); |
| } |
| @@ -115,6 +124,20 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi |
| })); |
| } |
| + private int getImageContainerVisibilityForItem(ListView items, int pos) { |
| + final int first = items.getFirstVisiblePosition(); |
| + final int last = first + items.getChildCount() - 1; |
|
juncai
2016/09/12 20:05:49
Maybe use: getLastVisiblePosition() here for |last
ortuno
2016/09/13 03:00:45
Done.
|
| + |
| + 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 item.findViewById(R.id.imageContainer).getVisibility(); |
| + } |
| + |
| @SmallTest |
| public void testSimpleItemSelection() throws InterruptedException { |
| Dialog dialog = mChooserDialog.getDialogForTesting(); |
| @@ -202,6 +225,104 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi |
| } |
| @SmallTest |
| + 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. |
| + ItemChooserDialog.ItemChooserRow item1 = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1); |
| + mChooserDialog.addOrUpdateItem(item1); |
| + assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)); |
| + assertEquals(1, itemAdapter.getCount()); |
| + assertEquals(itemAdapter.getItem(0), item1); |
| + |
| + // Add item 1 with no icon. |
| + ItemChooserDialog.ItemChooserRow item1WithNoIcon = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| + mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| + assertEquals(1, itemAdapter.getCount()); |
| + // We should still see the original item with the icon. |
| + ItemChooserDialog.ItemChooserRow expectedItem = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1); |
| + assertEquals(itemAdapter.getItem(0), expectedItem); |
| + assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)); |
| + |
| + mChooserDialog.setIdleState(); |
| + mChooserDialog.dismiss(); |
| + } |
| + |
| + @SmallTest |
| + 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 with no icon. |
| + ItemChooserDialog.ItemChooserRow item1WithNoIcon = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| + mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| + assertEquals(View.GONE, getImageContainerVisibilityForItem(items, 0)); |
| + assertEquals(1, itemAdapter.getCount()); |
| + assertEquals(itemAdapter.getItem(0), item1WithNoIcon); |
| + |
| + // Add item 1 with icon. |
| + ItemChooserDialog.ItemChooserRow item1 = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1); |
| + mChooserDialog.addOrUpdateItem(item1); |
| + assertEquals(1, itemAdapter.getCount()); |
| + ItemChooserDialog.ItemChooserRow expectedItem = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1); |
| + assertEquals(itemAdapter.getItem(0), expectedItem); |
| + assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)); |
| + |
| + mChooserDialog.setIdleState(); |
| + mChooserDialog.dismiss(); |
| + } |
| + |
| + @SmallTest |
| + public void testUpdateItemWithNoIconToNoIcon() 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. |
| + ItemChooserDialog.ItemChooserRow item1WithNoIcon = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| + mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| + assertEquals(View.GONE, getImageContainerVisibilityForItem(items, 0)); |
| + assertEquals(1, itemAdapter.getCount()); |
| + assertEquals(itemAdapter.getItem(0), item1WithNoIcon); |
| + |
| + // Add item 1 with no icon again. |
| + mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| + assertEquals(1, itemAdapter.getCount()); |
| + ItemChooserDialog.ItemChooserRow expectedItem = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| + assertEquals(itemAdapter.getItem(0), expectedItem); |
| + assertEquals(View.GONE, getImageContainerVisibilityForItem(items, 0)); |
| + |
| + mChooserDialog.setIdleState(); |
| + mChooserDialog.dismiss(); |
| + } |
| + |
| + @SmallTest |
| public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedException { |
| Dialog dialog = mChooserDialog.getDialogForTesting(); |
| assertTrue(dialog.isShowing()); |
| @@ -224,25 +345,28 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi |
| // Add item 1. |
| ItemChooserDialog.ItemChooserRow item1 = |
| - new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1); |
| mChooserDialog.addOrUpdateItem(item1); |
| assertEquals(1, itemAdapter.getCount()); |
| assertEquals(itemAdapter.getItem(0), item1); |
| + assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)); |
| - // Add item 1 with different description. |
| - ItemChooserDialog.ItemChooserRow item1_again = |
| - new ItemChooserDialog.ItemChooserRow("key1", "desc1_again"); |
| - mChooserDialog.addOrUpdateItem(item1_again); |
| + // Add item 1 with different description and icon. |
| + ItemChooserDialog.ItemChooserRow item1Again = |
| + new ItemChooserDialog.ItemChooserRow("key1", "desc1_again", TEST_ICON2); |
| + mChooserDialog.addOrUpdateItem(item1Again); |
| assertEquals(1, itemAdapter.getCount()); |
| - assertEquals(itemAdapter.getItem(0), item1_again); |
| + assertEquals(itemAdapter.getItem(0), item1Again); |
| + assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)); |
| // Add item 2. |
| ItemChooserDialog.ItemChooserRow item2 = |
| new ItemChooserDialog.ItemChooserRow("key2", "desc2"); |
| mChooserDialog.addOrUpdateItem(item2); |
| assertEquals(2, itemAdapter.getCount()); |
| - assertEquals(itemAdapter.getItem(0), item1_again); |
| + assertEquals(itemAdapter.getItem(0), item1Again); |
| assertEquals(itemAdapter.getItem(1), item2); |
| + assertEquals(View.GONE, getImageContainerVisibilityForItem(items, 1)); |
| mChooserDialog.setIdleState(); |
| @@ -253,7 +377,7 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi |
| // Remove item 2. |
| mChooserDialog.removeItemFromList(item2); |
| assertEquals(1, itemAdapter.getCount()); |
| - assertEquals(itemAdapter.getItem(0), item1_again); |
| + assertEquals(itemAdapter.getItem(0), item1Again); |
| // The list should be visible with one item, it should not show |
| // the empty view and the button should not be enabled. |
| @@ -264,7 +388,7 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi |
| assertFalse(button.isEnabled()); |
| // Remove item 1. |
| - mChooserDialog.removeItemFromList(item1_again); |
| + mChooserDialog.removeItemFromList(item1Again); |
| assertTrue(itemAdapter.isEmpty()); |
| // Listview should now be showing empty, with an empty view visible |