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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/junit/src/org/chromium/chrome/browser/widget/selection/SelectionDelegateTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/widget/selection/SelectionDelegateTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/widget/selection/SelectionDelegateTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5f7ad9a6aa10afdc07c50f0e25f5aa09587bc471
--- /dev/null
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/widget/selection/SelectionDelegateTest.java
@@ -0,0 +1,88 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.widget.selection;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+
+/**
+ * Tests for the {@link SelectionDelegate} class.
+ */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class SelectionDelegateTest {
+ private final Object mData1 = new Object();
+ private final Object mData2 = new Object();
+
+ @Test
+ public void testSelectionDelegateSingle() {
+ SelectionDelegate<Object> delegate = new SelectionDelegate<Object>();
+ delegate.setSingleSelectionMode();
+
+ // Starting state, nothing is selected.
+ assertFalse(delegate.isItemSelected(mData1));
+ assertFalse(delegate.isSelectionEnabled());
+
+ // Select first item and verify selection.
+ delegate.toggleSelectionForItem(mData1);
+ assertTrue(delegate.isItemSelected(mData1));
+ assertTrue(delegate.isSelectionEnabled());
+
+ // Select second item, first item gets unselected.
+ delegate.toggleSelectionForItem(mData2);
+ assertFalse(delegate.isItemSelected(mData1));
+ assertTrue(delegate.isItemSelected(mData2));
+ assertTrue(delegate.isSelectionEnabled());
+
+ // Unselect second item.
+ delegate.toggleSelectionForItem(mData2);
+ assertFalse(delegate.isItemSelected(mData2));
+ assertFalse(delegate.isSelectionEnabled());
+
+ // Test clearing selection.
+ delegate.toggleSelectionForItem(mData1);
+ delegate.clearSelection();
+ assertFalse(delegate.isItemSelected(mData2));
+ assertFalse(delegate.isSelectionEnabled());
+ }
+
+ @Test
+ public void testSelectionDelegateMulti() {
+ SelectionDelegate<Object> delegate = new SelectionDelegate<Object>();
+
+ // Starting state, nothing is selected.
+ assertFalse(delegate.isItemSelected(mData1));
+ assertFalse(delegate.isSelectionEnabled());
+
+ // Select first item and verify selection.
+ delegate.toggleSelectionForItem(mData1);
+ assertTrue(delegate.isItemSelected(mData1));
+ assertTrue(delegate.isSelectionEnabled());
+
+ // Select second item, first item does not get unselected.
+ delegate.toggleSelectionForItem(mData2);
+ assertTrue(delegate.isItemSelected(mData1));
+ assertTrue(delegate.isItemSelected(mData2));
+ assertTrue(delegate.isSelectionEnabled());
+
+ // Unselect second item.
+ delegate.toggleSelectionForItem(mData2);
+ assertFalse(delegate.isItemSelected(mData2));
+ assertTrue(delegate.isItemSelected(mData1));
+ assertTrue(delegate.isSelectionEnabled());
+
+ // Test clearing selection.
+ delegate.clearSelection();
+ assertFalse(delegate.isItemSelected(mData1));
+ assertFalse(delegate.isItemSelected(mData2));
+ assertFalse(delegate.isSelectionEnabled());
+ }
+}
« 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