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

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

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.widget;
6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE;
8
9 import android.os.SystemClock;
10 import android.test.suitebuilder.annotation.MediumTest;
11 import android.view.View;
12 import android.view.ViewGroup;
13 import android.widget.ListView;
14
15 import com.google.android.apps.chrome.R;
16
17 import org.chromium.base.CommandLine;
18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.test.util.Feature;
20 import org.chromium.base.test.util.Restriction;
21 import org.chromium.chrome.browser.ChromeSwitches;
22 import org.chromium.chrome.browser.Tab;
23 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
24 import org.chromium.chrome.browser.tabmodel.TabModel;
25 import org.chromium.chrome.browser.widget.accessibility.AccessibilityTabModelLis tItem;
26 import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
27 import org.chromium.chrome.test.util.ChromeTabUtils;
28 import org.chromium.chrome.test.util.MenuUtils;
29 import org.chromium.content.browser.test.util.CallbackHelper;
30 import org.chromium.content.browser.test.util.Criteria;
31 import org.chromium.content.browser.test.util.CriteriaHelper;
32 import org.chromium.content.browser.test.util.TestTouchUtils;
33
34 import java.util.concurrent.Callable;
35 import java.util.concurrent.TimeoutException;
36
37 /**
38 * Tests accessibility UI.
39 */
40 public class OverviewListLayoutTest extends ChromeTabbedActivityTestBase {
41 private static final int SWIPE_START_X_OFFSET = 10;
42 private static final int SWIPE_START_Y_OFFSET = 10;
43 private static final int SWIPE_END_X = 20;
44
45 private class ChildCountCriteria implements Criteria {
46 private final int mChildCount;
47
48 public ChildCountCriteria(int count) {
49 mChildCount = count;
50 }
51
52 @Override
53 public boolean isSatisfied() {
54 return mChildCount == ThreadUtils.runOnUiThreadBlockingNoException(
55 new Callable<Integer>() {
56 @Override
57 public Integer call() {
58 return getList().getChildCount();
59 }
60 });
61 }
62 }
63
64 private class TabModelCountCountCriteria implements Criteria {
65 private final boolean mIncognito;
66 private final int mTabCount;
67
68 public TabModelCountCountCriteria(boolean incognito, int count) {
69 mIncognito = incognito;
70 mTabCount = count;
71 }
72
73 @Override
74 public boolean isSatisfied() {
75 return mTabCount == ThreadUtils.runOnUiThreadBlockingNoException(
76 new Callable<Integer>() {
77 @Override
78 public Integer call() {
79 return getActivity().getTabModelSelector()
80 .getModel(mIncognito).getCount();
81 }
82 });
83 }
84 }
85
86 @Override
87 public void startMainActivity() throws InterruptedException {
88 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_ACCESSIBILI TY_TAB_SWITCHER);
89 startMainActivityFromLauncher();
90 }
91
92 private ViewGroup getContainer() {
93 return ((OverviewListLayout) getActivity().getOverviewListLayout()).getC ontainer();
94 }
95
96 private ListView getList() {
97 return (ListView) getContainer().findViewById(R.id.list_view);
98 }
99
100 private void setupTabs() throws InterruptedException {
101 ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 3);
102
103 TestTouchUtils.performClickOnMainSync(
104 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
105
106 assertTrue(
107 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(4)));
108 }
109
110 private AccessibilityTabModelListItem getListItemAndDisableAnimations(int in dex) {
111 AccessibilityTabModelListItem item = getListItem(index);
112 item.disableAnimations();
113 return item;
114 }
115
116 private AccessibilityTabModelListItem getListItem(int index) {
117 AccessibilityTabModelListItem item =
118 (AccessibilityTabModelListItem) getList().getChildAt(index);
119 return item;
120 }
121
122 @Restriction(RESTRICTION_TYPE_PHONE)
123 @MediumTest
124 @Feature({"Accessibility"})
125 public void testCanEnterSwitcher() {
126 TestTouchUtils.performClickOnMainSync(
127 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
128
129 assertNotNull("Accessibility container was not initialized", getContaine r());
130 assertNotNull("Accessibility container was not visible", getContainer(). getParent());
131 }
132
133 @Restriction(RESTRICTION_TYPE_PHONE)
134 @MediumTest
135 @Feature({"Accessibility"})
136 public void testCanLeaveSwitcher() {
137 TestTouchUtils.performClickOnMainSync(
138 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
139
140 assertNotNull("Accessibility container was not initialized", getContaine r());
141 assertNotNull("Accessibility container was not visible", getContainer(). getParent());
142
143 TestTouchUtils.performClickOnMainSync(
144 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
145 assertNull("Accessibility container was not visible", getContainer().get Parent());
146 }
147
148 @Restriction(RESTRICTION_TYPE_PHONE)
149 @MediumTest
150 @Feature({"Accessibility"})
151 public void testCanCloseWithCloseButton() throws InterruptedException, Timeo utException {
152 setupTabs();
153
154 AccessibilityTabModelListItem item = getListItemAndDisableAnimations(0);
155
156 final CallbackHelper didReceiveClosureCommittedHelper = new CallbackHelp er();
157 final TabModel model = getActivity().getCurrentTabModel();
158 model.addObserver(new EmptyTabModelObserver() {
159 @Override
160 public void tabClosureCommitted(Tab tab) {
161 didReceiveClosureCommittedHelper.notifyCalled();
162 }
163 });
164
165 TestTouchUtils.performClickOnMainSync(
166 getInstrumentation(), item.findViewById(R.id.close_btn));
167
168 didReceiveClosureCommittedHelper.waitForCallback(0);
169
170 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
171 @Override
172 public void run() {
173 assertEquals("Tab not closed", 3, getList().getChildCount());
174 }
175 });
176 }
177
178 @Restriction(RESTRICTION_TYPE_PHONE)
179 @MediumTest
180 @Feature({"Accessibility"})
181 public void testCanSwipeClosed() throws InterruptedException, TimeoutExcepti on {
182 setupTabs();
183
184 AccessibilityTabModelListItem item = getListItemAndDisableAnimations(1);
185
186 int[] location = TestTouchUtils.getAbsoluteLocationFromRelative(
187 item, SWIPE_START_X_OFFSET, SWIPE_START_Y_OFFSET);
188
189 final CallbackHelper didReceiveClosureCommittedHelper = new CallbackHelp er();
190 final TabModel model = getActivity().getCurrentTabModel();
191 model.addObserver(new EmptyTabModelObserver() {
192 @Override
193 public void tabClosureCommitted(Tab tab) {
194 didReceiveClosureCommittedHelper.notifyCalled();
195 }
196 });
197
198 long downTime = SystemClock.uptimeMillis();
199 dragStart(location[0], location[1], downTime);
200 dragTo(location[0], (int) (item.getWidth() / 1.5), location[1], location [1], 20, downTime);
201 dragEnd(400, location[1], downTime);
202
203 didReceiveClosureCommittedHelper.waitForCallback(0);
204
205 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
206 @Override
207 public void run() {
208 assertEquals("Tab not closed", 3, getList().getChildCount());
209 }
210 });
211 }
212
213 @Restriction(RESTRICTION_TYPE_PHONE)
214 @MediumTest
215 @Feature({"Accessibility"})
216 public void testResetSwipe() throws InterruptedException {
217 setupTabs();
218
219 AccessibilityTabModelListItem item = getListItemAndDisableAnimations(0);
220
221 int[] location = TestTouchUtils.getAbsoluteLocationFromRelative(
222 item, SWIPE_START_X_OFFSET, SWIPE_START_Y_OFFSET);
223
224 dragTo(location[0], SWIPE_END_X, location[1], location[1], 20, SystemClo ck.uptimeMillis());
225
226 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
227 @Override
228 public void run() {
229 assertEquals("Tab not reset as expected", 4, getList().getChildC ount());
230 }
231 });
232 }
233
234 @Restriction(RESTRICTION_TYPE_PHONE)
235 @MediumTest
236 @Feature({"Accessibility"})
237 public void testCloseAndUndo() throws InterruptedException, TimeoutException {
238 setupTabs();
239
240 final AccessibilityTabModelListItem item = getListItem(0);
241
242 final CallbackHelper didReceivePendingClosureHelper = new CallbackHelper ();
243 final TabModel model = getActivity().getCurrentTabModel();
244 model.addObserver(new EmptyTabModelObserver() {
245 @Override
246 public void tabPendingClosure(Tab tab) {
247 didReceivePendingClosureHelper.notifyCalled();
248 }
249 });
250
251 TestTouchUtils.performClickOnMainSync(
252 getInstrumentation(), item.findViewById(R.id.close_btn));
253
254 didReceivePendingClosureHelper.waitForCallback(0);
255
256 TestTouchUtils.performClickOnMainSync(
257 getInstrumentation(), item.findViewById(R.id.undo_button));
258
259 assertFalse("Close not undone", item.hasPendingClosure());
260
261 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
262 @Override
263 public void run() {
264 assertEquals("Tab closure not undone", 4, getList().getChildCoun t());
265 }
266 });
267 }
268
269 @Restriction(RESTRICTION_TYPE_PHONE)
270 @MediumTest
271 @Feature({"Accessibility"})
272 public void testCloseAll() throws InterruptedException {
273 setupTabs();
274
275 MenuUtils.invokeCustomMenuActionSync(
276 getInstrumentation(), getActivity(), R.id.close_all_tabs_menu_id );
277
278 assertTrue(
279 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(0)));
280 assertTrue("Tabs not closed on the model",
281 CriteriaHelper.pollForCriteria(new TabModelCountCountCriteria(fa lse, 0)));
282 assertFalse(getActivity().findViewById(R.id.tab_switcher_button).isEnabl ed());
283 }
284
285 @Restriction(RESTRICTION_TYPE_PHONE)
286 @MediumTest
287 @Feature({"Accessibility"})
288 public void testCloseAllIncognito() throws InterruptedException {
289 setupTabs();
290 newIncognitoTabsFromMenu(2);
291 TestTouchUtils.performClickOnMainSync(
292 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
293 assertTrue(
294 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(2)));
295
296 MenuUtils.invokeCustomMenuActionSync(
297 getInstrumentation(), getActivity(), R.id.close_all_incognito_ta bs_menu_id);
298 assertTrue("Tabs not closed on the model",
299 CriteriaHelper.pollForCriteria(new TabModelCountCountCriteria(tr ue, 0)));
300
301 assertTrue(
302 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(4)));
303 assertTrue(getActivity().findViewById(R.id.tab_switcher_button).isEnable d());
304
305 MenuUtils.invokeCustomMenuActionSync(
306 getInstrumentation(), getActivity(), R.id.close_all_tabs_menu_id );
307
308 assertTrue(
309 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(0)));
310 assertTrue("Tabs not closed on the model",
311 CriteriaHelper.pollForCriteria(new TabModelCountCountCriteria(fa lse, 0)));
312 assertFalse(getActivity().findViewById(R.id.tab_switcher_button).isEnabl ed());
313 }
314
315 @Restriction(RESTRICTION_TYPE_PHONE)
316 @MediumTest
317 @Feature({"Accessibility"})
318 public void testModelSwitcherVisibility() throws InterruptedException {
319 setupTabs();
320
321 View switcherButtons = getContainer().findViewById(R.id.button_wrapper);
322
323 assertEquals(
324 "Tab Model Switcher buttons visible", View.GONE, switcherButtons .getVisibility());
325
326 newIncognitoTabsFromMenu(2);
327
328 TestTouchUtils.performClickOnMainSync(
329 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
330
331 assertEquals("Tab Model switcher buttons not visible", View.VISIBLE,
332 switcherButtons.getVisibility());
333 }
334
335 @Restriction(RESTRICTION_TYPE_PHONE)
336 @MediumTest
337 @Feature({"Accessibility"})
338 public void testModelSwitcherFunctionality() throws InterruptedException {
339 newIncognitoTabsFromMenu(2);
340
341 ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 3);
342
343 TestTouchUtils.performClickOnMainSync(
344 getInstrumentation(), getActivity().findViewById(R.id.tab_switch er_button));
345
346 View switcherButtons = getContainer().findViewById(R.id.button_wrapper);
347
348 assertEquals("Tab Model Switcher buttons visible", View.VISIBLE,
349 switcherButtons.getVisibility());
350
351 View incognitoButton = switcherButtons.findViewById(R.id.incognito_tabs_ button);
352
353 assertNotNull("IncognitoButton is null", incognitoButton);
354
355 TestTouchUtils.performClickOnMainSync(getInstrumentation(), incognitoBut ton);
356
357 assertTrue(
358 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(2)));
359
360 TestTouchUtils.performClickOnMainSync(
361 getInstrumentation(), switcherButtons.findViewById(R.id.standard _tabs_button));
362
363 assertTrue(
364 "Wrong number of tabs", CriteriaHelper.pollForCriteria(new Child CountCriteria(4)));
365 }
366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698