-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
TabGridDialogMediatorUnitTest.java
1314 lines (1081 loc) · 60.2 KB
/
TabGridDialogMediatorUnitTest.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 2019 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.tasks.tab_management;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import org.junit.Assert;
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.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.Supplier;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabCreationState;
import org.chromium.chrome.browser.tab.TabImpl;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tab.TabSelectionType;
import org.chromium.chrome.browser.tab.state.CriticalPersistedTabData;
import org.chromium.chrome.browser.tabmodel.TabCreator;
import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelFilterProvider;
import org.chromium.chrome.browser.tabmodel.TabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorImpl;
import org.chromium.chrome.browser.tasks.tab_groups.TabGroupModelFilter;
import org.chromium.chrome.browser.tasks.tab_management.TabListRecyclerView.RecyclerViewPosition;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.KeyboardVisibilityDelegate;
import org.chromium.ui.base.TestActivity;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.url.GURL;
import org.chromium.url.JUnitTestGURLs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Tests for {@link TabGridDialogMediator}.
*/
@SuppressWarnings({"ArraysAsListWithZeroOrOneArgument", "ResultOfMethodCallIgnored"})
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
// clang-format off
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID,
ChromeFeatureList.TAB_SELECTION_EDITOR_V2})
public class TabGridDialogMediatorUnitTest {
// clang-format on
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
private static final String TAB1_TITLE = "Tab1";
private static final String TAB2_TITLE = "Tab2";
private static final String TAB3_TITLE = "Tab3";
private static final String DIALOG_TITLE1 = "1 tab";
private static final String DIALOG_TITLE2 = "2 tabs";
private static final String REMOVE_BUTTON_STRING = "Remove";
private static final String CUSTOMIZED_DIALOG_TITLE = "Cool Tabs";
private static final int TAB1_ID = 456;
private static final int TAB2_ID = 789;
private static final int TAB3_ID = 123;
private static final int POSITION1 = 0;
private static final int POSITION2 = 1;
@Mock
View mView;
@Mock
TabGridDialogMediator.DialogController mDialogController;
@Mock
TabModelSelectorImpl mTabModelSelector;
@Mock
TabCreatorManager mTabCreatorManager;
@Mock
TabCreator mTabCreator;
@Mock
TabSwitcherMediator.ResetHandler mTabSwitcherResetHandler;
@Mock
TabGridDialogMediator.AnimationSourceViewProvider mAnimationSourceViewProvider;
@Mock
TabModelFilterProvider mTabModelFilterProvider;
@Mock
TabGroupModelFilter mTabGroupModelFilter;
@Mock
TabModel mTabModel;
@Mock
TabSelectionEditorCoordinator.TabSelectionEditorController mTabSelectionEditorController;
@Mock
TabGroupTitleEditor mTabGroupTitleEditor;
@Mock
EditText mTitleTextView;
@Mock
Editable mEditable;
@Mock
ObservableSupplier<ShareDelegate> mShareDelegateSupplier;
@Mock
SnackbarManager mSnackbarManager;
@Mock
Supplier<RecyclerViewPosition> mRecyclerViewPositionSupplier;
@Captor
ArgumentCaptor<TabModelObserver> mTabModelObserverCaptor;
private TabImpl mTab1;
private TabImpl mTab2;
private Activity mActivity;
private PropertyModel mModel;
private TabGridDialogMediator mMediator;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mTab1 = prepareTab(TAB1_ID, TAB1_TITLE);
mTab2 = prepareTab(TAB2_ID, TAB2_TITLE);
List<Tab> tabs1 = new ArrayList<>(Arrays.asList(mTab1));
List<Tab> tabs2 = new ArrayList<>(Arrays.asList(mTab2));
List<TabModel> tabModelList = new ArrayList<>();
tabModelList.add(mTabModel);
doReturn(mTabModel).when(mTabModelSelector).getCurrentModel();
doReturn(tabModelList).when(mTabModelSelector).getModels();
doReturn(mTabModelFilterProvider).when(mTabModelSelector).getTabModelFilterProvider();
doReturn(mTabGroupModelFilter).when(mTabModelFilterProvider).getCurrentTabModelFilter();
doReturn(POSITION1).when(mTabGroupModelFilter).indexOf(mTab1);
doReturn(POSITION2).when(mTabGroupModelFilter).indexOf(mTab2);
doReturn(mTab1).when(mTabGroupModelFilter).getTabAt(POSITION1);
doReturn(mTab2).when(mTabGroupModelFilter).getTabAt(POSITION2);
doReturn(tabs1).when(mTabGroupModelFilter).getRelatedTabList(TAB1_ID);
doReturn(tabs2).when(mTabGroupModelFilter).getRelatedTabList(TAB2_ID);
doReturn(mTab1).when(mTabModelSelector).getCurrentTab();
doReturn(mTab1).when(mTabModelSelector).getTabById(TAB1_ID);
doReturn(mTab2).when(mTabModelSelector).getTabById(TAB2_ID);
doReturn(TAB1_ID).when(mTabModelSelector).getCurrentTabId();
doReturn(2).when(mTabModel).getCount();
doReturn(mTab1).when(mTabModel).getTabAt(POSITION1);
doReturn(mTab2).when(mTabModel).getTabAt(POSITION2);
doReturn(POSITION1).when(mTabModel).indexOf(mTab1);
doReturn(POSITION2).when(mTabModel).indexOf(mTab2);
doNothing()
.when(mTabModelFilterProvider)
.addTabModelFilterObserver(mTabModelObserverCaptor.capture());
doReturn(mView).when(mAnimationSourceViewProvider).getAnimationSourceViewForTab(anyInt());
doReturn(mTabCreator).when(mTabCreatorManager).getTabCreator(anyBoolean());
doReturn(mEditable).when(mTitleTextView).getText();
doReturn(CUSTOMIZED_DIALOG_TITLE).when(mEditable).toString();
doReturn(null).when(mRecyclerViewPositionSupplier).get();
if (!TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled(
ContextUtils.getApplicationContext())
&& !TabUiFeatureUtilities.isTabSelectionEditorV2Enabled(
ContextUtils.getApplicationContext())) {
mTabSelectionEditorController = null;
}
mActivity = Robolectric.buildActivity(TestActivity.class).get();
mModel = new PropertyModel(TabGridPanelProperties.ALL_KEYS);
mMediator =
new TabGridDialogMediator(mActivity, mDialogController, mModel, mTabModelSelector,
mTabCreatorManager, mTabSwitcherResetHandler, mRecyclerViewPositionSupplier,
mAnimationSourceViewProvider, mShareDelegateSupplier, mSnackbarManager, "");
// TabModelObserver is registered when native is ready.
assertThat(mTabModelObserverCaptor.getAllValues().isEmpty(), equalTo(true));
mMediator.initWithNative(
() -> { return mTabSelectionEditorController; }, mTabGroupTitleEditor);
assertThat(mTabModelObserverCaptor.getAllValues().isEmpty(), equalTo(false));
}
@Test
public void setupListenersAndObservers() {
// These listeners and observers should be setup when the mediator is created.
assertThat(mModel.get(TabGridPanelProperties.COLLAPSE_CLICK_LISTENER),
instanceOf(View.OnClickListener.class));
assertThat(mModel.get(TabGridPanelProperties.ADD_CLICK_LISTENER),
instanceOf(View.OnClickListener.class));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void setupTabGroupsContinuation_flagEnabled() {
assertThat(TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled(
ContextUtils.getApplicationContext()),
equalTo(true));
// Setup editable title.
assertThat(mMediator.getKeyboardVisibilityListenerForTesting(),
instanceOf(KeyboardVisibilityDelegate.KeyboardVisibilityListener.class));
assertThat(mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER),
instanceOf(TextWatcher.class));
assertThat(mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER),
instanceOf(View.OnFocusChangeListener.class));
// Setup selection editor for ungrouping.
assertThat(mModel.get(TabGridPanelProperties.MENU_CLICK_LISTENER),
instanceOf(View.OnClickListener.class));
mMediator.getToolbarMenuCallbackForTesting().onResult(R.id.ungroup_tab);
verify(mTabSelectionEditorController)
.configureToolbar(eq(REMOVE_BUTTON_STRING), anyInt(),
any(TabSelectionEditorActionProvider.class), eq(1), eq(null));
verify(mRecyclerViewPositionSupplier, never()).get();
verify(mTabSelectionEditorController).show(any(), eq(0), eq(null));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_SELECTION_EDITOR_V2)
public void setupTabSelectionEditorV2_flagEnabled() {
assertThat(TabUiFeatureUtilities.isTabSelectionEditorV2Enabled(
ContextUtils.getApplicationContext()),
equalTo(true));
assertThat(mMediator.getKeyboardVisibilityListenerForTesting(), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER), equalTo(null));
// Setup selection editor for multiple items.
assertThat(mModel.get(TabGridPanelProperties.MENU_CLICK_LISTENER),
instanceOf(View.OnClickListener.class));
ArgumentCaptor<List<TabSelectionEditorAction>> captor =
ArgumentCaptor.forClass((Class) List.class);
mMediator.getToolbarMenuCallbackForTesting().onResult(R.id.select_tabs);
verify(mTabSelectionEditorController)
.configureToolbarWithMenuItems(captor.capture(), eq(null));
verify(mRecyclerViewPositionSupplier, times(1)).get();
verify(mTabSelectionEditorController).show(any(), eq(0), eq(null));
List<TabSelectionEditorAction> actions = captor.getValue();
assertThat(actions.get(0), instanceOf(TabSelectionEditorSelectionAction.class));
assertThat(actions.get(1), instanceOf(TabSelectionEditorCloseAction.class));
assertThat(actions.get(2), instanceOf(TabSelectionEditorUngroupAction.class));
}
@Test
public void setupTabGroupsContinuation_flagDisabled() {
assertThat(TabUiFeatureUtilities.isTabGroupsAndroidContinuationEnabled(
ContextUtils.getApplicationContext()),
equalTo(false));
assertThat(mMediator.getKeyboardVisibilityListenerForTesting(), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.MENU_CLICK_LISTENER), equalTo(null));
assertNull(mTabSelectionEditorController);
}
@Test
public void onClickAdd_HasCurrentTab() {
// Mock that the animation source view is not null, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, mView);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
View.OnClickListener listener = mModel.get(TabGridPanelProperties.ADD_CLICK_LISTENER);
listener.onClick(mView);
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
verify(mDialogController).resetWithListOfTabs(null);
verify(mTabCreator)
.createNewTab(
isA(LoadUrlParams.class), eq(TabLaunchType.FROM_TAB_GROUP_UI), eq(mTab1));
}
@Test
public void onClickAdd_NoCurrentTab() {
mMediator.setCurrentTabIdForTesting(Tab.INVALID_TAB_ID);
View.OnClickListener listener = mModel.get(TabGridPanelProperties.ADD_CLICK_LISTENER);
listener.onClick(mView);
verify(mTabCreator).launchNTP();
}
@Test
public void onClickCollapse() {
// Mock that the keyboard and the dialog are showing.
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mModel.set(TabGridPanelProperties.IS_KEYBOARD_VISIBLE, true);
View.OnClickListener listener = mModel.get(TabGridPanelProperties.COLLAPSE_CLICK_LISTENER);
listener.onClick(mView);
verify(mDialogController).resetWithListOfTabs(null);
assertThat(mModel.get(TabGridPanelProperties.IS_KEYBOARD_VISIBLE), equalTo(false));
}
@Test
public void onClickScrim() {
// Show the group of {tab1, tab2} in dialog to trigger the set of scrim observer.
List<Tab> tabgroup = new ArrayList<>(Arrays.asList(mTab1, mTab2));
createTabGroup(tabgroup, TAB1_ID);
mMediator.onReset(tabgroup);
Runnable scrimClickRunnable = mModel.get(TabGridPanelProperties.SCRIMVIEW_CLICK_RUNNABLE);
scrimClickRunnable.run();
verify(mDialogController).resetWithListOfTabs(null);
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void onTitleTextChange_WithoutFocus() {
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
// Mock tab1 is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
assertThat(mEditable.toString(), equalTo(CUSTOMIZED_DIALOG_TITLE));
textWatcher.afterTextChanged(mEditable);
// TabGroupTitleEditor should not react to text change when there is no focus.
verify(mTabGroupTitleEditor, never()).storeTabGroupTitle(anyInt(), any(String.class));
verify(mTabGroupTitleEditor, never()).updateTabGroupTitle(any(Tab.class), anyString());
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(TAB1_TITLE));
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(), equalTo(null));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void onTitleTextChange_WithFocus() {
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
// Mock tab1 is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
assertThat(mEditable.toString(), equalTo(CUSTOMIZED_DIALOG_TITLE));
// Focus on title TextView.
View.OnFocusChangeListener listener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
listener.onFocusChange(mTitleTextView, true);
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(),
equalTo(CUSTOMIZED_DIALOG_TITLE));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void onTitleTextFocusChange() {
View.OnFocusChangeListener listener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
assertThat(mMediator.getIsUpdatingTitleForTesting(), equalTo(false));
listener.onFocusChange(mTitleTextView, true);
assertThat(mMediator.getIsUpdatingTitleForTesting(), equalTo(true));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void onKeyBoardVisibilityChanged_updateTextAndKeyboard() {
KeyboardVisibilityDelegate.KeyboardVisibilityListener listener =
mMediator.getKeyboardVisibilityListenerForTesting();
mModel.set(TabGridPanelProperties.TITLE_CURSOR_VISIBILITY, false);
mModel.set(TabGridPanelProperties.IS_TITLE_TEXT_FOCUSED, false);
listener.keyboardVisibilityChanged(true);
assertThat(mModel.get(TabGridPanelProperties.TITLE_CURSOR_VISIBILITY), equalTo(true));
assertThat(mModel.get(TabGridPanelProperties.IS_TITLE_TEXT_FOCUSED), equalTo(true));
assertThat(mModel.get(TabGridPanelProperties.IS_KEYBOARD_VISIBLE), equalTo(true));
listener.keyboardVisibilityChanged(false);
assertThat(mModel.get(TabGridPanelProperties.TITLE_CURSOR_VISIBILITY), equalTo(false));
assertThat(mModel.get(TabGridPanelProperties.IS_TITLE_TEXT_FOCUSED), equalTo(false));
assertThat(mModel.get(TabGridPanelProperties.IS_KEYBOARD_VISIBLE), equalTo(false));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void onKeyBoardVisibilityChanged_StoreGroupTitle() {
KeyboardVisibilityDelegate.KeyboardVisibilityListener keyboardVisibilityListener =
mMediator.getKeyboardVisibilityListenerForTesting();
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
// Mock that tab1 is in a group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
// Mock that keyboard shows and group title is updated.
keyboardVisibilityListener.keyboardVisibilityChanged(true);
View.OnFocusChangeListener onFocusChangeListener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
onFocusChangeListener.onFocusChange(mTitleTextView, true);
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(),
equalTo(CUSTOMIZED_DIALOG_TITLE));
keyboardVisibilityListener.keyboardVisibilityChanged(false);
verify(mTabGroupTitleEditor).storeTabGroupTitle(eq(TAB1_ID), eq(CUSTOMIZED_DIALOG_TITLE));
verify(mTabGroupTitleEditor).updateTabGroupTitle(eq(mTab1), eq(CUSTOMIZED_DIALOG_TITLE));
assertThat(
mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(CUSTOMIZED_DIALOG_TITLE));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void onKeyBoardVisibilityChanged_NoFocus_NotStoreGroupTitle() {
KeyboardVisibilityDelegate.KeyboardVisibilityListener keyboardVisibilityListener =
mMediator.getKeyboardVisibilityListenerForTesting();
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
// Mock that tab1 is in a group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
// Mock that keyboard shows but title edit text is not focused.
keyboardVisibilityListener.keyboardVisibilityChanged(true);
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getIsUpdatingTitleForTesting(), equalTo(false));
keyboardVisibilityListener.keyboardVisibilityChanged(false);
verify(mTabGroupTitleEditor, never()).storeTabGroupTitle(anyInt(), anyString());
verify(mTabGroupTitleEditor, never()).updateTabGroupTitle(any(Tab.class), anyString());
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(TAB1_TITLE));
}
@Test
public void tabAddition() {
TabImpl newTab = prepareTab(TAB3_ID, TAB3_TITLE);
// Mock that the animation source view is not null, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, mView);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
doReturn(true).when(mTabModelSelector).isTabStateInitialized();
mTabModelObserverCaptor.getValue().didAddTab(
newTab, TabLaunchType.FROM_CHROME_UI, TabCreationState.LIVE_IN_FOREGROUND, false);
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
verify(mDialogController).resetWithListOfTabs(null);
}
@Test
public void tabClosure_NotLast_NotCurrent() {
// Mock that tab1 and tab2 are in the same group, but tab2 just gets closed.
doReturn(new ArrayList<>(Arrays.asList(mTab1)))
.when(mTabGroupModelFilter)
.getRelatedTabList(TAB2_ID);
// Mock tab1 is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB1_ID);
// Mock dialog title is null and the dialog is showing.
mModel.set(TabGridPanelProperties.HEADER_TITLE, null);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().willCloseTab(mTab2, false, true);
// Current tab ID should not update.
assertThat(mMediator.getCurrentTabIdForTesting(), equalTo(TAB1_ID));
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE1));
verify(mTabSwitcherResetHandler).resetWithTabList(mTabGroupModelFilter, false, false);
}
@Test
public void tabClosure_NotLast_Current() {
// Mock that tab1 and tab2 are in the same group, but tab2 just gets closed.
doReturn(new ArrayList<>(Arrays.asList(mTab1)))
.when(mTabGroupModelFilter)
.getRelatedTabList(TAB2_ID);
// Mock tab2 is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB2_ID);
// Mock dialog title is null and the dialog is showing.
mModel.set(TabGridPanelProperties.HEADER_TITLE, null);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().willCloseTab(mTab2, false, true);
// Current tab ID should be updated to TAB1_ID now.
assertThat(mMediator.getCurrentTabIdForTesting(), equalTo(TAB1_ID));
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE1));
verify(mTabSwitcherResetHandler).resetWithTabList(mTabGroupModelFilter, false, false);
}
@Test
public void tabClosure_Last_Current() {
// Mock that tab1 is the last tab in the group and it just gets closed.
doReturn(new ArrayList<>()).when(mTabGroupModelFilter).getRelatedTabList(TAB1_ID);
// As last tab in the group, tab1 is definitely the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB1_ID);
// Mock the dialog is showing and the animation source view is not null.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, mView);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().willCloseTab(mTab1, false, true);
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
verify(mDialogController).resetWithListOfTabs(null);
verify(mTabSwitcherResetHandler, never())
.resetWithTabList(mTabGroupModelFilter, false, false);
mMediator.onReset(null);
assertThat(mMediator.getCurrentTabIdForTesting(), equalTo(Tab.INVALID_TAB_ID));
}
@Test
public void tabClosure_NotLast_Current_WithDialogHidden() {
// Mock that tab1 and tab2 are in the same group, but tab2 just gets closed.
doReturn(new ArrayList<>(Arrays.asList(mTab1)))
.when(mTabGroupModelFilter)
.getRelatedTabList(TAB2_ID);
// Mock tab2 is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB2_ID);
// Mock dialog title is null and the dialog is hidden.
mModel.set(TabGridPanelProperties.HEADER_TITLE, null);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, false);
mTabModelObserverCaptor.getValue().willCloseTab(mTab2, false, true);
// Current tab ID should be updated to TAB1_ID now.
assertThat(mMediator.getCurrentTabIdForTesting(), equalTo(TAB1_ID));
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE1));
// Dialog should still be hidden.
assertThat(mModel.get(TabGridPanelProperties.IS_DIALOG_VISIBLE), equalTo(false));
verify(mTabSwitcherResetHandler, never())
.resetWithTabList(mTabGroupModelFilter, false, false);
}
@Test
public void tabClosure_NonRootTab_StillGroupAfterClosure_WithStoredTitle() {
// Mock that tab1, tab2 and newTab are in the same group and tab1 is the root tab.
TabImpl newTab = prepareTab(TAB3_ID, TAB3_TITLE);
List<Tab> tabgroup = new ArrayList<>(Arrays.asList(mTab1, mTab2, newTab));
createTabGroup(tabgroup, TAB1_ID);
// Mock that newTab just get closed.
List<Tab> tabgroupAfterClosure = new ArrayList<>(Arrays.asList(mTab1, mTab2));
doReturn(tabgroupAfterClosure).when(mTabGroupModelFilter).getRelatedTabList(TAB1_ID);
doReturn(tabgroupAfterClosure).when(mTabGroupModelFilter).getRelatedTabList(TAB2_ID);
// Mock that newTab is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB3_ID);
// Mock that we have a stored title stored with reference to root ID of tab1.
doReturn(CUSTOMIZED_DIALOG_TITLE).when(mTabGroupTitleEditor).getTabGroupTitle(TAB1_ID);
assertThat(mTabGroupTitleEditor.getTabGroupTitle(
CriticalPersistedTabData.from(mTab1).getRootId()),
equalTo(CUSTOMIZED_DIALOG_TITLE));
mTabModelObserverCaptor.getValue().willCloseTab(newTab, false, true);
// Dialog title should still be the stored title.
assertThat(
mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(CUSTOMIZED_DIALOG_TITLE));
}
@Test
public void tabClosure_RootTab_StillGroupAfterClosure_WithStoredTitle() {
// Mock that tab1, tab2 and newTab are in the same group and newTab is the root tab.
TabImpl newTab = prepareTab(TAB3_ID, TAB3_TITLE);
List<Tab> tabgroup = new ArrayList<>(Arrays.asList(mTab1, mTab2, newTab));
createTabGroup(tabgroup, TAB3_ID);
// Mock that newTab just get closed.
List<Tab> tabgroupAfterClosure = new ArrayList<>(Arrays.asList(mTab1, mTab2));
doReturn(tabgroupAfterClosure).when(mTabGroupModelFilter).getRelatedTabList(TAB1_ID);
doReturn(tabgroupAfterClosure).when(mTabGroupModelFilter).getRelatedTabList(TAB2_ID);
// Mock that newTab is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB3_ID);
// Mock that we have a stored title stored with reference to root ID of newTab.
doReturn(CUSTOMIZED_DIALOG_TITLE).when(mTabGroupTitleEditor).getTabGroupTitle(TAB3_ID);
mTabModelObserverCaptor.getValue().willCloseTab(newTab, false, true);
// Dialog title should still be the stored title even if the root tab is closed.
assertThat(
mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(CUSTOMIZED_DIALOG_TITLE));
}
@Test
public void tabClosure_SingleTabAfterClosure_WithStoredTitle() {
// Mock that tab1, tab2 are in the same group and tab1 is the root tab.
List<Tab> tabgroup = new ArrayList<>(Arrays.asList(mTab1, mTab2));
createTabGroup(tabgroup, TAB1_ID);
// Mock that tab2 just get closed.
List<Tab> tabgroupAfterClosure = new ArrayList<>(Arrays.asList(mTab1));
doReturn(tabgroupAfterClosure).when(mTabGroupModelFilter).getRelatedTabList(TAB1_ID);
// Mock that tab2 is the current tab for the dialog.
mMediator.setCurrentTabIdForTesting(TAB2_ID);
// Mock that we have a stored title stored with reference to root ID of tab1.
doReturn(CUSTOMIZED_DIALOG_TITLE).when(mTabGroupTitleEditor).getTabGroupTitle(TAB1_ID);
mTabModelObserverCaptor.getValue().willCloseTab(mTab2, false, true);
// Even if there is a stored title for tab1, it is now a single tab, so we won't show the
// stored title.
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE1));
}
@Test
public void tabClosureUndone() {
// Mock that the dialog is showing.
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mModel.set(TabGridPanelProperties.HEADER_TITLE, null);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mTabModelObserverCaptor.getValue().tabClosureUndone(mTab1);
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE1));
verify(mTabSwitcherResetHandler).resetWithTabList(mTabGroupModelFilter, false, false);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator), eq(TAB1_ID));
}
@Test
public void tabClosureUndone_WithStoredTitle() {
// Mock that the dialog is showing.
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mModel.set(TabGridPanelProperties.HEADER_TITLE, null);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
// Mock that we have a stored title stored with reference to root ID of tab1.
doReturn(CUSTOMIZED_DIALOG_TITLE).when(mTabGroupTitleEditor).getTabGroupTitle(TAB1_ID);
// Mock that tab1 and tab2 are in the same group, and we are undoing tab2.
List<Tab> tabgroup = new ArrayList<>(Arrays.asList(mTab1, mTab2));
createTabGroup(tabgroup, TAB1_ID);
mTabModelObserverCaptor.getValue().tabClosureUndone(mTab2);
// If current group has a stored title, dialog title should be set to stored title when
// undoing a closure.
assertThat(
mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(CUSTOMIZED_DIALOG_TITLE));
verify(mTabSwitcherResetHandler).resetWithTabList(mTabGroupModelFilter, false, false);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator), eq(TAB2_ID));
}
@Test
public void tabClosureUndone_WithDialogHidden() {
// Mock that the dialog is hidden.
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, false);
mModel.set(TabGridPanelProperties.HEADER_TITLE, null);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mTabModelObserverCaptor.getValue().tabClosureUndone(mTab1);
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE1));
// Dialog should still be hidden.
assertThat(mModel.get(TabGridPanelProperties.IS_DIALOG_VISIBLE), equalTo(false));
verify(mTabSwitcherResetHandler, never())
.resetWithTabList(mTabGroupModelFilter, false, false);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator), eq(TAB1_ID));
}
@Test
public void tabClosureCommitted() {
mTabModelObserverCaptor.getValue().tabClosureCommitted(mTab1);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator), eq(TAB1_ID));
}
@Test
public void onFinishingMultipleTabClosure() {
List<Tab> tabs = Arrays.asList(mTab1, mTab2);
mTabModelObserverCaptor.getValue().onFinishingMultipleTabClosure(tabs);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator), eq(tabs));
}
@Test
public void onFinishingMultipleTabClosure_singleTab() {
List<Tab> tabs = Arrays.asList(mTab1);
mTabModelObserverCaptor.getValue().onFinishingMultipleTabClosure(tabs);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator), eq(TAB1_ID));
}
@Test
public void allTabsClosureCommitted() {
mTabModelObserverCaptor.getValue().allTabsClosureCommitted(false);
verify(mSnackbarManager).dismissSnackbars(eq(mMediator));
}
@Test
public void tabPendingClosure_DialogVisible() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().tabPendingClosure(mTab1);
verify(mSnackbarManager).showSnackbar(any(Snackbar.class));
}
@Test
public void tabPendingClosure_DialogInvisible() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, false);
mTabModelObserverCaptor.getValue().tabPendingClosure(mTab1);
verify(mSnackbarManager, never()).showSnackbar(any(Snackbar.class));
}
@Test
public void multipleTabsPendingClosure_DialogVisible() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().multipleTabsPendingClosure(
Arrays.asList(mTab1, mTab2), false);
verify(mSnackbarManager).showSnackbar(any(Snackbar.class));
}
@Test
public void multipleTabsPendingClosure_singleTab_DialogVisible() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().multipleTabsPendingClosure(Arrays.asList(mTab1), false);
verify(mSnackbarManager).showSnackbar(any(Snackbar.class));
}
@Test
public void multipleTabsPendingClosure_DialogInvisible() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, false);
mTabModelObserverCaptor.getValue().multipleTabsPendingClosure(
Arrays.asList(mTab1, mTab2), false);
verify(mSnackbarManager, never()).showSnackbar(any(Snackbar.class));
}
@Test
public void tabSelection() {
// Mock that the animation source view is not null, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, mView);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mTabModelObserverCaptor.getValue().didSelectTab(
mTab1, TabSelectionType.FROM_USER, Tab.INVALID_TAB_ID);
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
verify(mDialogController).resetWithListOfTabs(null);
}
@Test
public void hideDialog_FadeOutAnimation() {
// Mock that the animation source view is null, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, null);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mMediator.hideDialog(false);
// Animation source view should not be specified.
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
verify(mDialogController).resetWithListOfTabs(eq(null));
}
@Test
public void hideDialog_WithVisibilityListener_BasicAnimation() {
// Mock that the animation source view is null, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, null);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
// Set visibility listener.
mModel.set(TabGridPanelProperties.VISIBILITY_LISTENER, mMediator);
mMediator.hideDialog(false);
// Animation source view should not be specified.
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.IS_DIALOG_VISIBLE), equalTo(false));
verifyZeroInteractions(mDialogController);
}
@Test
public void hideDialog_FadeOutAnimation_ClearsViewAnimation() {
// Mock that the animation source view is set, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, mView);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mMediator.hideDialog(false);
// Animation source view should not be specified.
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
verify(mDialogController).resetWithListOfTabs(eq(null));
}
@Test
public void hideDialog_WithVisibilityListener_ClearsViewAnimation() {
// Mock that the animation source view exists, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, mView);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
// Set visibility listener.
mModel.set(TabGridPanelProperties.VISIBILITY_LISTENER, mMediator);
mMediator.hideDialog(false);
// Animation source view should not be specified.
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(null));
assertThat(mModel.get(TabGridPanelProperties.IS_DIALOG_VISIBLE), equalTo(false));
verifyZeroInteractions(mDialogController);
}
@Test
public void hideDialog_ZoomOutAnimation() {
// Mock that the animation source view is null, and the dialog is showing.
mModel.set(TabGridPanelProperties.ANIMATION_SOURCE_VIEW, null);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mMediator.hideDialog(true);
// Animation source view should be specified.
assertThat(mModel.get(TabGridPanelProperties.ANIMATION_SOURCE_VIEW), equalTo(mView));
verify(mDialogController).resetWithListOfTabs(eq(null));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void hideDialog_StoreModifiedGroupTitle() {
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
// Mock that tab1 is in a group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
// Mock that we have a modified group title before dialog is hidden.
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
View.OnFocusChangeListener onFocusChangeListener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
onFocusChangeListener.onFocusChange(mTitleTextView, true);
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(),
equalTo(CUSTOMIZED_DIALOG_TITLE));
mMediator.hideDialog(false);
verify(mTabGroupTitleEditor).storeTabGroupTitle(eq(TAB1_ID), eq(CUSTOMIZED_DIALOG_TITLE));
verify(mTabGroupTitleEditor).updateTabGroupTitle(eq(mTab1), eq(CUSTOMIZED_DIALOG_TITLE));
assertThat(
mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(CUSTOMIZED_DIALOG_TITLE));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void hideDialog_ModifiedGroupTitleEmpty() {
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
// Mock that tab1 is in a group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
// Mock that we have a modified group title which is an empty string.
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
View.OnFocusChangeListener onFocusChangeListener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
onFocusChangeListener.onFocusChange(mTitleTextView, true);
doReturn("").when(mEditable).toString();
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(), equalTo(""));
mMediator.hideDialog(false);
// When updated title is a empty string, delete stored title and restore default title in
// PropertyModel.
verify(mTabGroupTitleEditor).deleteTabGroupTitle(eq(TAB1_ID));
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(DIALOG_TITLE2));
verify(mTabGroupTitleEditor).updateTabGroupTitle(eq(mTab1), eq(DIALOG_TITLE2));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void hideDialog_NoModifiedGroupTitle() {
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
// Mock that tab1 is in a group.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1, mTab2)), TAB1_ID);
mMediator.hideDialog(false);
// When title is not updated, don't store title when hide dialog.
verify(mTabGroupTitleEditor, never()).storeTabGroupTitle(anyInt(), anyString());
verify(mTabGroupTitleEditor, never()).updateTabGroupTitle(any(Tab.class), anyString());
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(TAB1_TITLE));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void hideDialog_ClosingLastTab_SkipStoreGroupTitle() {
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
// Mock that the last tab in the group is closed.
doReturn(new ArrayList<>()).when(mTabGroupModelFilter).getRelatedTabList(TAB1_ID);
// Mock that we have a modified group title before dialog is hidden.
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
View.OnFocusChangeListener onFocusChangeListener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
onFocusChangeListener.onFocusChange(mTitleTextView, true);
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(),
equalTo(CUSTOMIZED_DIALOG_TITLE));
mMediator.hideDialog(false);
// Skip storing dialog title when the last tab is closing.
verify(mTabGroupTitleEditor, never()).storeTabGroupTitle(anyInt(), anyString());
verify(mTabGroupTitleEditor, never()).updateTabGroupTitle(any(Tab.class), anyString());
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(TAB1_TITLE));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void hideDialog_SingleTab_SkipStoreGroupTitle() {
mMediator.setCurrentTabIdForTesting(TAB1_ID);
mModel.set(TabGridPanelProperties.HEADER_TITLE, TAB1_TITLE);
// Mock that tab1 is now a single tab.
createTabGroup(new ArrayList<>(Arrays.asList(mTab1)), TAB1_ID);
// Mock that we have a modified group title before dialog is hidden.
TextWatcher textWatcher = mModel.get(TabGridPanelProperties.TITLE_TEXT_WATCHER);
View.OnFocusChangeListener onFocusChangeListener =
mModel.get(TabGridPanelProperties.TITLE_TEXT_ON_FOCUS_LISTENER);
onFocusChangeListener.onFocusChange(mTitleTextView, true);
textWatcher.afterTextChanged(mEditable);
assertThat(mMediator.getCurrentGroupModifiedTitleForTesting(),
equalTo(CUSTOMIZED_DIALOG_TITLE));
mMediator.hideDialog(false);
// Skip storing dialog title when this group becomes a single tab.
verify(mTabGroupTitleEditor, never()).storeTabGroupTitle(anyInt(), anyString());
verify(mTabGroupTitleEditor, never()).updateTabGroupTitle(any(Tab.class), anyString());
assertThat(mModel.get(TabGridPanelProperties.HEADER_TITLE), equalTo(TAB1_TITLE));
}
@Test
@Features.EnableFeatures(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
public void hideDialog_withTabGroupContinuation() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mMediator.hideDialog(false);
verify(mTabSelectionEditorController).hide();
}
@Test
public void onReset_hideDialog() {
mModel.set(TabGridPanelProperties.IS_DIALOG_VISIBLE, true);
mMediator.onReset(null);
assertThat(mModel.get(TabGridPanelProperties.IS_DIALOG_VISIBLE), equalTo(false));
verify(mDialogController).postHiding();
}
@Test