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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/panels/old_base_panel_browser_test.h"
#include "chrome/browser/ui/panels/docked_panel_strip.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/test_panel_mouse_watcher.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/screen.h"
using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
using content::WebContents;
using extensions::Extension;
class OldPanelBrowserTest : public OldBasePanelBrowserTest {
public:
OldPanelBrowserTest() : OldBasePanelBrowserTest() {
}
protected:
// Helper function for debugging.
void PrintAllPanelBounds() {
const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
DLOG(WARNING) << "PanelBounds:";
for (size_t i = 0; i < panels.size(); ++i) {
DLOG(WARNING) << "#=" << i
<< ", ptr=" << panels[i]
<< ", x=" << panels[i]->GetBounds().x()
<< ", y=" << panels[i]->GetBounds().y()
<< ", width=" << panels[i]->GetBounds().width()
<< ", height" << panels[i]->GetBounds().height();
}
}
std::vector<gfx::Rect> GetAllPanelBounds() {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<gfx::Rect> bounds;
for (size_t i = 0; i < panels.size(); i++)
bounds.push_back(panels[i]->GetBounds());
return bounds;
}
std::vector<gfx::Rect> AddXDeltaToBounds(const std::vector<gfx::Rect>& bounds,
const std::vector<int>& delta_x) {
std::vector<gfx::Rect> new_bounds = bounds;
for (size_t i = 0; i < bounds.size(); ++i)
new_bounds[i].Offset(delta_x[i], 0);
return new_bounds;
}
std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<Panel::ExpansionState> expansion_states;
for (size_t i = 0; i < panels.size(); i++)
expansion_states.push_back(panels[i]->expansion_state());
return expansion_states;
}
std::vector<bool> GetAllPanelActiveStates() {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<bool> active_states;
for (size_t i = 0; i < panels.size(); i++)
active_states.push_back(panels[i]->IsActive());
return active_states;
}
std::vector<bool> ProduceExpectedActiveStates(
int expected_active_panel_index) {
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
std::vector<bool> active_states;
for (int i = 0; i < static_cast<int>(panels.size()); i++)
active_states.push_back(i == expected_active_panel_index);
return active_states;
}
void WaitForPanelActiveStates(const std::vector<bool>& old_states,
const std::vector<bool>& new_states) {
DCHECK(old_states.size() == new_states.size());
std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
for (size_t i = 0; i < old_states.size(); i++) {
if (old_states[i] != new_states[i]){
WaitForPanelActiveState(
panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE);
}
}
}
void TestMinimizeRestore() {
// This constant is used to generate a point 'sufficiently higher then
// top edge of the panel'. On some platforms (Mac) we extend hover area
// a bit above the minimized panel as well, so it takes significant
// distance to 'move mouse out' of the hover-sensitive area.
const int kFarEnoughFromHoverArea = 153;
PanelManager* panel_manager = PanelManager::GetInstance();
std::vector<Panel*> panels = panel_manager->panels();
std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds();
std::vector<gfx::Rect> expected_bounds = test_begin_bounds;
std::vector<Panel::ExpansionState> expected_expansion_states(
panels.size(), Panel::EXPANDED);
std::vector<NativePanelTesting*> native_panels_testing(panels.size());
for (size_t i = 0; i < panels.size(); ++i) {
native_panels_testing[i] = CreateNativePanelTesting(panels[i]);
}
// Verify titlebar click does not minimize.
for (size_t index = 0; index < panels.size(); ++index) {
// Press left mouse button. Verify nothing changed.
native_panels_testing[index]->PressLeftMouseButtonTitlebar(
panels[index]->GetBounds().origin());
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
// Release mouse button. Verify nothing changed.
native_panels_testing[index]->ReleaseMouseButtonTitlebar();
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
}
// Minimize all panels for next stage in test.
for (size_t index = 0; index < panels.size(); ++index) {
panels[index]->Minimize();
expected_bounds[index].set_height(panel::kMinimizedPanelHeight);
expected_bounds[index].set_y(
test_begin_bounds[index].y() +
test_begin_bounds[index].height() - panel::kMinimizedPanelHeight);
expected_expansion_states[index] = Panel::MINIMIZED;
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
}
// Setup bounds and expansion states for minimized and titlebar-only
// states.
std::vector<Panel::ExpansionState> titlebar_exposed_states(
panels.size(), Panel::TITLE_ONLY);
std::vector<gfx::Rect> minimized_bounds = expected_bounds;
std::vector<Panel::ExpansionState> minimized_states(
panels.size(), Panel::MINIMIZED);
std::vector<gfx::Rect> titlebar_exposed_bounds = test_begin_bounds;
for (size_t index = 0; index < panels.size(); ++index) {
titlebar_exposed_bounds[index].set_height(
panels[index]->native_panel()->TitleOnlyHeight());
titlebar_exposed_bounds[index].set_y(
test_begin_bounds[index].y() +
test_begin_bounds[index].height() -
panels[index]->native_panel()->TitleOnlyHeight());
}
// Test hover. All panels are currently in minimized state.
EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
for (size_t index = 0; index < panels.size(); ++index) {
// Hover mouse on minimized panel.
// Verify titlebar is exposed on all panels.
gfx::Point hover_point(panels[index]->GetBounds().origin());
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
// Hover mouse above the panel. Verify all panels are minimized.
hover_point.set_y(
panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
// Hover mouse below minimized panel.
// Verify titlebar is exposed on all panels.
hover_point.set_y(panels[index]->GetBounds().y() +
panels[index]->GetBounds().height() + 5);
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
// Hover below titlebar exposed panel. Verify nothing changed.
hover_point.set_y(panels[index]->GetBounds().y() +
panels[index]->GetBounds().height() + 6);
MoveMouse(hover_point);
EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds());
EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates());
// Hover mouse above panel. Verify all panels are minimized.
hover_point.set_y(
panels[index]->GetBounds().y() - kFarEnoughFromHoverArea);
MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point);
EXPECT_EQ(minimized_bounds, GetAllPanelBounds());
EXPECT_EQ(minimized_states, GetAllPanelExpansionStates());
}
// Test restore. All panels are currently in minimized state.
for (size_t index = 0; index < panels.size(); ++index) {
// Hover on the last panel. This is to test the case of clicking on the
// panel when it's in titlebar exposed state.
if (index == panels.size() - 1)
MoveMouse(minimized_bounds[index].origin());
// Click minimized or title bar exposed panel as the case may be.
// Verify panel is restored to its original size.
native_panels_testing[index]->PressLeftMouseButtonTitlebar(
panels[index]->GetBounds().origin());
native_panels_testing[index]->ReleaseMouseButtonTitlebar();
expected_bounds[index].set_height(
test_begin_bounds[index].height());
expected_bounds[index].set_y(test_begin_bounds[index].y());
expected_expansion_states[index] = Panel::EXPANDED;
EXPECT_EQ(expected_bounds, GetAllPanelBounds());
EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates());
// Hover again on the last panel which is now restored, to reset the
// titlebar exposed state.
if (index == panels.size() - 1)
MoveMouse(minimized_bounds[index].origin());
}
// The below could be separate tests, just adding a TODO here for tracking.
// TODO(prasadt): Add test for dragging when in titlebar exposed state.
// TODO(prasadt): Add test in presence of auto hiding task bar.
for (size_t i = 0; i < panels.size(); ++i)
delete native_panels_testing[i];
}
};
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, CheckDockedPanelProperties) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelStrip* docked_strip = panel_manager->docked_strip();
// Create 3 docked panels that are in expanded, title-only or minimized states
// respectively.
Panel* panel1 = CreatePanelWithBounds("1", gfx::Rect(0, 0, 100, 100));
Panel* panel2 = CreatePanelWithBounds("2", gfx::Rect(0, 0, 100, 100));
panel2->SetExpansionState(Panel::TITLE_ONLY);
WaitForExpansionStateChanged(panel2, Panel::TITLE_ONLY);
Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100));
panel3->SetExpansionState(Panel::MINIMIZED);
WaitForExpansionStateChanged(panel3, Panel::MINIMIZED);
scoped_ptr<NativePanelTesting> panel1_testing(
CreateNativePanelTesting(panel1));
scoped_ptr<NativePanelTesting> panel2_testing(
CreateNativePanelTesting(panel2));
scoped_ptr<NativePanelTesting> panel3_testing(
CreateNativePanelTesting(panel3));
// Ensure that the layout message can get a chance to be processed so that
// the button visibility can be updated.
MessageLoop::current()->RunAllPending();
EXPECT_EQ(3, panel_manager->num_panels());
EXPECT_TRUE(docked_strip->HasPanel(panel1));
EXPECT_TRUE(docked_strip->HasPanel(panel2));
EXPECT_TRUE(docked_strip->HasPanel(panel3));
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
EXPECT_TRUE(panel1->always_on_top());
EXPECT_TRUE(panel2->always_on_top());
EXPECT_TRUE(panel3->always_on_top());
EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON));
EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON));
EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON));
EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON));
EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON));
EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON));
EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM,
panel1->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel1->attention_mode());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel2->attention_mode());
EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode());
panel_manager->CloseAll();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, CreatePanel) {
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
Panel* panel = CreatePanel("PanelTest");
EXPECT_EQ(1, panel_manager->num_panels());
gfx::Rect bounds = panel->GetBounds();
EXPECT_GT(bounds.x(), 0);
EXPECT_GT(bounds.y(), 0);
EXPECT_GT(bounds.width(), 0);
EXPECT_GT(bounds.height(), 0);
EXPECT_EQ(bounds.right(),
panel_manager->docked_strip()->StartingRightPosition());
CloseWindowAndWait(panel);
EXPECT_EQ(0, panel_manager->num_panels());
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, CreateBigPanel) {
gfx::Rect work_area = PanelManager::GetInstance()->
display_settings_provider()->GetDisplayArea();
Panel* panel = CreatePanelWithBounds("BigPanel", work_area);
gfx::Rect bounds = panel->GetBounds();
EXPECT_EQ(panel->max_size().width(), bounds.width());
EXPECT_LT(bounds.width(), work_area.width());
EXPECT_EQ(panel->max_size().height(), bounds.height());
EXPECT_LT(bounds.height(), work_area.height());
panel->Close();
}
// Flaky: http://crbug.com/105445
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, DISABLED_AutoResize) {
PanelManager* panel_manager = PanelManager::GetInstance();
panel_manager->enable_auto_sizing(true);
// Bigger space is needed by this test.
SetTestingAreas(gfx::Rect(0, 0, 1200, 900), gfx::Rect());
// Create a test panel with tab contents loaded.
CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
FilePath(kTestDir),
FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
// Expand the test page.
gfx::Rect initial_bounds = panel->GetBounds();
ui_test_utils::WindowedNotificationObserver enlarge(
chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
content::Source<Panel>(panel));
EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
panel->GetWebContents()->GetRenderViewHost(),
std::wstring(),
L"changeSize(50);"));
enlarge.Wait();
gfx::Rect bounds_on_grow = panel->GetBounds();
EXPECT_GT(bounds_on_grow.width(), initial_bounds.width());
EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height());
// Shrink the test page.
ui_test_utils::WindowedNotificationObserver shrink(
chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
content::Source<Panel>(panel));
EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
panel->GetWebContents()->GetRenderViewHost(),
std::wstring(),
L"changeSize(-30);"));
shrink.Wait();
gfx::Rect bounds_on_shrink = panel->GetBounds();
EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width());
EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width());
EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height());
// Verify resizing turns off auto-resizing and that it works.
gfx::Rect previous_bounds = panel->GetBounds();
// These should be identical because the panel is expanded.
EXPECT_EQ(previous_bounds.size(), panel->GetRestoredBounds().size());
gfx::Size new_size(previous_bounds.size());
new_size.Enlarge(5, 5);
gfx::Rect new_bounds(previous_bounds.origin(), new_size);
panel->SetBounds(new_bounds);
EXPECT_FALSE(panel->auto_resizable());
EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
// Turn back on auto-resize and verify that it works.
ui_test_utils::WindowedNotificationObserver auto_resize_enabled(
chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
content::Source<Panel>(panel));
panel->SetAutoResizable(true);
auto_resize_enabled.Wait();
gfx::Rect bounds_auto_resize_enabled = panel->GetBounds();
EXPECT_EQ(bounds_on_shrink.width(), bounds_auto_resize_enabled.width());
EXPECT_EQ(bounds_on_shrink.height(), bounds_auto_resize_enabled.height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, ResizePanel) {
PanelManager* panel_manager = PanelManager::GetInstance();
panel_manager->enable_auto_sizing(true);
Panel* panel = CreatePanel("TestPanel");
EXPECT_TRUE(panel->auto_resizable());
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
// Verify resizing turns off auto-resizing and that it works.
gfx::Rect original_bounds = panel->GetBounds();
// These should be identical because the panel is expanded.
EXPECT_EQ(original_bounds.size(), panel->GetRestoredBounds().size());
gfx::Size new_size(original_bounds.size());
new_size.Enlarge(5, 5);
gfx::Rect new_bounds(original_bounds.origin(), new_size);
panel->SetBounds(new_bounds);
EXPECT_FALSE(panel->auto_resizable());
EXPECT_EQ(new_bounds.size(), panel->GetBounds().size());
EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
// Verify current height unaffected when panel is not expanded.
panel->SetExpansionState(Panel::MINIMIZED);
int original_height = panel->GetBounds().height();
new_size.Enlarge(5, 5);
new_bounds.set_size(new_size);
panel->SetBounds(new_bounds);
EXPECT_EQ(new_bounds.size().width(), panel->GetBounds().width());
EXPECT_EQ(original_height, panel->GetBounds().height());
EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, AnimateBounds) {
Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
// Set bounds with animation.
gfx::Rect bounds = gfx::Rect(10, 20, 150, 160);
panel->SetPanelBounds(bounds);
EXPECT_TRUE(panel_testing->IsAnimatingBounds());
WaitForBoundsAnimationFinished(panel);
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
EXPECT_EQ(bounds, panel->GetBounds());
// Set bounds without animation.
bounds = gfx::Rect(30, 40, 200, 220);
panel->SetPanelBoundsInstantly(bounds);
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
EXPECT_EQ(bounds, panel->GetBounds());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, RestoredBounds) {
// Disable mouse watcher. We don't care about mouse movements in this test.
PanelManager* panel_manager = PanelManager::GetInstance();
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
panel_manager->SetMouseWatcherForTesting(mouse_watcher);
Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
panel->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
gfx::Rect bounds = panel->GetBounds();
gfx::Rect restored = panel->GetRestoredBounds();
EXPECT_EQ(bounds.x(), restored.x());
EXPECT_GT(bounds.y(), restored.y());
EXPECT_EQ(bounds.width(), restored.width());
EXPECT_LT(bounds.height(), restored.height());
panel->SetExpansionState(Panel::TITLE_ONLY);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
bounds = panel->GetBounds();
restored = panel->GetRestoredBounds();
EXPECT_EQ(bounds.x(), restored.x());
EXPECT_GT(bounds.y(), restored.y());
EXPECT_EQ(bounds.width(), restored.width());
EXPECT_LT(bounds.height(), restored.height());
panel->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
bounds = panel->GetBounds();
restored = panel->GetRestoredBounds();
EXPECT_EQ(bounds.x(), restored.x());
EXPECT_GT(bounds.y(), restored.y());
EXPECT_EQ(bounds.width(), restored.width());
EXPECT_LT(bounds.height(), restored.height());
panel->SetExpansionState(Panel::EXPANDED);
EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds());
// Verify that changing the panel bounds does not affect the restored height.
int saved_restored_height = restored.height();
panel->SetExpansionState(Panel::MINIMIZED);
bounds = gfx::Rect(10, 20, 300, 400);
panel->SetPanelBounds(bounds);
EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
panel->SetExpansionState(Panel::TITLE_ONLY);
bounds = gfx::Rect(20, 30, 100, 200);
panel->SetPanelBounds(bounds);
EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
panel->SetExpansionState(Panel::EXPANDED);
bounds = gfx::Rect(40, 60, 300, 400);
panel->SetPanelBounds(bounds);
EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height());
panel->set_full_size(bounds.size());
EXPECT_NE(saved_restored_height, panel->GetRestoredBounds().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MinimizeRestore) {
// We'll simulate mouse movements for test.
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
// Test with one panel.
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MinimizeRestoreTwoPanels) {
// We'll simulate mouse movements for test.
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
// Test with two panels.
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MinimizeRestoreThreePanels) {
// We'll simulate mouse movements for test.
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
// Test with three panels.
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110));
CreatePanelWithBounds("PanelTest3", gfx::Rect(0, 0, 120, 120));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MinimizeRestoreButtonClick) {
// Test with three panels.
Panel* panel1 = CreatePanel("PanelTest1");
Panel* panel2 = CreatePanel("PanelTest2");
Panel* panel3 = CreatePanel("PanelTest3");
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Click restore button on an expanded panel. Expect no change.
panel1->OnRestoreButtonClicked(panel::NO_MODIFIER);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Click minimize button on an expanded panel. Only that panel will minimize.
panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Click minimize button on a minimized panel. Expect no change.
panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Minimize all panels by clicking minimize button on an expanded panel
// with the apply-all modifier.
panel2->OnMinimizeButtonClicked(panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
// Click restore button on a minimized panel. Only that panel will restore.
panel2->OnRestoreButtonClicked(panel::NO_MODIFIER);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
// Restore all panels by clicking restore button on a minimized panel.
panel3->OnRestoreButtonClicked(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, RestoreAllWithTitlebarClick) {
// We'll simulate mouse movements for test.
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
// Test with three panels.
Panel* panel1 = CreatePanel("PanelTest1");
Panel* panel2 = CreatePanel("PanelTest2");
Panel* panel3 = CreatePanel("PanelTest3");
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
scoped_ptr<NativePanelTesting> test_panel1(
CreateNativePanelTesting(panel1));
scoped_ptr<NativePanelTesting> test_panel2(
CreateNativePanelTesting(panel2));
scoped_ptr<NativePanelTesting> test_panel3(
CreateNativePanelTesting(panel3));
// Click on an expanded panel's titlebar using the apply-all modifier.
// Verify expansion state is unchanged.
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Click on a minimized panel's titlebar using the apply-all modifier.
panel1->Minimize();
panel2->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
// Nothing changes until mouse is released.
test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
// Verify all panels restored when mouse is released.
test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Minimize a single panel. Then click on expanded panel with apply-all
// modifier. Verify nothing changes.
panel1->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Minimize another panel. Then click on a minimized panel with apply-all
// modifier to restore all panels.
panel2->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Click on the single minimized panel. Verify all are restored.
panel1->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Click on the single expanded panel. Verify nothing changes.
panel1->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
// Hover over a minimized panel and click on the titlebar while it is in
// title-only mode. Should restore all panels.
panel2->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
MoveMouseAndWaitForExpansionStateChange(panel2, panel2->GetBounds().origin());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state());
test_panel3->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel3->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
// Draw attention to a minimized panel. Click on a minimized panel that is
// not drawing attention. Verify restore all applies without affecting
// draw attention.
panel1->Minimize();
panel2->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
test_panel2->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
EXPECT_TRUE(panel1->IsDrawingAttention());
// Restore all panels by clicking on the minimized panel that is drawing
// attention. Verify restore all applies and clears draw attention.
panel1->Minimize();
panel2->Minimize();
panel3->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
EXPECT_TRUE(panel2->IsMinimized());
EXPECT_TRUE(panel3->IsMinimized());
test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(),
panel::APPLY_TO_ALL);
test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_FALSE(panel2->IsMinimized());
EXPECT_FALSE(panel3->IsMinimized());
EXPECT_FALSE(panel1->IsDrawingAttention());
PanelManager::GetInstance()->CloseAll();
}
#if defined(OS_MACOSX)
// This test doesn't pass on Snow Leopard (10.6), although it works just
// fine on Lion (10.7). The problem is not having a real run loop around
// the window close is at fault, given how window controllers in Chrome
// autorelease themselves on a -performSelector:withObject:afterDelay:
#define MAYBE_ActivatePanelOrTabbedWindow DISABLED_ActivatePanelOrTabbedWindow
#else
#define MAYBE_ActivatePanelOrTabbedWindow ActivatePanelOrTabbedWindow
#endif
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MAYBE_ActivatePanelOrTabbedWindow) {
CreatePanelParams params1("Panel1", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel1 = CreatePanelWithParams(params1);
CreatePanelParams params2("Panel2", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel2 = CreatePanelWithParams(params2);
// Need tab contents in order to trigger deactivation upon close.
CreateTestTabContents(panel2->browser());
ASSERT_FALSE(panel1->IsActive());
ASSERT_TRUE(panel2->IsActive());
// Activate main tabbed window.
browser()->window()->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
// Activate a panel.
panel2->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
// Activate the main tabbed window back.
browser()->window()->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
// Close the main tabbed window. That should move focus back to panel.
chrome::CloseWindow(browser());
WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
// Activate another panel.
panel1->Activate();
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
// Switch focus between panels.
panel2->Activate();
WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
// Close active panel, focus should move to the remaining one.
CloseWindowAndWait(panel2);
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
panel1->Close();
}
// TODO(jianli): To be enabled for other platforms.
#if defined(OS_WIN)
#define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
#else
#define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
#endif
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
// Create an active panel.
Panel* panel = CreatePanel("PanelTest");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
EXPECT_TRUE(panel->IsActive());
EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
// Deactivate the panel.
panel->Deactivate();
WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
EXPECT_FALSE(panel->IsActive());
EXPECT_TRUE(native_panel_testing->VerifyActiveState(false));
// Reactivate the panel.
panel->Activate();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_TRUE(panel->IsActive());
EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
}
// TODO(jianli): To be enabled for other platforms.
#if defined(OS_WIN)
#define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple
#else
#define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple
#endif
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MAYBE_ActivateDeactivateMultiple) {
BrowserWindow* tabbed_window = browser()->window();
// Create 4 panels in the following screen layout:
// P3 P2 P1 P0
const int kNumPanels = 4;
for (int i = 0; i < kNumPanels; ++i)
CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100));
const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels();
std::vector<bool> expected_active_states;
std::vector<bool> last_active_states;
// The last created panel, P3, should be active.
expected_active_states = ProduceExpectedActiveStates(3);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_FALSE(tabbed_window->IsActive());
// Activating P1 should cause P3 to lose focus.
panels[1]->Activate();
last_active_states = expected_active_states;
expected_active_states = ProduceExpectedActiveStates(1);
WaitForPanelActiveStates(last_active_states, expected_active_states);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
// Minimizing inactive panel P2 should not affect other panels' active states.
panels[2]->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_FALSE(tabbed_window->IsActive());
// Minimizing active panel P1 should activate last active panel P3.
panels[1]->SetExpansionState(Panel::MINIMIZED);
last_active_states = expected_active_states;
expected_active_states = ProduceExpectedActiveStates(3);
WaitForPanelActiveStates(last_active_states, expected_active_states);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_FALSE(tabbed_window->IsActive());
// Minimizing active panel P3 should activate last active panel P0.
panels[3]->SetExpansionState(Panel::MINIMIZED);
last_active_states = expected_active_states;
expected_active_states = ProduceExpectedActiveStates(0);
WaitForPanelActiveStates(last_active_states, expected_active_states);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_FALSE(tabbed_window->IsActive());
// Minimizing active panel P0 should activate last active tabbed window.
panels[0]->SetExpansionState(Panel::MINIMIZED);
last_active_states = expected_active_states;
expected_active_states = ProduceExpectedActiveStates(-1); // -1 means none.
WaitForPanelActiveStates(last_active_states, expected_active_states);
EXPECT_EQ(expected_active_states, GetAllPanelActiveStates());
EXPECT_TRUE(tabbed_window->IsActive());
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, DrawAttentionBasic) {
CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
// Test that the attention is drawn when the expanded panel is not in focus.
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_FALSE(panel->IsActive());
EXPECT_FALSE(panel->IsDrawingAttention());
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Stop drawing attention.
panel->FlashFrame(false);
EXPECT_FALSE(panel->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
// Draw attention, then minimize. Titlebar should remain visible.
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
panel->Minimize();
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
// Stop drawing attention. Titlebar should no longer be visible.
panel->FlashFrame(false);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, DrawAttentionWhileMinimized) {
// We'll simulate mouse movements for test.
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
// Create 3 panels so we end up with an inactive panel that can
// be made to draw attention.
Panel* panel = CreatePanel("test panel1");
Panel* panel2 = CreatePanel("test panel2");
Panel* panel3 = CreatePanel("test panel3");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
// Test that the attention is drawn and the title-bar is brought up when the
// minimized panel is drawing attention.
panel->Minimize();
WaitForExpansionStateChanged(panel, Panel::MINIMIZED);
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Test that we cannot bring up other minimized panel if the mouse is over
// the panel that draws attension.
panel2->Minimize();
gfx::Point hover_point(panel->GetBounds().origin());
MoveMouse(hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
// Test that we cannot bring down the panel that is drawing the attention.
hover_point.set_y(hover_point.y() - 200);
MoveMouse(hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
// Test that the attention is cleared when activated.
panel->Activate();
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
panel2->Close();
panel3->Close();
}
// Verify that minimized state of a panel is correct after draw attention
// is stopped when there are other minimized panels.
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
StopDrawingAttentionWhileMinimized) {
// We'll simulate mouse movements for test.
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
Panel* panel1 = CreatePanel("panel1");
Panel* panel2 = CreatePanel("panel2");
panel1->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel2->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
// Verify panel returns to minimized state when no longer drawing attention.
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
panel1->FlashFrame(false);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
// Hover over other minimized panel to bring up titlebars.
gfx::Point hover_point(panel2->GetBounds().origin());
MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
// Verify panel keeps titlebar visible when no longer drawing attention
// if titlebars are up.
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
panel1->FlashFrame(false);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
// Move mouse away. All panels should return to minimized state.
hover_point.set_y(hover_point.y() - 200);
MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
// Verify minimized panel that is drawing attention stays in title-only mode
// after attention is cleared if mouse is in the titlebar area.
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
gfx::Point hover_point_in_panel(panel1->GetBounds().origin());
MoveMouse(hover_point_in_panel);
panel1->FlashFrame(false);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
// Move mouse away and panel should go back to fully minimized state.
MoveMouseAndWaitForExpansionStateChange(panel1, hover_point);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
panel1->Close();
panel2->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, DrawAttentionWhenActive) {
CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
// Test that the attention should not be drawn if the expanded panel is in
// focus.
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_TRUE(panel->IsActive());
EXPECT_FALSE(panel->IsDrawingAttention());
panel->FlashFrame(true);
EXPECT_FALSE(panel->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, DrawAttentionResetOnActivate) {
// Create 2 panels so we end up with an inactive panel that can
// be made to draw attention.
Panel* panel = CreatePanel("test panel1");
Panel* panel2 = CreatePanel("test panel2");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Test that the attention is cleared when panel gets focus.
panel->Activate();
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
panel2->Close();
}
// http://crbug.com/133461
#if defined(OS_LINUX)
#define MAYBE_DrawAttentionMinimizedNotResetOnActivate DISABLED_DrawAttentionMinimizedNotResetOnActivate
#else
#define MAYBE_DrawAttentionMinimizedNotResetOnActivate DrawAttentionMinimizedNotResetOnActivate
#endif
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
MAYBE_DrawAttentionMinimizedNotResetOnActivate) {
// Create 2 panels so we end up with an inactive panel that can
// be made to draw attention.
Panel* panel1 = CreatePanel("test panel1");
Panel* panel2 = CreatePanel("test panel2");
panel1->Minimize();
EXPECT_TRUE(panel1->IsMinimized());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
// Simulate panel being activated while minimized. Cannot call
// Activate() as that expands the panel.
panel1->OnActiveStateChanged(true);
EXPECT_TRUE(panel1->IsDrawingAttention()); // Unchanged.
// Unminimize panel to show that attention would have been cleared
// if panel had not been minimized.
panel1->Restore();
EXPECT_FALSE(panel1->IsMinimized());
EXPECT_TRUE(panel1->IsDrawingAttention()); // Unchanged.
panel1->OnActiveStateChanged(true);
EXPECT_FALSE(panel1->IsDrawingAttention()); // Attention cleared.
panel1->Close();
panel2->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, DrawAttentionResetOnClick) {
CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Test that the attention is cleared when panel gets focus.
native_panel_testing->PressLeftMouseButtonTitlebar(
panel->GetBounds().origin());
native_panel_testing->ReleaseMouseButtonTitlebar();
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
MinimizeImmediatelyAfterRestore) {
CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->Minimize(); // this should deactivate.
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Restore();
MessageLoop::current()->RunAllPending();
WaitForExpansionStateChanged(panel, Panel::EXPANDED);
// Verify that minimizing a panel right after expansion works.
panel->Minimize();
MessageLoop::current()->RunAllPending();
WaitForExpansionStateChanged(panel, Panel::MINIMIZED);
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, FocusLostOnMinimize) {
CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
panel->SetExpansionState(Panel::MINIMIZED);
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
panel->Close();
}
// http://crbug.com/133364
#if defined(OS_LINUX)
#define MAYBE_CreateInactiveSwitchToActive DISABLED_CreateInactiveSwitchToActive
#else
#define MAYBE_CreateInactiveSwitchToActive CreateInactiveSwitchToActive
#endif
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, MAYBE_CreateInactiveSwitchToActive) {
// Compiz will not activate initially inactive window.
if (SkipTestIfCompizWM())
return;
CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
Panel* panel = CreatePanelWithParams(params);
panel->Activate();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
panel->Close();
}
// TODO(dimich): try/enable on other platforms. See bug 103253 for details on
// why this is disabled on windows.
#if defined(OS_MACOSX)
#define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
MinimizeTwoPanelsWithoutTabbedWindow
#else
#define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \
DISABLED_MinimizeTwoPanelsWithoutTabbedWindow
#endif
// When there are 2 panels and no chrome window, minimizing one panel does
// not expand/focuses another.
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) {
CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
Panel* panel1 = CreatePanelWithParams(params);
Panel* panel2 = CreatePanelWithParams(params);
// Close main tabbed window.
ui_test_utils::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser()));
chrome::CloseWindow(browser());
signal.Wait();
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
panel1->Activate();
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
panel1->SetExpansionState(Panel::MINIMIZED);
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel2->SetExpansionState(Panel::MINIMIZED);
MessageLoop::current()->RunAllPending();
WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
// Verify that panel1 is still minimized and not active.
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
// Another check for the same.
EXPECT_FALSE(panel1->IsActive());
EXPECT_FALSE(panel2->IsActive());
panel1->Close();
panel2->Close();
}
// http://crbug.com/133367
#if defined(OS_LINUX) || defined(OS_WIN)
#define MAYBE_NonExtensionDomainPanelsCloseOnUninstall DISABLED_NonExtensionDomainPanelsCloseOnUninstall
#else
#define MAYBE_NonExtensionDomainPanelsCloseOnUninstall NonExtensionDomainPanelsCloseOnUninstall
#endif
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
MAYBE_NonExtensionDomainPanelsCloseOnUninstall) {
// Create a test extension.
DictionaryValue empty_value;
scoped_refptr<Extension> extension =
CreateExtension(FILE_PATH_LITERAL("TestExtension"),
Extension::INVALID, empty_value);
std::string extension_app_name =
web_app::GenerateApplicationNameFromExtensionId(extension->id());
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels());
// Create a panel with the extension as host.
CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE);
std::string extension_domain_url(chrome::kExtensionScheme);
extension_domain_url += "://";
extension_domain_url += extension->id();
extension_domain_url += "/hello.html";
params.url = GURL(extension_domain_url);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
// Create a panel with a non-extension host.
CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE);
params1.url = GURL(chrome::kAboutBlankURL);
Panel* panel1 = CreatePanelWithParams(params1);
EXPECT_EQ(2, panel_manager->num_panels());
// Create another extension and a panel from that extension.
scoped_refptr<Extension> extension_other =
CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"),
Extension::INVALID, empty_value);
std::string extension_app_name_other =
web_app::GenerateApplicationNameFromExtensionId(extension_other->id());
Panel* panel_other = CreatePanel(extension_app_name_other);
ui_test_utils::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
ui_test_utils::WindowedNotificationObserver signal1(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel1));
// Send unload notification on the first extension.
extensions::UnloadedExtensionInfo details(extension,
extension_misc::UNLOAD_REASON_UNINSTALL);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(browser()->profile()),
content::Details<extensions::UnloadedExtensionInfo>(&details));
// Wait for the panels opened by the first extension to close.
signal.Wait();
signal1.Wait();
// Verify that the panel that's left is the panel from the second extension.
EXPECT_EQ(panel_other, panel_manager->panels()[0]);
panel_other->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, OnBeforeUnloadOnClose) {
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
const string16 title_first_close = UTF8ToUTF16("TitleFirstClose");
const string16 title_second_close = UTF8ToUTF16("TitleSecondClose");
// Create a test panel with tab contents loaded.
CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300),
SHOW_AS_ACTIVE);
params.url = ui_test_utils::GetTestUrl(
FilePath(kTestDir),
FilePath(FILE_PATH_LITERAL("onbeforeunload.html")));
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
WebContents* web_contents = panel->GetWebContents();
// Close panel and respond to the onbeforeunload dialog with cancel. This is
// equivalent to clicking "Stay on this page"
scoped_ptr<ui_test_utils::TitleWatcher> title_watcher(
new ui_test_utils::TitleWatcher(web_contents, title_first_close));
panel->Close();
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
alert->native_dialog()->CancelAppModalDialog();
EXPECT_EQ(title_first_close, title_watcher->WaitAndGetTitle());
EXPECT_EQ(1, panel_manager->num_panels());
// Close panel and respond to the onbeforeunload dialog with close. This is
// equivalent to clicking the OS close button on the dialog.
title_watcher.reset(
new ui_test_utils::TitleWatcher(web_contents, title_second_close));
panel->Close();
alert = ui_test_utils::WaitForAppModalDialog();
alert->native_dialog()->CloseAppModalDialog();
EXPECT_EQ(title_second_close, title_watcher->WaitAndGetTitle());
EXPECT_EQ(1, panel_manager->num_panels());
// Close panel and respond to the onbeforeunload dialog with accept. This is
// equivalent to clicking "Leave this page".
ui_test_utils::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
panel->Close();
alert = ui_test_utils::WaitForAppModalDialog();
alert->native_dialog()->AcceptAppModalDialog();
signal.Wait();
EXPECT_EQ(0, panel_manager->num_panels());
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, SizeClamping) {
// Using '0' sizes is equivalent of not providing sizes in API and causes
// minimum sizes to be applied to facilitate auto-sizing.
CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width());
EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height());
int reasonable_width = panel->min_size().width() + 10;
int reasonable_height = panel->min_size().height() + 20;
panel->Close();
// Using reasonable actual sizes should avoid clamping.
CreatePanelParams params1("Panel1",
gfx::Rect(0, 0,
reasonable_width, reasonable_height),
SHOW_AS_ACTIVE);
panel = CreatePanelWithParams(params1);
EXPECT_EQ(reasonable_width, panel->GetBounds().width());
EXPECT_EQ(reasonable_height, panel->GetBounds().height());
panel->Close();
// Using just one size should auto-compute some reasonable other size.
int given_height = 200;
CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height),
SHOW_AS_ACTIVE);
panel = CreatePanelWithParams(params2);
EXPECT_GT(panel->GetBounds().width(), 0);
EXPECT_EQ(given_height, panel->GetBounds().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest, TightAutosizeAroundSingleLine) {
PanelManager::GetInstance()->enable_auto_sizing(true);
// Using 0 sizes triggers auto-sizing.
CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE);
params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>");
Panel* panel = CreatePanelWithParams(params);
int initial_width = panel->GetBounds().width();
int initial_height = panel->GetBounds().height();
// Inject some HTML content into the panel.
ui_test_utils::WindowedNotificationObserver enlarge(
chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED,
content::Source<Panel>(panel));
EXPECT_TRUE(ui_test_utils::ExecuteJavaScript(
panel->GetWebContents()->GetRenderViewHost(),
std::wstring(),
L"document.body.innerHTML ="
L"'<nobr>line of text and a <button>Button</button>';"));
enlarge.Wait();
// The panel should have become larger in both dimensions (the minimums
// has to be set to be smaller then a simple 1-line content, so the autosize
// can work correctly.
EXPECT_GT(panel->GetBounds().width(), initial_width);
EXPECT_GT(panel->GetBounds().height(), initial_height);
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
DefaultMaxSizeOnDisplaySettingsChange) {
Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220));
gfx::Size old_max_size = panel->max_size();
gfx::Size old_full_size = panel->full_size();
// Shrink the work area. Expect max size and full size become smaller.
gfx::Size smaller_work_area_size = gfx::Size(500, 300);
SetTestingAreas(gfx::Rect(gfx::Point(0, 0), smaller_work_area_size),
gfx::Rect());
EXPECT_GT(old_max_size.width(), panel->max_size().width());
EXPECT_GT(old_max_size.height(), panel->max_size().height());
EXPECT_GT(smaller_work_area_size.width(), panel->max_size().width());
EXPECT_GT(smaller_work_area_size.height(), panel->max_size().height());
EXPECT_GT(old_full_size.width(), panel->full_size().width());
EXPECT_GT(old_full_size.height(), panel->full_size().height());
EXPECT_GE(panel->max_size().width(), panel->full_size().width());
EXPECT_GE(panel->max_size().height(), panel->full_size().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(OldPanelBrowserTest,
CustomMaxSizeOnDisplaySettingsChange) {
PanelManager* panel_manager = PanelManager::GetInstance();
Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220));
// Trigger custom max size by user resizing.
gfx::Size bigger_size = gfx::Size(550, 400);
gfx::Point mouse_location = panel->GetBounds().origin();
panel_manager->StartResizingByMouse(panel,
mouse_location,
panel::RESIZE_TOP_LEFT);
mouse_location.Offset(panel->GetBounds().width() - bigger_size.width(),
panel->GetBounds().height() - bigger_size.height());
panel_manager->ResizeByMouse(mouse_location);
panel_manager->EndResizingByMouse(false);
gfx::Size old_max_size = panel->max_size();
EXPECT_EQ(bigger_size, old_max_size);
gfx::Size old_full_size = panel->full_size();
EXPECT_EQ(bigger_size, old_full_size);
// Shrink the work area. Expect max size and full size become smaller.
gfx::Size smaller_work_area_size = gfx::Size(500, 300);
SetTestingAreas(gfx::Rect(gfx::Point(0, 0), smaller_work_area_size),
gfx::Rect());
EXPECT_GT(old_max_size.width(), panel->max_size().width());
EXPECT_GT(old_max_size.height(), panel->max_size().height());
EXPECT_GE(smaller_work_area_size.width(), panel->max_size().width());
EXPECT_EQ(smaller_work_area_size.height(), panel->max_size().height());
EXPECT_GT(old_full_size.width(), panel->full_size().width());
EXPECT_GT(old_full_size.height(), panel->full_size().height());
EXPECT_GE(panel->max_size().width(), panel->full_size().width());
EXPECT_GE(panel->max_size().height(), panel->full_size().height());
EXPECT_EQ(smaller_work_area_size.height(), panel->full_size().height());
panel->Close();
}
|