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
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/time/calendar_view.h"
#include <climits>
#include <memory>
#include <string_view>
#include "ash/calendar/calendar_client.h"
#include "ash/calendar/calendar_controller.h"
#include "ash/constants/ash_features.h"
#include "ash/glanceables/common/glanceables_view_id.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/icon_button.h"
#include "ash/system/notification_center/views/notification_center_view.h"
#include "ash/system/time/calendar_event_list_view.h"
#include "ash/system/time/calendar_list_model.h"
#include "ash/system/time/calendar_model.h"
#include "ash/system/time/calendar_month_view.h"
#include "ash/system/time/calendar_unittest_utils.h"
#include "ash/system/time/calendar_utils.h"
#include "ash/system/time/calendar_view_controller.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
#include "base/types/cxx23_to_underlying.h"
#include "chromeos/ash/components/settings/scoped_timezone_settings.h"
#include "components/account_id/account_id.h"
#include "google_apis/calendar/calendar_api_requests.h"
#include "google_apis/common/api_error_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/layer_animation_stopped_waiter.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/test/ax_event_counter.h"
#include "ui/views/view.h"
namespace ash {
namespace {
using ::google_apis::calendar::CalendarEvent;
using ::google_apis::calendar::EventList;
using ::google_apis::calendar::SingleCalendar;
constexpr char kTestUser[] = "user@test";
const char* kCalendarId1 = "user1@email.com";
const char* kCalendarSummary1 = "user1@email.com";
const char* kCalendarColorId1 = "12";
bool kCalendarSelected1 = true;
bool kCalendarPrimary1 = true;
} // namespace
class CalendarViewControllerTestObserver
: public CalendarViewController::Observer {
public:
explicit CalendarViewControllerTestObserver(
base::OnceCallback<void(void)> callback)
: callback_(std::move(callback)) {}
CalendarViewControllerTestObserver(
const CalendarViewControllerTestObserver&) = delete;
CalendarViewControllerTestObserver& operator=(
const CalendarViewControllerTestObserver&) = delete;
~CalendarViewControllerTestObserver() override = default;
void OnCalendarLoaded() override { std::move(callback_).Run(); }
private:
base::OnceCallback<void(void)> callback_;
};
class CalendarViewTest : public AshTestBase {
public:
CalendarViewTest() {
features_.InitWithFeatures(
/*enabled_features=*/{},
/*disabled_features=*/{
features::kGlanceablesTimeManagementClassroomStudentView,
features::kGlanceablesTimeManagementTasksView});
}
CalendarViewTest(const CalendarViewTest&) = delete;
CalendarViewTest& operator=(const CalendarViewTest&) = delete;
~CalendarViewTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
Shell::Get()->calendar_controller()->SetActiveUserAccountIdForTesting(
account_id_);
Shell::Get()->calendar_controller()->RegisterClientForUser(account_id_,
&client_);
widget_ = CreateFramelessTestWidget();
widget_->SetFullscreen(true);
}
void TearDown() override {
DestroyCalendarViewWidget();
Shell::Get()->calendar_controller()->RegisterClientForUser(account_id_,
nullptr);
AshTestBase::TearDown();
}
calendar_test_utils::CalendarClientTestImpl* client() { return &client_; }
// Gets date cell of a given CalendarMonthView and numerical `day`.
const views::LabelButton* GetDateCell(CalendarMonthView* month,
std::u16string day) {
const views::LabelButton* date_cell = nullptr;
for (const views::View* child_view : month->children()) {
auto* current_date_cell =
static_cast<const views::LabelButton*>(child_view);
if (day != current_date_cell->GetText()) {
continue;
}
date_cell = current_date_cell;
break;
}
return date_cell;
}
// Clicks on a given `date_cell`.
void ClickDateCell(const views::LabelButton* date_cell) {
auto* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(date_cell->GetBoundsInScreen().CenterPoint());
event_generator->ClickLeftButton();
}
void CreateCalendarView() {
if (!widget_) {
widget_ = CreateFramelessTestWidget();
widget_->SetFullscreen(true);
}
AccountId user_account = AccountId::FromUserEmail(kTestUser);
GetSessionControllerClient()->SwitchActiveUser(user_account);
auto calendar_view = std::make_unique<CalendarView>(
/*use_glanceables_container_style=*/false);
// This awkward-looking thing is to ensure that calendar_view_ (a raw_ptr)
// doesn't outlive the calendar view it points to, which is otherwise
// destroyed as part of Widget::SetContentsView().
calendar_view_ = nullptr;
calendar_view_ = widget_->SetContentsView(std::move(calendar_view));
}
void CloseEventList() { calendar_view_->CloseEventList(); }
void DestroyCalendarViewWidget() {
calendar_view_ = nullptr;
widget_.reset();
}
// Calendar has some arbitrary delays to allow itself to load, otherwise the
// test assertions run too early and fail. We hook into the `OnCalendarLoaded`
// callback here to pause the test until the Calendar has finished loading.
void WaitForCalendarToCompleteLoading() {
base::RunLoop run_loop;
auto callback = [](base::RunLoop* run_loop) {
run_loop->QuitClosure().Run();
};
auto observer = std::make_unique<CalendarViewControllerTestObserver>(
base::BindOnce(callback, &run_loop));
AddCalendarViewControllerObserver(observer.get());
run_loop.Run();
RemoveCalendarViewControllerObserver(observer.get());
}
CalendarView* calendar_view() { return calendar_view_; }
views::ScrollView* scroll_view() { return calendar_view_->scroll_view_; }
views::View* previous_label() { return calendar_view_->previous_label_; }
views::View* current_label() { return calendar_view_->current_label_; }
views::View* next_label() { return calendar_view_->next_label_; }
views::View* next_next_label() { return calendar_view_->next_next_label_; }
views::ScrollView::ScrollBarMode GetScrollBarMode() {
return scroll_view()->GetVerticalScrollBarMode();
}
// The position of the `next_month_`.
int NextMonthPosition() {
return previous_label()->GetPreferredSize().height() +
calendar_view_->previous_month_->GetPreferredSize().height() +
current_label()->GetPreferredSize().height() +
calendar_view_->current_month_->GetPreferredSize().height() +
next_label()->GetPreferredSize().height();
}
std::u16string_view GetPreviousLabelText() {
return static_cast<views::Label*>(previous_label()->children()[0])
->GetText();
}
std::u16string_view GetCurrentLabelText() {
return static_cast<views::Label*>(current_label()->children()[0])
->GetText();
}
std::u16string_view GetNextLabelText() {
return static_cast<views::Label*>(next_label()->children()[0])->GetText();
}
std::u16string_view GetNextNextLabelText() {
return static_cast<views::Label*>(next_next_label()->children()[0])
->GetText();
}
CalendarMonthView* previous_month() {
return calendar_view_->previous_month_;
}
CalendarMonthView* current_month() { return calendar_view_->current_month_; }
CalendarMonthView* next_month() { return calendar_view_->next_month_; }
CalendarMonthView* next_next_month() {
return calendar_view_->next_next_month_;
}
views::Label* month_header() { return calendar_view_->header_->header_; }
views::Label* header_year() { return calendar_view_->header_->header_year_; }
views::Button* reset_to_today_button() {
return calendar_view_->reset_to_today_button_;
}
views::Button* settings_button() { return calendar_view_->settings_button_; }
views::Button* managed_button() { return calendar_view_->managed_button_; }
IconButton* up_button() { return calendar_view_->up_button_; }
IconButton* down_button() { return calendar_view_->down_button_; }
views::View* close_button() {
return calendar_view_->event_list_view_->close_button_container_
->children()[0];
}
views::View* event_list_view() { return calendar_view_->event_list_view_; }
std::optional<base::Time> selected_date() {
return calendar_view_->event_list_view_->calendar_view_controller_
->selected_date_;
}
CalendarUpNextView* up_next_view() { return calendar_view_->up_next_view_; }
views::View* up_next_scroll_contents() {
return calendar_view_->up_next_view_->content_view_;
}
// Executes the given task immediately rather than waiting for the timer.
void run_upcoming_events_timer_task() {
calendar_view_->check_upcoming_events_timer_.user_task().Run();
}
views::View* calendar_sliding_surface_view() {
return calendar_view_->calendar_sliding_surface_;
}
views::View* up_next_todays_events_button() {
return calendar_view_->up_next_view_->todays_events_button_container_
->children()[0];
}
void ScrollUpOneMonth() {
calendar_view_->ScrollOneMonthAndAutoScroll(/*scroll_up=*/true);
}
void ScrollDownOneMonth() {
calendar_view_->ScrollOneMonthAndAutoScroll(/*scroll_up=*/false);
}
void ScrollUpOneMonthWithAnimation() {
calendar_view_->ScrollOneMonthWithAnimation(/*scroll_up=*/true);
}
void ScrollDownOneMonthWithAnimation() {
calendar_view_->ScrollOneMonthWithAnimation(/*scroll_up=*/false);
}
void ResetToToday() { calendar_view_->ResetToToday(); }
void RequestFocusForEventListCloseButton() {
calendar_view_->RequestFocusForEventListCloseButton();
}
void PressTab() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_TAB, ui::EF_NONE);
}
void PressShiftTab() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_TAB, ui::EF_SHIFT_DOWN);
}
void PressEnter() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_RETURN, ui::EF_NONE);
}
void PressUp() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_UP, ui::EF_NONE);
}
void PressDown() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_DOWN, ui::EF_NONE);
}
void PressLeft() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_LEFT, ui::EF_NONE);
}
void PressRight() {
ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.PressKey(ui::KeyboardCode::VKEY_RIGHT, ui::EF_NONE);
}
void AddCalendarViewControllerObserver(
CalendarViewController::Observer* observer) {
calendar_view_->calendar_view_controller_->AddObserver(observer);
}
void RemoveCalendarViewControllerObserver(
CalendarViewController::Observer* observer) {
calendar_view_->calendar_view_controller_->RemoveObserver(observer);
}
static base::Time FakeTimeNow() { return fake_time_; }
static void SetFakeNow(base::Time fake_now) { fake_time_ = fake_now; }
private:
base::test::ScopedFeatureList features_;
const AccountId account_id_ = AccountId::FromUserEmail("user1@email.com");
calendar_test_utils::CalendarClientTestImpl client_;
std::unique_ptr<views::Widget> widget_;
// Owned by `widget_`.
raw_ptr<CalendarView> calendar_view_ = nullptr;
std::unique_ptr<CalendarEventListView> event_list_view_;
static base::Time fake_time_;
};
base::Time CalendarViewTest::fake_time_;
// Test the init view of the `CalendarView`.
TEST_F(CalendarViewTest, Init) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Aug 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
EXPECT_EQ(u"July", GetPreviousLabelText());
EXPECT_EQ(u"August", GetCurrentLabelText());
EXPECT_EQ(u"September", GetNextLabelText());
EXPECT_EQ(u"October", GetNextNextLabelText());
EXPECT_EQ(u"August", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
EXPECT_EQ(u"27",
static_cast<views::LabelButton*>(previous_month()->children()[0])
->GetText());
EXPECT_EQ(u"1",
static_cast<views::LabelButton*>(current_month()->children()[0])
->GetText());
EXPECT_EQ(
u"29",
static_cast<views::LabelButton*>(next_month()->children()[0])->GetText());
EXPECT_EQ(u"26",
static_cast<views::LabelButton*>(next_next_month()->children()[0])
->GetText());
}
// Test the init view of the `CalendarView` starting with December.
TEST_F(CalendarViewTest, InitDec) {
base::Time dec_date;
ASSERT_TRUE(base::Time::FromString("24 Dec 2021 10:00 GMT", &dec_date));
// Set time override.
SetFakeNow(dec_date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
EXPECT_EQ(u"November", GetPreviousLabelText());
EXPECT_EQ(u"December", GetCurrentLabelText());
EXPECT_EQ(u"January", GetNextLabelText());
EXPECT_EQ(u"February", GetNextNextLabelText());
EXPECT_EQ(u"December", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
EXPECT_EQ(u"31",
static_cast<views::LabelButton*>(previous_month()->children()[0])
->GetText());
EXPECT_EQ(u"28",
static_cast<views::LabelButton*>(current_month()->children()[0])
->GetText());
EXPECT_EQ(u"30",
static_cast<views::LabelButton*>(next_next_month()->children()[0])
->GetText());
}
// TODO(b/285280977): Remove when CalendarView is out of TrayDetailedView.
TEST_F(CalendarViewTest, NoBackButton) {
CreateCalendarView();
// No back button should be shown.
EXPECT_FALSE(
calendar_view()->GetViewByID(VIEW_ID_QS_DETAILED_VIEW_BACK_BUTTON));
}
TEST_F(CalendarViewTest, Scroll) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
EXPECT_EQ(u"September", GetPreviousLabelText());
EXPECT_EQ(u"October", GetCurrentLabelText());
EXPECT_EQ(u"November", GetNextLabelText());
EXPECT_EQ(u"December", GetNextNextLabelText());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Scrolls to the next month.
scroll_view()->ScrollToPosition(scroll_view()->vertical_scroll_bar(),
NextMonthPosition());
EXPECT_EQ(u"October", GetPreviousLabelText());
EXPECT_EQ(u"November", GetCurrentLabelText());
EXPECT_EQ(u"December", GetNextLabelText());
EXPECT_EQ(u"January", GetNextNextLabelText());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
scroll_view()->ScrollToPosition(scroll_view()->vertical_scroll_bar(),
NextMonthPosition());
EXPECT_EQ(u"November", GetPreviousLabelText());
EXPECT_EQ(u"December", GetCurrentLabelText());
EXPECT_EQ(u"January", GetNextLabelText());
EXPECT_EQ(u"February", GetNextNextLabelText());
EXPECT_EQ(u"December", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
scroll_view()->ScrollToPosition(scroll_view()->vertical_scroll_bar(),
NextMonthPosition());
EXPECT_EQ(u"December", GetPreviousLabelText());
EXPECT_EQ(u"January", GetCurrentLabelText());
EXPECT_EQ(u"February", GetNextLabelText());
EXPECT_EQ(u"March", GetNextNextLabelText());
EXPECT_EQ(u"January", month_header()->GetText());
EXPECT_EQ(u"2022", header_year()->GetText());
}
// Tests the up, down, and reset_to_today button callback functions.
TEST_F(CalendarViewTest, ButtonFunctions) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
EXPECT_EQ(u"September", GetPreviousLabelText());
EXPECT_EQ(u"October", GetCurrentLabelText());
EXPECT_EQ(u"November", GetNextLabelText());
EXPECT_EQ(u"December", GetNextNextLabelText());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
ScrollDownOneMonth();
EXPECT_EQ(u"October", GetPreviousLabelText());
EXPECT_EQ(u"November", GetCurrentLabelText());
EXPECT_EQ(u"December", GetNextLabelText());
EXPECT_EQ(u"January", GetNextNextLabelText());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
ScrollDownOneMonth();
EXPECT_EQ(u"November", GetPreviousLabelText());
EXPECT_EQ(u"December", GetCurrentLabelText());
EXPECT_EQ(u"January", GetNextLabelText());
EXPECT_EQ(u"February", GetNextNextLabelText());
EXPECT_EQ(u"December", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
ScrollDownOneMonth();
EXPECT_EQ(u"December", GetPreviousLabelText());
EXPECT_EQ(u"January", GetCurrentLabelText());
EXPECT_EQ(u"February", GetNextLabelText());
EXPECT_EQ(u"January", month_header()->GetText());
EXPECT_EQ(u"2022", header_year()->GetText());
ScrollUpOneMonth();
EXPECT_EQ(u"November", GetPreviousLabelText());
EXPECT_EQ(u"December", GetCurrentLabelText());
EXPECT_EQ(u"January", GetNextLabelText());
EXPECT_EQ(u"December", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
ScrollDownOneMonth();
EXPECT_EQ(u"December", GetPreviousLabelText());
EXPECT_EQ(u"January", GetCurrentLabelText());
EXPECT_EQ(u"February", GetNextLabelText());
EXPECT_EQ(u"March", GetNextNextLabelText());
EXPECT_EQ(u"January", month_header()->GetText());
EXPECT_EQ(u"2022", header_year()->GetText());
// Goes back to the landing view.
ResetToToday();
EXPECT_EQ(u"September", GetPreviousLabelText());
EXPECT_EQ(u"October", GetCurrentLabelText());
EXPECT_EQ(u"November", GetNextLabelText());
EXPECT_EQ(u"December", GetNextNextLabelText());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Multiple clicking on the up/down buttons.
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
EXPECT_EQ(u"May", GetPreviousLabelText());
EXPECT_EQ(u"June", GetCurrentLabelText());
EXPECT_EQ(u"July", GetNextLabelText());
EXPECT_EQ(u"August", GetNextNextLabelText());
EXPECT_EQ(u"June", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
EXPECT_EQ(u"September", GetPreviousLabelText());
EXPECT_EQ(u"October", GetCurrentLabelText());
EXPECT_EQ(u"November", GetNextLabelText());
EXPECT_EQ(u"December", GetNextNextLabelText());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
}
// For all the Focusing tests below, Jun, 2021 is used.
// 30, 31, 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, 1 , 2 , 3
TEST_F(CalendarViewTest, HeaderFocusing) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open.
EXPECT_EQ(focus_manager->GetFocusedView()->GetClassName(),
"CalendarDateCellView");
EXPECT_EQ(
static_cast<const views::LabelButton*>(focus_manager->GetFocusedView())
->GetText(),
u"7");
// Moves to the next focusable view. Today's button.
PressTab();
EXPECT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
// Moves to settings button.
PressTab();
EXPECT_EQ(settings_button(), focus_manager->GetFocusedView());
// Moves to up button.
PressTab();
EXPECT_EQ(up_button(), focus_manager->GetFocusedView());
// Moves to down button.
PressTab();
EXPECT_EQ(down_button(), focus_manager->GetFocusedView());
// Moves to today's cell.
PressTab();
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
// Moves to down button.
PressShiftTab();
EXPECT_EQ(down_button(), focus_manager->GetFocusedView());
// Moves to up button.
PressShiftTab();
EXPECT_EQ(up_button(), focus_manager->GetFocusedView());
// Moves to settings button.
PressShiftTab();
EXPECT_EQ(settings_button(), focus_manager->GetFocusedView());
// Moves to "Go back to today" button.
PressShiftTab();
EXPECT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
}
// Tests the focus loop between the back button, today's button, settings
// button, and the todays date in the month.
TEST_F(CalendarViewTest, FocusingToDateCell) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Focus should start on todays CalendarDateCellView.
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressTab(); // Moves to Today's button.
EXPECT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
PressTab(); // Moves to settings button.
PressTab(); // Moves to down button.
PressTab(); // Moves to up button.
// Moves to the the 7th date cell, which is the date of "today".
PressTab();
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
}
// Tests the Ash.Calendar.MaxDistanceBrowsed metric only records once in
// CalendarViews lifetime.
TEST_F(CalendarViewTest, MaxDistanceBrowsedRecordsOncePerLifetime) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
auto histogram_tester = std::make_unique<base::HistogramTester>();
CreateCalendarView();
DestroyCalendarViewWidget();
// The metric should log once.
histogram_tester->ExpectTotalCount("Ash.Calendar.MaxDistanceBrowsed", 1);
// Create the CalendarView again, and scroll once. The metric should record
// once, but only once the widget has been destroyed.
histogram_tester = std::make_unique<base::HistogramTester>();
CreateCalendarView();
ScrollDownOneMonth();
histogram_tester->ExpectTotalCount("Ash.Calendar.MaxDistanceBrowsed", 0);
DestroyCalendarViewWidget();
histogram_tester->ExpectTotalCount("Ash.Calendar.MaxDistanceBrowsed", 1);
// Create the CalendarView again, scroll a few more times. Still the metric
// should only record once.
histogram_tester = std::make_unique<base::HistogramTester>();
CreateCalendarView();
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollUpOneMonth();
DestroyCalendarViewWidget();
histogram_tester->ExpectTotalCount("Ash.Calendar.MaxDistanceBrowsed", 1);
}
// Tests the Ash.Calendar.MaxDistanceBrowsed metric records max distance
// traveled from today.
TEST_F(CalendarViewTest,
MaxDistanceBrowsedRecordsAbsoluteValueOfDistanceTraveled) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
auto histogram_tester = base::HistogramTester();
CreateCalendarView();
const int scroll_up_count = 10;
const int scroll_down_count = scroll_up_count - 1;
// Scroll up.
for (int i = 0; i < scroll_up_count; ++i) {
ScrollUpOneMonth();
}
// Return to today.
for (int i = 0; i < scroll_up_count; ++i) {
ScrollDownOneMonth();
}
// Scroll down from today.
for (int i = 0; i < scroll_down_count; ++i) {
ScrollDownOneMonth();
}
DestroyCalendarViewWidget();
// `scroll_up_count` is the furthest traveled.
histogram_tester.ExpectBucketCount("Ash.Calendar.MaxDistanceBrowsed",
scroll_up_count, 1);
}
// Used to determine whether focus goes directly to the proper CalendarDateCell
// prior to moving on to the EventListView.
class DateCellFocusChangeListener : public views::FocusChangeListener {
public:
DateCellFocusChangeListener(views::FocusManager* focus_manager,
std::u16string looking_for,
int steps_to_find)
: focus_manager_(focus_manager),
looking_for_(looking_for),
steps_to_find_(steps_to_find) {
focus_manager_->AddFocusChangeListener(this);
}
DateCellFocusChangeListener(const DateCellFocusChangeListener& other) =
delete;
DateCellFocusChangeListener& operator=(
const DateCellFocusChangeListener& other) = delete;
~DateCellFocusChangeListener() override {
focus_manager_->RemoveFocusChangeListener(this);
EXPECT_EQ(steps_taken_, steps_to_find_);
}
bool found() const { return found_; }
// views::FocusChangeListener:
void OnDidChangeFocus(views::View* focused_before,
views::View* focused_now) override {
if (found_) {
return;
}
steps_taken_++;
found_ = static_cast<const views::LabelButton*>(focused_now)->GetText() ==
looking_for_;
DCHECK_LE(steps_taken_, steps_to_find_);
}
private:
// Whether a `views::Labelbutton` matching `looking_for_` was focused.
bool found_ = false;
// How many focus changes have occurred so far.
int steps_taken_ = 0;
// Unowned.
const raw_ptr<views::FocusManager> focus_manager_;
// The string being looked for.
const std::u16string looking_for_;
// The number of steps it is acceptable to have made before finding the
// appropriate view.
const int steps_to_find_;
};
// Tests that keyboard focus movement mixed with non-keyboard date cell
// activation results in proper focus directly to the date cell.
TEST_F(CalendarViewTest, MixedInput) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Focus starts on todays CalendarDateCellView.
ASSERT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
const auto* non_focused_date_cell_view =
GetDateCell(/*month=*/current_month(), /*day=*/u"9");
{
auto focus_change_listener = DateCellFocusChangeListener(
focus_manager, /*looking_for=*/u"9", /*steps_to_find=*/1);
ClickDateCell(non_focused_date_cell_view);
EXPECT_TRUE(focus_change_listener.found());
}
}
// Tests that focus returns to a DateCellView after closing the EventListView if
// the EventListView view tree had a focused view.
TEST_F(CalendarViewTest, FocusAfterClosingEventListView) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Should start with focus on today's cell.
ASSERT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
ASSERT_FALSE(event_list_view());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(calendar_view()->GetFocusManager()->GetFocusedView(),
close_button());
PressEnter();
EXPECT_EQ(
calendar_view()->GetFocusManager()->GetFocusedView()->GetClassName(),
"CalendarDateCellView");
}
TEST_F(CalendarViewTest, FocusReturnsToTodaysDate) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open.
ASSERT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
const auto* todays_date_cell_view = focus_manager->GetFocusedView();
ClickDateCell(static_cast<const views::LabelButton*>(todays_date_cell_view));
ASSERT_TRUE(event_list_view());
PressEnter();
// After EventListView is closed, todays DateCellView should be focused.
EXPECT_EQ(todays_date_cell_view, focus_manager->GetFocusedView());
}
TEST_F(CalendarViewTest, OpenListAndCloseListFireAccessibilityEvents) {
views::test::AXEventCounter counter(views::AXUpdateNotifier::Get());
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
const auto* todays_date_cell_view = focus_manager->GetFocusedView();
EXPECT_EQ(0, counter.GetCount(ax::mojom::Event::kTextChanged, scroll_view()));
// Clicking on the date cell will open the event list. There should be one
// text-changed accessibility event fired on the scroll view.
ClickDateCell(static_cast<const views::LabelButton*>(todays_date_cell_view));
EXPECT_EQ(1, counter.GetCount(ax::mojom::Event::kTextChanged, scroll_view()));
counter.ResetAllCounts();
// Pressing enter will close the event list. There should be one text-changed
// accessibility event fired on the scroll view.
PressEnter();
EXPECT_EQ(1, counter.GetCount(ax::mojom::Event::kTextChanged, scroll_view()));
}
// Tests `RequestFocusForEventListCloseButton()`.
TEST_F(CalendarViewTest, CloseButtonFocusing) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open.
ASSERT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
ASSERT_FALSE(event_list_view());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
// Focus moves back to the date cell.
PressShiftTab();
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
// Manually moves the focus to the close button.
RequestFocusForEventListCloseButton();
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
}
// Tests when the focus changes to another date cell with the event list opened,
// the focusing ring will go to the close button automatically.
TEST_F(CalendarViewTest, FocusingToCloseButtonWithEventListOpened) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open.
ASSERT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
ASSERT_FALSE(event_list_view());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
// Focus moves back to today's date cell.
PressShiftTab();
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
// Navigates to another date cell and focuses on it. The focusing ring should
// go to the close button automatically.
PressUp();
EXPECT_EQ(u"31",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
// Tests different date cells and expects the same focusing behavior.
PressShiftTab();
PressLeft();
EXPECT_EQ(u"29",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
PressShiftTab();
PressRight();
PressRight();
EXPECT_EQ(u"25",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
PressShiftTab();
PressDown();
EXPECT_EQ(u"30",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressEnter();
EXPECT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
}
TEST_F(CalendarViewTest, MonthViewFocusing) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open.
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
// Tapping on arrow keys should start navigating inside the month view.
PressUp();
EXPECT_EQ(u"31",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressDown();
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressLeft();
EXPECT_EQ(u"6",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressLeft();
EXPECT_EQ(u"5",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressDown();
EXPECT_EQ(u"12",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressRight();
EXPECT_EQ(u"13",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressRight();
EXPECT_EQ(u"14",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressRight();
EXPECT_EQ(u"15",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
}
// Should be able to use the arrow keys to navigate to the previous months or
// next months.
TEST_F(CalendarViewTest, FocusingToNavigate) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Focus starts on todays CalendarDateCellView.
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"June", GetCurrentLabelText());
// Tapping on arrow keys should start navigating inside the month view.
PressUp();
EXPECT_EQ(u"31",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"May", GetCurrentLabelText());
PressUp();
EXPECT_EQ(u"24",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressUp();
EXPECT_EQ(u"17",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressUp();
EXPECT_EQ(u"10",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
PressUp();
EXPECT_EQ(u"3",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"May", GetCurrentLabelText());
PressUp();
EXPECT_EQ(u"26",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"April", GetCurrentLabelText());
}
TEST_F(CalendarViewTest, ExpandableViewFocusing) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
EXPECT_EQ(views::ScrollView::ScrollBarMode::kHiddenButEnabled,
GetScrollBarMode());
auto* focus_manager = calendar_view()->GetFocusManager();
// Focus starts on todays CalendarDateCellView.
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"June", GetCurrentLabelText());
// Opens the event list.
PressEnter();
EXPECT_EQ(views::ScrollView::ScrollBarMode::kDisabled, GetScrollBarMode());
// Focus moves to the event list close button.
EXPECT_EQ(close_button(), focus_manager->GetFocusedView());
// Focus moves back to the date cell.
PressShiftTab();
EXPECT_EQ(u"7",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"June", GetCurrentLabelText());
// Tapping on up arrow keys should go to the previous month, which mens the
// scroll bar is enabled during the key pressed.
PressUp();
EXPECT_EQ(u"31",
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
EXPECT_EQ(u"May", GetCurrentLabelText());
EXPECT_EQ(views::ScrollView::ScrollBarMode::kDisabled, GetScrollBarMode());
// Moves to the event list.
PressTab();
EXPECT_EQ(close_button(), focus_manager->GetFocusedView());
// Goes to empty list view.
PressTab();
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_CALENDAR_NO_EVENTS),
static_cast<views::LabelButton*>(focus_manager->GetFocusedView())
->GetText());
// Moves to the next focusable view. Today's button.
PressTab();
EXPECT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
}
// Tests that the metric is recorded when calling `UpdateMonth`.
TEST_F(CalendarViewTest, RecordDwellTimeMetric) {
base::HistogramTester histogram_tester;
CreateCalendarView();
// Does not record metric if `UpdateMonth` is called with same month as the
// one in `current_date_`.
calendar_view()->calendar_view_controller()->UpdateMonth(base::Time::Now());
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/0);
// Records metric when `UpdateMonth` is called with a month different than the
// one in `current_date_`.
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Aug 2021 10:00 GMT", &date));
calendar_view()->calendar_view_controller()->UpdateMonth(date);
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/1);
}
TEST_F(CalendarViewTest, OnSessionBlocked) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::OOBE);
// The 17th child cell in the month, which is the non-grayed out 15th date
// cell.
EXPECT_EQ(u"15",
static_cast<views::LabelButton*>(current_month()->children()[16])
->GetText());
// The calendar view will show today's row as the first row, so only dates
// that are below today's row are in the visible rect.
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[16]));
bool is_showing_event_list_view = event_list_view();
EXPECT_FALSE(is_showing_event_list_view);
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::ACTIVE);
EXPECT_EQ(u"15",
static_cast<views::LabelButton*>(current_month()->children()[16])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[16]));
is_showing_event_list_view = event_list_view();
EXPECT_TRUE(is_showing_event_list_view);
GestureTapOn(close_button());
}
// Tests multiple scenarios that should record the metric when scrolling.
// TODO(crbug.com/333283676): Re-enable once the test failure is fixed.
TEST_F(CalendarViewTest, DISABLED_RecordDwellTimeMetricWhenScrolling) {
base::HistogramTester histogram_tester;
CreateCalendarView();
// Scroll up two times.
ScrollUpOneMonth();
ScrollUpOneMonth();
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/2);
// Scroll down three times.
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/5);
// Reset to today.
ResetToToday();
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/6);
// Opening and closing the CalendarEventListView through a date cell within
// the current month does not record the metric.
auto* first_of_month_date_cell =
GetDateCell(/*month=*/current_month(), /*day=*/u"1");
ClickDateCell(first_of_month_date_cell);
CloseEventList();
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/6);
// Closing the calendar view should record the metric.
DestroyCalendarViewWidget();
histogram_tester.ExpectTotalCount("Ash.Calendar.MonthDwellTime",
/*expected_count=*/7);
}
// Tests that EventListView has proper bounds when shown.
TEST_F(CalendarViewTest, EventListBoundsTest) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
ASSERT_EQ(u"15",
static_cast<views::LabelButton*>(current_month()->children()[16])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[16]));
ASSERT_TRUE(event_list_view());
ASSERT_FALSE(current_month()->layer()->GetAnimator()->is_animating());
// EventListView should be flush with the bottom of the scroll views visible
// area. EventListView is ignored by the CalendarViews LayoutManager, but it
// should be flush with the bottom of `scroll_view_`'s clipped height.
// `scroll_view_`'s bounds extend further to the end of the view, but the
// contents of `scroll_view_` are clipped.
const int bottom_of_scroll_view_visible_area =
scroll_view()->bounds().y() + scroll_view()->GetMaxHeight();
const int top_of_event_list_view = calendar_sliding_surface_view()->y();
EXPECT_EQ(bottom_of_scroll_view_visible_area, top_of_event_list_view);
}
TEST_F(CalendarViewTest, AdminDisabledTest) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
client()->set_is_disabled_by_admin(true);
CreateCalendarView();
auto* focus_manager = calendar_view()->GetFocusManager();
// Todays `DateCellView` should be focused on open.
ASSERT_TRUE(focus_manager->GetFocusedView());
// Moves to the next focusable view - managed icon button.
PressTab();
EXPECT_EQ(managed_button(), focus_manager->GetFocusedView());
// Moves to the next focusable view. Today's button.
PressTab();
EXPECT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
// Moves to settings button.
PressTab();
EXPECT_EQ(settings_button(), focus_manager->GetFocusedView());
// Moves back to managed icon button.
PressShiftTab();
PressShiftTab();
EXPECT_EQ(managed_button(), focus_manager->GetFocusedView());
}
TEST_F(CalendarViewTest, ManagedButtonTest) {
base::Time date;
// Create a monthview based on Jun,7th 2021.
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
client()->set_is_disabled_by_admin(true);
CreateCalendarView();
// Click on managed button to open chrome://management.
GestureTapOn(managed_button());
}
// A test class for testing animation. This class cannot set fake now since it's
// using `MOCK_TIME` to test the animations, and it can't inherit from
// CalendarAnimationTest due to the same reason.
class CalendarViewAnimationTest
: public AshTestBase,
public testing::WithParamInterface</*multi_calendar_enabled=*/bool> {
public:
CalendarViewAnimationTest()
: AshTestBase(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {
scoped_feature_list_.InitWithFeatureStates(
{{features::kMultiCalendarSupport, IsMultiCalendarEnabled()},
{features::kGlanceablesTimeManagementClassroomStudentView, false},
{features::kGlanceablesTimeManagementTasksView, false}});
}
CalendarViewAnimationTest(const CalendarViewAnimationTest&) = delete;
CalendarViewAnimationTest& operator=(const CalendarViewAnimationTest&) =
delete;
~CalendarViewAnimationTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
widget_ = CreateFramelessTestWidget();
widget_->SetFullscreen(true);
// Register a mock `CalendarClient` to the `CalendarController`.
const std::string email = "user1@email.com";
AccountId account_id = AccountId::FromUserEmail(email);
Shell::Get()->calendar_controller()->SetActiveUserAccountIdForTesting(
account_id);
calendar_list_model_ =
Shell::Get()->system_tray_model()->calendar_list_model();
calendar_model_ = Shell::Get()->system_tray_model()->calendar_model();
calendar_client_ =
std::make_unique<calendar_test_utils::CalendarClientTestImpl>();
Shell::Get()->calendar_controller()->RegisterClientForUser(
account_id, calendar_client_.get());
if (IsMultiCalendarEnabled()) {
// Set a mock calendar list so the calendar list fetch returns
// successfully.
SetCalendarList();
}
}
void TearDown() override {
calendar_list_model_ = nullptr;
calendar_model_ = nullptr;
calendar_view_ = nullptr;
widget_.reset();
time_overrides_.reset();
scoped_feature_list_.Reset();
AshTestBase::TearDown();
}
bool IsMultiCalendarEnabled() { return GetParam(); }
void CreateCalendarView() {
// Don't allow calendar_view_ to temporarily dangle while we're replacing
// the Widget's contents view. Otherwise, inside SetContentsView() the old
// calendar_view_ will be destroyed and will temporarily dangle.
calendar_view_ = nullptr;
calendar_view_ = widget_->SetContentsView(std::make_unique<CalendarView>(
/*use_glanceables_container_style=*/false));
}
void SetCalendarList() {
// Set a mock calendar list.
std::list<std::unique_ptr<google_apis::calendar::SingleCalendar>> calendars;
calendars.push_back(calendar_test_utils::CreateCalendar(
kCalendarId1, kCalendarSummary1, kCalendarColorId1, kCalendarSelected1,
kCalendarPrimary1));
calendar_client_->SetCalendarList(
calendar_test_utils::CreateMockCalendarList(std::move(calendars)));
}
// Gets date cell of a given CalendarMonthView and numerical `day`.
const views::LabelButton* GetDateCell(CalendarMonthView* month,
std::u16string day) {
const views::LabelButton* date_cell = nullptr;
for (const views::View* child_view : month->children()) {
auto* current_date_cell =
static_cast<const views::LabelButton*>(child_view);
if (day != current_date_cell->GetText()) {
continue;
}
date_cell = current_date_cell;
break;
}
return date_cell;
}
int GetPositionOfToday() { return calendar_view()->GetPositionOfToday(); }
// Clicks on a given `date_cell`.
void ClickDateCell(const views::LabelButton* date_cell) {
auto* event_generator = GetEventGenerator();
event_generator->MoveMouseTo(date_cell->GetBoundsInScreen().CenterPoint());
event_generator->ClickLeftButton();
}
std::optional<base::Time> GetSelectedDate() {
return calendar_view_->calendar_view_controller()->selected_date_;
}
void CloseEventList() { calendar_view_->CloseEventList(); }
void UpdateMonth(base::Time date) {
calendar_view_->calendar_view_controller()->UpdateMonth(date);
// Advances the time to allow `on_screen_month_` to update.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
calendar_view_->content_view_->RemoveAllChildViews();
calendar_view_->SetMonthViews();
scroll_view()->ScrollToPosition(
scroll_view()->vertical_scroll_bar(),
calendar_view_->GetPositionOfCurrentMonth());
}
// The position of the `next_month_`.
int NextMonthPosition() {
return previous_label()->GetPreferredSize().height() +
calendar_view_->previous_month_->GetPreferredSize().height() +
current_label()->GetPreferredSize().height() +
calendar_view_->current_month_->GetPreferredSize().height() +
next_label()->GetPreferredSize().height();
}
// The position of `current_month_`.
int CurrentMonthPosition() {
return calendar_view_->GetPositionOfCurrentMonth();
}
void ScrollUpOneMonth() {
calendar_view_->ScrollOneMonthWithAnimation(/*scroll_up=*/true);
}
void ScrollDownOneMonth() {
calendar_view_->ScrollOneMonthWithAnimation(/*scroll_up=*/false);
}
void ResetToTodayWithAnimation() {
calendar_view_->ResetToTodayWithAnimation();
}
bool IsAnimating() { return calendar_view_->IsAnimating(); }
bool is_scrolling_up() { return calendar_view_->is_scrolling_up_; }
views::ScrollView::ScrollBarMode GetScrollBarMode() {
return scroll_view()->GetVerticalScrollBarMode();
}
views::Widget* widget() { return widget_.get(); }
CalendarView* calendar_view() { return calendar_view_; }
views::Label* month_header() { return calendar_view_->header_->header_; }
views::Label* header_year() { return calendar_view_->header_->header_year_; }
CalendarHeaderView* header() { return calendar_view_->header_; }
CalendarHeaderView* temp_header() { return calendar_view_->temp_header_; }
CalendarMonthView* current_month() { return calendar_view_->current_month_; }
CalendarMonthView* previous_month() {
return calendar_view_->previous_month_;
}
CalendarMonthView* next_month() { return calendar_view_->next_month_; }
views::View* previous_label() { return calendar_view_->previous_label_; }
views::View* current_label() { return calendar_view_->current_label_; }
views::View* next_label() { return calendar_view_->next_label_; }
views::ScrollView* scroll_view() { return calendar_view_->scroll_view_; }
views::View* event_list_view() { return calendar_view_->event_list_view_; }
CalendarListModel* calendar_list_model() { return calendar_list_model_; }
CalendarModel* calendar_model() { return calendar_model_; }
views::View* calendar_sliding_surface_view() {
return calendar_view_->calendar_sliding_surface_;
}
calendar_test_utils::CalendarClientTestImpl* calendar_client() {
return calendar_client_.get();
}
bool should_months_animate() {
return calendar_view_->should_months_animate_;
}
std::map<base::Time, CalendarModel::FetchingStatus> on_screen_month() {
return calendar_view_->on_screen_month_;
}
// Wait until the response is back. Since we used `PostDelayedTask` with 1
// second to mimic the behavior of fetching, duration of 1 minute should be
// enough.
void WaitUntilFetched() {
task_environment()->FastForwardBy(base::Minutes(1));
base::RunLoop().RunUntilIdle();
}
void SetTodayFromTime(base::Time date) {
std::set<base::Time> months = calendar_utils::GetSurroundingMonthsUTC(
date, calendar_utils::kNumSurroundingMonthsCached);
calendar_model_->non_prunable_months_.clear();
// Non-prunable months are today's date and the two surrounding months.
calendar_model_->AddNonPrunableMonths(months);
}
private:
std::unique_ptr<views::Widget> widget_;
// Owned by `widget_`.
raw_ptr<CalendarView> calendar_view_ = nullptr;
std::unique_ptr<base::subtle::ScopedTimeClockOverrides> time_overrides_;
raw_ptr<CalendarListModel> calendar_list_model_ = nullptr;
raw_ptr<CalendarModel> calendar_model_ = nullptr;
std::unique_ptr<calendar_test_utils::CalendarClientTestImpl> calendar_client_;
base::test::ScopedFeatureList scoped_feature_list_;
};
INSTANTIATE_TEST_SUITE_P(MultiCalendar,
CalendarViewAnimationTest,
testing::Bool());
// The header should show the new header with animation once there's an update
// when the event list view is shown.
TEST_P(CalendarViewAnimationTest, HeaderAnimation) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::ACTIVE);
// Sets the timezone to "America/Los_Angeles".
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
CreateCalendarView();
// Gives it a duration to let the animation finish and pass the cool down
// duration.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
UpdateMonth(date);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Update the header to next month.
calendar_view()->calendar_view_controller()->UpdateMonth(date +
base::Days(10));
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationStartBufferDuration);
// Should not show animation if the event list is not open.
EXPECT_FALSE(temp_header()->GetVisible());
EXPECT_FALSE(header()->layer()->GetAnimator()->is_animating());
EXPECT_FALSE(temp_header()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Also update the month views to click on the correct date cell.
UpdateMonth(date + base::Days(10));
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Opens the event list view by click on a radom non-grayed out cell.
const auto* date_cell = GetDateCell(/*month=*/current_month(), /*day=*/u"10");
ClickDateCell(date_cell);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_TRUE(event_list_view());
// Update the header to next month.
calendar_view()->calendar_view_controller()->UpdateMonth(date +
base::Days(45));
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationStartBufferDuration);
// Showing the temp header for animation. All header should be animating.
EXPECT_TRUE(temp_header()->GetVisible());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(temp_header()->layer()->GetAnimator()->is_animating());
EXPECT_GE(1.0f, temp_header()->layer()->opacity());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Now the header is updated to the new month and year.
EXPECT_EQ(u"December", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
}
TEST_P(CalendarViewAnimationTest, HeaderAnimationDirection) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Aug 2023 10:00 GMT", &date));
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::ACTIVE);
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
CreateCalendarView();
// Gives it a duration to let the animation finish and pass the cool down
// duration.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
UpdateMonth(date);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Scrolls to the next month.
ScrollDownOneMonth();
EXPECT_FALSE(is_scrolling_up());
// Gives it a duration to let the animation finish.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Scrolls to the previous month.
ScrollUpOneMonth();
EXPECT_TRUE(is_scrolling_up());
// Gives it a duration to let the animation finish.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Opens the event list view by clicking on a non-grayed out cell on the next
// month, so that the header will animate to the next month's header.
const auto* date_cell = GetDateCell(/*month=*/next_month(), /*day=*/u"10");
ClickDateCell(date_cell);
// Gives it a duration to let the animation finish.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_FALSE(is_scrolling_up());
EXPECT_TRUE(event_list_view());
// Gives it a duration to let the animation finish.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
}
// The month views and header should animate when scrolling up or down.
TEST_P(CalendarViewAnimationTest, MonthAndHeaderAnimation) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
CreateCalendarView();
// Gives it a duration to let the animation finish and pass the cool down
// duration.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
UpdateMonth(date);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
EXPECT_FALSE(temp_header()->GetVisible());
// Scrolls to the next month.
ScrollDownOneMonth();
EXPECT_FALSE(is_scrolling_up());
// If scrolls down, the month views and labels will be animating.
EXPECT_EQ(1.0f, header()->layer()->opacity());
task_environment()->FastForwardBy(
calendar_utils::kAnimationDurationForMoving);
EXPECT_TRUE(current_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(current_label()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Showing the temp header for animation. All header should be animating.
EXPECT_TRUE(temp_header()->GetVisible());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(temp_header()->layer()->GetAnimator()->is_animating());
EXPECT_GE(1.0f, temp_header()->layer()->opacity());
// Gives it a duration to let the animation finish.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Now the header is updated to the new month and year before it starts
// showing up.
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
EXPECT_EQ(1.0f, header()->layer()->opacity());
EXPECT_FALSE(temp_header()->GetVisible());
// Scrolls to the previous month.
ScrollUpOneMonth();
EXPECT_TRUE(is_scrolling_up());
// If scrolls up, the month views and labels will be animating.
EXPECT_EQ(1.0f, header()->layer()->opacity());
task_environment()->FastForwardBy(
calendar_utils::kAnimationDurationForVisibility);
EXPECT_TRUE(current_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(current_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_label()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Showing the temp header for animation. All header should be animating.
EXPECT_TRUE(temp_header()->GetVisible());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(temp_header()->layer()->GetAnimator()->is_animating());
EXPECT_GE(1.0f, temp_header()->layer()->opacity());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Multiple clicking on the up/down buttons. Here only checks the label since
// if it scrolls too fast some scroll actions might be skipped due to
// `is_resetting_scroll_` == true.
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(u"2021", header_year()->GetText());
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
ScrollDownOneMonth();
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(u"2021", header_year()->GetText());
}
// The content view should not be scrollable when the month view is animating.
TEST_P(CalendarViewAnimationTest, NotScrollableWhenAnimating) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
base::Time date;
ASSERT_TRUE(base::Time::FromString("24 Oct 2021 10:00 GMT", &date));
CreateCalendarView();
// Gives it a duration to let the animation finish and pass the cool down
// duration.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
UpdateMonth(date);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// The scroll bar is enaled before tapping on the up button.
EXPECT_EQ(views::ScrollView::ScrollBarMode::kHiddenButEnabled,
GetScrollBarMode());
// Scrolls to the previous month.
ScrollUpOneMonth();
// If scrolls down, the month views and labels will be animating.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationStartBufferDuration);
EXPECT_TRUE(current_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(current_label()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Showing the temp header for animation. All header should be animating.
EXPECT_TRUE(temp_header()->GetVisible());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(temp_header()->layer()->GetAnimator()->is_animating());
// Try to scrol to the next month.
scroll_view()->ScrollToPosition(scroll_view()->vertical_scroll_bar(),
NextMonthPosition());
// Should not scroll and keep showing the animation.
EXPECT_EQ(views::ScrollView::ScrollBarMode::kDisabled, GetScrollBarMode());
EXPECT_TRUE(current_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(next_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_month()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(previous_label()->layer()->GetAnimator()->is_animating());
EXPECT_TRUE(current_label()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Animation finished. On the previous month.
EXPECT_EQ(u"September", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
EXPECT_EQ(views::ScrollView::ScrollBarMode::kHiddenButEnabled,
GetScrollBarMode());
// Try to scroll to the next month. Should get to the next month.
scroll_view()->ScrollToPosition(scroll_view()->vertical_scroll_bar(),
NextMonthPosition());
EXPECT_EQ(views::ScrollView::ScrollBarMode::kHiddenButEnabled,
GetScrollBarMode());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
}
TEST_P(CalendarViewAnimationTest, ResetToTodayWithAnimation) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Create calendar view and wait for the animation to finish.
CreateCalendarView();
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(header()->layer());
// Expect header visible before starting ResetToToday animation.
EXPECT_EQ(1.0f, header()->layer()->opacity());
ResetToTodayWithAnimation();
// The header starts to animate.
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
// The header's opacity should be between 0~1 after the first animator
// finished and in the middle of the second animation.
animation_waiter.Wait(header()->layer());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_GT(1.0f, header()->layer()->opacity());
// The header's opacity should be 1 after the second animator finished.
animation_waiter.Wait(header()->layer());
EXPECT_FALSE(header()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(1.0f, header()->layer()->opacity());
// Open event list by selecting the next month's first cell.
const auto* date_cell = GetDateCell(/*month=*/next_month(), /*day=*/u"1");
ClickDateCell(date_cell);
// Event list view starts to animate.
EXPECT_TRUE(
calendar_sliding_surface_view()->layer()->GetAnimator()->is_animating());
animation_waiter.Wait(current_label()->layer());
animation_waiter.Wait(calendar_sliding_surface_view()->layer());
// Event list view just finished animating.
EXPECT_FALSE(
calendar_sliding_surface_view()->layer()->GetAnimator()->is_animating());
EXPECT_FALSE(should_months_animate());
// The cool-down time for enabling animation. Otherwise the next reset to
// today animation will not be enabled.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_TRUE(should_months_animate());
EXPECT_TRUE(event_list_view());
EXPECT_EQ(1.0f, event_list_view()->layer()->opacity());
ResetToTodayWithAnimation();
// The header starts to animate.
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
// The header's opacity should be between 0~1 after the first animator
// finished and in the middle of the second animation.
animation_waiter.Wait(header()->layer());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_GT(1.0f, header()->layer()->opacity());
// The header's opacity should be 1 after the second animator finished.
animation_waiter.Wait(header()->layer());
EXPECT_FALSE(header()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(1.0f, header()->layer()->opacity());
// Expect today's date in `selected_date_` after resetting to today.
EXPECT_EQ(calendar_utils::GetMonthDayYear(base::Time::Now()),
calendar_utils::GetMonthDayYear(GetSelectedDate().value()));
// Expect header visible after closing event list and resetting to today.
CloseEventList();
EXPECT_TRUE(
calendar_sliding_surface_view()->layer()->GetAnimator()->is_animating());
// Wait `event_list_view()`'s layer first since it can be deleted after the
// animation finished.
animation_waiter.Wait(event_list_view()->layer());
animation_waiter.Wait(calendar_sliding_surface_view()->layer());
EXPECT_FALSE(
calendar_sliding_surface_view()->layer()->GetAnimator()->is_animating());
ResetToTodayWithAnimation();
// The header starts to animate.
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
// The header's opacity should be between 0~1 after the first animator
// finished and in the middle of the second animation.
animation_waiter.Wait(header()->layer());
EXPECT_TRUE(header()->layer()->GetAnimator()->is_animating());
EXPECT_GT(1.0f, header()->layer()->opacity());
// The header's opacity should be 1 after the second animator finished.
animation_waiter.Wait(header()->layer());
EXPECT_FALSE(header()->layer()->GetAnimator()->is_animating());
EXPECT_EQ(1.0f, header()->layer()->opacity());
}
// Tests that the loading bar becomes visible when any of the on screen months
// has not finished fetching and becomes invisible once all months on screen
// have finished fetching events.
TEST_P(CalendarViewAnimationTest, LoadingBarVisibilityForOneMonthOnScreen) {
// Sets the timezone to "America/Los_Angeles".
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
// Tests when the `CalendarView` size is small to hold only one month on
// screen.
UpdateDisplay("800x200");
CreateCalendarView();
// Advances the time to allow `on_screen_month_` to initialize.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_EQ(1U, on_screen_month().size());
const auto* progress_bar = calendar_view()->GetViewByID(
base::to_underlying(GlanceablesViewId::kProgressBar));
EXPECT_TRUE(progress_bar->GetVisible());
// Waits until the events are fetched, and tests the loading bar is invisible.
WaitUntilFetched();
EXPECT_FALSE(progress_bar->GetVisible());
}
TEST_P(CalendarViewAnimationTest, LoadingBarVisibility) {
// Sets the timezone to "America/Los_Angeles".
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
// Tests when the `CalendarView` has two months on screen.
UpdateDisplay("800x600");
CreateCalendarView();
// Advances the time to allow `on_screen_month_` to initialize.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
const auto* progress_bar = calendar_view()->GetViewByID(
base::to_underlying(GlanceablesViewId::kProgressBar));
EXPECT_TRUE(progress_bar->GetVisible());
// Waits until the events are fetched, and tests the loading bar is invisible.
WaitUntilFetched();
EXPECT_FALSE(progress_bar->GetVisible());
// Resets to today so that a new fetching request will be sent for on-screen
// months who have cached events(eg. a refetching status). Tests the loading
// bar is visible.
SetTodayFromTime(base::Time::Now());
ResetToTodayWithAnimation();
// Advances the time to allow `on_screen_month_` to update.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_TRUE(progress_bar->GetVisible());
}
// Tests the loading bar visibility for different user sessions.
TEST_P(CalendarViewAnimationTest,
LoadingBarVisibilityForDifferentUserSessions) {
// Make sure that the `CalendarView` can have enough space to hold at least 1
// month. 600 should be enough since the calendar bubble's height is set to
// 464 in the `UnifiedSystemTrayBubble`.
UpdateDisplay("800x600");
// Tests when the user is logged in, the loading bar is visible.
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::ACTIVE);
CreateCalendarView();
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_TRUE(
calendar_view()
->GetViewByID(base::to_underlying(GlanceablesViewId::kProgressBar))
->GetVisible());
// Tests when the screen is locked, the loading bar is invisible.
calendar_model()->ClearAllCachedEvents();
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::LOCKED);
CreateCalendarView();
// Advances the time to allow `on_screen_month_` to initialize.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_FALSE(
calendar_view()
->GetViewByID(base::to_underlying(GlanceablesViewId::kProgressBar))
->GetVisible());
// Tests when the user starts the login process, the loading bar is invisible.
calendar_model()->ClearAllCachedEvents();
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::LOGIN_PRIMARY);
CreateCalendarView();
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_FALSE(
calendar_view()
->GetViewByID(base::to_underlying(GlanceablesViewId::kProgressBar))
->GetVisible());
}
// Tests the loading bar visibility for when fetching events errors.
TEST_P(CalendarViewAnimationTest, LoadingBarVisibilityForErrorFetchingEvents) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("04 May 2022 15:00 GMT", &date));
// Sets the timezone to "America/Los_Angeles".
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
// Tests when the `CalendarView` size is small to hold only one month on
// screen.
UpdateDisplay("800x200");
CreateCalendarView();
// Advances the time to allow `on_screen_month_` to initialize.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
UpdateMonth(date);
EXPECT_EQ(1U, on_screen_month().size());
// Sets the fetching status of current month to be kFetching, and tests the
// loading bar is visible.
base::Time start_of_month = calendar_utils::GetStartOfMonthUTC(date);
base::Time current_date =
calendar_view()->calendar_view_controller()->currently_shown_date();
base::Time start_of_current_month = calendar_utils::GetStartOfMonthUTC(
current_date + calendar_utils::GetTimeDifference(current_date));
EXPECT_EQ(start_of_month, start_of_current_month);
calendar_client()->SetError(google_apis::NO_CONNECTION);
calendar_model()->FetchEvents(start_of_current_month);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
const auto* progress_bar = calendar_view()->GetViewByID(
base::to_underlying(GlanceablesViewId::kProgressBar));
EXPECT_TRUE(progress_bar->GetVisible());
// Waits until the events are fetched, and tests the loading bar is invisible.
WaitUntilFetched();
EXPECT_FALSE(progress_bar->GetVisible());
}
// Tests the loading bar visibility for when fetching events times out.
TEST_P(CalendarViewAnimationTest,
LoadingBarVisibilityForTimeoutFetchingEvents) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("04 May 2022 15:00 GMT", &date));
// Sets the timezone to "America/Los_Angeles".
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
// Tests when the `CalendarView` size is small to hold only one month on
// screen.
UpdateDisplay("800x200");
CreateCalendarView();
// Advances the time to allow `on_screen_month_` to initialize.
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
UpdateMonth(date);
EXPECT_EQ(1U, on_screen_month().size());
// Sets the fetching status of current month to be kFetching, and tests the
// loading bar is visible.
base::Time start_of_month = calendar_utils::GetStartOfMonthUTC(date);
base::Time current_date =
calendar_view()->calendar_view_controller()->currently_shown_date();
base::Time start_of_current_month = calendar_utils::GetStartOfMonthUTC(
current_date + calendar_utils::GetTimeDifference(current_date));
EXPECT_EQ(start_of_month, start_of_current_month);
calendar_client()->ForceTimeout();
calendar_model()->FetchEvents(start_of_current_month);
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
const auto* progress_bar = calendar_view()->GetViewByID(
base::to_underlying(GlanceablesViewId::kProgressBar));
EXPECT_TRUE(progress_bar->GetVisible());
// Waits until the events are fetched, and tests the loading bar is invisible.
WaitUntilFetched();
EXPECT_FALSE(progress_bar->GetVisible());
}
// Tests that the EventListView does not crash if shown during the initial open.
TEST_P(CalendarViewAnimationTest, QuickShowEventListInitialOpen) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
// Creates calendar view, which will trigger an animation.
CreateCalendarView();
// Try to show the EventListView during the initial animation by selecting a
// today's date cell.
ClickDateCell(
calendar_view()->calendar_view_controller()->todays_date_cell_view());
EXPECT_TRUE(IsAnimating());
EXPECT_TRUE(event_list_view());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
EXPECT_TRUE(event_list_view());
}
// Tests that the EventListView does not show during the month change animation.
TEST_P(CalendarViewAnimationTest, DontShowEventListDuringMonthAnimation) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
CreateCalendarView();
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Start the scroll down animation.
ScrollUpOneMonth();
task_environment()->FastForwardBy(
calendar_utils::kAnimationDurationForVisibility);
ASSERT_TRUE(current_month()->layer()->GetAnimator()->is_animating());
// Try to open the EventListView.
const auto* tomorrow_date_cell =
GetDateCell(/*month=*/current_month(), /*day=*/u"25");
ClickDateCell(tomorrow_date_cell);
EXPECT_FALSE(event_list_view());
}
// Regression test for b/265203105
// Tests open/close the `CalendarEventListView`. Also tests one corner case:
// when closing the event list right after opening it, do nothing since the
// animation is not finished.
TEST_P(CalendarViewAnimationTest, OpenAndCloseEventList) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Sets the timezone to "America/Los_Angeles".
ash::system::ScopedTimezoneSettings timezone_settings(u"America/Los_Angeles");
CreateCalendarView();
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(header()->layer());
// Opens the `CalendarEventListView`.
ClickDateCell(
calendar_view()->calendar_view_controller()->todays_date_cell_view());
EXPECT_TRUE(IsAnimating());
EXPECT_TRUE(event_list_view());
EXPECT_TRUE(GetSelectedDate().has_value());
// Should not close the event list before showing up animation is finished.
CloseEventList();
EXPECT_TRUE(IsAnimating());
EXPECT_TRUE(event_list_view());
EXPECT_TRUE(GetSelectedDate().has_value());
// After the showing up animation is finished, the event list view should be
// up.
animation_waiter.Wait(event_list_view()->layer());
animation_waiter.Wait(calendar_sliding_surface_view()->layer());
animation_waiter.Wait(current_label()->layer());
EXPECT_FALSE(IsAnimating());
EXPECT_TRUE(event_list_view());
EXPECT_TRUE(GetSelectedDate().has_value());
// Should close the event list now.
CloseEventList();
// The event list the view is still showing and `selected_date_` value is
// still set during the animation.
EXPECT_TRUE(IsAnimating());
EXPECT_TRUE(event_list_view());
EXPECT_TRUE(GetSelectedDate().has_value());
// Resets the `selected_date_` after the fading out animation is done.
animation_waiter.Wait(event_list_view()->layer());
animation_waiter.Wait(calendar_sliding_surface_view()->layer());
animation_waiter.Wait(current_label()->layer());
EXPECT_FALSE(IsAnimating());
EXPECT_FALSE(event_list_view());
EXPECT_FALSE(GetSelectedDate().has_value());
}
class CalendarViewWithUpNextViewTest : public CalendarViewTest {
public:
CalendarViewWithUpNextViewTest() = default;
CalendarViewWithUpNextViewTest(const CalendarViewWithUpNextViewTest&) =
delete;
CalendarViewWithUpNextViewTest& operator=(
const CalendarViewWithUpNextViewTest&) = delete;
~CalendarViewWithUpNextViewTest() override = default;
// Assumes current time is "18 Nov 2021 10:00 GMT".
std::unique_ptr<google_apis::calendar::EventList>
CreateMockEventListWithEventStartTimeMoreThanTwoHoursAway() {
auto event_list = std::make_unique<google_apis::calendar::EventList>();
event_list->set_time_zone("Greenwich Mean Time");
event_list->InjectItemForTesting(calendar_test_utils::CreateEvent(
"id_0", "summary_0", "18 Nov 2021 12:30 GMT", "18 Nov 2021 13:30 GMT"));
return event_list;
}
// Assumes current time is "18 Nov 2021 10:00 GMT".
std::unique_ptr<google_apis::calendar::EventList>
CreateMockEventListWithEventStartTimeTenMinsAway() {
auto event_list = std::make_unique<google_apis::calendar::EventList>();
event_list->set_time_zone("Greenwich Mean Time");
event_list->InjectItemForTesting(calendar_test_utils::CreateEvent(
"id_0", "summary_0", "18 Nov 2021 10:10 GMT", "18 Nov 2021 13:30 GMT"));
return event_list;
}
// Assumes current time is "18 Nov 2021 10:00 GMT".
std::unique_ptr<google_apis::calendar::EventList>
CreateMockEventListWithTwoEventsOneEndingInOneMin() {
auto event_list = std::make_unique<google_apis::calendar::EventList>();
event_list->set_time_zone("Greenwich Mean Time");
event_list->InjectItemForTesting(calendar_test_utils::CreateEvent(
"id_0", "summary_0", "18 Nov 2021 10:00 GMT", "18 Nov 2021 13:30 GMT"));
event_list->InjectItemForTesting(calendar_test_utils::CreateEvent(
"id_1", "summary_1", "18 Nov 2021 09:00 GMT", "18 Nov 2021 10:01 GMT"));
return event_list;
}
// Assumes current time is "18 Nov 2021 23:55 GMT".
std::unique_ptr<google_apis::calendar::EventList>
CreateMockEventListStartingFivePastMidnight() {
auto event_list = std::make_unique<google_apis::calendar::EventList>();
event_list->set_time_zone("Greenwich Mean Time");
event_list->InjectItemForTesting(calendar_test_utils::CreateEvent(
"id_0", "summary_0", "19 Nov 2021 00:05 GMT", "19 Nov 2021 01:30 GMT"));
return event_list;
}
void MockEventsFetched(
base::Time date,
std::unique_ptr<google_apis::calendar::EventList> event_list) {
Shell::Get()->system_tray_model()->calendar_model()->OnEventsFetched(
calendar_utils::GetStartOfMonthUTC(date),
google_apis::calendar::kPrimaryCalendarId,
google_apis::ApiErrorCode::HTTP_SUCCESS, event_list.get());
}
};
TEST_F(CalendarViewWithUpNextViewTest,
GivenNoEvents_WhenCalendarViewOpens_ThenUpNextViewShouldNotBeShown) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("7 Jun 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
client()->set_is_disabled_by_admin(true);
CreateCalendarView();
// When we've just created the calendar view and not fetched any events, then
// up next shouldn't have been created.
bool is_showing_up_next_view = up_next_view();
EXPECT_FALSE(is_showing_up_next_view);
}
TEST_F(
CalendarViewWithUpNextViewTest,
GivenEventsStartingMoreThanTwoHoursAway_WhenCalendarViewOpens_ThenUpNextViewShouldNotBeShown) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(
calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeMoreThanTwoHoursAway());
// Fetch an event starting more than two hours away, up next should show.
bool is_showing_up_next_view = up_next_view();
EXPECT_TRUE(is_showing_up_next_view);
}
TEST_F(CalendarViewWithUpNextViewTest, ShouldShowUpNextView) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE(up_next_view());
}
TEST_F(CalendarViewWithUpNextViewTest,
ShouldNotShowUpNextView_WhenEventListViewIsOpen) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Open the event list view for any day.
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[25]));
ASSERT_TRUE(event_list_view());
// Mock events that start in ten mins coming in.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
bool is_showing_up_next_view = up_next_view();
EXPECT_FALSE(is_showing_up_next_view);
const int bottom_of_scroll_view_visible_area =
scroll_view()->bounds().y() + scroll_view()->GetMaxHeight();
const int top_of_event_list_view = calendar_sliding_surface_view()->y();
EXPECT_EQ(bottom_of_scroll_view_visible_area, top_of_event_list_view);
}
// If there are upcoming events and the up next view should have been shown but
// the event list was open, then when it closes we should show the up next view.
TEST_F(
CalendarViewWithUpNextViewTest,
ShouldShowUpNextView_WhenEventListViewHasFinishedClosing_SelectedDateIsToday) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Open the event list view for today.
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[18]));
ASSERT_TRUE(event_list_view());
// Mock events that start in ten mins coming in.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
CloseEventList();
// After closing the event list view, we expect the up next view to now be
// shown.
bool is_showing_up_next_view = up_next_view();
EXPECT_TRUE(is_showing_up_next_view);
}
// If there are upcoming events and the event list was open for another day
// that's not on the same row with today, then when it closes we should not show
// the up next view.
TEST_F(
CalendarViewWithUpNextViewTest,
ShouldNotShowUpNextView_WhenEventListViewHasFinishedClosing_SelectedDateNotOnTheSameRowWithToday) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Open the event list view for a day that's not on the same row with today.
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[25]));
ASSERT_TRUE(event_list_view());
// Mock events that start in ten mins coming in.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
CloseEventList();
// After closing the event list view, we expect there's no up next view
// showing.
EXPECT_FALSE(up_next_view());
}
TEST_F(CalendarViewWithUpNextViewTest,
ShouldOpenEventListView_WhenUpNextShowTodaysEventsButtonPressed) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
bool is_showing_up_next_view = up_next_view();
EXPECT_TRUE(is_showing_up_next_view);
bool is_showing_event_list_view = event_list_view();
EXPECT_FALSE(is_showing_event_list_view);
LeftClickOn(up_next_todays_events_button());
is_showing_event_list_view = event_list_view();
EXPECT_TRUE(is_showing_event_list_view);
}
TEST_F(
CalendarViewWithUpNextViewTest,
GivenUpNextIsShown_WhenNewEventsMoreThanTwoHoursAwayAreFetched_UpNextViewShouldStillBeShown) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE((up_next_view() && up_next_view()->GetVisible()));
MockEventsFetched(
calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeMoreThanTwoHoursAway());
// When fetched events are now more than two hours away, the up next should
// still show.
EXPECT_TRUE((up_next_view() && up_next_view()->GetVisible()));
}
// Tests the following:
// - 2 upcoming events are displayed in the up next view
// - Time passes so that one event has ended
// - Up next refreshes to show the 1 upcoming event (as the other has now ended)
TEST_F(CalendarViewWithUpNextViewTest,
ShouldHideCompletedEventsInTheUpNextView) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithTwoEventsOneEndingInOneMin());
// Up next should be shown with the 2 events.
EXPECT_TRUE(up_next_view());
EXPECT_EQ(size_t(2), up_next_scroll_contents()->children().size());
// Move base::Time::Now to 1 minute past the event end time and force the
// upcoming events timer to fire.
base::Time time_one_min_past_event_end;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:02 GMT",
&time_one_min_past_event_end));
SetFakeNow(time_one_min_past_event_end);
run_upcoming_events_timer_task();
// Up next should still be showing but with a single event as the other has
// ended.
EXPECT_TRUE(up_next_view());
EXPECT_EQ(size_t(1), up_next_scroll_contents()->children().size());
}
TEST_F(CalendarViewWithUpNextViewTest,
ShouldClipHeightOfScrollView_WhenUpNextIsShown) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Expect the scrollview to have max int height when neither up next nor the
// event list view are showing.
EXPECT_EQ(INT_MAX, scroll_view()->GetMaxHeight());
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE(up_next_view());
// When up next is showing, the scrollview should be clipped to sit above but
// slightly overlapping the up next view bounds.
const int expected_max_height = scroll_view()->height() -
up_next_view()->GetPreferredSize().height() +
calendar_utils::kUpNextOverlapInPx;
EXPECT_EQ(expected_max_height, scroll_view()->GetMaxHeight());
}
TEST_F(
CalendarViewWithUpNextViewTest,
ShouldClipHeightOfScrollView_WhenEventListHasClosed_AndUpNextIsStillShown) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE(up_next_view());
// Open the event list view for today.
ASSERT_EQ(u"18",
static_cast<views::LabelButton*>(current_month()->children()[18])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[18]));
ASSERT_TRUE(event_list_view());
// Close the event list view.
GestureTapOn(close_button());
ASSERT_FALSE(event_list_view());
// When the event list view closes, the scrollview max height should have been
// clipped back to the right height for the up next view.
const int expected_max_height = scroll_view()->height() -
up_next_view()->GetPreferredSize().height() +
calendar_utils::kUpNextOverlapInPx;
EXPECT_EQ(expected_max_height, scroll_view()->GetMaxHeight());
}
TEST_F(CalendarViewWithUpNextViewTest,
ShouldShowUpNext_WhenEventListHasClosed_AndAnUpcomingEventJustCameIn) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(
calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeMoreThanTwoHoursAway());
EXPECT_TRUE(up_next_view());
// Open the event list view for today.
ASSERT_EQ(u"18",
static_cast<views::LabelButton*>(current_month()->children()[18])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[18]));
ASSERT_TRUE(event_list_view());
// Mock upcoming events coming in.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// Close the event list view.
GestureTapOn(close_button());
ASSERT_FALSE(event_list_view());
// Up next should be showing.
EXPECT_TRUE(up_next_view());
// When the event list view closes, the scrollview max height should have been
// clipped back to the right height for the up next view.
const int expected_max_height = scroll_view()->height() -
up_next_view()->GetPreferredSize().height() +
calendar_utils::kUpNextOverlapInPx;
EXPECT_EQ(expected_max_height, scroll_view()->GetMaxHeight());
}
// Tests the following:
// - 1 upcoming events are displayed in the up next view
// - Scroll down a couple of months
// - Up next view should be invisible after scrolling
// - Scroll back to today's month, and the up next view should remain invisible.
TEST_F(CalendarViewWithUpNextViewTest, ShouldNotShowUpNextView_AfterScrolling) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Mock upcoming events coming in.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// Up next view should be shown.
EXPECT_TRUE(up_next_view());
// Scroll down a couple of months so we're not on today's date or month any
// more.
ScrollDownOneMonthWithAnimation();
ScrollDownOneMonthWithAnimation();
EXPECT_EQ(u"December", GetPreviousLabelText());
EXPECT_EQ(u"January", GetCurrentLabelText());
EXPECT_EQ(u"February", GetNextLabelText());
EXPECT_EQ(u"March", GetNextNextLabelText());
EXPECT_EQ(u"January", month_header()->GetText());
EXPECT_EQ(u"2022", header_year()->GetText());
// `up_next_view()` still exists, just invisible.
EXPECT_FALSE(up_next_view()->GetVisible());
// Scroll up back to today's month, and `up_next_view()` should not be visible
// after scrolling.
ScrollUpOneMonthWithAnimation();
ScrollUpOneMonthWithAnimation();
EXPECT_EQ(u"November", GetCurrentLabelText());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
EXPECT_FALSE(up_next_view()->GetVisible());
}
// Tests the following:
// - 1 upcoming events are displayed in the up next view
// - Scroll down a couple of months
// - Up next view should be invisible after scrolling
// - Clicking the reset to today button
// - Up next view should be visible
TEST_F(CalendarViewWithUpNextViewTest,
ShouldShowUpNextView_AfterResettingToToday) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE(up_next_view());
// Scroll down a couple of months so we're not on today's date or month any
// more.
ScrollDownOneMonthWithAnimation();
ScrollDownOneMonthWithAnimation();
EXPECT_EQ(u"December", GetPreviousLabelText());
EXPECT_EQ(u"January", GetCurrentLabelText());
EXPECT_EQ(u"February", GetNextLabelText());
EXPECT_EQ(u"March", GetNextNextLabelText());
EXPECT_EQ(u"January", month_header()->GetText());
EXPECT_EQ(u"2022", header_year()->GetText());
// `up_next_view()` still exists, just invisible.
EXPECT_FALSE(up_next_view()->GetVisible());
// Clicks the reset to today button and `up_next_view()` should be visible.
GestureTapOn(reset_to_today_button());
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
EXPECT_TRUE(up_next_view()->GetVisible());
}
// Tests the following:
// - 1 upcoming events are displayed in the up next view
// - Open the event list view and scroll down
// - Close the event list view
// - Up next view should be invisible
TEST_F(CalendarViewWithUpNextViewTest,
ShouldNotShowUpNextView_WhenEventListHasClosedAfterScrolling) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE(up_next_view());
// Open the event list view.
ASSERT_EQ(u"25",
static_cast<views::LabelButton*>(current_month()->children()[25])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[25]));
ASSERT_TRUE(event_list_view());
// Scroll down one row with the event list open.
ScrollDownOneMonthWithAnimation();
EXPECT_EQ(u"October", GetPreviousLabelText());
EXPECT_EQ(u"November", GetCurrentLabelText());
EXPECT_EQ(u"December", GetNextLabelText());
EXPECT_EQ(u"January", GetNextNextLabelText());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
// Close the event list view.
GestureTapOn(close_button());
ASSERT_FALSE(event_list_view());
// `up_next_view()` still exists, just invisible.
EXPECT_FALSE(up_next_view()->GetVisible());
}
// Tests the following:
// - 1 upcoming events are displayed in the up next view
// - Open the event list view
// - Close the event list view
// - Up next view should be visible
TEST_F(CalendarViewWithUpNextViewTest,
ShouldShowUpNextView_WhenEventListHasClosedWithoutScrolling) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
EXPECT_TRUE(up_next_view());
// Open the event list view for today.
ASSERT_EQ(u"18",
static_cast<views::LabelButton*>(current_month()->children()[18])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[18]));
ASSERT_TRUE(event_list_view());
// Close the event list view.
GestureTapOn(close_button());
ASSERT_FALSE(event_list_view());
// `up_next_view()` should be visible.
EXPECT_TRUE(up_next_view()->GetVisible());
}
// Tests an upcoming event that starts at 00:05 but "now" is 23:55. In this case
// the up next view shouldn't be shown.
TEST_F(CalendarViewWithUpNextViewTest,
ShouldNotShowUpNextView_WhenNextEventStartsTomorrow) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 23:55 GMT", &date));
// Sets the timezone to GMT.
ash::system::ScopedTimezoneSettings timezone_settings(u"GMT");
// Sets time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Mock upcoming events coming in.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListStartingFivePastMidnight());
// Up next view should not be shown.
ASSERT_FALSE(up_next_view());
}
TEST_F(
CalendarViewWithUpNextViewTest,
ShouldFocusEventListCloseButton_WhenEventListViewLaunchedFromUpNextView) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
ASSERT_TRUE(up_next_view());
auto* focus_manager = calendar_view()->GetFocusManager();
up_next_todays_events_button()->RequestFocus();
ASSERT_EQ(up_next_todays_events_button(), focus_manager->GetFocusedView());
PressEnter();
ASSERT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
}
TEST_F(CalendarViewWithUpNextViewTest,
ShouldFocusEventListCloseButton_WhenFocusMovedFromTodayButton) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// When fetched events are in the next 10 mins, then up next should have been
// created.
ASSERT_TRUE(up_next_view());
auto* focus_manager = calendar_view()->GetFocusManager();
reset_to_today_button()->RequestFocus();
ASSERT_EQ(reset_to_today_button(), focus_manager->GetFocusedView());
GestureTapOn(up_next_todays_events_button());
ASSERT_TRUE(event_list_view());
EXPECT_EQ(focus_manager->GetFocusedView(), close_button());
}
TEST_F(CalendarViewWithUpNextViewTest, RecordEventsDisplayedToUserOnce) {
base::HistogramTester histogram_tester;
base::Time now;
ASSERT_TRUE(base::Time::FromString("1 Oct 2021 10:00 GMT", &now));
base::Time next_month;
ASSERT_TRUE(base::Time::FromString("1 Nov 2021 10:00 GMT", &next_month));
// Set time override.
SetFakeNow(now);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
CreateCalendarView();
// Mock events will be in the `next_month` so when the calendar opens we don't
// record the metric.
MockEventsFetched(
calendar_utils::GetStartOfMonthUTC(next_month),
CreateMockEventListWithEventStartTimeMoreThanTwoHoursAway());
// Make sure we're on the current month and no events have been displayed to
// the user.
EXPECT_EQ(u"October", GetCurrentLabelText());
EXPECT_EQ(u"October", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
histogram_tester.ExpectTotalCount("Ash.Calendar.EventsDisplayedToUser", 0);
// Scroll down a month, this month should contain events.
ScrollDownOneMonth();
EXPECT_EQ(u"November", GetCurrentLabelText());
EXPECT_EQ(u"November", month_header()->GetText());
EXPECT_EQ(u"2021", header_year()->GetText());
histogram_tester.ExpectTotalCount("Ash.Calendar.EventsDisplayedToUser", 1);
// Scroll back and forward to land on the month containing events again.
ScrollDownOneMonth();
ScrollUpOneMonth();
// We should still have only logged the metric once.
histogram_tester.ExpectTotalCount("Ash.Calendar.EventsDisplayedToUser", 1);
}
TEST_F(CalendarViewWithUpNextViewTest, ShouldShowUpNextWithCachedData) {
base::Time date;
ASSERT_TRUE(base::Time::FromString("18 Nov 2021 10:00 GMT", &date));
// Set time override.
SetFakeNow(date);
base::subtle::ScopedTimeClockOverrides time_override(
&CalendarViewTest::FakeTimeNow, /*time_ticks_override=*/nullptr,
/*thread_ticks_override=*/nullptr);
// Build the Calendar view.
CreateCalendarView();
// Populate model with events.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithEventStartTimeTenMinsAway());
// Up next should be displayed (with cached events).
EXPECT_TRUE(up_next_view());
EXPECT_EQ(size_t(1), up_next_scroll_contents()->children().size());
// Replace the cached data with new data.
Shell::Get()->system_tray_model()->calendar_model()->ClearAllCachedEvents();
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateMockEventListWithTwoEventsOneEndingInOneMin());
EXPECT_TRUE(up_next_view());
EXPECT_EQ(size_t(2), up_next_scroll_contents()->children().size());
}
class CalendarViewWithUpNextViewAnimationTest
: public CalendarViewAnimationTest {
public:
CalendarViewWithUpNextViewAnimationTest() = default;
CalendarViewWithUpNextViewAnimationTest(
const CalendarViewWithUpNextViewAnimationTest&) = delete;
CalendarViewWithUpNextViewAnimationTest& operator=(
const CalendarViewWithUpNextViewAnimationTest&) = delete;
~CalendarViewWithUpNextViewAnimationTest() override = default;
std::unique_ptr<google_apis::calendar::EventList> CreateUpcomingEvents(
base::Time date) {
const auto start_time = date + base::Minutes(5);
const auto end_time = start_time + base::Hours(1);
auto event_list = std::make_unique<google_apis::calendar::EventList>();
event_list->set_time_zone("Greenwich Mean Time");
event_list->InjectItemForTesting(calendar_test_utils::CreateEvent(
"id_0", "summary_0", start_time, end_time));
return event_list;
}
void MockEventsFetched(
base::Time date,
std::unique_ptr<google_apis::calendar::EventList> event_list) {
Shell::Get()->system_tray_model()->calendar_model()->OnEventsFetched(
calendar_utils::GetStartOfMonthUTC(date),
google_apis::calendar::kPrimaryCalendarId,
google_apis::ApiErrorCode::HTTP_SUCCESS, event_list.get());
}
void MockOnCalendarListFetched() {
std::list<std::unique_ptr<google_apis::calendar::SingleCalendar>> calendars;
calendars.push_back(calendar_test_utils::CreateCalendar(
kCalendarId1, kCalendarSummary1, kCalendarColorId1, kCalendarSelected1,
kCalendarPrimary1));
std::unique_ptr<google_apis::calendar::CalendarList> calendar_list =
calendar_test_utils::CreateMockCalendarList(std::move(calendars));
Shell::Get()
->system_tray_model()
->calendar_list_model()
->OnCalendarListFetched(google_apis::ApiErrorCode::HTTP_SUCCESS,
std::move(calendar_list));
}
};
INSTANTIATE_TEST_SUITE_P(MultiCalendar,
CalendarViewWithUpNextViewAnimationTest,
testing::Bool());
TEST_P(CalendarViewWithUpNextViewAnimationTest,
UpNextViewShouldNotCoversToday) {
auto histogram_tester = std::make_unique<base::HistogramTester>();
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date towards the end of the month so it's initial position is not on
// the top when it's created.
ASSERT_TRUE(base::Time::FromString("25 Apr 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
CreateCalendarView();
// Force the size of the calendar to be small enough that the bottom row of
// date cells will be covered by the up next view.
widget()->SetFullscreen(false);
widget()->SetSize(gfx::Size(kTrayMenuWidth, 350));
const int initial_scroll_position = scroll_view()->GetVisibleRect().y();
EXPECT_EQ(initial_scroll_position, GetPositionOfToday());
// Today should be visible.
bool todays_date_cell_is_visible =
scroll_view()->GetBoundsInScreen().Intersects(
calendar_view()
->calendar_view_controller()
->todays_date_cell_view()
->GetBoundsInScreen());
EXPECT_TRUE(todays_date_cell_is_visible);
// Fetch an upcoming event so up next is displayed.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date));
// Wait for the show up next animation and smooth scrolling to complete.
EXPECT_TRUE(calendar_view()->up_next_view());
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(calendar_view()->up_next_view()->layer());
animation_waiter.Wait(current_month()->layer());
// After the up next view is shown, the scroll view should not have moved.
EXPECT_EQ(initial_scroll_position, scroll_view()->GetVisibleRect().y());
todays_date_cell_is_visible = scroll_view()->GetBoundsInScreen().Intersects(
calendar_view()
->calendar_view_controller()
->todays_date_cell_view()
->GetBoundsInScreen());
EXPECT_TRUE(todays_date_cell_is_visible);
}
TEST_P(CalendarViewWithUpNextViewAnimationTest,
ShouldNotScrollToShowTodaysCell_WhenUpNextViewDoesNotCoverIt) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date at the start of the month so up next doesn't cover it.
ASSERT_TRUE(base::Time::FromString("1 Apr 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
CreateCalendarView();
// Force the size of the calendar to be small enough that the bottom row of
// date cells will be covered by the up next view.
widget()->SetFullscreen(false);
widget()->SetSize(gfx::Size(kTrayMenuWidth, 350));
const int initial_scroll_position = scroll_view()->GetVisibleRect().y();
// Fetch an upcoming event so up next is displayed.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date));
// Wait for the show up next animation to complete.
EXPECT_TRUE(calendar_view()->up_next_view());
ui::LayerAnimationStoppedWaiter().Wait(
calendar_view()->up_next_view()->layer());
// After the up next view is shown, the scroll view should not have moved as
// the today date cell should remain visible.
EXPECT_EQ(initial_scroll_position, scroll_view()->GetVisibleRect().y());
const bool todays_date_cell_is_visible =
scroll_view()->GetBoundsInScreen().Intersects(
calendar_view()
->calendar_view_controller()
->todays_date_cell_view()
->GetBoundsInScreen());
EXPECT_TRUE(todays_date_cell_is_visible);
}
TEST_P(
CalendarViewWithUpNextViewAnimationTest,
ShouldNotScrollToShowTodaysCell_WhenUserHasScrolled_AndAnUpcomingEventAppears) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date towards the end of the month so up next covers the bottom row.
ASSERT_TRUE(base::Time::FromString("25 Apr 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
CreateCalendarView();
// Force the size of the calendar to be small enough that the bottom row of
// date cells will be covered by the up next view.
widget()->SetFullscreen(false);
widget()->SetSize(gfx::Size(kTrayMenuWidth, 350));
if (IsMultiCalendarEnabled()) {
MockOnCalendarListFetched();
WaitUntilFetched();
}
// Fetch an event that starts in 11 mins and up next will show.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date + base::Minutes(6)));
WaitUntilFetched();
EXPECT_TRUE(calendar_view()->up_next_view()->GetVisible());
// Scroll up a bit so that today is off the screen.
ScrollUpOneMonth();
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(current_month()->layer());
const int initial_scroll_position = scroll_view()->GetVisibleRect().y();
// Now advance time so that our upcoming meeting is about to start and up next
// should be invisible since the user has scrolled.
task_environment()->FastForwardBy(base::Minutes(5));
EXPECT_FALSE(calendar_view()->up_next_view()->GetVisible());
// The scroll view should not have moved as the user has previously interacted
// with the scroll view.
EXPECT_EQ(initial_scroll_position, scroll_view()->GetVisibleRect().y());
}
TEST_P(CalendarViewWithUpNextViewAnimationTest,
ShouldNotScroll_WhenAnUpcomingEventAppears) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date towards the end of the month so up next covers the bottom row.
ASSERT_TRUE(base::Time::FromString("25 Apr 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
CreateCalendarView();
// Force the size of the calendar to be small enough that the bottom row of
// date cells will be covered by the up next view.
widget()->SetFullscreen(false);
widget()->SetSize(gfx::Size(kTrayMenuWidth, 350));
// Fetch an event that starts in 11 mins and up next will show.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date + base::Minutes(6)));
EXPECT_TRUE(calendar_view()->up_next_view());
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(current_month()->layer());
const int initial_scroll_position = scroll_view()->GetVisibleRect().y();
// The initial position show be the position of today's row.
EXPECT_EQ(initial_scroll_position, GetPositionOfToday());
// Now advance time so that our upcoming meeting is about to start and up next
// should not appear since the user has scrolled.
task_environment()->FastForwardBy(base::Minutes(5));
EXPECT_TRUE(calendar_view()->up_next_view());
animation_waiter.Wait(calendar_view()->up_next_view()->layer());
// The scroll view should have not moved to show the `up_next_view_`.
EXPECT_EQ(initial_scroll_position, scroll_view()->GetVisibleRect().y());
}
TEST_P(CalendarViewWithUpNextViewAnimationTest,
ShouldNotScrollToShowTodaysCell_WhenTodaysDateCellIsNull) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date towards the end of the month.
ASSERT_TRUE(base::Time::FromString("25 Apr 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
CreateCalendarView();
// Force the size of the calendar to be small enough that the bottom row of
// date cells will be covered by the up next view.
widget()->SetFullscreen(false);
widget()->SetSize(gfx::Size(kTrayMenuWidth, 350));
if (IsMultiCalendarEnabled()) {
MockOnCalendarListFetched();
WaitUntilFetched();
}
// Fetch an event that starts in 11 mins and up next view will be shown.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date + base::Minutes(6)));
WaitUntilFetched();
EXPECT_TRUE(calendar_view()->up_next_view()->GetVisible());
// Scrolls 4 months so that todays date cell is null.
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
ScrollUpOneMonth();
EXPECT_EQ(
calendar_view()->calendar_view_controller()->todays_date_cell_view(),
nullptr);
const int initial_scroll_position = scroll_view()->GetVisibleRect().y();
// Now advance time so that our upcoming meeting is about to start and up next
// shouldn't show since the user has scrolled, and the scroll view should not
// have moved as well.
task_environment()->FastForwardBy(base::Minutes(5));
EXPECT_FALSE(calendar_view()->up_next_view()->GetVisible());
EXPECT_EQ(initial_scroll_position, scroll_view()->GetVisibleRect().y());
}
// Tests that the scroll view scrolls up to today's row without the up-next
// view.
TEST_P(CalendarViewWithUpNextViewAnimationTest,
ShouldScrollToToday_WithoutUpNextView) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date towards the end of the month so that it need to scroll up to
// today's row.
ASSERT_TRUE(base::Time::FromString("30 Nov 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
SetTodayFromTime(date);
CreateCalendarView();
// After the view is settled, it should scroll to today's row.
EXPECT_EQ(GetPositionOfToday(), scroll_view()->GetVisibleRect().y());
}
// Tests that the scroll view scrolls up to today's row with the up-next view.
TEST_P(CalendarViewWithUpNextViewAnimationTest,
ShouldScrollToToday_WithUpNextView) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
// Pick a date towards the end of the month so that it need to scroll up to
// today's row.
ASSERT_TRUE(base::Time::FromString("30 Nov 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
SetTodayFromTime(date);
CreateCalendarView();
// Fetch an event that starts in 6 mins and up next will show.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date + base::Minutes(6)));
EXPECT_TRUE(calendar_view()->up_next_view());
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(current_month()->layer());
animation_waiter.Wait(calendar_view()->up_next_view()->layer());
// After the view is settled, it should scroll to today's row.
EXPECT_EQ(GetPositionOfToday(), scroll_view()->GetVisibleRect().y());
}
// Tests that the up-next view can show up after showing the event listview
// first. Regression test for b/336722659.
TEST_P(CalendarViewWithUpNextViewAnimationTest,
ShowUpNextViewAfterEventListViewCorrectly) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
base::Time date;
ASSERT_TRUE(base::Time::FromString("30 Nov 2023 10:00 GMT", &date));
task_environment()->AdvanceClock(date - base::Time::Now());
SetTodayFromTime(date);
CreateCalendarView();
ui::LayerAnimationStoppedWaiter animation_waiter;
animation_waiter.Wait(current_month()->layer());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// There's no `up_next_view()` before the events are fetched.
EXPECT_FALSE(calendar_view()->up_next_view());
// Open the event list view for today.
ASSERT_EQ(u"30",
static_cast<views::LabelButton*>(current_month()->children()[32])
->GetText());
GestureTapOn(
static_cast<views::LabelButton*>(current_month()->children()[32]));
animation_waiter.Wait(calendar_sliding_surface_view()->layer());
animation_waiter.Wait(current_label()->layer());
ASSERT_TRUE(event_list_view());
EXPECT_TRUE(event_list_view()->GetVisible());
task_environment()->FastForwardBy(
calendar_test_utils::kAnimationSettleDownDuration);
// Fetch an event that starts in 6 mins.
MockEventsFetched(calendar_utils::GetStartOfMonthUTC(date),
CreateUpcomingEvents(date + base::Minutes(6)));
EXPECT_FALSE(calendar_view()->up_next_view());
// Close the event list view.
CloseEventList();
animation_waiter.Wait(calendar_sliding_surface_view()->layer());
animation_waiter.Wait(current_label()->layer());
EXPECT_FALSE(event_list_view());
// `up_next_view()` should be visible.
EXPECT_TRUE(calendar_view()->up_next_view()->GetVisible());
}
} // namespace ash
|