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 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
|
// 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/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/panels/base_panel_browser_test.h"
#include "chrome/browser/ui/panels/docked_panel_collection.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_active_state_observer.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/app_modal/app_modal_dialog.h"
#include "components/app_modal/native_app_modal_dialog.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "net/base/net_util.h"
#include "net/test/url_request/url_request_mock_http_job.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/hit_test.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/screen.h"
using content::WebContents;
class PanelBrowserTest : public BasePanelBrowserTest {
public:
PanelBrowserTest() : BasePanelBrowserTest() {
}
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(PanelBrowserTest, CheckDockedPanelProperties) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
// 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));
Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100));
panel2->SetExpansionState(Panel::TITLE_ONLY);
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
panel3->SetExpansionState(Panel::MINIMIZED);
EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
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.
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(3, panel_manager->num_panels());
EXPECT_TRUE(docked_collection->HasPanel(panel1));
EXPECT_TRUE(docked_collection->HasPanel(panel2));
EXPECT_TRUE(docked_collection->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->IsAlwaysOnTop());
EXPECT_TRUE(panel2->IsAlwaysOnTop());
EXPECT_TRUE(panel3->IsAlwaysOnTop());
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));
// Expanded panel cannot be resized at the bottom.
EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel1->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse());
EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse());
EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
EXPECT_EQ(panel::TOP_ROUNDED, panel3_testing->GetWindowCornerStyle());
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(PanelBrowserTest, 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_collection()->StartingRightPosition());
CloseWindowAndWait(panel);
EXPECT_EQ(0, panel_manager->num_panels());
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) {
gfx::Rect work_area = PanelManager::GetInstance()->
display_settings_provider()->GetPrimaryWorkArea();
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();
}
class WaitForStableInitialSize : public TestPanelNotificationObserver {
public:
explicit WaitForStableInitialSize(Panel* panel)
: TestPanelNotificationObserver(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources()),
panel_(panel) {}
~WaitForStableInitialSize() override {}
protected:
bool AtExpectedState() override {
return panel_->GetBounds().height() > panel_->TitleOnlyHeight();
}
Panel* panel_;
};
class WaitForAutoResizeWider : public TestPanelNotificationObserver {
public:
explicit WaitForAutoResizeWider(Panel* panel)
: TestPanelNotificationObserver(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources()),
panel_(panel),
initial_size_(panel->GetBounds().size()) {}
~WaitForAutoResizeWider() override {}
protected:
bool AtExpectedState() override {
return panel_->GetBounds().width() > initial_size_.width();
}
Panel* panel_;
gfx::Size initial_size_;
};
class WaitForAutoResizeNarrower : public TestPanelNotificationObserver {
public:
explicit WaitForAutoResizeNarrower(Panel* panel)
: TestPanelNotificationObserver(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources()),
panel_(panel),
initial_size_(panel->GetBounds().size()) {}
~WaitForAutoResizeNarrower() override {}
protected:
bool AtExpectedState() override {
return panel_->GetBounds().width() < initial_size_.width();
}
Panel* panel_;
gfx::Size initial_size_;
};
// crbug.com/160504
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) {
PanelManager* panel_manager = PanelManager::GetInstance();
panel_manager->enable_auto_sizing(true);
// Bigger space is needed by this test.
mock_display_settings_provider()->SetPrimaryDisplay(
gfx::Rect(0, 0, 1200, 900), gfx::Rect(0, 0, 1200, 900));
// Create a test panel with web contents loaded.
CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
// Ensure panel has auto resized to original web content size.
// The resize will update the docked panel collection.
WaitForStableInitialSize initial_resize(panel);
initial_resize.Wait();
gfx::Rect initial_bounds = panel->GetBounds();
// Expand the test page. The resize will update the docked panel collection.
WaitForAutoResizeWider enlarge(panel);
EXPECT_TRUE(content::ExecuteScript(
panel->GetWebContents(), "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. The resize will update the docked panel collection.
WaitForAutoResizeNarrower shrink(panel);
EXPECT_TRUE(content::ExecuteScript(
panel->GetWebContents(), "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 panel no longer auto-resizes.
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 panel auto resizes.
content::WindowedNotificationObserver auto_resize_enabled(
chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED,
content::NotificationService::AllSources());
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(PanelBrowserTest, 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(PanelBrowserTest, AnimateBounds) {
// Create a detached panel, instead of docked panel because it cannot be
// moved to any location.
Panel* panel = CreateDetachedPanel("1", gfx::Rect(200, 100, 100, 100));
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
// Validates that no animation should be triggered when the panel is being
// dragged.
gfx::Point mouse_location(panel->GetBounds().origin());
panel_testing->PressLeftMouseButtonTitlebar(mouse_location);
panel_testing->DragTitlebar(mouse_location + gfx::Vector2d(-100, 5));
EXPECT_FALSE(panel_testing->IsAnimatingBounds());
panel_testing->FinishDragTitlebar();
// 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(PanelBrowserTest, RestoredBounds) {
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(PanelBrowserTest, MinimizeRestore) {
// Test with one panel.
CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100));
TestMinimizeRestore();
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreTwoPanels) {
// 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(PanelBrowserTest, MinimizeRestoreThreePanels) {
// 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(PanelBrowserTest, 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());
}
// http://crbug.com/243891 flaky on Linux
#if defined(OS_LINUX)
#define MAYBE_RestoreAllWithTitlebarClick DISABLED_RestoreAllWithTitlebarClick
#else
#define MAYBE_RestoreAllWithTitlebarClick RestoreAllWithTitlebarClick
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_RestoreAllWithTitlebarClick) {
// 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(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());
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();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MinimizeRestoreOnAutoHidingDesktopBar) {
PanelManager* panel_manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = panel_manager->docked_collection();
int expected_bottom_on_expanded = docked_collection->work_area().bottom();
int expected_bottom_on_title_only = expected_bottom_on_expanded;
int expected_bottom_on_minimized = expected_bottom_on_expanded;
// Turn on auto-hiding.
static const int bottom_bar_thickness = 40;
mock_display_settings_provider()->EnableAutoHidingDesktopBar(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
true,
bottom_bar_thickness);
expected_bottom_on_title_only -= bottom_bar_thickness;
Panel* panel = CreatePanel("1");
int initial_height = panel->GetBounds().height();
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
panel->Minimize();
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
EXPECT_EQ(panel::kMinimizedPanelHeight, panel->GetBounds().height());
EXPECT_EQ(expected_bottom_on_minimized, panel->GetBounds().bottom());
panel->SetExpansionState(Panel::TITLE_ONLY);
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
EXPECT_EQ(panel::kTitlebarHeight, panel->GetBounds().height());
EXPECT_EQ(expected_bottom_on_title_only, panel->GetBounds().bottom());
panel->Restore();
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
EXPECT_EQ(initial_height, panel->GetBounds().height());
EXPECT_EQ(expected_bottom_on_expanded, panel->GetBounds().bottom());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ChangeAutoHideTaskBarThickness) {
PanelManager* manager = PanelManager::GetInstance();
DockedPanelCollection* docked_collection = manager->docked_collection();
int initial_starting_right_position =
docked_collection->StartingRightPosition();
int bottom_bar_thickness = 20;
int right_bar_thickness = 30;
mock_display_settings_provider()->EnableAutoHidingDesktopBar(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
true,
bottom_bar_thickness);
mock_display_settings_provider()->EnableAutoHidingDesktopBar(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
true,
right_bar_thickness);
EXPECT_EQ(initial_starting_right_position,
docked_collection->StartingRightPosition());
Panel* panel = CreatePanel("PanelTest");
panel->SetExpansionState(Panel::TITLE_ONLY);
WaitForBoundsAnimationFinished(panel);
EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
panel->GetBounds().bottom());
EXPECT_EQ(docked_collection->StartingRightPosition(),
panel->GetBounds().right());
initial_starting_right_position = docked_collection->StartingRightPosition();
int bottom_bar_thickness_delta = 10;
bottom_bar_thickness += bottom_bar_thickness_delta;
int right_bar_thickness_delta = 15;
right_bar_thickness += right_bar_thickness_delta;
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
bottom_bar_thickness);
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
right_bar_thickness);
base::MessageLoopForUI::current()->RunUntilIdle();
EXPECT_EQ(initial_starting_right_position,
docked_collection->StartingRightPosition());
EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
panel->GetBounds().bottom());
EXPECT_EQ(docked_collection->StartingRightPosition(),
panel->GetBounds().right());
initial_starting_right_position = docked_collection->StartingRightPosition();
bottom_bar_thickness_delta = 20;
bottom_bar_thickness -= bottom_bar_thickness_delta;
right_bar_thickness_delta = 10;
right_bar_thickness -= right_bar_thickness_delta;
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM,
bottom_bar_thickness);
mock_display_settings_provider()->SetDesktopBarThickness(
DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT,
right_bar_thickness);
base::MessageLoopForUI::current()->RunUntilIdle();
EXPECT_EQ(docked_collection->StartingRightPosition(),
initial_starting_right_position);
EXPECT_EQ(docked_collection->work_area().bottom() - bottom_bar_thickness,
panel->GetBounds().bottom());
EXPECT_EQ(docked_collection->StartingRightPosition(),
panel->GetBounds().right());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivatePanelOrTabbedWindow) {
if (!WmSupportWindowActivation()) {
LOG(WARNING) << "Skipping test due to WM problems.";
return;
}
Panel* panel1 = CreatePanel("Panel1");
Panel* panel2 = CreatePanel("Panel2");
// 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);
// 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);
PanelManager::GetInstance()->CloseAll();
}
// TODO(jianli): To be enabled for other platforms.
#if defined(OS_WIN) || defined(OS_LINUX)
#define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic
#else
#define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
if (!WmSupportWindowActivation()) {
LOG(WARNING) << "Skipping test due to WM problems.";
return;
}
// Create an active panel.
Panel* panel = CreatePanel("PanelTest");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); // doublecheck active state
EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
// Deactivate the panel.
panel->Deactivate();
WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
// On GTK there is no way to deactivate a window. So the Deactivate() call
// above does not actually deactivate the window, but simply lowers it.
#if !defined(OS_LINUX)
EXPECT_TRUE(native_panel_testing->VerifyActiveState(false));
#endif
// This test does not reactivate the panel because the panel might not be
// reactivated programmatically once it is deactivated.
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ActivateDeactivateMultiple) {
if (!WmSupportWindowActivation()) {
LOG(WARNING) << "Skipping test due to WM problems.";
return;
}
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());
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionBasic) {
Panel* panel = CreateInactivePanel("P1");
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());
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Stop drawing attention.
panel->FlashFrame(false);
EXPECT_FALSE(panel->IsDrawingAttention());
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(PanelBrowserTest, DrawAttentionWhileMinimized) {
Panel* panel1 = CreateInactivePanel("P1");
Panel* panel2 = CreateInactivePanel("P2");
scoped_ptr<NativePanelTesting> native_panel1_testing(
CreateNativePanelTesting(panel1));
// Test that the attention is drawn and the title-bar is brought up when the
// minimized panel is drawing attention.
panel1->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel1->FlashFrame(true);
EXPECT_TRUE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_TRUE(native_panel1_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(panel1->GetBounds().origin());
MoveMouse(hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->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, panel1->expansion_state());
// Test that the attention is cleared when activated.
panel1->Activate();
WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
EXPECT_FALSE(native_panel1_testing->VerifyDrawingAttention());
PanelManager::GetInstance()->CloseAll();
}
// 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(PanelBrowserTest, StopDrawingAttentionWhileMinimized) {
Panel* panel1 = CreateInactivePanel("P1");
Panel* panel2 = CreateInactivePanel("P2");
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());
// Typical user scenario will detect the mouse in the panel
// after attention is cleared, causing titles to pop up, so
// we simulate that here.
MoveMouseAndWaitForExpansionStateChange(panel2, hover_point_in_panel);
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state());
// Move mouse away and panels 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());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) {
// Create an active panel.
Panel* panel = CreatePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
// Test that the attention should not be drawn if the expanded panel is in
// focus.
panel->FlashFrame(true);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) {
Panel* panel = CreateInactivePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Test that the attention is cleared when panel gets focus.
panel->Activate();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
DrawAttentionMinimizedNotResetOnActivate) {
Panel* panel = CreateInactivePanel("P1");
panel->Minimize();
EXPECT_TRUE(panel->IsMinimized());
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
// Simulate panel being activated while minimized. Cannot call
// Activate() as that expands the panel.
panel->OnActiveStateChanged(true);
EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged.
// Unminimize panel to show that attention would have been cleared
// if panel had not been minimized.
panel->Restore();
EXPECT_FALSE(panel->IsMinimized());
EXPECT_TRUE(panel->IsDrawingAttention()); // Unchanged.
panel->OnActiveStateChanged(true);
EXPECT_FALSE(panel->IsDrawingAttention()); // Attention cleared.
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) {
Panel* panel = CreateInactivePanel("P1");
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
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();
WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
EXPECT_FALSE(panel->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
}
// http://crbug.com/175760; several panel tests failing regularly on mac.
#if defined(OS_MACOSX)
#define MAYBE_MinimizeImmediatelyAfterRestore \
DISABLED_MinimizeImmediatelyAfterRestore
#else
#define MAYBE_MinimizeImmediatelyAfterRestore MinimizeImmediatelyAfterRestore
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_MinimizeImmediatelyAfterRestore) {
CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
CreateNativePanelTesting(panel));
PanelActiveStateObserver signal(panel, false);
panel->Minimize(); // this should deactivate.
signal.Wait();
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Restore();
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
// Verify that minimizing a panel right after expansion works.
panel->Minimize();
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) {
CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
PanelActiveStateObserver signal(panel, false);
panel->Minimize();
signal.Wait();
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateInactiveSwitchToActive) {
Panel* panel = CreateInactivePanel("1");
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(PanelBrowserTest,
MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) {
CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE);
Panel* panel1 = CreatePanelWithParams(params);
Panel* panel2 = CreatePanelWithParams(params);
// Close main tabbed window.
content::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);
base::MessageLoop::current()->RunUntilIdle();
WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
panel2->SetExpansionState(Panel::MINIMIZED);
base::MessageLoop::current()->RunUntilIdle();
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();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
NonExtensionDomainPanelsCloseOnUninstall) {
// Create a test extension.
base::DictionaryValue empty_value;
scoped_refptr<extensions::Extension> extension =
CreateExtension(FILE_PATH_LITERAL("TestExtension"),
extensions::Manifest::INTERNAL, 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_ACTIVE);
std::string extension_domain_url(extensions::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_ACTIVE);
params1.url = GURL(url::kAboutBlankURL);
Panel* panel1 = CreatePanelWithParams(params1);
EXPECT_EQ(2, panel_manager->num_panels());
// Create another extension and a panel from that extension.
scoped_refptr<extensions::Extension> extension_other =
CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"),
extensions::Manifest::INTERNAL, empty_value);
std::string extension_app_name_other =
web_app::GenerateApplicationNameFromExtensionId(extension_other->id());
Panel* panel_other = CreatePanel(extension_app_name_other);
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
content::WindowedNotificationObserver signal1(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel1));
// Send unload notification on the first extension.
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(browser()->profile());
registry->RemoveEnabled(extension->id());
registry->TriggerOnUnloaded(
extension.get(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
// 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(PanelBrowserTest, OnBeforeUnloadOnClose) {
PanelManager* panel_manager = PanelManager::GetInstance();
EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially.
const base::string16 title_first_close = base::UTF8ToUTF16("TitleFirstClose");
const base::string16 title_second_close =
base::UTF8ToUTF16("TitleSecondClose");
// Create a test panel with web contents loaded.
CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300),
SHOW_AS_ACTIVE);
params.url = ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("onbeforeunload.html")));
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
// Close panel and verify it closes despite having a onbeforeunload handler.
CloseWindowAndWait(panel);
EXPECT_EQ(0, panel_manager->num_panels());
}
// http://crbug.com/175760; several panel tests failing regularly on mac.
#if defined(OS_MACOSX)
#define MAYBE_SizeClamping DISABLED_SizeClamping
#else
#define MAYBE_SizeClamping SizeClamping
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_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();
}
// http://crbug.com/175760; several panel tests failing regularly on mac.
// http://crbug.com/179890; TightAutosizeAroundSingleLine broken on Windows by
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
DISABLED_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);
// Ensure panel has auto resized to original web content size.
WaitForStableInitialSize initial_resize(panel);
initial_resize.Wait();
int initial_width = panel->GetBounds().width();
int initial_height = panel->GetBounds().height();
// Inject some HTML content into the panel.
WaitForAutoResizeWider enlarge(panel);
EXPECT_TRUE(content::ExecuteScript(
panel->GetWebContents(),
"document.body.innerHTML ="
" '<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();
}
// http://crbug.com/175760; several panel tests failing regularly on mac.
#if defined(OS_MACOSX)
#define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \
DISABLED_DefaultMaxSizeOnDisplaySettingsChange
#else
#define MAYBE_DefaultMaxSizeOnDisplaySettingsChange \
DefaultMaxSizeOnDisplaySettingsChange
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_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::Rect smaller_work_area(0, 0, 500, 300);
mock_display_settings_provider()->SetPrimaryDisplay(
smaller_work_area, smaller_work_area);
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.width(), panel->max_size().width());
EXPECT_GT(smaller_work_area.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();
}
// http://crbug.com/175760; several panel tests failing regularly on mac.
#if defined(OS_MACOSX)
#define MAYBE_CustomMaxSizeOnDisplaySettingsChange \
DISABLED_CustomMaxSizeOnDisplaySettingsChange
#else
#define MAYBE_CustomMaxSizeOnDisplaySettingsChange \
CustomMaxSizeOnDisplaySettingsChange
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MAYBE_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,
HTTOPLEFT);
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::Rect smaller_work_area(0, 0, 500, 300);
mock_display_settings_provider()->SetPrimaryDisplay(
smaller_work_area, smaller_work_area);
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.width(), panel->max_size().width());
EXPECT_EQ(smaller_work_area.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.height(), panel->full_size().height());
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevTools) {
// Create a test panel with web contents loaded.
CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
// Open devtools.
size_t num_browsers = 1;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS));
signal.Wait();
// Check that the new browser window that opened is dev tools window.
++num_browsers;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
if (*iter == browser())
continue;
ASSERT_TRUE((*iter)->is_devtools());
}
panel->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DevToolsConsole) {
// Create a test panel with web contents loaded.
CreatePanelParams params("1", gfx::Rect(0, 0, 200, 220), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
// Open devtools console.
size_t num_browsers = 1;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_WINDOW_READY,
content::NotificationService::AllSources());
EXPECT_TRUE(panel->ExecuteCommandIfEnabled(IDC_DEV_TOOLS_CONSOLE));
signal.Wait();
// Check that the new browser window that opened is dev tools window.
++num_browsers;
EXPECT_EQ(num_browsers, chrome::GetBrowserCount(
browser()->profile(),
browser()->host_desktop_type()));
for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) {
if (*iter == browser())
continue;
ASSERT_TRUE((*iter)->is_devtools());
}
panel->Close();
}
#if defined(OS_WIN)
#define MAYBE_Accelerator Accelerator
#else
#define MAYBE_Accelerator DISABLED_Accelerator
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) {
PanelManager* panel_manager = PanelManager::GetInstance();
// Create a test panel with web contents loaded.
CreatePanelParams params("1", gfx::Rect(), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
base::FilePath(kTestDir),
base::FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
// Close the panel by accelerator.
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
#if defined(USE_AURA)
double now = ui::EventTimeForNow().InSecondsF();
content::NativeWebKeyboardEvent key_event(
ui::ET_KEY_PRESSED,
false,
ui::VKEY_W,
ui::EF_CONTROL_DOWN,
now);
#elif defined(OS_WIN)
::MSG key_msg = { NULL, WM_KEYDOWN, ui::VKEY_W, 0 };
content::NativeWebKeyboardEvent key_event(key_msg);
key_event.modifiers = content::NativeWebKeyboardEvent::ControlKey;
#else
content::NativeWebKeyboardEvent key_event;
#endif
panel->HandleKeyboardEvent(key_event);
signal.Wait();
EXPECT_EQ(0, panel_manager->num_panels());
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
HideDockedPanelCreatedBeforeFullScreenMode) {
// Create a docked panel.
Panel* panel = CreatePanel("PanelTest");
scoped_ptr<NativePanelTesting> panel_testing(CreateNativePanelTesting(panel));
// Panel should be visible at first.
EXPECT_TRUE(panel_testing->IsWindowVisible());
// Panel should become hidden when entering full-screen mode.
mock_display_settings_provider()->EnableFullScreenMode(true);
EXPECT_FALSE(panel_testing->IsWindowVisible());
// Panel should become visible when leaving full-screen mode.
mock_display_settings_provider()->EnableFullScreenMode(false);
EXPECT_TRUE(panel_testing->IsWindowVisible());
PanelManager::GetInstance()->CloseAll();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
HideDockedPanelCreatedOnFullScreenMode) {
// Enable full-screen mode first.
mock_display_settings_provider()->EnableFullScreenMode(true);
// Create a docked panel without waiting for it to be shown since it is not
// supposed to be shown on full-screen mode.
CreatePanelParams params("1", gfx::Rect(0, 0, 250, 200), SHOW_AS_ACTIVE);
params.wait_for_fully_created = false;
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> panel_testing(
CreateNativePanelTesting(panel));
// Panel should not be shown on full-screen mode.
EXPECT_FALSE(panel_testing->IsWindowVisible());
// Panel should become visible when leaving full-screen mode.
mock_display_settings_provider()->EnableFullScreenMode(false);
EXPECT_TRUE(panel_testing->IsWindowVisible());
PanelManager::GetInstance()->CloseAll();
}
class PanelExtensionApiTest : public ExtensionApiTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnablePanels);
}
};
#if defined(OS_LINUX) || (!defined(OS_WIN) && defined(USE_AURA)) || \
defined(OS_MACOSX)
// Focus test fails if there is no window manager on Linux.
// Aura panels have different behavior that do not apply to this test.
#define MAYBE_FocusChangeEventOnMinimize DISABLED_FocusChangeEventOnMinimize
#else
#define MAYBE_FocusChangeEventOnMinimize FocusChangeEventOnMinimize
#endif
IN_PROC_BROWSER_TEST_F(PanelExtensionApiTest,
MAYBE_FocusChangeEventOnMinimize) {
// This is needed so the subsequently created panels can be activated.
// On a Mac, it transforms background-only test process into foreground one.
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_TRUE(RunExtensionTest("panels/focus_change_on_minimize")) << message_;
}
|