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 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_layout_manager.h"
#include <memory>
#include <utility>
#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/accelerators/accelerator_table.h"
#include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/accessibility/test_accessibility_controller_client.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_switches.h"
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/focus_cycler.h"
#include "ash/keyboard/keyboard_controller_impl.h"
#include "ash/keyboard/ui/keyboard_ui.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/keyboard/ui/keyboard_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/ash_prefs.h"
#include "ash/public/cpp/keyboard/keyboard_controller.h"
#include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_item.h"
#include "ash/public/cpp/shelf_prefs.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/test/shell_test_api.h"
#include "ash/public/cpp/wallpaper/wallpaper_controller_observer.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/drag_window_from_shelf_controller.h"
#include "ash/shelf/drag_window_from_shelf_controller_test_api.h"
#include "ash/shelf/home_button.h"
#include "ash/shelf/hotseat_widget.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_app_button.h"
#include "ash/shelf/shelf_controller.h"
#include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_metrics.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shelf/test/hotseat_state_watcher.h"
#include "ash/shelf/test/shelf_layout_manager_test_base.h"
#include "ash/shell.h"
#include "ash/system/eche/eche_tray.h"
#include "ash/system/ime_menu/ime_menu_tray.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_ash_web_view_factory.h"
#include "ash/test/test_widget_builder.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/work_area_insets.h"
#include "ash/wm/workspace_controller.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/icu_test_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/ui/base/window_properties.h"
#include "components/prefs/pref_service.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display.h"
#include "ui/display/display_layout.h"
#include "ui/display/display_observer.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event_constants.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/views/animation/bounds_animator.h"
#include "ui/views/test/widget_animation_waiter.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/window_util.h"
namespace ash {
namespace {
using ::chromeos::kHideShelfWhenFullscreenKey;
void PressHomeButton() {
Shell::Get()->app_list_controller()->ToggleAppList(
display::Screen::GetScreen()->GetPrimaryDisplay().id(),
AppListShowSource::kShelfButton, base::TimeTicks());
}
void StepWidgetLayerAnimatorToEnd(views::Widget* widget) {
widget->GetNativeView()->layer()->GetAnimator()->Step(base::TimeTicks::Now() +
base::Seconds(1));
}
ShelfWidget* GetShelfWidget() {
return AshTestBase::GetPrimaryShelf()->shelf_widget();
}
ShelfLayoutManager* GetShelfLayoutManager() {
return AshTestBase::GetPrimaryShelf()->shelf_layout_manager();
}
HotseatWidget* GetHotseatWidget() {
return AshTestBase::GetPrimaryShelf()->hotseat_widget();
}
gfx::Rect GetScreenAvailableBounds() {
const WorkAreaInsets* const work_area =
WorkAreaInsets::ForWindow(GetShelfWidget()->GetNativeWindow());
gfx::Rect available_bounds = screen_util::GetDisplayBoundsWithShelf(
GetShelfWidget()->GetNativeWindow());
available_bounds.Inset(work_area->GetAccessibilityInsets());
return available_bounds;
}
// Returns the distance of the top of a widget from the bottom of the primary
// screen.
int GetWidgetOffsetFromBottom(const views::Widget* widget) {
const int display_bottom =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds().bottom();
return display_bottom -
widget->GetClientAreaBoundsInScreen().top_center().y();
}
// Creates and displays a test app in the hotseat.
void AddApp() {
ShelfController* controller = Shell::Get()->shelf_controller();
const int next_app_index = controller->model()->item_count();
ShelfTestUtil::AddAppShortcut(
"app_id_" + base::NumberToString(next_app_index), TYPE_PINNED_APP);
}
class TestDisplayObserver : public display::DisplayObserver {
public:
TestDisplayObserver() = default;
TestDisplayObserver(const TestDisplayObserver&) = delete;
TestDisplayObserver& operator=(const TestDisplayObserver&) = delete;
~TestDisplayObserver() override = default;
int metrics_change_count() const { return metrics_change_count_; }
private:
// ShelfLayoutManagerObserver:
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override {
metrics_change_count_++;
}
display::ScopedDisplayObserver display_observer_{this};
int metrics_change_count_ = 0;
};
class WallpaperShownWaiter : public WallpaperControllerObserver {
public:
WallpaperShownWaiter() {
Shell::Get()->wallpaper_controller()->AddObserver(this);
}
WallpaperShownWaiter(const WallpaperShownWaiter&) = delete;
WallpaperShownWaiter& operator=(const WallpaperShownWaiter&) = delete;
~WallpaperShownWaiter() override {
Shell::Get()->wallpaper_controller()->RemoveObserver(this);
}
// Note this could only be called once because RunLoop would not run after
// Quit is called. Create a new instance if there's need to wait again.
void Wait() { run_loop_.Run(); }
private:
// WallpaperControllerObserver:
void OnFirstWallpaperShown() override { run_loop_.Quit(); }
base::RunLoop run_loop_;
};
// This class detects the auto hide state change in shelf layout manager within
// its lifetime.
class AutoHideStateDetector : public ShelfLayoutManagerObserver {
public:
AutoHideStateDetector() {
Shell::GetPrimaryRootWindowController()
->shelf()
->shelf_layout_manager()
->AddObserver(this);
}
AutoHideStateDetector(const AutoHideStateDetector&) = delete;
AutoHideStateDetector& operator=(const AutoHideStateDetector&) = delete;
~AutoHideStateDetector() override {
Shell::GetPrimaryRootWindowController()
->shelf()
->shelf_layout_manager()
->RemoveObserver(this);
}
void OnAutoHideStateChanged(ShelfAutoHideState new_state) override {
if (new_state == SHELF_AUTO_HIDE_HIDDEN)
was_shelf_auto_hidden = true;
}
bool WasShelfAutoHidden() const { return was_shelf_auto_hidden; }
private:
bool was_shelf_auto_hidden = false;
};
} // namespace
class ShelfLayoutManagerTest : public ShelfLayoutManagerTestBase {
public:
ShelfLayoutManagerTest() {
// TODO(b/293400777): Test currently crashes when Jelly is enabled because
// of a crash in ShellTestApi. Remove when that is fixed.
scoped_features_.InitAndDisableFeature(chromeos::features::kJelly);
}
void SetUpKioskSession() {
SessionInfo info;
info.is_running_in_app_mode = true;
info.state = session_manager::SessionState::ACTIVE;
Shell::Get()->session_controller()->SetSessionInfo(info);
}
private:
base::test::ScopedFeatureList scoped_features_;
};
// Makes sure SetVisible updates work area and widget appropriately.
TEST_F(ShelfLayoutManagerTest, SetVisible) {
ShelfWidget* shelf_widget = GetShelfWidget();
ShelfLayoutManager* manager = shelf_widget->shelf_layout_manager();
// Force an initial layout.
manager->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
gfx::Rect status_bounds(
shelf_widget->status_area_widget()->GetWindowBoundsInScreen());
gfx::Rect shelf_bounds(shelf_widget->GetWindowBoundsInScreen());
int shelf_height = manager->GetIdealBounds().height();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
const gfx::Rect stable_work_area = display.work_area();
ASSERT_NE(-1, display.id());
// Bottom inset should be the max of widget heights.
EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
// Hide the shelf.
SetState(manager, SHELF_HIDDEN);
// Run the animation to completion.
StepWidgetLayerAnimatorToEnd(shelf_widget);
StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state());
display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
// Make sure the bounds of the two widgets changed.
EXPECT_GE(shelf_widget->GetNativeView()->bounds().y(),
display.bounds().bottom());
EXPECT_GE(shelf_widget->status_area_widget()->GetNativeView()->bounds().y(),
display.bounds().bottom());
EXPECT_EQ(stable_work_area,
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
// And show it again.
SetState(manager, SHELF_VISIBLE);
// Run the animation to completion.
StepWidgetLayerAnimatorToEnd(shelf_widget);
StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(stable_work_area,
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
// Make sure the bounds of the two widgets changed.
shelf_bounds = shelf_widget->GetNativeView()->bounds();
EXPECT_LT(shelf_bounds.y(), display.bounds().bottom());
status_bounds = shelf_widget->status_area_widget()->GetNativeView()->bounds();
EXPECT_LT(status_bounds.y(), display.bounds().bottom());
}
// Makes sure LayoutShelf invoked while animating cleans things up.
TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
// Force an initial layout.
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Hide the shelf.
SetState(layout_manager, SHELF_HIDDEN);
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
// Make sure the bounds of the two widgets changed.
ShelfWidget* shelf_widget = GetShelfWidget();
EXPECT_GE(shelf_widget->GetNativeView()->bounds().y(),
display.bounds().bottom());
EXPECT_GE(shelf_widget->status_area_widget()->GetNativeView()->bounds().y(),
display.bounds().bottom());
}
// Test that switching to a different visibility state does not restart the
// shelf show / hide animation if it is already running. (crbug.com/250918)
TEST_F(ShelfLayoutManagerTest, SetStateWhileAnimating) {
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
SetState(layout_manager, SHELF_VISIBLE);
ShelfWidget* shelf_widget = GetShelfWidget();
gfx::Rect initial_shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
gfx::Rect initial_status_bounds =
shelf_widget->status_area_widget()->GetWindowBoundsInScreen();
ui::ScopedAnimationDurationScaleMode normal_animation_duration(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
SetState(layout_manager, SHELF_HIDDEN);
SetState(layout_manager, SHELF_VISIBLE);
gfx::Rect current_shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
gfx::Rect current_status_bounds =
shelf_widget->status_area_widget()->GetWindowBoundsInScreen();
const int small_change = initial_shelf_bounds.height() / 2;
EXPECT_LE(
std::abs(initial_shelf_bounds.height() - current_shelf_bounds.height()),
small_change);
EXPECT_LE(
std::abs(initial_status_bounds.height() - current_status_bounds.height()),
small_change);
}
// Various assertions around auto-hide.
TEST_F(ShelfLayoutManagerTest, AutoHide) {
ui::test::EventGenerator* generator = GetEventGenerator();
const gfx::Rect stable_work_area =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
views::Widget* widget = CreateTestWidget();
widget->Maximize();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
// LayoutShelf() forces the animation to completion, at which point the
// shelf should go off the screen.
layout_manager->LayoutShelf();
const int display_bottom = display.bounds().bottom();
EXPECT_EQ(
display_bottom - ShelfConfig::Get()->hidden_shelf_in_screen_portion(),
GetShelfWidget()->GetWindowBoundsInScreen().y());
EXPECT_EQ(display_bottom, display.work_area().bottom());
EXPECT_EQ(stable_work_area,
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
// Move the mouse to the bottom of the screen.
generator->MoveMouseTo(0, display_bottom - 1);
// Shelf should be shown again (but it shouldn't have changed the work area).
SetState(layout_manager, SHELF_AUTO_HIDE);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
layout_manager->LayoutShelf();
EXPECT_EQ(display_bottom - layout_manager->GetIdealBounds().height(),
GetShelfWidget()->GetWindowBoundsInScreen().y());
EXPECT_EQ(display_bottom, display.work_area().bottom());
EXPECT_EQ(stable_work_area,
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
// Tap the system tray when shelf is shown should open the system tray menu.
generator->GestureTapAt(
GetPrimaryUnifiedSystemTray()->GetBoundsInScreen().CenterPoint());
EXPECT_TRUE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
// Move mouse back up and click to dismiss the opened system tray menu.
generator->MoveMouseTo(0, 0);
generator->ClickLeftButton();
SetState(layout_manager, SHELF_AUTO_HIDE);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
layout_manager->LayoutShelf();
EXPECT_EQ(
display_bottom - ShelfConfig::Get()->hidden_shelf_in_screen_portion(),
GetShelfWidget()->GetWindowBoundsInScreen().y());
EXPECT_EQ(stable_work_area,
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
// Move the mouse to the bottom again to show the shelf.
generator->MoveMouseTo(0, display_bottom - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// A tap on the maximized window should hide the shelf, even if the most
// recent mouse position was over the shelf (crbug.com/963977).
EXPECT_TRUE(widget->IsMouseEventsEnabled());
gfx::Rect window_bounds = widget->GetNativeWindow()->GetBoundsInScreen();
generator->GestureTapAt(window_bounds.origin() + gfx::Vector2d(10, 10));
EXPECT_FALSE(widget->IsMouseEventsEnabled());
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Return the mouse to the top.
generator->MoveMouseTo(0, 0);
// Drag mouse to bottom of screen.
generator->PressLeftButton();
generator->MoveMouseTo(0, display_bottom - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
generator->ReleaseLeftButton();
generator->MoveMouseTo(1, display_bottom - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
generator->PressLeftButton();
generator->MoveMouseTo(1, display_bottom - 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Switch to tablet mode should hide the AUTO_HIDE_SHOWN shelf even the mouse
// cursor is inside the shelf area.
EXPECT_FALSE(TabletModeControllerTestApi().IsTabletModeStarted());
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(TabletModeControllerTestApi().IsTabletModeStarted());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Test the behavior of the shelf when it is auto hidden and it is on the
// boundary between the primary and the secondary display.
TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) {
UpdateDisplay("800x600,800x600");
Shell::Get()->display_manager()->SetLayoutForCurrentDisplays(
display::test::CreateDisplayLayout(display_manager(),
display::DisplayPlacement::RIGHT, 0));
// Put the primary monitor's shelf on the display boundary.
Shelf* shelf = GetPrimaryShelf();
shelf->SetAlignment(ShelfAlignment::kRight);
// Create a window because the shelf is always shown when no windows are
// visible.
CreateTestWidget();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
const int right_edge = display.bounds().right() - 1;
const int y = display.bounds().y();
// Start off the mouse nowhere near the shelf; the shelf should be hidden.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(right_edge - 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Moving the mouse over the light bar (but not to the edge of the screen)
// should show the shelf.
generator->MoveMouseTo(right_edge - 1, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(right_edge - 1,
display::Screen::GetScreen()->GetCursorScreenPoint().x());
// Moving the mouse off the light bar should hide the shelf.
generator->MoveMouseTo(right_edge - 60, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Moving the mouse to the right edge of the screen crossing the light bar
// should show the shelf despite the mouse cursor getting warped to the
// secondary display.
generator->MoveMouseTo(right_edge - 1, y);
generator->MoveMouseTo(right_edge, y);
UpdateAutoHideStateNow();
EXPECT_NE(right_edge - 1,
display::Screen::GetScreen()->GetCursorScreenPoint().x());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Hide the shelf.
generator->MoveMouseTo(right_edge - 60, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Moving the mouse to the right edge of the screen crossing the light bar and
// overshooting by a lot should keep the shelf hidden.
generator->MoveMouseTo(right_edge - 1, y);
generator->MoveMouseTo(right_edge + 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Moving the mouse to the right edge of the screen crossing the light bar and
// overshooting a bit should show the shelf.
generator->MoveMouseTo(right_edge - 1, y);
generator->MoveMouseTo(right_edge + 2, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Keeping the mouse close to the left edge of the secondary display after the
// shelf is shown should keep the shelf shown.
generator->MoveMouseTo(right_edge + 2, y + 1);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Moving the mouse far from the left edge of the secondary display should
// hide the shelf.
generator->MoveMouseTo(right_edge + 50, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Moving to the left edge of the secondary display without first crossing
// the primary display's right aligned shelf first should not show the shelf.
generator->MoveMouseTo(right_edge + 2, y);
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Assertions around the login screen.
TEST_F(ShelfLayoutManagerTest, VisibleWhenLoginScreenShowing) {
Shelf* shelf = GetPrimaryShelf();
auto* wallpaper_controller = Shell::Get()->wallpaper_controller();
WallpaperShownWaiter waiter;
SessionInfo info;
info.state = session_manager::SessionState::LOGIN_PRIMARY;
Shell::Get()->session_controller()->SetSessionInfo(info);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// No wallpaper.
ASSERT_FALSE(wallpaper_controller->HasShownAnyWallpaper());
EXPECT_EQ(ShelfBackgroundType::kLogin,
GetShelfLayoutManager()->shelf_background_type());
// Showing wallpaper is asynchronous.
wallpaper_controller->ShowDefaultWallpaperForTesting();
waiter.Wait();
ASSERT_TRUE(wallpaper_controller->HasShownAnyWallpaper());
// Non-blurred wallpaper.
wallpaper_controller->UpdateWallpaperBlurForLockState(/*blur=*/false);
EXPECT_EQ(ShelfBackgroundType::kLoginNonBlurredWallpaper,
GetShelfLayoutManager()->shelf_background_type());
// Blurred wallpaper.
wallpaper_controller->UpdateWallpaperBlurForLockState(/*blur=*/true);
EXPECT_EQ(ShelfBackgroundType::kLogin,
GetShelfLayoutManager()->shelf_background_type());
}
// Assertions around the lock screen showing.
TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
views::Widget* widget = CreateTestWidget();
widget->Maximize();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// LayoutShelf() forces the animation to completion, at which point the
// shelf should go off the screen.
layout_manager->LayoutShelf();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(display.bounds().bottom() -
ShelfConfig::Get()->hidden_shelf_in_screen_portion(),
GetShelfWidget()->GetWindowBoundsInScreen().y());
std::unique_ptr<views::Widget> lock_widget(AshTestBase::CreateTestWidget(
nullptr, kShellWindowId_LockScreenContainer, gfx::Rect(200, 200)));
lock_widget->Maximize();
// Lock the screen.
LockScreen();
// Showing a widget in the lock screen should force the shelf to be visible.
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfBackgroundType::kLogin,
GetShelfLayoutManager()->shelf_background_type());
UnlockScreen();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
}
// Verifies that the hidden shelf shows after triggering the
// AcceleratorAction::kFocusShelf accelerator (https://crbug.com/1111426).
TEST_F(ShelfLayoutManagerTest, ShowHiddenShelfByFocusShelfAccelerator) {
// Open a window so that the shelf will auto-hide.
std::unique_ptr<aura::Window> window(CreateTestWindow());
window->Show();
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Focus on the shelf by accelerator.
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(
AcceleratorAction::kFocusShelf, {});
// Shelf should be visible.
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
TEST_F(ShelfLayoutManagerTest, ShelfDoesNotAutoHideWithVoxAndTabletMode) {
TabletModeControllerTestApi().EnterTabletMode();
// Open a window so that the shelf will auto-hide.
std::unique_ptr<aura::Window> window(CreateTestWindow());
window->Show();
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Enable Chromevox. The shelf should now show.
Shell::Get()->accessibility_controller()->SetSpokenFeedbackEnabled(
true, A11Y_NOTIFICATION_NONE);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Disable Chromevox again. The shelf should be able to auto-hide again.
Shell::Get()->accessibility_controller()->SetSpokenFeedbackEnabled(
false, A11Y_NOTIFICATION_NONE);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Tests that the shelf should be visible when in overview mode.
TEST_F(ShelfLayoutManagerTest, VisibleInOverview) {
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
std::unique_ptr<aura::Window> window(CreateTestWindow());
window->SetBounds({0, 0, 120, 320});
window->Show();
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// LayoutShelf() forces the animation to completion, at which point the
// shelf should go off the screen.
GetShelfLayoutManager()->LayoutShelf();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(display.bounds().bottom() -
ShelfConfig::Get()->hidden_shelf_in_screen_portion(),
GetShelfWidget()->GetWindowBoundsInScreen().y());
// Tests that the shelf is visible when in overview mode.
EnterOverview();
ShellTestApi().WaitForOverviewAnimationState(
OverviewAnimationState::kEnterAnimationComplete);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(ShelfBackgroundType::kOverview,
GetShelfLayoutManager()->shelf_background_type());
// Test that on exiting overview mode, the shelf returns to auto hide state.
ExitOverview();
ShellTestApi().WaitForOverviewAnimationState(
OverviewAnimationState::kExitAnimationComplete);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(display.bounds().bottom() -
ShelfConfig::Get()->hidden_shelf_in_screen_portion(),
GetShelfWidget()->GetNativeWindow()->GetTargetBounds().y());
}
// Assertions around SetAutoHideBehavior.
TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
Shelf* shelf = GetPrimaryShelf();
views::Widget* widget = CreateTestWidget();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
widget->Maximize();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
display::Screen* screen = display::Screen::GetScreen();
EXPECT_EQ(screen->GetPrimaryDisplay().work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(screen->GetPrimaryDisplay().work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
ui::ScopedAnimationDurationScaleMode animation_duration(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
ShelfWidget* shelf_widget = GetShelfWidget();
EXPECT_TRUE(shelf_widget->status_area_widget()->IsVisible());
StepWidgetLayerAnimatorToEnd(shelf_widget);
StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(screen->GetPrimaryDisplay().work_area().bottom(),
widget->GetWorkAreaBoundsInScreen().bottom());
}
// Verifies the shelf is visible when status/shelf is focused.
TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrShelfFocused) {
Shelf* shelf = GetPrimaryShelf();
views::Widget* widget = CreateTestWidget();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Focus the shelf. Have to go through the focus cycler as normal focus
// requests to it do nothing.
GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
widget->Activate();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Trying to activate the status should fail, since we only allow activating
// it when the user is using the keyboard (i.e. through FocusCycler).
GetShelfWidget()->status_area_widget()->Activate();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
// Checks that the status area follows along the auto-hidden shelf when the
// user swipes it up or down.
TEST_F(ShelfLayoutManagerTest, StatusAreaMoveWithSwipeOnAutoHiddenShelf) {
Shelf* shelf = GetPrimaryShelf();
CreateTestWidget();
TabletModeControllerTestApi().EnterTabletMode();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
const int hidden_shelf_in_screen_portion =
ShelfConfig::Get()->hidden_shelf_in_screen_portion();
// The shelf is hidden. The status area should also be off-screen.
EXPECT_EQ(hidden_shelf_in_screen_portion,
GetWidgetOffsetFromBottom(shelf->status_area_widget()));
gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
const gfx::Point start(display_bounds.bottom_center());
const gfx::Point middle(start + gfx::Vector2d(0, -40));
const gfx::Point end(start + gfx::Vector2d(0, -80));
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveTouch(start);
generator->PressTouch();
// The drag has just started, but we haven't moved yet.
EXPECT_EQ(hidden_shelf_in_screen_portion,
GetWidgetOffsetFromBottom(shelf->status_area_widget()));
generator->MoveTouch(middle);
// Now the status area should have entered the screen.
const int status_area_visible_px_mid_gesture =
GetWidgetOffsetFromBottom(shelf->status_area_widget());
EXPECT_LT(hidden_shelf_in_screen_portion, status_area_visible_px_mid_gesture);
// Finish the gesture, the status area should follow.
generator->MoveTouch(end);
generator->ReleaseTouch();
const int status_area_visible_px_end_gesture =
GetWidgetOffsetFromBottom(shelf->status_area_widget());
EXPECT_LT(status_area_visible_px_mid_gesture,
status_area_visible_px_end_gesture);
// Now start swiping down. The status area should follow the other way.
generator->MoveTouch(end);
generator->PressTouch();
EXPECT_EQ(status_area_visible_px_end_gesture,
GetWidgetOffsetFromBottom(shelf->status_area_widget()));
// And it should be back to off-screen after the gesture ends.
generator->MoveTouch(start);
generator->ReleaseTouch();
EXPECT_EQ(hidden_shelf_in_screen_portion,
GetWidgetOffsetFromBottom(shelf->status_area_widget()));
}
// Checks that the shelf keeps hidden during the Kiosk mode.
TEST_F(ShelfLayoutManagerTest, HiddenShelfInKioskMode_FullScreen) {
SetUpKioskSession();
// Create a window and make it full screen; the shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window->SetProperty(kHideShelfWhenFullscreenKey, false);
window->Show();
wm::ActivateWindow(window);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState());
EXPECT_EQ(WorkspaceWindowState::kFullscreen, GetWorkspaceWindowState());
SwipeUpOnShelf();
EXPECT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState());
}
// Checks that the shelf keeps hidden during the Kiosk mode. (Some windows might
// not be fullscreen, e.g., the a11y setting window.)
TEST_F(ShelfLayoutManagerTest, HiddenShelfInKioskMode_Default) {
SetUpKioskSession();
// Create a default window; the shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(kHideShelfWhenFullscreenKey, false);
window->Show();
wm::ActivateWindow(window);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState());
EXPECT_EQ(WorkspaceWindowState::kDefault, GetWorkspaceWindowState());
SwipeUpOnShelf();
EXPECT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState());
}
TEST_F(ShelfLayoutManagerTest,
NavigationWidgetDoesNotMoveWithoutAutoHiddenShelf) {
Shelf* shelf = GetPrimaryShelf();
CreateTestWidget();
TabletModeControllerTestApi().EnterTabletMode();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
gfx::Rect nav_widget_bounds =
shelf->navigation_widget()->GetWindowBoundsInScreen();
const gfx::Point end(nav_widget_bounds.top_center());
const gfx::Point middle(end +
gfx::Vector2d(0, -nav_widget_bounds.height() / 2));
const gfx::Point start(end + gfx::Vector2d(0, -nav_widget_bounds.height()));
// Perform a drag down on the status area widget.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveTouch(start);
generator->PressTouch();
generator->MoveTouch(middle);
EXPECT_EQ(nav_widget_bounds,
shelf->navigation_widget()->GetWindowBoundsInScreen());
generator->MoveTouch(end);
EXPECT_EQ(nav_widget_bounds,
shelf->navigation_widget()->GetWindowBoundsInScreen());
generator->ReleaseTouch();
EXPECT_EQ(nav_widget_bounds,
shelf->navigation_widget()->GetWindowBoundsInScreen());
}
TEST_F(ShelfLayoutManagerTest, StatusWidgetDoesNotMoveWithoutAutoHiddenShelf) {
Shelf* shelf = GetPrimaryShelf();
CreateTestWidget();
TabletModeControllerTestApi().EnterTabletMode();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
gfx::Rect status_widget_bounds =
shelf->status_area_widget()->GetWindowBoundsInScreen();
const gfx::Point end(status_widget_bounds.top_center());
const gfx::Point middle(end +
gfx::Vector2d(0, -status_widget_bounds.height() / 2));
const gfx::Point start(end +
gfx::Vector2d(0, -status_widget_bounds.height()));
// Perform a drag down on the status area widget.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveTouch(start);
generator->PressTouch();
generator->MoveTouch(middle);
EXPECT_EQ(status_widget_bounds,
shelf->status_area_widget()->GetWindowBoundsInScreen());
generator->MoveTouch(end);
EXPECT_EQ(status_widget_bounds,
shelf->status_area_widget()->GetWindowBoundsInScreen());
generator->ReleaseTouch();
EXPECT_EQ(status_widget_bounds,
shelf->status_area_widget()->GetWindowBoundsInScreen());
}
// Checks that the navigation widget follows along the auto-hidden shelf when
// the user swipes it up or down.
TEST_F(ShelfLayoutManagerTest, NavigationWidgetMoveWithSwipeOnAutoHiddenShelf) {
Shell::Get()
->accessibility_controller()
->SetTabletModeShelfNavigationButtonsEnabled(true);
Shelf* shelf = GetPrimaryShelf();
CreateTestWidget();
TabletModeControllerTestApi().EnterTabletMode();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
const int hidden_shelf_in_screen_portion =
ShelfConfig::Get()->hidden_shelf_in_screen_portion();
// The shelf is hidden. The navigation widget should also be off-screen.
EXPECT_EQ(hidden_shelf_in_screen_portion,
GetWidgetOffsetFromBottom(shelf->navigation_widget()));
gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
const gfx::Point start(display_bounds.bottom_center());
const gfx::Point middle(start + gfx::Vector2d(0, -40));
const gfx::Point end(start + gfx::Vector2d(0, -80));
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveTouch(start);
generator->PressTouch();
// The drag has just started, but we haven't moved yet.
EXPECT_EQ(hidden_shelf_in_screen_portion,
GetWidgetOffsetFromBottom(shelf->navigation_widget()));
generator->MoveTouch(middle);
// Now the navigation widget should have entered the screen.
const int navigation_visible_px_mid_gesture =
GetWidgetOffsetFromBottom(shelf->navigation_widget());
EXPECT_LT(hidden_shelf_in_screen_portion, navigation_visible_px_mid_gesture);
// Verify that the navigation widget and status area moved the same amount.
EXPECT_EQ(navigation_visible_px_mid_gesture,
GetWidgetOffsetFromBottom(shelf->status_area_widget()));
// Finish the gesture, the navigation widget should follow.
generator->MoveTouch(end);
generator->ReleaseTouch();
const int navigation_visible_px_end_gesture =
GetWidgetOffsetFromBottom(shelf->navigation_widget());
EXPECT_LT(navigation_visible_px_mid_gesture,
navigation_visible_px_end_gesture);
// Now start swiping down. The navigation widget should follow the other way.
generator->MoveTouch(end);
generator->PressTouch();
EXPECT_EQ(navigation_visible_px_end_gesture,
GetWidgetOffsetFromBottom(shelf->navigation_widget()));
// And it should be back to off-screen after the gesture ends.
generator->MoveTouch(start);
generator->ReleaseTouch();
EXPECT_EQ(hidden_shelf_in_screen_portion,
GetWidgetOffsetFromBottom(shelf->navigation_widget()));
}
// Ensure a SHELF_VISIBLE shelf stays visible when the app list is shown.
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
// Create a normal unmaximized window; the shelf should be visible.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Show the app list and the shelf stays visible.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Hide the app list and the shelf stays visible.
GetAppListTestHelper()->DismissAndRunLoop();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
}
// Ensure a SHELF_AUTO_HIDE shelf is shown temporarily (SHELF_AUTO_HIDE_SHOWN)
// when the app list is shown, but the visibility state doesn't change.
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Create a normal unmaximized window; the shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Show the app list and the shelf should be temporarily visible.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
// The shelf's auto hide state won't be changed until the timer fires, so
// force it to update now.
GetShelfLayoutManager()->UpdateVisibilityState(/*force_layout=*/false);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Hide the app list and the shelf should be hidden again.
GetAppListTestHelper()->DismissAndRunLoop();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Makes sure that when we have dual displays, with one or both shelves are set
// to AutoHide, viewing the AppList on one of them doesn't unhide the other
// hidden shelf.
TEST_F(ShelfLayoutManagerTest, DualDisplayOpenAppListWithShelfAutoHideState) {
// Create two displays.
UpdateDisplay("0+0-200x300,+200+0-100x200");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(root_windows.size(), 2U);
// Get the shelves in both displays and set them to be 'AutoHide'.
Shelf* shelf_1 = Shelf::ForWindow(root_windows[0]);
Shelf* shelf_2 = Shelf::ForWindow(root_windows[1]);
EXPECT_NE(shelf_1, shelf_2);
EXPECT_NE(shelf_1->GetWindow()->GetRootWindow(),
shelf_2->GetWindow()->GetRootWindow());
shelf_1->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
shelf_1->shelf_layout_manager()->LayoutShelf();
shelf_2->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
shelf_2->shelf_layout_manager()->LayoutShelf();
// Create a window in each display and show them in maximized state.
aura::Window* window_1 = CreateTestWindowInParent(root_windows[0]);
window_1->SetBounds(gfx::Rect(0, 0, 100, 100));
window_1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window_1->Show();
aura::Window* window_2 = CreateTestWindowInParent(root_windows[1]);
window_2->SetBounds(gfx::Rect(201, 0, 100, 100));
window_2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window_2->Show();
EXPECT_EQ(shelf_1->GetWindow()->GetRootWindow(), window_1->GetRootWindow());
EXPECT_EQ(shelf_2->GetWindow()->GetRootWindow(), window_2->GetRootWindow());
// Activate one window in one display.
wm::ActivateWindow(window_1);
Shelf::UpdateShelfVisibility();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
// Show the app list; only the shelf on the same display should be shown.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
Shelf::UpdateShelfVisibility();
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
// Hide the app list, both shelves should be hidden.
GetAppListTestHelper()->DismissAndRunLoop();
Shelf::UpdateShelfVisibility();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
}
// Ensure a SHELF_HIDDEN shelf (for a fullscreen window) is shown temporarily
// when the app list is shown, and hidden again when the app list is dismissed.
TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) {
Shelf* shelf = GetPrimaryShelf();
// Create a window and make it full screen; the shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window->Show();
wm::ActivateWindow(window);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
EXPECT_EQ(WorkspaceWindowState::kFullscreen, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
// Show the app list and the shelf should be temporarily visible.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Hide the app list and the shelf should be hidden again.
GetAppListTestHelper()->DismissAndRunLoop();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
}
// Test that in tablet mode with auto hide enabled, opening a tray bubble while
// closing another keeps the hotseat hidden.
TEST_F(ShelfLayoutManagerTest, HotseatExtendingWhileClosingTrayBubble) {
TabletModeControllerTestApi().EnterTabletMode();
ui::test::EventGenerator* generator = GetEventGenerator();
Shelf* shelf = GetPrimaryShelf();
StatusAreaWidget* status_area = shelf->status_area_widget();
status_area->ime_menu_tray()->SetVisiblePreferred(true);
// Set the shelf to be auto hidden.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Create a widget. The shelf and hotseat should become hidden.
CreateTestWidget()->GetNativeWindow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
// Swipe up to show the auto-hide shelf, and extend the hotseat.
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
// Tap on the ime menu tray button, to show a tray bubble. The shelf
// should be showing, but the hotseat should be hidden.
EXPECT_FALSE(status_area->ime_menu_tray()->GetBubbleView());
generator->GestureTapAt(
status_area->ime_menu_tray()->GetBoundsInScreen().CenterPoint());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(status_area->ime_menu_tray()->GetBubbleView());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
// Tap on the unified system tray to open its bubble and close the ime menu
// bubble. The hotseat should remain in the hidden state.
EXPECT_FALSE(status_area->IsMessageBubbleShown());
generator->GestureTapAt(
status_area->unified_system_tray()->GetBoundsInScreen().CenterPoint());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(status_area->IsMessageBubbleShown());
EXPECT_FALSE(status_area->ime_menu_tray()->GetBubbleView());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
// Check that the status bubble and shelf are hidden after tapping on the
// in-app shelf.
generator->GestureTapAt(
GetShelfWidget()->GetVisibleShelfBounds().CenterPoint());
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(status_area->IsMessageBubbleShown());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
}
// With a fullscreen window, ensure the hidden shelf is shown temporarily when
// the app list is shown and when tray bubbles are shown. Ensure that the shelf
// is hidden again once tray bubbles are closed.
TEST_F(ShelfLayoutManagerTest, OpenAppListInFullscreenWithShelfHiddenState) {
Shelf* shelf = GetPrimaryShelf();
StatusAreaWidget* status_area = shelf->status_area_widget();
status_area->ime_menu_tray()->SetVisiblePreferred(true);
// Create a window and make it full screen; the shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window->Show();
wm::ActivateWindow(window);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
EXPECT_EQ(WorkspaceWindowState::kFullscreen, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
// Show the app list and the shelf should be temporarily visible.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click on the ime menu tray button, to show a tray bubble. The shelf
// should still be showing and the app list should hide.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(
status_area->ime_menu_tray()->GetBoundsInScreen().CenterPoint());
generator->PressLeftButton();
base::RunLoop().RunUntilIdle();
generator->ReleaseLeftButton();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
// Click away from the shelf and tray bubble to hide the shelf.
generator->MoveMouseTo(10, 10);
generator->ClickLeftButton();
EXPECT_TRUE(RunVisibilityUpdateForTrayCallback());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
// Show the app list and the shelf should be temporarily visible.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click on the unified system tray button, opening the tray and hiding the
// app list.
EXPECT_FALSE(status_area->IsMessageBubbleShown());
generator->MoveMouseTo(
status_area->unified_system_tray()->GetBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(status_area->IsMessageBubbleShown());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
// Click away from the shelf and unified system tray to hide the shelf.
generator->MoveMouseTo(10, 10);
generator->ClickLeftButton();
EXPECT_TRUE(RunVisibilityUpdateForTrayCallback());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
// Show the app list and the shelf should be temporarily visible.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click on the unified system tray button, closing the app list.
EXPECT_FALSE(status_area->IsMessageBubbleShown());
generator->MoveMouseTo(
status_area->unified_system_tray()->GetBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(status_area->IsMessageBubbleShown());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
// Click on the ime menu tray button, to show a tray bubble and close the
// unified system tray. The shelf should still be showing.
generator->MoveMouseTo(
status_area->ime_menu_tray()->GetBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
EXPECT_FALSE(status_area->IsMessageBubbleShown());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click away from the shelf and tray bubble to hide the shelf.
generator->MoveMouseTo(10, 10);
generator->ClickLeftButton();
EXPECT_TRUE(RunVisibilityUpdateForTrayCallback());
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
}
// Tests the correct behavior of the shelf when there is a system modal window
// open when we have a single display.
TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowSingleDisplay) {
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window->Show();
wm::ActivateWindow(window);
// Enable system modal dialog, and make sure shelf is still hidden.
ShellTestApi().SimulateModalWindowOpenForTest(true);
EXPECT_TRUE(Shell::IsSystemModalWindowOpen());
EXPECT_FALSE(wm::CanActivateWindow(window));
Shelf::UpdateShelfVisibility();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Tests the correct behavior of the shelf when there is a system modal window
// open when we have dual display.
TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowDualDisplay) {
// Create two displays.
UpdateDisplay("200x300,100x200");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(2U, root_windows.size());
// Get the shelves in both displays and set them to be 'AutoHide'.
Shelf* shelf_1 = Shelf::ForWindow(root_windows[0]);
Shelf* shelf_2 = Shelf::ForWindow(root_windows[1]);
EXPECT_NE(shelf_1, shelf_2);
EXPECT_NE(shelf_1->GetWindow()->GetRootWindow(),
shelf_2->GetWindow()->GetRootWindow());
shelf_1->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
shelf_1->shelf_layout_manager()->LayoutShelf();
shelf_2->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
shelf_2->shelf_layout_manager()->LayoutShelf();
// Create a window in each display and show them in maximized state.
aura::Window* window_1 = CreateTestWindowInParent(root_windows[0]);
window_1->SetBounds(gfx::Rect(0, 0, 100, 100));
window_1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window_1->Show();
aura::Window* window_2 = CreateTestWindowInParent(root_windows[1]);
window_2->SetBounds(gfx::Rect(201, 0, 100, 100));
window_2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window_2->Show();
EXPECT_EQ(shelf_1->GetWindow()->GetRootWindow(), window_1->GetRootWindow());
EXPECT_EQ(shelf_2->GetWindow()->GetRootWindow(), window_2->GetRootWindow());
EXPECT_TRUE(window_1->IsVisible());
EXPECT_TRUE(window_2->IsVisible());
// Enable system modal dialog, and make sure both shelves are still hidden.
ShellTestApi().SimulateModalWindowOpenForTest(true);
EXPECT_TRUE(Shell::IsSystemModalWindowOpen());
EXPECT_FALSE(wm::CanActivateWindow(window_1));
EXPECT_FALSE(wm::CanActivateWindow(window_2));
Shelf::UpdateShelfVisibility();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
}
TEST_F(ShelfLayoutManagerTest, FullscreenWidgetHidesShelf) {
Shelf* shelf = GetPrimaryShelf();
// Create a normal window.
views::Widget* widget = TestWidgetBuilder()
.SetBounds(gfx::Rect(11, 22, 300, 400))
.BuildOwnedByNativeWidget();
ASSERT_FALSE(widget->IsFullscreen());
// Shelf defaults to visible.
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Fullscreen window hides it.
widget->SetFullscreen(true);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
// Restoring the window restores it.
widget->Restore();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Clean up.
widget->Close();
}
// Tests that the shelf is only hidden for a fullscreen window at the front and
// toggles visibility when another window is activated.
TEST_F(ShelfLayoutManagerTest, FullscreenWindowInFrontHidesShelf) {
Shelf* shelf = GetPrimaryShelf();
EXPECT_EQ(WorkspaceWindowState::kDefault, GetWorkspaceWindowState());
EXPECT_TRUE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
// Create a window and make it full screen.
aura::Window* window1 = CreateTestWindow();
window1->SetBounds(gfx::Rect(0, 0, 100, 100));
window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window1->Show();
EXPECT_EQ(WorkspaceWindowState::kFullscreen, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
aura::Window* window2 = CreateTestWindow();
window2->SetBounds(gfx::Rect(0, 0, 100, 100));
window2->Show();
WindowState::Get(window1)->Activate();
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
WindowState::Get(window2)->Activate();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
WindowState::Get(window1)->Activate();
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
}
// Test the behavior of the shelf when a window on one display is fullscreen
// but the other display has the active window.
TEST_F(ShelfLayoutManagerTest, FullscreenWindowOnSecondDisplay) {
UpdateDisplay("800x600,800x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
// Create windows on either display.
aura::Window* window1 = CreateTestWindow();
window1->SetBoundsInScreen(gfx::Rect(0, 0, 100, 100),
display::Screen::GetScreen()->GetAllDisplays()[0]);
window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
window1->Show();
aura::Window* window2 = CreateTestWindow();
window2->SetBoundsInScreen(gfx::Rect(800, 0, 100, 100),
display::Screen::GetScreen()->GetAllDisplays()[1]);
window2->Show();
EXPECT_EQ(root_windows[0], window1->GetRootWindow());
EXPECT_EQ(root_windows[1], window2->GetRootWindow());
WindowState::Get(window2)->Activate();
EXPECT_EQ(
SHELF_HIDDEN,
Shelf::ForWindow(window1)->shelf_layout_manager()->visibility_state());
EXPECT_EQ(
SHELF_VISIBLE,
Shelf::ForWindow(window2)->shelf_layout_manager()->visibility_state());
}
// Test for Pinned mode.
TEST_F(ShelfLayoutManagerTest, PinnedWindowHidesShelf) {
Shelf* shelf = GetPrimaryShelf();
aura::Window* window1 = CreateTestWindow();
window1->SetBounds(gfx::Rect(0, 0, 100, 100));
window1->Show();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
window_util::PinWindow(window1, /* trusted */ false);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
WindowState::Get(window1)->Restore();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
}
// Tests SHELF_ALIGNMENT_(LEFT, RIGHT).
TEST_F(ShelfLayoutManagerTest, SetAlignment) {
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
// Force an initial layout.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
shelf->SetAlignment(ShelfAlignment::kLeft);
gfx::Rect shelf_bounds(GetShelfWidget()->GetWindowBoundsInScreen());
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
ASSERT_NE(-1, display.id());
EXPECT_EQ(layout_manager->GetIdealBounds().width(),
display.GetWorkAreaInsets().left());
EXPECT_GE(shelf_bounds.width(),
GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(ShelfAlignment::kLeft, GetPrimaryShelf()->alignment());
EXPECT_EQ(display.work_area(),
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen());
// TODO(estade): Re-enable this check. See crbug.com/660928.
// EXPECT_GE(
// status_bounds.width(),
// status_area_widget->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(layout_manager->GetIdealBounds().width(),
display.GetWorkAreaInsets().left());
EXPECT_EQ(0, display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().right());
EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(0, display.GetWorkAreaInsets().left());
EXPECT_EQ(0, display.work_area().x());
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
shelf->SetAlignment(ShelfAlignment::kRight);
shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
display = display::Screen::GetScreen()->GetPrimaryDisplay();
ASSERT_NE(-1, display.id());
EXPECT_EQ(layout_manager->GetIdealBounds().width(),
display.GetWorkAreaInsets().right());
EXPECT_GE(shelf_bounds.width(),
GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(ShelfAlignment::kRight, GetPrimaryShelf()->alignment());
EXPECT_EQ(display.work_area(),
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
// TODO(estade): Re-enable this check. See crbug.com/660928.
// EXPECT_GE(
// status_bounds.width(),
// status_area_widget->GetContentsView()->GetPreferredSize().width());
EXPECT_EQ(layout_manager->GetIdealBounds().width(),
display.GetWorkAreaInsets().right());
EXPECT_EQ(0, display.GetWorkAreaInsets().top());
EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
EXPECT_EQ(0, display.GetWorkAreaInsets().left());
EXPECT_EQ(display.work_area().right(), shelf_bounds.x());
EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
const gfx::Rect stable_work_area =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
display = display::Screen::GetScreen()->GetPrimaryDisplay();
EXPECT_EQ(0, display.GetWorkAreaInsets().right());
EXPECT_EQ(0, display.bounds().right() - display.work_area().right());
EXPECT_EQ(stable_work_area,
GetPrimaryWorkAreaInsets()->ComputeStableWorkArea());
}
// Verifies that the shelf looks the way it should after an alignment change.
// See crbug/1051824 .
TEST_F(ShelfLayoutManagerTest, ShelfWidgetLayoutUpdatedAfterAlignmentChange) {
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
ShelfWidget* shelf_widget = shelf->shelf_widget();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
shelf->SetAlignment(ShelfAlignment::kLeft);
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
gfx::Rect opaque_background_bounds =
shelf->shelf_widget()->GetOpaqueBackground()->bounds();
::wm::ConvertRectToScreen(shelf_widget->GetNativeWindow(),
&opaque_background_bounds);
int cross_axis_visible_pixels =
opaque_background_bounds.right() - display::Screen::GetScreen()
->GetPrimaryDisplay()
.bounds()
.left_center()
.x();
EXPECT_EQ(ShelfConfig::Get()->shelf_size(), cross_axis_visible_pixels);
shelf->SetAlignment(ShelfAlignment::kRight);
layout_manager->LayoutShelf();
opaque_background_bounds =
shelf->shelf_widget()->GetOpaqueBackground()->bounds();
::wm::ConvertRectToScreen(shelf_widget->GetNativeWindow(),
&opaque_background_bounds);
cross_axis_visible_pixels =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds().right() -
opaque_background_bounds.left_center().x();
EXPECT_EQ(ShelfConfig::Get()->shelf_size(), cross_axis_visible_pixels);
}
// Tests swipe gestures in a various of shelf alignments and shelf auto hide
// configurations.
TEST_F(ShelfLayoutManagerTest, GestureDrag) {
// Slop is an implementation detail of gesture recognition, and complicates
// these tests. Ignore it.
ui::GestureConfiguration::GetInstance()
->set_max_touch_move_in_pixels_for_click(0);
Shelf* shelf = GetPrimaryShelf();
{
SCOPED_TRACE("BOTTOM");
shelf->SetAlignment(ShelfAlignment::kBottom);
gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point bottom_center = shelf_bounds.bottom_center();
bottom_center.Offset(0, -1); // Make sure the point is inside shelf.
RunGestureDragTests(bottom_center, shelf_bounds.top_center());
GetAppListTestHelper()->WaitUntilIdle();
}
{
SCOPED_TRACE("LEFT");
shelf->SetAlignment(ShelfAlignment::kLeft);
gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point right_center = shelf_bounds.right_center();
right_center.Offset(-1, 0); // Make sure the point is inside shelf.
RunGestureDragTests(shelf_bounds.left_center(), right_center);
GetAppListTestHelper()->WaitUntilIdle();
}
{
SCOPED_TRACE("RIGHT");
shelf->SetAlignment(ShelfAlignment::kRight);
gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point right_center = shelf_bounds.right_center();
right_center.Offset(-1, 0); // Make sure the point is inside shelf.
RunGestureDragTests(right_center, shelf_bounds.left_center());
GetAppListTestHelper()->WaitUntilIdle();
}
}
// Tests that the shelf does not "overscroll", that is, dragging the shelf in
// does not bring it past its ideal bounds.
TEST_F(ShelfLayoutManagerTest, ShelfDoesNotOverscrollDuringGestureDragIn) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
// Note: A window must be visible in order to hide the shelf.
CreateTestWidget();
{
SCOPED_TRACE("BOTTOM");
shelf->SetAlignment(ShelfAlignment::kBottom);
gfx::Rect ideal_bounds = layout_manager->GetIdealBounds();
ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Scroll past the shelf's ideal bounds.
gfx::Point start = GetPrimaryDisplay().bounds().bottom_center();
StartScroll(start);
UpdateScroll(gfx::Vector2d(0, -ideal_bounds.height() - 50));
// The shelf should not extend past its ideal bounds.
EXPECT_EQ(ideal_bounds, shelf->GetShelfBoundsInScreen());
// End the scroll so as not to interfere with future tests.
EndScroll(/*is_fling=*/false, 0.f);
}
{
SCOPED_TRACE("LEFT");
shelf->SetAlignment(ShelfAlignment::kLeft);
gfx::Rect ideal_bounds = layout_manager->GetIdealBounds();
ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Scroll past the shelf's ideal bounds.
gfx::Point start = GetPrimaryDisplay().bounds().left_center();
StartScroll(start);
UpdateScroll(gfx::Vector2d(ideal_bounds.width() + 50, 0));
EXPECT_EQ(ideal_bounds, shelf->GetShelfBoundsInScreen());
// End the scroll so as not to interfere with future tests.
EndScroll(/*is_fling=*/false, 0.f);
}
{
SCOPED_TRACE("RIGHT");
shelf->SetAlignment(ShelfAlignment::kRight);
gfx::Rect ideal_bounds = layout_manager->GetIdealBounds();
ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Scroll past the shelf's ideal bounds.
gfx::Point start = GetPrimaryDisplay().bounds().right_center();
StartScroll(start);
UpdateScroll(gfx::Vector2d(-ideal_bounds.width() - 50, 0));
EXPECT_EQ(ideal_bounds, shelf->GetShelfBoundsInScreen());
// End the scroll so as not to interfere with future tests.
EndScroll(/*is_fling=*/false, 0.f);
}
}
// Swiping on shelf when fullscreen app list is opened should have no effect.
TEST_F(ShelfLayoutManagerTest, SwipingOnShelfIfAppListOpened) {
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->OnAppListVisibilityChanged(true, GetPrimaryDisplayId());
EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());
EXPECT_EQ(ShelfAutoHideBehavior::kNever, shelf->auto_hide_behavior());
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Note: A window must be visible in order to hide the shelf.
CreateTestWidget();
ui::test::EventGenerator* generator = GetEventGenerator();
constexpr base::TimeDelta kTimeDelta = base::Milliseconds(100);
constexpr int kNumScrollSteps = 4;
gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
// Swiping down on shelf when the fullscreen app list is opened
// should not hide the shelf.
gfx::Point end = start + gfx::Vector2d(0, 120);
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfAutoHideBehavior::kNever, shelf->auto_hide_behavior());
// Swiping left on shelf when the fullscreen app list is opened
// should not hide the shelf.
shelf->SetAlignment(ShelfAlignment::kLeft);
end = start + gfx::Vector2d(-120, 0);
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfAutoHideBehavior::kNever, shelf->auto_hide_behavior());
// Swiping right on shelf when the fullscreen app list is opened
// should not hide the shelf.
shelf->SetAlignment(ShelfAlignment::kRight);
end = start + gfx::Vector2d(120, 0);
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfAutoHideBehavior::kNever, shelf->auto_hide_behavior());
}
TEST_F(ShelfLayoutManagerTest, WindowVisibilityDisablesAutoHide) {
UpdateDisplay("800x600,800x600");
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Create a visible window so auto-hide behavior is enforced
views::Widget* dummy = CreateTestWidget();
// Window visible => auto hide behaves normally.
layout_manager->UpdateVisibilityState(/*force_layout=*/false);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Window minimized => auto hide disabled.
dummy->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Window closed => auto hide disabled.
dummy->CloseNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Multiple window test
views::Widget* window1 = CreateTestWidget();
views::Widget* window2 = CreateTestWidget();
// both visible => normal autohide
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// either minimzed => normal autohide
window2->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
window2->Restore();
window1->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// both minimized => disable auto hide
window2->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Test moving windows to/from other display.
window2->Restore();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Move to second display.
window2->SetBounds(gfx::Rect(850, 50, 50, 50));
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Move back to primary display.
window2->SetBounds(gfx::Rect(50, 50, 50, 50));
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Tests the shelf animates back to its original visible bounds when it is
// dragged down but there are no visible windows.
TEST_F(ShelfLayoutManagerTest,
ShelfAnimatesWhenGestureCompleteNoVisibleWindow) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
{
// Enable animations so that we can make sure that they occur.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
ui::test::EventGenerator* generator = GetEventGenerator();
gfx::Rect shelf_bounds_in_screen =
GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start(shelf_bounds_in_screen.CenterPoint());
gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
views::WidgetAnimationWaiter waiter(GetShelfWidget(), visible_bounds);
generator->GestureScrollSequence(start, end, base::Milliseconds(10), 5);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Wait for the animation to complete and check that it was valid.
waiter.WaitForAnimation();
EXPECT_TRUE(waiter.WasValidAnimation());
}
}
// Tests that the shelf animates to the visible bounds after a swipe up on
// the auto hidden shelf.
TEST_F(ShelfLayoutManagerTest, ShelfAnimatesToVisibleWhenGestureInComplete) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
// Create a visible window, otherwise the shelf will not hide.
CreateTestWidget();
// Get the bounds of the shelf when it is hidden.
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
{
// Enable the animations so that we can make sure they do occur.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
gfx::Point start = display.bounds().bottom_center();
gfx::Point end(
start.x(),
start.y() - (Shell::Get()->shelf_config()->shelf_size() - 1));
ui::test::EventGenerator* generator = GetEventGenerator();
views::WidgetAnimationWaiter waiter(GetShelfWidget(), visible_bounds);
generator->GestureScrollSequence(start, end, base::Milliseconds(10), 1);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
waiter.WaitForAnimation();
EXPECT_TRUE(waiter.WasValidAnimation());
}
}
// Tests that the shelf hide immediately without animation after a swipe down
// on the visible shelf to the bottom of the display bounds.
TEST_F(ShelfLayoutManagerTest,
ShelfHidesImmediatelyWhenGestureOutCompleteBelowTargetBounds) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Create a visible window, otherwise the shelf will not hide.
CreateTestWidget();
gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
{
// Enable the animations so that we can make sure they do occur.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
ui::test::EventGenerator* generator = GetEventGenerator();
// Show the shelf first.
SwipeUpOnShelf();
EXPECT_FALSE(GetShelfWidget()->GetLayer()->GetAnimator()->is_animating());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().top_center();
// Set the endpoint below the display bounds of the shelf widget.
gfx::Point endpoint_below_target(start.x(), start.y() + 100);
// Now swipe down to the endpoint.
generator->GestureScrollSequence(start, endpoint_below_target,
base::Milliseconds(10), 1);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Check that the shelf widget is moved back to the auto hidden bounds
// without animating.
EXPECT_FALSE(GetShelfWidget()->GetLayer()->GetAnimator()->is_animating());
EXPECT_EQ(auto_hidden_bounds, GetShelfWidget()->GetWindowBoundsInScreen());
}
}
// Tests that the shelf animates to the auto hidden bounds after a swipe down
// on the visible shelf to a point above the auto hidden bounds.
TEST_F(ShelfLayoutManagerTest,
ShelfAnimatesToHiddenWhenGestureOutCompleteAboveTargetBounds) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Create a visible window, otherwise the shelf will not hide.
CreateTestWidget();
gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
{
// Enable the animations so that we can make sure they do occur.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
ui::test::EventGenerator* generator = GetEventGenerator();
// Show the shelf first.
SwipeUpOnShelf();
EXPECT_FALSE(GetShelfWidget()->GetLayer()->GetAnimator()->is_animating());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().top_center();
// Set the end point to a point above the target bounds which is
// hidden_shelf_in_screen_portion pixels high.
const gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
gfx::Point endpoint_above_target = gfx::Point(
display_bounds.bottom_center().x(),
display_bounds.bottom_center().y() -
ShelfConfig::Get()->hidden_shelf_in_screen_portion() - 1);
// Now swipe down to the endpoint.
views::WidgetAnimationWaiter waiter2(GetShelfWidget(), auto_hidden_bounds);
generator->GestureScrollSequence(start, endpoint_above_target,
base::Milliseconds(10), 1);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
waiter2.WaitForAnimation();
// Check if the shelf widget is animated to the auto hidden bounds after the
// drag.
EXPECT_TRUE(waiter2.WasValidAnimation());
}
}
TEST_F(ShelfLayoutManagerTest, AutohideShelfForAutohideWhenActiveWindow) {
Shelf* shelf = GetPrimaryShelf();
views::Widget* widget_one = CreateTestWidget();
views::Widget* widget_two = CreateTestWidget();
aura::Window* window_two = widget_two->GetNativeWindow();
// Turn on hide_shelf_when_active behavior for window two - shelf should
// still be visible when window two is made active since it is not yet
// maximized.
widget_one->Activate();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
WindowState::Get(window_two)
->set_autohide_shelf_when_maximized_or_fullscreen(true);
widget_two->Activate();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Now the flag takes effect once window two is maximized.
widget_two->Maximize();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
// The hide_shelf_when_active flag should override the behavior of the
// hide_shelf_when_fullscreen flag even if the window is currently fullscreen.
WindowState::Get(window_two)->SetHideShelfWhenFullscreen(false);
widget_two->SetFullscreen(true);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
WindowState::Get(window_two)->Restore();
// With the flag off, shelf no longer auto-hides.
widget_one->Activate();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
WindowState::Get(window_two)
->set_autohide_shelf_when_maximized_or_fullscreen(false);
widget_two->Activate();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
WindowState::Get(window_two)
->set_autohide_shelf_when_maximized_or_fullscreen(true);
window_two->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
auto* shelf_window = shelf->GetWindow();
aura::Window* container = shelf_window->GetRootWindow()->GetChildById(
kShellWindowId_AlwaysOnTopContainer);
EXPECT_TRUE(base::Contains(container->children(), window_two));
widget_two->Maximize();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
}
TEST_F(ShelfLayoutManagerTest, ShelfFlickerOnTrayActivation) {
Shelf* shelf = GetPrimaryShelf();
// Create a visible window so auto-hide behavior is enforced.
CreateTestWidget();
// Turn on auto-hide for the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Show the status menu. That should make the shelf visible again.
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(
AcceleratorAction::kToggleSystemTrayBubble, {});
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_TRUE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
}
TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) {
// Make sure the shelf is always visible.
Shelf* shelf = GetPrimaryShelf();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
layout_manager->LayoutShelf();
views::Widget* widget_one = CreateTestWidget();
widget_one->Maximize();
views::Widget* widget_two = CreateTestWidget();
widget_two->Maximize();
widget_two->Activate();
// Both windows are maximized. They should be of the same size.
EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
widget_two->GetNativeWindow()->bounds().ToString());
int area_when_shelf_shown =
widget_one->GetNativeWindow()->bounds().size().GetArea();
// Now hide the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Both windows should be resized according to the shelf status.
EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
widget_two->GetNativeWindow()->bounds().ToString());
// Resized to small.
EXPECT_LT(area_when_shelf_shown,
widget_one->GetNativeWindow()->bounds().size().GetArea());
// Now show the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
// Again both windows should be of the same size.
EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
widget_two->GetNativeWindow()->bounds().ToString());
EXPECT_EQ(area_when_shelf_shown,
widget_one->GetNativeWindow()->bounds().size().GetArea());
}
TEST_F(ShelfLayoutManagerTest, BackgroundTypeWhenLockingScreen) {
// Creates a maximized window to have a background type other than default.
std::unique_ptr<aura::Window> window(CreateTestWindow());
window->Show();
wm::ActivateWindow(window.get());
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(ShelfBackgroundType::kMaximized,
GetShelfLayoutManager()->shelf_background_type());
Shell::Get()->lock_state_controller()->LockWithoutAnimation();
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
}
TEST_F(ShelfLayoutManagerTest, WorkspaceMask) {
std::unique_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
EXPECT_EQ(WorkspaceWindowState::kDefault, GetWorkspaceWindowState());
EXPECT_TRUE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
// Overlaps with shelf should not cause any specific behavior.
w1->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
EXPECT_EQ(WorkspaceWindowState::kDefault, GetWorkspaceWindowState());
EXPECT_TRUE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(WorkspaceWindowState::kFullscreen, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
std::unique_ptr<aura::Window> w2(CreateTestWindow());
w2->Show();
EXPECT_EQ(WorkspaceWindowState::kDefault, GetWorkspaceWindowState());
EXPECT_TRUE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
w2.reset();
EXPECT_EQ(WorkspaceWindowState::kFullscreen, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(WorkspaceWindowState::kDefault, GetWorkspaceWindowState());
EXPECT_TRUE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
}
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColor) {
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
std::unique_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(ShelfBackgroundType::kMaximized,
GetShelfLayoutManager()->shelf_background_type());
std::unique_ptr<aura::Window> w2(CreateTestWindow());
w2->Show();
wm::ActivateWindow(w2.get());
// Overlaps with shelf.
w2->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
// Still background is 'maximized'.
EXPECT_EQ(ShelfBackgroundType::kMaximized,
GetShelfLayoutManager()->shelf_background_type());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(ShelfBackgroundType::kMaximized,
GetShelfLayoutManager()->shelf_background_type());
std::unique_ptr<aura::Window> w3(CreateTestWindow());
w3->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
::wm::AddTransientChild(w1.get(), w3.get());
w3->Show();
wm::ActivateWindow(w3.get());
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_FALSE(GetNonLockScreenContainersContainerLayer()->GetMasksToBounds());
w3.reset();
w1.reset();
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
}
// Tests that the shelf background gets updated when the AppList stays open
// during the tablet mode transition with a visible window.
TEST_F(ShelfLayoutManagerTest, TabletModeTransitionWithAppListVisible) {
// Home Launcher requires an internal display.
display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
.SetFirstDisplayAsInternalDisplay();
// Show a window, which will later fill the whole screen.
std::unique_ptr<aura::Window> window(
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400)));
window->SetProperty(aura::client::kResizeBehaviorKey,
aura::client::kResizeBehaviorCanResize |
aura::client::kResizeBehaviorCanMaximize);
wm::ActivateWindow(window.get());
// Show the AppList over |window|.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
// Transition to tablet mode.
TabletModeControllerTestApi().EnterTabletMode();
// |window| should be maximized, and the shelf background should match the
// maximized state.
EXPECT_EQ(WorkspaceWindowState::kMaximized, GetWorkspaceWindowState());
EXPECT_EQ(ShelfBackgroundType::kInApp,
GetShelfLayoutManager()->shelf_background_type());
// Hiding the window should exit app mode.
window->Hide();
EXPECT_EQ(ShelfBackgroundType::kHomeLauncher,
GetShelfLayoutManager()->shelf_background_type());
}
// Verify that the auto-hide shelf has default background by default and still
// has the default background when a window is maximized in clamshell mode.
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorAutoHide) {
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
std::unique_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
}
// Verify that the shelf has a maximized background when a window is in the
// fullscreen state.
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorFullscreen) {
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
std::unique_ptr<aura::Window> w1(CreateTestWindow());
w1->Show();
wm::ActivateWindow(w1.get());
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
GetShelfLayoutManager()->shelf_background_type());
w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(ShelfBackgroundType::kMaximized,
GetShelfLayoutManager()->shelf_background_type());
}
// Verify the hit bounds of the status area extend to the edge of the shelf.
TEST_F(ShelfLayoutManagerTest, StatusAreaHitBoxCoversEdge) {
StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
ui::test::EventGenerator* generator = GetEventGenerator();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
gfx::Rect inset_display_bounds = display.bounds();
inset_display_bounds.Inset(gfx::Insets::TLBR(0, 0, 1, 1));
// Test bottom right pixel for bottom alignment.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kBottom);
generator->MoveMouseTo(inset_display_bounds.bottom_right());
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator->ClickLeftButton();
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
generator->ClickLeftButton();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
// Test bottom right pixel for right alignment.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kRight);
generator->MoveMouseTo(inset_display_bounds.bottom_right());
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator->ClickLeftButton();
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
generator->ClickLeftButton();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
// Test bottom left pixel for left alignment.
generator->MoveMouseTo(inset_display_bounds.bottom_left());
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kLeft);
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
generator->ClickLeftButton();
EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
generator->ClickLeftButton();
EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
}
// Tests that when the auto-hide behaviour is changed during an animation the
// target bounds are updated to reflect the new state.
TEST_F(ShelfLayoutManagerTest,
ShelfAutoHideToggleDuringAnimationUpdatesBounds) {
aura::Window* status_window =
GetShelfWidget()->status_area_widget()->GetNativeView();
gfx::Rect initial_bounds = status_window->bounds();
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlwaysHidden);
gfx::Rect hide_target_bounds = status_window->GetTargetBounds();
EXPECT_GT(hide_target_bounds.y(), initial_bounds.y());
GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
gfx::Rect reshow_target_bounds = status_window->GetTargetBounds();
EXPECT_EQ(initial_bounds, reshow_target_bounds);
}
// Tests that during shutdown, that window activation changes are properly
// handled, and do not crash (crbug.com/458768)
TEST_F(ShelfLayoutManagerTest, ShutdownHandlesWindowActivation) {
GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
aura::Window* window1 = CreateTestWindowInShellWithId(0);
window1->SetBounds(gfx::Rect(0, 0, 100, 100));
window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
window1->Show();
std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(0));
window2->SetBounds(gfx::Rect(0, 0, 100, 100));
window2->Show();
wm::ActivateWindow(window1);
GetShelfLayoutManager()->PrepareForShutdown();
// Deleting a focused maximized window will switch focus to |window2|. This
// would normally cause the ShelfLayoutManager to update its state. However
// during shutdown we want to handle this without crashing.
delete window1;
}
TEST_F(ShelfLayoutManagerTest, ShelfLayoutInUnifiedDesktop) {
Shell::Get()->display_manager()->SetUnifiedDesktopEnabled(true);
UpdateDisplay("500x400, 500x400");
// When the unified desktop is enabled, UpdateDisplay() adds a display so the
// shelf is recreated. Therefore, update the shelf related data members.
UpdateShelfRelatedMembers();
StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
EXPECT_TRUE(status_area_widget->IsVisible());
// Shelf should be in the first display's area.
gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen());
EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds));
EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right());
}
// Tests that tapping the home button is successful on the autohidden shelf.
TEST_F(ShelfLayoutManagerTest, PressHomeButtonOnAutoHideShelf) {
// Enable accessibility feature that forces home button to be shown even with
// kHideShelfControlsInTabletMode enabled.
Shell::Get()
->accessibility_controller()
->SetTabletModeShelfNavigationButtonsEnabled(true);
TabletModeControllerTestApi().EnterTabletMode();
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
const display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
// Create a window to hide the shelf in auto-hide mode.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
ShelfNavigationWidget::TestApi navigation_test_api(
shelf->navigation_widget());
ASSERT_TRUE(navigation_test_api.IsHomeButtonVisible());
// Wait for the back button to finish animating from behind the home button.
ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())
.RunMessageLoopUntilAnimationsDone(
navigation_test_api.GetBoundsAnimator());
// Press the home button with touch.
GetEventGenerator()->GestureTapAt(shelf->shelf_widget()
->navigation_widget()
->GetHomeButton()
->GetBoundsInScreen()
.CenterPoint());
// The app list should now be visible, and the window we created should hide.
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_FALSE(window->IsVisible());
}
// Tests that the auto-hide shelf has expected behavior when pressing the
// AppList button while the shelf is being dragged by gesture (see
// https://crbug.com/953877).
TEST_F(ShelfLayoutManagerTest, PressHomeBtnWhenAutoHideShelfBeingDragged) {
// Create a widget to hide the shelf in auto-hide mode.
CreateTestWidget();
GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_FALSE(GetPrimaryShelf()->IsVisible());
// Emulate to drag the shelf to show it.
gfx::Point gesture_location = display::Screen::GetScreen()
->GetPrimaryDisplay()
.bounds()
.bottom_center();
int delta_y = -1;
base::TimeTicks timestamp = base::TimeTicks::Now();
ui::GestureEvent start_event = ui::GestureEvent(
gesture_location.x(), gesture_location.y(), ui::EF_NONE, timestamp,
ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, delta_y));
GetShelfLayoutManager()->ProcessGestureEventOfAutoHideShelf(
&start_event, GetShelfWidget()->GetNativeView());
gesture_location.Offset(0, delta_y);
// Ensure that Shelf is higher than the default height, required by the bug
// reproduction procedures.
delta_y = -ShelfConfig::Get()->shelf_size() - 1;
timestamp += base::Milliseconds(200);
ui::GestureEvent update_event = ui::GestureEvent(
gesture_location.x(), gesture_location.y(), ui::EF_NONE, timestamp,
ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 0, delta_y));
GetShelfLayoutManager()->ProcessGestureEventOfAutoHideShelf(
&update_event, GetShelfWidget()->GetNativeView());
// Emulate to press the AppList button while dragging the Shelf.
PressHomeButton();
EXPECT_TRUE(GetPrimaryShelf()->IsVisible());
// Release the press.
delta_y -= 1;
gesture_location.Offset(0, delta_y);
timestamp += base::Milliseconds(200);
ui::GestureEvent scroll_end_event = ui::GestureEvent(
gesture_location.x(), gesture_location.y(), ui::EF_NONE, timestamp,
ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END));
GetShelfLayoutManager()->ProcessGestureEventOfAutoHideShelf(
&scroll_end_event, GetShelfWidget()->GetNativeView());
ui::GestureEvent gesture_end_event =
ui::GestureEvent(gesture_location.x(), gesture_location.y(), ui::EF_NONE,
timestamp, ui::GestureEventDetails(ui::ET_GESTURE_END));
GetShelfLayoutManager()->ProcessGestureEventOfAutoHideShelf(
&gesture_end_event, GetShelfWidget()->GetNativeView());
// Press the AppList button to hide the AppList and Shelf. Check the following
// things:
// (1) Shelf is hidden
// (2) Shelf has correct bounds in screen coordinates.
PressHomeButton();
EXPECT_EQ(
GetScreenAvailableBounds().bottom_left() +
gfx::Point(0, -ShelfConfig::Get()->hidden_shelf_in_screen_portion())
.OffsetFromOrigin(),
GetPrimaryShelf()->shelf_widget()->GetWindowBoundsInScreen().origin());
EXPECT_FALSE(GetPrimaryShelf()->IsVisible());
}
// Tests that the shelf has expected bounds when dragging the shelf by gesture
// and pressing the AppList button by mouse during drag (see
// https://crbug.com/968768).
TEST_F(ShelfLayoutManagerTest, MousePressAppListBtnWhenShelfBeingDragged) {
// Drag the shelf upward. Notice that in order to drag shelf instead of
// AppList from shelf, we need to drag the shelf downward a little bit then
// upward. Because the bug is related with RootView, the event should be sent
// through the shelf widget.
gfx::Point gesture_location =
GetPrimaryShelf()->GetShelfViewForTesting()->bounds().CenterPoint();
int delta_y = 1;
base::TimeTicks timestamp = base::TimeTicks::Now();
ui::GestureEvent start_event = ui::GestureEvent(
gesture_location.x(), gesture_location.y(), ui::EF_NONE, timestamp,
ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, delta_y));
GetPrimaryShelf()->shelf_widget()->OnGestureEvent(&start_event);
delta_y = -5;
timestamp += base::Milliseconds(200);
ui::GestureEvent update_event = ui::GestureEvent(
gesture_location.x(), gesture_location.y(), ui::EF_NONE, timestamp,
ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 0, delta_y));
GetPrimaryShelf()->shelf_widget()->OnGestureEvent(&update_event);
// Press the AppList button by mouse.
views::View* home_button =
GetPrimaryShelf()->navigation_widget()->GetHomeButton();
GetEventGenerator()->MoveMouseTo(
home_button->GetBoundsInScreen().CenterPoint());
GetEventGenerator()->ClickLeftButton();
// End the gesture event.
delta_y -= 1;
gesture_location.Offset(0, delta_y);
timestamp += base::Milliseconds(200);
ui::GestureEvent scroll_end_event = ui::GestureEvent(
gesture_location.x(), gesture_location.y(), ui::EF_NONE, timestamp,
ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END));
GetPrimaryShelf()->shelf_widget()->OnGestureEvent(&scroll_end_event);
// Verify that the shelf has expected bounds.
EXPECT_EQ(
GetScreenAvailableBounds().bottom_left() +
gfx::Point(0, -ShelfConfig::Get()->shelf_size()).OffsetFromOrigin(),
GetPrimaryShelf()->shelf_widget()->GetWindowBoundsInScreen().origin());
}
// Tests that tap outside of the AUTO_HIDE_SHOWN shelf should hide it.
TEST_F(ShelfLayoutManagerTest, TapOutsideOfAutoHideShownShelf) {
views::Widget* widget = CreateTestWidget();
Shelf* shelf = GetPrimaryShelf();
ui::test::EventGenerator* generator = GetEventGenerator();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
aura::Window* window = widget->GetNativeWindow();
gfx::Rect window_bounds = window->GetBoundsInScreen();
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap outside the window and AUTO_HIDE_SHOWN shelf should hide the shelf.
gfx::Point tap_location =
window_bounds.bottom_right() + gfx::Vector2d(10, 10);
generator->GestureTapAt(tap_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
SwipeUpOnShelf();
// Tap inside the AUTO_HIDE_SHOWN shelf should not hide the shelf.
gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
tap_location = gfx::Point(shelf_bounds.CenterPoint());
generator->GestureTapAt(tap_location);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap inside the window should still hide the shelf.
tap_location = window_bounds.origin() + gfx::Vector2d(10, 10);
generator->GestureTapAt(tap_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
SwipeUpOnShelf();
// Tap the system tray that inside the status area should not hide the shelf
// but open the systrem tray bubble.
generator->GestureTapAt(
GetPrimaryUnifiedSystemTray()->GetBoundsInScreen().CenterPoint());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_TRUE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
}
// Tests that swiping up on the AUTO_HIDE_HIDDEN shelf, with various speeds,
// offsets, and angles, always shows the shelf.
TEST_F(ShelfLayoutManagerTest, SwipeUpAutoHideHiddenShelf) {
ui::test::EventGenerator* generator = GetEventGenerator();
Shelf* shelf = GetPrimaryShelf();
// Create a window so that the shelf will hide.
const aura::Window* window = CreateTestWidget()->GetNativeWindow();
const gfx::Point tap_to_hide_shelf_location =
window->GetBoundsInScreen().CenterPoint();
const gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
const int time_deltas[] = {10, 50, 100, 500};
const int num_scroll_steps[] = {2, 5, 10, 50};
const int x_offsets[] = {10, 20, 50};
const int y_offsets[] = {70, 100, 300, 500};
for (int time_delta : time_deltas) {
for (int scroll_steps : num_scroll_steps) {
for (int x_offset : x_offsets) {
for (int y_offset : y_offsets) {
const gfx::Point start(display_bounds.bottom_center());
const gfx::Point end(start + gfx::Vector2d(x_offset, -y_offset));
generator->GestureScrollSequence(
start, end, base::Milliseconds(time_delta), scroll_steps);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState())
<< "Failure to show shelf after a swipe up in " << time_delta
<< "ms, " << scroll_steps << " steps, " << x_offset
<< " X-offset and " << y_offset << " Y-offset.";
generator->GestureTapAt(tap_to_hide_shelf_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
}
}
}
}
// Tests the auto-hide shelf status when moving the mouse in and out.
TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnMouseMove) {
// Create one window, or the shelf won't auto-hide.
CreateTestWidget();
Shelf* shelf = GetPrimaryShelf();
ui::test::EventGenerator* generator = GetEventGenerator();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
// Set the shelf to auto-hide.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Swipe up to show the shelf.
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Move the mouse far away from the shelf, but without having been on the
// shelf first. This isn't technically a mouse-out event, so the shelf should
// not hide.
generator->MoveMouseTo(0, 0);
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Now place the mouse on the shelf, then move away. The shelf should hide.
generator->MoveMouseTo(1, display.bounds().bottom() - 1);
generator->MoveMouseTo(0, 0);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Now let's show the shelf again.
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Move the mouse away, but move it back within the shelf immediately. The
// shelf should remain shown.
generator->MoveMouseTo(0, 0);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
generator->MoveMouseTo(1, display.bounds().bottom() - 1);
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
// Verifies that after showing the system tray by shortcut, the shelf item still
// responds to the gesture event. (see https://crbug.com/921182)
TEST_F(ShelfLayoutManagerTest, ShelfItemRespondToGestureEvent) {
// Prepare for the auto-hide shelf test.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
Shelf* shelf = GetPrimaryShelf();
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(0, 0);
ShelfTestUtil::AddAppShortcut("app_id", TYPE_APP);
ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())
.RunMessageLoopUntilAnimationsDone();
// Turn on the auto-hide mode for shelf. Check the initial states.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Show the system tray with the shortcut. Expect that the shelf is shown
// after triggering the accelerator.
PressAndReleaseKey(ui::VKEY_S, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap on the shelf button. Expect that the shelf button responds to gesture
// events.
base::UserActionTester user_action_tester;
user_action_tester.ResetCounts();
views::View* button = GetPrimaryShelf()
->GetShelfViewForTesting()
->first_visible_button_for_testing();
gfx::Point shelf_btn_center = button->GetBoundsInScreen().CenterPoint();
generator->GestureTapAt(shelf_btn_center);
EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_ClickOnApp"));
}
// Tests the auto-hide shelf status with mouse events.
TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnMouseEvents) {
views::Widget* widget = CreateTestWidget();
widget->Maximize();
Shelf* shelf = GetPrimaryShelf();
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(0, 0);
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Swipe up to show the auto-hide shelf.
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Move the mouse should not hide the AUTO_HIDE_SHOWN shelf immediately.
generator->MoveMouseTo(5, 5);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Mouse press outside the shelf should hide the AUTO_HIDE_SHOWN shelf.
generator->PressLeftButton();
generator->ReleaseLeftButton();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Move the mouse to the position which is contained by the bounds of the
// shelf when it is visible should show the auto-hide shelf.
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
const int display_bottom = display.bounds().bottom();
generator->MoveMouseTo(1, display_bottom - 1);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Mouse press inside the shelf should not hide the AUTO_HIDE_SHOWN shelf.
generator->MoveMouseTo(
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint());
generator->PressLeftButton();
generator->ReleaseLeftButton();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Mouse press the system tray should open the system tray bubble.
generator->MoveMouseTo(
GetPrimaryUnifiedSystemTray()->GetBoundsInScreen().CenterPoint());
generator->PressLeftButton();
generator->ReleaseLeftButton();
EXPECT_TRUE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
}
// Tests that tap shelf item in auto-hide shelf should do nothing.
TEST_F(ShelfLayoutManagerTest, TapShelfItemInAutoHideShelf) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Create a normal unmaximized window; the shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Tap home button should not open the app list and shelf should keep
// hidden.
gfx::Rect home_button_bounds = shelf->shelf_widget()
->navigation_widget()
->GetHomeButton()
->GetBoundsInScreen();
gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
home_button_bounds.Intersect(display_bounds);
GetEventGenerator()->GestureTapAt(home_button_bounds.CenterPoint());
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Tests the a11y feedback for entering/exiting fullscreen workspace state.
TEST_F(ShelfLayoutManagerTest, A11yAlertOnWorkspaceState) {
TestAccessibilityControllerClient client;
std::unique_ptr<aura::Window> window1(
AshTestBase::CreateToplevelTestWindow());
std::unique_ptr<aura::Window> window2(
AshTestBase::CreateToplevelTestWindow());
EXPECT_NE(AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED,
client.last_a11y_alert());
// Toggle the current normal window in workspace to fullscreen should send the
// ENTERED alert.
const WMEvent fullscreen(WM_EVENT_TOGGLE_FULLSCREEN);
WindowState* window_state2 = WindowState::Get(window2.get());
window_state2->OnWMEvent(&fullscreen);
EXPECT_TRUE(window_state2->IsFullscreen());
EXPECT_EQ(AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED,
client.last_a11y_alert());
// Toggle the current fullscreen'ed window in workspace to exit fullscreen
// should send the EXITED alert.
window_state2->OnWMEvent(&fullscreen);
EXPECT_FALSE(window_state2->IsFullscreen());
EXPECT_EQ(AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_EXITED,
client.last_a11y_alert());
// Fullscreen the |window2| again to prepare for the following tests.
window_state2->OnWMEvent(&fullscreen);
EXPECT_TRUE(window_state2->IsFullscreen());
EXPECT_EQ(AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED,
client.last_a11y_alert());
// Changes the current window in workspace from a fullscreen window to a
// normal window should send the EXITD alert.
window_state2->Minimize();
EXPECT_EQ(AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_EXITED,
client.last_a11y_alert());
// Changes the current window in workspace from a normal window to fullscreen
// window should send ENTERED alert.
window_state2->Unminimize();
EXPECT_TRUE(window_state2->IsFullscreen());
EXPECT_EQ(AccessibilityAlert::WORKSPACE_FULLSCREEN_STATE_ENTERED,
client.last_a11y_alert());
}
// Verifies the auto-hide shelf is shown if there is only a single PIP window.
TEST_F(ShelfLayoutManagerTest, AutoHideShelfShownForSinglePipWindow) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Create a PIP window.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
// Set always on top so it is put in the PIP container.
window->SetProperty(aura::client::kZOrderingKey,
ui::ZOrderLevel::kFloatingWindow);
window->Show();
const WMEvent pip_event(WM_EVENT_PIP);
WindowState::Get(window)->OnWMEvent(&pip_event);
Shelf::UpdateShelfVisibility();
// Expect the shelf to be hidden.
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
// Verifies that shelf components are placed properly in right-to-left UI.
TEST_F(ShelfLayoutManagerTest, RtlPlacement) {
// Helper function to check that the given widget is placed symmetrically
// between LTR and RTL.
auto check_mirrored_placement = [](views::Widget* widget) {
base::i18n::SetICUDefaultLocale("en");
EXPECT_FALSE(base::i18n::IsRTL());
GetShelfLayoutManager()->LayoutShelf();
const int ltr_left_position =
widget->GetNativeWindow()->GetBoundsInScreen().x();
base::i18n::SetICUDefaultLocale("ar");
EXPECT_TRUE(base::i18n::IsRTL());
GetShelfLayoutManager()->LayoutShelf();
const int rtl_right_position =
widget->GetNativeWindow()->GetBoundsInScreen().right();
EXPECT_EQ(
GetShelfWidget()->GetWindowBoundsInScreen().width() - ltr_left_position,
rtl_right_position);
};
const std::string locale = base::i18n::GetConfiguredLocale();
ShelfWidget* shelf_widget = GetPrimaryShelf()->shelf_widget();
check_mirrored_placement(shelf_widget->navigation_widget());
check_mirrored_placement(shelf_widget->status_area_widget());
check_mirrored_placement(shelf_widget);
// Reset the lauguage setting.
base::i18n::SetICUDefaultLocale(locale);
}
// Tests the auto-hide shelf status when opening and closing a context menu.
TEST_F(ShelfLayoutManagerTest, AutoHideShelfWithContextMenu) {
// Create one window, or the shelf won't auto-hide.
CreateTestWidget();
// Set the shelf to auto-hide.
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Create an app that we can use to pull up a context menu.
EXPECT_EQ(0u,
ShelfViewTestAPI(shelf->GetShelfViewForTesting()).GetButtonCount());
AddApp();
EXPECT_EQ(1u,
ShelfViewTestAPI(shelf->GetShelfViewForTesting()).GetButtonCount());
// Swipe up to show the shelf.
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Open hotseat context menu.
ui::test::EventGenerator* generator = GetEventGenerator();
ShelfAppButton* clickable_app_button =
ShelfViewTestAPI(shelf->GetShelfViewForTesting()).GetButton(0);
EXPECT_TRUE(clickable_app_button);
EXPECT_FALSE(shelf->shelf_widget()->IsShowingMenu());
generator->MoveMouseTo(
clickable_app_button->GetBoundsInScreen().CenterPoint());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
generator->ClickRightButton();
EXPECT_TRUE(shelf->shelf_widget()->IsShowingMenu());
// Close the context menu with the mouse over the shelf. The shelf should
// remain shown.
generator->ClickRightButton();
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_FALSE(shelf->shelf_widget()->IsShowingMenu());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Reopen hotseat context menu.
generator->ClickRightButton();
EXPECT_TRUE(shelf->shelf_widget()->IsShowingMenu());
// Mouse away from the shelf with the context menu still showing. The shelf
// should remain shown.
generator->MoveMouseTo(0, 0);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Close the context menu with the mouse away from the shelf. The shelf
// should hide.
generator->ClickRightButton();
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_FALSE(shelf->shelf_widget()->IsShowingMenu());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
namespace {
class DragTestView : public views::View {
public:
DragTestView() = default;
DragTestView(const DragTestView&) = delete;
DragTestView& operator=(const DragTestView&) = delete;
~DragTestView() override = default;
int DragThreshold() { return views::View::GetVerticalDragThreshold(); }
private:
// views::View:
int GetDragOperations(const gfx::Point& press_pt) override {
return ui::DragDropTypes::DRAG_COPY;
}
void WriteDragData(const gfx::Point& p, OSExchangeData* data) override {
gfx::ImageSkiaRep image_rep(gfx::Size(1, 1), 1.0f);
gfx::ImageSkia image_skia(image_rep);
data->provider().SetDragImage(image_skia, gfx::Vector2d());
}
};
enum class DragEventType {
kMouse,
kGesture,
};
} // namespace
// Shelf tests parametrized to perform drags using mouse and gesture events.
class ShelfLayoutManagerDragDropTest
: public ShelfLayoutManagerTestBase,
public testing::WithParamInterface<DragEventType> {
public:
ShelfLayoutManagerDragDropTest() = default;
void SetUp() override {
ShelfLayoutManagerTestBase::SetUp();
auto* drag_drop_controller =
static_cast<DragDropController*>(aura::client::GetDragDropClient(
GetPrimaryShelf()->GetWindow()->GetRootWindow()));
drag_drop_controller->set_should_block_during_drag_drop(false);
generator_ = GetEventGenerator();
}
// Moves to `view` and mouse/gesture presses it. Does not actually start
// dragging `view` to a different location.
void StartDrag(DragTestView* view) {
if (GetParam() == DragEventType::kMouse) {
generator_->MoveMouseTo(view->GetBoundsInScreen().origin());
generator_->PressLeftButton();
} else {
generator_->PressTouch(view->GetBoundsInScreen().origin());
ui::GestureEvent long_press(
generator_->current_screen_location().x(),
generator_->current_screen_location().y(), ui::EF_NONE,
ui::EventTimeForNow(),
ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
generator_->Dispatch(&long_press);
}
}
// Drags a view vertically by `dy` pixels. Assumes the drag has been started.
void MoveDragBy(int dy) {
auto move_fn =
base::BindRepeating(GetParam() == DragEventType::kMouse
? &ui::test::EventGenerator::MoveMouseBy
: &ui::test::EventGenerator::MoveTouchBy,
base::Unretained(generator_));
const int step = dy / abs(dy);
for (int i = 0; i < abs(dy); ++i) {
move_fn.Run(0, step);
}
}
// Releases the mouse/gesture press that started a drag, possibly triggering
// a drop.
void EndDrag() {
if (GetParam() == DragEventType::kMouse) {
generator_->ReleaseLeftButton();
} else {
generator_->ReleaseTouch();
}
}
private:
raw_ptr<ui::test::EventGenerator, DanglingUntriaged | ExperimentalAsh>
generator_;
};
INSTANTIATE_TEST_SUITE_P(All,
ShelfLayoutManagerDragDropTest,
testing::Values(DragEventType::kMouse,
DragEventType::kGesture));
// Tests the auto-hide shelf status with drag-drop events.
TEST_P(ShelfLayoutManagerDragDropTest, AutoHideShelfOnDragDropEvents) {
// Create one window, or the shelf won't auto-hide.
std::unique_ptr<views::Widget> widget = CreateFramelessTestWidget();
// Set the shelf to auto-hide.
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Create draggable view.
DragTestView* view =
widget->SetContentsView(std::make_unique<DragTestView>());
const int drag_distance =
view->DragThreshold() + layout_manager->GetIdealBounds().height();
auto bounds = gfx::Rect(
0, GetShelfWidget()->GetVisibleShelfBounds().y() - drag_distance, 1, 1);
// `DragDropController` applies a vertical offset when determining the target
// view for touch-initiated dragging, so we compensate for that here.
if (GetParam() == DragEventType::kGesture)
bounds.Offset(0, /*DragDropController::kTouchDragImageVerticalOffset=*/25);
widget->SetBounds(bounds);
// Drag a view to make the shelf appear.
StartDrag(view);
MoveDragBy(drag_distance);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Drag a view away to make the shelf disappear.
MoveDragBy(-drag_distance);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Drag a view to make the shelf reappear (make sure all state has reset).
MoveDragBy(drag_distance);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// End the drag with mouse over the shelf, so the shelf should stay shown.
EndDrag();
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_EQ(GetParam() == DragEventType::kMouse ? SHELF_AUTO_HIDE_SHOWN
: SHELF_AUTO_HIDE_HIDDEN,
shelf->GetAutoHideState());
// Move pointer away to make the shelf disappear.
StartDrag(view);
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Drag a view to make the shelf reappear (make sure all state has reset).
MoveDragBy(drag_distance);
ASSERT_TRUE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Verify that dragging does nothing when the shelf is not in auto-hide mode.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
MoveDragBy(-drag_distance);
MoveDragBy(drag_distance);
ASSERT_FALSE(TriggerAutoHideTimeout());
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// If the dragging had been observed, the shelf would be shown.
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// TODO(crbug.com/1240332): Test screen exits when behavior is consistent.
}
// Tests that the shelf background does not change when the bubble launcher is
// shown.
TEST_F(ShelfLayoutManagerTest, NoBackgroundChange) {
const auto shelf_background_type =
GetShelfLayoutManager()->shelf_background_type();
AppListControllerImpl* app_list_controller =
Shell::Get()->app_list_controller();
// Show the AppListBubble, test that the shelf background has not changed.
PressHomeButton();
ASSERT_TRUE(app_list_controller->IsVisible());
EXPECT_EQ(shelf_background_type,
GetShelfLayoutManager()->shelf_background_type());
// Hide the bubble, test that the shelf background has still not changed.
PressHomeButton();
ASSERT_FALSE(app_list_controller->IsVisible());
EXPECT_EQ(shelf_background_type,
GetShelfLayoutManager()->shelf_background_type());
}
// Tests that tapping the home button is successful on the autohidden shelf.
//
// TODO(crbug.com/1418325): Test is flaky.
TEST_F(ShelfLayoutManagerTest,
DISABLED_NoTemporaryAutoHideStateWhileOpeningLauncher) {
// Enable animations and simulate the zero state search called when showing
// the launcher.
ui::ScopedAnimationDurationScaleMode duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
GetTestAppListClient()->set_run_zero_state_callback_immediately(false);
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
const display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
// Create a window to hide the shelf in auto-hide mode.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
{
AutoHideStateDetector detector;
// Open the launcher by tapping the home button.
GestureTapOn(GetPrimaryShelf()->navigation_widget()->GetHomeButton());
// Wait until the zero state callback is called.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, GetTestAppListClient()->zero_state_search_done_count());
// No `SHELF_AUTO_HIDE_HIDDEN` should be set when launcher is showing.
EXPECT_FALSE(detector.WasShelfAutoHidden());
}
// The app list should now be visible.
GetAppListTestHelper()->CheckVisibility(true);
}
class ShelfLayoutManagerWindowDraggingTest : public ShelfLayoutManagerTestBase {
public:
ShelfLayoutManagerWindowDraggingTest() = default;
~ShelfLayoutManagerWindowDraggingTest() override = default;
// ShelfLayoutManagerTestBase:
void SetUp() override {
ShelfLayoutManagerTestBase::SetUp();
TabletModeControllerTestApi().EnterTabletMode();
base::RunLoop().RunUntilIdle();
}
bool IsWindowDragInProgress() {
return GetShelfLayoutManager()->IsWindowDragInProgress();
}
};
// Test that when swiping up on the shelf, we may or may not drag up the MRU
// window.
TEST_F(ShelfLayoutManagerWindowDraggingTest, DraggedMRUWindow) {
const int shelf_widget_height =
GetShelfWidget()->GetWindowBoundsInScreen().height();
const int shelf_widget_bottom =
GetShelfWidget()->GetWindowBoundsInScreen().bottom();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
const struct TestCase {
// The shelf widget whose bounds are used as the base for gesture start and
// end locations.
raw_ptr<const views::Widget, ExperimentalAsh> widget;
// Whether the widget bounds are completely in the left part of the split
// view.
const bool left_in_split_view;
// Whether the widget bounds are completely in the right part of the split
// view.
const bool right_in_split_view;
const std::string description;
} test_cases[] = {
{GetShelfWidget(), false /*left_in_split_view*/,
false /*right_in_split_view*/, "Shelf widget"},
{GetPrimaryShelf()->navigation_widget(), true /*left_in_split_view*/,
false /*right_in_split_view*/, "Navigation widget"},
{GetShelfWidget()->status_area_widget(), false /*left_in_split_view*/,
true /*right_in_split_view*/, "Status area widget"}};
for (const auto& test_case : test_cases) {
SCOPED_TRACE(test_case.description);
ASSERT_TRUE(!test_case.left_in_split_view ||
!test_case.right_in_split_view);
// Starts the drag from the center of the shelf's bottom.
const gfx::Rect widget_bounds = test_case.widget->GetWindowBoundsInScreen();
// NOTE: Navigation widget might have zero size (depending on whether
// home and back buttons are shown) - use the shelf widget bottom value to
// ensure the drag starts from the bottom of the shelf.
gfx::Point start(widget_bounds.CenterPoint().x(), shelf_widget_bottom);
StartScroll(start);
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
// We need at least one window to work with.
EXPECT_FALSE(IsWindowDragInProgress());
EndScroll(/*is_fling=*/false, 0.f);
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
StartScroll(start);
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
DragWindowFromShelfController* window_drag_controller =
GetShelfLayoutManager()->window_drag_controller_for_testing();
EXPECT_TRUE(IsWindowDragInProgress());
EXPECT_EQ(window_drag_controller->dragged_window(), window.get());
UpdateScroll(gfx::Vector2d(0, -shelf_widget_height - hotseat_size));
EXPECT_FALSE(window->transform().IsIdentityOrTranslation());
EXPECT_TRUE(window->transform().IsScaleOrTranslation());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
// The window needs to be visible to drag up.
window->Hide();
StartScroll(start);
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
// In splitview, depends on the drag position, the active dragged window
// might be different.
window->Show();
auto window2 = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
SplitViewController* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(
window.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller->SnapWindow(
window2.get(), SplitViewController::SnapPosition::kSecondary);
StartScroll(gfx::Point(widget_bounds.x(), shelf_widget_bottom));
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
window_drag_controller =
GetShelfLayoutManager()->window_drag_controller_for_testing();
EXPECT_TRUE(IsWindowDragInProgress());
aura::Window* drag_window =
test_case.right_in_split_view ? window2.get() : window.get();
EXPECT_EQ(window_drag_controller->dragged_window(), drag_window);
// No window transform at the point where the window drag starts.
EXPECT_TRUE(drag_window->transform().IsIdentity());
// The window is expected to be scaled down as the drag progresses.
UpdateScroll(gfx::Vector2d(0, -10));
EXPECT_FALSE(drag_window->transform().IsIdentityOrTranslation());
EXPECT_TRUE(drag_window->transform().IsScaleOrTranslation());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(drag_window->transform().IsIdentity());
StartScroll(gfx::Point(widget_bounds.right(), shelf_widget_bottom));
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
window_drag_controller =
GetShelfLayoutManager()->window_drag_controller_for_testing();
EXPECT_TRUE(IsWindowDragInProgress());
drag_window = test_case.left_in_split_view ? window.get() : window2.get();
EXPECT_EQ(window_drag_controller->dragged_window(), drag_window);
EXPECT_FALSE(drag_window->transform().IsIdentityOrTranslation());
EXPECT_TRUE(drag_window->transform().IsScaleOrTranslation());
EndScroll(/*is_fling=*/false, 0.f);
split_view_controller->EndSplitView();
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EXPECT_TRUE(window2->transform().IsIdentity());
}
}
// Tests that downward swipe on shelf does not start window drag.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
DownwardSwipeDoesnotStartWnidowDrag) {
// Starts the drag from the center of the shelf's bottom.
const gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start = shelf_bounds.top_center();
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
// Tests that downward swipe on shelf does not start window drag, nor change
// the window transform when hotseat is hidden.
ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
StartScroll(start);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, shelf_bounds.height() / 2));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, shelf_bounds.height() / 2));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
// Tests that downward swipe on shelf does not start window drag, nor change
// the window transform when hotseat is extended.
SwipeUpOnShelf();
ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
StartScroll(start);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, shelf_bounds.height() / 2));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, shelf_bounds.height() / 2));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
}
// Test that drag from shelf when overview is active is a no-op.
TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpInOverview) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
std::unique_ptr<aura::Window> window2 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window1.get());
// Starts the drag from the center of the shelf's bottom.
EnterOverview();
gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EndScroll(/*is_fling=*/false, 0.f);
// In splitview + overview case, drag from shelf in the overview side of the
// screen also does nothing.
SplitViewController* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(
window1.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller->SnapWindow(
window2.get(), SplitViewController::SnapPosition::kSecondary);
EnterOverview();
EXPECT_TRUE(split_view_controller->InSplitViewMode());
EXPECT_TRUE(OverviewController::Get()->InOverviewSession());
StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EndScroll(/*is_fling=*/false, 0.f);
}
// Test that upward fling to exit overview mode does not cause the shelf to
// animate if we are in kShownHomeLauncher.
TEST_F(ShelfLayoutManagerWindowDraggingTest, SwipeToExitOverview) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
// Hide |window1| so we remain in kShownHomeLauncher when we enter overview.
window1->Hide();
EXPECT_EQ(HotseatState::kShownHomeLauncher, GetHotseatWidget()->state());
EnterOverview();
GetHotseatWidget()->SetState(HotseatState::kShownHomeLauncher);
const gfx::Rect hotseat_bounds = GetHotseatWidget()->GetTargetBounds();
// Fling up from the center of the shelf's bottom.
StartScroll(shelf_widget_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
// Hotseat should move as it is in the |kShownHomeLauncher| state.
EXPECT_EQ(hotseat_bounds, GetHotseatWidget()->GetTargetBounds());
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
// We should exit overview mode after completing the fling gesture.
EXPECT_FALSE(OverviewController::Get()->InOverviewSession());
}
// Test that upward fling in overview transitions from overview to home.
TEST_F(ShelfLayoutManagerWindowDraggingTest, FlingInOverview) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window1.get());
EnterOverview();
base::HistogramTester histogram_tester;
HotseatStateWatcher watcher(GetShelfLayoutManager());
// Fling up from the center of the shelf's bottom.
StartScroll(shelf_widget_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_FALSE(OverviewController::Get()->InOverviewSession());
watcher.WaitUntilStateChanged();
watcher.CheckEqual({HotseatState::kShownHomeLauncher});
histogram_tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kFlingUpToShowHomeScreen, 1);
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 0);
}
// Test that upward fling in overview transitions from home shelf overview to
// home.
TEST_F(ShelfLayoutManagerWindowDraggingTest, FlingInOverviewHomeShelf) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
// This will ensure we enter overview in home shelf mode.
WindowState::Get(window1.get())->Minimize();
OverviewController* overview_controller = OverviewController::Get();
EnterOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
base::HistogramTester histogram_tester;
// Fling up from the center of the shelf's bottom.
StartScroll(shelf_widget_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
// Exit overview session.
EXPECT_FALSE(overview_controller->InOverviewSession());
histogram_tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kFlingUpToShowHomeScreen, 1);
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 0);
}
// Test that upward fling in split mode on overview side shows hotseat and
// remains in split view is the swipe is short.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
FlingToShowHotseatInSplitModeWithOverview) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
std::unique_ptr<aura::Window> window2 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
SplitViewController* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(
window1.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller->SnapWindow(
window2.get(), SplitViewController::SnapPosition::kSecondary);
OverviewController* overview_controller = OverviewController::Get();
base::HistogramTester histogram_tester;
HotseatStateWatcher watcher(GetShelfLayoutManager());
// Short fling (little longer than the drag required to show the extended
// hotseat).
StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(gfx::Vector2d(
0, -shelf_size - 1.5f * hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_TRUE(split_view_controller->InSplitViewMode());
watcher.CheckEqual({HotseatState::kExtended});
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 1);
// The same fling gesture should transition to overview since the hotseat is
// in extended state.
StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(gfx::Vector2d(
0, -shelf_size - 1.5f * hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_TRUE(split_view_controller->InSplitViewMode());
watcher.CheckEqual({HotseatState::kExtended});
// The same fling gesture should transition to home since overview mode
// is active.
StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(gfx::Vector2d(
0, -shelf_size - 1.5f * hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_FALSE(split_view_controller->InSplitViewMode());
watcher.WaitUntilStateChanged();
watcher.CheckEqual(
{HotseatState::kExtended, HotseatState::kShownHomeLauncher});
histogram_tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kFlingUpToShowHomeScreen, 1);
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 1);
}
// Test that upward fling in split mode on overview side transitions to home, if
// the swipe length is long enough.
TEST_F(ShelfLayoutManagerWindowDraggingTest, FlingHomeInSplitModeWithOverview) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
std::unique_ptr<aura::Window> window2 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
SplitViewController* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(
window1.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller->SnapWindow(
window2.get(), SplitViewController::SnapPosition::kSecondary);
OverviewController* overview_controller = OverviewController::Get();
EnterOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
base::HistogramTester histogram_tester;
HotseatStateWatcher watcher(GetShelfLayoutManager());
// Longer fling, one that significantly exceeds the distance required to show
// the hotseat (by 2 hotseat heights).
StartScroll(shelf_widget_bounds.bottom_right());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - 3 * hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_FALSE(split_view_controller->InSplitViewMode());
watcher.WaitUntilStateChanged();
EXPECT_EQ(HotseatState::kShownHomeLauncher,
GetShelfLayoutManager()->hotseat_state());
histogram_tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kFlingUpToShowHomeScreen, 1);
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 0);
}
// Tests that the hotseat ends up in manually extended state after swiping up
// a window in split screen to overview (the final state is a split screen with
// one side in overview).
TEST_F(ShelfLayoutManagerWindowDraggingTest, FlingInSplitView) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
std::unique_ptr<aura::Window> window2 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
SplitViewController* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(
window1.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller->SnapWindow(
window2.get(), SplitViewController::SnapPosition::kSecondary);
base::HistogramTester histogram_tester;
HotseatStateWatcher watcher(GetShelfLayoutManager());
// Longer fling, one that significantly exceeds the distance required to show
// the hotseat (by 2 hotseat heights).
StartScroll(shelf_widget_bounds.bottom_left());
// Ensure swipe goes past the top of the hotseat first to activate the window
// drag controller
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size - 10));
UpdateScroll(gfx::Vector2d(0, -2 * hotseat_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_TRUE(OverviewController::Get()->InOverviewSession());
EXPECT_TRUE(split_view_controller->InSplitViewMode());
watcher.CheckEqual({HotseatState::kExtended});
EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->is_manually_extended());
histogram_tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kFlingUpToShowHomeScreen, 0);
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 1);
}
// Tests that the hotseat ends up in manually extended state after swiping up
// hotseat when window drag from shelf in split view ends up restoring original
// window bounds.
TEST_F(ShelfLayoutManagerWindowDraggingTest, ShortFlingInSplitView) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
std::unique_ptr<aura::Window> window2 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
SplitViewController* split_view_controller =
SplitViewController::Get(Shell::GetPrimaryRootWindow());
split_view_controller->SnapWindow(
window1.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller->SnapWindow(
window2.get(), SplitViewController::SnapPosition::kSecondary);
base::HistogramTester histogram_tester;
HotseatStateWatcher watcher(GetShelfLayoutManager());
StartScroll(shelf_widget_bounds.bottom_left());
UpdateScroll(gfx::Vector2d(
0, -shelf_size - 1.5f * hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
EXPECT_FALSE(OverviewController::Get()->InOverviewSession());
EXPECT_TRUE(split_view_controller->InSplitViewMode());
watcher.CheckEqual({HotseatState::kExtended});
EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->is_manually_extended());
histogram_tester.ExpectBucketCount(
kHotseatGestureHistogramName,
InAppShelfGestures::kFlingUpToShowHomeScreen, 0);
histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
InAppShelfGestures::kSwipeUpToShow, 1);
}
// Tests that hotseat transition animation is not delayed (i.e. that it happens
// as soon as shelf opaque background changes) when virtual keyboard is hidden,
// and the user swipes from shelf to home.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
NoDelayedAnimatingBackgroundForTransitionFromVirtualKeyboardToHome) {
std::unique_ptr<aura::Window> window1 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window1.get());
std::unique_ptr<aura::Window> window2 =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window2.get());
// Show virtual keyboard.
KeyboardController* const keyboard_controller =
Shell::Get()->keyboard_controller();
keyboard_controller->SetEnableFlag(
keyboard::KeyboardEnableFlag::kShelfEnabled);
keyboard_controller->ShowKeyboard();
// Verify the shelf state.
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
// Make animations not end immediately for the rest of the test (so the test
// can test whether the animating shelf background is animating).
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
// Simulate virtual keyboard closing, and a swipe from shelf to home.
StartScroll(shelf_widget_bounds.bottom_right());
keyboard_controller->HideKeyboard(HideReason::kUser);
UpdateScroll(
gfx::Vector2d(0, -shelf_size - 3 * hotseat_size - hotseat_padding_size));
EndScroll(
true /* is_fling */,
-(DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 10));
// Verify that the shelf background start animating immediately.
EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_TRUE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_TRUE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
keyboard_controller->ClearEnableFlag(
keyboard::KeyboardEnableFlag::kShelfEnabled);
}
// Test that if shelf if hidden or auto-hide hidden, drag window from shelf is a
// no-op.
// TODO(1024163): This test consistently crashes.
TEST_F(ShelfLayoutManagerWindowDraggingTest, DISABLED_NoOpForHiddenShelf) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
Shelf* shelf = GetPrimaryShelf();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
// The window can be dragged on a visible shelf.
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
StartScroll(shelf_widget_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_TRUE(IsWindowDragInProgress());
EXPECT_FALSE(window->transform().IsIdentityOrTranslation());
EndScroll(/*is_fling=*/false, 0.f);
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// The window can't be dragged on an auto-hidden hidden shelf.
gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
StartScroll(display_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
// The window can be dragged on an auto-hidden shown shelf.
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
StartScroll(display_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_TRUE(IsWindowDragInProgress());
EXPECT_FALSE(window->transform().IsIdentityOrTranslation());
EXPECT_TRUE(window->transform().IsScaleOrTranslation());
EndScroll(/*is_fling=*/false, 0.f);
// The window can't be dragged on a hidden shelf.
SetState(GetShelfLayoutManager(), SHELF_HIDDEN);
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
StartScroll(display_bounds.bottom_center());
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
}
// Tests that dragging below the hotseat after dragging the MRU up results in
// the hotseat not moving from its extended position.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
DragBelowHotseatDoesNotMoveHotseat) {
// Go to in-app shelf, then drag the hotseat up until it is extended, this
// will start a window drag.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
const int hotseat_y =
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen().y();
// Drag down, the hotseat should not move because it was extended when the
// window drag began.
UpdateScroll(gfx::Vector2d(0, 10));
EXPECT_EQ(hotseat_y,
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen().y());
EndScroll(/*is_fling=*/false, 0.f);
}
// Tests that dragging below the hotseat after dragging the MRU up results in
// the hotseat not moving from its extended position with an autohidden shelf.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
DragBelowHotseatDoesNotMoveHotseatAutoHiddenShelf) {
// Extend the hotseat, then start dragging the window.
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
SwipeUpOnShelf();
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
UpdateScroll(
gfx::Vector2d(0, -shelf_size - hotseat_size - hotseat_padding_size));
const int hotseat_y =
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen().y();
// Drag down, the hotseat should not move because it was extended when the
// window drag began.
UpdateScroll(gfx::Vector2d(0, 10));
EXPECT_EQ(hotseat_y,
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen().y());
EndScroll(/*is_fling=*/false, 0.f);
}
TEST_F(ShelfLayoutManagerWindowDraggingTest, NoOpIfDragStartsAboveShelf) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
gfx::Rect hotseat_bounds =
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
StartScroll(hotseat_bounds.CenterPoint());
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
}
// Test that gesture that starts within hotseat bounds, goes down to shelf, and
// start moving up does not start window drag (as upward swipe from hotseat does
// not start window drag either).
TEST_F(ShelfLayoutManagerWindowDraggingTest,
NoOpIfDragSTartsAboveShelfAndMovesToShelf) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
gfx::Rect hotseat_bounds =
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
StartScroll(hotseat_bounds.CenterPoint());
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
const gfx::Vector2d vector_from_hotseat_to_shelf_center =
hotseat_bounds.CenterPoint() -
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
UpdateScroll(gfx::Vector2d(0, vector_from_hotseat_to_shelf_center.y()));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, -vector_from_hotseat_to_shelf_center.y()));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
}
// Tests that the MRU window can only be dragged window after the hotseat is
// fully dragged up if hotseat was hidden before.
TEST_F(ShelfLayoutManagerWindowDraggingTest, StartsDragAfterHotseatIsUp) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = ShelfConfig::Get()->shelf_size();
const int hotseat_size = GetHotseatWidget()->GetHotseatSize();
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
// Starts the drag from the center of the shelf's bottom.
gfx::Point start = shelf_widget_bounds.bottom_center();
StartScroll(start);
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
// Continues the drag until the hotseat should have been fully dragged up.
UpdateScroll(gfx::Vector2d(0, -shelf_size));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, -hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(gfx::Vector2d(0, -hotseat_size));
EXPECT_TRUE(IsWindowDragInProgress());
// The window should not be transformed at the point where the drag starts.
EXPECT_TRUE(window->transform().IsIdentity());
// The window is expected to be scaled down as the drag progresses.
UpdateScroll(gfx::Vector2d(0, -10));
EXPECT_FALSE(window->transform().IsIdentityOrTranslation());
EXPECT_TRUE(window->transform().IsScaleOrTranslation());
EndScroll(/*is_fling=*/false, 0.f);
}
TEST_F(ShelfLayoutManagerWindowDraggingTest, NoDragForDownwardEvent) {
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
SwipeUpOnShelf();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
// Start drag on the extended hotseat.
const int hotseat_padding_size = ShelfConfig::Get()->hotseat_bottom_padding();
gfx::Rect hotseat_bounds =
GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
StartScroll(hotseat_bounds.CenterPoint());
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
UpdateScroll(
gfx::Vector2d(0, hotseat_bounds.height() + hotseat_padding_size));
EXPECT_FALSE(IsWindowDragInProgress());
EXPECT_TRUE(window->transform().IsIdentity());
EndScroll(/*is_fling=*/false, 0.f);
}
// Verifies that there is no crash on shutdown while swipe from home to overview
// is in progress.
TEST_F(ShelfLayoutManagerWindowDraggingTest,
ShutdownWhileSwipingHomeToOverview) {
const gfx::Rect shelf_widget_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
StartScroll(shelf_widget_bounds.bottom_center());
UpdateScroll(gfx::Vector2d(0, -20));
UpdateScroll(gfx::Vector2d(0, -20));
ASSERT_TRUE(
GetShelfLayoutManager()->swipe_home_to_overview_controller_for_testing());
}
class ShelfLayoutManagerKeyboardTest : public AshTestBase {
public:
ShelfLayoutManagerKeyboardTest() = default;
ShelfLayoutManagerKeyboardTest(const ShelfLayoutManagerKeyboardTest&) =
delete;
ShelfLayoutManagerKeyboardTest& operator=(
const ShelfLayoutManagerKeyboardTest&) = delete;
~ShelfLayoutManagerKeyboardTest() override = default;
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
UpdateDisplay("800x600");
keyboard::SetTouchKeyboardEnabled(true);
keyboard::SetAccessibilityKeyboardEnabled(true);
}
// AshTestBase:
void TearDown() override {
keyboard::SetAccessibilityKeyboardEnabled(false);
keyboard::SetTouchKeyboardEnabled(false);
AshTestBase::TearDown();
}
void InitKeyboardBounds() {
gfx::Rect work_area(
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
keyboard_bounds_.SetRect(work_area.x(),
work_area.y() + work_area.height() / 2,
work_area.width(), work_area.height() / 2);
}
void NotifyKeyboardChanging(ShelfLayoutManager* layout_manager,
bool is_locked,
const gfx::Rect& bounds_in_screen) {
WorkAreaInsets* work_area_insets = GetPrimaryWorkAreaInsets();
KeyboardStateDescriptor state;
state.visual_bounds = bounds_in_screen;
state.occluded_bounds_in_screen = bounds_in_screen;
state.displaced_bounds_in_screen =
is_locked ? bounds_in_screen : gfx::Rect();
state.is_visible = !bounds_in_screen.IsEmpty();
work_area_insets->OnKeyboardVisibilityChanged(state.is_visible);
work_area_insets->OnKeyboardAppearanceChanged(state);
}
const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; }
private:
gfx::Rect keyboard_bounds_;
};
TEST_F(ShelfLayoutManagerKeyboardTest, ShelfNotMoveOnKeyboardOpen) {
gfx::Rect orig_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
InitKeyboardBounds();
auto* kb_controller = keyboard::KeyboardUIController::Get();
// Open keyboard in non-sticky mode.
kb_controller->ShowKeyboard(false);
NotifyKeyboardChanging(layout_manager, false, keyboard_bounds());
// Shelf position should not be changed.
EXPECT_EQ(orig_bounds, GetShelfWidget()->GetWindowBoundsInScreen());
}
// When kAshUseNewVKWindowBehavior flag enabled, do not change accessibility
// keyboard work area in non-sticky mode.
TEST_F(ShelfLayoutManagerKeyboardTest,
ShelfIgnoreWorkAreaChangeInNonStickyMode) {
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
InitKeyboardBounds();
auto* kb_controller = keyboard::KeyboardUIController::Get();
gfx::Rect orig_work_area(
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
// Open keyboard in non-sticky mode.
kb_controller->ShowKeyboard(false);
NotifyKeyboardChanging(layout_manager, false, keyboard_bounds());
// Work area should not be changed.
EXPECT_EQ(orig_work_area,
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
kb_controller->HideKeyboardExplicitlyBySystem();
NotifyKeyboardChanging(layout_manager, false, gfx::Rect());
EXPECT_EQ(orig_work_area,
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
}
// Change accessibility keyboard work area in sticky mode.
TEST_F(ShelfLayoutManagerKeyboardTest, ShelfShouldChangeWorkAreaInStickyMode) {
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
InitKeyboardBounds();
auto* kb_controller = keyboard::KeyboardUIController::Get();
gfx::Rect orig_work_area(
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
// Open keyboard in sticky mode.
kb_controller->ShowKeyboard(true);
NotifyKeyboardChanging(layout_manager, true, keyboard_bounds());
// Work area should be changed.
EXPECT_NE(orig_work_area,
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
// Hide the keyboard.
kb_controller->HideKeyboardByUser();
NotifyKeyboardChanging(layout_manager, true, gfx::Rect());
// Work area should be reset to its original value.
EXPECT_EQ(orig_work_area,
display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
}
// Make sure we don't update the work area during overview animation
// (crbug.com/947343).
TEST_F(ShelfLayoutManagerTest, NoShelfUpdateDuringOverviewAnimation) {
// Finish lid detection task.
base::RunLoop().RunUntilIdle();
TabletModeControllerTestApi().EnterTabletMode();
// Run overview animations.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
std::unique_ptr<aura::Window> window1(CreateTestWindow());
std::unique_ptr<aura::Window> fullscreen(CreateTestWindow());
fullscreen->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
wm::ActivateWindow(fullscreen.get());
TestDisplayObserver observer;
EnterOverview();
WaitForOverviewAnimation(/*enter=*/true);
ASSERT_TRUE(TabletModeControllerTestApi().IsTabletModeStarted());
EXPECT_EQ(0, observer.metrics_change_count());
ExitOverview();
WaitForOverviewAnimation(/*enter=*/false);
ASSERT_TRUE(TabletModeControllerTestApi().IsTabletModeStarted());
EXPECT_EQ(0, observer.metrics_change_count());
}
// Tests that shelf bounds are updated properly after overview animation.
TEST_F(ShelfLayoutManagerTest, ShelfBoundsUpdateAfterOverviewAnimation) {
// Run overview animations.
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
Shelf* shelf = GetPrimaryShelf();
ASSERT_EQ(ShelfAlignment::kBottom, shelf->alignment());
const gfx::Rect bottom_shelf_bounds =
GetShelfWidget()->GetWindowBoundsInScreen();
const int shelf_size = bottom_shelf_bounds.height();
const gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
const gfx::Rect left_shelf_bounds =
gfx::Rect(display_bounds.x(), display_bounds.y(), shelf_size,
display_bounds.height());
// Change alignment during overview enter animation.
EnterOverview();
// When setting the shelf alignment, bounds aren't expected to animate.
shelf->SetAlignment(ShelfAlignment::kLeft);
// Setting alignment exits overview which we should wait for.
WaitForOverviewAnimation(/*enter=*/false);
EXPECT_EQ(left_shelf_bounds, GetShelfWidget()->GetWindowBoundsInScreen());
// Change alignment during overview exit animation.
EnterOverview();
WaitForOverviewAnimation(/*enter=*/true);
ExitOverview();
// When setting the shelf alignment, bounds aren't expected to animate.
shelf->SetAlignment(ShelfAlignment::kBottom);
WaitForOverviewAnimation(/*enter=*/false);
EXPECT_EQ(bottom_shelf_bounds, GetShelfWidget()->GetWindowBoundsInScreen());
}
// Tests that the shelf on a second display is properly centered.
TEST_F(ShelfLayoutManagerTest, ShelfRemainsCenteredOnSecondDisplay) {
// Create two displays.
UpdateDisplay("600x400,1000x700");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(2U, root_windows.size());
Shelf* shelf_1 = Shelf::ForWindow(root_windows[0]);
Shelf* shelf_2 = Shelf::ForWindow(root_windows[1]);
EXPECT_NE(shelf_1, shelf_2);
EXPECT_NE(shelf_1->GetWindow()->GetRootWindow(),
shelf_2->GetWindow()->GetRootWindow());
ShelfView* shelf_view_1 = shelf_1->GetShelfViewForTesting();
ShelfView* shelf_view_2 = shelf_2->GetShelfViewForTesting();
const display::Display display_1 =
display::Screen::GetScreen()->GetPrimaryDisplay();
const display::Display display_2 =
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[1]);
EXPECT_NE(display_1, display_2);
ShelfTestUtil::AddAppShortcut("app_id", TYPE_PINNED_APP);
ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())
.RunMessageLoopUntilAnimationsDone();
gfx::Point app_center_1 = shelf_1->GetShelfViewForTesting()
->first_visible_button_for_testing()
->bounds()
.CenterPoint();
views::View::ConvertPointToScreen(shelf_view_1, &app_center_1);
gfx::Point app_center_2 = shelf_2->GetShelfViewForTesting()
->first_visible_button_for_testing()
->bounds()
.CenterPoint();
views::View::ConvertPointToScreen(shelf_view_2, &app_center_2);
// The app icon should be at the horizontal center of each display.
EXPECT_EQ(display_1.bounds().CenterPoint().x(), app_center_1.x());
EXPECT_EQ(display_2.bounds().CenterPoint().x(), app_center_2.x());
}
// Verifies that showing the system tray view on the secondary display
// should not affect the auto-hide shelf on the primary display
// (https://crbug.com/1079464).
TEST_F(ShelfLayoutManagerTest, VerifyAutoHideBehaviorOnMultipleDisplays) {
UpdateDisplay("800x600, 800x600");
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
CreateTestWidget();
// The primary shelf should be hidden.
ASSERT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Set focus on the secondary display.
aura::Window* secondary_root_window =
Shell::GetRootWindowForDisplayId(GetSecondaryDisplay().id());
Shell::SetRootWindowForNewWindows(secondary_root_window);
// Show the system tray on the secondary display.
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(
AcceleratorAction::kToggleSystemTrayBubble, {});
Shelf* secondary_shelf =
RootWindowController::ForWindow(secondary_root_window)->shelf();
ASSERT_TRUE(secondary_shelf->status_area_widget()->IsMessageBubbleShown());
ASSERT_FALSE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
// Verify that the primary shelf is still hidden.
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
// Tests that pinned app icons are visible on non-primary displays.
TEST_F(ShelfLayoutManagerTest, ShelfShowsPinnedAppsOnOtherDisplays) {
// Create three displays. Should use 600+ pixel as the horizontal display
// size, otherwise there's no enough space to show both the date tray and
// unified system tray on the screen.
UpdateDisplay("700x400,1000x700,800x900");
const unsigned int display_count = 3U;
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(display_count, root_windows.size());
// Keep this low so that all apps fit at the center of the screen on all
// displays.
const size_t max_app_count = 4;
for (size_t app_count = 1; app_count <= max_app_count; ++app_count) {
AddApp();
// Wait for everything to settle down.
for (unsigned int display_index = 0; display_index < display_count;
++display_index) {
Shelf* shelf = Shelf::ForWindow(root_windows[display_index]);
ShelfView* shelf_view = shelf->GetShelfViewForTesting();
ShelfViewTestAPI(shelf_view).RunMessageLoopUntilAnimationsDone();
}
// If everything is as expected, the middle app (if applicable) should be
// exactly at the center of the screen, on all displays. Also, the
// distance between the first app and the left edge of the display should be
// the same as the distance between the third app and the right edge of the
// display.
for (unsigned int display_index = 0; display_index < display_count;
++display_index) {
const display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(
root_windows[display_index]);
Shelf* shelf = Shelf::ForWindow(root_windows[display_index]);
ShelfView* shelf_view = shelf->GetShelfViewForTesting();
EXPECT_EQ(app_count, shelf_view->number_of_visible_apps());
// Only check the middle app if we have an odd number of apps.
if (app_count % 2 == 1) {
const gfx::Point center = ShelfViewTestAPI(shelf_view)
.GetViewAt(app_count / 2)
->GetBoundsInScreen()
.CenterPoint();
EXPECT_EQ(display.bounds().CenterPoint().x(), center.x())
<< "App at index " << (app_count / 2) << " should be at "
<< "the center of display " << display_index << " with "
<< app_count << " apps";
}
const gfx::Point left = ShelfViewTestAPI(shelf_view)
.GetViewAt(0)
->GetBoundsInScreen()
.left_center();
const gfx::Point right = ShelfViewTestAPI(shelf_view)
.GetViewAt(app_count - 1)
->GetBoundsInScreen()
.right_center();
EXPECT_EQ(left.x() - display.bounds().x(),
display.bounds().right() - right.x())
<< "Apps on either end should be at the same distance from the "
<< "screen edge on display " << display_index << " with " << app_count
<< " apps";
}
}
}
class QuickActionShowBubbleTest : public ShelfLayoutManagerTestBase,
public testing::WithParamInterface<bool> {
public:
QuickActionShowBubbleTest() : scoped_locale_(GetParam() ? "ar" : "") {}
~QuickActionShowBubbleTest() override = default;
private:
base::test::ScopedRestoreICUDefaultLocale scoped_locale_;
};
const struct {
ShelfAlignment alignment;
bool swipe_gesture;
} test_table[]{
{ShelfAlignment::kBottom, false},
{ShelfAlignment::kBottom, true},
{ShelfAlignment::kBottomLocked, false},
{ShelfAlignment::kBottomLocked, true},
{ShelfAlignment::kLeft, false},
{ShelfAlignment::kLeft, true},
{ShelfAlignment::kRight, false},
{ShelfAlignment::kRight, true},
};
// Used to test RTL UI orientation.
INSTANTIATE_TEST_SUITE_P(All, QuickActionShowBubbleTest, testing::Bool());
// Tests that the two finger gesture and the swipe gesture when the mouse is
// over the shelf near the edge shows the bubble launcher.
TEST_P(QuickActionShowBubbleTest, ScrollFromShelfToShowAppList) {
base::HistogramTester histogram_tester;
const int scroll_offset_threshold =
ShelfConfig::Get()->mousewheel_scroll_offset_threshold() + 10;
int bucket_scroll_count = 0;
int bucket_swipe_count = 0;
for (auto test : test_table) {
GetShelfLayoutManager()->LayoutShelf();
GetPrimaryShelf()->SetAlignment(test.alignment);
ASSERT_EQ(test.alignment, GetPrimaryShelf()->alignment());
// Direction of the swipe gesture depends on the shelf alignment and on the
// event being a swipe or a fling.
gfx::Vector2d offset = GetPrimaryShelf()->SelectValueForShelfAlignment(
gfx::Vector2d(0, scroll_offset_threshold),
gfx::Vector2d(-scroll_offset_threshold, 0),
gfx::Vector2d(scroll_offset_threshold, 0));
// Action performed from the navigation_widget should show the bubble
// launcher.
const gfx::Point navigation_widget_center = GetPrimaryShelf()
->navigation_widget()
->GetContentsView()
->GetBoundsInScreen()
.CenterPoint();
if (test.swipe_gesture) {
FlingBetweenLocations(navigation_widget_center,
navigation_widget_center - offset);
++bucket_swipe_count;
} else {
DoTwoFingerScrollAtLocation(navigation_widget_center, offset.x(),
offset.y(), false);
++bucket_scroll_count;
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kSwipeFromShelf,
bucket_swipe_count);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kScrollFromShelf,
bucket_scroll_count);
// The same gesture on the opposite direction should dismiss the app list.
if (test.swipe_gesture) {
FlingBetweenLocations(navigation_widget_center,
navigation_widget_center + offset);
} else {
DoTwoFingerScrollAtLocation(navigation_widget_center, -offset.x(),
-offset.y(), false);
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Action performed from the status area should not show the bubble
// launcher.
const gfx::Point status_area_widget_center = GetShelfWidget()
->status_area_widget()
->GetContentsView()
->GetBoundsInScreen()
.CenterPoint();
if (test.swipe_gesture) {
FlingBetweenLocations(status_area_widget_center,
status_area_widget_center - offset);
} else {
DoTwoFingerScrollAtLocation(status_area_widget_center, offset.x(),
offset.y(), false);
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kSwipeFromShelf,
bucket_swipe_count);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kScrollFromShelf,
bucket_scroll_count);
}
}
// Tests that the two finger gesture and the swipe gesture when the mouse is
// over the shelf before the shelf apps, does not show the bubble launcher.
TEST_P(QuickActionShowBubbleTest, ScrollFromShelfToShowAppListOverShelfApps) {
base::HistogramTester histogram_tester;
const int scroll_offset_threshold =
ShelfConfig::Get()->mousewheel_scroll_offset_threshold() + 10;
int bucket_scroll_count = 0;
int bucket_swipe_count = 0;
ShelfView* shelf_view = GetPrimaryShelf()->GetShelfViewForTesting();
const size_t max_app_count = 4;
for (size_t app_count = 1; app_count <= max_app_count; ++app_count)
AddApp();
EXPECT_EQ(max_app_count, shelf_view->number_of_visible_apps());
for (auto test : test_table) {
GetShelfLayoutManager()->LayoutShelf();
GetPrimaryShelf()->SetAlignment(test.alignment);
ASSERT_EQ(test.alignment, GetPrimaryShelf()->alignment());
// Direction of the swipe gesture depends on the shelf alignment and on the
// event being a swipe or a fling.
gfx::Vector2d offset = GetPrimaryShelf()->SelectValueForShelfAlignment(
gfx::Vector2d(0, scroll_offset_threshold),
gfx::Vector2d(-scroll_offset_threshold, 0),
gfx::Vector2d(scroll_offset_threshold, 0));
// Action performed on the edge closer to the home button should show the
// bubble launcher.
gfx::Point swipe_point;
if (GetParam())
swipe_point = GetHotseatWidget()->GetTargetBounds().right_center();
else
swipe_point = GetHotseatWidget()->GetTargetBounds().left_center();
swipe_point = GetPrimaryShelf()->PrimaryAxisValue(
swipe_point, GetHotseatWidget()->GetTargetBounds().top_center());
if (test.swipe_gesture) {
FlingBetweenLocations(swipe_point, swipe_point - offset);
++bucket_swipe_count;
} else {
DoTwoFingerScrollAtLocation(swipe_point, offset.x(), offset.y(), false);
++bucket_scroll_count;
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kSwipeFromShelf,
bucket_swipe_count);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kScrollFromShelf,
bucket_scroll_count);
// The same gesture on the opposite direction should dismiss the app list.
if (test.swipe_gesture)
FlingBetweenLocations(swipe_point, swipe_point + offset);
else
DoTwoFingerScrollAtLocation(swipe_point, -offset.x(), -offset.y(), false);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Action performed over the hotseat should not show the bubble launcher
swipe_point = GetHotseatWidget()->GetTargetBounds().CenterPoint();
if (test.swipe_gesture) {
FlingBetweenLocations(swipe_point, swipe_point - offset);
} else {
DoTwoFingerScrollAtLocation(swipe_point, offset.x(), offset.y(), false);
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kSwipeFromShelf,
bucket_swipe_count);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kScrollFromShelf,
bucket_scroll_count);
// Action performed on the edge farther to the home button should not show
// the bubble launcher.
if (GetParam())
swipe_point = GetHotseatWidget()->GetTargetBounds().left_center();
else
swipe_point = GetHotseatWidget()->GetTargetBounds().right_center();
swipe_point = GetPrimaryShelf()->PrimaryAxisValue(
swipe_point, GetHotseatWidget()->GetTargetBounds().bottom_center());
if (test.swipe_gesture) {
FlingBetweenLocations(swipe_point, swipe_point - offset);
} else {
DoTwoFingerScrollAtLocation(swipe_point, offset.x(), offset.y(), false);
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kSwipeFromShelf,
bucket_swipe_count);
histogram_tester.ExpectBucketCount("Apps.AppListBubbleShowSource",
AppListShowSource::kScrollFromShelf,
bucket_scroll_count);
}
}
// TODO(https://crbug.com/1286875): This behavior is broken in production. An
// auto-hidden shelf will close after a short swipe up that fails to show the
// app list.
TEST_P(QuickActionShowBubbleTest,
DISABLED_ShortSwipeUpOnAutoHideShelfKeepsShelfOpen) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
auto* generator = GetEventGenerator();
constexpr base::TimeDelta kTimeDelta = base::Milliseconds(100);
constexpr int kNumScrollSteps = 4;
// Starts the drag from the center of the shelf's bottom.
gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point start = shelf_bounds.bottom_center();
// Create a normal unmaximized window, the auto-hide shelf should be hidden.
aura::Window* window = CreateTestWindow();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Show();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Swiping up to show the auto-hide shelf.
gfx::Point end = shelf_bounds.top_center();
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Swiping up on the auto-hide shelf to drag up the app list. Scroll Velocity
// is not enough to show the app list but keep the previous shown auto-hide
// shelf still visible. Starts fling from the navigation_widget.
start = GetPrimaryShelf()
->navigation_widget()
->GetContentsView()
->GetBoundsInScreen()
.CenterPoint();
const int scroll_offset_threshold =
ShelfConfig::Get()->mousewheel_scroll_offset_threshold() + 10;
gfx::Vector2d offset(0, scroll_offset_threshold);
end = start - offset;
generator->GestureScrollSequence(
start, end,
generator->CalculateScrollDurationForFlingVelocity(start, end,
/*velocity =*/50, 4),
4);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// This line fails, see https://crbug.com/1286875.
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
// Tests that the shelf background is opaque in both screens after app list is
// dismissed in a secondary display. (See https://crbug.com/1060686)
TEST_F(ShelfLayoutManagerTest, ShelfBackgroundOpaqueAfterAppListUpdate) {
UpdateDisplay("800x600,800x600");
AppListControllerImpl* app_list_controller =
Shell::Get()->app_list_controller();
int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
app_list_controller->ToggleAppList(
secondary_display_id, AppListShowSource::kShelfButton, base::TimeTicks());
EXPECT_FALSE(app_list_controller->IsVisible(primary_display_id));
EXPECT_TRUE(app_list_controller->IsVisible(secondary_display_id));
app_list_controller->ToggleAppList(
secondary_display_id, AppListShowSource::kShelfButton, base::TimeTicks());
EXPECT_FALSE(app_list_controller->IsVisible(primary_display_id));
EXPECT_FALSE(app_list_controller->IsVisible(secondary_display_id));
auto* primary_root_window_controller =
Shell::GetRootWindowControllerWithDisplayId(primary_display_id);
auto* secondary_root_window_controller =
Shell::GetRootWindowControllerWithDisplayId(secondary_display_id);
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
primary_root_window_controller->shelf()
->shelf_layout_manager()
->shelf_background_type());
EXPECT_EQ(ShelfBackgroundType::kDefaultBg,
secondary_root_window_controller->shelf()
->shelf_layout_manager()
->shelf_background_type());
}
using NoSessionShelfLayoutManagerTest = NoSessionAshTestBase;
// Tests that shelf visibility is updated on login. (See
// https://crbug.com/1097464)
TEST_F(NoSessionShelfLayoutManagerTest, UpdateShelfVisibilityAfterLogin) {
UpdateDisplay("1000x800");
constexpr char kUser[] = "user1@test.com";
const AccountId kUserAccount = AccountId::FromUserEmail(kUser);
// Setup autohide shelf pref.
auto pref_service = std::make_unique<TestingPrefServiceSimple>();
RegisterUserProfilePrefs(pref_service->registry(), /*country=*/"",
/*for_test=*/true);
SetShelfAutoHideBehaviorPref(pref_service.get(),
WindowTreeHostManager::GetPrimaryDisplayId(),
ShelfAutoHideBehavior::kAlways);
GetSessionControllerClient()->SetUserPrefService(kUserAccount,
std::move(pref_service));
// Create a window that covers the full height of the in-session work area.
const int kExpectedWindowHeight = 800 - ShelfConfig::Get()->shelf_size();
auto window = CreateTestWindow(gfx::Rect(400, kExpectedWindowHeight));
// Simulate login.
SimulateUserLogin(kUser);
// The window should be the same height.
EXPECT_EQ(kExpectedWindowHeight, window->bounds().height());
}
// Test base for unit test related to shelf dimming.
class DimShelfLayoutManagerTestBase : public ShelfLayoutManagerTestBase {
public:
DimShelfLayoutManagerTestBase() = default;
bool AutoDimEventHandlerInitialized() {
return GetPrimaryShelf()->auto_dim_event_handler_.get();
}
bool ShelfDimmed() { return GetShelfLayoutManager()->dimmed_for_inactivity_; }
void TriggerDimShelf() { GetPrimaryShelf()->DimShelf(); }
void ResetDimShelf() { GetPrimaryShelf()->UndimShelf(); }
bool HasDimShelfTimer() {
return AutoDimEventHandlerInitialized() &&
GetPrimaryShelf()->HasDimShelfTimer();
}
float GetWidgetOpacity(views::Widget* widget) {
return widget->GetNativeView()->layer()->opacity();
}
// Expected opacity for floating shelf.
const float kExpectedFloatingShelfDimOpacity = 0.74f;
// Expected opacity for shelf when shelf is in the maximized state.
const float kExpectedMaximizedShelfDimOpacity = 0.6f;
// Expected opacity for shelf without dimming.
const float kExpectedDefaultShelfOpacity = 1.0f;
};
// Paramaterized tests for shelf with and without shelf dimming enabled.
class DimShelfLayoutManagerTest : public DimShelfLayoutManagerTestBase,
public testing::WithParamInterface<bool> {
public:
DimShelfLayoutManagerTest() = default;
// testing::Test:
void SetUp() override {
if (GetParam()) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableDimShelf);
}
DimShelfLayoutManagerTestBase::SetUp();
}
};
// Used to test shelf dimming.
INSTANTIATE_TEST_SUITE_P(All, DimShelfLayoutManagerTest, testing::Bool());
// Tests that the auto dim handler is initialized and shelf is not dim on
// startup.
TEST_P(DimShelfLayoutManagerTest, AutoDimHandlerInitialized) {
ASSERT_FALSE(ShelfDimmed());
ASSERT_EQ(GetParam(), AutoDimEventHandlerInitialized());
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->navigation_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->hotseat_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()->status_area_widget()),
kExpectedDefaultShelfOpacity);
}
// Tests that the auto dim handler dims the shelf when called.
TEST_P(DimShelfLayoutManagerTest, AutoDimHandlerSetDim) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
ASSERT_FALSE(ShelfDimmed());
if (!dim_shelf_enabled)
return;
TriggerDimShelf();
ASSERT_TRUE(ShelfDimmed());
ResetDimShelf();
ASSERT_FALSE(ShelfDimmed());
}
// Tests that the auto dim handler sets the shelf opacity correctly for floating
// shelf.
TEST_P(DimShelfLayoutManagerTest, FloatingShelfDimAlpha) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->hotseat_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->navigation_widget()),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetPrimaryShelf()->hotseat_widget()->GetShelfView()->layer()->opacity(),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()->status_area_widget()),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
}
// Tests that the auto dim handler sets the shelf opacity correctly in the
// special case of maximized shelf.
TEST_P(DimShelfLayoutManagerTest, MaximizedShelfDimAlpha) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
ASSERT_FALSE(ShelfDimmed());
if (dim_shelf_enabled) {
views::Widget* widget = CreateTestWidget();
widget->Maximize();
TriggerDimShelf();
}
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->navigation_widget()),
dim_shelf_enabled ? kExpectedMaximizedShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->hotseat_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetPrimaryShelf()->hotseat_widget()->GetShelfView()->layer()->opacity(),
dim_shelf_enabled ? kExpectedMaximizedShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()->status_area_widget()),
dim_shelf_enabled ? kExpectedMaximizedShelfDimOpacity
: kExpectedDefaultShelfOpacity);
}
// Tests that navigation and status area widgets are dimmed. Verifies the shelf
// view is not dimmed when the hotseat is in the kExtended state. Verifies that
// the shelf background/hotseat widget are not dimmed.
TEST_P(DimShelfLayoutManagerTest, InAppShelfDimAlpha) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
TabletModeControllerTestApi().EnterTabletMode();
views::Widget* widget = CreateTestWidget();
widget->Maximize();
ASSERT_FALSE(ShelfDimmed());
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
SwipeUpOnShelf();
EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->hotseat_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetPrimaryShelf()->hotseat_widget()->GetShelfView()->layer()->opacity(),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->navigation_widget()),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()->status_area_widget()),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
}
// Tests that shelf view, navigation widget, and status area widget are
// dimmed but the shelf background and hotseat are not.
TEST_P(DimShelfLayoutManagerTest, TabletModeHomeShelfDimAlpha) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_FALSE(ShelfDimmed());
EXPECT_EQ(HotseatState::kShownHomeLauncher,
GetShelfLayoutManager()->hotseat_state());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->hotseat_widget()),
kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetPrimaryShelf()->hotseat_widget()->GetShelfView()->layer()->opacity(),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(GetWidgetOpacity(GetPrimaryShelf()->navigation_widget()),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
EXPECT_EQ(
GetWidgetOpacity(GetPrimaryShelf()->shelf_widget()->status_area_widget()),
dim_shelf_enabled ? kExpectedFloatingShelfDimOpacity
: kExpectedDefaultShelfOpacity);
}
// Shelf dimming should not trigger when shelf is hidden in tablet mode.
TEST_P(DimShelfLayoutManagerTest, AutoHiddenShelfTabletModeDimAlpha) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
TabletModeControllerTestApi().EnterTabletMode();
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_FALSE(ShelfDimmed());
views::Widget* widget = CreateTestWidget();
widget->Maximize();
// Shelf should not be dimmed when auto hidden.
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_FALSE(ShelfDimmed());
// Minimizing the widget should show the shelf. The shelf can now be dimmed.
widget->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_FALSE(ShelfDimmed());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(dim_shelf_enabled, ShelfDimmed());
}
// Shelf dimming should not trigger when shelf is hidden in clamshell mode.
TEST_P(DimShelfLayoutManagerTest, AutoHiddenShelfClamshellModeDimAlpha) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_FALSE(ShelfDimmed());
views::Widget* widget = CreateTestWidget();
widget->Maximize();
// Shelf should not be dimmed when auto hidden. The dim shelf timer should
// persist after failing to dim the shelf.
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_FALSE(ShelfDimmed());
EXPECT_EQ(dim_shelf_enabled, HasDimShelfTimer());
// Minimizing the widget should show the shelf. The shelf can now be dimmed
// and the dim shelf timer should no longer be active.
widget->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
ASSERT_FALSE(ShelfDimmed());
EXPECT_EQ(dim_shelf_enabled, HasDimShelfTimer());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(dim_shelf_enabled, ShelfDimmed());
EXPECT_FALSE(HasDimShelfTimer());
}
// Shelf should be undimmed when transitioning into the visible state and create
// a dim shelf timer.
TEST_P(DimShelfLayoutManagerTest, AutoHiddenShelfUndimOnShow) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_FALSE(ShelfDimmed());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(dim_shelf_enabled, ShelfDimmed());
views::Widget* widget = CreateTestWidget();
// Maximize and minimize the widget to cycle between shelf auto hidden states.
widget->Maximize();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
widget->Minimize();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Hiding and showing the auto hidden shelf should set the shelf to the
// undimmed state but also create a dim shelf timer.
ASSERT_FALSE(ShelfDimmed());
EXPECT_EQ(dim_shelf_enabled, HasDimShelfTimer());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(dim_shelf_enabled, ShelfDimmed());
EXPECT_FALSE(HasDimShelfTimer());
}
// Shelf should be undimmed when auto hidden shelf is disabled.
TEST_P(DimShelfLayoutManagerTest, AutoHiddenShelfUndimOnDisable) {
const bool dim_shelf_enabled = GetParam();
ASSERT_EQ(dim_shelf_enabled, AutoDimEventHandlerInitialized());
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_FALSE(ShelfDimmed());
if (dim_shelf_enabled)
TriggerDimShelf();
EXPECT_EQ(dim_shelf_enabled, ShelfDimmed());
// Create and maximize a widget to cycle force auto hidden shelf.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Disabling auto hidden shelf should undim the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
ASSERT_FALSE(ShelfDimmed());
}
class NavigationWidgetRTLTest
: public ShelfLayoutManagerTest,
public testing::WithParamInterface<
std::tuple</*in_tablet=*/bool, /*in_rtl=*/bool>> {
public:
NavigationWidgetRTLTest()
: in_tablet_(std::get<0>(GetParam())),
in_rtl_(std::get<1>(GetParam())),
scoped_locale_(in_rtl_ ? "ar" : "") {}
~NavigationWidgetRTLTest() override = default;
// Indicates whether the test should run in the tablet mode.
const bool in_tablet_;
// Indicates whether the test should run under RTL.
const bool in_rtl_;
base::test::ScopedRestoreICUDefaultLocale scoped_locale_;
};
INSTANTIATE_TEST_SUITE_P(ALL,
NavigationWidgetRTLTest,
testing::Combine(testing::Bool(), testing::Bool()));
TEST_P(NavigationWidgetRTLTest, VerifyHomeButtonBounds) {
if (in_tablet_) {
Shell::Get()
->accessibility_controller()
->SetTabletModeShelfNavigationButtonsEnabled(true);
TabletModeControllerTestApi().EnterTabletMode();
ASSERT_EQ(HotseatState::kShownHomeLauncher,
GetShelfLayoutManager()->hotseat_state());
} else {
ASSERT_EQ(HotseatState::kShownClamshell,
GetShelfLayoutManager()->hotseat_state());
}
const gfx::Rect display_bounds = GetPrimaryDisplay().bounds();
Shelf* shelf = GetPrimaryShelf();
ShelfNavigationWidget* navigation_widget = shelf->navigation_widget();
const gfx::Size widget_size_in_home_launcher =
navigation_widget->GetWindowBoundsInScreen().size();
auto fetch_home_button_screen_bounds =
[](const ShelfNavigationWidget* navigation_widget,
bool in_rtl) -> gfx::Rect {
gfx::Rect home_button_bounds_in_widget =
navigation_widget->bounds_animator_for_test()->GetTargetBounds(
navigation_widget->GetHomeButton());
if (in_rtl) {
home_button_bounds_in_widget =
navigation_widget->GetRootView()->GetMirroredRect(
home_button_bounds_in_widget);
}
gfx::Rect home_button_bounds_in_screen = home_button_bounds_in_widget;
home_button_bounds_in_screen.Offset(
navigation_widget->GetWindowBoundsInScreen().OffsetFromOrigin());
return home_button_bounds_in_screen;
};
// Verify home button bounds in home launcher.
{
const gfx::Rect home_button_bounds_in_screen =
fetch_home_button_screen_bounds(navigation_widget, in_rtl_);
const int horizontal_edge_spacing =
ShelfConfig::Get()->control_button_edge_spacing(
/*is_primary_axis_edge=*/true);
EXPECT_EQ(
horizontal_edge_spacing,
in_rtl_ ? display_bounds.right() - home_button_bounds_in_screen.right()
: home_button_bounds_in_screen.x());
const int vertical_edge_spacing =
ShelfConfig::Get()->control_button_edge_spacing(
/*is_primary_axis_edge=*/false);
EXPECT_EQ(display_bounds.bottom(),
home_button_bounds_in_screen.bottom() + vertical_edge_spacing);
auto* home_button = navigation_widget->GetHomeButton();
ASSERT_EQ(views::Button::STATE_NORMAL, home_button->GetState());
GetEventGenerator()->MoveMouseTo(
home_button_bounds_in_screen.CenterPoint());
EXPECT_EQ(views::Button::STATE_HOVERED, home_button->GetState());
}
if (!in_tablet_)
return;
// The test code below is only for the tablet mode.
// Activate a window and wait for the navigation widget animation to finish.
views::WidgetAnimationWaiter waiter(shelf->navigation_widget());
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
waiter.WaitForAnimation();
ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
const gfx::Size widget_size_in_hidden_state =
navigation_widget->GetWindowBoundsInScreen().size();
EXPECT_EQ(widget_size_in_home_launcher, widget_size_in_hidden_state);
// Verify home button bounds in the hidden state.
{
const gfx::Rect home_button_bounds_in_screen =
fetch_home_button_screen_bounds(navigation_widget, in_rtl_);
EXPECT_EQ(display_bounds.bottom(), home_button_bounds_in_screen.bottom());
}
}
class ShelfLayoutManagerWithEcheTest : public ShelfLayoutManagerTestBase {
public:
template <typename... TaskEnvironmentTraits>
explicit ShelfLayoutManagerWithEcheTest(TaskEnvironmentTraits&&... traits)
: ShelfLayoutManagerTestBase(
std::forward<TaskEnvironmentTraits>(traits)...) {
scoped_feature_list_.InitAndEnableFeature(features::kEcheSWA);
}
protected:
void SetUp() override { ShelfLayoutManagerTestBase::SetUp(); }
private:
base::test::ScopedFeatureList scoped_feature_list_;
// Calling the factory constructor is enough to set it up.
TestAshWebViewFactory test_web_view_factory_;
};
TEST_F(ShelfLayoutManagerWithEcheTest, AutoHideShelfWithEcheHidden) {
// Create and maximize a widget to cycle force auto hidden shelf.
views::Widget* widget = CreateTestWidget();
widget->Maximize();
// Set the shelf to auto-hide.
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
GetShelfLayoutManager()->UpdateVisibilityState(/*force_layout=*/false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Create and show Eche Bubble.
StatusAreaWidget* status_area =
StatusAreaWidgetTestHelper::GetStatusAreaWidget();
SkBitmap bitmap;
bitmap.allocN32Pixels(30, 30);
gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
image_skia.MakeThreadSafe();
status_area->eche_tray()->LoadBubble(
GURL("http://google.com"), gfx::Image(image_skia), u"app 1",
u"your phone",
eche_app::mojom::ConnectionStatus::kConnectionStatusDisconnected,
eche_app::mojom::AppStreamLaunchEntryPoint::RECENT_APPS);
status_area->eche_tray()->ShowBubble();
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Hide Eche Bubble.
status_area->eche_tray()->HideBubble();
UpdateAutoHideStateNow();
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
} // namespace ash
|