| 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( |
| 53 resources, R.drawable.ic_signal_cellular_0_bar_grey, nul
l /* theme */), |
| 54 VectorDrawableCompat.create( |
| 55 resources, R.drawable.ic_signal_cellular_0_bar_white, nu
ll /* theme */), |
| 56 resources.getQuantityString(R.plurals.signal_strength_level_n_ba
rs, 0, 0)); |
| 57 |
| 58 mTestIcon2 = new ItemChooserDialog.ItemChooserRowIcon( |
| 59 VectorDrawableCompat.create( |
| 60 resources, R.drawable.ic_signal_cellular_1_bar_grey, nul
l /* theme */), |
| 61 VectorDrawableCompat.create( |
| 62 resources, R.drawable.ic_signal_cellular_1_bar_white, nu
ll /* 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 getIconVisibilityForItem(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.icon).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, getIconVisibilityForItem(items, 0)); |
| 258 |
| 259 ItemChooserDialog.ItemChooserRow item2 = |
| 260 new ItemChooserDialog.ItemChooserRow("key2", "desc2", mTestIcon1
); |
| 261 mChooserDialog.addOrUpdateItem(item2); |
| 262 assertEquals(View.GONE, getIconVisibilityForItem(items, 1)); |
| 263 |
| 264 mChooserDialog.setIdleState(); |
| 265 mChooserDialog.dismiss(); |
| 266 } |
| 267 |
| 268 @LargeTest |
| 206 public void testPairButtonDisabledOrEnabledAfterSelectedItemDisabledOrEnable
d() | 269 public void testPairButtonDisabledOrEnabledAfterSelectedItemDisabledOrEnable
d() |
| 207 throws InterruptedException { | 270 throws InterruptedException { |
| 208 Dialog dialog = mChooserDialog.getDialogForTesting(); | 271 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 209 assertTrue(dialog.isShowing()); | 272 assertTrue(dialog.isShowing()); |
| 210 | 273 |
| 211 final Button button = (Button) dialog.findViewById(R.id.positive); | 274 final Button button = (Button) dialog.findViewById(R.id.positive); |
| 212 | 275 |
| 213 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key
1", "desc1")); | 276 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key
1", "desc1")); |
| 214 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key
2", "desc2")); | 277 mChooserDialog.addOrUpdateItem(new ItemChooserDialog.ItemChooserRow("key
2", "desc2")); |
| 215 | 278 |
| 216 selectItem(dialog, 1, "key1", true); | 279 selectItem(dialog, 1, "key1", true); |
| 217 assertTrue(button.isEnabled()); | 280 assertTrue(button.isEnabled()); |
| 218 | 281 |
| 219 mChooserDialog.setEnabled("key1", false); | 282 mChooserDialog.setEnabled("key1", false); |
| 220 assertFalse(button.isEnabled()); | 283 assertFalse(button.isEnabled()); |
| 221 | 284 |
| 222 mChooserDialog.setEnabled("key1", true); | 285 mChooserDialog.setEnabled("key1", true); |
| 223 assertTrue(button.isEnabled()); | 286 assertTrue(button.isEnabled()); |
| 224 | 287 |
| 225 mChooserDialog.dismiss(); | 288 mChooserDialog.dismiss(); |
| 226 } | 289 } |
| 227 | 290 |
| 228 @LargeTest | 291 @LargeTest |
| 292 public void testUsingIconAdapterRows() throws InterruptedException { |
| 293 mChooserDialog = createDialog(true /* usingIcon */); |
| 294 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 295 assertTrue(dialog.isShowing()); |
| 296 |
| 297 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 298 final ListView items = (ListView) dialog.findViewById(R.id.items); |
| 299 |
| 300 // Initially the itemAdapter is empty. |
| 301 assertTrue(itemAdapter.isEmpty()); |
| 302 |
| 303 // Add item 1 with no icon. |
| 304 ItemChooserDialog.ItemChooserRow item1 = |
| 305 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 306 mChooserDialog.addOrUpdateItem(item1); |
| 307 assertEquals(View.INVISIBLE, getIconVisibilityForItem(items, 0)); |
| 308 |
| 309 ItemChooserDialog.ItemChooserRow item2 = |
| 310 new ItemChooserDialog.ItemChooserRow("key2", "desc2", mTestIcon1
); |
| 311 mChooserDialog.addOrUpdateItem(item2); |
| 312 assertEquals(View.VISIBLE, getIconVisibilityForItem(items, 1)); |
| 313 |
| 314 mChooserDialog.setIdleState(); |
| 315 mChooserDialog.dismiss(); |
| 316 } |
| 317 |
| 318 @LargeTest |
| 229 public void testPairButtonDisabledAfterSelectedItemRemoved() throws Interrup
tedException { | 319 public void testPairButtonDisabledAfterSelectedItemRemoved() throws Interrup
tedException { |
| 230 Dialog dialog = mChooserDialog.getDialogForTesting(); | 320 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 231 assertTrue(dialog.isShowing()); | 321 assertTrue(dialog.isShowing()); |
| 232 | 322 |
| 233 final Button button = (Button) dialog.findViewById(R.id.positive); | 323 final Button button = (Button) dialog.findViewById(R.id.positive); |
| 234 | 324 |
| 235 ItemChooserDialog.ItemChooserRow item1 = | 325 ItemChooserDialog.ItemChooserRow item1 = |
| 236 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | 326 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 237 ItemChooserDialog.ItemChooserRow item2 = | 327 ItemChooserDialog.ItemChooserRow item2 = |
| 238 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); | 328 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); |
| 239 mChooserDialog.addOrUpdateItem(item1); | 329 mChooserDialog.addOrUpdateItem(item1); |
| 240 mChooserDialog.addOrUpdateItem(item2); | 330 mChooserDialog.addOrUpdateItem(item2); |
| 241 | 331 |
| 242 selectItem(dialog, 1, "key1", true); | 332 selectItem(dialog, 1, "key1", true); |
| 243 assertTrue(button.isEnabled()); | 333 assertTrue(button.isEnabled()); |
| 244 | 334 |
| 245 mChooserDialog.removeItemFromList(item1); | 335 mChooserDialog.removeItemFromList(item1); |
| 246 assertFalse(button.isEnabled()); | 336 assertFalse(button.isEnabled()); |
| 247 | 337 |
| 248 mChooserDialog.dismiss(); | 338 mChooserDialog.dismiss(); |
| 249 } | 339 } |
| 250 | 340 |
| 251 @LargeTest | 341 @LargeTest |
| 342 public void testUpdateItemWithIconToNoIcon() throws InterruptedException { |
| 343 mChooserDialog = createDialog(true /* usingIcon */); |
| 344 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 345 assertTrue(dialog.isShowing()); |
| 346 |
| 347 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 348 final ListView items = (ListView) dialog.findViewById(R.id.items); |
| 349 |
| 350 // Initially the itemAdapter is empty. |
| 351 assertTrue(itemAdapter.isEmpty()); |
| 352 |
| 353 // Add item 1. |
| 354 ItemChooserDialog.ItemChooserRow item1 = |
| 355 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1
); |
| 356 mChooserDialog.addOrUpdateItem(item1); |
| 357 assertEquals(View.VISIBLE, getIconVisibilityForItem(items, 0)); |
| 358 assertEquals(1, itemAdapter.getCount()); |
| 359 assertEquals(itemAdapter.getItem(0), item1); |
| 360 |
| 361 // Add item 1 with no icon. |
| 362 ItemChooserDialog.ItemChooserRow item1WithNoIcon = |
| 363 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 364 mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| 365 assertEquals(1, itemAdapter.getCount()); |
| 366 // We should still see the original item with the icon. |
| 367 ItemChooserDialog.ItemChooserRow expectedItem = |
| 368 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1
); |
| 369 assertEquals(itemAdapter.getItem(0), expectedItem); |
| 370 assertEquals(View.VISIBLE, getIconVisibilityForItem(items, 0)); |
| 371 |
| 372 mChooserDialog.setIdleState(); |
| 373 mChooserDialog.dismiss(); |
| 374 } |
| 375 |
| 376 @LargeTest |
| 377 public void testUpdateItemWithNoIconToIcon() throws InterruptedException { |
| 378 mChooserDialog = createDialog(true /* usingIcon */); |
| 379 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 380 assertTrue(dialog.isShowing()); |
| 381 |
| 382 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 383 final ListView items = (ListView) dialog.findViewById(R.id.items); |
| 384 |
| 385 // Initially the itemAdapter is empty. |
| 386 assertTrue(itemAdapter.isEmpty()); |
| 387 |
| 388 // Add item 1 with no icon. |
| 389 ItemChooserDialog.ItemChooserRow item1WithNoIcon = |
| 390 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 391 mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| 392 assertEquals(View.INVISIBLE, getIconVisibilityForItem(items, 0)); |
| 393 assertEquals(1, itemAdapter.getCount()); |
| 394 assertEquals(itemAdapter.getItem(0), item1WithNoIcon); |
| 395 |
| 396 // Add item 1 with icon. |
| 397 ItemChooserDialog.ItemChooserRow item1 = |
| 398 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1
); |
| 399 mChooserDialog.addOrUpdateItem(item1); |
| 400 assertEquals(1, itemAdapter.getCount()); |
| 401 ItemChooserDialog.ItemChooserRow expectedItem = |
| 402 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1
); |
| 403 assertEquals(itemAdapter.getItem(0), expectedItem); |
| 404 assertEquals(View.VISIBLE, getIconVisibilityForItem(items, 0)); |
| 405 |
| 406 mChooserDialog.setIdleState(); |
| 407 mChooserDialog.dismiss(); |
| 408 } |
| 409 |
| 410 @LargeTest |
| 252 public void testSelectAnItemAndRemoveAnotherItem() throws InterruptedExcepti
on { | 411 public void testSelectAnItemAndRemoveAnotherItem() throws InterruptedExcepti
on { |
| 253 Dialog dialog = mChooserDialog.getDialogForTesting(); | 412 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 254 assertTrue(dialog.isShowing()); | 413 assertTrue(dialog.isShowing()); |
| 255 | 414 |
| 256 final Button button = (Button) dialog.findViewById(R.id.positive); | 415 final Button button = (Button) dialog.findViewById(R.id.positive); |
| 257 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); | 416 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 258 | 417 |
| 259 ItemChooserDialog.ItemChooserRow item1 = | 418 ItemChooserDialog.ItemChooserRow item1 = |
| 260 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | 419 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 261 ItemChooserDialog.ItemChooserRow item2 = | 420 ItemChooserDialog.ItemChooserRow item2 = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 277 | 436 |
| 278 // Remove the item after the currently selected item. | 437 // Remove the item after the currently selected item. |
| 279 mChooserDialog.removeItemFromList(item3); | 438 mChooserDialog.removeItemFromList(item3); |
| 280 assertTrue(button.isEnabled()); | 439 assertTrue(button.isEnabled()); |
| 281 assertEquals("key2", itemAdapter.getSelectedItemKey()); | 440 assertEquals("key2", itemAdapter.getSelectedItemKey()); |
| 282 | 441 |
| 283 mChooserDialog.dismiss(); | 442 mChooserDialog.dismiss(); |
| 284 } | 443 } |
| 285 | 444 |
| 286 @LargeTest | 445 @LargeTest |
| 446 public void testUpdateItemWithNoIconToNoIcon() throws InterruptedException { |
| 447 mChooserDialog = createDialog(true /* usingIcon */); |
| 448 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 449 assertTrue(dialog.isShowing()); |
| 450 |
| 451 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 452 final ListView items = (ListView) dialog.findViewById(R.id.items); |
| 453 |
| 454 // Initially the itemAdapter is empty. |
| 455 assertTrue(itemAdapter.isEmpty()); |
| 456 |
| 457 // Add item 1 with no icon. |
| 458 ItemChooserDialog.ItemChooserRow item1WithNoIcon = |
| 459 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 460 mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| 461 assertEquals(View.INVISIBLE, getIconVisibilityForItem(items, 0)); |
| 462 assertEquals(1, itemAdapter.getCount()); |
| 463 assertEquals(itemAdapter.getItem(0), item1WithNoIcon); |
| 464 |
| 465 // Add item 1 with no icon again. |
| 466 mChooserDialog.addOrUpdateItem(item1WithNoIcon); |
| 467 assertEquals(1, itemAdapter.getCount()); |
| 468 ItemChooserDialog.ItemChooserRow expectedItem = |
| 469 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 470 assertEquals(itemAdapter.getItem(0), expectedItem); |
| 471 assertEquals(View.INVISIBLE, getIconVisibilityForItem(items, 0)); |
| 472 |
| 473 mChooserDialog.setIdleState(); |
| 474 mChooserDialog.dismiss(); |
| 475 } |
| 476 |
| 477 @LargeTest |
| 287 public void testSelectAnItemAndRemoveTheSelectedItem() throws InterruptedExc
eption { | 478 public void testSelectAnItemAndRemoveTheSelectedItem() throws InterruptedExc
eption { |
| 288 Dialog dialog = mChooserDialog.getDialogForTesting(); | 479 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 289 assertTrue(dialog.isShowing()); | 480 assertTrue(dialog.isShowing()); |
| 290 | 481 |
| 291 final Button button = (Button) dialog.findViewById(R.id.positive); | 482 final Button button = (Button) dialog.findViewById(R.id.positive); |
| 292 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); | 483 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 293 | 484 |
| 294 ItemChooserDialog.ItemChooserRow item1 = | 485 ItemChooserDialog.ItemChooserRow item1 = |
| 295 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | 486 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); |
| 296 ItemChooserDialog.ItemChooserRow item2 = | 487 ItemChooserDialog.ItemChooserRow item2 = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 308 // Remove the selected item. | 499 // Remove the selected item. |
| 309 mChooserDialog.removeItemFromList(item2); | 500 mChooserDialog.removeItemFromList(item2); |
| 310 assertFalse(button.isEnabled()); | 501 assertFalse(button.isEnabled()); |
| 311 assertEquals("", itemAdapter.getSelectedItemKey()); | 502 assertEquals("", itemAdapter.getSelectedItemKey()); |
| 312 | 503 |
| 313 mChooserDialog.dismiss(); | 504 mChooserDialog.dismiss(); |
| 314 } | 505 } |
| 315 | 506 |
| 316 @LargeTest | 507 @LargeTest |
| 317 public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedExc
eption { | 508 public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedExc
eption { |
| 509 mChooserDialog = createDialog(true /* usingIcon */); |
| 318 Dialog dialog = mChooserDialog.getDialogForTesting(); | 510 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 319 assertTrue(dialog.isShowing()); | 511 assertTrue(dialog.isShowing()); |
| 320 | 512 |
| 321 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) | 513 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) |
| 322 dialog.findViewById(R.id.status); | 514 dialog.findViewById(R.id.status); |
| 323 final ListView items = (ListView) dialog.findViewById(R.id.items); | 515 final ListView items = (ListView) dialog.findViewById(R.id.items); |
| 324 final Button button = (Button) dialog.findViewById(R.id.positive); | 516 final Button button = (Button) dialog.findViewById(R.id.positive); |
| 325 | 517 |
| 326 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); | 518 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 327 ItemChooserDialog.ItemChooserRow nonExistentItem = | 519 ItemChooserDialog.ItemChooserRow nonExistentItem = |
| 328 new ItemChooserDialog.ItemChooserRow("key", "key"); | 520 new ItemChooserDialog.ItemChooserRow("key", "key"); |
| 329 | 521 |
| 330 // Initially the itemAdapter is empty. | 522 // Initially the itemAdapter is empty. |
| 331 assertTrue(itemAdapter.isEmpty()); | 523 assertTrue(itemAdapter.isEmpty()); |
| 332 | 524 |
| 333 // Try removing an item from an empty itemAdapter. | 525 // Try removing an item from an empty itemAdapter. |
| 334 mChooserDialog.removeItemFromList(nonExistentItem); | 526 mChooserDialog.removeItemFromList(nonExistentItem); |
| 335 assertTrue(itemAdapter.isEmpty()); | 527 assertTrue(itemAdapter.isEmpty()); |
| 336 | 528 |
| 337 // Add item 1. | 529 // Add item 1. |
| 338 ItemChooserDialog.ItemChooserRow item1 = | 530 ItemChooserDialog.ItemChooserRow item1 = |
| 339 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); | 531 new ItemChooserDialog.ItemChooserRow("key1", "desc1", mTestIcon1
); |
| 340 mChooserDialog.addOrUpdateItem(item1); | 532 mChooserDialog.addOrUpdateItem(item1); |
| 341 assertEquals(1, itemAdapter.getCount()); | 533 assertEquals(1, itemAdapter.getCount()); |
| 342 assertEquals(itemAdapter.getItem(0), item1); | 534 assertEquals(itemAdapter.getItem(0), item1); |
| 535 assertEquals(View.VISIBLE, getIconVisibilityForItem(items, 0)); |
| 343 | 536 |
| 344 // Add item 1 with different description. | 537 // Add item 1 with different description and icon. |
| 345 ItemChooserDialog.ItemChooserRow item1_again = | 538 ItemChooserDialog.ItemChooserRow item1Again = |
| 346 new ItemChooserDialog.ItemChooserRow("key1", "desc1_again"); | 539 new ItemChooserDialog.ItemChooserRow("key1", "desc1_again", mTes
tIcon2); |
| 347 mChooserDialog.addOrUpdateItem(item1_again); | 540 mChooserDialog.addOrUpdateItem(item1Again); |
| 348 assertEquals(1, itemAdapter.getCount()); | 541 assertEquals(1, itemAdapter.getCount()); |
| 349 assertEquals(itemAdapter.getItem(0), item1_again); | 542 assertEquals(itemAdapter.getItem(0), item1Again); |
| 543 assertEquals(View.VISIBLE, getIconVisibilityForItem(items, 0)); |
| 350 | 544 |
| 351 // Add item 2. | 545 // Add item 2. |
| 352 ItemChooserDialog.ItemChooserRow item2 = | 546 ItemChooserDialog.ItemChooserRow item2 = |
| 353 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); | 547 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); |
| 354 mChooserDialog.addOrUpdateItem(item2); | 548 mChooserDialog.addOrUpdateItem(item2); |
| 355 assertEquals(2, itemAdapter.getCount()); | 549 assertEquals(2, itemAdapter.getCount()); |
| 356 assertEquals(itemAdapter.getItem(0), item1_again); | 550 assertEquals(itemAdapter.getItem(0), item1Again); |
| 357 assertEquals(itemAdapter.getItem(1), item2); | 551 assertEquals(itemAdapter.getItem(1), item2); |
| 552 assertEquals(View.INVISIBLE, getIconVisibilityForItem(items, 1)); |
| 358 | 553 |
| 359 mChooserDialog.setIdleState(); | 554 mChooserDialog.setIdleState(); |
| 360 | 555 |
| 361 // Try removing an item that doesn't exist. | 556 // Try removing an item that doesn't exist. |
| 362 mChooserDialog.removeItemFromList(nonExistentItem); | 557 mChooserDialog.removeItemFromList(nonExistentItem); |
| 363 assertEquals(2, itemAdapter.getCount()); | 558 assertEquals(2, itemAdapter.getCount()); |
| 364 | 559 |
| 365 // Remove item 2. | 560 // Remove item 2. |
| 366 mChooserDialog.removeItemFromList(item2); | 561 mChooserDialog.removeItemFromList(item2); |
| 367 assertEquals(1, itemAdapter.getCount()); | 562 assertEquals(1, itemAdapter.getCount()); |
| 368 assertEquals(itemAdapter.getItem(0), item1_again); | 563 assertEquals(itemAdapter.getItem(0), item1Again); |
| 369 | 564 |
| 370 // The list should be visible with one item, it should not show | 565 // The list should be visible with one item, it should not show |
| 371 // the empty view and the button should not be enabled. | 566 // the empty view and the button should not be enabled. |
| 372 // The chooser should show a status message at the bottom. | 567 // The chooser should show a status message at the bottom. |
| 373 assertEquals(View.VISIBLE, items.getVisibility()); | 568 assertEquals(View.VISIBLE, items.getVisibility()); |
| 374 assertEquals(View.GONE, items.getEmptyView().getVisibility()); | 569 assertEquals(View.GONE, items.getEmptyView().getVisibility()); |
| 375 assertEquals("statusIdleSomeFound", statusView.getText().toString()); | 570 assertEquals("statusIdleSomeFound", statusView.getText().toString()); |
| 376 assertFalse(button.isEnabled()); | 571 assertFalse(button.isEnabled()); |
| 377 | 572 |
| 378 // Remove item 1. | 573 // Remove item 1. |
| 379 mChooserDialog.removeItemFromList(item1_again); | 574 mChooserDialog.removeItemFromList(item1Again); |
| 380 assertTrue(itemAdapter.isEmpty()); | 575 assertTrue(itemAdapter.isEmpty()); |
| 381 | 576 |
| 382 // Listview should now be showing empty, with an empty view visible | 577 // Listview should now be showing empty, with an empty view visible |
| 383 // and the button should not be enabled. | 578 // and the button should not be enabled. |
| 384 // The chooser should show a status message at the bottom. | 579 // The chooser should show a status message at the bottom. |
| 385 assertEquals(View.GONE, items.getVisibility()); | 580 assertEquals(View.GONE, items.getVisibility()); |
| 386 assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); | 581 assertEquals(View.VISIBLE, items.getEmptyView().getVisibility()); |
| 387 assertEquals("statusIdleNoneFound", statusView.getText().toString()); | 582 assertEquals("statusIdleNoneFound", statusView.getText().toString()); |
| 388 assertFalse(button.isEnabled()); | 583 assertFalse(button.isEnabled()); |
| 389 | 584 |
| 390 mChooserDialog.dismiss(); | 585 mChooserDialog.dismiss(); |
| 391 } | 586 } |
| 392 | 587 |
| 393 @LargeTest | 588 @LargeTest |
| 394 public void testAddItemWithSameNameToListAndRemoveItemFromList() throws Inte
rruptedException { | 589 public void testAddItemWithSameNameToListAndRemoveItemFromList() throws Inte
rruptedException { |
| 590 mChooserDialog = createDialog(false /* usingIcon */); |
| 395 Dialog dialog = mChooserDialog.getDialogForTesting(); | 591 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 396 assertTrue(dialog.isShowing()); | 592 assertTrue(dialog.isShowing()); |
| 397 | 593 |
| 398 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); | 594 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte
rForTesting(); |
| 399 | 595 |
| 400 // Add item 1. | 596 // Add item 1. |
| 401 ItemChooserDialog.ItemChooserRow item1 = | 597 ItemChooserDialog.ItemChooserRow item1 = |
| 402 new ItemChooserDialog.ItemChooserRow("device_id_1", "same_device
_name"); | 598 new ItemChooserDialog.ItemChooserRow("device_id_1", "same_device
_name"); |
| 403 mChooserDialog.addOrUpdateItem(item1); | 599 mChooserDialog.addOrUpdateItem(item1); |
| 404 assertEquals(1, itemAdapter.getCount()); | 600 assertEquals(1, itemAdapter.getCount()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 654 |
| 459 // 1460 * .3 is 438, which rounds above the maximum height. | 655 // 1460 * .3 is 438, which rounds above the maximum height. |
| 460 assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f)); | 656 assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f)); |
| 461 | 657 |
| 462 // 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp
* | 658 // 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp
* |
| 463 // 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds t
o | 659 // 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds t
o |
| 464 // 370. | 660 // 370. |
| 465 assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f)); | 661 assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f)); |
| 466 } | 662 } |
| 467 } | 663 } |
| OLD | NEW |