OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.app.Dialog; | 7 import android.app.Dialog; |
8 import android.content.res.Resources; | |
9 import android.support.graphics.drawable.VectorDrawableCompat; | |
8 import android.test.suitebuilder.annotation.LargeTest; | 10 import android.test.suitebuilder.annotation.LargeTest; |
9 import android.text.SpannableString; | 11 import android.text.SpannableString; |
10 import android.view.View; | 12 import android.view.View; |
11 import android.widget.Button; | 13 import android.widget.Button; |
12 import android.widget.ListView; | 14 import android.widget.ListView; |
13 | 15 |
14 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
15 import org.chromium.base.test.util.RetryOnFailure; | 17 import org.chromium.base.test.util.RetryOnFailure; |
16 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 19 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
18 import org.chromium.content.browser.test.util.Criteria; | 20 import org.chromium.content.browser.test.util.Criteria; |
19 import org.chromium.content.browser.test.util.CriteriaHelper; | 21 import org.chromium.content.browser.test.util.CriteriaHelper; |
20 import org.chromium.content.browser.test.util.TouchCommon; | 22 import org.chromium.content.browser.test.util.TouchCommon; |
21 import org.chromium.ui.widget.TextViewWithClickableSpans; | 23 import org.chromium.ui.widget.TextViewWithClickableSpans; |
22 | 24 |
23 import java.util.concurrent.Callable; | 25 import java.util.concurrent.Callable; |
24 | 26 |
25 /** | 27 /** |
26 * Tests for the ItemChooserDialog class. | 28 * Tests for the ItemChooserDialog class. |
27 */ | 29 */ |
28 @RetryOnFailure | 30 @RetryOnFailure |
29 public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi vity> | 31 public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi vity> |
30 implements ItemChooserDialog.ItemSelectedCallback { | 32 implements ItemChooserDialog.ItemSelectedCallback { |
31 | 33 |
32 ItemChooserDialog mChooserDialog; | 34 ItemChooserDialog mChooserDialog; |
33 | 35 |
34 String mLastSelectedId = "None"; | 36 String mLastSelectedId = "None"; |
35 | 37 |
38 private ItemChooserDialog.ItemChooserRowIcon mTestIcon1; | |
39 private ItemChooserDialog.ItemChooserRowIcon mTestIcon2; | |
40 | |
36 public ItemChooserDialogTest() { | 41 public ItemChooserDialogTest() { |
37 super(ChromeActivity.class); | 42 super(ChromeActivity.class); |
38 } | 43 } |
39 | 44 |
40 // ChromeActivityTestCaseBase: | 45 // ChromeActivityTestCaseBase: |
41 | 46 |
42 @Override | 47 @Override |
43 protected void setUp() throws Exception { | 48 protected void setUp() throws Exception { |
44 super.setUp(); | 49 super.setUp(); |
45 mChooserDialog = createDialog(); | 50 Resources resources = getActivity().getResources(); |
51 mTestIcon1 = new ItemChooserDialog.ItemChooserRowIcon( | |
52 VectorDrawableCompat.create(resources, | |
53 R.drawable.ic_signal_cellular_0_bar_grey600_24dp, null / * theme */), | |
54 VectorDrawableCompat.create(resources, | |
55 R.drawable.ic_signal_cellular_0_bar_white_24dp, null /* theme */), | |
56 resources.getQuantityString(R.plurals.signal_strength_level_n_ba rs, 0, 0)); | |
57 | |
58 mTestIcon2 = new ItemChooserDialog.ItemChooserRowIcon( | |
59 VectorDrawableCompat.create(resources, | |
60 R.drawable.ic_signal_cellular_1_bar_grey600_24dp, null / * theme */), | |
61 VectorDrawableCompat.create(resources, | |
62 R.drawable.ic_signal_cellular_1_bar_white_24dp, null /* theme */), | |
63 resources.getQuantityString(R.plurals.signal_strength_level_n_ba rs, 1, 1)); | |
46 } | 64 } |
47 | 65 |
48 @Override | 66 @Override |
49 public void startMainActivity() throws InterruptedException { | 67 public void startMainActivity() throws InterruptedException { |
50 startMainActivityOnBlankPage(); | 68 startMainActivityOnBlankPage(); |
51 } | 69 } |
52 | 70 |
53 // ItemChooserDialog.ItemSelectedCallback: | 71 // ItemChooserDialog.ItemSelectedCallback: |
54 | 72 |
55 @Override | 73 @Override |
56 public void onItemSelected(String id) { | 74 public void onItemSelected(String id) { |
57 mLastSelectedId = id; | 75 mLastSelectedId = id; |
58 } | 76 } |
59 | 77 |
60 private ItemChooserDialog createDialog() { | 78 private ItemChooserDialog createDialog(final boolean usingIcon) { |
61 SpannableString title = new SpannableString("title"); | 79 SpannableString title = new SpannableString("title"); |
62 SpannableString searching = new SpannableString("searching"); | 80 SpannableString searching = new SpannableString("searching"); |
63 SpannableString noneFound = new SpannableString("noneFound"); | 81 SpannableString noneFound = new SpannableString("noneFound"); |
64 SpannableString statusActive = new SpannableString("statusActive"); | 82 SpannableString statusActive = new SpannableString("statusActive"); |
65 SpannableString statusIdleNoneFound = new SpannableString("statusIdleNon eFound"); | 83 SpannableString statusIdleNoneFound = new SpannableString("statusIdleNon eFound"); |
66 SpannableString statusIdleSomeFound = new SpannableString("statusIdleSom eFound"); | 84 SpannableString statusIdleSomeFound = new SpannableString("statusIdleSom eFound"); |
67 String positiveButton = new String("positiveButton"); | 85 String positiveButton = new String("positiveButton"); |
68 final ItemChooserDialog.ItemChooserLabels labels = | 86 final ItemChooserDialog.ItemChooserLabels labels = |
69 new ItemChooserDialog.ItemChooserLabels(title, searching, noneFo und, statusActive, | 87 new ItemChooserDialog.ItemChooserLabels(title, searching, noneFo und, statusActive, |
70 statusIdleNoneFound, statusIdleSomeFound, positiveButton ); | 88 statusIdleNoneFound, statusIdleSomeFound, positiveButton ); |
71 ItemChooserDialog dialog = ThreadUtils.runOnUiThreadBlockingNoException( | 89 ItemChooserDialog dialog = ThreadUtils.runOnUiThreadBlockingNoException( |
72 new Callable<ItemChooserDialog>() { | 90 new Callable<ItemChooserDialog>() { |
73 @Override | 91 @Override |
74 public ItemChooserDialog call() { | 92 public ItemChooserDialog call() { |
75 ItemChooserDialog dialog = new ItemChooserDialog( | 93 ItemChooserDialog dialog = new ItemChooserDialog( |
76 getActivity(), ItemChooserDialogTest.this, l abels); | 94 getActivity(), ItemChooserDialogTest.this, l abels, usingIcon); |
77 return dialog; | 95 return dialog; |
78 } | 96 } |
79 }); | 97 }); |
80 return dialog; | 98 return dialog; |
81 } | 99 } |
82 | 100 |
83 private void selectItem(Dialog dialog, int position, String expectedItemId, | 101 private void selectItem(Dialog dialog, int position, String expectedItemId, |
84 boolean expectedEnabledState) throws InterruptedException { | 102 boolean expectedEnabledState) throws InterruptedException { |
85 final ListView items = (ListView) dialog.findViewById(R.id.items); | 103 final ListView items = (ListView) dialog.findViewById(R.id.items); |
86 final Button button = (Button) dialog.findViewById(R.id.positive); | 104 final Button button = (Button) dialog.findViewById(R.id.positive); |
(...skipping 22 matching lines...) Expand all Loading... | |
109 | 127 |
110 CriteriaHelper.pollUiThread( | 128 CriteriaHelper.pollUiThread( |
111 Criteria.equals(expectedItemId, new Callable<String>() { | 129 Criteria.equals(expectedItemId, new Callable<String>() { |
112 @Override | 130 @Override |
113 public String call() { | 131 public String call() { |
114 return mLastSelectedId; | 132 return mLastSelectedId; |
115 } | 133 } |
116 })); | 134 })); |
117 } | 135 } |
118 | 136 |
137 private int getImageContainerVisibilityForItem(ListView items, int pos) { | |
138 final int first = items.getFirstVisiblePosition(); | |
139 final int last = items.getLastVisiblePosition(); | |
140 | |
141 View item; | |
142 if (pos < first || pos > last) { | |
143 item = items.getAdapter().getView(pos, null, items); | |
144 } else { | |
145 final int visiblePos = pos - first; | |
146 item = items.getChildAt(visiblePos); | |
147 } | |
148 return item.findViewById(R.id.imageContainer).getVisibility(); | |
149 } | |
150 | |
119 @LargeTest | 151 @LargeTest |
120 public void testSimpleItemSelection() throws InterruptedException { | 152 public void testSimpleItemSelection() throws InterruptedException { |
153 mChooserDialog = createDialog(false /* usingIcon */); | |
154 | |
121 Dialog dialog = mChooserDialog.getDialogForTesting(); | 155 Dialog dialog = mChooserDialog.getDialogForTesting(); |
122 assertTrue(dialog.isShowing()); | 156 assertTrue(dialog.isShowing()); |
123 | 157 |
124 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) | 158 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) |
125 dialog.findViewById(R.id.status); | 159 dialog.findViewById(R.id.status); |
126 final ListView items = (ListView) dialog.findViewById(R.id.items); | 160 final ListView items = (ListView) dialog.findViewById(R.id.items); |
127 final Button button = (Button) dialog.findViewById(R.id.positive); | 161 final Button button = (Button) dialog.findViewById(R.id.positive); |
128 | 162 |
129 // Before we add items to the dialog, the 'searching' message should be | 163 // Before we add items to the dialog, the 'searching' message should be |
130 // showing, the Commit button should be disabled and the list view hidde n. | 164 // showing, the Commit button should be disabled and the list view hidde n. |
(...skipping 21 matching lines...) Expand all Loading... | |
152 assertFalse(button.isEnabled()); | 186 assertFalse(button.isEnabled()); |
153 | 187 |
154 // Select the first item and verify it got selected. | 188 // Select the first item and verify it got selected. |
155 selectItem(dialog, 1, "key", true); | 189 selectItem(dialog, 1, "key", true); |
156 | 190 |
157 mChooserDialog.dismiss(); | 191 mChooserDialog.dismiss(); |
158 } | 192 } |
159 | 193 |
160 @LargeTest | 194 @LargeTest |
161 public void testNoItemsAddedDiscoveryIdle() throws InterruptedException { | 195 public void testNoItemsAddedDiscoveryIdle() throws InterruptedException { |
196 mChooserDialog = createDialog(false /* usingIcon */); | |
162 Dialog dialog = mChooserDialog.getDialogForTesting(); | 197 Dialog dialog = mChooserDialog.getDialogForTesting(); |
163 assertTrue(dialog.isShowing()); | 198 assertTrue(dialog.isShowing()); |
164 | 199 |
165 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) | 200 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) |
166 dialog.findViewById(R.id.status); | 201 dialog.findViewById(R.id.status); |
167 final ListView items = (ListView) dialog.findViewById(R.id.items); | 202 final ListView items = (ListView) dialog.findViewById(R.id.items); |
168 final Button button = (Button) dialog.findViewById(R.id.positive); | 203 final Button button = (Button) dialog.findViewById(R.id.positive); |
169 | 204 |
170 // Before we add items to the dialog, the 'searching' message should be | 205 // Before we add items to the dialog, the 'searching' message should be |
171 // showing, the Commit button should be disabled and the list view hidde n. | 206 // showing, the Commit button should be disabled and the list view hidde n. |
172 assertEquals("searching", statusView.getText().toString()); | 207 assertEquals("searching", statusView.getText().toString()); |
173 assertFalse(button.isEnabled()); | 208 assertFalse(button.isEnabled()); |
174 assertEquals(View.GONE, items.getVisibility()); | 209 assertEquals(View.GONE, items.getVisibility()); |
175 | 210 |
176 mChooserDialog.setIdleState(); | 211 mChooserDialog.setIdleState(); |
177 | 212 |
178 // Listview should now be showing empty, with an empty view visible to | 213 // Listview should now be showing empty, with an empty view visible to |
179 // drive home the point and a status message at the bottom. | 214 // drive home the point and a status message at the bottom. |
180 assertEquals(View.GONE, items.getVisibility()); | 215 assertEquals(View.GONE, items.getVisibility()); |
181 assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); | 216 assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); |
182 assertEquals("statusIdleNoneFound", statusView.getText().toString()); | 217 assertEquals("statusIdleNoneFound", statusView.getText().toString()); |
183 assertFalse(button.isEnabled()); | 218 assertFalse(button.isEnabled()); |
184 | 219 |
185 mChooserDialog.dismiss(); | 220 mChooserDialog.dismiss(); |
186 } | 221 } |
187 | 222 |
188 @LargeTest | 223 @LargeTest |
189 public void testDisabledSelection() throws InterruptedException { | 224 public void testDisabledSelection() throws InterruptedException { |
225 mChooserDialog = createDialog(false /* usingIcon */); | |
190 Dialog dialog = mChooserDialog.getDialogForTesting(); | 226 Dialog dialog = mChooserDialog.getDialogForTesting(); |
191 assertTrue(dialog.isShowing()); | 227 assertTrue(dialog.isShowing()); |
192 | 228 |
193 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key ", "key")); | 229 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key ", "key")); |
194 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key 2", "key2")); | 230 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key 2", "key2")); |
195 | 231 |
196 // Disable one item and try to select it. | 232 // Disable one item and try to select it. |
197 mChooserDialog.setEnabled("key", false); | 233 mChooserDialog.setEnabled("key", false); |
198 selectItem(dialog, 1, "None", false); | 234 selectItem(dialog, 1, "None", false); |
199 // The other is still selectable. | 235 // The other is still selectable. |
200 selectItem(dialog, 2, "key2", true); | 236 selectItem(dialog, 2, "key2", true); |
201 | 237 |
202 mChooserDialog.dismiss(); | 238 mChooserDialog.dismiss(); |
203 } | 239 } |
204 | 240 |
205 @LargeTest | 241 @LargeTest |
242 public void testNotUsingIconAdapterRows() throws InterruptedException { | |
243 mChooserDialog = createDialog(false /* usingIcon */); | |
244 Dialog dialog = mChooserDialog.getDialogForTesting(); | |
245 assertTrue(dialog.isShowing()); | |
246 | |
247 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | |
248 final ListView items = (ListView) dialog.findViewById(R.id.items); | |
249 | |
250 // Initially the itemAdapter is empty. | |
251 assertTrue(itemAdapter.isEmpty()); | |
252 | |
253 // Add item 1 with no icon. | |
254 ItemChooserDialog.ItemChooserRow item1 = | |
255 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | |
256 mChooserDialog.addOrUpdateItem(item1); | |
257 assertEquals(View.GONE, getImageContainerVisibilityForItem(items, 0)); | |
258 | |
259 ItemChooserDialog.ItemChooserRow item2 = | |
260 new ItemChooserDialog.ItemChooserRow("key2", "desc2", mTestIcon1 ); | |
261 mChooserDialog.addOrUpdateItem(item2); | |
262 assertEquals(View.GONE, getImageContainerVisibilityForItem(items, 1)); | |
263 | |
264 mChooserDialog.setIdleState(); | |
265 mChooserDialog.dismiss(); | |
266 } | |
267 | |
268 @LargeTest | |
269 public void testUsingIconAdapterRows() throws InterruptedException { | |
270 mChooserDialog = createDialog(true /* usingIcon */); | |
271 Dialog dialog = mChooserDialog.getDialogForTesting(); | |
272 assertTrue(dialog.isShowing()); | |
273 | |
274 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | |
275 final ListView items = (ListView) dialog.findViewById(R.id.items); | |
276 | |
277 // Initially the itemAdapter is empty. | |
278 assertTrue(itemAdapter.isEmpty()); | |
279 | |
280 // Add item 1 with no icon. | |
281 ItemChooserDialog.ItemChooserRow item1 = | |
282 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | |
283 mChooserDialog.addOrUpdateItem(item1); | |
284 assertEquals(View.INVISIBLE, getImageContainerVisibilityForItem(items, 0 )); | |
285 | |
286 ItemChooserDialog.ItemChooserRow item2 = | |
287 new ItemChooserDialog.ItemChooserRow("key2", "desc2", mTestIcon1 ); | |
288 mChooserDialog.addOrUpdateItem(item2); | |
289 assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 1)) ; | |
290 | |
291 mChooserDialog.setIdleState(); | |
292 mChooserDialog.dismiss(); | |
293 } | |
294 | |
295 @LargeTest | |
296 public void testUpdateItemWithIconToNoIcon() throws InterruptedException { | |
297 mChooserDialog = createDialog(true /* usingIcon */); | |
298 Dialog dialog = mChooserDialog.getDialogForTesting(); | |
299 assertTrue(dialog.isShowing()); | |
300 | |
301 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | |
302 final ListView items = (ListView) dialog.findViewById(R.id.items); | |
303 | |
304 // Initially the itemAdapter is empty. | |
305 assertTrue(itemAdapter.isEmpty()); | |
306 | |
307 // Add item 1. | |
308 ItemChooserDialog.ItemChooserRow item1 = | |
309 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1 ); | |
310 mChooserDialog.addOrUpdateItem(item1); | |
311 assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)) ; | |
312 assertEquals(1, itemAdapter.getCount()); | |
313 assertEquals(itemAdapter.getItem(0), item1); | |
314 | |
315 // Add item 1 with no icon. | |
316 ItemChooserDialog.ItemChooserRow item1WithNoIcon = | |
317 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | |
318 mChooserDialog.addOrUpdateItem(item1WithNoIcon); | |
319 assertEquals(1, itemAdapter.getCount()); | |
320 // We should still see the original item with the icon. | |
321 ItemChooserDialog.ItemChooserRow expectedItem = | |
322 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1 ); | |
323 assertEquals(itemAdapter.getItem(0), expectedItem); | |
324 assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)) ; | |
325 | |
326 mChooserDialog.setIdleState(); | |
327 mChooserDialog.dismiss(); | |
328 } | |
329 | |
330 @LargeTest | |
331 public void testUpdateItemWithNoIconToIcon() throws InterruptedException { | |
332 mChooserDialog = createDialog(true /* usingIcon */); | |
333 Dialog dialog = mChooserDialog.getDialogForTesting(); | |
334 assertTrue(dialog.isShowing()); | |
335 | |
336 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | |
337 final ListView items = (ListView) dialog.findViewById(R.id.items); | |
338 | |
339 // Initially the itemAdapter is empty. | |
340 assertTrue(itemAdapter.isEmpty()); | |
341 | |
342 // Add item 1 with no icon. | |
343 ItemChooserDialog.ItemChooserRow item1WithNoIcon = | |
344 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | |
345 mChooserDialog.addOrUpdateItem(item1WithNoIcon); | |
346 assertEquals(View.INVISIBLE, getImageContainerVisibilityForItem(items, 0 )); | |
347 assertEquals(1, itemAdapter.getCount()); | |
348 assertEquals(itemAdapter.getItem(0), item1WithNoIcon); | |
349 | |
350 // Add item 1 with icon. | |
351 ItemChooserDialog.ItemChooserRow item1 = | |
352 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1 ); | |
353 mChooserDialog.addOrUpdateItem(item1); | |
354 assertEquals(1, itemAdapter.getCount()); | |
355 ItemChooserDialog.ItemChooserRow expectedItem = | |
356 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1 ); | |
357 assertEquals(itemAdapter.getItem(0), expectedItem); | |
358 assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)) ; | |
359 | |
360 mChooserDialog.setIdleState(); | |
361 mChooserDialog.dismiss(); | |
362 } | |
363 | |
364 @LargeTest | |
365 public void testUpdateItemWithNoIconToNoIcon() throws InterruptedException { | |
366 mChooserDialog = createDialog(true /* usingIcon */); | |
367 Dialog dialog = mChooserDialog.getDialogForTesting(); | |
368 assertTrue(dialog.isShowing()); | |
369 | |
370 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | |
371 final ListView items = (ListView) dialog.findViewById(R.id.items); | |
372 | |
373 // Initially the itemAdapter is empty. | |
374 assertTrue(itemAdapter.isEmpty()); | |
375 | |
376 // Add item 1 with no icon. | |
377 ItemChooserDialog.ItemChooserRow item1WithNoIcon = | |
378 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | |
379 mChooserDialog.addOrUpdateItem(item1WithNoIcon); | |
380 assertEquals(View.INVISIBLE, getImageContainerVisibilityForItem(items, 0 )); | |
381 assertEquals(1, itemAdapter.getCount()); | |
382 assertEquals(itemAdapter.getItem(0), item1WithNoIcon); | |
383 | |
384 // Add item 1 with no icon again. | |
385 mChooserDialog.addOrUpdateItem(item1WithNoIcon); | |
386 assertEquals(1, itemAdapter.getCount()); | |
387 ItemChooserDialog.ItemChooserRow expectedItem = | |
388 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | |
389 assertEquals(itemAdapter.getItem(0), expectedItem); | |
390 assertEquals(View.INVISIBLE, getImageContainerVisibilityForItem(items, 0 )); | |
391 | |
392 mChooserDialog.setIdleState(); | |
393 mChooserDialog.dismiss(); | |
394 } | |
395 | |
juncai
2016/09/26 18:49:01
Maybe add some test code to test different color i
| |
396 @LargeTest | |
206 public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedExc eption { | 397 public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedExc eption { |
398 mChooserDialog = createDialog(true /* usingIcon */); | |
207 Dialog dialog = mChooserDialog.getDialogForTesting(); | 399 Dialog dialog = mChooserDialog.getDialogForTesting(); |
208 assertTrue(dialog.isShowing()); | 400 assertTrue(dialog.isShowing()); |
209 | 401 |
210 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) | 402 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) |
211 dialog.findViewById(R.id.status); | 403 dialog.findViewById(R.id.status); |
212 final ListView items = (ListView) dialog.findViewById(R.id.items); | 404 final ListView items = (ListView) dialog.findViewById(R.id.items); |
213 final Button button = (Button) dialog.findViewById(R.id.positive); | 405 final Button button = (Button) dialog.findViewById(R.id.positive); |
214 | 406 |
215 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | 407 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); |
216 ItemChooserDialog.ItemChooserRow nonExistentItem = | 408 ItemChooserDialog.ItemChooserRow nonExistentItem = |
217 new ItemChooserDialog.ItemChooserRow("key", "key"); | 409 new ItemChooserDialog.ItemChooserRow("key", "key"); |
218 | 410 |
219 // Initially the itemAdapter is empty. | 411 // Initially the itemAdapter is empty. |
220 assertTrue(itemAdapter.isEmpty()); | 412 assertTrue(itemAdapter.isEmpty()); |
221 | 413 |
222 // Try removing an item from an empty itemAdapter. | 414 // Try removing an item from an empty itemAdapter. |
223 mChooserDialog.removeItemFromList(nonExistentItem); | 415 mChooserDialog.removeItemFromList(nonExistentItem); |
224 assertTrue(itemAdapter.isEmpty()); | 416 assertTrue(itemAdapter.isEmpty()); |
225 | 417 |
226 // Add item 1. | 418 // Add item 1. |
227 ItemChooserDialog.ItemChooserRow item1 = | 419 ItemChooserDialog.ItemChooserRow item1 = |
228 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | 420 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1 ); |
229 mChooserDialog.addOrUpdateItem(item1); | 421 mChooserDialog.addOrUpdateItem(item1); |
230 assertEquals(1, itemAdapter.getCount()); | 422 assertEquals(1, itemAdapter.getCount()); |
231 assertEquals(itemAdapter.getItem(0), item1); | 423 assertEquals(itemAdapter.getItem(0), item1); |
424 assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)) ; | |
232 | 425 |
233 // Add item 1 with different description. | 426 // Add item 1 with different description and icon. |
234 ItemChooserDialog.ItemChooserRow item1_again = | 427 ItemChooserDialog.ItemChooserRow item1Again = |
235 new ItemChooserDialog.ItemChooserRow("key1", "desc1_again"); | 428 new ItemChooserDialog.ItemChooserRow("key1", "desc1_again", mTes tIcon2); |
236 mChooserDialog.addOrUpdateItem(item1_again); | 429 mChooserDialog.addOrUpdateItem(item1Again); |
237 assertEquals(1, itemAdapter.getCount()); | 430 assertEquals(1, itemAdapter.getCount()); |
238 assertEquals(itemAdapter.getItem(0), item1_again); | 431 assertEquals(itemAdapter.getItem(0), item1Again); |
432 assertEquals(View.VISIBLE, getImageContainerVisibilityForItem(items, 0)) ; | |
239 | 433 |
240 // Add item 2. | 434 // Add item 2. |
241 ItemChooserDialog.ItemChooserRow item2 = | 435 ItemChooserDialog.ItemChooserRow item2 = |
242 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); | 436 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); |
243 mChooserDialog.addOrUpdateItem(item2); | 437 mChooserDialog.addOrUpdateItem(item2); |
244 assertEquals(2, itemAdapter.getCount()); | 438 assertEquals(2, itemAdapter.getCount()); |
245 assertEquals(itemAdapter.getItem(0), item1_again); | 439 assertEquals(itemAdapter.getItem(0), item1Again); |
246 assertEquals(itemAdapter.getItem(1), item2); | 440 assertEquals(itemAdapter.getItem(1), item2); |
441 assertEquals(View.INVISIBLE, getImageContainerVisibilityForItem(items, 1 )); | |
247 | 442 |
248 mChooserDialog.setIdleState(); | 443 mChooserDialog.setIdleState(); |
249 | 444 |
250 // Try removing an item that doesn't exist. | 445 // Try removing an item that doesn't exist. |
251 mChooserDialog.removeItemFromList(nonExistentItem); | 446 mChooserDialog.removeItemFromList(nonExistentItem); |
252 assertEquals(2, itemAdapter.getCount()); | 447 assertEquals(2, itemAdapter.getCount()); |
253 | 448 |
254 // Remove item 2. | 449 // Remove item 2. |
255 mChooserDialog.removeItemFromList(item2); | 450 mChooserDialog.removeItemFromList(item2); |
256 assertEquals(1, itemAdapter.getCount()); | 451 assertEquals(1, itemAdapter.getCount()); |
257 assertEquals(itemAdapter.getItem(0), item1_again); | 452 assertEquals(itemAdapter.getItem(0), item1Again); |
258 | 453 |
259 // The list should be visible with one item, it should not show | 454 // The list should be visible with one item, it should not show |
260 // the empty view and the button should not be enabled. | 455 // the empty view and the button should not be enabled. |
261 // The chooser should show a status message at the bottom. | 456 // The chooser should show a status message at the bottom. |
262 assertEquals(View.VISIBLE, items.getVisibility()); | 457 assertEquals(View.VISIBLE, items.getVisibility()); |
263 assertEquals(View.GONE, items.getEmptyView().getVisibility()); | 458 assertEquals(View.GONE, items.getEmptyView().getVisibility()); |
264 assertEquals("statusIdleSomeFound", statusView.getText().toString()); | 459 assertEquals("statusIdleSomeFound", statusView.getText().toString()); |
265 assertFalse(button.isEnabled()); | 460 assertFalse(button.isEnabled()); |
266 | 461 |
267 // Remove item 1. | 462 // Remove item 1. |
268 mChooserDialog.removeItemFromList(item1_again); | 463 mChooserDialog.removeItemFromList(item1Again); |
269 assertTrue(itemAdapter.isEmpty()); | 464 assertTrue(itemAdapter.isEmpty()); |
270 | 465 |
271 // Listview should now be showing empty, with an empty view visible | 466 // Listview should now be showing empty, with an empty view visible |
272 // and the button should not be enabled. | 467 // and the button should not be enabled. |
273 // The chooser should show a status message at the bottom. | 468 // The chooser should show a status message at the bottom. |
274 assertEquals(View.GONE, items.getVisibility()); | 469 assertEquals(View.GONE, items.getVisibility()); |
275 assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); | 470 assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); |
276 assertEquals("statusIdleNoneFound", statusView.getText().toString()); | 471 assertEquals("statusIdleNoneFound", statusView.getText().toString()); |
277 assertFalse(button.isEnabled()); | 472 assertFalse(button.isEnabled()); |
278 | 473 |
279 mChooserDialog.dismiss(); | 474 mChooserDialog.dismiss(); |
280 } | 475 } |
281 | 476 |
282 @LargeTest | 477 @LargeTest |
283 public void testAddItemWithSameNameToListAndRemoveItemFromList() throws Inte rruptedException { | 478 public void testAddItemWithSameNameToListAndRemoveItemFromList() throws Inte rruptedException { |
479 mChooserDialog = createDialog(false /* usingIcon */); | |
284 Dialog dialog = mChooserDialog.getDialogForTesting(); | 480 Dialog dialog = mChooserDialog.getDialogForTesting(); |
285 assertTrue(dialog.isShowing()); | 481 assertTrue(dialog.isShowing()); |
286 | 482 |
287 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); | 483 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); |
288 | 484 |
289 // Add item 1. | 485 // Add item 1. |
290 ItemChooserDialog.ItemChooserRow item1 = | 486 ItemChooserDialog.ItemChooserRow item1 = |
291 new ItemChooserDialog.ItemChooserRow("device_id_1", "same_device _name"); | 487 new ItemChooserDialog.ItemChooserRow("device_id_1", "same_device _name"); |
292 mChooserDialog.addOrUpdateItem(item1); | 488 mChooserDialog.addOrUpdateItem(item1); |
293 assertEquals(1, itemAdapter.getCount()); | 489 assertEquals(1, itemAdapter.getCount()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 | 543 |
348 // 1460 * .3 is 438, which rounds above the maximum height. | 544 // 1460 * .3 is 438, which rounds above the maximum height. |
349 assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f)); | 545 assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f)); |
350 | 546 |
351 // 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp * | 547 // 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp * |
352 // 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds t o | 548 // 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds t o |
353 // 370. | 549 // 370. |
354 assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f)); | 550 assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f)); |
355 } | 551 } |
356 } | 552 } |
OLD | NEW |