Chromium Code Reviews| 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.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; |
| 11 import android.widget.ArrayAdapter; | |
| 11 import android.widget.Button; | 12 import android.widget.Button; |
| 12 import android.widget.ListView; | 13 import android.widget.ListView; |
| 13 | 14 |
| 14 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
| 15 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 16 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 17 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 17 import org.chromium.content.browser.test.util.Criteria; | 18 import org.chromium.content.browser.test.util.Criteria; |
| 18 import org.chromium.content.browser.test.util.CriteriaHelper; | 19 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 19 import org.chromium.content.browser.test.util.TouchCommon; | 20 import org.chromium.content.browser.test.util.TouchCommon; |
| 20 import org.chromium.ui.widget.TextViewWithClickableSpans; | 21 import org.chromium.ui.widget.TextViewWithClickableSpans; |
| 21 | 22 |
| 22 import java.util.ArrayList; | |
| 23 import java.util.List; | |
| 24 import java.util.concurrent.Callable; | 23 import java.util.concurrent.Callable; |
| 25 | 24 |
| 26 /** | 25 /** |
| 27 * Tests for the ItemChooserDialog class. | 26 * Tests for the ItemChooserDialog class. |
| 28 */ | 27 */ |
| 29 public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi vity> | 28 public class ItemChooserDialogTest extends ChromeActivityTestCaseBase<ChromeActi vity> |
| 30 implements ItemChooserDialog.ItemSelectedCallback { | 29 implements ItemChooserDialog.ItemSelectedCallback { |
| 31 | 30 |
| 32 ItemChooserDialog mChooserDialog; | 31 ItemChooserDialog mChooserDialog; |
| 33 | 32 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 dialog.findViewById(R.id.status); | 124 dialog.findViewById(R.id.status); |
| 126 final ListView items = (ListView) dialog.findViewById(R.id.items); | 125 final ListView items = (ListView) dialog.findViewById(R.id.items); |
| 127 final Button button = (Button) dialog.findViewById(R.id.positive); | 126 final Button button = (Button) dialog.findViewById(R.id.positive); |
| 128 | 127 |
| 129 // Before we add items to the dialog, the 'searching' message should be | 128 // 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. | 129 // showing, the Commit button should be disabled and the list view hidde n. |
| 131 assertEquals("searching", statusView.getText().toString()); | 130 assertEquals("searching", statusView.getText().toString()); |
| 132 assertFalse(button.isEnabled()); | 131 assertFalse(button.isEnabled()); |
| 133 assertEquals(View.GONE, items.getVisibility()); | 132 assertEquals(View.GONE, items.getVisibility()); |
| 134 | 133 |
| 135 List<ItemChooserDialog.ItemChooserRow> devices = | 134 mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key", "key")); |
| 136 new ArrayList<ItemChooserDialog.ItemChooserRow>(); | 135 mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key2" , "key2")); |
| 137 devices.add(new ItemChooserDialog.ItemChooserRow("key", "key")); | |
| 138 devices.add(new ItemChooserDialog.ItemChooserRow("key2", "key2")); | |
| 139 mChooserDialog.addItemsToList(devices); | |
| 140 | 136 |
| 141 // Two items showing, the empty view should be no more and the button | 137 // After discovery stops the list should be visible with two items, |
| 142 // should now be enabled. | |
| 143 assertEquals(View.VISIBLE, items.getVisibility()); | |
| 144 assertEquals(View.GONE, items.getEmptyView().getVisibility()); | |
| 145 assertEquals("statusActive", statusView.getText().toString()); | |
| 146 assertFalse(button.isEnabled()); | |
| 147 | |
| 148 mChooserDialog.setIdleState(); | |
| 149 // After discovery stops the list should still be visible, | |
|
Finnur
2016/03/16 13:35:14
Why is this changing (line 141 and below)?
juncai
2016/03/16 21:01:35
I think since State.PROGRESS_UPDATE_AVAILABLE was
| |
| 150 // it should not show the empty view and the button should not be enable d. | 138 // it should not show the empty view and the button should not be enable d. |
| 151 // The chooser should show the status idle text. | 139 // The chooser should show the status idle text. |
| 152 assertEquals(View.VISIBLE, items.getVisibility()); | 140 assertEquals(View.VISIBLE, items.getVisibility()); |
| 153 assertEquals(View.GONE, items.getEmptyView().getVisibility()); | 141 assertEquals(View.GONE, items.getEmptyView().getVisibility()); |
| 154 assertEquals("statusIdleSomeFound", statusView.getText().toString()); | 142 assertEquals("statusIdleSomeFound", statusView.getText().toString()); |
| 155 assertFalse(button.isEnabled()); | 143 assertFalse(button.isEnabled()); |
| 156 | 144 |
| 157 // Select the first item and verify it got selected. | 145 // Select the first item and verify it got selected. |
| 158 selectItem(dialog, 1, "key", true); | 146 selectItem(dialog, 1, "key", true); |
| 159 | 147 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 186 assertFalse(button.isEnabled()); | 174 assertFalse(button.isEnabled()); |
| 187 | 175 |
| 188 mChooserDialog.dismiss(); | 176 mChooserDialog.dismiss(); |
| 189 } | 177 } |
| 190 | 178 |
| 191 @SmallTest | 179 @SmallTest |
| 192 public void testDisabledSelection() throws InterruptedException { | 180 public void testDisabledSelection() throws InterruptedException { |
| 193 Dialog dialog = mChooserDialog.getDialogForTesting(); | 181 Dialog dialog = mChooserDialog.getDialogForTesting(); |
| 194 assertTrue(dialog.isShowing()); | 182 assertTrue(dialog.isShowing()); |
| 195 | 183 |
| 196 List<ItemChooserDialog.ItemChooserRow> devices = | 184 mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key", "key")); |
| 197 new ArrayList<ItemChooserDialog.ItemChooserRow>(); | 185 mChooserDialog.addItemToList(new ItemChooserDialog.ItemChooserRow("key2" , "key2")); |
| 198 devices.add(new ItemChooserDialog.ItemChooserRow("key", "key")); | |
| 199 devices.add(new ItemChooserDialog.ItemChooserRow("key2", "key2")); | |
| 200 mChooserDialog.addItemsToList(devices); | |
| 201 | 186 |
| 202 // Disable one item and try to select it. | 187 // Disable one item and try to select it. |
| 203 mChooserDialog.setEnabled("key", false); | 188 mChooserDialog.setEnabled("key", false); |
| 204 selectItem(dialog, 1, "None", false); | 189 selectItem(dialog, 1, "None", false); |
| 205 // The other is still selectable. | 190 // The other is still selectable. |
| 206 selectItem(dialog, 2, "key2", true); | 191 selectItem(dialog, 2, "key2", true); |
| 207 | 192 |
| 208 mChooserDialog.dismiss(); | 193 mChooserDialog.dismiss(); |
| 209 } | 194 } |
| 195 | |
| 196 @SmallTest | |
| 197 public void testAddItemToListAndRemoveItemFromList() throws InterruptedExcep tion { | |
| 198 Dialog dialog = mChooserDialog.getDialogForTesting(); | |
| 199 assertTrue(dialog.isShowing()); | |
| 200 | |
| 201 ArrayAdapter itemAdapter = mChooserDialog.getItemAdapterForTesting(); | |
| 202 ItemChooserDialog.ItemChooserRow nonExistentItem = | |
| 203 new ItemChooserDialog.ItemChooserRow("key", "key"); | |
| 204 | |
| 205 // Initially the itemAdapter is empty. | |
| 206 assertTrue(itemAdapter.isEmpty()); | |
| 207 | |
| 208 // Try removing an item from an empty itemAdapter. | |
| 209 mChooserDialog.removeItemFromList(nonExistentItem); | |
| 210 assertTrue(itemAdapter.isEmpty()); | |
| 211 | |
| 212 // Add item1. | |
|
Finnur
2016/03/16 13:35:14
nit: s/item1/item 1/
(same with item2 and incident
juncai
2016/03/16 21:01:35
Done.
| |
| 213 ItemChooserDialog.ItemChooserRow item1 = | |
| 214 new ItemChooserDialog.ItemChooserRow("key1", "key1"); | |
| 215 mChooserDialog.addItemToList(item1); | |
| 216 assertEquals(1, itemAdapter.getCount()); | |
| 217 assertEquals(itemAdapter.getItem(0), item1); | |
| 218 | |
| 219 // Add item2. | |
| 220 ItemChooserDialog.ItemChooserRow item2 = | |
| 221 new ItemChooserDialog.ItemChooserRow("key2", "key2"); | |
| 222 mChooserDialog.addItemToList(item2); | |
| 223 assertEquals(2, itemAdapter.getCount()); | |
| 224 assertEquals(itemAdapter.getItem(0), item1); | |
| 225 assertEquals(itemAdapter.getItem(1), item2); | |
| 226 | |
| 227 // Try removing an item that doesn't exist. | |
| 228 mChooserDialog.removeItemFromList(nonExistentItem); | |
| 229 assertEquals(2, itemAdapter.getCount()); | |
| 230 | |
| 231 // Remove item2. | |
| 232 mChooserDialog.removeItemFromList(item2); | |
| 233 assertEquals(1, itemAdapter.getCount()); | |
| 234 // Make sure the remaining item is item1. | |
| 235 assertEquals(itemAdapter.getItem(0), item1); | |
| 236 | |
| 237 // Remove item1. | |
| 238 mChooserDialog.removeItemFromList(item1); | |
| 239 assertTrue(itemAdapter.isEmpty()); | |
|
Finnur
2016/03/16 13:35:14
I would add verification that the list is showing
juncai
2016/03/16 21:01:35
Done.
| |
| 240 | |
| 241 mChooserDialog.dismiss(); | |
| 242 } | |
| 210 } | 243 } |
| OLD | NEW |