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
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include <memory>
#include <string>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/app_list/app_list_bubble_presenter.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/app_list_model_provider.h"
#include "ash/app_list/app_list_presenter_impl.h"
#include "ash/app_list/model/app_list_item.h"
#include "ash/app_list/model/app_list_test_model.h"
#include "ash/app_list/model/search/test_search_result.h"
#include "ash/app_list/quick_app_access_model.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/app_list/views/app_list_bubble_search_page.h"
#include "ash/app_list/views/app_list_bubble_view.h"
#include "ash/app_list/views/app_list_folder_view.h"
#include "ash/app_list/views/app_list_item_view.h"
#include "ash/app_list/views/app_list_main_view.h"
#include "ash/app_list/views/app_list_search_view.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/apps_container_view.h"
#include "ash/app_list/views/apps_grid_view.h"
#include "ash/app_list/views/apps_grid_view_test_api.h"
#include "ash/app_list/views/contents_view.h"
#include "ash/app_list/views/continue_section_view.h"
#include "ash/app_list/views/paged_apps_grid_view.h"
#include "ash/app_list/views/recent_apps_view.h"
#include "ash/app_list/views/remove_query_confirmation_dialog.h"
#include "ash/app_list/views/result_selection_controller.h"
#include "ash/app_list/views/scrollable_apps_grid_view.h"
#include "ash/app_list/views/search_box_view.h"
#include "ash/app_list/views/search_result_actions_view.h"
#include "ash/app_list/views/search_result_base_view.h"
#include "ash/app_list/views/search_result_list_view.h"
#include "ash/app_list/views/search_result_page_anchored_dialog.h"
#include "ash/app_list/views/search_result_page_view.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/display/display_configuration_controller.h"
#include "ash/display/display_configuration_controller_test_api.h"
#include "ash/keyboard/keyboard_controller_impl.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/keyboard/ui/test/keyboard_test_util.h"
#include "ash/public/cpp/app_list/app_list_controller_observer.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/keyboard/keyboard_switches.h"
#include "ash/public/cpp/shelf_config.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/root_window_controller.h"
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/shelf/home_button.h"
#include "ash/shelf/scrollable_shelf_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_app_button.h"
#include "ash/shelf/shelf_layout_manager.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/shell.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/test/ash_test_base.h"
#include "ash/wallpaper/wallpaper_controller_test_api.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_types.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/workspace_controller_test_api.h"
#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_targeter.h"
#include "ui/base/mojom/window_show_state.mojom.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/layer_animation_stopped_waiter.h"
#include "ui/display/display.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/event_constants.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/transform_util.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/touch_selection/touch_selection_menu_runner.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/textfield/textfield_test_api.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/touchui/touch_selection_controller_impl.h"
#include "ui/views/touchui/touch_selection_menu_runner_views.h"
#include "ui/views/view_class_properties.h"
#include "ui/wm/core/window_util.h"
namespace ash {
namespace {
constexpr int kBestMatchContainerIndex = 1;
SearchModel* GetSearchModel() {
return AppListModelProvider::Get()->search_model();
}
int64_t GetPrimaryDisplayId() {
return display::Screen::GetScreen()->GetPrimaryDisplay().id();
}
void EnableTabletMode(bool enable) {
// Avoid |TabletModeController::OnGetSwitchStates| from disabling tablet mode
// again at the end of |TabletModeController::TabletModeController|.
base::RunLoop().RunUntilIdle();
if (enable) {
ash::TabletModeControllerTestApi().EnterTabletMode();
} else {
ash::TabletModeControllerTestApi().LeaveTabletMode();
}
// The app list will be shown automatically when tablet mode is enabled (Home
// launcher flag is enabled). Wait here for the animation complete.
base::RunLoop().RunUntilIdle();
}
std::unique_ptr<TestSearchResult> CreateOmniboxSuggestionResult(
const std::string& result_id,
bool support_removal) {
auto suggestion_result = std::make_unique<TestSearchResult>();
suggestion_result->set_result_id(result_id);
suggestion_result->set_best_match(true);
suggestion_result->set_display_type(SearchResultDisplayType::kList);
if (support_removal) {
SearchResultActions actions;
actions.emplace_back(SearchResultActionType::kRemove, u"Remove");
suggestion_result->SetActions(actions);
}
// Give this item a name so that the accessibility paint checks pass.
// (Focusable items should have accessible names.)
suggestion_result->SetAccessibleName(base::UTF8ToUTF16(result_id));
return suggestion_result;
}
// Verifies the current search result page anchored dialog bounds.
// The dialog is expected to be positioned horizontally centered within the
// search box bounds.
void SanityCheckSearchResultsAnchoredDialogBounds(
const views::Widget* dialog,
const SearchBoxView* search_box_view) {
auto horizontal_center_offset = [](const gfx::Rect& inner,
const gfx::Rect& outer) -> int {
return outer.CenterPoint().x() - inner.CenterPoint().x();
};
const gfx::Rect dialog_bounds = dialog->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds = search_box_view->GetBoundsInScreen();
// The dialog should be horizontally centered within the search box.
EXPECT_EQ(0, horizontal_center_offset(dialog_bounds, search_box_bounds));
// Verify the confirmation dialog is positioned with the top within search
// box bounds.
EXPECT_GT(dialog_bounds.y(), search_box_bounds.y());
EXPECT_LT(dialog_bounds.y(), search_box_bounds.bottom());
}
// Returns the search box view from either the clamshell bubble or the tablet
// mode fullscreen launcher.
SearchBoxView* GetSearchBoxViewFromHelper(AppListTestHelper* helper) {
if (!Shell::Get()->IsInTabletMode()) {
DCHECK(Shell::Get()->app_list_controller()->IsVisible());
return helper->GetBubbleSearchBoxView();
}
return helper->GetSearchBoxView();
}
// Test observer to verify that `AppListView` / its presenter do not call
// `OnVisibilityChanged(false)` during **aborted** hide animation.
class TestAppListControllerObserver : public AppListControllerObserver {
public:
TestAppListControllerObserver() = default;
TestAppListControllerObserver(const TestAppListControllerObserver&) = delete;
TestAppListControllerObserver& operator=(
const TestAppListControllerObserver&) = delete;
~TestAppListControllerObserver() override {
Shell::Get()->app_list_controller()->RemoveObserver(this);
}
void OnAppListVisibilityChanged(bool shown, int64_t display_id) override {
if (!shown)
++visibility_changed_to_hidden_times_;
}
int visibility_changed_to_hidden_times() const {
return visibility_changed_to_hidden_times_;
}
private:
int visibility_changed_to_hidden_times_ = 0;
};
} // namespace
// This suite used to be called AppListPresenterDelegateTest. It's not called
// AppListPresenterImplTest because that name was already taken. The two test
// suite were not merged in order to maintain git blame history for this file.
class AppListPresenterTest : public AshTestBase,
public testing::WithParamInterface<bool> {
public:
AppListPresenterTest() = default;
AppListPresenterTest(const AppListPresenterTest&) = delete;
AppListPresenterTest& operator=(const AppListPresenterTest&) = delete;
~AppListPresenterTest() override = default;
// testing::Test:
void SetUp() override {
AshTestBase::SetUp();
// Make the display big enough to hold the app list.
UpdateDisplay("1024x768");
}
// Ensures the launcher is visible and showing the apps grid.
void EnsureLauncherWithVisibleAppsGrid() {
auto* helper = GetAppListTestHelper();
helper->ShowAndRunLoop(GetPrimaryDisplayId());
helper->WaitUntilIdle();
}
void SetAppListStateAndWait(AppListViewState new_state) {
GetAppListView()->SetState(new_state);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(new_state);
}
// Whether to run the test with mouse or gesture events.
bool TestMouseEventParam() const { return GetParam(); }
// Whether to run the test with fullscreen or not.
bool TestFullscreenParam() const { return GetParam(); }
test::AppListTestModel* GetAppListModel() {
return GetAppListTestHelper()->model();
}
SearchBoxView* GetSearchBoxView() {
return GetSearchBoxViewFromHelper(GetAppListTestHelper());
}
gfx::Point GetPointOutsideSearchbox() {
// Ensures that the point satisfies the following conditions:
// (1) The point is within AppListView.
// (2) The point is outside of the search box.
// (3) The touch event on the point should not be consumed by the handler
// for back gesture.
return GetSearchBoxView()->GetBoundsInScreen().bottom_right();
}
gfx::Point GetPointInsideSearchbox() {
return GetSearchBoxView()->GetBoundsInScreen().CenterPoint();
}
AppListView* GetAppListView() {
return GetAppListTestHelper()->GetAppListView();
}
SearchResultPageView* search_result_page() {
return GetAppListView()
->app_list_main_view()
->contents_view()
->search_result_page_view();
}
SearchResultContainerView* GetDefaultSearchResultListView() {
return search_result_page()
->search_view()
->result_container_views_for_test()[kBestMatchContainerIndex];
}
AppsGridView* apps_grid_view() {
return GetAppListTestHelper()->GetScrollableAppsGridView();
}
void ClickMouseAt(const gfx::Point& point) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(point);
generator->PressLeftButton();
generator->ReleaseLeftButton();
}
void LongPressAt(const gfx::Point& point) {
ui::GestureEvent long_press(
point.x(), point.y(), 0, base::TimeTicks::Now(),
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
GetEventGenerator()->Dispatch(&long_press);
}
};
// Instantiate the values in the parameterized tests. Used to
// toggle mouse and touch events and in some tests to toggle fullscreen mode
// tests.
INSTANTIATE_TEST_SUITE_P(All, AppListPresenterTest, testing::Bool());
// Tests tablet and clamshell mode combinations.
class AppListBubbleAndTabletTestBase : public AshTestBase {
public:
explicit AppListBubbleAndTabletTestBase(bool tablet_mode)
: tablet_mode_(tablet_mode) {}
AppListBubbleAndTabletTestBase(const AppListBubbleAndTabletTestBase&) =
delete;
AppListBubbleAndTabletTestBase& operator=(
const AppListBubbleAndTabletTestBase&) = delete;
~AppListBubbleAndTabletTestBase() override = default;
// testing::Test:
void SetUp() override {
AshTestBase::SetUp();
// Make the display big enough to hold the app list.
UpdateDisplay("1024x768");
}
AppsGridView* GetAppsGridView() {
if (tablet_mode_param())
return GetAppListTestHelper()->GetRootPagedAppsGridView();
return GetAppListTestHelper()->GetScrollableAppsGridView();
}
void SetupGridTestApi() {
grid_test_api_ =
std::make_unique<test::AppsGridViewTestApi>(GetAppsGridView());
}
void OnReorderAnimationDone(base::OnceClosure closure,
bool aborted,
AppListGridAnimationStatus status) {
EXPECT_FALSE(aborted);
EXPECT_EQ(AppListGridAnimationStatus::kReorderFadeIn, status);
std::move(closure).Run();
}
void SortAppList(AppListSortOrder order) {
tablet_mode_param()
? GetAppListTestHelper()
->GetAppsContainerView()
->UpdateForNewSortingOrder(
order,
/*animate=*/true,
/*update_position_closure=*/base::DoNothing(),
/*animation_done_closure=*/base::DoNothing())
: GetAppListTestHelper()->GetBubbleView()->UpdateForNewSortingOrder(
order,
/*animate=*/true, /*update_position_closure=*/base::DoNothing());
base::RunLoop run_loop;
GetAppsGridView()->AddReorderCallbackForTest(base::BindRepeating(
&AppListBubbleAndTabletTestBase::OnReorderAnimationDone,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
}
// Whether we should run the test in tablet mode.
bool tablet_mode_param() { return tablet_mode_; }
// Bubble launcher is visible in clamshell mode.
bool should_show_bubble_launcher() { return !tablet_mode_param(); }
test::AppListTestModel* GetAppListModel() {
return GetAppListTestHelper()->model();
}
SearchBoxView* GetSearchBoxView() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleSearchBoxView()
: GetAppListTestHelper()->GetAppListView()->search_box_view();
}
SearchResultPageView* GetFullscreenSearchPage() {
return GetAppListTestHelper()
->GetAppListView()
->app_list_main_view()
->contents_view()
->search_result_page_view();
}
bool AppListSearchResultPageVisible() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleSearchPage()->GetVisible()
: GetFullscreenSearchPage()->GetVisible();
}
SearchResultContainerView* GetDefaultSearchResultListView() {
if (should_show_bubble_launcher()) {
return GetAppListTestHelper()
->GetBubbleAppListSearchView()
->result_container_views_for_test()[kBestMatchContainerIndex];
}
return GetFullscreenSearchPage()
->search_view()
->result_container_views_for_test()[kBestMatchContainerIndex];
}
ResultSelectionController* GetResultSelectionController() {
if (should_show_bubble_launcher()) {
return GetAppListTestHelper()
->GetBubbleAppListSearchView()
->result_selection_controller_for_test();
}
return GetFullscreenSearchPage()
->search_view()
->result_selection_controller_for_test();
}
SearchResultPageAnchoredDialog* GetSearchResultPageDialog() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleSearchPageDialog()
: GetAppListTestHelper()->GetFullscreenSearchPageDialog();
}
void CancelSearchResultPageDialog() {
views::Widget* widget = GetSearchResultPageDialog()->widget();
views::WidgetDelegate* widget_delegate = widget->widget_delegate();
views::test::WidgetDestroyedWaiter widget_waiter(widget);
GestureTapOn(static_cast<RemoveQueryConfirmationDialog*>(widget_delegate)
->GetCancelButtonForTesting());
widget_waiter.Wait();
}
void AcceptSearchResultPageDialog() {
views::Widget* widget = GetSearchResultPageDialog()->widget();
views::WidgetDelegate* widget_delegate = widget->widget_delegate();
views::test::WidgetDestroyedWaiter widget_waiter(widget);
GestureTapOn(static_cast<RemoveQueryConfirmationDialog*>(widget_delegate)
->GetAcceptButtonForTesting());
widget_waiter.Wait();
}
ContinueSectionView* GetContinueSectionView() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleContinueSectionView()
: GetAppListTestHelper()->GetFullscreenContinueSectionView();
}
RecentAppsView* GetRecentAppsView() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleRecentAppsView()
: GetAppListTestHelper()->GetFullscreenRecentAppsView();
}
views::View* GetAppsSeparator() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleLauncherAppsSeparatorView()
: GetAppListTestHelper()
->GetFullscreenLauncherAppsSeparatorView();
}
AppListFolderView* GetFolderView() {
return should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleFolderView()
: GetAppListTestHelper()->GetFullscreenFolderView();
}
void DeleteFolderItemChildren(AppListFolderItem* item) {
std::vector<std::string> items_to_delete;
for (size_t i = 0; i < item->ChildItemCount(); ++i) {
items_to_delete.push_back(item->GetChildItemAt(i)->id());
}
for (auto& item_to_delete : items_to_delete)
GetAppListModel()->DeleteItem(item_to_delete);
}
void LongPressAt(const gfx::Point& point) {
ui::GestureEvent long_press(
point.x(), point.y(), 0, base::TimeTicks::Now(),
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
GetEventGenerator()->Dispatch(&long_press);
}
void EnsureBubbleLauncherShown() {
Shell::Get()->app_list_controller()->bubble_presenter_for_test()->Show(
GetPrimaryDisplay().id());
}
void EnsureLauncherShown() {
const bool in_tablet_mode = Shell::Get()->IsInTabletMode();
// App list always visible in tablet mode, so launcher needs to explicitly
// be shown only when in clamshell mode.
if (!in_tablet_mode)
EnsureBubbleLauncherShown();
auto* helper = GetAppListTestHelper();
if (!in_tablet_mode) {
apps_grid_view_ = helper->GetScrollableAppsGridView();
} else {
apps_grid_view_ = helper->GetRootPagedAppsGridView();
}
DCHECK(apps_grid_view_);
}
gfx::Point SearchBoxCenterPoint() {
SearchBoxView* search_box_view =
should_show_bubble_launcher()
? GetAppListTestHelper()->GetBubbleSearchBoxView()
: GetAppListTestHelper()->GetAppListView()->search_box_view();
return search_box_view->GetBoundsInScreen().CenterPoint();
}
AppListFolderView* folder_view() {
auto* helper = GetAppListTestHelper();
return should_show_bubble_launcher() ? helper->GetBubbleFolderView()
: helper->GetFullscreenFolderView();
}
bool AppListIsInFolderView() {
return GetAppListTestHelper()->IsInFolderView();
}
protected:
const bool tablet_mode_;
std::unique_ptr<test::AppsGridViewTestApi> grid_test_api_;
raw_ptr<AppsGridView, DanglingUntriaged> apps_grid_view_ = nullptr;
};
// Parameterized by tablet/clamshell mode.
class AppListBubbleAndTabletTest : public AppListBubbleAndTabletTestBase,
public testing::WithParamInterface<bool> {
public:
AppListBubbleAndTabletTest()
: AppListBubbleAndTabletTestBase(/*tablet_mode=*/GetParam()) {}
AppListBubbleAndTabletTest(const AppListBubbleAndTabletTest&) = delete;
AppListBubbleAndTabletTest& operator=(const AppListBubbleAndTabletTest&) =
delete;
~AppListBubbleAndTabletTest() override = default;
};
// Instantiate the values in the parameterized tests. The boolean
// determines whether to run the test in tablet mode.
INSTANTIATE_TEST_SUITE_P(TabletMode,
AppListBubbleAndTabletTest,
testing::Bool());
// Subclass suite to test drag specific behavior, parameterized by
// tablet/clamshell mode and drag and whether drag and drop refactor is enabled.
class AppListBubbleAndTabletDragTest
: public AppListBubbleAndTabletTestBase,
public testing::WithParamInterface<bool> {
public:
AppListBubbleAndTabletDragTest()
: AppListBubbleAndTabletTestBase(
/*tablet_mode=*/GetParam()) {}
AppListBubbleAndTabletDragTest(const AppListBubbleAndTabletDragTest&) =
delete;
AppListBubbleAndTabletDragTest& operator=(
const AppListBubbleAndTabletDragTest&) = delete;
~AppListBubbleAndTabletDragTest() override = default;
};
// Instantiate the values in the parameterized tests. The boolean
// determines whether to run the test in tablet mode.
INSTANTIATE_TEST_SUITE_P(TabletMode,
AppListBubbleAndTabletDragTest,
testing::Bool());
// Tests only tablet mode.
class AppListTabletTest : public AppListBubbleAndTabletTestBase {
public:
AppListTabletTest() : AppListBubbleAndTabletTestBase(/*tablet_mode=*/true) {}
AppListTabletTest(const AppListTabletTest&) = delete;
AppListTabletTest& operator=(const AppListTabletTest&) = delete;
~AppListTabletTest() override = default;
};
// Used to test app_list behavior with a populated apps_grid.
class PopulatedAppListTest : public AshTestBase {
public:
PopulatedAppListTest() {}
~PopulatedAppListTest() override = default;
void SetUp() override {
AppListConfigProvider::Get().ResetForTesting();
AshTestBase::SetUp();
// Make the display big enough to hold the app list.
UpdateDisplay("1024x768");
// Fullscreen launcher is used only in tablet mode, so enable tablet mode.
EnableTabletMode(true);
}
protected:
void OpenAppListInFullscreen() {
AppListPresenterImpl* presenter =
Shell::Get()->app_list_controller()->fullscreen_presenter();
presenter->Show(AppListViewState::kFullscreenAllApps,
GetPrimaryDisplay().id(), base::TimeTicks::Now(),
/*show_source=*/std::nullopt);
app_list_view_ = presenter->GetView();
}
void InitializeAppsGrid() {
if (!app_list_view_)
OpenAppListInFullscreen();
apps_grid_view_ = app_list_view_->app_list_main_view()
->contents_view()
->apps_container_view()
->apps_grid_view();
apps_grid_test_api_ =
std::make_unique<test::AppsGridViewTestApi>(apps_grid_view_);
}
void PopulateApps(int n) {
GetAppListModel()->PopulateApps(n);
app_list_view_->GetWidget()->LayoutRootViewIfNecessary();
}
AppListFolderItem* CreateAndPopulateFolderWithApps(int n) {
auto* folder = GetAppListModel()->CreateAndPopulateFolderWithApps(n);
app_list_view_->GetWidget()->LayoutRootViewIfNecessary();
return folder;
}
gfx::Rect GetItemRectOnCurrentPageAt(int row, int col) {
DCHECK_GT(GetAppListModel()->top_level_item_list()->item_count(), 0u);
return apps_grid_test_api_->GetItemTileRectOnCurrentPageAt(row, col);
}
bool AppListIsInFolderView() const {
return app_list_view_->app_list_main_view()
->contents_view()
->apps_container_view()
->IsInFolderView();
}
AppListFolderView* folder_view() {
return app_list_view_->app_list_main_view()
->contents_view()
->apps_container_view()
->app_list_folder_view();
}
void UpdateFolderName(const std::string& name) {
std::u16string folder_name = base::UTF8ToUTF16(name);
folder_view()->folder_header_view()->SetFolderNameForTest(folder_name);
folder_view()->folder_header_view()->ContentsChanged(
folder_view()->folder_header_view()->GetFolderNameViewForTest(),
folder_name);
}
test::AppListTestModel* GetAppListModel() {
return GetAppListTestHelper()->model();
}
const std::string GetFolderName() {
return base::UTF16ToUTF8(
folder_view()->folder_header_view()->GetFolderNameForTest());
}
void RefreshFolderName() {
folder_view()->folder_header_view()->ItemNameChanged();
}
void RotateScreen() {
display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
display_manager()->SetDisplayRotation(
display.id(), display::Display::ROTATE_90,
display::Display::RotationSource::ACTIVE);
// AppListView is usually notified of display bounds changes by
// AppListPresenter, though the test delegate implementation does not
// track display metrics changes, so OnParentWindowBoundsChanged() has to be
// explicitly called here.
app_list_view_->OnParentWindowBoundsChanged();
}
std::unique_ptr<test::AppsGridViewTestApi> apps_grid_test_api_;
raw_ptr<AppListView, DanglingUntriaged> app_list_view_ =
nullptr; // Owned by native widget.
raw_ptr<PagedAppsGridView, DanglingUntriaged> apps_grid_view_ =
nullptr; // Owned by |app_list_view_|.
};
// Subclass of PopulatedAppListTest which enables the virtual keyboard.
class PopulatedAppListWithVKEnabledTest : public PopulatedAppListTest {
public:
PopulatedAppListWithVKEnabledTest() = default;
~PopulatedAppListWithVKEnabledTest() override = default;
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
PopulatedAppListTest::SetUp();
}
};
// Subclass of PopulatedAppListTest which tests the apps grid drag behavior
// interrumpted during a screen rotation. Enables drag and drop refactor by
// default.
class PopulatedAppListScreenRotationTest : public PopulatedAppListTest {
public:
PopulatedAppListScreenRotationTest() = default;
~PopulatedAppListScreenRotationTest() override = default;
};
// Verify that open folders are closed after sorting apps grid.
TEST_P(AppListBubbleAndTabletTest, SortingClosesOpenFolderView) {
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
GetAppListModel()->CreateAndPopulateFolderWithApps(4);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
grid_test_api_->PressItemAt(0);
EXPECT_TRUE(AppListIsInFolderView());
SortAppList(AppListSortOrder::kNameAlphabetical);
EXPECT_FALSE(AppListIsInFolderView());
}
// Tests that folder item view does not animate out and in after folder is
// closed (and the folder item location in apps grid did not change while the
// folder was shown).
TEST_P(AppListBubbleAndTabletTest,
FolderItemViewNotAnimatingAfterClosingFolder) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Cache the initial folder item bounds.
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* const folder_view = GetFolderView();
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(2);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(
GetFolderView()->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
EXPECT_TRUE(folder_view->IsAnimationRunning());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
base::RunLoop folder_animation_waiter;
// Once folder completes hiding, the folder item view should be moved to
// target location.
folder_view->SetAnimationDoneTestCallback(base::BindLambdaForTesting([&]() {
folder_animation_waiter.Quit();
EXPECT_EQ(original_folder_item_bounds,
folder_item_view->GetBoundsInScreen());
// The folder item position did not change, so the item view should not
// start fading out when the folder view hides.
EXPECT_FALSE(folder_item_view->layer());
}));
folder_animation_waiter.Run();
EXPECT_FALSE(AppListIsInFolderView());
// Verify that the folder is visible, and positioned in its final bounds.
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// No item layers are expected to be created.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder view bounds do not change if an item gets added to app list
// model while the folder view is visible (even if it changes the folder item
// view position in the root apps grid).
TEST_P(AppListBubbleAndTabletTest,
FolderViewRemainsInPlaceWhenAddingItemToModel) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* const folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect final_folder_item_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Add a new item.
test::AppListTestModel::AppListTestItem* new_item =
model->CreateItem("new_test_item");
new_item->SetPosition(GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->position()
.CreateBefore());
model->AddItem(new_item);
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
grid_test_api_->WaitForItemMoveAnimationDone();
// Verify that the folder view location did not change.
EXPECT_EQ(folder_bounds, GetFolderView()->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(3);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 2 should be laid out right of the folder while the folder
// is shown.
EXPECT_LT(original_folder_item_bounds.right(),
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen().x());
// The item at slot 1 should be laid out left of the folder.
EXPECT_GT(original_folder_item_bounds.x(),
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen().right());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(
GetFolderView()->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
EXPECT_TRUE(folder_view->IsAnimationRunning());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
base::RunLoop folder_animation_waiter;
// Once folder completes hiding, the folder item view should be moved to
// target location.
folder_view->SetAnimationDoneTestCallback(base::BindLambdaForTesting([&]() {
folder_animation_waiter.Quit();
EXPECT_EQ(original_folder_item_bounds,
folder_item_view->GetBoundsInScreen());
// The folder item should start fading out in it's current position.
ASSERT_TRUE(folder_item_view->layer());
EXPECT_EQ(0.0f, folder_item_view->layer()->GetTargetOpacity());
}));
folder_animation_waiter.Run();
EXPECT_FALSE(AppListIsInFolderView());
// Wait for the folder item to fade out.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
grid_test_api_->WaitForItemMoveAnimationDone();
// Make sure the folder item view fade in animation is done.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
// Verify that the folder is visible, and positioned in its final bounds.
EXPECT_EQ(final_folder_item_bounds, folder_item_view->GetBoundsInScreen());
EXPECT_FALSE(folder_item_view->layer());
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Verify that item view layers have been deleted.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder view bounds do not change if position of the original
// folder item view changes in the model (as long as the folder is open).
TEST_P(AppListBubbleAndTabletTest,
FolderViewRemainsInPlaceWhenItemMovedToEndInModel) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* const folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
const gfx::Rect final_folder_item_bounds =
apps_grid_view_->GetItemViewAt(5)->GetBoundsInScreen();
// Move the folder item to the last position in the model.
model->RequestPositionUpdate(folder_id,
GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(5)
->position()
.CreateAfter(),
RequestPositionUpdateReason::kMoveItem);
// Verify that the folder view location did not actually change.
EXPECT_EQ(folder_bounds, folder_view->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(5);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 2 in the model should remain at slot 3 (where it was
// before folder item moved in the model).
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// The item at slot 1 should be remain in place.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(folder_view->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
EXPECT_TRUE(folder_view->IsAnimationRunning());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
base::RunLoop folder_animation_waiter;
// Once folder completes hiding, the folder item view should be moved to
// target location.
folder_view->SetAnimationDoneTestCallback(base::BindLambdaForTesting([&]() {
folder_animation_waiter.Quit();
EXPECT_EQ(original_folder_item_bounds,
folder_item_view->GetBoundsInScreen());
// The folder item should start fading out in it's current position.
ASSERT_TRUE(folder_item_view->layer());
EXPECT_EQ(0.0f, folder_item_view->layer()->GetTargetOpacity());
}));
folder_animation_waiter.Run();
EXPECT_FALSE(AppListIsInFolderView());
// Wait for the folder item to fade out.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
grid_test_api_->WaitForItemMoveAnimationDone();
// Make sure the folder item view fade in animation is done.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
// Verify that the folder is visible, and positioned in its final bounds.
EXPECT_EQ(final_folder_item_bounds, folder_item_view->GetBoundsInScreen());
EXPECT_FALSE(folder_item_view->layer());
// The item at slot 1 should be remain in place.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
// The item at slot 2 in the model should move into original folder item slot.
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Verify that item view layers have been deleted.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder view bounds do not change if position of the original
// folder item view changes in the model (as long as the folder is open).
TEST_P(AppListBubbleAndTabletTest,
FolderViewRemainsInPlaceWhenItemMovedToStartInModel) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* const folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
const gfx::Rect final_folder_item_bounds =
apps_grid_view_->GetItemViewAt(0)->GetBoundsInScreen();
// Move the folder item to the last position in the model.
model->RequestPositionUpdate(folder_id,
GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->position()
.CreateBefore(),
RequestPositionUpdateReason::kMoveItem);
// Verify that the folder view location did not actually change.
EXPECT_EQ(folder_bounds, folder_view->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 3 in the model did not change, so it should remain in
// place.
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// The item at slot 2 in the model should remain in the old position (slot 1).
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(folder_view->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
EXPECT_TRUE(folder_view->IsAnimationRunning());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
base::RunLoop folder_animation_waiter;
// Once folder completes hiding, the folder item view should be moved to
// target location.
folder_view->SetAnimationDoneTestCallback(base::BindLambdaForTesting([&]() {
folder_animation_waiter.Quit();
EXPECT_EQ(original_folder_item_bounds,
folder_item_view->GetBoundsInScreen());
// The folder item should start fading out in it's current position.
ASSERT_TRUE(folder_item_view->layer());
EXPECT_EQ(0.0f, folder_item_view->layer()->GetTargetOpacity());
}));
folder_animation_waiter.Run();
EXPECT_FALSE(AppListIsInFolderView());
// Wait for the folder item to fade out.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
grid_test_api_->WaitForItemMoveAnimationDone();
// Make sure the folder item view fade in animation is done.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
// Verify that the folder is visible, and positioned in its final bounds.
EXPECT_EQ(final_folder_item_bounds, folder_item_view->GetBoundsInScreen());
EXPECT_FALSE(folder_item_view->layer());
// The item at slot 2 in the model should move into original folder item slot.
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// The item at slot 3 in the model should move into new position.
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// Verify that item view layers have been deleted.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder item deletion during folder view hide animation is handled
// well.
TEST_P(AppListBubbleAndTabletTest,
ReorderedFolderItemDeletionDuringFolderClose) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* const folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Move the folder item to the first position in the model.
model->RequestPositionUpdate(folder_id,
GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->position()
.CreateBefore(),
RequestPositionUpdateReason::kMoveItem);
// Verify that the folder view location did not actually change.
EXPECT_EQ(folder_bounds, folder_view->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 3 in the model did not change, so it should remain in
// place.
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// The item at slot 2 in the model should remain in the old position (slot 1).
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(folder_view->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
// Delete the folder item while the folder is animating out.
DeleteFolderItemChildren(folder_item);
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
// Verify remaining items are moved into correct slots.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// Verify that item view layers have been deleted.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder item deletion just after folder gets hidden (while item
// bounds are still animating to final positions) gets handled well.
TEST_P(AppListBubbleAndTabletTest,
ReorderedFolderItemDeletionDuringFolderItemFadeOut) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Move the folder item to the last position in the model.
model->RequestPositionUpdate(folder_id,
GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->position()
.CreateBefore(),
RequestPositionUpdateReason::kMoveItem);
// Verify that the folder view location did not actually change.
EXPECT_EQ(folder_bounds, folder_view->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 3 in the model did not change, so it should remain in
// place.
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// The item at slot 2 in the model should remain in the old position (slot 1).
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(folder_view->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
EXPECT_TRUE(folder_view->IsAnimationRunning());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
base::RunLoop folder_animation_waiter;
// Once folder completes hiding, the folder item view should be moved to
// target location.
folder_view->SetAnimationDoneTestCallback(base::BindLambdaForTesting([&]() {
folder_animation_waiter.Quit();
// Delete the folder item while items are animating into their final
// positions.
DeleteFolderItemChildren(folder_item);
}));
folder_animation_waiter.Run();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
// Verify remaining items are moved into correct slots.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// Verify that item view layers have been deleted.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder item deletion just after folder gets hidden (while item
// bounds are still animating to final positions) gets handled well.
TEST_P(AppListBubbleAndTabletTest,
ReorderedFolderItemDeletionAfterFolderItemFadeOut) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Move the folder item to the last position in the model.
model->RequestPositionUpdate(folder_id,
GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->position()
.CreateBefore(),
RequestPositionUpdateReason::kMoveItem);
// Verify that the folder view location did not actually change.
EXPECT_EQ(folder_bounds, folder_view->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 3 in the model did not change, so it should remain in
// place.
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// The item at slot 2 in the model should remain in the old position (slot 1).
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(folder_view->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
EXPECT_TRUE(folder_view->IsAnimationRunning());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
GetAppListTestHelper()->WaitForFolderAnimation();
// Wait for the folder item to fade out.
if (folder_item_view->layer()) {
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(folder_item_view->layer());
}
// Delete the folder item while items are animating into their final
// positions.
DeleteFolderItemChildren(folder_item);
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
// Verify remaining items are moved into correct slots.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// Verify that item view layers have been deleted.
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests that folder item deletion while the folder is shown gets handled well.
TEST_P(AppListBubbleAndTabletTest,
ReorderedFolderItemDeletionWhileFolderShown) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
GetAppListTestHelper()->WaitForFolderAnimation();
AppListFolderView* folder_view = GetFolderView();
// Cache the initial folder bounds.
const gfx::Rect folder_bounds = folder_view->GetBoundsInScreen();
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Move the folder item to the last position in the model.
model->RequestPositionUpdate(folder_id,
GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->position()
.CreateBefore(),
RequestPositionUpdateReason::kMoveItem);
// Verify that the folder view location did not actually change.
EXPECT_EQ(folder_bounds, folder_view->GetBoundsInScreen());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_TRUE(folder_item_view);
ASSERT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(original_folder_item_bounds, folder_item_view->GetBoundsInScreen());
// The item at slot 3 in the model did not change, so it should remain in
// place.
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
// The item at slot 2 in the model should remain in the old position (slot 1).
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
// Delete the folder item while it's still shown.
DeleteFolderItemChildren(folder_item);
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
// Verify remaining items are moved into correct slots.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
}
// Tests that folder item deletion while the folder view is still animating into
// shown state gets handled well.
TEST_P(AppListBubbleAndTabletTest, ReorderedFolderItemDeletionDuringShow) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* const folder_item =
model->CreateAndPopulateFolderWithApps(3);
const std::string folder_id = folder_item->id();
model->PopulateApps(3);
// Setup tablet/clamshell mode and show launcher.
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
SetupGridTestApi();
ui::ScopedAnimationDurationScaleMode scope_duration(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
grid_test_api_->PressItemAt(2);
EXPECT_TRUE(AppListIsInFolderView());
// Cache the initial folder bounds.
const gfx::Rect original_folder_item_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
const gfx::Rect original_item_1_bounds =
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen();
const gfx::Rect original_item_3_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Delete the folder item while the folder is still showing.
DeleteFolderItemChildren(folder_item);
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
// Verify remaining items are moved into correct slots.
EXPECT_EQ(original_item_1_bounds,
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen());
EXPECT_EQ(original_folder_item_bounds,
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen());
EXPECT_EQ(original_item_3_bounds,
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen());
}
// Tests that Zero State Search is only shown when needed.
TEST_P(AppListBubbleAndTabletTest, LauncherSearchZeroState) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
ui::test::EventGenerator* generator = GetEventGenerator();
// Tap Search Box to activate it and check search result view visibility.
generator->GestureTapAt(SearchBoxCenterPoint());
EXPECT_FALSE(AppListSearchResultPageVisible());
// Type a character into the textfield and check visibility.
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Delete the character in the textfield and check visibility.
generator->PressKey(ui::VKEY_BACK, 0);
EXPECT_FALSE(AppListSearchResultPageVisible());
}
// Verifies that changes in launcher search box do not cause duplicate search
// requests if both clamshell and tablet app list views exist (and one of them
// is hidden).
TEST_P(AppListBubbleAndTabletTest, NoDuplicateSearchRequests) {
// Toggle tablet mode to ensure the app list view for tablet mode state
// opposite to the one used in test is created.
EnableTabletMode(!tablet_mode_param());
EnsureLauncherShown();
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Type a character into the textfield and verify this issues a single search
// request.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
TestAppListClient* const client = GetAppListTestHelper()->app_list_client();
EXPECT_EQ(std::vector<std::u16string>({u"a"}),
client->GetAndResetPastSearchQueries());
generator->PressKey(ui::VKEY_B, 0);
EXPECT_EQ(std::vector<std::u16string>({u"ab"}),
client->GetAndResetPastSearchQueries());
generator->PressKey(ui::VKEY_BACK, 0);
EXPECT_EQ(std::vector<std::u16string>({u"a"}),
client->GetAndResetPastSearchQueries());
generator->PressKey(ui::VKEY_BACK, 0);
EXPECT_EQ(std::vector<std::u16string>({u""}),
client->GetAndResetPastSearchQueries());
}
TEST_P(AppListBubbleAndTabletTest, ClearSearchButtonClearsSearch) {
// Toggle tablet mode to ensure the app list view for tablet mode state
// opposite to the one used in test is created.
EnableTabletMode(!tablet_mode_param());
EnsureLauncherShown();
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Type a character into the textfield and verify this issues a single search
// request.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
TestAppListClient* const client = GetAppListTestHelper()->app_list_client();
EXPECT_EQ(std::vector<std::u16string>({u"a"}),
client->GetAndResetPastSearchQueries());
generator->PressKey(ui::VKEY_B, 0);
EXPECT_EQ(std::vector<std::u16string>({u"ab"}),
client->GetAndResetPastSearchQueries());
SearchBoxView* search_box_view = GetSearchBoxView();
search_box_view->GetWidget()->LayoutRootViewIfNecessary();
EXPECT_TRUE(
search_box_view->filter_and_close_button_container()->GetVisible());
LeftClickOn(search_box_view->close_button());
EXPECT_EQ(std::vector<std::u16string>({u""}),
client->GetAndResetPastSearchQueries());
}
// Regression test for b/204482740.
TEST_P(AppListBubbleAndTabletTest, AppListEventTargeterForAssistantScrolling) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// A custom event targeter is installed.
aura::Window* window = Shell::Get()->app_list_controller()->GetWindow();
ASSERT_TRUE(window);
aura::WindowTargeter* targeter = window->targeter();
ASSERT_TRUE(targeter);
// Simulate an assistant card with a webview being shown, which sets a window
// property on its window. See AssistantCardElementView::AddedToWidget().
aura::Window* child =
aura::test::CreateTestWindowWithBounds(gfx::Rect(100, 100), window);
child->SetProperty(assistant::ui::kOnlyAllowMouseClickEvents, true);
// Scroll events are blocked for that window.
constexpr int offset = 10;
ui::ScrollEvent scroll_down(ui::EventType::kScroll, gfx::Point(),
base::TimeTicks::Now(), ui::EF_NONE, 0, offset, 0,
offset, /*finger_count=*/2);
EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(child, scroll_down));
// Click events are not blocked.
ui::MouseEvent press(ui::EventType::kMousePressed, gfx::Point(), gfx::Point(),
base::TimeTicks::Now(), ui::EF_NONE,
ui::EF_LEFT_MOUSE_BUTTON);
ui::MouseEvent release(ui::EventType::kMouseReleased, gfx::Point(),
gfx::Point(), base::TimeTicks::Now(), ui::EF_NONE,
ui::EF_LEFT_MOUSE_BUTTON);
EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(child, press));
EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(child, press));
}
// Tests that apps container/page does not have a separator between apps grid
// and recent apps/continue section if neither continue section nor recent apps
// are shown.
TEST_P(AppListBubbleAndTabletTest,
NoSeparatorWithoutRecentAppsOrContinueSection) {
GetAppListTestHelper()->AddAppItems(5);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
views::View* separator = GetAppsSeparator();
EXPECT_TRUE(separator);
RecentAppsView* recent_apps = GetRecentAppsView();
EXPECT_TRUE(recent_apps);
ContinueSectionView* continue_section = GetContinueSectionView();
EXPECT_TRUE(continue_section);
EXPECT_FALSE(separator->GetVisible());
EXPECT_FALSE(recent_apps->GetVisible());
EXPECT_FALSE(continue_section->GetVisible());
// If some content gets added to continue section, separator is expected to
// show.
GetAppListTestHelper()->AddContinueSuggestionResults(3);
// Run loop, as continue section content is updated asynchronously.
base::RunLoop().RunUntilIdle();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
EXPECT_TRUE(separator->GetVisible());
EXPECT_TRUE(continue_section->GetVisible());
EXPECT_FALSE(recent_apps->GetVisible());
}
// Tests that apps container/page has a separator between apps grid
// and recent apps/continue section if recent apps are shown.
TEST_P(AppListBubbleAndTabletTest, SeparatorShownWithRecentApps) {
GetAppListTestHelper()->AddAppItems(5);
GetAppListTestHelper()->AddRecentApps(4);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
views::View* separator = GetAppsSeparator();
EXPECT_TRUE(separator);
RecentAppsView* recent_apps = GetRecentAppsView();
EXPECT_TRUE(recent_apps);
ContinueSectionView* continue_section = GetContinueSectionView();
EXPECT_TRUE(continue_section);
EXPECT_TRUE(separator->GetVisible());
EXPECT_TRUE(recent_apps->GetVisible());
EXPECT_FALSE(continue_section->GetVisible());
}
// Tests that apps container/page has a separator between apps grid
// and recent apps/continue section if continue section is shown.
TEST_P(AppListBubbleAndTabletTest, SeparatorShownWithContinueSection) {
GetAppListTestHelper()->AddAppItems(5);
GetAppListTestHelper()->AddContinueSuggestionResults(4);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
views::View* separator = GetAppsSeparator();
EXPECT_TRUE(separator);
RecentAppsView* recent_apps = GetRecentAppsView();
EXPECT_TRUE(recent_apps);
ContinueSectionView* continue_section = GetContinueSectionView();
EXPECT_TRUE(continue_section);
EXPECT_TRUE(separator->GetVisible());
EXPECT_TRUE(continue_section->GetVisible());
EXPECT_FALSE(recent_apps->GetVisible());
}
// Tests that apps container/page has a separator between apps grid
// and recent apps/continue section if recent apps and continue section are
// shown.
TEST_P(AppListBubbleAndTabletTest,
SeparatorShownWithContinueSectionAndRecentApps) {
GetAppListTestHelper()->AddAppItems(5);
GetAppListTestHelper()->AddContinueSuggestionResults(4);
GetAppListTestHelper()->AddRecentApps(4);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
views::View* separator = GetAppsSeparator();
EXPECT_TRUE(separator);
RecentAppsView* recent_apps = GetRecentAppsView();
EXPECT_TRUE(recent_apps);
ContinueSectionView* continue_section = GetContinueSectionView();
EXPECT_TRUE(continue_section);
EXPECT_TRUE(separator->GetVisible());
EXPECT_TRUE(recent_apps->GetVisible());
EXPECT_TRUE(continue_section->GetVisible());
}
// Test that the separator is centered between recent apps and the first row
// of the apps grid, when recent apps are shown.
TEST_F(AppListTabletTest, SeparatorCenteredBetweenRecentAppsAndAppsGrid) {
GetAppListTestHelper()->AddAppItems(5);
GetAppListTestHelper()->AddContinueSuggestionResults(3);
EnableTabletMode(true);
views::View* separator = GetAppsSeparator();
AppsContainerView* apps_container =
GetAppListTestHelper()->GetAppsContainerView();
// Separator is not centered and should be positioned below the continue
// section, because recent apps are not shown.
EXPECT_EQ(separator->GetBoundsInScreen().y(),
GetContinueSectionView()->GetBoundsInScreen().bottom() +
separator->GetProperty(views::kMarginsKey)->height() / 2);
// Add recent apps and layout to update the separator's bounds.
GetAppListTestHelper()->AddRecentApps(4);
apps_container->ResetForShowApps();
GetAppsGridView()->GetWidget()->LayoutRootViewIfNecessary();
views::View* recent_apps = GetRecentAppsView();
SetupGridTestApi();
const AppListItemView* first_row_item =
grid_test_api_->GetViewAtIndex(GridIndex(0, 0));
// Separator should be centered between the bottom of recent apps and the
// top of the first row of the apps grid.
const int centered_y = recent_apps->GetBoundsInScreen().bottom() +
(first_row_item->GetBoundsInScreen().y() -
recent_apps->GetBoundsInScreen().bottom()) /
2;
EXPECT_EQ(centered_y, separator->GetBoundsInScreen().y());
}
// Verifies that tapping on the search box in tablet mode with animation and
// zero state enabled should not bring Chrome crash (https://crbug.com/958267).
TEST_P(AppListPresenterTest, ClickSearchBoxInTabletMode) {
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Necessary for AppListView::StateAnimationMetricsReporter::Report being
// called when animation ends.
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
ui::test::EventGenerator* generator = GetEventGenerator();
// Gesture tap on the search box.
generator->GestureTapAt(GetPointInsideSearchbox());
// Wait until animation finishes. Verifies AppListView's state.
base::RunLoop().RunUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
// Gesture tap on the area out of search box.
generator->GestureTapAt(GetPointOutsideSearchbox());
// Wait until animation finishes. Verifies AppListView's state.
base::RunLoop().RunUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
}
TEST_P(AppListBubbleAndTabletTest, RemoveSuggestionShowsConfirmDialog) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add suggestion results - the result that will be tested is in
// the second place.
GetSearchModel()->results()->Add(CreateOmniboxSuggestionResult(
"Another suggestion", /*support_removal=*/true));
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/true));
// The result list is updated asynchronously.
base::RunLoop().RunUntilIdle();
SearchResultBaseView* result_view =
GetDefaultSearchResultListView()->GetResultViewAt(1);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
ASSERT_EQ(kTestResultId, result_view->result()->id());
// Make sure the search results page is laid out after adding result action
// buttons.
result_view->GetWidget()->LayoutRootViewIfNecessary();
ASSERT_TRUE(result_view->actions_view());
EXPECT_EQ(1u, result_view->actions_view()->children().size());
views::View* const action_view = result_view->actions_view()->children()[0];
// The remove action button is visible on hover only.
EXPECT_FALSE(action_view->GetVisible());
generator->MoveMouseTo(result_view->GetBoundsInScreen().CenterPoint());
EXPECT_TRUE(action_view->GetVisible());
// Record the current result selection before clicking the remove action
// button.
ResultSelectionController* result_selection_controller =
GetResultSelectionController();
EXPECT_TRUE(result_selection_controller->selected_result()->selected());
ResultLocationDetails* result_location =
result_selection_controller->selected_location_details();
// Ensure layout after the action view visibility has been updated.
result_view->GetWidget()->LayoutRootViewIfNecessary();
// Click the remove action button, this should surface a confirmation dialog.
LeftClickOn(action_view);
EXPECT_TRUE(GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions()
.empty());
ASSERT_TRUE(GetSearchResultPageDialog());
// Cancel the dialog - the app list should remain in the search result page,
// the suggestion removal dialog should be hidden, and no result action should
// be invoked.
CancelSearchResultPageDialog();
EXPECT_TRUE(AppListSearchResultPageVisible());
EXPECT_FALSE(GetSearchResultPageDialog());
EXPECT_TRUE(GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions()
.empty());
// The result selection should be at the same position.
EXPECT_TRUE(result_selection_controller->selected_result()->selected());
EXPECT_EQ(*result_location,
*result_selection_controller->selected_location_details());
// Make sure that the action view is shown.
generator->MoveMouseTo(action_view->GetBoundsInScreen().left_center());
EXPECT_TRUE(action_view->GetVisible());
// Ensure layout after the action view visibility has been updated.
result_view->GetWidget()->LayoutRootViewIfNecessary();
// Click remove suggestion action button again.
generator->MoveMouseTo(action_view->GetBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
// Expect the removal confirmation dialog - this time, accept it.
ASSERT_TRUE(GetSearchResultPageDialog());
AcceptSearchResultPageDialog();
// The app list should remain showing search results, the dialog should be
// closed, and result removal action should be invoked.
EXPECT_TRUE(AppListSearchResultPageVisible());
EXPECT_FALSE(GetSearchResultPageDialog());
// A result should still be selected.
EXPECT_TRUE(result_selection_controller->selected_result()->selected());
std::vector<TestAppListClient::SearchResultActionId> expected_actions = {
{kTestResultId, SearchResultActionType::kRemove}};
std::vector<TestAppListClient::SearchResultActionId> invoked_actions =
GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions();
EXPECT_EQ(expected_actions, invoked_actions);
}
TEST_P(AppListBubbleAndTabletTest, RemoveSuggestionUsingLongTap) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add suggestion results - the result that will be tested is in
// the second place.
GetSearchModel()->results()->Add(CreateOmniboxSuggestionResult(
"Another suggestion", /*support_removal=*/true));
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/true));
GetAppListTestHelper()->WaitUntilIdle();
SearchResultBaseView* result_view =
GetDefaultSearchResultListView()->GetResultViewAt(1);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
ASSERT_EQ(kTestResultId, result_view->result()->id());
// Make sure the search results page is laid out after adding result action
// buttons.
result_view->GetWidget()->LayoutRootViewIfNecessary();
ASSERT_TRUE(result_view->actions_view());
EXPECT_EQ(1u, result_view->actions_view()->children().size());
views::View* const action_view = result_view->actions_view()->children()[0];
EXPECT_FALSE(action_view->GetVisible());
LongPressAt(result_view->GetBoundsInScreen().CenterPoint());
EXPECT_TRUE(action_view->GetVisible());
// Ensure layout after the action view visibility has been updated.
result_view->GetWidget()->LayoutRootViewIfNecessary();
// Click the remove action button, this should surface a confirmation dialog.
LeftClickOn(action_view);
EXPECT_TRUE(GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions()
.empty());
ASSERT_TRUE(GetSearchResultPageDialog());
// Cancel the dialog - the app list should remain in the search result page,
// the suggestion removal dialog should be hidden, and no result action should
// be invoked.
CancelSearchResultPageDialog();
EXPECT_TRUE(AppListSearchResultPageVisible());
EXPECT_FALSE(GetSearchResultPageDialog());
EXPECT_TRUE(GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions()
.empty());
EXPECT_FALSE(result_view->selected());
// Long tap on the result again.
LongPressAt(result_view->GetBoundsInScreen().CenterPoint());
// Ensure layout after the action view visibility has been updated.
result_view->GetWidget()->LayoutRootViewIfNecessary();
// Click the remove action button, this should surface a confirmation dialog.
LeftClickOn(action_view);
// Expect the removal confirmation dialog - this time, accept it.
ASSERT_TRUE(GetSearchResultPageDialog());
AcceptSearchResultPageDialog();
// The app list should remain showing search results, the dialog should be
// closed, and result removal action should be invoked.
EXPECT_TRUE(AppListSearchResultPageVisible());
EXPECT_FALSE(GetSearchResultPageDialog());
EXPECT_FALSE(result_view->selected());
std::vector<TestAppListClient::SearchResultActionId> expected_actions = {
{kTestResultId, SearchResultActionType::kRemove}};
std::vector<TestAppListClient::SearchResultActionId> invoked_actions =
GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions();
EXPECT_EQ(expected_actions, invoked_actions);
}
TEST_P(AppListBubbleAndTabletTest, RemoveSuggestionUsingKeyboard) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add suggestion results - the result that will be tested is in
// the second place.
GetSearchModel()->results()->Add(CreateOmniboxSuggestionResult(
"Another suggestion", /*support_removal=*/true));
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/true));
GetAppListTestHelper()->WaitUntilIdle();
// Select a removable suggestion.
generator->PressKey(ui::VKEY_DOWN, 0);
SearchResultBaseView* result_view =
GetDefaultSearchResultListView()->GetResultViewAt(1);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
ASSERT_EQ(kTestResultId, result_view->result()->id());
ASSERT_TRUE(result_view->selected());
ASSERT_TRUE(result_view->actions_view());
EXPECT_EQ(1u, result_view->actions_view()->children().size());
// Press shortcut to delete the result.
generator->PressKey(ui::VKEY_BROWSER_BACK, ui::EF_ALT_DOWN);
EXPECT_TRUE(GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions()
.empty());
ASSERT_TRUE(GetSearchResultPageDialog());
// Expect the removal confirmation dialog - accept it.
ASSERT_TRUE(GetSearchResultPageDialog());
AcceptSearchResultPageDialog();
// The app list should remain showing search results, the dialog should be
// closed, and result removal action should be invoked.
EXPECT_TRUE(AppListSearchResultPageVisible());
EXPECT_FALSE(GetSearchResultPageDialog());
EXPECT_FALSE(result_view->selected());
std::vector<TestAppListClient::SearchResultActionId> expected_actions = {
{kTestResultId, SearchResultActionType::kRemove}};
std::vector<TestAppListClient::SearchResultActionId> invoked_actions =
GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions();
EXPECT_EQ(expected_actions, invoked_actions);
}
TEST_P(AppListBubbleAndTabletTest,
SuggestionRemoveShortcutOnViewWithNoRemovalAction) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add suggestion results.
GetSearchModel()->results()->Add(CreateOmniboxSuggestionResult(
"Another suggestion", /*support_removal=*/false));
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/false));
GetAppListTestHelper()->WaitUntilIdle();
generator->PressKey(ui::VKEY_DOWN, 0);
SearchResultBaseView* result_view =
GetDefaultSearchResultListView()->GetResultViewAt(1);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
ASSERT_EQ(kTestResultId, result_view->result()->id());
ASSERT_TRUE(result_view->selected());
// Press shortcut to delete the result.
generator->PressKey(ui::VKEY_BROWSER_BACK, ui::EF_ALT_DOWN);
EXPECT_TRUE(GetAppListTestHelper()
->app_list_client()
->GetAndResetInvokedResultActions()
.empty());
EXPECT_FALSE(GetSearchResultPageDialog());
EXPECT_TRUE(AppListSearchResultPageVisible());
EXPECT_EQ(u"a", GetSearchBoxView()->search_box()->GetText());
result_view = GetDefaultSearchResultListView()->GetResultViewAt(1);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
EXPECT_EQ(kTestResultId, result_view->result()->id());
EXPECT_TRUE(result_view->selected());
}
TEST_P(AppListBubbleAndTabletTest,
TransitionToAppsContainerClosesRemoveSuggestionDialog) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add a zero state suggestion result.
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/true));
GetAppListTestHelper()->WaitUntilIdle();
SearchResultBaseView* result_view =
GetDefaultSearchResultListView()->GetResultViewAt(0);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
ASSERT_EQ(kTestResultId, result_view->result()->id());
// Show remove suggestion dialog.
result_view->GetWidget()->LayoutRootViewIfNecessary();
LongPressAt(result_view->GetBoundsInScreen().CenterPoint());
result_view->GetWidget()->LayoutRootViewIfNecessary();
LeftClickOn(result_view->actions_view()->children()[0]);
ASSERT_TRUE(GetSearchResultPageDialog());
views::Widget* const confirmation_dialog =
GetSearchResultPageDialog()->widget();
ASSERT_TRUE(confirmation_dialog);
SanityCheckSearchResultsAnchoredDialogBounds(confirmation_dialog,
GetSearchBoxView());
// Verify that transition to apps page hides the removal confirmation dialog.
views::test::WidgetDestroyedWaiter widget_close_waiter(confirmation_dialog);
GetSearchBoxView()->ClearSearchAndDeactivateSearchBox();
EXPECT_FALSE(AppListSearchResultPageVisible());
widget_close_waiter.Wait();
}
TEST_P(AppListBubbleAndTabletTest,
RemoveSuggestionDialogBoundsUpdateWhenVKHidden) {
// Enable virtual keyboard for this test.
KeyboardController* const keyboard_controller =
Shell::Get()->keyboard_controller();
keyboard_controller->SetEnableFlag(
keyboard::KeyboardEnableFlag::kCommandLineEnabled);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add a suggestion result.
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/true));
GetAppListTestHelper()->WaitUntilIdle();
SearchResultBaseView* result_view =
GetDefaultSearchResultListView()->GetResultViewAt(0);
ASSERT_TRUE(result_view);
ASSERT_TRUE(result_view->result());
ASSERT_EQ(kTestResultId, result_view->result()->id());
auto* const keyboard_ui_controller = keyboard::KeyboardUIController::Get();
keyboard_ui_controller->ShowKeyboard(false /* locked */);
ASSERT_TRUE(keyboard::test::WaitUntilShown());
// Show remove suggestion dialog.
result_view->GetWidget()->LayoutRootViewIfNecessary();
LongPressAt(result_view->GetBoundsInScreen().CenterPoint());
// Ensure layout after the action view visibility has been updated.
result_view->GetWidget()->LayoutRootViewIfNecessary();
// Click the remove action button, this should surface a confirmation dialog.
LeftClickOn(result_view->actions_view()->children()[0]);
ASSERT_TRUE(GetSearchResultPageDialog());
// The search box should have lost the focus, which should have hidden the
// keyboard.
EXPECT_FALSE(keyboard_ui_controller->IsKeyboardVisible());
// Sanity check the confirmation dialog bounds (hiding the keyboard might have
// changed the position of the search box - the confirmation dialog should
// have followed it).
views::Widget* const confirmation_dialog =
GetSearchResultPageDialog()->widget();
SanityCheckSearchResultsAnchoredDialogBounds(confirmation_dialog,
GetSearchBoxView());
views::test::WidgetDestroyedWaiter widget_close_waiter(confirmation_dialog);
GetSearchBoxView()->ClearSearchAndDeactivateSearchBox();
EXPECT_FALSE(AppListSearchResultPageVisible());
if (tablet_mode_param())
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
// Exiting the search results page should close the dialog.
widget_close_waiter.Wait();
}
// Verifies that rotating the screen when launcher is shown does not crash.
TEST_P(AppListBubbleAndTabletTest, RotationAnimationSmoke) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(15);
model->CreateAndPopulateFolderWithApps(3);
model->PopulateApps(15);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
ScreenRotationAnimator* animator =
DisplayConfigurationControllerTestApi(
Shell::Get()->display_configuration_controller())
.GetScreenRotationAnimatorForDisplay(display.id());
animator->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::USER,
DisplayConfigurationController::ANIMATION_SYNC);
}
// Verifies that rotating the screen and shutting down when the launcher is
// shown does not crash.
TEST_P(AppListBubbleAndTabletTest, ShutdownDuringRotationAnimationSmoke) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(1);
model->CreateAndPopulateFolderWithApps(3);
model->PopulateApps(1);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
ScreenRotationAnimator* animator =
DisplayConfigurationControllerTestApi(
Shell::Get()->display_configuration_controller())
.GetScreenRotationAnimatorForDisplay(display.id());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
animator->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::USER,
DisplayConfigurationController::ANIMATION_SYNC);
}
// Verifies that rotating the screen when launcher is shown does not crash.
TEST_P(AppListBubbleAndTabletTest, RotationAnimationWithFolderSmoke) {
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(1);
model->CreateAndPopulateFolderWithApps(3);
model->PopulateApps(1);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Tap the folder item to show it.
GestureTapOn(apps_grid_view_->GetItemViewAt(1));
ASSERT_TRUE(AppListIsInFolderView());
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
ScreenRotationAnimator* animator =
DisplayConfigurationControllerTestApi(
Shell::Get()->display_configuration_controller())
.GetScreenRotationAnimatorForDisplay(display.id());
animator->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::USER,
DisplayConfigurationController::ANIMATION_SYNC);
// Close the folder view.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(
GetFolderView()->GetBoundsInScreen().right_center() +
gfx::Vector2d(10, 0));
event_generator->ClickLeftButton();
ASSERT_FALSE(AppListIsInFolderView());
EXPECT_FALSE(GetFolderView()->shadow()->GetLayer()->visible());
}
TEST_P(AppListBubbleAndTabletTest, RotationAnimationInSearchSmoke) {
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
// Show search page.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
EXPECT_TRUE(AppListSearchResultPageVisible());
// Add suggestion results - the result that will be tested is in
// the second place.
GetSearchModel()->results()->Add(CreateOmniboxSuggestionResult(
"Another suggestion", /*support_removal=*/true));
const std::string kTestResultId = "Test suggestion";
GetSearchModel()->results()->Add(
CreateOmniboxSuggestionResult(kTestResultId, /*support_removal=*/true));
// The result list is updated asynchronously.
base::RunLoop().RunUntilIdle();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
ScreenRotationAnimator* animator =
DisplayConfigurationControllerTestApi(
Shell::Get()->display_configuration_controller())
.GetScreenRotationAnimatorForDisplay(display.id());
animator->Rotate(display::Display::ROTATE_90,
display::Display::RotationSource::USER,
DisplayConfigurationController::ANIMATION_SYNC);
}
// Tests that mouse app list item drag is cancelled when mouse capture is lost
// (e.g. on screen rotation).
TEST_F(PopulatedAppListTest, CancelItemDragOnMouseCaptureLoss) {
InitializeAppsGrid();
PopulateApps(apps_grid_test_api_->TilesPerPageInPagedGrid(0) + 1);
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(0);
// Start dragging the first item - move it in between items 1 and 2.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressLeftButton();
dragged_view->FireMouseDragTimerForTest();
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
event_generator->MoveMouseTo(
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen().left_center());
EXPECT_TRUE(apps_grid_view_->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
UpdateDisplay("600x1200");
// AppListView is usually notified of display bounds changes by
// AppListPresenter, though the test delegate implementation does not
// track display metrics changes, so OnParentWindowBoundsChanged() has to be
// explicitly called here.
app_list_view_->OnParentWindowBoundsChanged();
// Verify that mouse drag has been canceled due to mouse capture loss.
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ("Item 2", apps_grid_view_->GetItemViewAt(2)->item()->id());
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/false);
}
// Tests that app list item drag gets canceled if the dragged app list item gets
// deleted.
TEST_F(PopulatedAppListTest, CancelItemDragOnDragItemDeletion) {
InitializeAppsGrid();
PopulateApps(4);
// Start dragging a view.
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(0);
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressLeftButton();
dragged_view->FireMouseDragTimerForTest();
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
event_generator->MoveMouseTo(
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen().left_center());
EXPECT_TRUE(apps_grid_view_->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Delete the dragged item.
GetAppListModel()->DeleteItem(dragged_view->item()->id());
// Verify that mouse drag has been canceled.
EXPECT_FALSE(apps_grid_view_->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Required by the DragDropController to finalize drag sequence.
// TODO(b/261985897): Investigate the crash that occurs on these tests if
// they are not properly releasing the drag.
event_generator->ReleaseLeftButton();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/false);
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 2", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ("Item 3", apps_grid_view_->GetItemViewAt(2)->item()->id());
// Hide and show the app list again to verify checks done when resetting the
// apps grid for show pass (e.g. verification that size of the app list views
// model matches the size of app list data model).
AppListTestHelper* helper = GetAppListTestHelper();
helper->ShowAndRunLoop(GetPrimaryDisplay().id());
helper->DismissAndRunLoop();
}
// Tests that app list item drag in folder gets canceled if the dragged app list
// item gets deleted.
TEST_F(PopulatedAppListTest, CancelFolderItemDragOnDragItemDeletion) {
InitializeAppsGrid();
PopulateApps(2);
AppListFolderItem* folder = CreateAndPopulateFolderWithApps(3);
PopulateApps(3);
// Tap the folder item to show it.
GestureTapOn(apps_grid_view_->GetItemViewAt(2));
ASSERT_TRUE(AppListIsInFolderView());
// Start dragging the first item in the active folder.
AppListItemView* const dragged_view =
folder_view()->items_grid_view()->GetItemViewAt(0);
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
event_generator->MoveTouchBy(5, 5);
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_TRUE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Delete the dragged item.
GetAppListModel()->DeleteItem(dragged_view->item()->id());
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Required by the DragDropController to finalize drag sequence.
// TODO(b/261985897): Investigate the crash that occurs on these tests if
// they are not properly releasing the drag.
event_generator->ReleaseTouch();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ(folder->id(), apps_grid_view_->GetItemViewAt(2)->item()->id());
EXPECT_EQ("Item 3",
folder_view()->items_grid_view()->GetItemViewAt(0)->item()->id());
// Hide and show the app list again to verify checks done when resetting the
// apps grid for show pass (e.g. verification that size of the app list views
// model matches the size of app list data model).
AppListTestHelper* helper = GetAppListTestHelper();
helper->ShowAndRunLoop(GetPrimaryDisplay().id());
helper->DismissAndRunLoop();
}
// Tests that app list item drag from folder to root apps grid gets canceled if
// the dragged app list item gets deleted.
TEST_F(PopulatedAppListTest, CancelFolderItemReparentDragOnDragItemDeletion) {
InitializeAppsGrid();
PopulateApps(2);
AppListFolderItem* folder = CreateAndPopulateFolderWithApps(3);
PopulateApps(3);
// Tap the folder item to show it.
GestureTapOn(apps_grid_view_->GetItemViewAt(2));
ASSERT_TRUE(AppListIsInFolderView());
// Start dragging the first item in the active folder.
AppListItemView* const dragged_view =
folder_view()->items_grid_view()->GetItemViewAt(0);
const std::string dragged_app_id = dragged_view->item()->id();
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Generate another mouse event to properly start the drag and drop sequence
// with DragUpdate().
event_generator->MoveTouchBy(5, 5);
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_TRUE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Drag the item outside the folder bounds and fire reparenting timer.
event_generator->MoveTouch(
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen().CenterPoint());
event_generator->MoveTouchBy(2, 2);
EXPECT_FALSE(AppListIsInFolderView());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move item again to generate OnDragEnter()/OnDragExit() event.
event_generator->MoveTouch(
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen().CenterPoint());
EXPECT_TRUE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Delete the dragged item.
GetAppListModel()->DeleteItem(dragged_app_id);
// Verify that drag has been canceled.
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Required by the DragDropController to finalize drag sequence.
// TODO(b/261985897): Investigate the crash that occurs on these tests if
// they are not properly releasing the drag.
event_generator->ReleaseTouch();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ(folder->id(), apps_grid_view_->GetItemViewAt(2)->item()->id());
EXPECT_EQ("Item 5", apps_grid_view_->GetItemViewAt(3)->item()->id());
// Hide and show the app list again to verify checks done when resetting the
// apps grid for show pass (e.g. verification that size of the app list views
// model matches the size of app list data model).
AppListTestHelper* helper = GetAppListTestHelper();
helper->ShowAndRunLoop(GetPrimaryDisplay().id());
helper->DismissAndRunLoop();
}
TEST_F(PopulatedAppListTest,
CancelFolderItemReparentDragOnDragItemAndFolderDeletion) {
InitializeAppsGrid();
PopulateApps(2);
CreateAndPopulateFolderWithApps(2);
PopulateApps(3);
// Tap the folder item to show it.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->GestureTapAt(
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen().CenterPoint());
ASSERT_TRUE(AppListIsInFolderView());
// Start dragging the first item in the active folder.
AppListItemView* const dragged_view =
folder_view()->items_grid_view()->GetItemViewAt(0);
const std::string dragged_app_id = dragged_view->item()->id();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
event_generator->MoveTouchBy(5, 5);
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_TRUE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Drag the item outside the folder bounds.
event_generator->MoveTouch(
apps_grid_view_->GetItemViewAt(1)->GetBoundsInScreen().CenterPoint());
event_generator->MoveTouchBy(2, 2);
EXPECT_FALSE(AppListIsInFolderView());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move item within the main grid.
event_generator->MoveTouch(
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen().CenterPoint());
EXPECT_TRUE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Leave the dragged item as it's folder only child, and then delete it,
// which should also delete the folder.
GetAppListModel()->DeleteItem("Item 3");
GetAppListModel()->DeleteItem(dragged_app_id);
// Verify that drag has been canceled.
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Required by the DragDropController to finalize drag sequence.
// TODO(b/261985897): Investigate the crash that occurs on these tests if
// they are not properly releasing the drag.
event_generator->ReleaseTouch();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ("Item 4", apps_grid_view_->GetItemViewAt(2)->item()->id());
EXPECT_EQ("Item 5", apps_grid_view_->GetItemViewAt(3)->item()->id());
// Hide and show the app list again to verify checks done when resetting the
// apps grid for show pass (e.g. verification that size of the app list views
// model matches the size of app list data model).
AppListTestHelper* helper = GetAppListTestHelper();
helper->ShowAndRunLoop(GetPrimaryDisplay().id());
helper->DismissAndRunLoop();
}
// Tests that apps grid item layers are not destroyed immediately after item
// drag ends.
TEST_F(PopulatedAppListTest,
ItemLayersNotDestroyedDuringBoundsAnimationAfterDrag) {
InitializeAppsGrid();
const int kItemCount = 5;
PopulateApps(kItemCount);
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(0);
// Drag the first item between items 1 and 2.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressLeftButton();
dragged_view->FireMouseDragTimerForTest();
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
event_generator->MoveMouseTo(
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen().left_center());
// Items should have layers during app list item drag.
for (int i = 0; i < kItemCount; ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_TRUE(item_view->layer()) << "at " << i;
}
EXPECT_TRUE(apps_grid_view_->IsDragging());
}));
tasks.push_back(base::BindLambdaForTesting(
[&]() { GetEventGenerator()->ReleaseLeftButton(); }));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/false);
// After the drag is released, the item bounds should animate to their final
// bounds.
EXPECT_TRUE(apps_grid_view_->IsItemAnimationRunning());
for (int i = 0; i < kItemCount; ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_TRUE(item_view->layer()) << "at " << i;
}
// Wait for each item's layer animation to complete.
ui::LayerAnimationStoppedWaiter animation_waiter;
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); i++) {
if (apps_grid_view_->view_model()->view_at(i)->layer())
animation_waiter.Wait(apps_grid_view_->view_model()->view_at(i)->layer());
}
// Layers should be destroyed once the item animations complete.
for (int i = 0; i < kItemCount; ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
}
// Tests screen rotation during apps grid item drag where the drag gets
// canceled.
TEST_F(PopulatedAppListScreenRotationTest,
ScreenRotationDuringAppsGridItemDragCancelsOperation) {
// Set the display dimensions so rotation also changes the app list config.
UpdateDisplay("1200x600");
InitializeAppsGrid();
PopulateApps(apps_grid_test_api_->TilesPerPageInPagedGrid(0) +
apps_grid_test_api_->TilesPerPageInPagedGrid(1));
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(0);
// Start dragging the first item.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// While the drag is running, rotate screen.
RotateScreen();
EXPECT_FALSE(apps_grid_view_->IsDragging());
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
// The model state should not have been changed.
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ("Item 2", apps_grid_view_->GetItemViewAt(2)->item()->id());
}
// Tests screen rotation during a folder apps grid item reparent drag where the
// drag gets canceled.
TEST_F(PopulatedAppListScreenRotationTest,
ScreenRotationDuringFolderAppsGridItemDragCancelsOperation) {
InitializeAppsGrid();
PopulateApps(2);
AppListFolderItem* folder = CreateAndPopulateFolderWithApps(3);
PopulateApps(10);
// Tap the folder item to show it.
GestureTapOn(apps_grid_view_->GetItemViewAt(2));
ASSERT_TRUE(AppListIsInFolderView());
// Start dragging the first item in the active folder.
AppListItemView* const dragged_view =
folder_view()->items_grid_view()->GetItemViewAt(0);
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Drag the item within the folder bounds.
event_generator->MoveTouch(
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen().CenterPoint());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// While the drag is running, rotate screen.
RotateScreen();
EXPECT_FALSE(AppListIsInFolderView());
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
// The model state should not have been changed.
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ(folder->id(), apps_grid_view_->GetItemViewAt(2)->item()->id());
EXPECT_EQ("Item 5", apps_grid_view_->GetItemViewAt(3)->item()->id());
}
// Tests screen rotation during apps grid item drag where the drag gets
// canceled after a page change. Verifies the correct page is selected for the
// item that started the drag.
TEST_F(PopulatedAppListScreenRotationTest,
ScreenRotationDuringAppsGridItemWithPageChange) {
// Set the display dimensions so rotation also changes the app list config.
UpdateDisplay("1200x600");
InitializeAppsGrid();
PopulateApps(apps_grid_test_api_->TilesPerPageInPagedGrid(0) +
apps_grid_test_api_->TilesPerPageInPagedGrid(1));
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_EQ(2, apps_grid_view_->pagination_model()->total_pages());
// Start dragging the first item.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move the item close to apps grid edge, to flip to the next page.
event_generator->MoveTouch(
apps_grid_view_->GetBoundsInScreen().bottom_center() +
gfx::Vector2d(0, 5));
EXPECT_TRUE(apps_grid_view_->FirePageFlipTimerForTest());
apps_grid_view_->pagination_model()->FinishAnimation();
EXPECT_EQ(1, apps_grid_view_->pagination_model()->selected_page());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// While the drag is running, rotate screen.
RotateScreen();
EXPECT_FALSE(AppListIsInFolderView());
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
// Make sure that the correct page displays, with the selected app.
EXPECT_EQ(2, apps_grid_view_->pagination_model()->total_pages());
EXPECT_EQ(0, apps_grid_view_->pagination_model()->selected_page());
// The model state should not have been changed.
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ("Item 2", apps_grid_view_->GetItemViewAt(2)->item()->id());
}
// Tests screen rotation during apps grid item drag where the drag gets
// canceled after a page change. Verifies that the correct page is selected for
// them item that started the drag even if the item ends up in a different page.
TEST_F(PopulatedAppListScreenRotationTest,
ScreenRotationDuringAppsGridItemWithPageNumberChange) {
// Set the display dimensions so rotation also changes the app list config.
UpdateDisplay("1200x600");
// Initialize an apps grid with enough apps to have two pages on landscape
// mode but only one page on portrait mode.
InitializeAppsGrid();
PopulateApps(apps_grid_test_api_->TilesPerPageInPagedGrid(0) + 2);
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(0);
ASSERT_EQ(2, apps_grid_view_->pagination_model()->total_pages());
// Start dragging the first item.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move the item close to apps grid edge, to flip to the next page.
event_generator->MoveTouch(
apps_grid_view_->GetBoundsInScreen().bottom_center() +
gfx::Vector2d(0, 5));
EXPECT_TRUE(apps_grid_view_->FirePageFlipTimerForTest());
apps_grid_view_->pagination_model()->FinishAnimation();
EXPECT_EQ(1, apps_grid_view_->pagination_model()->selected_page());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// While the drag is running, rotate screen.
RotateScreen();
EXPECT_FALSE(AppListIsInFolderView());
EXPECT_FALSE(apps_grid_view_->IsDragging());
EXPECT_FALSE(folder_view()->items_grid_view()->IsDragging());
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
// Make sure that the correct page displays, with the selected app.
EXPECT_EQ(1, apps_grid_view_->pagination_model()->total_pages());
EXPECT_EQ(0, apps_grid_view_->pagination_model()->selected_page());
// The model state should not have been changed.
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ("Item 2", apps_grid_view_->GetItemViewAt(2)->item()->id());
}
// Tests that app list folder item reparenting drag to another folder.
TEST_P(AppListBubbleAndTabletDragTest, AppsGridItemReparentToFolderDrag) {
UpdateDisplay("1200x600");
test::AppListTestModel* model = GetAppListModel();
model->PopulateApps(2);
AppListFolderItem* folder = model->CreateAndPopulateFolderWithApps(3);
model->PopulateApps(10);
EnableTabletMode(tablet_mode_param());
EnsureLauncherShown();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
// Tap the folder item to show it.
AppListItemView* folder_item = apps_grid_view_->GetItemViewAt(2);
ASSERT_TRUE(folder_item);
GestureTapOn(folder_item);
ASSERT_TRUE(AppListIsInFolderView());
ui::test::EventGenerator* event_generator = GetEventGenerator();
// Start dragging the first item in the active folder.
AppListItemView* dragged_view =
folder_view()->items_grid_view()->GetItemViewAt(0);
ASSERT_TRUE(dragged_view);
AppListItem* dragged_item = dragged_view->item();
event_generator->MoveTouch(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressTouch();
ASSERT_TRUE(dragged_view->FireTouchDragTimerForTest());
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Drag the item outside the folder bounds.
event_generator->MoveTouch(
apps_grid_view_->GetItemViewAt(0)->GetBoundsInScreen().CenterPoint());
event_generator->MoveTouchBy(2, 2);
EXPECT_FALSE(AppListIsInFolderView());
}));
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move the pointer over the item 3, and drop the dragged item.
gfx::Point target =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen().CenterPoint();
event_generator->MoveTouch(target);
event_generator->ReleaseTouch();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/true);
// Verify the new item location within the apps grid.
EXPECT_EQ("Item 0", apps_grid_view_->GetItemViewAt(0)->item()->id());
EXPECT_EQ("Item 1", apps_grid_view_->GetItemViewAt(1)->item()->id());
EXPECT_EQ(folder->id(), apps_grid_view_->GetItemViewAt(2)->item()->id());
EXPECT_TRUE(apps_grid_view_->GetItemViewAt(3)->item()->is_folder());
EXPECT_EQ(dragged_item->folder_id(),
apps_grid_view_->GetItemViewAt(3)->item()->id());
// Newly created folder should open and have the name input focused.
EXPECT_TRUE(GetAppListTestHelper()->IsInFolderView());
EXPECT_EQ(dragged_item->folder_id(), folder_view()->folder_item()->id());
EXPECT_TRUE(folder_view()
->folder_header_view()
->GetFolderNameViewForTest()
->HasFocus());
}
// Tests that an item can be removed just after creating a folder that contains
// that item. See https://crbug.com/1083942
TEST_F(PopulatedAppListTest, RemoveFolderItemAfterFolderCreation) {
InitializeAppsGrid();
const int kItemCount = 6;
PopulateApps(kItemCount);
// Dragging the item with index 2.
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(2);
AppListItem* const dragged_item = dragged_view->item();
AppListItem* const merged_item = apps_grid_view_->GetItemViewAt(3)->item();
const gfx::Rect expected_folder_item_view_bounds =
apps_grid_view_->GetItemViewAt(2)->GetBoundsInScreen();
// Drag the item on top of the item with index 3.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressLeftButton();
dragged_view->FireMouseDragTimerForTest();
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move mouse to switch to cardified state -the cardified state starts only
// once the drag distance exceeds a drag threshold, so the pointer has to
// sufficiently move from the original position.
event_generator->MoveMouseBy(10, 10);
event_generator->MoveMouseTo(
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen().CenterPoint());
event_generator->ReleaseLeftButton();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/false);
EXPECT_FALSE(apps_grid_view_->IsDragging());
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(2);
EXPECT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(expected_folder_item_view_bounds,
folder_item_view->GetBoundsInScreen());
EXPECT_EQ(dragged_item->folder_id(), folder_item_view->item()->id());
// Verify that item layers have been destroyed after the drag operation ended.
apps_grid_test_api_->WaitForItemMoveAnimationDone();
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
// Verify that item views have no layers after the folder has been opened.
apps_grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_EQ(expected_folder_item_view_bounds,
folder_item_view->GetBoundsInScreen());
EXPECT_TRUE(AppListIsInFolderView());
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
// Verify that a pending layout, if any, does not cause a crash.
apps_grid_view_->InvalidateLayout();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
// Remove an item from the folder, and leave it as a single item folder.
GetAppListModel()->DeleteItem(merged_item->id());
EXPECT_TRUE(AppListIsInFolderView());
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
// Remove the original drag view item.
GetAppListModel()->DeleteItem(dragged_item->id());
apps_grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
EXPECT_FALSE(apps_grid_view_->GetItemViewAt(2)->item()->is_folder());
// Verify that a pending layout, if any, does not cause a crash.
apps_grid_view_->InvalidateLayout();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
}
TEST_F(PopulatedAppListTest, ReparentLastFolderItemAfterFolderCreation) {
InitializeAppsGrid();
const int kItemCount = 5;
PopulateApps(kItemCount);
// Dragging the item with index 4.
AppListItemView* const dragged_view = apps_grid_view_->GetItemViewAt(4);
AppListItem* const dragged_item = dragged_view->item();
AppListItem* const merged_item = apps_grid_view_->GetItemViewAt(3)->item();
const gfx::Rect expected_folder_item_view_bounds =
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen();
// Drag the item on top of the item with index 3.
ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(dragged_view->GetBoundsInScreen().CenterPoint());
event_generator->PressLeftButton();
dragged_view->FireMouseDragTimerForTest();
std::list<base::OnceClosure> tasks;
tasks.push_back(base::BindLambdaForTesting([&]() {
// Move mouse to switch to cardified state -the cardified state starts only
// once the drag distance exceeds a drag threshold, so the pointer has to
// sufficiently move from the original position.
event_generator->MoveMouseBy(10, 10);
event_generator->MoveMouseTo(
apps_grid_view_->GetItemViewAt(3)->GetBoundsInScreen().CenterPoint());
event_generator->ReleaseLeftButton();
}));
MaybeRunDragAndDropSequenceForAppList(&tasks, /*is_touch =*/false);
EXPECT_FALSE(apps_grid_view_->IsDragging());
AppListItem* folder_item = apps_grid_view_->GetItemViewAt(3)->item();
EXPECT_TRUE(folder_item->is_folder());
EXPECT_EQ(dragged_item->folder_id(), folder_item->id());
// Verify that item layers have been destroyed after the drag operation ended.
apps_grid_test_api_->WaitForItemMoveAnimationDone();
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
AppListItemView* const folder_item_view = apps_grid_view_->GetItemViewAt(3);
EXPECT_TRUE(folder_item_view->is_folder());
EXPECT_EQ(expected_folder_item_view_bounds,
folder_item_view->GetBoundsInScreen());
// Verify that item views have no layers after the folder has been opened.
apps_grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_TRUE(AppListIsInFolderView());
for (size_t i = 0; i < apps_grid_view_->view_model()->view_size(); ++i) {
views::View* item_view = apps_grid_view_->view_model()->view_at(i);
EXPECT_FALSE(item_view->layer()) << "at " << i;
}
// Verify that a pending layout, if any, does not cause a crash.
apps_grid_view_->InvalidateLayout();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
// Remove the original drag view item.
GetAppListModel()->DeleteItem(dragged_item->id());
// Reparent the remaining folder item to the root apps grid (as it's done by
// Chrome when cleaning up single-item folders).
GetAppListModel()->MoveItemToRootAt(merged_item, folder_item->position());
apps_grid_test_api_->WaitForItemMoveAnimationDone();
EXPECT_FALSE(AppListIsInFolderView());
EXPECT_FALSE(apps_grid_view_->GetItemViewAt(3)->item()->is_folder());
// Verify that a pending layout, if any, does not cause a crash.
apps_grid_view_->InvalidateLayout();
apps_grid_view_->GetWidget()->LayoutRootViewIfNecessary();
}
TEST_F(PopulatedAppListWithVKEnabledTest,
TappingAppsGridClosesVirtualKeyboard) {
InitializeAppsGrid();
PopulateApps(2);
gfx::Point between_apps = GetItemRectOnCurrentPageAt(0, 0).right_center();
views::View::ConvertPointToScreen(apps_grid_view_, &between_apps);
gfx::Point empty_space = GetItemRectOnCurrentPageAt(0, 2).CenterPoint();
views::View::ConvertPointToScreen(apps_grid_view_, &empty_space);
// Manually show the virtual keyboard.
auto* const keyboard_controller = keyboard::KeyboardUIController::Get();
keyboard_controller->ShowKeyboard(true /* locked */);
ASSERT_TRUE(keyboard::test::WaitUntilShown());
// Touch the apps_grid outside of any apps. Expect that the keyboard is
// closed.
GetEventGenerator()->GestureTapAt(empty_space);
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
// Reshow the VKeyboard
keyboard_controller->ShowKeyboard(true);
ASSERT_TRUE(keyboard::test::WaitUntilShown());
// Touch the apps_grid between two apps. Expect that the keyboard is closed.
GetEventGenerator()->GestureTapAt(between_apps);
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
}
// Tests that app list hides when focus moves to a normal window.
TEST_P(AppListPresenterTest, HideOnFocusOut) {
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
wm::ActivateWindow(window.get());
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
}
// Tests that app list remains visible when focus is moved to a different
// window in kShellWindowId_AppListContainer.
TEST_P(AppListPresenterTest, RemainVisibleWhenFocusingToApplistContainer) {
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
aura::Window* applist_container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer);
std::unique_ptr<aura::Window> window(
aura::test::CreateTestWindowWithId(0, applist_container));
wm::ActivateWindow(window.get());
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
}
// Tests opening the app list on a secondary display, then deleting the display.
TEST_P(AppListPresenterTest, NonPrimaryDisplay) {
// Set up a screen with two displays (horizontally adjacent).
UpdateDisplay("1024x768,1024x768");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(2u, root_windows.size());
ASSERT_EQ("1024,0 1024x768", root_windows[1]->GetBoundsInScreen().ToString());
GetAppListTestHelper()->ShowAndRunLoop(GetSecondaryDisplay().id());
GetAppListTestHelper()->CheckVisibility(true);
// Remove the secondary display. Shouldn't crash (http://crbug.com/368990).
UpdateDisplay("1024x768");
// Updating the displays should close the app list.
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
}
// Tests updating display should not close the app list.
TEST_P(AppListPresenterTest, UpdateDisplayNotCloseAppList) {
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
// Change display bounds.
UpdateDisplay("1024x768");
// Updating the display should not close the app list.
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
}
// Tests that the app list window's bounds and the search box bounds are updated
// when the display bounds change.
TEST_F(AppListPresenterTest, AppListBoundsChangeForDisplayChange) {
UpdateDisplay("1024x768");
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
const gfx::Rect app_list_bounds =
GetAppListView()->GetWidget()->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds = GetSearchBoxView()->GetBoundsInScreen();
UpdateDisplay("800x600");
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
const gfx::Rect app_list_bounds2 =
GetAppListView()->GetWidget()->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds2 = GetSearchBoxView()->GetBoundsInScreen();
EXPECT_GT(app_list_bounds.size().GetArea(),
app_list_bounds2.size().GetArea());
EXPECT_NE(search_box_bounds, search_box_bounds2);
EXPECT_EQ(400, search_box_bounds2.CenterPoint().x());
}
// Tests that the app list window's bounds and the search box bounds in the
// fullscreen state are updated when the display bounds change.
TEST_F(AppListPresenterTest, AppListBoundsChangeForDisplayChangeFullscreen) {
EnableTabletMode(true);
UpdateDisplay("1024x768");
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
SetAppListStateAndWait(AppListViewState::kFullscreenAllApps);
const gfx::Rect app_list_bounds =
GetAppListView()->GetWidget()->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds = GetSearchBoxView()->GetBoundsInScreen();
UpdateDisplay("800x600");
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
const gfx::Rect app_list_bounds2 =
GetAppListView()->GetWidget()->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds2 = GetSearchBoxView()->GetBoundsInScreen();
EXPECT_GT(app_list_bounds.size().GetArea(),
app_list_bounds2.size().GetArea());
EXPECT_NE(search_box_bounds, search_box_bounds2);
EXPECT_EQ(400, search_box_bounds2.CenterPoint().x());
}
// Tests that the app list window's bounds and the search box bounds in the
// fullscreen search state are updated when the display bounds change.
TEST_F(AppListPresenterTest,
AppListBoundsChangeForDisplayChangeFullscreenSearch) {
EnableTabletMode(true);
UpdateDisplay("1024x768");
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
SetAppListStateAndWait(AppListViewState::kFullscreenAllApps);
SetAppListStateAndWait(AppListViewState::kFullscreenSearch);
const gfx::Rect app_list_bounds =
GetAppListView()->GetWidget()->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds = GetSearchBoxView()->GetBoundsInScreen();
UpdateDisplay("800x600");
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
const gfx::Rect app_list_bounds2 =
GetAppListView()->GetWidget()->GetWindowBoundsInScreen();
const gfx::Rect search_box_bounds2 = GetSearchBoxView()->GetBoundsInScreen();
EXPECT_GT(app_list_bounds.size().GetArea(),
app_list_bounds2.size().GetArea());
EXPECT_NE(search_box_bounds, search_box_bounds2);
EXPECT_EQ(400, search_box_bounds2.CenterPoint().x());
}
// Tests that the app list initializes in fullscreen with tablet mode active
// and that the state transitions via text input act properly.
TEST_P(AppListPresenterTest, TabletModeTextStateTransitions) {
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Enter text in the searchbox, the app list should transition to fullscreen
// search.
PressAndReleaseKey(ui::KeyboardCode::VKEY_0);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
// Pressing the escape key should transition the app list to the fullscreen
// all apps state.
PressAndReleaseKey(ui::KeyboardCode::VKEY_ESCAPE);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
}
// Tests that the app list closes when tablet mode deactivates.
TEST_P(AppListPresenterTest, AppListClosesWhenLeavingTabletMode) {
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EnableTabletMode(false);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Enter text in the searchbox, the app list should transition to fullscreen
// search.
PressAndReleaseKey(ui::KeyboardCode::VKEY_0);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
EnableTabletMode(false);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
}
// Tests the shelf background type is as expected when a window is created after
// going to tablet mode.
TEST_F(AppListPresenterTest, ShelfBackgroundWithHomeLauncher) {
// Enter tablet mode to display the home launcher.
EnableTabletMode(true);
ShelfLayoutManager* shelf_layout_manager =
Shelf::ForWindow(Shell::GetRootWindowForDisplayId(GetPrimaryDisplayId()))
->shelf_layout_manager();
EXPECT_EQ(ShelfBackgroundType::kHomeLauncher,
shelf_layout_manager->shelf_background_type());
// Add a window. It should be in-app because it is in tablet mode.
auto window = CreateTestWindow();
wm::ActivateWindow(window.get());
EXPECT_EQ(ShelfBackgroundType::kInApp,
shelf_layout_manager->shelf_background_type());
}
// Tests that the bottom shelf is auto hidden when a window is fullscreened in
// tablet mode (home launcher is shown behind).
TEST_F(AppListPresenterTest, ShelfAutoHiddenWhenFullscreen) {
EnableTabletMode(true);
Shelf* shelf =
Shelf::ForWindow(Shell::GetRootWindowForDisplayId(GetPrimaryDisplayId()));
EXPECT_EQ(ShelfVisibilityState::SHELF_VISIBLE, shelf->GetVisibilityState());
// Create and fullscreen a window. The shelf should be auto hidden.
auto window = CreateTestWindow();
window->SetProperty(aura::client::kShowStateKey,
ui::mojom::WindowShowState::kFullscreen);
EXPECT_EQ(ShelfVisibilityState::SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfAutoHideState::SHELF_AUTO_HIDE_HIDDEN,
shelf->GetAutoHideState());
}
// Tests that a keypress activates the searchbox and that clearing the
// searchbox, the searchbox remains active. Does not apply to bubble launcher,
// where the search box is always active.
TEST_F(AppListPresenterTest, KeyPressEnablesSearchBox) {
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
SearchBoxView* search_box_view = GetAppListView()->search_box_view();
EXPECT_FALSE(search_box_view->is_search_box_active());
// Press any key, the search box should be active.
PressAndReleaseKey(ui::VKEY_0);
EXPECT_TRUE(search_box_view->is_search_box_active());
// Delete the text, the search box should be inactive.
search_box_view->ClearSearch();
EXPECT_TRUE(search_box_view->is_search_box_active());
}
// Tests that search box gets deactivated if the active search model gets
// switched. Does not apply to bubble launcher, where the search box is
// always active.
TEST_P(AppListPresenterTest, SearchBoxDeactivatedOnModelChange) {
EnableTabletMode(true);
const bool test_mouse_event = TestMouseEventParam();
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
SearchBoxView* search_box_view = GetAppListView()->search_box_view();
// Tap/Click the search box, it should activate.
ui::test::EventGenerator* generator = GetEventGenerator();
if (test_mouse_event) {
generator->MoveMouseTo(GetPointInsideSearchbox());
generator->PressLeftButton();
generator->ReleaseLeftButton();
} else {
generator->GestureTapAt(GetPointInsideSearchbox());
}
EXPECT_TRUE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
// Switch the active app list and search model, and verify the search box is
// deactivated.
auto model_override = std::make_unique<test::AppListTestModel>();
auto search_model_override = std::make_unique<SearchModel>();
auto quick_app_access_model_override =
std::make_unique<QuickAppAccessModel>();
Shell::Get()->app_list_controller()->SetActiveModel(
/*profile_id=*/1, model_override.get(), search_model_override.get(),
quick_app_access_model_override.get());
EXPECT_FALSE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
Shell::Get()->app_list_controller()->ClearActiveModel();
}
// Tests that search UI gets closed if search model changes.
TEST_F(AppListPresenterTest, SearchClearedOnModelChange) {
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
SearchBoxView* search_box_view = GetAppListView()->search_box_view();
// Press a key to start search, and activate the search box.
PressAndReleaseKey(ui::VKEY_A);
SearchModel* search_model = GetSearchModel();
auto test_result = std::make_unique<TestSearchResult>();
test_result->set_result_id("test");
// Give this item a name so that the accessibility paint checks pass.
// (Focusable items should have accessible names.)
test_result->SetAccessibleName(u"test");
test_result->set_display_type(SearchResultDisplayType::kList);
search_model->results()->Add(std::move(test_result));
auto test_list_result = std::make_unique<TestSearchResult>();
test_list_result->set_result_id("test_list");
// Give this item a name so that the accessibility paint checks pass.
// (Focusable items should have accessible names.)
test_list_result->SetAccessibleName(u"test_list");
test_list_result->set_best_match(true);
test_list_result->set_display_type(SearchResultDisplayType::kList);
search_model->results()->Add(std::move(test_list_result));
// The results are updated asynchronously. Wait until the update is finished.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
SearchResultContainerView* item_list_container =
GetDefaultSearchResultListView();
ASSERT_EQ(1u, item_list_container->num_results());
EXPECT_EQ("test_list",
item_list_container->GetResultViewAt(0)->result()->id());
// Switch the active app list and search model, and verify the search UI gets
// cleared.
auto model_override = std::make_unique<test::AppListTestModel>();
auto search_model_override = std::make_unique<SearchModel>();
auto quick_app_access_model_override =
std::make_unique<QuickAppAccessModel>();
Shell::Get()->app_list_controller()->SetActiveModel(
/*profile_id=*/1, model_override.get(), search_model_override.get(),
quick_app_access_model_override.get());
EXPECT_FALSE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Verify that the search UI shows results from the current active search
// model.
PressAndReleaseKey(ui::VKEY_A);
auto test_list_result_override = std::make_unique<TestSearchResult>();
test_list_result_override->set_result_id("test_list_override");
// Give this item a name so that the accessibility paint checks pass.
// (Focusable items should have accessible names.)
test_list_result_override->SetAccessibleName(u"test_list_override");
test_list_result_override->set_display_type(SearchResultDisplayType::kList);
test_list_result_override->set_best_match(true);
search_model_override->results()->Add(std::move(test_list_result_override));
// The results are updated asynchronously. Wait until the update is finished.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
item_list_container = GetDefaultSearchResultListView();
ASSERT_EQ(1u, item_list_container->num_results());
EXPECT_EQ("test_list_override",
item_list_container->GetResultViewAt(0)->result()->id());
Shell::Get()->app_list_controller()->ClearActiveModel();
EXPECT_FALSE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
}
// Tests that the result selection will reset after closing the search box by
// clicking the close button.
TEST_F(AppListTabletTest,
ClosingSearchBoxByClickingCloseButtonResetsResultSelection) {
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
SearchBoxView* search_box_view = GetSearchBoxView();
ResultSelectionController* result_selection_controller =
GetResultSelectionController();
// Add search results to the search model.
// Click on the search box to activate search.
GetEventGenerator()->GestureTapAt(SearchBoxCenterPoint());
EXPECT_TRUE(search_box_view->is_search_box_active());
ASSERT_FALSE(result_selection_controller->selected_result());
// Start search.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->PressKey(ui::VKEY_A, 0);
// Add some search results to the search model.
SearchModel* search_model = GetSearchModel();
search_model->results()->Add(
CreateOmniboxSuggestionResult("Suggestion1", /*support_removal=*/true));
search_model->results()->Add(
CreateOmniboxSuggestionResult("Suggestion2", /*support_removal=*/true));
EXPECT_TRUE(AppListSearchResultPageVisible());
// The results are updated asynchronously. Wait until the update is finished.
base::RunLoop().RunUntilIdle();
// Click the search box, the result selection should be the first one in
// default.
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
EXPECT_TRUE(search_box_view->is_search_box_active());
ASSERT_TRUE(result_selection_controller->selected_result());
EXPECT_TRUE(result_selection_controller->selected_result()->selected());
EXPECT_TRUE(result_selection_controller->selected_location_details()
->is_first_result());
// Move the selection to the second result.
PressAndReleaseKey(ui::KeyboardCode::VKEY_DOWN);
ASSERT_TRUE(result_selection_controller->selected_result());
EXPECT_TRUE(result_selection_controller->selected_result()->selected());
EXPECT_FALSE(result_selection_controller->selected_location_details()
->is_first_result());
// Use the close button in search_box_view to close the search box.
const views::View* close_button = GetSearchBoxView()->close_button();
GestureTapOn(close_button);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(search_box_view->is_search_box_active());
// Delete all search result after closing the search box.
search_model->DeleteAllResults();
// Tap the search box again, the result selection should be reset to the first
// one.
GestureTapOn(search_box_view);
// Verify that there is no existing result.
EXPECT_TRUE(search_box_view->is_search_box_active());
EXPECT_FALSE(result_selection_controller->selected_result());
}
// Regression test for crash due to use-after-free. https://crbug.com/1163332
TEST_P(AppListPresenterTest, ShouldNotCrashOnItemClickAfterMonitorDisconnect) {
// Set up two displays.
UpdateDisplay("1024x768,1200x900");
test::AppListTestModel* model = GetAppListModel();
AppListItem* item0 = model->AddItem(new AppListItem("item 0"));
AppListItem* item1 = model->AddItem(new AppListItem("item 1"));
// Give each item a name so that the accessibility paint checks pass.
// (Focusable items should have accessible names.)
model->SetItemName(item0, item0->id());
model->SetItemName(item1, item1->id());
// Open and close app list on secondary display.
AppListTestHelper* helper = GetAppListTestHelper();
helper->ShowAndRunLoop(GetSecondaryDisplay().id());
helper->DismissAndRunLoop();
// Open and close app list on primary display.
helper->ShowAndRunLoop(GetPrimaryDisplayId());
helper->DismissAndRunLoop();
// Disconnect secondary display.
UpdateDisplay("1024x768");
// Open app list to show app items.
EnsureLauncherWithVisibleAppsGrid();
// Click on an item.
AppListItemView* item_view = apps_grid_view()->GetItemViewAt(0);
EXPECT_EQ(item_view->GetViewAccessibility().GetCachedName(),
base::UTF8ToUTF16(item0->id()));
LeftClickOn(item_view);
// No crash. No use-after-free detected by ASAN.
}
// Tests that no crash occurs after an attempt to show app list in an invalid
// display.
TEST_P(AppListPresenterTest, ShowInInvalidDisplay) {
GetAppListTestHelper()->ShowAndRunLoop(display::kInvalidDisplayId);
GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
}
TEST_F(AppListPresenterTest, TapAppListThenSystemTrayShowsAutoHiddenShelf) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Create a normal unmaximized window; the shelf should be hidden.
std::unique_ptr<views::Widget> window =
CreateTestWidget(views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
window->SetBounds(gfx::Rect(0, 0, 100, 100));
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap the system tray should open system tray bubble and keep shelf visible.
GestureTapOn(GetPrimaryUnifiedSystemTray());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap to dismiss the app list and the auto-hide shelf.
GetEventGenerator()->GestureTapAt(gfx::Point(0, 0));
EXPECT_FALSE(GetPrimaryUnifiedSystemTray()->IsBubbleShown());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
GetAppListTestHelper()->CheckVisibility(false);
}
TEST_F(AppListPresenterTest, TapAppListThenShelfHidesAutoHiddenShelf) {
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Create a normal unmaximized window; the shelf should be hidden.
std::unique_ptr<views::Widget> window =
CreateTestWidget(views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
window->SetBounds(gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Show the AppList.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Make sure the shelf has at least one item.
ShelfItem item =
ShelfTestUtil::AddAppShortcut(base::NumberToString(1), TYPE_PINNED_APP);
// Wait for shelf view's bounds animation to end. Otherwise the scrollable
// shelf's bounds are not updated yet.
ShelfView* const shelf_view = shelf->GetShelfViewForTesting();
ShelfViewTestAPI shelf_view_test_api(shelf_view);
shelf_view_test_api.RunMessageLoopUntilAnimationsDone();
// Test that tapping the auto-hidden shelf dismisses the app list when tapping
// part of the shelf that does not contain the apps.
GetEventGenerator()->GestureTapAt(
shelf_view->GetBoundsInScreen().left_center() + gfx::Vector2d(10, 0));
base::RunLoop().RunUntilIdle(); // Wait for autohide to be recomputed.
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Show the AppList again.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// App list should remain visible when tapping on a shelf app button.
ASSERT_TRUE(shelf_view_test_api.GetButton(0));
GestureTapOn(shelf_view_test_api.GetButton(0));
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
TEST_F(AppListPresenterTest, ClickingShelfArrowDoesNotHideAppList) {
SetShelfAnimationDuration(base::Milliseconds(1));
// Add enough shelf items for the shelf to enter overflow.
Shelf* const shelf = GetPrimaryShelf();
ScrollableShelfView* const scrollable_shelf_view =
shelf->hotseat_widget()->scrollable_shelf_view();
int index = 0;
while (scrollable_shelf_view->layout_strategy_for_test() ==
ScrollableShelfView::kNotShowArrowButtons) {
ShelfItem item = ShelfTestUtil::AddAppShortcut(
base::NumberToString(index++), TYPE_PINNED_APP);
}
WaitForShelfAnimation();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click right scrollable shelf arrow - verify the the app list remains
// visible.
const views::View* right_arrow = scrollable_shelf_view->right_arrow();
ASSERT_TRUE(right_arrow->GetVisible());
LeftClickOn(right_arrow);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click left button - verify the app list stays visible.
const views::View* left_arrow = scrollable_shelf_view->left_arrow();
ASSERT_TRUE(left_arrow->GetVisible());
LeftClickOn(left_arrow);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Click right of the right arrow - verify the app list gets dismissed.
ASSERT_TRUE(right_arrow->GetVisible());
GetEventGenerator()->MoveMouseTo(
right_arrow->GetBoundsInScreen().right_center() + gfx::Vector2d(10, 0));
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
// Tests that the touch selection menu created when tapping an open folder's
// folder name view be interacted with.
TEST_F(PopulatedAppListTest, TouchSelectionMenu) {
InitializeAppsGrid();
AppListFolderItem* folder_item = CreateAndPopulateFolderWithApps(4);
EXPECT_TRUE(folder_item->is_folder());
EXPECT_EQ(1u, GetAppListModel()->top_level_item_list()->item_count());
EXPECT_EQ(AppListFolderItem::kItemType, GetAppListTestHelper()
->model()
->top_level_item_list()
->item_at(0)
->GetItemType());
// Open the folder.
ASSERT_FALSE(AppListIsInFolderView());
GestureTapOn(apps_grid_view_->GetItemViewAt(0));
ASSERT_TRUE(AppListIsInFolderView());
// Check that the touch selection menu runner is not running.
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance());
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Set the folder name and simulate tap on the folder name view.
views::View* folder_name_view =
folder_view()->folder_header_view()->GetFolderNameViewForTest();
UpdateFolderName("folder_name");
GestureTapOn(folder_name_view);
// Fire the timer to show the textfield quick menu.
views::TextfieldTestApi textfield_test_api(
folder_view()->folder_header_view()->GetFolderNameViewForTest());
static_cast<views::TouchSelectionControllerImpl*>(
textfield_test_api.touch_selection_controller())
->ShowQuickMenuImmediatelyForTesting();
EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Tap the leftmost button in the touch_menu_container and check that the
// folder name has been cut.
views::TouchSelectionMenuRunnerViews::TestApi test_api(
static_cast<views::TouchSelectionMenuRunnerViews*>(
ui::TouchSelectionMenuRunner::GetInstance()));
views::LabelButton* button = test_api.GetFirstButton();
ASSERT_TRUE(button);
GestureTapOn(button);
EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
// Refresh the folder item name.
RefreshFolderName();
// Check folder_name_view's name.
ASSERT_EQ("", GetFolderName());
}
// Test a variety of behaviors for home launcher (app list in tablet mode).
// Parameterized by Mouse or touch parameter.
class AppListPresenterHomeLauncherTest
: public AshTestBase,
public testing::WithParamInterface<bool> {
public:
AppListPresenterHomeLauncherTest() = default;
AppListPresenterHomeLauncherTest(const AppListPresenterHomeLauncherTest&) =
delete;
AppListPresenterHomeLauncherTest& operator=(
const AppListPresenterHomeLauncherTest&) = delete;
~AppListPresenterHomeLauncherTest() override = default;
// testing::Test:
void SetUp() override {
AshTestBase::SetUp();
GetAppListTestHelper()->WaitUntilIdle();
wallpaper_test_api_ = std::make_unique<WallpaperControllerTestApi>(
Shell::Get()->wallpaper_controller());
}
void TearDown() override {
wallpaper_test_api_.reset();
AshTestBase::TearDown();
}
bool TestMouseEventParam() const { return GetParam(); }
void TapHomeButton(int64_t display_id) {
HomeButton* const home_button =
Shell::GetRootWindowControllerWithDisplayId(display_id)
->shelf()
->navigation_widget()
->GetHomeButton();
gfx::Point tap_point = home_button->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->GestureTapDownAndUp(tap_point);
GetAppListTestHelper()->WaitUntilIdle();
}
// Ensures transition to home screen in tablet mode (where home button is not
// always shown).
void GoHome() {
const int64_t primary_display_id = GetPrimaryDisplay().id();
// If home button is not expected to be shown, use
// AppListControllerImpl::GoHome() directly, otherwise tap on the primary
// screen home button.
if (!Shell::Get()->shelf_config()->shelf_controls_shown()) {
Shell::Get()->app_list_controller()->GoHome(primary_display_id);
return;
}
TapHomeButton(primary_display_id);
}
SplitViewController* split_view_controller() {
return SplitViewController::Get(Shell::GetPrimaryRootWindow());
}
AppListView* GetAppListView() {
return GetAppListTestHelper()->GetAppListView();
}
gfx::Point GetPointOutsideSearchbox() {
// Ensures that the point satisfies the following conditions:
// (1) The point is within AppListView.
// (2) The point is outside of the search box.
// (3) The touch event on the point should not be consumed by the handler
// for back gesture.
return GetSearchBoxViewFromHelper(GetAppListTestHelper())
->GetBoundsInScreen()
.bottom_right();
}
gfx::Point GetPointInsideSearchbox() {
return GetSearchBoxViewFromHelper(GetAppListTestHelper())
->GetBoundsInScreen()
.CenterPoint();
}
void ShowAppList() {
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
}
bool IsAppListVisible() {
auto* app_list_controller = Shell::Get()->app_list_controller();
return app_list_controller->IsVisible() &&
app_list_controller->GetTargetVisibility(std::nullopt);
}
protected:
std::unique_ptr<WallpaperControllerTestApi> wallpaper_test_api_;
};
INSTANTIATE_TEST_SUITE_P(MouseTouchEvent,
AppListPresenterHomeLauncherTest,
testing::Bool());
// Tests that the app list is shown automatically when the tablet mode is on.
// The app list is dismissed when the tablet mode is off.
TEST_F(AppListPresenterHomeLauncherTest, ShowAppListForTabletMode) {
GetAppListTestHelper()->CheckVisibility(false);
// Turns on tablet mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
// Turns off tablet mode.
EnableTabletMode(false);
GetAppListTestHelper()->CheckVisibility(false);
}
TEST_F(AppListPresenterHomeLauncherTest,
RunZeroStateSearchWhenShownOnTabletModeTransition) {
EXPECT_EQ(0, GetTestAppListClient()->start_zero_state_search_count());
GetAppListTestHelper()->CheckVisibility(false);
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(1, GetTestAppListClient()->start_zero_state_search_count());
}
TEST_F(AppListPresenterHomeLauncherTest,
RunZeroStateSearchWhenShownAfterMinimizingWindows) {
EXPECT_EQ(0, GetTestAppListClient()->start_zero_state_search_count());
GetAppListTestHelper()->CheckVisibility(false);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(0, GetTestAppListClient()->start_zero_state_search_count());
window->SetProperty(aura::client::kShowStateKey,
ui::mojom::WindowShowState::kMinimized);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(1, GetTestAppListClient()->start_zero_state_search_count());
}
// Tests that the app list window's parent is changed after entering tablet
// mode.
TEST_F(AppListPresenterHomeLauncherTest, ParentWindowContainer) {
// Show app list in non-tablet mode. The window container should be
// kShellWindowId_AppListContainer.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
aura::Window* window = Shell::Get()->app_list_controller()->GetWindow();
aura::Window* root_window = window->GetRootWindow();
EXPECT_TRUE(root_window->GetChildById(kShellWindowId_AppListContainer)
->Contains(window));
// Turn on tablet mode. The window container should be
// kShellWindowId_HomeScreenContainer.
EnableTabletMode(true);
aura::Window* window2 = Shell::Get()->app_list_controller()->GetWindow();
EXPECT_TRUE(root_window->GetChildById(kShellWindowId_HomeScreenContainer)
->Contains(window2));
}
// Tests that tapping or clicking on background cannot dismiss the app list.
TEST_F(AppListPresenterHomeLauncherTest, TapOrClickToDismiss) {
// Show app list in non-tablet mode. Click outside search box.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
ui::test::EventGenerator* generator = GetEventGenerator();
const gfx::Point origin;
generator->MoveMouseTo(origin);
generator->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(IsAppListVisible());
// Show app list in non-tablet mode. Tap outside search box.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
generator->GestureTapDownAndUp(origin);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(IsAppListVisible());
// Show app list in tablet mode. Click outside search box.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
generator->MoveMouseTo(origin);
generator->PressLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_TRUE(IsAppListVisible());
// Tap outside search box.
generator->GestureTapDownAndUp(origin);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_TRUE(IsAppListVisible());
}
TEST_F(AppListPresenterHomeLauncherTest,
EscapeKeyInNonTabletModeClosesLauncher) {
ShowAppList();
EXPECT_TRUE(IsAppListVisible());
PressAndReleaseKey(ui::KeyboardCode::VKEY_ESCAPE);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(IsAppListVisible());
}
TEST_F(AppListPresenterHomeLauncherTest, BackKeyInNonTabletModeClosesLauncher) {
ShowAppList();
EXPECT_TRUE(IsAppListVisible());
PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_BACK);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(IsAppListVisible());
}
TEST_F(AppListPresenterHomeLauncherTest,
SearchKeyInNonTabletModeClosesLauncher) {
ShowAppList();
EXPECT_TRUE(IsAppListVisible());
PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(IsAppListVisible());
}
TEST_F(AppListPresenterHomeLauncherTest,
EscapeKeyInTabletModeDoesNotCloseLauncher) {
EnableTabletMode(true);
EXPECT_TRUE(IsAppListVisible());
PressAndReleaseKey(ui::KeyboardCode::VKEY_ESCAPE);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsAppListVisible());
}
TEST_F(AppListPresenterHomeLauncherTest,
BackKeyInTabletModeDoesNotCloseLauncher) {
EnableTabletMode(true);
EXPECT_TRUE(IsAppListVisible());
PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_BACK);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsAppListVisible());
}
TEST_F(AppListPresenterHomeLauncherTest,
SearchKeyInTabletModeDoesNotCloseLauncher) {
EnableTabletMode(true);
EXPECT_TRUE(IsAppListVisible());
PressAndReleaseKey(ui::KeyboardCode::VKEY_BROWSER_SEARCH);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsAppListVisible());
}
// Tests that moving focus outside app list window can dismiss it.
TEST_F(AppListPresenterHomeLauncherTest, FocusOutToDismiss) {
// Show app list in non-tablet mode. Move focus to another window.
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckVisibility(true);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
wm::ActivateWindow(window.get());
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Go to tablet mode with a focused window, the AppList should not be visible.
EnableTabletMode(true);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Refocusing the already focused window should change nothing.
wm::ActivateWindow(window.get());
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Minimizing the focused window with no remaining windows should result in a
// shown applist.
window->SetProperty(aura::client::kShowStateKey,
ui::mojom::WindowShowState::kMinimized);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
}
// Tests that tapping home button while home screen is visible and showing
// search results moves the home screen to apps container page.
TEST_F(AppListPresenterHomeLauncherTest, HomeButtonDismissesSearchResults) {
// Show app list in tablet mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Enable accessibility feature that forces home button to be shown even with
// kHideShelfControlsInTabletMode enabled.
// TODO(crbug.com/40673209) Use the a11y feature specific to showing
// navigation buttons in tablet mode once it lands.
Shell::Get()->accessibility_controller()->autoclick().SetEnabled(true);
// Enter text in the searchbox, the app list should transition to fullscreen
// search.
PressAndReleaseKey(ui::KeyboardCode::VKEY_0);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
// Tap home button - verify that home goes back to showing the apps page.
TapHomeButton(GetPrimaryDisplay().id());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
}
// Tests the app list opacity in overview mode.
TEST_F(AppListPresenterHomeLauncherTest, OpacityInOverviewMode) {
// Show app list in tablet mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
// Enable overview mode.
OverviewController* overview_controller = OverviewController::Get();
EnterOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
ui::Layer* layer = GetAppListView()->GetWidget()->GetNativeWindow()->layer();
EXPECT_EQ(0.0f, layer->opacity());
// Disable overview mode.
ExitOverview();
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_EQ(1.0f, layer->opacity());
}
TEST_F(AppListPresenterHomeLauncherTest, AppListHiddenDuringWallpaperPreview) {
EnableTabletMode(true);
wallpaper_test_api_->StartWallpaperPreview();
GetAppListTestHelper()->CheckVisibility(false);
}
TEST_F(AppListPresenterHomeLauncherTest,
AppListShownAfterWallpaperPreviewConfirmed) {
EnableTabletMode(true);
wallpaper_test_api_->StartWallpaperPreview();
wallpaper_test_api_->EndWallpaperPreview(/*confirm_preview_wallpaper=*/true);
GetAppListTestHelper()->CheckVisibility(true);
}
TEST_F(AppListPresenterHomeLauncherTest,
AppListShownAfterWallpaperPreviewCanceled) {
EnableTabletMode(true);
wallpaper_test_api_->StartWallpaperPreview();
wallpaper_test_api_->EndWallpaperPreview(/*confirm_preview_wallpaper=*/false);
GetAppListTestHelper()->CheckVisibility(true);
}
TEST_F(AppListPresenterHomeLauncherTest,
AppListShownAfterWallpaperPreviewAndExitOverviewMode) {
EnableTabletMode(true);
wallpaper_test_api_->StartWallpaperPreview();
EnterOverview();
EXPECT_FALSE(IsAppListVisible());
// Disable overview mode.
ExitOverview();
EXPECT_TRUE(IsAppListVisible());
}
// Tests that going home will minimize all windows.
TEST_F(AppListPresenterHomeLauncherTest, GoingHomeMinimizesAllWindows) {
// Show app list in tablet mode. Maximize all windows.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)),
window2(CreateTestWindowInShellWithId(1)),
window3(CreateTestWindowInShellWithId(2));
WindowState* state1 = WindowState::Get(window1.get());
WindowState* state2 = WindowState::Get(window2.get());
WindowState* state3 = WindowState::Get(window3.get());
state1->Maximize();
state2->Maximize();
state3->Maximize();
EXPECT_TRUE(state1->IsMaximized());
EXPECT_TRUE(state2->IsMaximized());
EXPECT_TRUE(state3->IsMaximized());
// The windows need to be activated for the mru window tracker.
wm::ActivateWindow(window1.get());
wm::ActivateWindow(window2.get());
wm::ActivateWindow(window3.get());
auto ordering =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList(kActiveDesk);
GoHome();
EXPECT_TRUE(state1->IsMinimized());
EXPECT_TRUE(state2->IsMinimized());
EXPECT_TRUE(state3->IsMinimized());
GetAppListTestHelper()->CheckVisibility(true);
// Tests that the window ordering remains the same as before we minimize.
auto new_order =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList(kActiveDesk);
EXPECT_TRUE(std::ranges::equal(ordering, new_order));
}
// Tests that going home will end split view mode.
TEST_F(AppListPresenterHomeLauncherTest, GoingHomeEndsSplitViewMode) {
// Show app list in tablet mode. Enter split view mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
split_view_controller()->SnapWindow(window.get(), SnapPosition::kPrimary);
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
GoHome();
EXPECT_FALSE(split_view_controller()->InSplitViewMode());
GetAppListTestHelper()->CheckVisibility(true);
}
// Tests that going home will end overview mode.
TEST_F(AppListPresenterHomeLauncherTest, GoingHomeEndOverviewMode) {
// Show app list in tablet mode. Enter overview mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
OverviewController* overview_controller = OverviewController::Get();
EnterOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
GoHome();
EXPECT_FALSE(overview_controller->InOverviewSession());
GetAppListTestHelper()->CheckVisibility(true);
}
// Tests that going home will end overview and split view mode if both are
// active (e.g. one side of the split view contains overview).
TEST_F(AppListPresenterHomeLauncherTest,
GoingHomeEndsSplitViewModeWithOverview) {
// Show app list in tablet mode. Enter split view mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
std::unique_ptr<aura::Window> dummy_window(CreateTestWindowInShellWithId(1));
OverviewController* overview_controller = OverviewController::Get();
EnterOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
split_view_controller()->SnapWindow(window.get(), SnapPosition::kPrimary);
EXPECT_TRUE(split_view_controller()->InSplitViewMode());
EXPECT_TRUE(overview_controller->InOverviewSession());
GoHome();
EXPECT_FALSE(split_view_controller()->InSplitViewMode());
EXPECT_FALSE(overview_controller->InOverviewSession());
GetAppListTestHelper()->CheckVisibility(true);
}
// Tests that the context menu is triggered in the same way as if we are on
// the wallpaper.
TEST_F(AppListPresenterHomeLauncherTest, WallpaperContextMenu) {
// Show app list in tablet mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
// Long press on the app list to open the context menu.
// TODO(ginko) look into a way to populate an apps grid, then get a point
// between these apps so that clicks/taps between apps can be tested
const gfx::Point onscreen_point(GetPointOutsideSearchbox());
ui::test::EventGenerator* generator = GetEventGenerator();
ui::GestureEvent long_press(
onscreen_point.x(), onscreen_point.y(), 0, base::TimeTicks(),
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
generator->Dispatch(&long_press);
GetAppListTestHelper()->WaitUntilIdle();
const aura::Window* root = window_util::GetRootWindowAt(onscreen_point);
const RootWindowController* root_window_controller =
RootWindowController::ForWindow(root);
EXPECT_TRUE(root_window_controller->IsContextMenuShownForTest());
// Tap down to close the context menu.
ui::GestureEvent tap_down(
onscreen_point.x(), onscreen_point.y(), 0, base::TimeTicks(),
ui::GestureEventDetails(ui::EventType::kGestureTapDown));
generator->Dispatch(&tap_down);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(root_window_controller->IsContextMenuShownForTest());
// Right click to open the context menu.
generator->MoveMouseTo(onscreen_point);
generator->ClickRightButton();
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_TRUE(root_window_controller->IsContextMenuShownForTest());
// Left click to close the context menu.
generator->MoveMouseTo(onscreen_point);
generator->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(root_window_controller->IsContextMenuShownForTest());
}
// Test backdrop exists for active non-fullscreen window in tablet mode.
TEST_F(AppListPresenterHomeLauncherTest, BackdropTest) {
WorkspaceControllerTestApi test_helper(ShellTestApi().workspace_controller());
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_FALSE(test_helper.GetBackdropWindow());
std::unique_ptr<aura::Window> non_fullscreen_window(
CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
non_fullscreen_window->Show();
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_TRUE(test_helper.GetBackdropWindow());
}
// Tests that app list is not active when switching to tablet mode if an active
// window exists.
TEST_F(AppListPresenterHomeLauncherTest,
NotActivateAppListWindowWhenActiveWindowExists) {
// No window is active.
EXPECT_EQ(nullptr, window_util::GetActiveWindow());
// Show app list in tablet mode. It should become active.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_EQ(GetAppListView()->GetWidget()->GetNativeWindow(),
window_util::GetActiveWindow());
// End tablet mode.
EnableTabletMode(false);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(nullptr, window_util::GetActiveWindow());
// Activate a window.
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
WindowState::Get(window.get())->Activate();
EXPECT_EQ(window.get(), window_util::GetActiveWindow());
// Show app list in tablet mode. It should not be active.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(false);
EXPECT_EQ(window.get(), window_util::GetActiveWindow());
}
// Tests that involve the virtual keyboard.
class AppListPresenterVirtualKeyboardTest : public AppListPresenterTest {
public:
AppListPresenterVirtualKeyboardTest() = default;
~AppListPresenterVirtualKeyboardTest() override = default;
// AppListPresenterTest:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AppListPresenterTest::SetUp();
}
// Performs mouse click or tap gesture on the provided point, depending on
// whether the test is parameterized to use mouse clicks or tap gestures.
void ClickOrTap(const gfx::Point& point) {
if (TestMouseEventParam())
ClickMouseAt(point);
else
GetEventGenerator()->GestureTapAt(point);
}
};
// Instantiate the values in the parameterized tests. Used to toggle mouse and
// touch events.
INSTANTIATE_TEST_SUITE_P(Mouse,
AppListPresenterVirtualKeyboardTest,
testing::Bool());
// Tests that tapping or clicking the body of the applist with an active virtual
// keyboard when there exists text in the searchbox results in the virtual
// keyboard closing with no side effects.
TEST_P(AppListPresenterVirtualKeyboardTest,
TapAppListWithVirtualKeyboardDismissesVirtualKeyboardWithSearchText) {
EnableTabletMode(true);
// Tap to activate the searchbox.
ClickOrTap(GetPointInsideSearchbox());
// Enter some text in the searchbox, the applist should transition to
// fullscreen search.
PressAndReleaseKey(ui::KeyboardCode::VKEY_0);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
// Manually show the virtual keyboard.
auto* const keyboard_controller = keyboard::KeyboardUIController::Get();
keyboard_controller->ShowKeyboard(true);
ASSERT_TRUE(keyboard::test::WaitUntilShown());
// Tap or click outside the searchbox, the virtual keyboard should hide.
ClickOrTap(GetPointOutsideSearchbox());
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
// The searchbox should still be active and the AppListView should still be in
// FULLSCREEN_SEARCH.
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
EXPECT_TRUE(GetSearchBoxView()->is_search_box_active());
// Tap or click the body of the AppList again, the searchbox should deactivate
// and the applist should be in FULLSCREEN_ALL_APPS.
ClickOrTap(GetPointOutsideSearchbox());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EXPECT_FALSE(GetSearchBoxView()->is_search_box_active());
}
// Tests that tapping or clicking the body of the applist with an active virtual
// keyboard when there is no text in the searchbox results in both the virtual
// keyboard and searchbox closing with no side effects.
TEST_P(AppListPresenterVirtualKeyboardTest,
TapAppListWithVirtualKeyboardDismissesVirtualKeyboardWithoutSearchText) {
EnableTabletMode(true);
// Tap to activate the searchbox.
ClickOrTap(GetPointInsideSearchbox());
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
// Manually show the virtual keyboard.
auto* const keyboard_controller = keyboard::KeyboardUIController::Get();
keyboard_controller->ShowKeyboard(true);
ASSERT_TRUE(keyboard::test::WaitUntilShown());
// Tap or click outside the searchbox, the virtual keyboard should hide and
// the searchbox should be inactive when there is no text in the searchbox.
ClickOrTap(GetPointOutsideSearchbox());
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EXPECT_FALSE(keyboard_controller->IsKeyboardVisible());
EXPECT_FALSE(GetSearchBoxView()->is_search_box_active());
}
TEST_F(AppListPresenterHomeLauncherTest, TapHomeButtonOnExternalDisplay) {
UpdateDisplay("800x600,1000x768");
TapHomeButton(GetSecondaryDisplay().id());
{
SCOPED_TRACE("1st tap");
GetAppListTestHelper()->CheckVisibility(true);
}
TapHomeButton(GetSecondaryDisplay().id());
{
SCOPED_TRACE("2nd tap");
GetAppListTestHelper()->CheckVisibility(false);
}
}
// Tests that a tap/click on the AppListView from Fullscreen search returns
// the AppListView to fullscreen all apps, and that a tap/click on the
// AppListView from fullscreen all apps closes the app list.
TEST_P(AppListPresenterHomeLauncherTest,
StateTransitionsByTappingAppListBodyFromFullscreen) {
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
SearchBoxView* search_box_view = GetAppListView()->search_box_view();
ui::test::EventGenerator* generator = GetEventGenerator();
const bool test_mouse_event = TestMouseEventParam();
// Press a key, this should activate the searchbox and transition to
// fullscreen search.
PressAndReleaseKey(ui::KeyboardCode::VKEY_0);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenSearch);
EXPECT_TRUE(search_box_view->is_search_box_active());
// Tap outside the searchbox, this should deactivate the searchbox and the
// applistview should return to fullscreen all apps.
if (test_mouse_event) {
generator->MoveMouseTo(GetPointOutsideSearchbox());
generator->ClickLeftButton();
} else {
generator->GestureTapDownAndUp(GetPointOutsideSearchbox());
}
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EXPECT_FALSE(search_box_view->is_search_box_active());
}
// Tests that the searchbox activates when it is tapped and that the widget is
// closed after tapping outside the searchbox.
TEST_P(AppListPresenterHomeLauncherTest, TapAndClickEnablesSearchBox) {
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
SearchBoxView* search_box_view = GetAppListView()->search_box_view();
ui::test::EventGenerator* generator = GetEventGenerator();
const bool test_mouse_event = TestMouseEventParam();
if (test_mouse_event) {
generator->MoveMouseTo(GetPointInsideSearchbox());
generator->PressLeftButton();
generator->ReleaseLeftButton();
} else {
generator->GestureTapAt(GetPointInsideSearchbox());
}
EXPECT_TRUE(search_box_view->is_search_box_active());
// Tap on the body of the app list, the search box should deactivate.
if (test_mouse_event) {
generator->MoveMouseTo(GetPointOutsideSearchbox());
generator->PressLeftButton();
generator->ReleaseLeftButton();
} else {
generator->GestureTapAt(GetPointOutsideSearchbox());
}
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(search_box_view->is_search_box_active());
GetAppListTestHelper()->CheckVisibility(true);
}
// Test that gesture tapping the app list search box correctly handles the event
// by moving the textfield's cursor to the tapped position within the text.
TEST_P(AppListPresenterTest, SearchBoxTextfieldGestureTap) {
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
// Tap on the search box to focus and open it.
ui::test::EventGenerator* generator = GetEventGenerator();
generator->GestureTapAt(GetPointInsideSearchbox());
// Set the text of the search box textfield.
views::Textfield* textfield = GetSearchBoxView()->search_box();
textfield->SetText(u"Test search box string");
// The textfield's cursor position should start out at the end of the string.
size_t initial_cursor_position = textfield->GetCursorPosition();
// Gesture tap to move the cursor to the middle of the string.
gfx::Rect textfield_bounds = textfield->GetBoundsInScreen();
gfx::Rect cursor_bounds =
views::TextfieldTestApi(textfield).GetCursorViewRect();
EXPECT_GT(cursor_bounds.x(), 0);
gfx::Point touch_location(textfield_bounds.x() + cursor_bounds.x() / 2,
textfield_bounds.y());
generator->GestureTapAt(touch_location);
// Cursor position should have changed after the gesture tap.
EXPECT_LT(textfield->GetCursorPosition(), initial_cursor_position);
}
// Tests tablet <-> clamshell mode transition.
class AppListPresenterWithScaleAnimationOnTabletModeTransitionTest
: public AppListPresenterTest {
protected:
void EnsureAppListViewIsCached() {
ASSERT_FALSE(GetAppListTestHelper()->GetAppListView());
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EnableTabletMode(false);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
// Entering and exiting from tablet mode should keep `AppListView` cached.
ASSERT_TRUE(GetAppListTestHelper()->GetAppListView());
}
};
TEST_F(AppListPresenterWithScaleAnimationOnTabletModeTransitionTest,
UpdatesScaleAndOpacity) {
// Enter tablet mode.
EnableTabletMode(true);
GetAppListTestHelper()->ShowAndRunLoop(GetPrimaryDisplayId());
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
auto* const window =
GetAppListTestHelper()->GetAppListView()->GetWidget()->GetNativeWindow();
auto* const layer = window->layer();
const auto center_point = gfx::Rect(layer->size()).CenterPoint();
const auto no_transform = gfx::GetScaleTransform(center_point, 1.0f);
const auto scaled_down_transform =
gfx::GetScaleTransform(center_point, 0.92f);
// The layer is fully visible and without applied transform.
EXPECT_EQ(layer->opacity(), 1.0f);
EXPECT_EQ(layer->transform(), no_transform);
EXPECT_TRUE(window->IsVisible());
// Exit tablet mode.
EnableTabletMode(false);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckState(AppListViewState::kClosed);
// The layer is fully transparent, scaled down and the window is hidden.
EXPECT_EQ(layer->opacity(), 0.00f);
EXPECT_EQ(layer->transform(), scaled_down_transform);
EXPECT_FALSE(window->IsVisible());
}
TEST_F(AppListPresenterWithScaleAnimationOnTabletModeTransitionTest,
ExitingFromOverviewInClamshellModeShouldNotAffectFullscreenLauncher) {
EnsureAppListViewIsCached();
auto* const layer = GetAppListTestHelper()
->GetAppListView()
->GetWidget()
->GetNativeWindow()
->layer();
const auto expected_opacity = layer->opacity();
const auto expected_transform = layer->transform();
OverviewController* overview_controller = OverviewController::Get();
EnterOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
ExitOverview();
EXPECT_FALSE(overview_controller->InOverviewSession());
// Layer's opacity and transform should stay the same.
EXPECT_EQ(layer->opacity(), expected_opacity);
EXPECT_EQ(layer->transform(), expected_transform);
}
// Tests that dismiss animation while animating to fullscreen state and open
// animation while animating to closed state continue from the same
// opacity/scale values where it was interrupted.
TEST_F(AppListPresenterWithScaleAnimationOnTabletModeTransitionTest,
TransitionContinuesWhereItWasInterrupted) {
EnsureAppListViewIsCached();
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
auto* const layer = GetAppListTestHelper()
->GetAppListView()
->GetWidget()
->GetNativeWindow()
->layer();
const auto center_point = gfx::Rect(layer->size()).CenterPoint();
const auto no_transform = gfx::GetScaleTransform(center_point, 1.0f);
const auto scaled_down_transform =
gfx::GetScaleTransform(center_point, 0.92f);
const auto initial_opacity = 0.01f;
const auto initial_transform = scaled_down_transform;
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_EQ(layer->opacity(), initial_opacity);
EXPECT_EQ(layer->GetTargetOpacity(), 1.0f);
EXPECT_EQ(layer->transform(), initial_transform);
EXPECT_EQ(layer->GetTargetTransform(), no_transform);
// Interrupt clamshell -> tablet transition by switching back to clamshell
// mode. Current transform and opacity stay at initial values.
ash::TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_EQ(layer->opacity(), initial_opacity);
EXPECT_EQ(layer->GetTargetOpacity(), 0.0f);
EXPECT_EQ(layer->transform(), initial_transform);
EXPECT_EQ(layer->GetTargetTransform(), scaled_down_transform);
// Interrupt tablet -> clamshell transition by switching back to tablet mode.
// Current transform and opacity stay at initial values.
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_EQ(layer->opacity(), initial_opacity);
EXPECT_EQ(layer->GetTargetOpacity(), 1.0f);
EXPECT_EQ(layer->transform(), initial_transform);
EXPECT_EQ(layer->GetTargetTransform(), no_transform);
}
TEST_F(AppListPresenterWithScaleAnimationOnTabletModeTransitionTest,
AbortedHideAnimationDoesNotChangeVisibility) {
// Configure test observer.
auto visibility_observer = std::make_unique<TestAppListControllerObserver>();
auto* const app_list_controller = Shell::Get()->app_list_controller();
app_list_controller->AddObserver(visibility_observer.get());
// Switch to tablet mode and set normal animation duration.
ash::TabletModeControllerTestApi().EnterTabletMode();
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
EXPECT_EQ(visibility_observer->visibility_changed_to_hidden_times(), 0);
ash::TabletModeControllerTestApi().LeaveTabletMode();
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_EQ(visibility_observer->visibility_changed_to_hidden_times(), 0);
}
} // namespace ash
|