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

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/widget/selection/SelectionDelegateTest.java

Issue 2789363003: Implement single-selection mode for SelectionDelegate. (Closed)
Patch Set: Address feedback from Theresa 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 unified diff | Download patch
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.widget.selection;
6
7 import static org.junit.Assert.assertFalse;
8 import static org.junit.Assert.assertTrue;
9
10 import org.junit.Test;
11 import org.junit.runner.RunWith;
12 import org.robolectric.annotation.Config;
13
14 import org.chromium.testing.local.LocalRobolectricTestRunner;
15
16 /**
17 * Tests for the {@link SelectionDelegate} class.
18 */
19 @RunWith(LocalRobolectricTestRunner.class)
20 @Config(manifest = Config.NONE)
21 public class SelectionDelegateTest {
22 private final Object mData1 = new Object();
23 private final Object mData2 = new Object();
24
25 @Test
26 public void testSelectionDelegateSingle() {
27 SelectionDelegate<Object> delegate = new SelectionDelegate<Object>();
28 delegate.setSingleSelectionMode();
29
30 // Starting state, nothing is selected.
31 assertFalse(delegate.isItemSelected(mData1));
32 assertFalse(delegate.isSelectionEnabled());
33
34 // Select first item and verify selection.
35 delegate.toggleSelectionForItem(mData1);
36 assertTrue(delegate.isItemSelected(mData1));
37 assertTrue(delegate.isSelectionEnabled());
38
39 // Select second item, first item gets unselected.
40 delegate.toggleSelectionForItem(mData2);
41 assertFalse(delegate.isItemSelected(mData1));
42 assertTrue(delegate.isItemSelected(mData2));
43 assertTrue(delegate.isSelectionEnabled());
44
45 // Unselect second item.
46 delegate.toggleSelectionForItem(mData2);
47 assertFalse(delegate.isItemSelected(mData2));
48 assertFalse(delegate.isSelectionEnabled());
49
50 // Test clearing selection.
51 delegate.toggleSelectionForItem(mData1);
52 delegate.clearSelection();
53 assertFalse(delegate.isItemSelected(mData2));
54 assertFalse(delegate.isSelectionEnabled());
55 }
56
57 @Test
58 public void testSelectionDelegateMulti() {
59 SelectionDelegate<Object> delegate = new SelectionDelegate<Object>();
60
61 // Starting state, nothing is selected.
62 assertFalse(delegate.isItemSelected(mData1));
63 assertFalse(delegate.isSelectionEnabled());
64
65 // Select first item and verify selection.
66 delegate.toggleSelectionForItem(mData1);
67 assertTrue(delegate.isItemSelected(mData1));
68 assertTrue(delegate.isSelectionEnabled());
69
70 // Select second item, first item does not get unselected.
71 delegate.toggleSelectionForItem(mData2);
72 assertTrue(delegate.isItemSelected(mData1));
73 assertTrue(delegate.isItemSelected(mData2));
74 assertTrue(delegate.isSelectionEnabled());
75
76 // Unselect second item.
77 delegate.toggleSelectionForItem(mData2);
78 assertFalse(delegate.isItemSelected(mData2));
79 assertTrue(delegate.isItemSelected(mData1));
80 assertTrue(delegate.isSelectionEnabled());
81
82 // Test clearing selection.
83 delegate.clearSelection();
84 assertFalse(delegate.isItemSelected(mData1));
85 assertFalse(delegate.isItemSelected(mData2));
86 assertFalse(delegate.isSelectionEnabled());
87 }
88 }
OLDNEW
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698