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

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

Issue 1739523002: WebUsb Android chooser UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and resolved conflicts Created 4 years, 9 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 a18141d806c1ddca6fd2ad32bf54da5cd76c4f0a..b3895aff849c6dc986ce817fab8a6c34e12ade71 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java
@@ -8,6 +8,7 @@ import android.app.Dialog;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.SpannableString;
import android.view.View;
+import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
@@ -19,8 +20,6 @@ import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.ui.widget.TextViewWithClickableSpans;
-import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.Callable;
/**
@@ -132,21 +131,10 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
assertFalse(button.isEnabled());
assertEquals(View.GONE, items.getVisibility());
- List<ItemChooserDialog.ItemChooserRow> devices =
- new ArrayList<ItemChooserDialog.ItemChooserRow>();
- devices.add(new ItemChooserDialog.ItemChooserRow("key", "key"));
- devices.add(new ItemChooserDialog.ItemChooserRow("key2", "key2"));
- mChooserDialog.addItemsToList(devices);
+ mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key", "key"));
+ mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key2", "key2"));
- // 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());
-
- mChooserDialog.setIdleState();
- // After discovery stops the list should still be visible,
Finnur 2016/03/16 13:35:14 Why is this changing (line 141 and below)?
juncai 2016/03/16 21:01:35 I think since State.PROGRESS_UPDATE_AVAILABLE was
+ // 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());
@@ -193,11 +181,8 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
Dialog dialog = mChooserDialog.getDialogForTesting();
assertTrue(dialog.isShowing());
- List<ItemChooserDialog.ItemChooserRow> devices =
- new ArrayList<ItemChooserDialog.ItemChooserRow>();
- devices.add(new ItemChooserDialog.ItemChooserRow("key", "key"));
- devices.add(new ItemChooserDialog.ItemChooserRow("key2", "key2"));
- mChooserDialog.addItemsToList(devices);
+ mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key", "key"));
+ mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key2", "key2"));
// Disable one item and try to select it.
mChooserDialog.setEnabled("key", false);
@@ -207,4 +192,52 @@ public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi
mChooserDialog.dismiss();
}
+
+ @SmallTest
+ public void testAddItemToListAndRemoveItemFromList() throws InterruptedException {
+ Dialog dialog = mChooserDialog.getDialogForTesting();
+ assertTrue(dialog.isShowing());
+
+ ArrayAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting();
+ ItemChooserDialog.ItemChooserRow nonExistentItem =
+ new ItemChooserDialog.ItemChooserRow("key", "key");
+
+ // Initially the itemAdapter is empty.
+ assertTrue(itemAdapter.isEmpty());
+
+ // Try removing an item from an empty itemAdapter.
+ mChooserDialog.removeItemFromList(nonExistentItem);
+ assertTrue(itemAdapter.isEmpty());
+
+ // Add item1.
Finnur 2016/03/16 13:35:14 nit: s/item1/item 1/ (same with item2 and incident
juncai 2016/03/16 21:01:35 Done.
+ ItemChooserDialog.ItemChooserRow item1 =
+ new ItemChooserDialog.ItemChooserRow("key1", "key1");
+ mChooserDialog.addItemToList(item1);
+ assertEquals(1, itemAdapter.getCount());
+ assertEquals(itemAdapter.getItem(0), item1);
+
+ // Add item2.
+ ItemChooserDialog.ItemChooserRow item2 =
+ new ItemChooserDialog.ItemChooserRow("key2", "key2");
+ mChooserDialog.addItemToList(item2);
+ assertEquals(2, itemAdapter.getCount());
+ assertEquals(itemAdapter.getItem(0), item1);
+ assertEquals(itemAdapter.getItem(1), item2);
+
+ // Try removing an item that doesn't exist.
+ mChooserDialog.removeItemFromList(nonExistentItem);
+ assertEquals(2, itemAdapter.getCount());
+
+ // Remove item2.
+ mChooserDialog.removeItemFromList(item2);
+ assertEquals(1, itemAdapter.getCount());
+ // Make sure the remaining item is item1.
+ assertEquals(itemAdapter.getItem(0), item1);
+
+ // Remove item1.
+ mChooserDialog.removeItemFromList(item1);
+ assertTrue(itemAdapter.isEmpty());
Finnur 2016/03/16 13:35:14 I would add verification that the list is showing
juncai 2016/03/16 21:01:35 Done.
+
+ mChooserDialog.dismiss();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698