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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.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.compositor.overlays.strip;
6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_TABLET;
8
9 import android.content.pm.ActivityInfo;
10 import android.test.suitebuilder.annotation.LargeTest;
11
12 import org.chromium.base.ThreadUtils;
13 import org.chromium.base.test.util.DisabledTest;
14 import org.chromium.base.test.util.Feature;
15 import org.chromium.base.test.util.Restriction;
16 import org.chromium.chrome.browser.Tab;
17 import org.chromium.chrome.browser.compositor.layouts.components.CompositorButto n;
18 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
19 import org.chromium.chrome.browser.tabmodel.TabModel;
20 import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
21 import org.chromium.chrome.browser.tabmodel.TabModelUtils;
22 import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
23 import org.chromium.chrome.test.util.ChromeTabUtils;
24 import org.chromium.chrome.test.util.TabStripUtils;
25 import org.chromium.content.browser.test.util.CallbackHelper;
26
27 import java.util.concurrent.TimeoutException;
28
29 /**
30 * Test suite for the TabStrip and making sure it properly represents the TabMod el backend.
31 */
32 public class TabStripTest extends ChromeTabbedActivityTestBase {
33
34 @Override
35 public void startMainActivity() throws InterruptedException {
36 startMainActivityOnBlankPage();
37 }
38
39 /**
40 * Tests that the initial state of the system is good. This is so the defau lt TabStrips match
41 * the TabModels and we do not have to test this in further tests.
42 * @throws InterruptedException
43 */
44 @LargeTest
45 @Restriction(RESTRICTION_TYPE_TABLET)
46 @Feature({"TabStrip"})
47 public void testInitialState() throws InterruptedException {
48 getInstrumentation().waitForIdleSync();
49 compareAllTabStripsWithModel();
50 }
51
52 /**
53 * Tests that pressing the new tab button creates a new tab, properly updati ng the selected
54 * index.
55 * @throws InterruptedException
56 */
57 @LargeTest
58 @Restriction(RESTRICTION_TYPE_TABLET)
59 @Feature({"TabStrip", "Main"})
60 public void testNewTabButtonWithOneTab() throws InterruptedException {
61 getInstrumentation().waitForIdleSync();
62 assertEquals("Expected original tab to be selected",
63 getActivity().getTabModelSelector().getModel(false).index(), 0);
64
65 ChromeTabUtils.clickNewTabButton(this, this);
66
67 getInstrumentation().waitForIdleSync();
68 assertEquals("Expected two tabs to exist",
69 getActivity().getTabModelSelector().getModel(false).getCount(), 2);
70 compareAllTabStripsWithModel();
71 assertEquals("Expected second tab to be selected",
72 getActivity().getTabModelSelector().getModel(false).index(), 1);
73 }
74
75 /**
76 * Tests that pressing the new tab button creates a new tab when many exist, properly updating
77 * the selected index.
78 * @throws InterruptedException
79 */
80 @LargeTest
81 @Restriction(RESTRICTION_TYPE_TABLET)
82 @Feature({"TabStrip"})
83 public void testNewTabButtonWithManyTabs() throws InterruptedException {
84 ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 3);
85 getInstrumentation().runOnMainSync(new Runnable() {
86 @Override
87 public void run() {
88 TabModelUtils.setIndex(getActivity().getTabModelSelector().getMo del(false), 0);
89 }
90 });
91 getInstrumentation().waitForIdleSync();
92 assertEquals("Expected original tab to be selected",
93 getActivity().getTabModelSelector().getModel(false).index(), 0);
94 compareAllTabStripsWithModel();
95
96 ChromeTabUtils.clickNewTabButton(this, this);
97
98 getInstrumentation().waitForIdleSync();
99 assertEquals("Expected five tabs to exist",
100 getActivity().getTabModelSelector().getModel(false).getCount(), 5);
101 assertEquals("Expected last tab to be selected",
102 getActivity().getTabModelSelector().getModel(false).index(), 4);
103 compareAllTabStripsWithModel();
104 }
105
106 /**
107 * Tests that creating a new tab from the menu properly updates the TabStrip .
108 * @throws InterruptedException
109 */
110 @LargeTest
111 @Restriction(RESTRICTION_TYPE_TABLET)
112 @Feature({"TabStrip"})
113 public void testNewTabFromMenu() throws InterruptedException {
114 getInstrumentation().waitForIdleSync();
115 compareAllTabStripsWithModel();
116 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
117 getInstrumentation().waitForIdleSync();
118 assertEquals("Expected two tabs to exist",
119 getActivity().getTabModelSelector().getModel(false).getCount(), 2);
120 compareAllTabStripsWithModel();
121 }
122
123 /**
124 * Tests that creating a new incognito from the menu properly updates the Ta bStrips and
125 * activates the incognito TabStrip.
126 * @throws InterruptedException
127 */
128 /*
129 * @LargeTest
130 * @Restriction(RESTRICTION_TYPE_TABLET)
131 * @Feature({"TabStrip"})
132 * Bug crbug.com/258495
133 */
134 @DisabledTest
135 public void testNewIncognitoTabFromMenuAtNormalStrip() throws InterruptedExc eption {
136 getInstrumentation().waitForIdleSync();
137 assertFalse("Expected normal strip to be selected",
138 getActivity().getTabModelSelector().isIncognitoSelected());
139 newIncognitoTabFromMenu();
140 getInstrumentation().waitForIdleSync();
141 compareAllTabStripsWithModel();
142 assertTrue("Expected incognito strip to be selected",
143 getActivity().getTabModelSelector().isIncognitoSelected());
144 assertEquals("Expected normal model to have one tab",
145 getActivity().getTabModelSelector().getModel(false).getCount(), 1);
146 assertEquals("Expected incognito model to have one tab",
147 getActivity().getTabModelSelector().getModel(false).getCount(), 1);
148 }
149
150 /**
151 * Tests that selecting a tab properly selects the new tab.
152 * @throws InterruptedException
153 */
154 @LargeTest
155 @Restriction(RESTRICTION_TYPE_TABLET)
156 @Feature({"TabStrip"})
157 public void testSelectWithTwoTabs() throws InterruptedException {
158 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
159 getInstrumentation().waitForIdleSync();
160 assertEquals("The second tab is not selected",
161 getActivity().getCurrentTabModel().index(), 1);
162 selectTab(false, getActivity().getCurrentTabModel().getTabAt(0).getId()) ;
163 getInstrumentation().waitForIdleSync();
164 assertEquals("The first tab is not selected",
165 getActivity().getCurrentTabModel().index(), 0);
166 compareAllTabStripsWithModel();
167 }
168
169 /**
170 * Tests that selecting a tab properly selects the new tab with many present . This lets us
171 * also check that the visible tab ordering is correct.
172 * @throws InterruptedException
173 */
174 /*
175 * @LargeTest
176 * @Restriction(RESTRICTION_TYPE_TABLET)
177 * @Feature({"TabStrip"})
178 * Bug crbug.com/258495
179 */
180 @DisabledTest
181 public void testSelectWithManyTabs() throws InterruptedException {
182 ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 4);
183 getInstrumentation().waitForIdleSync();
184 assertEquals("The last tab is not selected",
185 getActivity().getCurrentTabModel().index(), 4);
186 compareAllTabStripsWithModel();
187 selectTab(false, getActivity().getCurrentTabModel().getTabAt(2).getId()) ;
188 getInstrumentation().waitForIdleSync();
189 assertEquals("The middle tab is not selected",
190 getActivity().getCurrentTabModel().index(), 2);
191 compareAllTabStripsWithModel();
192 }
193
194 /**
195 * Tests closing a tab when there are two tabs open. The remaining tab shou ld still be
196 * selected.
197 * @throws InterruptedException
198 */
199 @LargeTest
200 @Restriction(RESTRICTION_TYPE_TABLET)
201 @Feature({"TabStrip"})
202 public void testCloseTabWithTwoTabs() throws InterruptedException {
203 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
204 getInstrumentation().waitForIdleSync();
205 assertEquals("There are not two tabs present",
206 getActivity().getCurrentTabModel().getCount(), 2);
207 assertEquals("The second tab is not selected",
208 getActivity().getCurrentTabModel().index(), 1);
209 int initialSelectedId = getActivity().getActivityTab().getId();
210 closeTab(false, getActivity().getCurrentTabModel().getTabAt(0).getId());
211 getInstrumentation().waitForIdleSync();
212 assertEquals("There is not one tab present",
213 getActivity().getCurrentTabModel().getCount(), 1);
214 assertEquals("The wrong tab index is selected after close",
215 getActivity().getCurrentTabModel().index(), 0);
216 assertEquals("Same tab not still selected", initialSelectedId,
217 getActivity().getActivityTab().getId());
218 compareAllTabStripsWithModel();
219 }
220
221 /**
222 * Tests closing a tab when there are many tabs open. The remaining tab sho uld still be
223 * selected, even if the index has changed.
224 * @throws InterruptedException
225 */
226 @LargeTest
227 @Restriction(RESTRICTION_TYPE_TABLET)
228 @Feature({"TabStrip"})
229 public void testCloseTabWithManyTabs() throws InterruptedException {
230 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA NDSCAPE);
231
232 ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 4);
233 getInstrumentation().waitForIdleSync();
234 assertEquals("There are not five tabs present",
235 getActivity().getCurrentTabModel().getCount(), 5);
236 assertEquals("The last tab is not selected",
237 getActivity().getCurrentTabModel().index(), 4);
238 int initialSelectedId = getActivity().getActivityTab().getId();
239 closeTab(false, getActivity().getCurrentTabModel().getTabAt(2).getId());
240 getInstrumentation().waitForIdleSync();
241 assertEquals("There are not four tabs present",
242 getActivity().getCurrentTabModel().getCount(), 4);
243 assertEquals("The wrong tab index is selected after close",
244 getActivity().getCurrentTabModel().index(), 3);
245 assertEquals("Same tab not still selected", initialSelectedId,
246 getActivity().getActivityTab().getId());
247 compareAllTabStripsWithModel();
248 }
249
250 /**
251 * Tests that closing the selected tab properly closes the current tab and u pdates to a new
252 * selected tab.
253 * @throws InterruptedException
254 */
255 @LargeTest
256 @Restriction(RESTRICTION_TYPE_TABLET)
257 @Feature({"TabStrip"})
258 public void testCloseSelectedTab() throws InterruptedException {
259 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
260 getInstrumentation().waitForIdleSync();
261 assertEquals("There are not two tabs present",
262 getActivity().getCurrentTabModel().getCount(), 2);
263 assertEquals("The second tab is not selected",
264 getActivity().getCurrentTabModel().index(), 1);
265 int newSelectionId = getActivity().getCurrentTabModel().getTabAt(0).getI d();
266 closeTab(false, getActivity().getCurrentTabModel().getTabAt(1).getId());
267 getInstrumentation().waitForIdleSync();
268 assertEquals("There is not one tab present",
269 getActivity().getCurrentTabModel().getCount(), 1);
270 assertEquals("The wrong tab index is selected after close",
271 getActivity().getCurrentTabModel().index(), 0);
272 assertEquals("New tab not selected", newSelectionId,
273 getActivity().getActivityTab().getId());
274 compareAllTabStripsWithModel();
275 }
276
277 /**
278 * Tests that selecting "Close all tabs" from the tab menu closes all tabs.
279 * Also tests that long press on close button selects the tab and displays t he menu.
280 * @throws InterruptedException
281 */
282 @LargeTest
283 @Restriction(RESTRICTION_TYPE_TABLET)
284 @Feature({"TabStrip"})
285 public void testCloseAllTabsFromTabMenuClosesAllTabs() throws InterruptedExc eption {
286 // 1. Create a second tab
287 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
288 getInstrumentation().waitForIdleSync();
289 assertEquals("There are not two tabs present",
290 2, getActivity().getCurrentTabModel().getCount());
291 assertEquals("The second tab is not selected",
292 1, getActivity().getCurrentTabModel().index());
293
294 // 2. Display tab menu on first tab
295 int tabSelectionId = getActivity().getCurrentTabModel().getTabAt(0).getI d();
296 longPressCloseTab(false, tabSelectionId);
297 getInstrumentation().waitForIdleSync();
298 assertEquals("There are not two tabs present",
299 2, getActivity().getCurrentTabModel().getCount());
300 assertEquals("The wrong tab index is selected after long press",
301 0, getActivity().getCurrentTabModel().index());
302 assertEquals("Long pressed tab not selected",
303 tabSelectionId, getActivity().getActivityTab().getId());
304
305 // 3. Invoke "close all tabs" menu action; block until action is complet ed
306 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
307 @Override
308 public void run() {
309 TabStripUtils.getActiveStripLayoutHelper(getActivity()).clickTab MenuItem(
310 StripLayoutHelper.ID_CLOSE_ALL_TABS);
311 }
312 });
313
314 // 4. Ensure all tabs were closed
315 assertEquals("Expected no tabs to be present",
316 0, getActivity().getCurrentTabModel().getCount());
317 }
318
319 /**
320 * Tests that the tab menu is dismissed when the orientation changes and no tabs
321 * are closed.
322 * @throws InterruptedException
323 */
324 @LargeTest
325 @Restriction(RESTRICTION_TYPE_TABLET)
326 @Feature({"TabStrip"})
327 public void testTabMenuDismissedOnOrientationChange() throws InterruptedExce ption {
328 // 1. Set orientation to portrait
329 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PO RTRAIT);
330 getInstrumentation().waitForIdleSync();
331
332 // 2. Open tab menu
333 int tabSelectionId = getActivity().getCurrentTabModel().getTabAt(0).getI d();
334 longPressCloseTab(false, tabSelectionId);
335 getInstrumentation().waitForIdleSync();
336
337 // 3. Set orientation to landscape and assert tab menu is not showing
338 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LA NDSCAPE);
339 getInstrumentation().waitForIdleSync();
340 assertFalse(TabStripUtils.getActiveStripLayoutHelper(getActivity()).isTa bMenuShowing());
341 assertEquals("Expected 1 tab to be present",
342 1, getActivity().getCurrentTabModel().getCount());
343
344 // 4. Reset orientation
345 getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PO RTRAIT);
346 getInstrumentation().waitForIdleSync();
347 }
348
349 /**
350 * Tests that pressing the incognito toggle button properly switches between the incognito
351 * and normal TabStrips.
352 * @throws InterruptedException
353 */
354 /*
355 * @LargeTest
356 * @Restriction(RESTRICTION_TYPE_TABLET)
357 * @Feature({"TabStrip"})
358 * Bug crbug.com/258495
359 */
360 @DisabledTest
361 public void testToggleIncognitoMode() throws InterruptedException {
362 getInstrumentation().waitForIdleSync();
363 assertFalse("Expected normal strip to be selected",
364 getActivity().getTabModelSelector().isIncognitoSelected());
365 newIncognitoTabFromMenu();
366 getInstrumentation().waitForIdleSync();
367 assertTrue("Expected incognito strip to be selected",
368 getActivity().getTabModelSelector().isIncognitoSelected());
369 compareAllTabStripsWithModel();
370 clickIncognitoToggleButton();
371 getInstrumentation().waitForIdleSync();
372 assertFalse("Expected normal strip to be selected",
373 getActivity().getTabModelSelector().isIncognitoSelected());
374 compareAllTabStripsWithModel();
375 clickIncognitoToggleButton();
376 getInstrumentation().waitForIdleSync();
377 assertTrue("Expected incognito strip to be selected",
378 getActivity().getTabModelSelector().isIncognitoSelected());
379 }
380
381 /**
382 * Tests that closing the last incognito tab properly closes the incognito T abStrip and
383 * switches to the normal TabStrip.
384 * @throws InterruptedException
385 */
386 @LargeTest
387 @Feature({"TabStrip"})
388 @Restriction(RESTRICTION_TYPE_TABLET)
389 public void testCloseLastIncognitoTab() throws InterruptedException {
390 getInstrumentation().waitForIdleSync();
391 assertFalse("Expected normal strip to be selected",
392 getActivity().getTabModelSelector().isIncognitoSelected());
393 newIncognitoTabFromMenu();
394 getInstrumentation().waitForIdleSync();
395 assertTrue("Expected incognito strip to be selected",
396 getActivity().getTabModelSelector().isIncognitoSelected());
397 closeTab(true, TabModelUtils.getCurrentTab(
398 getActivity().getTabModelSelector().getModel(true)).getId());
399 getInstrumentation().waitForIdleSync();
400 assertFalse("Expected normal strip to be selected",
401 getActivity().getTabModelSelector().isIncognitoSelected());
402 assertEquals("Expected incognito strip to have no tabs",
403 getActivity().getTabModelSelector().getModel(true).getCount(), 0 );
404 }
405
406 /**
407 * Tests that closing all incognito tab properly closes the incognito TabStr ip and
408 * switches to the normal TabStrip.
409 * @throws InterruptedException
410 */
411 @LargeTest
412 @Feature({"TabStrip"})
413 @Restriction(RESTRICTION_TYPE_TABLET)
414 public void testCloseAllIncognitoTabsFromTabMenu() throws InterruptedExcepti on {
415 //1. Create two incognito tabs
416 getInstrumentation().waitForIdleSync();
417 assertFalse("Expected normal strip to be selected",
418 getActivity().getTabModelSelector().isIncognitoSelected());
419 newIncognitoTabFromMenu();
420 getInstrumentation().waitForIdleSync();
421 newIncognitoTabFromMenu();
422 getInstrumentation().waitForIdleSync();
423 assertTrue("Expected incognito strip to be selected",
424 getActivity().getTabModelSelector().isIncognitoSelected());
425 assertEquals("Expected incognito strip to have 2 tabs",
426 2, getActivity().getTabModelSelector().getModel(true).getCount() );
427
428 // 2. Open tab menu
429 int tabSelectionId = TabModelUtils.getCurrentTab(
430 getActivity().getTabModelSelector().getModel(true)).getId();
431 longPressCloseTab(true, tabSelectionId);
432 getInstrumentation().waitForIdleSync();
433
434 // 3. Invoke menu action; block until action is completed
435 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
436 @Override
437 public void run() {
438 TabStripUtils.getActiveStripLayoutHelper(getActivity()).clickTab MenuItem(
439 StripLayoutHelper.ID_CLOSE_ALL_TABS);
440 }
441 });
442
443 // 4. Ensure all incognito tabs were closed and TabStrip is switched to normal
444 assertFalse("Expected normal strip to be selected",
445 getActivity().getTabModelSelector().isIncognitoSelected());
446 assertEquals("Expected normal strip to have 1 tab",
447 1, getActivity().getTabModelSelector().getModel(false).getCount( ));
448 assertEquals("Expected incognito strip to have no tabs",
449 0, getActivity().getTabModelSelector().getModel(true).getCount() );
450 }
451
452 /**
453 * Test that switching a tab and quickly changing the model stays on the cor rect new tab/model
454 * when the tab finishes loading (when the GL overlay goes away).
455 * @throws InterruptedException
456 */
457 @LargeTest
458 @Restriction(RESTRICTION_TYPE_TABLET)
459 @Feature({"TabStrip"})
460 public void testTabSelectionViewDoesNotBreakModelSwitch() throws Interrupted Exception {
461 getInstrumentation().waitForIdleSync();
462 assertFalse("Expected normal strip to be selected",
463 getActivity().getTabModelSelector().isIncognitoSelected());
464 newIncognitoTabFromMenu();
465 getInstrumentation().waitForIdleSync();
466 assertTrue("Expected incognito strip to be selected",
467 getActivity().getTabModelSelector().isIncognitoSelected());
468 newIncognitoTabFromMenu();
469 ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), 0);
470
471 clickIncognitoToggleButton();
472
473 assertFalse("Expected normal strip to be selected",
474 getActivity().getTabModelSelector().isIncognitoSelected());
475 }
476
477 /**
478 * Take a model index and figure out which index it will be in the TabStrip' s view hierarchy.
479 * @param tabCount The number of tabs.
480 * @param selectedIndex The index of the selected tab.
481 * @param modelPos The position in the model we want to map.
482 * @return The position in the view hierarchy that represents the tab at mod elPos.
483 */
484 private int mapModelToViewIndex(int tabCount, int selectedIndex, int modelPo s) {
485 if (modelPos < selectedIndex) {
486 return modelPos;
487 } else if (modelPos == selectedIndex) {
488 return tabCount - 1;
489 } else {
490 return tabCount - 1 - modelPos + selectedIndex;
491 }
492 }
493
494 /**
495 * Simulates a click to the incognito toggle button.
496 */
497 protected void clickIncognitoToggleButton() throws InterruptedException {
498 final CallbackHelper tabModelSelectedCallback = new CallbackHelper();
499 TabModelSelectorObserver observer = new EmptyTabModelSelectorObserver() {
500 @Override
501 public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
502 tabModelSelectedCallback.notifyCalled();
503 }
504 };
505 getActivity().getTabModelSelector().addObserver(observer);
506 StripLayoutHelperManager manager = TabStripUtils.getStripLayoutHelperMan ager(getActivity());
507 TabStripUtils.clickCompositorButton(manager.getModelSelectorButton(), th is);
508 try {
509 tabModelSelectedCallback.waitForCallback(0);
510 } catch (TimeoutException e) {
511 fail("Tab model selected event never occurred.");
512 }
513 getActivity().getTabModelSelector().removeObserver(observer);
514 }
515
516 /**
517 * Simulates a click on a tab, selecting it.
518 * @param incognito Whether or not this tab is in the incognito or normal st ack.
519 * @param id The id of the tab to click.
520 */
521 protected void selectTab(final boolean incognito, final int id) throws Inter ruptedException {
522 ChromeTabUtils.selectTabWithAction(getInstrumentation(), getActivity(), new Runnable() {
523 @Override
524 public void run() {
525 TabStripUtils.clickTab(
526 TabStripUtils.findStripLayoutTab(getActivity(), incognit o, id),
527 TabStripTest.this);
528 }
529 });
530 }
531
532 /**
533 * Simulates a click on the close button of a tab.
534 * @param incognito Whether or not this tab is in the incognito or normal st ack.
535 * @param id The id of the tab to click.
536 */
537 protected void closeTab(final boolean incognito, final int id) throws Interr uptedException {
538 ChromeTabUtils.closeTabWithAction(getInstrumentation(), getActivity(), n ew Runnable() {
539 @Override
540 public void run() {
541 StripLayoutTab tab = TabStripUtils.findStripLayoutTab(
542 getActivity(), incognito, id);
543 TabStripUtils.clickCompositorButton(tab.getCloseButton(), TabStr ipTest.this);
544 }
545 });
546 }
547
548 /**
549 * Simulates a long press on the close button of a tab. Asserts that the tab
550 * is selected and the tab menu is showing.
551 * @param incognito Whether or not this tab is in the incognito or normal st ack.
552 * @param id The id of the tab to click.
553 */
554 protected void longPressCloseTab(final boolean incognito, final int id)
555 throws InterruptedException {
556 ChromeTabUtils.selectTabWithAction(getInstrumentation(), getActivity(), new Runnable() {
557 @Override
558 public void run() {
559 StripLayoutTab tab = TabStripUtils.findStripLayoutTab(
560 getActivity(), incognito, id);
561 TabStripUtils.longPressCompositorButton(tab.getCloseButton(), Ta bStripTest.this);
562 }
563 });
564 assertTrue(TabStripUtils.getActiveStripLayoutHelper(getActivity()).isTab MenuShowing());
565 }
566
567 /**
568 * Compares a TabView with the corresponding model Tab. This tries to compa re as many
569 * features as possible making sure the TabView properly mirrors the Tab it represents.
570 * @param incognito Whether or not this tab is incognito or not.
571 * @param id The id of the tab to compare.
572 */
573 protected void compareTabViewWithModel(boolean incognito, int id) {
574 TabModel model = getActivity().getTabModelSelector().getModel(incognito) ;
575 Tab tab = TabModelUtils.getTabById(model, id);
576 StripLayoutHelper tabStrip = TabStripUtils.getStripLayoutHelper(getActiv ity(), incognito);
577 StripLayoutTab tabView = TabStripUtils.findStripLayoutTab(getActivity(), incognito, id);
578
579 assertTrue("One of Tab and TabView does not exist", (tabView == null && tab == null)
580 || (tabView != null && tab != null));
581
582 if (tabView == null || tab == null) return;
583
584 assertEquals("The IDs are not identical", tabView.getId(), tab.getId());
585
586 int assumedTabViewIndex = mapModelToViewIndex(model.getCount(), model.in dex(),
587 model.indexOf(tab));
588
589 assertEquals("The tab is not in the proper position ",
590 assumedTabViewIndex, tabStrip.visualIndexOfTab(tabView));
591
592 if (TabModelUtils.getCurrentTab(model) == tab
593 && getActivity().getTabModelSelector().isIncognitoSelected() == incognito) {
594 assertTrue("ChromeTab is not in the proper selection state",
595 tabStrip.isForegroundTab(tabView));
596 assertEquals("ChromeTab is not completely visible, but is selected",
597 tabView.getVisiblePercentage(), 1.0f);
598 }
599
600 // TODO(dtrainor): Compare favicon bitmaps? Only compare a few pixels.
601 }
602
603 /**
604 * Compares an entire TabStrip with the corresponding TabModel. This tries to compare
605 * as many features as possible, including checking all of the tabs through
606 * compareTabViewWithModel. It also checks that the incognito indicator is visible if the
607 * incognito tab is showing.
608 * @param incognito Whether or not to check the incognito or normal TabStrip .
609 */
610 protected void compareTabStripWithModel(boolean incognito) {
611 TabModel model = getActivity().getTabModelSelector().getModel(incognito) ;
612 StripLayoutHelper strip = TabStripUtils.getStripLayoutHelper(getActivity (), incognito);
613 StripLayoutHelper activeStrip = TabStripUtils.getActiveStripLayoutHelper (getActivity());
614 TabModel activeModel = getActivity().getCurrentTabModel();
615
616 if (activeModel.isIncognito() == incognito) {
617 assertEquals("TabStrip is not in the right visible state", strip, ac tiveStrip);
618 assertEquals("TabStrip does not have the same number of views as the model",
619 strip.getTabCount(), model.getCount());
620 } else {
621 assertTrue("TabStrip is not in the right visible state", model != ac tiveModel);
622 }
623
624 CompositorButton incognitoIndicator =
625 TabStripUtils.getStripLayoutHelperManager(getActivity()).getMode lSelectorButton();
626 if (activeModel.isIncognito()) {
627 assertNotNull("Incognito indicator null in incognito mode", incognit oIndicator);
628 assertTrue("Incognito indicator not visible in incognito mode",
629 incognitoIndicator.isVisible());
630 } else if (getActivity().getTabModelSelector().getModel(true).getCount() == 0) {
631 assertFalse("Incognito indicator visible in non incognito mode",
632 incognitoIndicator.isVisible());
633 }
634
635 for (int i = 0; i < model.getCount(); ++i) {
636 compareTabViewWithModel(incognito, model.getTabAt(i).getId());
637 }
638 }
639
640 /**
641 * Compares all TabStrips with the corresponding TabModels. This also check s if the incognito
642 * toggle is visible if necessary.
643 */
644 protected void compareAllTabStripsWithModel() {
645 compareTabStripWithModel(true);
646 compareTabStripWithModel(false);
647 }
648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698