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

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

Issue 2271413002: bluetooth: Implement RSSI indicator on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-impl-rssi-tx-power
Patch Set: Clean up Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 import android.text.SpannableString; 9 import android.text.SpannableString;
10 import android.view.View; 10 import android.view.View;
(...skipping 14 matching lines...) Expand all
25 /** 25 /**
26 * Tests for the ItemChooserDialog class. 26 * Tests for the ItemChooserDialog class.
27 */ 27 */
28 public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi vity> 28 public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi vity>
29 implements ItemChooserDialog.ItemSelectedCallback { 29 implements ItemChooserDialog.ItemSelectedCallback {
30 30
31 ItemChooserDialog mChooserDialog; 31 ItemChooserDialog mChooserDialog;
32 32
33 String mLastSelectedId = "None"; 33 String mLastSelectedId = "None";
34 34
35 private static final ItemChooserDialog.ItemChooserRowIcon TEST_ICON1 =
36 new ItemChooserDialog.ItemChooserRowIcon(R.drawable.ic_signal_cellul ar_0_bar_black_48dp,
37 R.drawable.ic_signal_cellular_0_bar_white_48dp, "test icon1" );
38 private static final ItemChooserDialog.ItemChooserRowIcon TEST_ICON2 =
39 new ItemChooserDialog.ItemChooserRowIcon(R.drawable.ic_signal_cellul ar_1_bar_black_48dp,
40 R.drawable.ic_signal_cellular_1_bar_white_48dp, "test icon2" );
41
35 public ItemChooserDialogTest() { 42 public ItemChooserDialogTest() {
36 super(ChromeActivity.class); 43 super(ChromeActivity.class);
37 } 44 }
38 45
39 // ChromeActivityTestCaseBase: 46 // ChromeActivityTestCaseBase:
40 47
41 @Override 48 @Override
42 protected void setUp() throws Exception { 49 protected void setUp() throws Exception {
43 super.setUp(); 50 super.setUp();
44 mChooserDialog = createDialog(); 51 mChooserDialog = createDialog();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Disable one item and try to select it. 202 // Disable one item and try to select it.
196 mChooserDialog.setEnabled("key", false); 203 mChooserDialog.setEnabled("key", false);
197 selectItem(dialog, 1, "None", false); 204 selectItem(dialog, 1, "None", false);
198 // The other is still selectable. 205 // The other is still selectable.
199 selectItem(dialog, 2, "key2", true); 206 selectItem(dialog, 2, "key2", true);
200 207
201 mChooserDialog.dismiss(); 208 mChooserDialog.dismiss();
202 } 209 }
203 210
204 @SmallTest 211 @SmallTest
212 public void testUpdateItemWithIconToNoIcon() throws InterruptedException {
213 Dialog dialog = mChooserDialog.getDialogForTesting();
214 assertTrue(dialog.isShowing());
215
216 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting();
217
218 // Initially the itemAdapter is empty.
219 assertTrue(itemAdapter.isEmpty());
220
221 // Add item 1.
222 ItemChooserDialog.ItemChooserRow item1 =
223 new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1 );
224 mChooserDialog.addOrUpdateItem(item1);
225 assertEquals(1, itemAdapter.getCount());
226 assertEquals(itemAdapter.getItem(0), item1);
227
228 // Add item 1 with no icon.
229 ItemChooserDialog.ItemChooserRow item1_with_no_icon =
juncai 2016/08/26 19:37:48 Use lowerCamelCase. Same for the other variable n
ortuno 2016/09/12 05:11:28 Done.
230 new ItemChooserDialog.ItemChooserRow("key1", "desc1");
231 mChooserDialog.addOrUpdateItem(item1_with_no_icon);
232 assertEquals(1, itemAdapter.getCount());
233 // We should still see the original item with the icon.
234 assertEquals(itemAdapter.getItem(0), item1);
235
236 mChooserDialog.setIdleState();
237 mChooserDialog.dismiss();
238 }
239
240 @SmallTest
241 public void testUpdateItemWithNoIconToIcon() throws InterruptedException {
242 Dialog dialog = mChooserDialog.getDialogForTesting();
243 assertTrue(dialog.isShowing());
244
245 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting();
246
247 // Initially the itemAdapter is empty.
248 assertTrue(itemAdapter.isEmpty());
249
250 // Add item 1 with no icon.
251 ItemChooserDialog.ItemChooserRow item1_with_no_icon =
252 new ItemChooserDialog.ItemChooserRow("key1", "desc1");
253 mChooserDialog.addOrUpdateItem(item1_with_no_icon);
254 assertEquals(1, itemAdapter.getCount());
255 assertEquals(itemAdapter.getItem(0), item1_with_no_icon);
256
257 // Add item 1 with icon.
258 ItemChooserDialog.ItemChooserRow item1 =
259 new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1 );
260 mChooserDialog.addOrUpdateItem(item1);
261 assertEquals(1, itemAdapter.getCount());
262 assertEquals(itemAdapter.getItem(0), item1);
263
264 mChooserDialog.setIdleState();
265 mChooserDialog.dismiss();
266 }
267
268 @SmallTest
269 public void testUpdateItemWithNoIconToNoIcon() throws InterruptedException {
270 Dialog dialog = mChooserDialog.getDialogForTesting();
271 assertTrue(dialog.isShowing());
272
273 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting();
274
275 // Initially the itemAdapter is empty.
276 assertTrue(itemAdapter.isEmpty());
277
278 // Add item 1 with no icon.
279 ItemChooserDialog.ItemChooserRow item1_with_no_icon =
280 new ItemChooserDialog.ItemChooserRow("key1", "desc1");
281 mChooserDialog.addOrUpdateItem(item1_with_no_icon);
282 assertEquals(1, itemAdapter.getCount());
283 // We should still see the original item with the icon.
284 assertEquals(itemAdapter.getItem(0), item1_with_no_icon);
285
286 // Add item 1 with no icon again.
287 mChooserDialog.addOrUpdateItem(item1_with_no_icon);
288 assertEquals(1, itemAdapter.getCount());
289 // We should still see the original item with the icon.
290 assertEquals(itemAdapter.getItem(0), item1_with_no_icon);
291
292 mChooserDialog.setIdleState();
293 mChooserDialog.dismiss();
294 }
295
296 @SmallTest
205 public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedExc eption { 297 public void testAddOrUpdateItemAndRemoveItemFromList() throws InterruptedExc eption {
206 Dialog dialog = mChooserDialog.getDialogForTesting(); 298 Dialog dialog = mChooserDialog.getDialogForTesting();
207 assertTrue(dialog.isShowing()); 299 assertTrue(dialog.isShowing());
208 300
209 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans) 301 TextViewWithClickableSpans statusView = (TextViewWithClickableSpans)
210 dialog.findViewById(R.id.status); 302 dialog.findViewById(R.id.status);
211 final ListView items = (ListView) dialog.findViewById(R.id.items); 303 final ListView items = (ListView) dialog.findViewById(R.id.items);
212 final Button button = (Button) dialog.findViewById(R.id.positive); 304 final Button button = (Button) dialog.findViewById(R.id.positive);
213 305
214 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting(); 306 ItemChooserDialog.ItemAdapter itemAdapter = mChooserDialog.getItemAdapte rForTesting();
215 ItemChooserDialog.ItemChooserRow nonExistentItem = 307 ItemChooserDialog.ItemChooserRow nonExistentItem =
216 new ItemChooserDialog.ItemChooserRow("key", "key"); 308 new ItemChooserDialog.ItemChooserRow("key", "key");
217 309
218 // Initially the itemAdapter is empty. 310 // Initially the itemAdapter is empty.
219 assertTrue(itemAdapter.isEmpty()); 311 assertTrue(itemAdapter.isEmpty());
220 312
221 // Try removing an item from an empty itemAdapter. 313 // Try removing an item from an empty itemAdapter.
222 mChooserDialog.removeItemFromList(nonExistentItem); 314 mChooserDialog.removeItemFromList(nonExistentItem);
223 assertTrue(itemAdapter.isEmpty()); 315 assertTrue(itemAdapter.isEmpty());
224 316
225 // Add item 1. 317 // Add item 1.
226 ItemChooserDialog.ItemChooserRow item1 = 318 ItemChooserDialog.ItemChooserRow item1 =
227 new ItemChooserDialog.ItemChooserRow("key1", "desc1"); 319 new ItemChooserDialog.ItemChooserRow("key1", "desc1", TEST_ICON1 );
228 mChooserDialog.addOrUpdateItem(item1); 320 mChooserDialog.addOrUpdateItem(item1);
229 assertEquals(1, itemAdapter.getCount()); 321 assertEquals(1, itemAdapter.getCount());
230 assertEquals(itemAdapter.getItem(0), item1); 322 assertEquals(itemAdapter.getItem(0), item1);
231 323
232 // Add item 1 with different description. 324 // Add item 1 with different description and icon.
233 ItemChooserDialog.ItemChooserRow item1_again = 325 ItemChooserDialog.ItemChooserRow item1_again =
234 new ItemChooserDialog.ItemChooserRow("key1", "desc1_again"); 326 new ItemChooserDialog.ItemChooserRow("key1", "desc1_again", TEST _ICON2);
235 mChooserDialog.addOrUpdateItem(item1_again); 327 mChooserDialog.addOrUpdateItem(item1_again);
236 assertEquals(1, itemAdapter.getCount()); 328 assertEquals(1, itemAdapter.getCount());
237 assertEquals(itemAdapter.getItem(0), item1_again); 329 assertEquals(itemAdapter.getItem(0), item1_again);
238 330
239 // Add item 2. 331 // Add item 2.
240 ItemChooserDialog.ItemChooserRow item2 = 332 ItemChooserDialog.ItemChooserRow item2 =
241 new ItemChooserDialog.ItemChooserRow("key2", "desc2"); 333 new ItemChooserDialog.ItemChooserRow("key2", "desc2");
242 mChooserDialog.addOrUpdateItem(item2); 334 mChooserDialog.addOrUpdateItem(item2);
243 assertEquals(2, itemAdapter.getCount()); 335 assertEquals(2, itemAdapter.getCount());
244 assertEquals(itemAdapter.getItem(0), item1_again); 336 assertEquals(itemAdapter.getItem(0), item1_again);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 440
349 // 1460 * .3 is 438, which rounds above the maximum height. 441 // 1460 * .3 is 438, which rounds above the maximum height.
350 assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f)); 442 assertEquals(408, ItemChooserDialog.getListHeight(1460, 1.0f));
351 443
352 // 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp * 444 // 1100px is 500dp at a density of 2.2. 500 * .3 is 150dp, which is 48dp *
353 // 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds t o 445 // 3.125. 48dp * 3.5 is 168dp. 168dp * 2.2px/dp is 369.6, which rounds t o
354 // 370. 446 // 370.
355 assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f)); 447 assertEquals(370, ItemChooserDialog.getListHeight(1100, 2.2f));
356 } 448 }
357 } 449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698