-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
StripLayoutHelperTest.java
1842 lines (1577 loc) · 84 KB
/
StripLayoutHelperTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 The Chromium Authors
// 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.compositor.overlays.strip;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost;
import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
import org.chromium.chrome.browser.compositor.layouts.components.CompositorButton;
import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutTab.StripLayoutTabDelegate;
import org.chromium.chrome.browser.compositor.overlays.strip.TabLoadTracker.TabLoadTrackerCallback;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.layouts.animation.CompositorAnimationHandler;
import org.chromium.chrome.browser.layouts.animation.CompositorAnimator;
import org.chromium.chrome.browser.layouts.components.VirtualView;
import org.chromium.chrome.browser.tasks.tab_groups.TabGroupModelFilter;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.ui.base.LocalizationUtils;
import java.util.ArrayList;
import java.util.List;
/** Tests for {@link StripLayoutHelper}. */
@RunWith(BaseRobolectricTestRunner.class)
@Features.EnableFeatures({ChromeFeatureList.TAB_STRIP_IMPROVEMENTS,
ChromeFeatureList.GRID_TAB_SWITCHER_FOR_TABLETS, ChromeFeatureList.TAB_GROUPS_FOR_TABLETS})
@Config(manifest = Config.NONE, qualifiers = "sw600dp")
public class StripLayoutHelperTest {
@Rule
public TestRule mFeaturesProcessorRule = new Features.JUnitProcessor();
@Mock
private View mInteractingTabView;
@Mock
private LayoutUpdateHost mUpdateHost;
@Mock
private LayoutRenderHost mRenderHost;
@Mock
private CompositorButton mModelSelectorBtn;
@Mock
private TabGroupModelFilter mTabGroupModelFilter;
private Activity mActivity;
private TestTabModel mModel = new TestTabModel();
private StripLayoutHelper mStripLayoutHelper;
private boolean mIncognito;
private static final String[] TEST_TAB_TITLES = {"Tab 1", "Tab 2", "Tab 3", "", null};
private static final String EXPECTED_MARGIN = "The tab should have a trailing margin.";
private static final String EXPECTED_NO_MARGIN = "The tab should not have a trailing margin.";
private static final String CLOSE_TAB = "Close %1$s tab";
private static final String IDENTIFIER = "Tab";
private static final String IDENTIFIER_SELECTED = "Selected Tab";
private static final String INCOGNITO_IDENTIFIER = "Incognito Tab";
private static final String INCOGNITO_IDENTIFIER_SELECTED = "Selected Incognito Tab";
private static final float SCREEN_WIDTH = 800.f;
private static final float SCREEN_WIDTH_LANDSCAPE = 1200.f;
private static final float SCREEN_HEIGHT = 1600.f;
private static final float TAB_WIDTH_1 = 140.f;
private static final float TAB_WIDTH_2 = 160.f;
private static final float TAB_WIDTH_SMALL = 108.f;
private static final float TAB_OVERLAP_WIDTH = 24.f;
private static final float TAB_WIDTH_MEDIUM = 156.f;
private static final float TAB_MARGIN_WIDTH = 95.f;
private static final long TIMESTAMP = 5000;
private static final float NEW_TAB_BTN_X = 700.f;
private static final float NEW_TAB_BTN_Y = 1400.f;
private static final float NEW_TAB_BTN_WIDTH = 100.f;
private static final float NEW_TAB_BTN_HEIGHT = 100.f;
private static final float CLOSE_BTN_VISIBILITY_THRESHOLD_END = 72;
private static final float CLOSE_BTN_VISIBILITY_THRESHOLD_END_MODEL_SELECTOR = 120;
private static final float EPSILON = 0.001f;
/** Reset the environment before each test. */
@Before
public void beforeTest() {
MockitoAnnotations.initMocks(this);
when(mModelSelectorBtn.isVisible()).thenReturn(true);
when(mTabGroupModelFilter.hasOtherRelatedTabs(any())).thenReturn(false);
mActivity = Robolectric.buildActivity(Activity.class).setup().get();
TabUiFeatureUtilities.setTabMinWidthForTesting(190.f);
}
@After
public void tearDown() {
if (mStripLayoutHelper != null) {
mStripLayoutHelper.stopReorderModeForTesting();
mStripLayoutHelper.setTabAtPositionForTesting(null);
}
TabUiFeatureUtilities.setTabMinWidthForTesting(null);
}
/**
* Test method for {@link StripLayoutHelper#getVirtualViews(List<VirtualView>)}.
*
* Checks that it returns the correct order of tabs, including correct content.
*/
@Test
@Feature({"Accessibility"})
public void testSimpleTabOrder() {
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(false, false, 0);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.updateLayout(TIMESTAMP);
assertTabStripAndOrder(getExpectedAccessibilityDescriptions(0));
}
/**
* Test method for {@link StripLayoutHelper#getVirtualViews(List<VirtualView>)}.
*
* Checks that it returns the correct order of tabs, even when a tab except the first one is
* selected.
*/
@Test
@Feature({"Accessibility"})
public void testTabOrderWithIndex() {
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_SMALL);
initializeTest(false, false, 1);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.updateLayout(TIMESTAMP);
// Tabs should be in left to right order regardless of index
assertTabStripAndOrder(getExpectedAccessibilityDescriptions(1));
}
/**
* Test method for {@link StripLayoutHelper#getVirtualViews(List<VirtualView>)}.
*
* Checks that it returns the correct order of tabs, even in RTL mode.
*/
@Test
@Feature({"Accessibility"})
public void testTabOrderRtl() {
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_SMALL);
initializeTest(true, false, 0);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.updateLayout(TIMESTAMP);
// Tabs should be in linear order even in RTL.
// Android will take care of reversing it.
assertTabStripAndOrder(getExpectedAccessibilityDescriptions(0));
}
/**
* Test method for {@link StripLayoutHelper#getVirtualViews(List<VirtualView>)}.
*
* Checks that it returns the correct order of tabs, even in incognito mode.
*/
@Test
@Feature({"Accessibility"})
public void testIncognitoAccessibilityDescriptions() {
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_SMALL);
initializeTest(false, true, 0);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.updateLayout(TIMESTAMP);
assertTabStripAndOrder(getExpectedAccessibilityDescriptions(0));
}
@Test
@Feature("Tab Strip Improvements")
@Config(qualifiers = "sw800dp")
public void testStripStacker_TabStripImprovementsEnabled_Scroll() {
initializeTest(false, true, 0);
// Assert
assertFalse(mStripLayoutHelper.shouldCascadeTabs());
}
@Test
@Feature("Tab Strip Improvements")
@Config(qualifiers = "sw800dp")
@Features.DisableFeatures(ChromeFeatureList.TAB_STRIP_IMPROVEMENTS)
public void testStripStacker_TabStripImprovementsDisabled_Cascade() {
initializeTest(false, true, 0);
// Assert
assertTrue(mStripLayoutHelper.shouldCascadeTabs());
}
@Test
public void testAllTabsClosed() {
initializeTest(false, false, 0);
assertTrue(mStripLayoutHelper.getStripLayoutTabs().length == TEST_TAB_TITLES.length);
// Close all tabs
mModel.closeAllTabs();
// Notify strip of tab closure
mStripLayoutHelper.willCloseAllTabs();
// Verify strip has no tabs.
assertTrue(mStripLayoutHelper.getStripLayoutTabs().length == 0);
}
@Test
@Feature("Tab Strip Improvements")
public void testStripStacker_UpdateCloseButtons() {
// Set fourth tab as selected
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_SMALL);
initializeTest(false, true, 3);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_1);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Close btn should be visible on the selected tab.
Mockito.verify(tabs[3]).setCanShowCloseButton(true, false);
// Close btn is hidden on unselected tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(false, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(false, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(false, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(false, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_SelectedTab_EdgeTab_HideCloseBtn() {
// Set fourth tab as selected
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_SMALL);
initializeTest(false, true, 3);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_1);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
when(tabs[3].getDrawX()).thenReturn(600.f);
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Close btn should be hidden on the selected tab as its an edge tab.
Mockito.verify(tabs[3]).setCanShowCloseButton(false, false);
// Close btn is hidden on unselected tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(false, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(false, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(false, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(false, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_EdgeTab_Start_Ltr_HideCloseBtn() {
// Arrange
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(false, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2);
// Set mWidth value to 800.f
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.getNewTabButton().setX(600.f);
// The leftmost tab is partially hidden
when(tabs[0].getDrawX()).thenReturn(-80.f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close btn should be hidden for the partially visible edge tab.
Mockito.verify(tabs[0]).setCanShowCloseButton(false, false);
// Close button is visible for the rest of the tabs.
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[3]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(true, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_EdgeTab_End_Ltr_HideCloseBtn() {
// Arrange
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(false, false, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2);
// Set mWidth value to 800.f
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.getNewTabButton().setX(700);
float drawXToHideCloseBtn = SCREEN_WIDTH - CLOSE_BTN_VISIBILITY_THRESHOLD_END_MODEL_SELECTOR
- TAB_WIDTH_2 + TAB_OVERLAP_WIDTH + 1; // 1 is to cross threshold
when(tabs[3].getDrawX()).thenReturn(drawXToHideCloseBtn);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close button is visible for the rest of the tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(true, false);
// Close btn should be hidden for the partially visible edge tab.
Mockito.verify(tabs[3]).setCanShowCloseButton(false, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_LastTab_ShowCloseBtn() {
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(false, false, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2);
// Set mWidth value to 800.f
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.getNewTabButton().setX(NEW_TAB_BTN_X);
// newTabBtn.X(700.f) - tab.width(160.f) + mTabOverlapWidth(24.f)
when(tabs[4].getDrawX()).thenReturn(564.f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close button is visible for all tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[3]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(true, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_LastTab_EdgeTab_HideCloseBtn() {
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(false, false, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2);
// Set mWidth value to 800.f
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.getNewTabButton().setX(NEW_TAB_BTN_X);
// newTabBtn.X(700.f) - tab.width(160.f) + mTabOverlapWidth(24.f) + 1
when(tabs[4].getDrawX()).thenReturn(565.f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close btn should be visible for rest of the tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[3]).setCanShowCloseButton(true, false);
// Close btn should be hidden for the partially visible edge tab.
Mockito.verify(tabs[4]).setCanShowCloseButton(false, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_EdgeTab_End_Ltr_NoModelSelBtn_HideCloseBtn() {
// Arrange
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
when(mModelSelectorBtn.isVisible()).thenReturn(false);
initializeTest(false, false, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2);
// Set mWidth value to 800.f
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.getNewTabButton().setX(700);
float drawXToHideCloseBtn = SCREEN_WIDTH - CLOSE_BTN_VISIBILITY_THRESHOLD_END - TAB_WIDTH_2
+ TAB_OVERLAP_WIDTH + 1; // 1 is to cross threshold
when(tabs[3].getDrawX()).thenReturn(drawXToHideCloseBtn);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close button is visible for the rest of the tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(true, false);
// Close btn should be hidden for the partially visible edge tab.
Mockito.verify(tabs[3]).setCanShowCloseButton(false, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_EdgeTab_Start_Rtl_HideCloseBtn() {
// Arrange
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(true, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2, 150.f, 5);
// Set mWidth value to 800.f.
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
// The leftmost tab is partially hidden.
when(tabs[0].getDrawX()).thenReturn(60.f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close btn should be hidden for the partially visible edge tab.
Mockito.verify(tabs[0]).setCanShowCloseButton(false, false);
// Close button is visible for the rest of the tabs.
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[3]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[4]).setCanShowCloseButton(true, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_EdgeTab_End_Rtl_HideCloseBtn() {
// Arrange
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
initializeTest(true, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_2, 150.f, 5);
// Set mWidth value to 800.f
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
// To make rightmost tab partially hidden value should be gt than (SCREEN_WIDTH - 120.f -
// TAB_WIDTH_2).
when(tabs[4].getDrawX()).thenReturn(710.f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Act
mStripLayoutHelper.tabSelected(1, 3, 0, false);
// Assert
// Close button is visible for the rest of the tabs.
Mockito.verify(tabs[0]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[1]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[2]).setCanShowCloseButton(true, false);
Mockito.verify(tabs[3]).setCanShowCloseButton(true, false);
// Close btn should be hidden for the partially visible edge tab.
Mockito.verify(tabs[4]).setCanShowCloseButton(false, false);
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollOffset_OnResume_StartOnLeft_SelectedRightmostTab() {
// Arrange: Initialize tabs with last tab selected.
initializeTest(false, true, false, 9, 10);
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM, 150.f, 10);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Set screen width to 800dp.
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.scrollTabToView(TIMESTAMP, false);
int expectedFinalX = -1004; // delta(optimalRight(-980) - scrollOffset(0)
// - tabOverlapWidth(24)) + scrollOffset(0)
assertEquals(expectedFinalX, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollOffset_OnResume_StartOnLeft_NoModelSelBtn_SelectedRightmostTab() {
// Arrange: Initialize tabs with last tab selected.
when(mModelSelectorBtn.isVisible()).thenReturn(false);
initializeTest(false, true, false, 9, 10);
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM, 150.f, 10);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Set screen width to 800dp.
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.scrollTabToView(TIMESTAMP, false);
int expectedFinalX = -956; // delta(optimalRight(-932) - scrollOffset(0)
// - tabOverlapWidth(24)) + scrollOffset(0)
assertEquals(expectedFinalX, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollOffset_OnResume_StartOnRight_SelectedLeftmostTab() {
// Arrange: Initialize tabs with first tab selected.
initializeTest(false, true, false, 0, 10);
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM, 150.f, 10);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
mStripLayoutHelper.testSetScrollOffset(-1200);
// Set screen width to 800dp.
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.scrollTabToView(TIMESTAMP, false);
int expectedFinalX = 0; // optimalLeft(0) - scrollOffset(-1200)) + scrollOffset(-1200)
assertEquals(expectedFinalX, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollOffset_OnResume_StartOnRight_NoModelSelBtn_SelectedRightmostTab() {
// Arrange: Initialize tabs with first tab selected.
when(mModelSelectorBtn.isVisible()).thenReturn(false);
initializeTest(false, true, false, 0, 10);
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM, 150.f, 10);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
mStripLayoutHelper.testSetScrollOffset(-1200);
// Set screen width to 800dp.
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
mStripLayoutHelper.scrollTabToView(TIMESTAMP, false);
int expectedFinalX = 0; // optimalLeft(0) - scrollOffset(-1200)) + scrollOffset(-1200)
assertEquals(expectedFinalX, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollOffset_OnOrientationChange_SelectedTabVisible() {
// Arrange: Initialize tabs with last tab selected.
when(mModelSelectorBtn.isVisible()).thenReturn(false);
initializeTest(false, true, false, 9, 10);
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM, 150.f, 10);
when(tabs[9].isVisible()).thenReturn(true);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
mStripLayoutHelper.testSetScrollOffset(1000);
// Set screen width to 1200 to start.
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH_LANDSCAPE, SCREEN_HEIGHT, false, TIMESTAMP);
// Assert: finalX value before orientation change.
int initialFinalX = -1494;
assertEquals(initialFinalX, mStripLayoutHelper.getScroller().getFinalX());
// Act: change orientation.
when(tabs[9].getDrawX()).thenReturn(-1.f);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, true, TIMESTAMP);
// Assert: finalX value after orientation change.
int expectedFinalX = -956; // delta(optimalRight(-932) - tabOverlapWidth(24)) -
// scrollOffset(1000) + scrollOffset(1000)
assertEquals(expectedFinalX, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollOffset_OnOrientationChange_SelectedTabNotVisible() {
// Arrange: Initialize tabs with last tab selected.
when(mModelSelectorBtn.isVisible()).thenReturn(false);
initializeTest(false, true, false, 9, 10);
TabUiFeatureUtilities.setTabMinWidthForTesting(TAB_WIDTH_MEDIUM);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM, 150.f, 10);
when(tabs[9].isVisible()).thenReturn(false);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
mStripLayoutHelper.testSetScrollOffset(1000);
// Set screen width to 1200 to start
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH_LANDSCAPE, SCREEN_HEIGHT, false, TIMESTAMP);
// Assert: finalX value before orientation change.
int initialFinalX = -1494;
assertEquals(initialFinalX, mStripLayoutHelper.getScroller().getFinalX());
// Act: change orientation.
when(tabs[9].getDrawX()).thenReturn(-1.f);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, true, TIMESTAMP);
// Assert: finalX value remains the same on orientation change.
assertEquals(initialFinalX, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_AfterTabClose_SkipsAutoScroll() {
initializeTest(false, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Set initial scroller position to 1000.
mStripLayoutHelper.getScroller().setFinalX(1000);
// Act: close a non selected tab.
mStripLayoutHelper.handleCloseButtonClick(tabs[1], TIMESTAMP);
// Assert: scroller position is not modified.
assertEquals(1000, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testTabSelected_AfterSelectedTabClose_SkipsAutoScroll() {
initializeTest(false, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Set initial scroller position to 1000.
mStripLayoutHelper.getScroller().setFinalX(1000);
// Act: close the selected tab.
mStripLayoutHelper.handleCloseButtonClick(tabs[3], TIMESTAMP);
// Assert: scroller position is not modified.
assertEquals(1000, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testTabCreated_RestoredTab_SkipsAutoscroll() {
initializeTest(false, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Set initial scroller position to 1000.
mStripLayoutHelper.getScroller().setFinalX(1000);
// Act: Tab was restored after undoing a tab closure.
boolean closureCancelled = true;
mStripLayoutHelper.tabCreated(TIMESTAMP, 6, 3, false, closureCancelled, false);
// Assert: scroller position is not modified.
assertEquals(1000, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testTabCreated_NonRestoredTab_SkipsAutoscroll() {
initializeTest(false, true, 3);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(TAB_WIDTH_MEDIUM);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Set initial scroller position to 1000.
mStripLayoutHelper.getScroller().setFinalX(1000);
// Act: Tab was restored after undoing a tab closure.
boolean closureCancelled = false;
mStripLayoutHelper.tabCreated(TIMESTAMP, 6, 3, false, closureCancelled, false);
// Assert: scroller position is modified.
assertNotEquals(1000, mStripLayoutHelper.getScroller().getFinalX());
}
@Test
@Feature("Tab Strip Improvements")
public void testTabCreated_BringSelectedTabToVisibleArea_StartupRestoredUnselectedTab() {
initializeTest(false, false, true, 1, 10);
mStripLayoutHelper.onSizeChanged(SCREEN_WIDTH, SCREEN_HEIGHT, false, TIMESTAMP);
// Set initial scroller position to -500.
mStripLayoutHelper.testSetScrollOffset(-500);
mStripLayoutHelper.updateLayout(TIMESTAMP);
// Act: Tab was restored during startup.
boolean selected = false;
boolean onStartup = true;
mStripLayoutHelper.tabCreated(TIMESTAMP, 11, 11, selected, false, onStartup);
// Assert: We don't scroll to the created tab. The selected tab is not already visible, so
// we scroll to it. Offset = -(1 tab width) = -166.
float expectedOffset = -166f;
assertEquals("We should scroll to the selected tab", expectedOffset,
mStripLayoutHelper.getScrollOffset(), EPSILON);
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollDuration() {
initializeTest(false, true, 3);
// Act: Set scroll offset greater than -960.
mStripLayoutHelper.testSetScrollOffset(-800);
// Assert: Expand duration is 250.
assertEquals(mStripLayoutHelper.getExpandDurationForTesting(), 250);
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollDuration_Medium() {
initializeTest(false, true, false, 3, 10);
// Act: Set scroll offset between -960 and -1920.
mStripLayoutHelper.testSetScrollOffset(-1000);
// Assert: Expand duration is 350.
assertEquals(mStripLayoutHelper.getExpandDurationForTesting(), 350);
}
@Test
@Feature("Tab Strip Improvements")
public void testScrollDuration_Large() {
initializeTest(false, true, false, 3, 15);
// Act: Set scroll offset less than -1920
mStripLayoutHelper.testSetScrollOffset(-2000);
// Assert: Expand duration is 450.
assertEquals(mStripLayoutHelper.getExpandDurationForTesting(), 450);
}
@Test
public void testOnDown_OnNewTabButton() {
// Initialize.
initializeTest(false, false, 0);
// Set new tab button location and dimensions.
mStripLayoutHelper.getNewTabButton().setX(NEW_TAB_BTN_X);
mStripLayoutHelper.getNewTabButton().setY(NEW_TAB_BTN_Y);
mStripLayoutHelper.getNewTabButton().setWidth(NEW_TAB_BTN_WIDTH);
mStripLayoutHelper.getNewTabButton().setHeight(NEW_TAB_BTN_HEIGHT);
// Press down on new tab button.
// CenterX = getX() + (getWidth() / 2) = 700 + (100 / 2) = 750
// CenterY = getY() + (getHeight() / 2) = 1400 + (100 / 2) = 1450
mStripLayoutHelper.onDown(TIMESTAMP, 750f, 1450f, false, 0);
// Verify.
assertTrue("New tab button should be pressed.",
mStripLayoutHelper.getNewTabButton().isPressed());
assertNull("Should not set an interacting tab when pressing down on new tab button.",
mStripLayoutHelper.getInteractingTab());
assertFalse("Should not start reorder mode when pressing down on new tab button.",
mStripLayoutHelper.getInReorderModeForTesting());
}
@Test
public void testOnDown_OnTab() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Press down on second tab.
when(tabs[1].checkCloseHitTest(anyFloat(), anyFloat())).thenReturn(false);
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onDown(TIMESTAMP, 150f, 0f, false, 0);
// Verify.
assertFalse("New tab button should not be pressed.",
mStripLayoutHelper.getNewTabButton().isPressed());
assertEquals("Second tab should be interacting tab.", tabs[1],
mStripLayoutHelper.getInteractingTab());
assertFalse("Should not start reorder mode when pressing down on tab without mouse.",
mStripLayoutHelper.getInReorderModeForTesting());
verify(tabs[1], never()).setClosePressed(anyBoolean());
}
@Test
public void testOnDown_OnTab_WithMouse() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Press down on second tab with mouse.
when(tabs[1].checkCloseHitTest(anyFloat(), anyFloat())).thenReturn(false);
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onDown(TIMESTAMP, 150f, 0f, true, 0);
// Verify.
assertFalse("New tab button should not be pressed.",
mStripLayoutHelper.getNewTabButton().isPressed());
assertEquals("Second tab should be interacting tab.", tabs[1],
mStripLayoutHelper.getInteractingTab());
assertTrue("Should start reorder mode when pressing down on tab with mouse.",
mStripLayoutHelper.getInReorderModeForTesting());
verify(tabs[1], never()).setClosePressed(anyBoolean());
}
@Test
public void testOnDown_OnTabCloseButton() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Press down on second tab's close button.
when(tabs[1].checkCloseHitTest(anyFloat(), anyFloat())).thenReturn(true);
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onDown(TIMESTAMP, 150f, 0f, false, 0);
// Verify.
assertFalse("New tab button should not be pressed.",
mStripLayoutHelper.getNewTabButton().isPressed());
assertEquals("Second tab should be interacting tab.", tabs[1],
mStripLayoutHelper.getInteractingTab());
assertFalse("Should not start reorder mode from close button.",
mStripLayoutHelper.getInReorderModeForTesting());
verify(tabs[1]).setClosePressed(eq(true));
}
@Test
public void testOnDown_OnTabCloseButton_WithMouse() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Press down on second tab's close button with mouse.
when(tabs[1].checkCloseHitTest(anyFloat(), anyFloat())).thenReturn(true);
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onDown(TIMESTAMP, 150f, 0f, true, 0);
// Verify.
assertFalse("New tab button should not be pressed.",
mStripLayoutHelper.getNewTabButton().isPressed());
assertEquals("Second tab should be interacting tab.", tabs[1],
mStripLayoutHelper.getInteractingTab());
assertFalse("Should not start reorder mode from close button.",
mStripLayoutHelper.getInReorderModeForTesting());
verify(tabs[1]).setClosePressed(eq(true));
}
@Test
public void testOnDown_WhileScrolling() {
// Initialize and assert scroller is finished.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
assertTrue("Scroller should be finished right after initializing.",
mStripLayoutHelper.getScroller().isFinished());
// Start scroll and assert scroller is not finished.
mStripLayoutHelper.getScroller().startScroll(0, 0, 0, 0, TIMESTAMP, 1000);
assertFalse("Scroller should not be finished after starting scroll.",
mStripLayoutHelper.getScroller().isFinished());
// Press down on second tab and assert scroller is finished.
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onDown(TIMESTAMP, 150f, 0f, false, 0);
assertFalse("New tab button should not be pressed.",
mStripLayoutHelper.getNewTabButton().isPressed());
assertNull("Should not set an interacting tab when pressing down to stop scrolling.",
mStripLayoutHelper.getInteractingTab());
assertTrue("Scroller should be force finished after pressing down on strip.",
mStripLayoutHelper.getScroller().isFinished());
}
@Test
public void testOnLongPress_OnTab() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Long press on second tab.
when(tabs[1].checkCloseHitTest(anyFloat(), anyFloat())).thenReturn(false);
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onLongPress(TIMESTAMP, 150f, 0f);
// Verify that we enter reorder mode.
assertTrue("Should be in reorder mode after long press on tab.",
mStripLayoutHelper.getInReorderModeForTesting());
assertFalse("Should not show tab menu after long press on tab.",
mStripLayoutHelper.isTabMenuShowing());
}
@Test
public void testOnLongPress_OnCloseButton() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Mock tab's view.
View tabView = new View(mActivity);
tabView.setLayoutParams(new MarginLayoutParams(150, 50));
when(mModel.getTabAt(1).getView()).thenReturn(tabView);
// Long press on second tab's close button.
when(tabs[1].checkCloseHitTest(anyFloat(), anyFloat())).thenReturn(true);
mStripLayoutHelper.setTabAtPositionForTesting(tabs[1]);
mStripLayoutHelper.onLongPress(TIMESTAMP, 150f, 0f);
// Verify that we show the "Close all tabs" popup menu.
assertFalse("Should not be in reorder mode after long press on tab close button.",
mStripLayoutHelper.getInReorderModeForTesting());
assertTrue("Should show tab menu after long press on tab close button.",
mStripLayoutHelper.isTabMenuShowing());
}
@Test
public void testOnLongPress_OffTab() {
// Initialize.
initializeTest(false, false, 0);
StripLayoutTab[] tabs = getMockedStripLayoutTabs(150f);
mStripLayoutHelper.setStripLayoutTabsForTest(tabs);
// Long press past the last tab.
mStripLayoutHelper.setTabAtPositionForTesting(null);
mStripLayoutHelper.onLongPress(TIMESTAMP, 150f, 0f);
// Verify that we show the "Close all tabs" popup menu.
assertFalse("Should not be in reorder mode after long press on empty space on tab strip.",
mStripLayoutHelper.getInReorderModeForTesting());
assertFalse("Should not show after long press on empty space on tab strip.",
mStripLayoutHelper.isTabMenuShowing());
}
@Test
@Feature("Tab Groups on Tab Strip")
public void testTabGroupMargins_BetweenTabs() {
// Initialize with 3 tabs.
initializeTest(false, false, true, 0, 3);
// Start reorder.
mStripLayoutHelper.startReorderModeAtIndexForTesting(0);
// Verify no tabs have a trailing margin, since there are no tab groups.
StripLayoutTab[] tabs = mStripLayoutHelper.getStripLayoutTabs();
assertEquals(EXPECTED_NO_MARGIN, tabs[0].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[1].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[2].getTrailingMargin(), 0f, EPSILON);
}
@Test
@Feature("Tab Groups on Tab Strip")
public void testTabGroupMargins_TabToLeft() {
// Mock 1 tab to the left of a tab group with 3 tabs.
initializeTest(false, false, true, 0, 4);
groupTabs(1, 4);
// Start reorder.
mStripLayoutHelper.startReorderModeAtIndexForTesting(0);
// Verify the leftmost and final tabs have a trailing margin.
StripLayoutTab[] tabs = mStripLayoutHelper.getStripLayoutTabs();
assertEquals(EXPECTED_MARGIN, tabs[0].getTrailingMargin(), TAB_MARGIN_WIDTH, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[1].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[2].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_MARGIN, tabs[3].getTrailingMargin(), TAB_MARGIN_WIDTH, EPSILON);
}
@Test
@Feature("Tab Groups on Tab Strip")
public void testTabGroupMargins_TabToRight() {
// Mock 1 tab to the right of a tab group with 3 tabs.
initializeTest(false, false, true, 0, 4);
groupTabs(0, 3);
// Start reorder.
mStripLayoutHelper.startReorderModeAtIndexForTesting(0);
// Verify the rightmost tab in the tab group has a trailing margin.
StripLayoutTab[] tabs = mStripLayoutHelper.getStripLayoutTabs();
assertEquals(EXPECTED_NO_MARGIN, tabs[0].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[1].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_MARGIN, tabs[2].getTrailingMargin(), TAB_MARGIN_WIDTH, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[3].getTrailingMargin(), 0f, EPSILON);
}
@Test
@Feature("Tab Groups on Tab Strip")
public void testTabGroupMargins_BetweenGroups() {
// Mock a tab group with 2 tabs to the left of a tab group with 3 tabs.
initializeTest(false, false, true, 0, 5);
groupTabs(0, 2);
groupTabs(2, 5);
// Start reorder.
mStripLayoutHelper.startReorderModeAtIndexForTesting(0);
// Verify the rightmost tab in the first group has a trailing margin.
StripLayoutTab[] tabs = mStripLayoutHelper.getStripLayoutTabs();
assertEquals(EXPECTED_NO_MARGIN, tabs[0].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_MARGIN, tabs[1].getTrailingMargin(), TAB_MARGIN_WIDTH, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[2].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_NO_MARGIN, tabs[3].getTrailingMargin(), 0f, EPSILON);
assertEquals(EXPECTED_MARGIN, tabs[4].getTrailingMargin(), TAB_MARGIN_WIDTH, EPSILON);
}