Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: rebase and convert newly added test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 fdc2aecb460c29c989a24dc55fc2fd94ae0a43b1..e7a0701662368ae0c8050e384df7732cd7e9f0ee 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
@@ -8,7 +8,6 @@ import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.test.filters.LargeTest;
-import android.test.UiThreadTest;
import android.text.SpannableString;
import android.view.View;
import android.widget.Button;
@@ -16,11 +15,19 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
-import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TouchCommon;
@@ -31,9 +38,14 @@ import java.util.concurrent.Callable;
/**
* Tests for the ItemChooserDialog class.
*/
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
@RetryOnFailure
-public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
- implements ItemChooserDialog.ItemSelectedCallback {
+public class ItemChooserDialogTest implements ItemChooserDialog.ItemSelectedCallback {
+ @Rule
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
+ new ChromeActivityTestRule<>(ChromeActivity.class);
ItemChooserDialog mChooserDialog;
@@ -45,15 +57,11 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
Drawable mTestDrawable2;
String mTestDrawableDescription2;
- public ItemChooserDialogTest() {
- super(ChromeActivity.class);
- }
-
// ChromeActivityTestCaseBase:
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
mChooserDialog = createDialog();
mTestDrawable1 = getNewTestDrawable();
@@ -62,12 +70,7 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mTestDrawable2 = getNewTestDrawable();
mTestDrawableDescription2 = "icon2 description";
- assertFalse(ApiCompatibilityUtils.objectEquals(mTestDrawable1, mTestDrawable2));
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
+ Assert.assertFalse(ApiCompatibilityUtils.objectEquals(mTestDrawable1, mTestDrawable2));
}
// ItemChooserDialog.ItemSelectedCallback:
@@ -78,8 +81,9 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
}
private Drawable getNewTestDrawable() {
- Drawable drawable = VectorDrawableCompat.create(
- getActivity().getResources(), R.drawable.ic_bluetooth_connected, null);
+ Drawable drawable =
+ VectorDrawableCompat.create(mActivityTestRule.getActivity().getResources(),
+ R.drawable.ic_bluetooth_connected, null);
// Calling mutate() on a Drawable should typically create a new ConstantState
// for that Drawable. Ensure the new drawable doesn't share a state with other
// drwables.
@@ -101,8 +105,9 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
new Callable<ItemChooserDialog>() {
@Override
public ItemChooserDialog call() {
- ItemChooserDialog dialog = new ItemChooserDialog(
- getActivity(), ItemChooserDialogTest.this, labels);
+ ItemChooserDialog dialog =
+ new ItemChooserDialog(mActivityTestRule.getActivity(),
+ ItemChooserDialogTest.this, labels);
return dialog;
}
});
@@ -167,310 +172,359 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
return (TextView) getRowView(dialog, position).findViewById(R.id.description);
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testAddItemsWithNoIcons() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- {
- // Add item 1 with no icon.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.GONE, icon1.getVisibility());
- assertEquals(null, icon1.getDrawable());
- }
-
- {
- // Add item 2 with no icon.
- mChooserDialog.addOrUpdateItem("key2", "desc2");
- ImageView icon2 = getIconImageView(dialog, 1);
- assertEquals(View.GONE, icon2.getVisibility());
- assertEquals(null, icon2.getDrawable());
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testAddItemsWithNoIcons() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ {
+ // Add item 1 with no icon.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.GONE, icon1.getVisibility());
+ Assert.assertEquals(null, icon1.getDrawable());
+ }
+
+ {
+ // Add item 2 with no icon.
+ mChooserDialog.addOrUpdateItem("key2", "desc2");
+ ImageView icon2 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.GONE, icon2.getVisibility());
+ Assert.assertEquals(null, icon2.getDrawable());
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testAddItemsWithIcons() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- {
- // Add item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
- }
-
- {
- // Add item 2 with icon.
- mChooserDialog.addOrUpdateItem(
- "key2", "desc2", mTestDrawable2, mTestDrawableDescription2);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
- ImageView icon2 = getIconImageView(dialog, 2);
- assertEquals(View.VISIBLE, icon2.getVisibility());
- assertEquals(mTestDrawable2, icon2.getDrawable());
- assertEquals(mTestDrawableDescription2, icon2.getContentDescription());
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testAddItemsWithIcons() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ {
+ // Add item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ Assert.assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
+ }
+
+ {
+ // Add item 2 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key2", "desc2", mTestDrawable2, mTestDrawableDescription2);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ Assert.assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
+ ImageView icon2 = getIconImageView(dialog, 2);
+ Assert.assertEquals(View.VISIBLE, icon2.getVisibility());
+ Assert.assertEquals(mTestDrawable2, icon2.getDrawable());
+ Assert.assertEquals(mTestDrawableDescription2, icon2.getContentDescription());
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testAddItemWithIconAfterItemWithNoIcon() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- {
- // Add item 1 with no icon.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.GONE, icon1.getVisibility());
- assertEquals(null, icon1.getDrawable());
- }
-
- {
- // Add item 2 with icon.
- mChooserDialog.addOrUpdateItem(
- "key2", "desc2", mTestDrawable2, mTestDrawableDescription2);
- ImageView icon1 = getIconImageView(dialog, 1);
- ImageView icon2 = getIconImageView(dialog, 2);
- assertEquals(View.INVISIBLE, icon1.getVisibility());
- assertEquals(View.VISIBLE, icon2.getVisibility());
- assertEquals(mTestDrawable2, icon2.getDrawable());
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testAddItemWithIconAfterItemWithNoIcon() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ {
+ // Add item 1 with no icon.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.GONE, icon1.getVisibility());
+ Assert.assertEquals(null, icon1.getDrawable());
+ }
+
+ {
+ // Add item 2 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key2", "desc2", mTestDrawable2, mTestDrawableDescription2);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ ImageView icon2 = getIconImageView(dialog, 2);
+ Assert.assertEquals(View.INVISIBLE, icon1.getVisibility());
+ Assert.assertEquals(View.VISIBLE, icon2.getVisibility());
+ Assert.assertEquals(mTestDrawable2, icon2.getDrawable());
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testAddItemWithNoIconAfterItemWithIcon() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- {
- // Add item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- }
-
- {
- // Add item 2 with no icon.
- mChooserDialog.addOrUpdateItem("key2", "desc2");
- ImageView icon1 = getIconImageView(dialog, 1);
- ImageView icon2 = getIconImageView(dialog, 2);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- assertEquals(View.INVISIBLE, icon2.getVisibility());
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testAddItemWithNoIconAfterItemWithIcon() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ {
+ // Add item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ }
+
+ {
+ // Add item 2 with no icon.
+ mChooserDialog.addOrUpdateItem("key2", "desc2");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ ImageView icon2 = getIconImageView(dialog, 2);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ Assert.assertEquals(View.INVISIBLE, icon2.getVisibility());
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testRemoveItemWithIconNoItemsWithIconsLeft() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- {
- // Add item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- }
-
- {
- // Add item 2 with no icon.
- mChooserDialog.addOrUpdateItem("key2", "desc2");
- ImageView icon1 = getIconImageView(dialog, 1);
- ImageView icon2 = getIconImageView(dialog, 2);
- 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(dialog, 1);
- assertEquals(View.GONE, icon2.getVisibility());
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testRemoveItemWithIconNoItemsWithIconsLeft() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ {
+ // Add item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ }
+
+ {
+ // Add item 2 with no icon.
+ mChooserDialog.addOrUpdateItem("key2", "desc2");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ ImageView icon2 = getIconImageView(dialog, 2);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(View.INVISIBLE, icon2.getVisibility());
+ }
+
+ {
+ // Remove item 1 with icon. No items with icons left.
+ mChooserDialog.removeItemFromList("key1");
+ ImageView icon2 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.GONE, icon2.getVisibility());
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testRemoveItemWithIconOneItemWithIconLeft() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- {
- // Add item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- }
-
- {
- // Add item 2 with icon.
- mChooserDialog.addOrUpdateItem(
- "key2", "desc2", mTestDrawable2, mTestDrawableDescription2);
- ImageView icon1 = getIconImageView(dialog, 1);
- ImageView icon2 = getIconImageView(dialog, 2);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(View.VISIBLE, icon2.getVisibility());
- }
-
- {
- // Add item 3 with no icon.
- mChooserDialog.addOrUpdateItem("key3", "desc3");
- ImageView icon1 = getIconImageView(dialog, 1);
- ImageView icon2 = getIconImageView(dialog, 2);
- ImageView icon3 = getIconImageView(dialog, 3);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(View.VISIBLE, icon2.getVisibility());
- assertEquals(View.INVISIBLE, icon3.getVisibility());
- }
-
- {
- mChooserDialog.removeItemFromList("key1");
- ImageView icon2 = getIconImageView(dialog, 1);
- ImageView icon3 = getIconImageView(dialog, 2);
- assertEquals(View.VISIBLE, icon2.getVisibility());
- assertEquals(mTestDrawable2, icon2.getDrawable());
- assertEquals(View.INVISIBLE, icon3.getVisibility());
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testRemoveItemWithIconOneItemWithIconLeft() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ {
+ // Add item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ }
+
+ {
+ // Add item 2 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key2", "desc2", mTestDrawable2, mTestDrawableDescription2);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ ImageView icon2 = getIconImageView(dialog, 2);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(View.VISIBLE, icon2.getVisibility());
+ }
+
+ {
+ // Add item 3 with no icon.
+ mChooserDialog.addOrUpdateItem("key3", "desc3");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ ImageView icon2 = getIconImageView(dialog, 2);
+ ImageView icon3 = getIconImageView(dialog, 3);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(View.VISIBLE, icon2.getVisibility());
+ Assert.assertEquals(View.INVISIBLE, icon3.getVisibility());
+ }
+
+ {
+ mChooserDialog.removeItemFromList("key1");
+ ImageView icon2 = getIconImageView(dialog, 1);
+ ImageView icon3 = getIconImageView(dialog, 2);
+ Assert.assertEquals(View.VISIBLE, icon2.getVisibility());
+ Assert.assertEquals(mTestDrawable2, icon2.getDrawable());
+ Assert.assertEquals(View.INVISIBLE, icon3.getVisibility());
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testUpdateItemWithIconToNoIcon() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
- ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
-
- {
- // Add item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
- }
-
- {
- // Update item 1 to no icon.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.GONE, icon1.getVisibility());
- assertEquals(null, icon1.getContentDescription());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testUpdateItemWithIconToNoIcon() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+ ItemChooserDialog.ItemAdapter itemAdapter =
+ mChooserDialog.getItemAdapterForTesting();
+
+ {
+ // Add item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
+ }
+
+ {
+ // Update item 1 to no icon.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.GONE, icon1.getVisibility());
+ Assert.assertEquals(null, icon1.getContentDescription());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testUpdateItemWithNoIconToIcon() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
- ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
-
- {
- // Add item 1 to no icon.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.GONE, icon1.getVisibility());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
- }
-
- {
- // Update item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testUpdateItemWithNoIconToIcon() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+ ItemChooserDialog.ItemAdapter itemAdapter =
+ mChooserDialog.getItemAdapterForTesting();
+
+ {
+ // Add item 1 to no icon.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.GONE, icon1.getVisibility());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+ }
+
+ {
+ // Update item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ Assert.assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testUpdateItemIcon() throws InterruptedException {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
- ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
-
- {
- // Update item 1 with icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable1, icon1.getDrawable());
- assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
- }
-
- {
- // Update item 1 with different icon.
- mChooserDialog.addOrUpdateItem(
- "key1", "desc1", mTestDrawable2, mTestDrawableDescription2);
- ImageView icon1 = getIconImageView(dialog, 1);
- assertEquals(View.VISIBLE, icon1.getVisibility());
- assertEquals(mTestDrawable2, icon1.getDrawable());
- assertEquals(mTestDrawableDescription2, icon1.getContentDescription());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", mTestDrawable2, mTestDrawableDescription2));
- }
-
- mChooserDialog.setIdleState();
- mChooserDialog.dismiss();
+ public void testUpdateItemIcon() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+ ItemChooserDialog.ItemAdapter itemAdapter =
+ mChooserDialog.getItemAdapterForTesting();
+
+ {
+ // Update item 1 with icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable1, icon1.getDrawable());
+ Assert.assertEquals(mTestDrawableDescription1, icon1.getContentDescription());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", mTestDrawable1, mTestDrawableDescription1));
+ }
+
+ {
+ // Update item 1 with different icon.
+ mChooserDialog.addOrUpdateItem(
+ "key1", "desc1", mTestDrawable2, mTestDrawableDescription2);
+ ImageView icon1 = getIconImageView(dialog, 1);
+ Assert.assertEquals(View.VISIBLE, icon1.getVisibility());
+ Assert.assertEquals(mTestDrawable2, icon1.getDrawable());
+ Assert.assertEquals(mTestDrawableDescription2, icon1.getContentDescription());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", mTestDrawable2, mTestDrawableDescription2));
+ }
+
+ mChooserDialog.setIdleState();
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
public void testSimpleItemSelection() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
TextViewWithClickableSpans statusView = (TextViewWithClickableSpans)
dialog.findViewById(R.id.status);
@@ -479,40 +533,41 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
// Before we add items to the dialog, the 'searching' message should be
// showing, the Commit button should be disabled and the list view hidden.
- assertEquals("searching", statusView.getText().toString());
- assertFalse(button.isEnabled());
- assertEquals(View.GONE, items.getVisibility());
+ Assert.assertEquals("searching", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
+ Assert.assertEquals(View.GONE, items.getVisibility());
mChooserDialog.addOrUpdateItem("key1", "desc1");
mChooserDialog.addOrUpdateItem("key2", "desc2");
// Two items showing, the empty view should be no more and the button
// should now be enabled.
- assertEquals(View.VISIBLE, items.getVisibility());
- assertEquals(View.GONE, items.getEmptyView().getVisibility());
- assertEquals("statusActive", statusView.getText().toString());
- assertFalse(button.isEnabled());
+ Assert.assertEquals(View.VISIBLE, items.getVisibility());
+ Assert.assertEquals(View.GONE, items.getEmptyView().getVisibility());
+ Assert.assertEquals("statusActive", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
mChooserDialog.setIdleState();
// After discovery stops the list should be visible with two items,
// it should not show the empty view and the button should not be enabled.
// The chooser should show the status idle text.
- assertEquals(View.VISIBLE, items.getVisibility());
- assertEquals(View.GONE, items.getEmptyView().getVisibility());
- assertEquals("statusIdleSomeFound", statusView.getText().toString());
- assertFalse(button.isEnabled());
+ Assert.assertEquals(View.VISIBLE, items.getVisibility());
+ Assert.assertEquals(View.GONE, items.getEmptyView().getVisibility());
+ Assert.assertEquals("statusIdleSomeFound", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
// Select the first item and verify it got selected.
selectItem(dialog, 1, "key1", true);
- assertTrue(getDescriptionTextView(dialog, 1).isSelected());
+ Assert.assertTrue(getDescriptionTextView(dialog, 1).isSelected());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testNoItemsAddedDiscoveryIdle() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
TextViewWithClickableSpans statusView = (TextViewWithClickableSpans)
dialog.findViewById(R.id.status);
@@ -521,26 +576,27 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
// Before we add items to the dialog, the 'searching' message should be
// showing, the Commit button should be disabled and the list view hidden.
- assertEquals("searching", statusView.getText().toString());
- assertFalse(button.isEnabled());
- assertEquals(View.GONE, items.getVisibility());
+ Assert.assertEquals("searching", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
+ Assert.assertEquals(View.GONE, items.getVisibility());
mChooserDialog.setIdleState();
// Listview should now be showing empty, with an empty view visible to
// drive home the point and a status message at the bottom.
- assertEquals(View.GONE, items.getVisibility());
- assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
- assertEquals("statusIdleNoneFound", statusView.getText().toString());
- assertFalse(button.isEnabled());
+ Assert.assertEquals(View.GONE, items.getVisibility());
+ Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
+ Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testDisabledSelection() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
mChooserDialog.addOrUpdateItem("key1", "desc1");
mChooserDialog.addOrUpdateItem("key2", "desc2");
@@ -554,10 +610,11 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testSelectOneItemThenDisableTheSelectedItem() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
@@ -565,21 +622,22 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.addOrUpdateItem("key2", "desc2");
selectItem(dialog, 1, "key1", true);
- assertEquals("key1", itemAdapter.getSelectedItemKey());
+ Assert.assertEquals("key1", itemAdapter.getSelectedItemKey());
mChooserDialog.setEnabled("key1", false);
// The selected item is disabled, so no item is selected.
- assertEquals("", itemAdapter.getSelectedItemKey());
+ Assert.assertEquals("", itemAdapter.getSelectedItemKey());
mChooserDialog.setEnabled("key1", true);
// The disabled item is not automatically selected again when it is re-enabled.
- assertEquals("", itemAdapter.getSelectedItemKey());
+ Assert.assertEquals("", itemAdapter.getSelectedItemKey());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testPairButtonDisabledOrEnabledAfterSelectedItemDisabledOrEnabled() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
final Button button = (Button) dialog.findViewById(R.id.positive);
@@ -587,23 +645,24 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.addOrUpdateItem("key2", "desc2");
selectItem(dialog, 1, "key1", true);
- assertTrue(button.isEnabled());
+ Assert.assertTrue(button.isEnabled());
mChooserDialog.setEnabled("key1", false);
- assertFalse(button.isEnabled());
+ Assert.assertFalse(button.isEnabled());
mChooserDialog.setEnabled("key1", true);
// The disabled item is not automatically selected again when it is re-enabled,
// so the button is still disabled.
- assertFalse(button.isEnabled());
+ Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testPairButtonDisabledAfterSelectedItemRemoved() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
final Button button = (Button) dialog.findViewById(R.id.positive);
@@ -611,18 +670,19 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.addOrUpdateItem("key2", "desc2");
selectItem(dialog, 1, "key1", true);
- assertTrue(button.isEnabled());
+ Assert.assertTrue(button.isEnabled());
mChooserDialog.removeItemFromList("key1");
- assertFalse(button.isEnabled());
+ Assert.assertFalse(button.isEnabled());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testSelectAnItemAndRemoveAnotherItem() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
final Button button = (Button) dialog.findViewById(R.id.positive);
ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
@@ -632,25 +692,26 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.addOrUpdateItem("key3", "desc3");
selectItem(dialog, 2, "key2", true);
- assertTrue(button.isEnabled());
+ Assert.assertTrue(button.isEnabled());
// Remove the item before the currently selected item.
mChooserDialog.removeItemFromList("key1");
- assertTrue(button.isEnabled());
- assertEquals("key2", itemAdapter.getSelectedItemKey());
+ Assert.assertTrue(button.isEnabled());
+ Assert.assertEquals("key2", itemAdapter.getSelectedItemKey());
// Remove the item after the currently selected item.
mChooserDialog.removeItemFromList("key3");
- assertTrue(button.isEnabled());
- assertEquals("key2", itemAdapter.getSelectedItemKey());
+ Assert.assertTrue(button.isEnabled());
+ Assert.assertEquals("key2", itemAdapter.getSelectedItemKey());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
public void testSelectAnItemAndRemoveTheSelectedItem() {
Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
+ Assert.assertTrue(dialog.isShowing());
final Button button = (Button) dialog.findViewById(R.id.positive);
ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
@@ -660,204 +721,223 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.addOrUpdateItem("key3", "desc3");
selectItem(dialog, 2, "key2", true);
- assertTrue(button.isEnabled());
+ Assert.assertTrue(button.isEnabled());
// Remove the selected item.
mChooserDialog.removeItemFromList("key2");
- assertFalse(button.isEnabled());
- assertEquals("", itemAdapter.getSelectedItemKey());
+ Assert.assertFalse(button.isEnabled());
+ Assert.assertEquals("", itemAdapter.getSelectedItemKey());
mChooserDialog.dismiss();
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testUpdateItemAndRemoveItemFromList() {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- TextViewWithClickableSpans statusView = (TextViewWithClickableSpans)
- dialog.findViewById(R.id.status);
- final ListView items = (ListView) dialog.findViewById(R.id.items);
- final Button button = (Button) dialog.findViewById(R.id.positive);
-
- ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
- final String nonExistentKey = "key";
-
- // Initially the itemAdapter is empty.
- assertTrue(itemAdapter.isEmpty());
-
- // Try removing an item from an empty itemAdapter.
- mChooserDialog.removeItemFromList(nonExistentKey);
- assertTrue(itemAdapter.isEmpty());
-
- // Add item 1.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- assertEquals(1, itemAdapter.getCount());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
-
- // Update item 1 with different description.
- mChooserDialog.addOrUpdateItem("key1", "desc2");
- assertEquals(1, itemAdapter.getCount());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc2", null /* icon */, null /* iconDescription */));
-
- mChooserDialog.setIdleState();
-
- // Remove item 1.
- mChooserDialog.removeItemFromList("key1");
- assertTrue(itemAdapter.isEmpty());
-
- // Listview should now be showing empty, with an empty view visible
- // and the button should not be enabled.
- // The chooser should show a status message at the bottom.
- assertEquals(View.GONE, items.getVisibility());
- assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
- assertEquals("statusIdleNoneFound", statusView.getText().toString());
- assertFalse(button.isEnabled());
-
- mChooserDialog.dismiss();
+ public void testUpdateItemAndRemoveItemFromList() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ TextViewWithClickableSpans statusView =
+ (TextViewWithClickableSpans) dialog.findViewById(R.id.status);
+ final ListView items = (ListView) dialog.findViewById(R.id.items);
+ final Button button = (Button) dialog.findViewById(R.id.positive);
+
+ ItemChooserDialog.ItemAdapter itemAdapter =
+ mChooserDialog.getItemAdapterForTesting();
+ final String nonExistentKey = "key";
+
+ // Initially the itemAdapter is empty.
+ Assert.assertTrue(itemAdapter.isEmpty());
+
+ // Try removing an item from an empty itemAdapter.
+ mChooserDialog.removeItemFromList(nonExistentKey);
+ Assert.assertTrue(itemAdapter.isEmpty());
+
+ // Add item 1.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ Assert.assertEquals(1, itemAdapter.getCount());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+
+ // Update item 1 with different description.
+ mChooserDialog.addOrUpdateItem("key1", "desc2");
+ Assert.assertEquals(1, itemAdapter.getCount());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc2", null /* icon */, null /* iconDescription */));
+
+ mChooserDialog.setIdleState();
+
+ // Remove item 1.
+ mChooserDialog.removeItemFromList("key1");
+ Assert.assertTrue(itemAdapter.isEmpty());
+
+ // Listview should now be showing empty, with an empty view visible
+ // and the button should not be enabled.
+ // The chooser should show a status message at the bottom.
+ Assert.assertEquals(View.GONE, items.getVisibility());
+ Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
+ Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
+
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testAddItemAndRemoveItemFromList() {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- TextViewWithClickableSpans statusView =
- (TextViewWithClickableSpans) dialog.findViewById(R.id.status);
- final ListView items = (ListView) dialog.findViewById(R.id.items);
- final Button button = (Button) dialog.findViewById(R.id.positive);
-
- ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
- final String nonExistentKey = "key";
-
- // Initially the itemAdapter is empty.
- assertTrue(itemAdapter.isEmpty());
-
- // Try removing an item from an empty itemAdapter.
- mChooserDialog.removeItemFromList(nonExistentKey);
- assertTrue(itemAdapter.isEmpty());
-
- // Add item 1.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- assertEquals(1, itemAdapter.getCount());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
-
- // Add item 2.
- mChooserDialog.addOrUpdateItem("key2", "desc2");
- assertEquals(2, itemAdapter.getCount());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
- assertTrue(itemAdapter.getItem(1).hasSameContents(
- "key2", "desc2", null /* icon */, null /* iconDescription */));
-
- mChooserDialog.setIdleState();
-
- // Try removing an item that doesn't exist.
- mChooserDialog.removeItemFromList(nonExistentKey);
- assertEquals(2, itemAdapter.getCount());
-
- // Remove item 2.
- mChooserDialog.removeItemFromList("key2");
- assertEquals(1, itemAdapter.getCount());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
-
- // The list should be visible with one item, it should not show
- // the empty view and the button should not be enabled.
- // The chooser should show a status message at the bottom.
- assertEquals(View.VISIBLE, items.getVisibility());
- assertEquals(View.GONE, items.getEmptyView().getVisibility());
- assertEquals("statusIdleSomeFound", statusView.getText().toString());
- assertFalse(button.isEnabled());
-
- // Remove item 1.
- mChooserDialog.removeItemFromList("key1");
- assertTrue(itemAdapter.isEmpty());
-
- // Listview should now be showing empty, with an empty view visible
- // and the button should not be enabled.
- // The chooser should show a status message at the bottom.
- assertEquals(View.GONE, items.getVisibility());
- assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
- assertEquals("statusIdleNoneFound", statusView.getText().toString());
- assertFalse(button.isEnabled());
-
- mChooserDialog.dismiss();
+ public void testAddItemAndRemoveItemFromList() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ TextViewWithClickableSpans statusView =
+ (TextViewWithClickableSpans) dialog.findViewById(R.id.status);
+ final ListView items = (ListView) dialog.findViewById(R.id.items);
+ final Button button = (Button) dialog.findViewById(R.id.positive);
+
+ ItemChooserDialog.ItemAdapter itemAdapter =
+ mChooserDialog.getItemAdapterForTesting();
+ final String nonExistentKey = "key";
+
+ // Initially the itemAdapter is empty.
+ Assert.assertTrue(itemAdapter.isEmpty());
+
+ // Try removing an item from an empty itemAdapter.
+ mChooserDialog.removeItemFromList(nonExistentKey);
+ Assert.assertTrue(itemAdapter.isEmpty());
+
+ // Add item 1.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ Assert.assertEquals(1, itemAdapter.getCount());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+
+ // Add item 2.
+ mChooserDialog.addOrUpdateItem("key2", "desc2");
+ Assert.assertEquals(2, itemAdapter.getCount());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+ Assert.assertTrue(itemAdapter.getItem(1).hasSameContents(
+ "key2", "desc2", null /* icon */, null /* iconDescription */));
+
+ mChooserDialog.setIdleState();
+
+ // Try removing an item that doesn't exist.
+ mChooserDialog.removeItemFromList(nonExistentKey);
+ Assert.assertEquals(2, itemAdapter.getCount());
+
+ // Remove item 2.
+ mChooserDialog.removeItemFromList("key2");
+ Assert.assertEquals(1, itemAdapter.getCount());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+
+ // The list should be visible with one item, it should not show
+ // the empty view and the button should not be enabled.
+ // The chooser should show a status message at the bottom.
+ Assert.assertEquals(View.VISIBLE, items.getVisibility());
+ Assert.assertEquals(View.GONE, items.getEmptyView().getVisibility());
+ Assert.assertEquals("statusIdleSomeFound", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
+
+ // Remove item 1.
+ mChooserDialog.removeItemFromList("key1");
+ Assert.assertTrue(itemAdapter.isEmpty());
+
+ // Listview should now be showing empty, with an empty view visible
+ // and the button should not be enabled.
+ // The chooser should show a status message at the bottom.
+ Assert.assertEquals(View.GONE, items.getVisibility());
+ Assert.assertEquals(View.VISIBLE, items.getEmptyView().getVisibility());
+ Assert.assertEquals("statusIdleNoneFound", statusView.getText().toString());
+ Assert.assertFalse(button.isEnabled());
+
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
- @UiThreadTest
- public void testAddItemWithSameNameToListAndRemoveItemFromList() {
- Dialog dialog = mChooserDialog.getDialogForTesting();
- assertTrue(dialog.isShowing());
-
- ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
-
- // Add item 1.
- mChooserDialog.addOrUpdateItem("key1", "desc1");
- assertEquals(1, itemAdapter.getCount());
- // Add item 2.
- mChooserDialog.addOrUpdateItem("key2", "desc2");
- assertEquals(2, itemAdapter.getCount());
- // Add item 3 with same description as item 1.
- mChooserDialog.addOrUpdateItem("key3", "desc1");
- assertEquals(3, itemAdapter.getCount());
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
- assertTrue(itemAdapter.getItem(1).hasSameContents(
- "key2", "desc2", null /* icon */, null /* iconDescription */));
- assertTrue(itemAdapter.getItem(2).hasSameContents(
- "key3", "desc1", null /* icon */, null /* iconDescription */));
-
- // Since two items have the same name, their display text should have their unique
- // keys appended.
- assertEquals("desc1 (key1)", itemAdapter.getDisplayText(0));
- assertEquals("desc2", itemAdapter.getDisplayText(1));
- assertEquals("desc1 (key3)", itemAdapter.getDisplayText(2));
-
- // Remove item 2.
- mChooserDialog.removeItemFromList("key2");
- assertEquals(2, itemAdapter.getCount());
- // Make sure the remaining items are item 1 and item 3.
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key1", "desc1", null /* icon */, null /* iconDescription */));
- assertTrue(itemAdapter.getItem(1).hasSameContents(
- "key3", "desc1", null /* icon */, null /* iconDescription */));
- assertEquals("desc1 (key1)", itemAdapter.getDisplayText(0));
- assertEquals("desc1 (key3)", itemAdapter.getDisplayText(1));
-
- // Remove item 1.
- mChooserDialog.removeItemFromList("key1");
- assertEquals(1, itemAdapter.getCount());
- // Make sure the remaining item is item 3.
- assertTrue(itemAdapter.getItem(0).hasSameContents(
- "key3", "desc1", null /* icon */, null /* iconDescription */));
- // After removing item 1, item 3 is the only remaining item, so its display text
- // also changed to its original description.
- assertEquals("desc1", itemAdapter.getDisplayText(0));
-
- mChooserDialog.dismiss();
+ public void testAddItemWithSameNameToListAndRemoveItemFromList() throws Throwable {
+ mActivityTestRule.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ Assert.assertTrue(dialog.isShowing());
+
+ ItemChooserDialog.ItemAdapter itemAdapter =
+ mChooserDialog.getItemAdapterForTesting();
+
+ // Add item 1.
+ mChooserDialog.addOrUpdateItem("key1", "desc1");
+ Assert.assertEquals(1, itemAdapter.getCount());
+ // Add item 2.
+ mChooserDialog.addOrUpdateItem("key2", "desc2");
+ Assert.assertEquals(2, itemAdapter.getCount());
+ // Add item 3 with same description as item 1.
+ mChooserDialog.addOrUpdateItem("key3", "desc1");
+ Assert.assertEquals(3, itemAdapter.getCount());
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+ Assert.assertTrue(itemAdapter.getItem(1).hasSameContents(
+ "key2", "desc2", null /* icon */, null /* iconDescription */));
+ Assert.assertTrue(itemAdapter.getItem(2).hasSameContents(
+ "key3", "desc1", null /* icon */, null /* iconDescription */));
+
+ // Since two items have the same name, their display text should have their unique
+ // keys appended.
+ Assert.assertEquals("desc1 (key1)", itemAdapter.getDisplayText(0));
+ Assert.assertEquals("desc2", itemAdapter.getDisplayText(1));
+ Assert.assertEquals("desc1 (key3)", itemAdapter.getDisplayText(2));
+
+ // Remove item 2.
+ mChooserDialog.removeItemFromList("key2");
+ Assert.assertEquals(2, itemAdapter.getCount());
+ // Make sure the remaining items are item 1 and item 3.
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key1", "desc1", null /* icon */, null /* iconDescription */));
+ Assert.assertTrue(itemAdapter.getItem(1).hasSameContents(
+ "key3", "desc1", null /* icon */, null /* iconDescription */));
+ Assert.assertEquals("desc1 (key1)", itemAdapter.getDisplayText(0));
+ Assert.assertEquals("desc1 (key3)", itemAdapter.getDisplayText(1));
+
+ // Remove item 1.
+ mChooserDialog.removeItemFromList("key1");
+ Assert.assertEquals(1, itemAdapter.getCount());
+ // Make sure the remaining item is item 3.
+ Assert.assertTrue(itemAdapter.getItem(0).hasSameContents(
+ "key3", "desc1", null /* icon */, null /* iconDescription */));
+ // After removing item 1, item 3 is the only remaining item, so its display text
+ // also changed to its original description.
+ Assert.assertEquals("desc1", itemAdapter.getDisplayText(0));
+
+ mChooserDialog.dismiss();
+ }
+ });
}
+ @Test
@LargeTest
public void testListHeight() {
// 500 * .3 is 150, which is 48 * 3.125. 48 * 3.5 is 168.
- assertEquals(168, ItemChooserDialog.getListHeight(500, 1.0f));
+ Assert.assertEquals(168, ItemChooserDialog.getListHeight(500, 1.0f));
// 150 * .3 is 45, which rounds below the minimum height.
- assertEquals(72, ItemChooserDialog.getListHeight(150, 1.0f));
+ Assert.assertEquals(72, ItemChooserDialog.getListHeight(150, 1.0f));
// 1460 * .3 is 438, which rounds above the maximum height.
- assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f));
+ Assert.assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f));
// 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp *
// 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds to
// 370.
- assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f));
+ Assert.assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f));
}
}

Powered by Google App Engine
This is Rietveld 408576698