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
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/compositor_frame_metadata.h"
#include "cc/output/copy_output_request.h"
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_manager.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/compositor/resize_lock.h"
#include "content/browser/compositor/test/no_transport_image_transport_factory.h"
#include "content/browser/frame_host/render_widget_host_view_guest.h"
#include "content/browser/renderer_host/input/web_input_event_util.h"
#include "content/browser/renderer_host/overscroll_controller.h"
#include "content/browser/renderer_host/overscroll_controller_delegate.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/gpu/client/gl_helper.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/host_shared_bitmap_manager.h"
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "ipc/ipc_test_sink.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/test/aura_test_helper.h"
#include "ui/aura/test/test_cursor_client.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_observer.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/keycodes/dom3/dom_code.h"
#include "ui/events/keycodes/dom4/keycode_converter.h"
#include "ui/events/test/event_generator.h"
#include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/default_screen_position_client.h"
#include "ui/wm/core/window_util.h"
using testing::_;
using blink::WebGestureEvent;
using blink::WebInputEvent;
using blink::WebMouseEvent;
using blink::WebMouseWheelEvent;
using blink::WebTouchEvent;
using blink::WebTouchPoint;
namespace content {
namespace {
class TestOverscrollDelegate : public OverscrollControllerDelegate {
public:
explicit TestOverscrollDelegate(RenderWidgetHostView* view)
: view_(view),
current_mode_(OVERSCROLL_NONE),
completed_mode_(OVERSCROLL_NONE),
delta_x_(0.f),
delta_y_(0.f) {}
~TestOverscrollDelegate() override {}
OverscrollMode current_mode() const { return current_mode_; }
OverscrollMode completed_mode() const { return completed_mode_; }
float delta_x() const { return delta_x_; }
float delta_y() const { return delta_y_; }
void Reset() {
current_mode_ = OVERSCROLL_NONE;
completed_mode_ = OVERSCROLL_NONE;
delta_x_ = delta_y_ = 0.f;
}
private:
// Overridden from OverscrollControllerDelegate:
gfx::Rect GetVisibleBounds() const override {
return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect();
}
bool OnOverscrollUpdate(float delta_x, float delta_y) override {
delta_x_ = delta_x;
delta_y_ = delta_y;
return true;
}
void OnOverscrollComplete(OverscrollMode overscroll_mode) override {
EXPECT_EQ(current_mode_, overscroll_mode);
completed_mode_ = overscroll_mode;
current_mode_ = OVERSCROLL_NONE;
}
void OnOverscrollModeChange(OverscrollMode old_mode,
OverscrollMode new_mode) override {
EXPECT_EQ(current_mode_, old_mode);
current_mode_ = new_mode;
delta_x_ = delta_y_ = 0.f;
}
RenderWidgetHostView* view_;
OverscrollMode current_mode_;
OverscrollMode completed_mode_;
float delta_x_;
float delta_y_;
DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate);
};
class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
public:
MockRenderWidgetHostDelegate() {}
~MockRenderWidgetHostDelegate() override {}
const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); }
protected:
// RenderWidgetHostDelegate:
bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) override {
last_event_.reset(new NativeWebKeyboardEvent(event));
return true;
}
private:
scoped_ptr<NativeWebKeyboardEvent> last_event_;
DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate);
};
// Simple observer that keeps track of changes to a window for tests.
class TestWindowObserver : public aura::WindowObserver {
public:
explicit TestWindowObserver(aura::Window* window_to_observe)
: window_(window_to_observe) {
window_->AddObserver(this);
}
~TestWindowObserver() override {
if (window_)
window_->RemoveObserver(this);
}
bool destroyed() const { return destroyed_; }
// aura::WindowObserver overrides:
void OnWindowDestroyed(aura::Window* window) override {
CHECK_EQ(window, window_);
destroyed_ = true;
window_ = NULL;
}
private:
// Window that we're observing, or NULL if it's been destroyed.
aura::Window* window_;
// Was |window_| destroyed?
bool destroyed_;
DISALLOW_COPY_AND_ASSIGN(TestWindowObserver);
};
class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber {
public:
FakeFrameSubscriber(gfx::Size size, base::Callback<void(bool)> callback)
: size_(size), callback_(callback) {}
bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
base::TimeTicks present_time,
scoped_refptr<media::VideoFrame>* storage,
DeliverFrameCallback* callback) override {
*storage = media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
size_,
gfx::Rect(size_),
size_,
base::TimeDelta());
*callback = base::Bind(&FakeFrameSubscriber::CallbackMethod, callback_);
return true;
}
static void CallbackMethod(base::Callback<void(bool)> callback,
base::TimeTicks timestamp,
bool success) {
callback.Run(success);
}
private:
gfx::Size size_;
base::Callback<void(bool)> callback_;
};
class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
public:
FakeRenderWidgetHostViewAura(RenderWidgetHost* widget,
bool is_guest_view_hack)
: RenderWidgetHostViewAura(widget, is_guest_view_hack),
has_resize_lock_(false) {}
~FakeRenderWidgetHostViewAura() override {}
scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) override {
gfx::Size desired_size = window()->bounds().size();
return scoped_ptr<ResizeLock>(
new FakeResizeLock(desired_size, defer_compositor_lock));
}
void RunOnCompositingDidCommit() {
GetDelegatedFrameHost()->OnCompositingDidCommitForTesting(
window()->GetHost()->compositor());
}
bool ShouldCreateResizeLock() override {
return GetDelegatedFrameHost()->ShouldCreateResizeLockForTesting();
}
void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request) override {
last_copy_request_ = request.Pass();
if (last_copy_request_->has_texture_mailbox()) {
// Give the resulting texture a size.
GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
GLuint texture = gl_helper->ConsumeMailboxToTexture(
last_copy_request_->texture_mailbox().mailbox(),
last_copy_request_->texture_mailbox().sync_point());
gl_helper->ResizeTexture(texture, window()->bounds().size());
gl_helper->DeleteTexture(texture);
}
}
cc::DelegatedFrameProvider* frame_provider() const {
return GetDelegatedFrameHost()->FrameProviderForTesting();
}
cc::SurfaceId surface_id() const {
return GetDelegatedFrameHost()->SurfaceIdForTesting();
}
bool HasFrameData() const {
return frame_provider() || !surface_id().is_null();
}
bool released_front_lock_active() const {
return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
}
// A lock that doesn't actually do anything to the compositor, and does not
// time out.
class FakeResizeLock : public ResizeLock {
public:
FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
: ResizeLock(new_size, defer_compositor_lock) {}
};
void OnTouchEvent(ui::TouchEvent* event) override {
RenderWidgetHostViewAura::OnTouchEvent(event);
if (pointer_state().GetPointerCount() > 0) {
touch_event_.reset(
new blink::WebTouchEvent(CreateWebTouchEventFromMotionEvent(
pointer_state(), event->may_cause_scrolling())));
} else {
// Never create a WebTouchEvent with 0 touch points.
touch_event_.reset();
}
}
bool has_resize_lock_;
gfx::Size last_frame_size_;
scoped_ptr<cc::CopyOutputRequest> last_copy_request_;
// null if there are 0 active touch points.
scoped_ptr<blink::WebTouchEvent> touch_event_;
};
// A layout manager that always resizes a child to the root window size.
class FullscreenLayoutManager : public aura::LayoutManager {
public:
explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {}
~FullscreenLayoutManager() override {}
// Overridden from aura::LayoutManager:
void OnWindowResized() override {
aura::Window::Windows::const_iterator i;
for (i = owner_->children().begin(); i != owner_->children().end(); ++i) {
(*i)->SetBounds(gfx::Rect());
}
}
void OnWindowAddedToLayout(aura::Window* child) override {
child->SetBounds(gfx::Rect());
}
void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
void OnWindowRemovedFromLayout(aura::Window* child) override {}
void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) override {}
void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) override {
SetChildBoundsDirect(child, gfx::Rect(owner_->bounds().size()));
}
private:
aura::Window* owner_;
DISALLOW_COPY_AND_ASSIGN(FullscreenLayoutManager);
};
class MockWindowObserver : public aura::WindowObserver {
public:
MOCK_METHOD2(OnDelegatedFrameDamage, void(aura::Window*, const gfx::Rect&));
};
} // namespace
class RenderWidgetHostViewAuraTest : public testing::Test {
public:
RenderWidgetHostViewAuraTest()
: widget_host_uses_shutdown_to_destroy_(false),
is_guest_view_hack_(false),
browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
void SetUpEnvironment() {
ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ImageTransportFactory>(
new NoTransportImageTransportFactory));
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp(
ImageTransportFactory::GetInstance()->GetContextFactory());
new wm::DefaultActivationClient(aura_test_helper_->root_window());
browser_context_.reset(new TestBrowserContext);
process_host_ = new MockRenderProcessHost(browser_context_.get());
sink_ = &process_host_->sink();
parent_host_ = new RenderWidgetHostImpl(
&delegate_, process_host_, MSG_ROUTING_NONE, false);
parent_view_ = new RenderWidgetHostViewAura(parent_host_,
is_guest_view_hack_);
parent_view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
aura_test_helper_->root_window(),
gfx::Rect());
widget_host_ = new RenderWidgetHostImpl(
&delegate_, process_host_, MSG_ROUTING_NONE, false);
widget_host_->Init();
view_ = new FakeRenderWidgetHostViewAura(widget_host_, is_guest_view_hack_);
}
void TearDownEnvironment() {
sink_ = NULL;
process_host_ = NULL;
if (view_)
view_->Destroy();
if (widget_host_uses_shutdown_to_destroy_)
widget_host_->Shutdown();
else
delete widget_host_;
parent_view_->Destroy();
delete parent_host_;
browser_context_.reset();
aura_test_helper_->TearDown();
message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
message_loop_.RunUntilIdle();
ImageTransportFactory::Terminate();
}
void SetUp() override { SetUpEnvironment(); }
void TearDown() override { TearDownEnvironment(); }
void set_widget_host_uses_shutdown_to_destroy(bool use) {
widget_host_uses_shutdown_to_destroy_ = use;
}
void SimulateMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) {
// Here should be base::MemoryPressureListener::NotifyMemoryPressure, but
// since the RendererFrameManager is installing a MemoryPressureListener
// which uses ObserverListThreadSafe, which furthermore remembers the
// message loop for the thread it was created in. Between tests, the
// RendererFrameManager singleton survives and and the MessageLoop gets
// destroyed. The correct fix would be to have ObserverListThreadSafe look
// up the proper message loop every time (see crbug.com/443824.)
RendererFrameManager::GetInstance()->OnMemoryPressure(level);
}
protected:
// If true, then calls RWH::Shutdown() instead of deleting RWH.
bool widget_host_uses_shutdown_to_destroy_;
bool is_guest_view_hack_;
base::MessageLoopForUI message_loop_;
BrowserThreadImpl browser_thread_for_ui_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<BrowserContext> browser_context_;
MockRenderWidgetHostDelegate delegate_;
MockRenderProcessHost* process_host_;
// Tests should set these to NULL if they've already triggered their
// destruction.
RenderWidgetHostImpl* parent_host_;
RenderWidgetHostViewAura* parent_view_;
// Tests should set these to NULL if they've already triggered their
// destruction.
RenderWidgetHostImpl* widget_host_;
FakeRenderWidgetHostViewAura* view_;
IPC::TestSink* sink_;
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest);
};
// Helper class to instantiate RenderWidgetHostViewGuest which is backed
// by an aura platform view.
class RenderWidgetHostViewGuestAuraTest : public RenderWidgetHostViewAuraTest {
public:
RenderWidgetHostViewGuestAuraTest() {
// Use RWH::Shutdown to destroy RWH, instead of deleting.
// This will ensure that the RenderWidgetHostViewGuest is not leaked and
// is deleted properly upon RWH going away.
set_widget_host_uses_shutdown_to_destroy(true);
}
// We explicitly invoke SetUp to allow gesture debounce customization.
void SetUp() override {
is_guest_view_hack_ = true;
RenderWidgetHostViewAuraTest::SetUp();
guest_view_weak_ = (new RenderWidgetHostViewGuest(
widget_host_, NULL, view_->GetWeakPtr()))->GetWeakPtr();
}
void TearDown() override {
// Internal override to do nothing, we clean up ourselves in the test body.
// This helps us test that |guest_view_weak_| does not leak.
}
protected:
base::WeakPtr<RenderWidgetHostViewBase> guest_view_weak_;
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestAuraTest);
};
class RenderWidgetHostViewAuraOverscrollTest
: public RenderWidgetHostViewAuraTest {
public:
RenderWidgetHostViewAuraOverscrollTest() {}
// We explicitly invoke SetUp to allow gesture debounce customization.
void SetUp() override {}
protected:
void SetUpOverscrollEnvironmentWithDebounce(int debounce_interval_in_ms) {
SetUpOverscrollEnvironmentImpl(debounce_interval_in_ms);
}
void SetUpOverscrollEnvironment() { SetUpOverscrollEnvironmentImpl(0); }
void SetUpOverscrollEnvironmentImpl(int debounce_interval_in_ms) {
ui::GestureConfiguration::GetInstance()->set_scroll_debounce_interval_in_ms(
debounce_interval_in_ms);
RenderWidgetHostViewAuraTest::SetUp();
view_->SetOverscrollControllerEnabled(true);
overscroll_delegate_.reset(new TestOverscrollDelegate(view_));
view_->overscroll_controller()->set_delegate(overscroll_delegate_.get());
view_->InitAsChild(NULL);
view_->SetBounds(gfx::Rect(0, 0, 400, 200));
view_->Show();
sink_->ClearMessages();
}
// TODO(jdduke): Simulate ui::Events, injecting through the view.
void SimulateMouseEvent(WebInputEvent::Type type) {
widget_host_->ForwardMouseEvent(SyntheticWebMouseEventBuilder::Build(type));
}
void SimulateMouseEventWithLatencyInfo(WebInputEvent::Type type,
const ui::LatencyInfo& ui_latency) {
widget_host_->ForwardMouseEventWithLatencyInfo(
SyntheticWebMouseEventBuilder::Build(type), ui_latency);
}
void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) {
widget_host_->ForwardWheelEvent(
SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise));
}
void SimulateWheelEventWithLatencyInfo(float dX,
float dY,
int modifiers,
bool precise,
const ui::LatencyInfo& ui_latency) {
widget_host_->ForwardWheelEventWithLatencyInfo(
SyntheticWebMouseWheelEventBuilder::Build(dX, dY, modifiers, precise),
ui_latency);
}
void SimulateMouseMove(int x, int y, int modifiers) {
SimulateMouseEvent(WebInputEvent::MouseMove, x, y, modifiers, false);
}
void SimulateMouseEvent(WebInputEvent::Type type,
int x,
int y,
int modifiers,
bool pressed) {
WebMouseEvent event =
SyntheticWebMouseEventBuilder::Build(type, x, y, modifiers);
if (pressed)
event.button = WebMouseEvent::ButtonLeft;
widget_host_->ForwardMouseEvent(event);
}
void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) {
widget_host_->ForwardWheelEvent(
SyntheticWebMouseWheelEventBuilder::Build(phase));
}
// Inject provided synthetic WebGestureEvent instance.
void SimulateGestureEventCore(const WebGestureEvent& gesture_event) {
widget_host_->ForwardGestureEvent(gesture_event);
}
void SimulateGestureEventCoreWithLatencyInfo(
const WebGestureEvent& gesture_event,
const ui::LatencyInfo& ui_latency) {
widget_host_->ForwardGestureEventWithLatencyInfo(gesture_event, ui_latency);
}
// Inject simple synthetic WebGestureEvent instances.
void SimulateGestureEvent(WebInputEvent::Type type,
blink::WebGestureDevice sourceDevice) {
SimulateGestureEventCore(
SyntheticWebGestureEventBuilder::Build(type, sourceDevice));
}
void SimulateGestureEventWithLatencyInfo(WebInputEvent::Type type,
blink::WebGestureDevice sourceDevice,
const ui::LatencyInfo& ui_latency) {
SimulateGestureEventCoreWithLatencyInfo(
SyntheticWebGestureEventBuilder::Build(type, sourceDevice), ui_latency);
}
void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildScrollUpdate(
dX, dY, modifiers, blink::WebGestureDeviceTouchscreen));
}
void SimulateGesturePinchUpdateEvent(float scale,
float anchorX,
float anchorY,
int modifiers) {
SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildPinchUpdate(
scale,
anchorX,
anchorY,
modifiers,
blink::WebGestureDeviceTouchscreen));
}
// Inject synthetic GestureFlingStart events.
void SimulateGestureFlingStartEvent(float velocityX,
float velocityY,
blink::WebGestureDevice sourceDevice) {
SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling(
velocityX, velocityY, sourceDevice));
}
void SendInputEventACK(WebInputEvent::Type type,
InputEventAckState ack_result) {
InputHostMsg_HandleInputEvent_ACK_Params ack;
ack.type = type;
ack.state = ack_result;
InputHostMsg_HandleInputEvent_ACK response(0, ack);
widget_host_->OnMessageReceived(response);
}
bool ScrollStateIsContentScrolling() const {
return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING;
}
bool ScrollStateIsOverscrolling() const {
return scroll_state() == OverscrollController::STATE_OVERSCROLLING;
}
bool ScrollStateIsUnknown() const {
return scroll_state() == OverscrollController::STATE_UNKNOWN;
}
OverscrollController::ScrollState scroll_state() const {
return view_->overscroll_controller()->scroll_state_;
}
OverscrollMode overscroll_mode() const {
return view_->overscroll_controller()->overscroll_mode_;
}
float overscroll_delta_x() const {
return view_->overscroll_controller()->overscroll_delta_x_;
}
float overscroll_delta_y() const {
return view_->overscroll_controller()->overscroll_delta_y_;
}
TestOverscrollDelegate* overscroll_delegate() {
return overscroll_delegate_.get();
}
void SendTouchEvent() {
widget_host_->ForwardTouchEventWithLatencyInfo(touch_event_,
ui::LatencyInfo());
touch_event_.ResetPoints();
}
void PressTouchPoint(int x, int y) {
touch_event_.PressPoint(x, y);
SendTouchEvent();
}
void MoveTouchPoint(int index, int x, int y) {
touch_event_.MovePoint(index, x, y);
SendTouchEvent();
}
void ReleaseTouchPoint(int index) {
touch_event_.ReleasePoint(index);
SendTouchEvent();
}
size_t GetSentMessageCountAndResetSink() {
size_t count = sink_->message_count();
sink_->ClearMessages();
return count;
}
void AckLastSentInputEventIfNecessary(InputEventAckState ack_result) {
if (!sink_->message_count())
return;
InputMsg_HandleInputEvent::Param params;
if (!InputMsg_HandleInputEvent::Read(
sink_->GetMessageAt(sink_->message_count() - 1), ¶ms)) {
return;
}
if (WebInputEventTraits::IgnoresAckDisposition(*get<0>(params)))
return;
SendInputEventACK(get<0>(params)->type, ack_result);
}
SyntheticWebTouchEvent touch_event_;
scoped_ptr<TestOverscrollDelegate> overscroll_delegate_;
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraOverscrollTest);
};
class RenderWidgetHostViewAuraShutdownTest
: public RenderWidgetHostViewAuraTest {
public:
RenderWidgetHostViewAuraShutdownTest() {}
void TearDown() override {
// No TearDownEnvironment here, we do this explicitly during the test.
}
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraShutdownTest);
};
// Checks that a fullscreen view has the correct show-state and receives the
// focus.
TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) {
view_->InitAsFullscreen(parent_view_);
aura::Window* window = view_->GetNativeView();
ASSERT_TRUE(window != NULL);
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN,
window->GetProperty(aura::client::kShowStateKey));
// Check that we requested and received the focus.
EXPECT_TRUE(window->HasFocus());
// Check that we'll also say it's okay to activate the window when there's an
// ActivationClient defined.
EXPECT_TRUE(view_->ShouldActivate());
}
// Checks that a popup is positioned correctly relative to its parent using
// screen coordinates.
TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
wm::DefaultScreenPositionClient screen_position_client;
aura::Window* window = parent_view_->GetNativeView();
aura::Window* root = window->GetRootWindow();
aura::client::SetScreenPositionClient(root, &screen_position_client);
parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
int horiz = bounds_in_screen.width() / 4;
int vert = bounds_in_screen.height() / 4;
bounds_in_screen.Inset(horiz, vert);
// Verify that when the popup is initialized for the first time, it correctly
// treats the input bounds as screen coordinates.
view_->InitAsPopup(parent_view_, bounds_in_screen);
gfx::Rect final_bounds_in_screen = view_->GetViewBounds();
EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString());
// Verify that directly setting the bounds via SetBounds() treats the input
// as screen coordinates.
bounds_in_screen = gfx::Rect(60, 60, 100, 100);
view_->SetBounds(bounds_in_screen);
final_bounds_in_screen = view_->GetViewBounds();
EXPECT_EQ(final_bounds_in_screen.ToString(), bounds_in_screen.ToString());
// Verify that setting the size does not alter the origin.
gfx::Point original_origin = window->bounds().origin();
view_->SetSize(gfx::Size(120, 120));
gfx::Point new_origin = window->bounds().origin();
EXPECT_EQ(original_origin.ToString(), new_origin.ToString());
aura::client::SetScreenPositionClient(root, NULL);
}
// Checks that a fullscreen view is destroyed when it loses the focus.
TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) {
view_->InitAsFullscreen(parent_view_);
aura::Window* window = view_->GetNativeView();
ASSERT_TRUE(window != NULL);
ASSERT_TRUE(window->HasFocus());
// After we create and focus another window, the RWHVA's window should be
// destroyed.
TestWindowObserver observer(window);
aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> sibling(new aura::Window(&delegate));
sibling->Init(aura::WINDOW_LAYER_TEXTURED);
sibling->Show();
window->parent()->AddChild(sibling.get());
sibling->Focus();
ASSERT_TRUE(sibling->HasFocus());
ASSERT_TRUE(observer.destroyed());
widget_host_ = NULL;
view_ = NULL;
}
// Checks that a popup view is destroyed when a user clicks outside of the popup
// view and focus does not change. This is the case when the user clicks on the
// desktop background on Chrome OS.
TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupClickOutsidePopup) {
parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
parent_view_->Focus();
EXPECT_TRUE(parent_view_->HasFocus());
view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
aura::Window* window = view_->GetNativeView();
ASSERT_TRUE(window != NULL);
gfx::Point click_point;
EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(click_point));
aura::Window* parent_window = parent_view_->GetNativeView();
EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(click_point));
TestWindowObserver observer(window);
ui::test::EventGenerator generator(window->GetRootWindow(), click_point);
generator.ClickLeftButton();
ASSERT_TRUE(parent_view_->HasFocus());
ASSERT_TRUE(observer.destroyed());
widget_host_ = NULL;
view_ = NULL;
}
// Checks that a popup view is destroyed when a user taps outside of the popup
// view and focus does not change. This is the case when the user taps the
// desktop background on Chrome OS.
TEST_F(RenderWidgetHostViewAuraTest, DestroyPopupTapOutsidePopup) {
parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
parent_view_->Focus();
EXPECT_TRUE(parent_view_->HasFocus());
view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
aura::Window* window = view_->GetNativeView();
ASSERT_TRUE(window != NULL);
gfx::Point tap_point;
EXPECT_FALSE(window->GetBoundsInRootWindow().Contains(tap_point));
aura::Window* parent_window = parent_view_->GetNativeView();
EXPECT_FALSE(parent_window->GetBoundsInRootWindow().Contains(tap_point));
TestWindowObserver observer(window);
ui::test::EventGenerator generator(window->GetRootWindow(), tap_point);
generator.GestureTapAt(tap_point);
ASSERT_TRUE(parent_view_->HasFocus());
ASSERT_TRUE(observer.destroyed());
widget_host_ = NULL;
view_ = NULL;
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// On Desktop Linux, select boxes need mouse capture in order to work. Test that
// when a select box is opened via a mouse press that it retains mouse capture
// after the mouse is released.
TEST_F(RenderWidgetHostViewAuraTest, PopupRetainsCaptureAfterMouseRelease) {
parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
parent_view_->Focus();
EXPECT_TRUE(parent_view_->HasFocus());
ui::test::EventGenerator generator(
parent_view_->GetNativeView()->GetRootWindow(), gfx::Point(300, 300));
generator.PressLeftButton();
view_->SetPopupType(blink::WebPopupTypeSelect);
view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
ASSERT_TRUE(view_->NeedsMouseCapture());
aura::Window* window = view_->GetNativeView();
EXPECT_TRUE(window->HasCapture());
generator.ReleaseLeftButton();
EXPECT_TRUE(window->HasCapture());
}
#endif
// Test that select boxes close when their parent window loses focus (e.g. due
// to an alert or system modal dialog).
TEST_F(RenderWidgetHostViewAuraTest, PopupClosesWhenParentLosesFocus) {
parent_view_->SetBounds(gfx::Rect(10, 10, 400, 400));
parent_view_->Focus();
EXPECT_TRUE(parent_view_->HasFocus());
view_->SetPopupType(blink::WebPopupTypeSelect);
view_->InitAsPopup(parent_view_, gfx::Rect(10, 10, 100, 100));
aura::Window* popup_window = view_->GetNativeView();
TestWindowObserver observer(popup_window);
aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> dialog_window(new aura::Window(&delegate));
dialog_window->Init(aura::WINDOW_LAYER_TEXTURED);
aura::client::ParentWindowWithContext(
dialog_window.get(), popup_window, gfx::Rect());
dialog_window->Show();
wm::ActivateWindow(dialog_window.get());
dialog_window->Focus();
ASSERT_TRUE(wm::IsActiveWindow(dialog_window.get()));
EXPECT_TRUE(observer.destroyed());
widget_host_ = NULL;
view_ = NULL;
}
// Checks that IME-composition-event state is maintained correctly.
TEST_F(RenderWidgetHostViewAuraTest, SetCompositionText) {
view_->InitAsChild(NULL);
view_->Show();
ui::CompositionText composition_text;
composition_text.text = base::ASCIIToUTF16("|a|b");
// Focused segment
composition_text.underlines.push_back(
ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
// Non-focused segment, with different background color.
composition_text.underlines.push_back(
ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
const ui::CompositionUnderlines& underlines = composition_text.underlines;
// Caret is at the end. (This emulates Japanese MSIME 2007 and later)
composition_text.selection = gfx::Range(4);
sink_->ClearMessages();
view_->SetCompositionText(composition_text);
EXPECT_TRUE(view_->has_composition_text_);
{
const IPC::Message* msg =
sink_->GetFirstMessageMatching(InputMsg_ImeSetComposition::ID);
ASSERT_TRUE(msg != NULL);
InputMsg_ImeSetComposition::Param params;
InputMsg_ImeSetComposition::Read(msg, ¶ms);
// composition text
EXPECT_EQ(composition_text.text, get<0>(params));
// underlines
ASSERT_EQ(underlines.size(), get<1>(params).size());
for (size_t i = 0; i < underlines.size(); ++i) {
EXPECT_EQ(underlines[i].start_offset, get<1>(params)[i].startOffset);
EXPECT_EQ(underlines[i].end_offset, get<1>(params)[i].endOffset);
EXPECT_EQ(underlines[i].color, get<1>(params)[i].color);
EXPECT_EQ(underlines[i].thick, get<1>(params)[i].thick);
EXPECT_EQ(underlines[i].background_color,
get<1>(params)[i].backgroundColor);
}
// highlighted range
EXPECT_EQ(4, get<2>(params)) << "Should be the same to the caret pos";
EXPECT_EQ(4, get<3>(params)) << "Should be the same to the caret pos";
}
view_->ImeCancelComposition();
EXPECT_FALSE(view_->has_composition_text_);
}
// Checks that sequence of IME-composition-event and mouse-event when mouse
// clicking to cancel the composition.
TEST_F(RenderWidgetHostViewAuraTest, FinishCompositionByMouse) {
view_->InitAsChild(NULL);
view_->Show();
ui::CompositionText composition_text;
composition_text.text = base::ASCIIToUTF16("|a|b");
// Focused segment
composition_text.underlines.push_back(
ui::CompositionUnderline(0, 3, 0xff000000, true, 0x78563412));
// Non-focused segment, with different background color.
composition_text.underlines.push_back(
ui::CompositionUnderline(3, 4, 0xff000000, false, 0xefcdab90));
// Caret is at the end. (This emulates Japanese MSIME 2007 and later)
composition_text.selection = gfx::Range(4);
view_->SetCompositionText(composition_text);
EXPECT_TRUE(view_->has_composition_text_);
sink_->ClearMessages();
// Simulates the mouse press.
ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED,
gfx::Point(), gfx::Point(),
ui::EF_LEFT_MOUSE_BUTTON, 0);
view_->OnMouseEvent(&mouse_event);
EXPECT_FALSE(view_->has_composition_text_);
EXPECT_EQ(2U, sink_->message_count());
if (sink_->message_count() == 2) {
// Verify mouse event happens after the confirm-composition event.
EXPECT_EQ(InputMsg_ImeConfirmComposition::ID,
sink_->GetMessageAt(0)->type());
EXPECT_EQ(InputMsg_HandleInputEvent::ID,
sink_->GetMessageAt(1)->type());
}
}
// Checks that touch-event state is maintained correctly.
TEST_F(RenderWidgetHostViewAuraTest, TouchEventState) {
view_->InitAsChild(NULL);
view_->Show();
// Start with no touch-event handler in the renderer.
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
EXPECT_FALSE(widget_host_->ShouldForwardTouchEvent());
ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
gfx::Point(30, 30),
0,
ui::EventTimeForNow());
ui::TouchEvent move(ui::ET_TOUCH_MOVED,
gfx::Point(20, 20),
0,
ui::EventTimeForNow());
ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
gfx::Point(20, 20),
0,
ui::EventTimeForNow());
view_->OnTouchEvent(&press);
EXPECT_FALSE(press.handled());
EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
EXPECT_TRUE(view_->touch_event_->cancelable);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StatePressed,
view_->touch_event_->touches[0].state);
view_->OnTouchEvent(&move);
EXPECT_FALSE(move.handled());
EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
EXPECT_TRUE(view_->touch_event_->cancelable);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StateMoved,
view_->touch_event_->touches[0].state);
view_->OnTouchEvent(&release);
EXPECT_FALSE(release.handled());
EXPECT_EQ(nullptr, view_->touch_event_);
// Now install some touch-event handlers and do the same steps. The touch
// events should now be consumed. However, the touch-event state should be
// updated as before.
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
view_->OnTouchEvent(&press);
EXPECT_TRUE(press.synchronous_handling_disabled());
EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
EXPECT_TRUE(view_->touch_event_->cancelable);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StatePressed,
view_->touch_event_->touches[0].state);
view_->OnTouchEvent(&move);
EXPECT_TRUE(move.synchronous_handling_disabled());
EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
EXPECT_TRUE(view_->touch_event_->cancelable);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StateMoved,
view_->touch_event_->touches[0].state);
view_->OnTouchEvent(&release);
EXPECT_TRUE(release.synchronous_handling_disabled());
EXPECT_EQ(nullptr, view_->touch_event_);
// Now start a touch event, and remove the event-handlers before the release.
view_->OnTouchEvent(&press);
EXPECT_TRUE(press.synchronous_handling_disabled());
EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StatePressed,
view_->touch_event_->touches[0].state);
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
// Ack'ing the outstanding event should flush the pending touch queue.
InputHostMsg_HandleInputEvent_ACK_Params ack;
ack.type = blink::WebInputEvent::TouchStart;
ack.state = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
widget_host_->OnMessageReceived(InputHostMsg_HandleInputEvent_ACK(0, ack));
EXPECT_FALSE(widget_host_->ShouldForwardTouchEvent());
ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0,
base::Time::NowFromSystemTime() - base::Time());
view_->OnTouchEvent(&move2);
EXPECT_FALSE(move2.handled());
EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StateMoved,
view_->touch_event_->touches[0].state);
ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0,
base::Time::NowFromSystemTime() - base::Time());
view_->OnTouchEvent(&release2);
EXPECT_FALSE(release2.handled());
EXPECT_EQ(nullptr, view_->touch_event_);
}
// Checks that touch-events are queued properly when there is a touch-event
// handler on the page.
TEST_F(RenderWidgetHostViewAuraTest, TouchEventSyncAsync) {
view_->InitAsChild(NULL);
view_->Show();
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
gfx::Point(30, 30),
0,
ui::EventTimeForNow());
ui::TouchEvent move(ui::ET_TOUCH_MOVED,
gfx::Point(20, 20),
0,
ui::EventTimeForNow());
ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
gfx::Point(20, 20),
0,
ui::EventTimeForNow());
view_->OnTouchEvent(&press);
EXPECT_TRUE(press.synchronous_handling_disabled());
EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StatePressed,
view_->touch_event_->touches[0].state);
view_->OnTouchEvent(&move);
EXPECT_TRUE(move.synchronous_handling_disabled());
EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StateMoved,
view_->touch_event_->touches[0].state);
// Send the same move event. Since the point hasn't moved, it won't affect the
// queue. However, the view should consume the event.
view_->OnTouchEvent(&move);
EXPECT_TRUE(move.synchronous_handling_disabled());
EXPECT_EQ(blink::WebInputEvent::TouchMove, view_->touch_event_->type);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StateMoved,
view_->touch_event_->touches[0].state);
view_->OnTouchEvent(&release);
EXPECT_TRUE(release.synchronous_handling_disabled());
EXPECT_EQ(nullptr, view_->touch_event_);
}
TEST_F(RenderWidgetHostViewAuraTest, PhysicalBackingSizeWithScale) {
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
sink_->ClearMessages();
view_->SetSize(gfx::Size(100, 100));
EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString());
EXPECT_EQ(1u, sink_->message_count());
EXPECT_EQ(ViewMsg_Resize::ID, sink_->GetMessageAt(0)->type());
{
const IPC::Message* msg = sink_->GetMessageAt(0);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ("100x100", get<0>(params).new_size.ToString()); // dip size
EXPECT_EQ("100x100",
get<0>(params).physical_backing_size.ToString()); // backing size
}
widget_host_->ResetSizeAndRepaintPendingFlags();
sink_->ClearMessages();
aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f);
EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString());
// Extra ScreenInfoChanged message for |parent_view_|.
EXPECT_EQ(1u, sink_->message_count());
{
const IPC::Message* msg = sink_->GetMessageAt(0);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ(2.0f, get<0>(params).screen_info.deviceScaleFactor);
EXPECT_EQ("100x100", get<0>(params).new_size.ToString()); // dip size
EXPECT_EQ("200x200",
get<0>(params).physical_backing_size.ToString()); // backing size
}
widget_host_->ResetSizeAndRepaintPendingFlags();
sink_->ClearMessages();
aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f);
// Extra ScreenInfoChanged message for |parent_view_|.
EXPECT_EQ(1u, sink_->message_count());
EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString());
{
const IPC::Message* msg = sink_->GetMessageAt(0);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ(1.0f, get<0>(params).screen_info.deviceScaleFactor);
EXPECT_EQ("100x100", get<0>(params).new_size.ToString()); // dip size
EXPECT_EQ("100x100",
get<0>(params).physical_backing_size.ToString()); // backing size
}
}
// Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched
// to the renderer at the correct times.
TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) {
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(gfx::Size(100, 100));
aura::test::TestCursorClient cursor_client(
parent_view_->GetNativeView()->GetRootWindow());
cursor_client.AddObserver(view_);
// Expect a message the first time the cursor is shown.
view_->WasShown();
sink_->ClearMessages();
cursor_client.ShowCursor();
EXPECT_EQ(1u, sink_->message_count());
EXPECT_TRUE(sink_->GetUniqueMessageMatching(
InputMsg_CursorVisibilityChange::ID));
// No message expected if the renderer already knows the cursor is visible.
sink_->ClearMessages();
cursor_client.ShowCursor();
EXPECT_EQ(0u, sink_->message_count());
// Hiding the cursor should send a message.
sink_->ClearMessages();
cursor_client.HideCursor();
EXPECT_EQ(1u, sink_->message_count());
EXPECT_TRUE(sink_->GetUniqueMessageMatching(
InputMsg_CursorVisibilityChange::ID));
// No message expected if the renderer already knows the cursor is invisible.
sink_->ClearMessages();
cursor_client.HideCursor();
EXPECT_EQ(0u, sink_->message_count());
// No messages should be sent while the view is invisible.
view_->WasHidden();
sink_->ClearMessages();
cursor_client.ShowCursor();
EXPECT_EQ(0u, sink_->message_count());
cursor_client.HideCursor();
EXPECT_EQ(0u, sink_->message_count());
// Show the view. Since the cursor was invisible when the view was hidden,
// no message should be sent.
sink_->ClearMessages();
view_->WasShown();
EXPECT_FALSE(sink_->GetUniqueMessageMatching(
InputMsg_CursorVisibilityChange::ID));
// No message expected if the renderer already knows the cursor is invisible.
sink_->ClearMessages();
cursor_client.HideCursor();
EXPECT_EQ(0u, sink_->message_count());
// Showing the cursor should send a message.
sink_->ClearMessages();
cursor_client.ShowCursor();
EXPECT_EQ(1u, sink_->message_count());
EXPECT_TRUE(sink_->GetUniqueMessageMatching(
InputMsg_CursorVisibilityChange::ID));
// No messages should be sent while the view is invisible.
view_->WasHidden();
sink_->ClearMessages();
cursor_client.HideCursor();
EXPECT_EQ(0u, sink_->message_count());
// Show the view. Since the cursor was visible when the view was hidden,
// a message is expected to be sent.
sink_->ClearMessages();
view_->WasShown();
EXPECT_TRUE(sink_->GetUniqueMessageMatching(
InputMsg_CursorVisibilityChange::ID));
cursor_client.RemoveObserver(view_);
}
TEST_F(RenderWidgetHostViewAuraTest, UpdateCursorIfOverSelf) {
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
// Note that all coordinates in this test are screen coordinates.
view_->SetBounds(gfx::Rect(60, 60, 100, 100));
view_->Show();
aura::test::TestCursorClient cursor_client(
parent_view_->GetNativeView()->GetRootWindow());
// Cursor is in the middle of the window.
cursor_client.reset_calls_to_set_cursor();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(110, 110));
view_->UpdateCursorIfOverSelf();
EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
// Cursor is near the top of the window.
cursor_client.reset_calls_to_set_cursor();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(80, 65));
view_->UpdateCursorIfOverSelf();
EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
// Cursor is near the bottom of the window.
cursor_client.reset_calls_to_set_cursor();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(159, 159));
view_->UpdateCursorIfOverSelf();
EXPECT_EQ(1, cursor_client.calls_to_set_cursor());
// Cursor is above the window.
cursor_client.reset_calls_to_set_cursor();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(67, 59));
view_->UpdateCursorIfOverSelf();
EXPECT_EQ(0, cursor_client.calls_to_set_cursor());
// Cursor is below the window.
cursor_client.reset_calls_to_set_cursor();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(161, 161));
view_->UpdateCursorIfOverSelf();
EXPECT_EQ(0, cursor_client.calls_to_set_cursor());
}
scoped_ptr<cc::CompositorFrame> MakeDelegatedFrame(float scale_factor,
gfx::Size size,
gfx::Rect damage) {
scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
frame->metadata.device_scale_factor = scale_factor;
frame->delegated_frame_data.reset(new cc::DelegatedFrameData);
scoped_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
pass->SetNew(
cc::RenderPassId(1, 1), gfx::Rect(size), damage, gfx::Transform());
frame->delegated_frame_data->render_pass_list.push_back(pass.Pass());
return frame.Pass();
}
// Resizing in fullscreen mode should send the up-to-date screen info.
// http://crbug.com/324350
TEST_F(RenderWidgetHostViewAuraTest, DISABLED_FullscreenResize) {
aura::Window* root_window = aura_test_helper_->root_window();
root_window->SetLayoutManager(new FullscreenLayoutManager(root_window));
view_->InitAsFullscreen(parent_view_);
view_->WasShown();
widget_host_->ResetSizeAndRepaintPendingFlags();
sink_->ClearMessages();
// Call WasResized to flush the old screen info.
view_->GetRenderWidgetHost()->WasResized();
{
// 0 is CreatingNew message.
const IPC::Message* msg = sink_->GetMessageAt(0);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ("0,0 800x600",
gfx::Rect(get<0>(params).screen_info.availableRect).ToString());
EXPECT_EQ("800x600", get<0>(params).new_size.ToString());
// Resizes are blocked until we swapped a frame of the correct size, and
// we've committed it.
view_->OnSwapCompositorFrame(
0,
MakeDelegatedFrame(
1.f, get<0>(params).new_size, gfx::Rect(get<0>(params).new_size)));
ui::DrawWaiterForTest::WaitForCommit(
root_window->GetHost()->compositor());
}
widget_host_->ResetSizeAndRepaintPendingFlags();
sink_->ClearMessages();
// Make sure the corrent screen size is set along in the resize
// request when the screen size has changed.
aura_test_helper_->test_screen()->SetUIScale(0.5);
EXPECT_EQ(1u, sink_->message_count());
{
const IPC::Message* msg = sink_->GetMessageAt(0);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ("0,0 1600x1200",
gfx::Rect(get<0>(params).screen_info.availableRect).ToString());
EXPECT_EQ("1600x1200", get<0>(params).new_size.ToString());
view_->OnSwapCompositorFrame(
0,
MakeDelegatedFrame(
1.f, get<0>(params).new_size, gfx::Rect(get<0>(params).new_size)));
ui::DrawWaiterForTest::WaitForCommit(
root_window->GetHost()->compositor());
}
}
// Swapping a frame should notify the window.
TEST_F(RenderWidgetHostViewAuraTest, SwapNotifiesWindow) {
gfx::Size view_size(100, 100);
gfx::Rect view_rect(view_size);
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_size);
view_->WasShown();
MockWindowObserver observer;
view_->window_->AddObserver(&observer);
// Delegated renderer path
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, view_size, view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_,
gfx::Rect(5, 5, 5, 5)));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, view_size, gfx::Rect(5, 5, 5, 5)));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->window_->RemoveObserver(&observer);
}
// Recreating the layers for a window should cause Surface destruction to
// depend on both layers.
TEST_F(RenderWidgetHostViewAuraTest, RecreateLayers) {
gfx::Size view_size(100, 100);
gfx::Rect view_rect(view_size);
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_size);
view_->WasShown();
view_->OnSwapCompositorFrame(0,
MakeDelegatedFrame(1.f, view_size, view_rect));
scoped_ptr<ui::LayerTreeOwner> cloned_owner(
wm::RecreateLayers(view_->GetNativeView()));
cc::SurfaceId id = view_->GetDelegatedFrameHost()->SurfaceIdForTesting();
if (!id.is_null()) {
ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
cc::SurfaceManager* manager = factory->GetSurfaceManager();
cc::Surface* surface = manager->GetSurfaceForId(id);
EXPECT_TRUE(surface);
// Should be a SurfaceSequence for both the original and new layers.
EXPECT_EQ(2u, surface->GetDestructionDependencyCount());
}
}
TEST_F(RenderWidgetHostViewAuraTest, Resize) {
gfx::Size size1(100, 100);
gfx::Size size2(200, 200);
gfx::Size size3(300, 300);
aura::Window* root_window = parent_view_->GetNativeView()->GetRootWindow();
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(), root_window, gfx::Rect(size1));
view_->WasShown();
view_->SetSize(size1);
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, size1, gfx::Rect(size1)));
ui::DrawWaiterForTest::WaitForCommit(
root_window->GetHost()->compositor());
ViewHostMsg_UpdateRect_Params update_params;
update_params.view_size = size1;
update_params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
widget_host_->OnMessageReceived(
ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params));
sink_->ClearMessages();
// Resize logic is idle (no pending resize, no pending commit).
EXPECT_EQ(size1.ToString(), view_->GetRequestedRendererSize().ToString());
// Resize renderer, should produce a Resize message
view_->SetSize(size2);
EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
EXPECT_EQ(1u, sink_->message_count());
{
const IPC::Message* msg = sink_->GetMessageAt(0);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ(size2.ToString(), get<0>(params).new_size.ToString());
}
// Send resize ack to observe new Resize messages.
update_params.view_size = size2;
widget_host_->OnMessageReceived(
ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params));
sink_->ClearMessages();
// Resize renderer again, before receiving a frame. Should not produce a
// Resize message.
view_->SetSize(size3);
EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
EXPECT_EQ(0u, sink_->message_count());
// Receive a frame of the new size, should be skipped and not produce a Resize
// message.
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, size3, gfx::Rect(size3)));
// Expect the frame ack;
EXPECT_EQ(1u, sink_->message_count());
EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID, sink_->GetMessageAt(0)->type());
sink_->ClearMessages();
EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
// Receive a frame of the correct size, should not be skipped and, and should
// produce a Resize message after the commit.
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, size2, gfx::Rect(size2)));
cc::SurfaceId surface_id = view_->surface_id();
if (surface_id.is_null()) {
// No frame ack yet.
EXPECT_EQ(0u, sink_->message_count());
} else {
// Frame isn't desired size, so early ack.
EXPECT_EQ(1u, sink_->message_count());
}
EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
// Wait for commit, then we should unlock the compositor and send a Resize
// message (and a frame ack)
ui::DrawWaiterForTest::WaitForCommit(
root_window->GetHost()->compositor());
EXPECT_EQ(size3.ToString(), view_->GetRequestedRendererSize().ToString());
EXPECT_EQ(2u, sink_->message_count());
EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID,
sink_->GetMessageAt(0)->type());
{
const IPC::Message* msg = sink_->GetMessageAt(1);
EXPECT_EQ(ViewMsg_Resize::ID, msg->type());
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(msg, ¶ms);
EXPECT_EQ(size3.ToString(), get<0>(params).new_size.ToString());
}
update_params.view_size = size3;
widget_host_->OnMessageReceived(
ViewHostMsg_UpdateRect(widget_host_->GetRoutingID(), update_params));
sink_->ClearMessages();
}
// Skipped frames should not drop their damage.
TEST_F(RenderWidgetHostViewAuraTest, SkippedDelegatedFrames) {
gfx::Rect view_rect(100, 100);
gfx::Size frame_size = view_rect.size();
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_rect.size());
MockWindowObserver observer;
view_->window_->AddObserver(&observer);
// A full frame of damage.
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// A partial damage frame.
gfx::Rect partial_view_rect(30, 30, 20, 20);
EXPECT_CALL(observer,
OnDelegatedFrameDamage(view_->window_, partial_view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, partial_view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// Lock the compositor. Now we should drop frames.
view_rect = gfx::Rect(150, 150);
view_->SetSize(view_rect.size());
// This frame is dropped.
gfx::Rect dropped_damage_rect_1(10, 20, 30, 40);
EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0);
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_1));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
gfx::Rect dropped_damage_rect_2(40, 50, 10, 20);
EXPECT_CALL(observer, OnDelegatedFrameDamage(_, _)).Times(0);
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, dropped_damage_rect_2));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// Unlock the compositor. This frame should damage everything.
frame_size = view_rect.size();
gfx::Rect new_damage_rect(5, 6, 10, 10);
EXPECT_CALL(observer,
OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, new_damage_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// A partial damage frame, this should not be dropped.
EXPECT_CALL(observer,
OnDelegatedFrameDamage(view_->window_, partial_view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, partial_view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// Resize to something empty.
view_rect = gfx::Rect(100, 0);
view_->SetSize(view_rect.size());
// We're never expecting empty frames, resize to something non-empty.
view_rect = gfx::Rect(100, 100);
view_->SetSize(view_rect.size());
// This frame should not be dropped.
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, view_rect.size(), view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
view_->window_->RemoveObserver(&observer);
}
TEST_F(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange) {
gfx::Rect view_rect(100, 100);
gfx::Size frame_size = view_rect.size();
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_rect.size());
MockWindowObserver observer;
view_->window_->AddObserver(&observer);
// Swap a frame.
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(
0, MakeDelegatedFrame(1.f, frame_size, view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// Swap a frame with a different surface id.
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// Swap an empty frame, with a different surface id.
view_->OnSwapCompositorFrame(
2, MakeDelegatedFrame(1.f, gfx::Size(), gfx::Rect()));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
// Swap another frame, with a different surface id.
EXPECT_CALL(observer, OnDelegatedFrameDamage(view_->window_, view_rect));
view_->OnSwapCompositorFrame(3,
MakeDelegatedFrame(1.f, frame_size, view_rect));
testing::Mock::VerifyAndClearExpectations(&observer);
view_->RunOnCompositingDidCommit();
view_->window_->RemoveObserver(&observer);
}
TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFrames) {
size_t max_renderer_frames =
RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
ASSERT_LE(2u, max_renderer_frames);
size_t renderer_count = max_renderer_frames + 1;
gfx::Rect view_rect(100, 100);
gfx::Size frame_size = view_rect.size();
DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
scoped_ptr<RenderWidgetHostImpl * []> hosts(
new RenderWidgetHostImpl* [renderer_count]);
scoped_ptr<FakeRenderWidgetHostViewAura * []> views(
new FakeRenderWidgetHostViewAura* [renderer_count]);
// Create a bunch of renderers.
for (size_t i = 0; i < renderer_count; ++i) {
hosts[i] = new RenderWidgetHostImpl(
&delegate_, process_host_, MSG_ROUTING_NONE, false);
hosts[i]->Init();
views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false);
views[i]->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
views[i]->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
views[i]->SetSize(view_rect.size());
}
// Make each renderer visible, and swap a frame on it, then make it invisible.
for (size_t i = 0; i < renderer_count; ++i) {
views[i]->WasShown();
views[i]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_TRUE(views[i]->HasFrameData());
views[i]->WasHidden();
}
// There should be max_renderer_frames with a frame in it, and one without it.
// Since the logic is LRU eviction, the first one should be without.
EXPECT_FALSE(views[0]->HasFrameData());
for (size_t i = 1; i < renderer_count; ++i)
EXPECT_TRUE(views[i]->HasFrameData());
// LRU renderer is [0], make it visible, it shouldn't evict anything yet.
views[0]->WasShown();
EXPECT_FALSE(views[0]->HasFrameData());
EXPECT_TRUE(views[1]->HasFrameData());
// Since [0] doesn't have a frame, it should be waiting for the renderer to
// give it one.
EXPECT_TRUE(views[0]->released_front_lock_active());
// Swap a frame on it, it should evict the next LRU [1].
views[0]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_TRUE(views[0]->HasFrameData());
EXPECT_FALSE(views[1]->HasFrameData());
// Now that [0] got a frame, it shouldn't be waiting any more.
EXPECT_FALSE(views[0]->released_front_lock_active());
views[0]->WasHidden();
// LRU renderer is [1], still hidden. Swap a frame on it, it should evict
// the next LRU [2].
views[1]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_TRUE(views[0]->HasFrameData());
EXPECT_TRUE(views[1]->HasFrameData());
EXPECT_FALSE(views[2]->HasFrameData());
for (size_t i = 3; i < renderer_count; ++i)
EXPECT_TRUE(views[i]->HasFrameData());
// Make all renderers but [0] visible and swap a frame on them, keep [0]
// hidden, it becomes the LRU.
for (size_t i = 1; i < renderer_count; ++i) {
views[i]->WasShown();
// The renderers who don't have a frame should be waiting. The ones that
// have a frame should not.
// In practice, [1] has a frame, but anything after has its frame evicted.
EXPECT_EQ(!views[i]->HasFrameData(),
views[i]->released_front_lock_active());
views[i]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
// Now everyone has a frame.
EXPECT_FALSE(views[i]->released_front_lock_active());
EXPECT_TRUE(views[i]->HasFrameData());
}
EXPECT_FALSE(views[0]->HasFrameData());
// Swap a frame on [0], it should be evicted immediately.
views[0]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_FALSE(views[0]->HasFrameData());
// Make [0] visible, and swap a frame on it. Nothing should be evicted
// although we're above the limit.
views[0]->WasShown();
// We don't have a frame, wait.
EXPECT_TRUE(views[0]->released_front_lock_active());
views[0]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_FALSE(views[0]->released_front_lock_active());
for (size_t i = 0; i < renderer_count; ++i)
EXPECT_TRUE(views[i]->HasFrameData());
// Make [0] hidden, it should evict its frame.
views[0]->WasHidden();
EXPECT_FALSE(views[0]->HasFrameData());
// Make [0] visible, don't give it a frame, it should be waiting.
views[0]->WasShown();
EXPECT_TRUE(views[0]->released_front_lock_active());
// Make [0] hidden, it should stop waiting.
views[0]->WasHidden();
EXPECT_FALSE(views[0]->released_front_lock_active());
// Make [1] hidden, resize it. It should drop its frame.
views[1]->WasHidden();
EXPECT_TRUE(views[1]->HasFrameData());
gfx::Size size2(200, 200);
views[1]->SetSize(size2);
EXPECT_FALSE(views[1]->HasFrameData());
// Show it, it should block until we give it a frame.
views[1]->WasShown();
EXPECT_TRUE(views[1]->released_front_lock_active());
views[1]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, size2, gfx::Rect(size2)));
EXPECT_FALSE(views[1]->released_front_lock_active());
for (size_t i = 0; i < renderer_count - 1; ++i)
views[i]->WasHidden();
// Allocate enough bitmaps so that two frames (proportionally) would be
// enough hit the handle limit.
int handles_per_frame = 5;
RendererFrameManager::GetInstance()->set_max_handles(handles_per_frame * 2);
for (size_t i = 0; i < (renderer_count - 1) * handles_per_frame; i++) {
HostSharedBitmapManager::current()->ChildAllocatedSharedBitmap(
1,
base::SharedMemory::NULLHandle(),
base::GetCurrentProcessHandle(),
cc::SharedBitmap::GenerateId());
}
// Hiding this last bitmap should evict all but two frames.
views[renderer_count - 1]->WasHidden();
for (size_t i = 0; i < renderer_count; ++i) {
if (i + 2 < renderer_count)
EXPECT_FALSE(views[i]->HasFrameData());
else
EXPECT_TRUE(views[i]->HasFrameData());
}
HostSharedBitmapManager::current()->ProcessRemoved(
base::GetCurrentProcessHandle());
RendererFrameManager::GetInstance()->set_max_handles(
base::SharedMemory::GetHandleLimit());
for (size_t i = 0; i < renderer_count; ++i) {
views[i]->Destroy();
delete hosts[i];
}
}
TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithLocking) {
size_t max_renderer_frames =
RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
ASSERT_LE(2u, max_renderer_frames);
size_t renderer_count = max_renderer_frames + 1;
gfx::Rect view_rect(100, 100);
gfx::Size frame_size = view_rect.size();
DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
scoped_ptr<RenderWidgetHostImpl * []> hosts(
new RenderWidgetHostImpl* [renderer_count]);
scoped_ptr<FakeRenderWidgetHostViewAura * []> views(
new FakeRenderWidgetHostViewAura* [renderer_count]);
// Create a bunch of renderers.
for (size_t i = 0; i < renderer_count; ++i) {
hosts[i] = new RenderWidgetHostImpl(
&delegate_, process_host_, MSG_ROUTING_NONE, false);
hosts[i]->Init();
views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false);
views[i]->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
views[i]->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
views[i]->SetSize(view_rect.size());
}
// Make each renderer visible and swap a frame on it. No eviction should
// occur because all frames are visible.
for (size_t i = 0; i < renderer_count; ++i) {
views[i]->WasShown();
views[i]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_TRUE(views[i]->HasFrameData());
}
// If we hide [0], then [0] should be evicted.
views[0]->WasHidden();
EXPECT_FALSE(views[0]->HasFrameData());
// If we lock [0] before hiding it, then [0] should not be evicted.
views[0]->WasShown();
views[0]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_TRUE(views[0]->HasFrameData());
views[0]->GetDelegatedFrameHost()->LockResources();
views[0]->WasHidden();
EXPECT_TRUE(views[0]->HasFrameData());
// If we unlock [0] now, then [0] should be evicted.
views[0]->GetDelegatedFrameHost()->UnlockResources();
EXPECT_FALSE(views[0]->HasFrameData());
for (size_t i = 0; i < renderer_count; ++i) {
views[i]->Destroy();
delete hosts[i];
}
}
// Test that changing the memory pressure should delete saved frames. This test
// only applies to ChromeOS.
TEST_F(RenderWidgetHostViewAuraTest, DiscardDelegatedFramesWithMemoryPressure) {
size_t max_renderer_frames =
RendererFrameManager::GetInstance()->GetMaxNumberOfSavedFrames();
ASSERT_LE(2u, max_renderer_frames);
size_t renderer_count = max_renderer_frames;
gfx::Rect view_rect(100, 100);
gfx::Size frame_size = view_rect.size();
DCHECK_EQ(0u, HostSharedBitmapManager::current()->AllocatedBitmapCount());
scoped_ptr<RenderWidgetHostImpl * []> hosts(
new RenderWidgetHostImpl* [renderer_count]);
scoped_ptr<FakeRenderWidgetHostViewAura * []> views(
new FakeRenderWidgetHostViewAura* [renderer_count]);
// Create a bunch of renderers.
for (size_t i = 0; i < renderer_count; ++i) {
hosts[i] = new RenderWidgetHostImpl(
&delegate_, process_host_, MSG_ROUTING_NONE, false);
hosts[i]->Init();
views[i] = new FakeRenderWidgetHostViewAura(hosts[i], false);
views[i]->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
views[i]->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
views[i]->SetSize(view_rect.size());
}
// Make each renderer visible and swap a frame on it. No eviction should
// occur because all frames are visible.
for (size_t i = 0; i < renderer_count; ++i) {
views[i]->WasShown();
views[i]->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, view_rect));
EXPECT_TRUE(views[i]->HasFrameData());
}
// If we hide one, it should not get evicted.
views[0]->WasHidden();
message_loop_.RunUntilIdle();
EXPECT_TRUE(views[0]->HasFrameData());
// Using a lesser memory pressure event however, should evict.
SimulateMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE);
message_loop_.RunUntilIdle();
EXPECT_FALSE(views[0]->HasFrameData());
// Check the same for a higher pressure event.
views[1]->WasHidden();
message_loop_.RunUntilIdle();
EXPECT_TRUE(views[1]->HasFrameData());
SimulateMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
message_loop_.RunUntilIdle();
EXPECT_FALSE(views[1]->HasFrameData());
for (size_t i = 0; i < renderer_count; ++i) {
views[i]->Destroy();
delete hosts[i];
}
}
TEST_F(RenderWidgetHostViewAuraTest, SoftwareDPIChange) {
gfx::Rect view_rect(100, 100);
gfx::Size frame_size(100, 100);
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_rect.size());
view_->WasShown();
// With a 1x DPI UI and 1x DPI Renderer.
view_->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, frame_size, gfx::Rect(frame_size)));
// Save the frame provider.
scoped_refptr<cc::DelegatedFrameProvider> frame_provider =
view_->frame_provider();
cc::SurfaceId surface_id = view_->surface_id();
// This frame will have the same number of physical pixels, but has a new
// scale on it.
view_->OnSwapCompositorFrame(
1, MakeDelegatedFrame(2.f, frame_size, gfx::Rect(frame_size)));
// When we get a new frame with the same frame size in physical pixels, but a
// different scale, we should generate a new frame provider, as the final
// result will need to be scaled differently to the screen.
if (frame_provider.get())
EXPECT_NE(frame_provider.get(), view_->frame_provider());
else
EXPECT_NE(surface_id, view_->surface_id());
}
class RenderWidgetHostViewAuraCopyRequestTest
: public RenderWidgetHostViewAuraShutdownTest {
public:
RenderWidgetHostViewAuraCopyRequestTest()
: callback_count_(0), result_(false) {}
void CallbackMethod(const base::Closure& quit_closure, bool result) {
result_ = result;
callback_count_++;
quit_closure.Run();
}
int callback_count_;
bool result_;
private:
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraCopyRequestTest);
};
TEST_F(RenderWidgetHostViewAuraCopyRequestTest, DestroyedAfterCopyRequest) {
base::RunLoop run_loop;
gfx::Rect view_rect(100, 100);
scoped_ptr<cc::CopyOutputRequest> request;
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_rect.size());
view_->WasShown();
scoped_ptr<FakeFrameSubscriber> frame_subscriber(new FakeFrameSubscriber(
view_rect.size(),
base::Bind(&RenderWidgetHostViewAuraCopyRequestTest::CallbackMethod,
base::Unretained(this),
run_loop.QuitClosure())));
EXPECT_EQ(0, callback_count_);
EXPECT_FALSE(view_->last_copy_request_);
view_->BeginFrameSubscription(frame_subscriber.Pass());
view_->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect)));
EXPECT_EQ(0, callback_count_);
EXPECT_TRUE(view_->last_copy_request_);
EXPECT_TRUE(view_->last_copy_request_->has_texture_mailbox());
request = view_->last_copy_request_.Pass();
// Send back the mailbox included in the request. There's no release callback
// since the mailbox came from the RWHVA originally.
request->SendTextureResult(view_rect.size(),
request->texture_mailbox(),
scoped_ptr<cc::SingleReleaseCallback>());
// This runs until the callback happens.
run_loop.Run();
// The callback should succeed.
EXPECT_EQ(1, callback_count_);
EXPECT_TRUE(result_);
view_->OnSwapCompositorFrame(
1, MakeDelegatedFrame(1.f, view_rect.size(), gfx::Rect(view_rect)));
EXPECT_EQ(1, callback_count_);
request = view_->last_copy_request_.Pass();
// Destroy the RenderWidgetHostViewAura and ImageTransportFactory.
TearDownEnvironment();
// Send back the mailbox included in the request. There's no release callback
// since the mailbox came from the RWHVA originally.
request->SendTextureResult(view_rect.size(),
request->texture_mailbox(),
scoped_ptr<cc::SingleReleaseCallback>());
// Because the copy request callback may be holding state within it, that
// state must handle the RWHVA and ImageTransportFactory going away before the
// callback is called. This test passes if it does not crash as a result of
// these things being destroyed.
EXPECT_EQ(2, callback_count_);
EXPECT_FALSE(result_);
}
TEST_F(RenderWidgetHostViewAuraTest, VisibleViewportTest) {
gfx::Rect view_rect(100, 100);
view_->InitAsChild(NULL);
aura::client::ParentWindowWithContext(
view_->GetNativeView(),
parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->SetSize(view_rect.size());
view_->WasShown();
// Defaults to full height of the view.
EXPECT_EQ(100, view_->GetVisibleViewportSize().height());
widget_host_->ResetSizeAndRepaintPendingFlags();
sink_->ClearMessages();
view_->SetInsets(gfx::Insets(0, 0, 40, 0));
EXPECT_EQ(60, view_->GetVisibleViewportSize().height());
const IPC::Message *message = sink_->GetFirstMessageMatching(
ViewMsg_Resize::ID);
ASSERT_TRUE(message != NULL);
ViewMsg_Resize::Param params;
ViewMsg_Resize::Read(message, ¶ms);
EXPECT_EQ(60, get<0>(params).visible_viewport_size.height());
}
// Ensures that touch event positions are never truncated to integers.
TEST_F(RenderWidgetHostViewAuraTest, TouchEventPositionsArentRounded) {
const float kX = 30.58f;
const float kY = 50.23f;
view_->InitAsChild(NULL);
view_->Show();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
gfx::PointF(kX, kY),
0,
ui::EventTimeForNow());
view_->OnTouchEvent(&press);
EXPECT_EQ(blink::WebInputEvent::TouchStart, view_->touch_event_->type);
EXPECT_TRUE(view_->touch_event_->cancelable);
EXPECT_EQ(1U, view_->touch_event_->touchesLength);
EXPECT_EQ(blink::WebTouchPoint::StatePressed,
view_->touch_event_->touches[0].state);
EXPECT_EQ(kX, view_->touch_event_->touches[0].screenPosition.x);
EXPECT_EQ(kX, view_->touch_event_->touches[0].position.x);
EXPECT_EQ(kY, view_->touch_event_->touches[0].screenPosition.y);
EXPECT_EQ(kY, view_->touch_event_->touches[0].position.y);
}
// Tests that scroll ACKs are correctly handled by the overscroll-navigation
// controller.
TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollEventOverscrolls) {
SetUpOverscrollEnvironment();
// Simulate wheel events.
SimulateWheelEvent(-5, 0, 0, true); // sent directly
SimulateWheelEvent(-1, 1, 0, true); // enqueued
SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK the first wheel event as not processed.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK for the second (coalesced) event as not processed. This will
// start a back navigation. However, this will also cause the queued next
// event to be sent to the renderer. But since overscroll navigation has
// started, that event will also be included in the overscroll computation
// instead of being sent to the renderer. So the result will be an overscroll
// back navigation, and no event will be sent to the renderer.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
EXPECT_EQ(-81.f, overscroll_delta_x());
EXPECT_EQ(-31.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(0U, sink_->message_count());
// Send a mouse-move event. This should cancel the overscroll navigation.
SimulateMouseMove(5, 10, 0);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, sink_->message_count());
}
// Tests that if some scroll events are consumed towards the start, then
// subsequent scrolls do not horizontal overscroll.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
WheelScrollConsumedDoNotHorizOverscroll) {
SetUpOverscrollEnvironment();
// Simulate wheel events.
SimulateWheelEvent(-5, 0, 0, true); // sent directly
SimulateWheelEvent(-1, -1, 0, true); // enqueued
SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK the first wheel event as processed.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK for the second (coalesced) event as not processed. This should
// not initiate overscroll, since the beginning of the scroll has been
// consumed. The queued event with different modifiers should be sent to the
// renderer.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
// Indicate the end of the scrolling from the touchpad.
SimulateGestureFlingStartEvent(-1200.f, 0.f, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Start another scroll. This time, do not consume any scroll events.
SimulateWheelEvent(0, -5, 0, true); // sent directly
SimulateWheelEvent(0, -1, 0, true); // enqueued
SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-20, 6, 1, true); // enqueued, different modifiers
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK for the first wheel and the subsequent coalesced event as not
// processed. This should start a back-overscroll.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
}
// Tests that wheel-scrolling correctly turns overscroll on and off.
TEST_F(RenderWidgetHostViewAuraOverscrollTest, WheelScrollOverscrollToggle) {
SetUpOverscrollEnvironment();
// Send a wheel event. ACK the event as not processed. This should not
// initiate an overscroll gesture since it doesn't cross the threshold yet.
SimulateWheelEvent(10, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Scroll some more so as to not overscroll.
SimulateWheelEvent(10, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Scroll some more to initiate an overscroll.
SimulateWheelEvent(40, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(60.f, overscroll_delta_x());
EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Scroll in the reverse direction enough to abort the overscroll.
SimulateWheelEvent(-20, 0, 0, true);
EXPECT_EQ(0U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
// Continue to scroll in the reverse direction.
SimulateWheelEvent(-20, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Continue to scroll in the reverse direction enough to initiate overscroll
// in that direction.
SimulateWheelEvent(-55, 0, 0, true);
EXPECT_EQ(1U, sink_->message_count());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
EXPECT_EQ(-75.f, overscroll_delta_x());
EXPECT_EQ(-25.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
}
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
ScrollEventsOverscrollWithFling) {
SetUpOverscrollEnvironment();
// Send a wheel event. ACK the event as not processed. This should not
// initiate an overscroll gesture since it doesn't cross the threshold yet.
SimulateWheelEvent(10, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Scroll some more so as to not overscroll.
SimulateWheelEvent(20, 0, 0, true);
EXPECT_EQ(1U, sink_->message_count());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
sink_->ClearMessages();
// Scroll some more to initiate an overscroll.
SimulateWheelEvent(30, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(60.f, overscroll_delta_x());
EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send a fling start, but with a small velocity, so that the overscroll is
// aborted. The fling should proceed to the renderer, through the gesture
// event filter.
SimulateGestureFlingStartEvent(0.f, 0.1f, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, sink_->message_count());
}
// Same as ScrollEventsOverscrollWithFling, but with zero velocity. Checks that
// the zero-velocity fling does not reach the renderer.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
ScrollEventsOverscrollWithZeroFling) {
SetUpOverscrollEnvironment();
// Send a wheel event. ACK the event as not processed. This should not
// initiate an overscroll gesture since it doesn't cross the threshold yet.
SimulateWheelEvent(10, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Scroll some more so as to not overscroll.
SimulateWheelEvent(20, 0, 0, true);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
// Scroll some more to initiate an overscroll.
SimulateWheelEvent(30, 0, 0, true);
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(60.f, overscroll_delta_x());
EXPECT_EQ(10.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send a fling start, but with a small velocity, so that the overscroll is
// aborted. The fling should proceed to the renderer, through the gesture
// event filter.
SimulateGestureFlingStartEvent(10.f, 0.f, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, sink_->message_count());
}
// Tests that a fling in the opposite direction of the overscroll cancels the
// overscroll nav instead of completing it.
TEST_F(RenderWidgetHostViewAuraOverscrollTest, ReverseFlingCancelsOverscroll) {
SetUpOverscrollEnvironment();
{
// Start and end a gesture in the same direction without processing the
// gesture events in the renderer. This should initiate and complete an
// overscroll navigation.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureScrollUpdateEvent(300, -5, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
sink_->ClearMessages();
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, sink_->message_count());
}
{
// Start over, except instead of ending the gesture with ScrollEnd, end it
// with a FlingStart, with velocity in the reverse direction. This should
// initiate an overscroll navigation, but it should be cancelled because of
// the fling in the opposite direction.
overscroll_delegate()->Reset();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureScrollUpdateEvent(-300, -5, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
sink_->ClearMessages();
SimulateGestureFlingStartEvent(100, 0, blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, sink_->message_count());
}
}
// Tests that touch-scroll events are handled correctly by the overscroll
// controller. This also tests that the overscroll controller and the
// gesture-event filter play nice with each other.
TEST_F(RenderWidgetHostViewAuraOverscrollTest, GestureScrollOverscrolls) {
SetUpOverscrollEnvironment();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send another gesture event and ACK as not being processed. This should
// initiate the navigation gesture.
SimulateGestureScrollUpdateEvent(55, -5, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(55.f, overscroll_delta_x());
EXPECT_EQ(-5.f, overscroll_delta_y());
EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send another gesture update event. This event should be consumed by the
// controller, and not be forwarded to the renderer. The gesture-event filter
// should not also receive this event.
SimulateGestureScrollUpdateEvent(10, -5, 0);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(65.f, overscroll_delta_x());
EXPECT_EQ(-10.f, overscroll_delta_y());
EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
EXPECT_EQ(-10.f, overscroll_delegate()->delta_y());
EXPECT_EQ(0U, sink_->message_count());
// Now send a scroll end. This should cancel the overscroll gesture, and send
// the event to the renderer. The gesture-event filter should receive this
// event.
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, sink_->message_count());
}
// Tests that if the page is scrolled because of a scroll-gesture, then that
// particular scroll sequence never generates overscroll if the scroll direction
// is horizontal.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
GestureScrollConsumedHorizontal) {
SetUpOverscrollEnvironment();
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureScrollUpdateEvent(10, 0, 0);
// Start scrolling on content. ACK both events as being processed.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
sink_->ClearMessages();
// Send another gesture event and ACK as not being processed. This should
// not initiate overscroll because the beginning of the scroll event did
// scroll some content on the page. Since there was no overscroll, the event
// should reach the renderer.
SimulateGestureScrollUpdateEvent(55, 0, 0);
EXPECT_EQ(1U, sink_->message_count());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
}
// Tests that the overscroll controller plays nice with touch-scrolls and the
// gesture event filter with debounce filtering turned on.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
GestureScrollDebounceOverscrolls) {
SetUpOverscrollEnvironmentWithDebounce(100);
// Start scrolling. Receive ACK as it being processed.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send update events.
SimulateGestureScrollUpdateEvent(25, 0, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Quickly end and restart the scroll gesture. These two events should get
// discarded.
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, sink_->message_count());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, sink_->message_count());
// Send another update event. This should get into the queue.
SimulateGestureScrollUpdateEvent(30, 0, 0);
EXPECT_EQ(0U, sink_->message_count());
// Receive an ACK for the first scroll-update event as not being processed.
// This will contribute to the overscroll gesture, but not enough for the
// overscroll controller to start consuming gesture events. This also cause
// the queued gesture event to be forwarded to the renderer.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send another update event. This should get into the queue.
SimulateGestureScrollUpdateEvent(10, 0, 0);
EXPECT_EQ(0U, sink_->message_count());
// Receive an ACK for the second scroll-update event as not being processed.
// This will now initiate an overscroll. This will also cause the queued
// gesture event to be released. But instead of going to the renderer, it will
// be consumed by the overscroll controller.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(65.f, overscroll_delta_x());
EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(0U, sink_->message_count());
}
// Tests that the gesture debounce timer plays nice with the overscroll
// controller.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
GestureScrollDebounceTimerOverscroll) {
SetUpOverscrollEnvironmentWithDebounce(10);
// Start scrolling. Receive ACK as it being processed.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send update events.
SimulateGestureScrollUpdateEvent(55, 0, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send an end event. This should get in the debounce queue.
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, sink_->message_count());
// Receive ACK for the scroll-update event.
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(55.f, overscroll_delta_x());
EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(0U, sink_->message_count());
// Let the timer for the debounce queue fire. That should release the queued
// scroll-end event. Since overscroll has started, but there hasn't been
// enough overscroll to complete the gesture, the overscroll controller
// will reset the state. The scroll-end should therefore be dispatched to the
// renderer, and the gesture-event-filter should await an ACK for it.
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(15));
base::MessageLoop::current()->Run();
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, sink_->message_count());
}
// Tests that when touch-events are dispatched to the renderer, the overscroll
// gesture deals with them correctly.
TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollWithTouchEvents) {
SetUpOverscrollEnvironmentWithDebounce(10);
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
sink_->ClearMessages();
// The test sends an intermingled sequence of touch and gesture events.
PressTouchPoint(0, 1);
SendInputEventACK(WebInputEvent::TouchStart,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
MoveTouchPoint(0, 20, 5);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::TouchMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureScrollUpdateEvent(20, 0, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
// Another touch move event should reach the renderer since overscroll hasn't
// started yet. Note that touch events sent during the scroll period may
// not require an ack (having been marked uncancelable).
MoveTouchPoint(0, 65, 10);
AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureScrollUpdateEvent(45, 0, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(65.f, overscroll_delta_x());
EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send another touch event. The page should get the touch-move event, even
// though overscroll has started.
MoveTouchPoint(0, 55, 5);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(65.f, overscroll_delta_x());
EXPECT_EQ(15.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureScrollUpdateEvent(-10, 0, 0);
EXPECT_EQ(0U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(55.f, overscroll_delta_x());
EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
PressTouchPoint(255, 5);
AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureScrollUpdateEvent(200, 0, 0);
EXPECT_EQ(0U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(255.f, overscroll_delta_x());
EXPECT_EQ(205.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
// The touch-end/cancel event should always reach the renderer if the page has
// touch handlers.
ReleaseTouchPoint(1);
AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
ReleaseTouchPoint(0);
AckLastSentInputEventIfNecessary(INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(10));
base::MessageLoop::current()->Run();
EXPECT_EQ(1U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
}
// Tests that touch-gesture end is dispatched to the renderer at the end of a
// touch-gesture initiated overscroll.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
TouchGestureEndDispatchedAfterOverscrollComplete) {
SetUpOverscrollEnvironmentWithDebounce(10);
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
sink_->ClearMessages();
// Start scrolling. Receive ACK as it being processed.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The scroll begin event will have received a synthetic ack from the input
// router.
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
// Send update events.
SimulateGestureScrollUpdateEvent(55, -5, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(55.f, overscroll_delta_x());
EXPECT_EQ(5.f, overscroll_delegate()->delta_x());
EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
// Send end event.
SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, sink_->message_count());
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(10));
base::MessageLoop::current()->Run();
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Start scrolling. Receive ACK as it being processed.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
// Send update events.
SimulateGestureScrollUpdateEvent(235, -5, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(0U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(235.f, overscroll_delta_x());
EXPECT_EQ(185.f, overscroll_delegate()->delta_x());
EXPECT_EQ(-5.f, overscroll_delegate()->delta_y());
// Send end event.
SimulateGestureEvent(blink::WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, sink_->message_count());
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(10));
base::MessageLoop::current()->Run();
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
EXPECT_EQ(1U, sink_->message_count());
}
TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollDirectionChange) {
SetUpOverscrollEnvironmentWithDebounce(100);
// Start scrolling. Receive ACK as it being processed.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Send update events and receive ack as not consumed.
SimulateGestureScrollUpdateEvent(125, -5, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(0U, sink_->message_count());
// Send another update event, but in the reverse direction. The overscroll
// controller will not consume the event, because it is not triggering
// gesture-nav.
SimulateGestureScrollUpdateEvent(-260, 0, 0);
EXPECT_EQ(1U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
// Since the overscroll mode has been reset, the next scroll update events
// should reach the renderer.
SimulateGestureScrollUpdateEvent(-20, 0, 0);
EXPECT_EQ(1U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
}
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
OverscrollDirectionChangeMouseWheel) {
SetUpOverscrollEnvironment();
// Send wheel event and receive ack as not consumed.
SimulateWheelEvent(125, -5, 0, true);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(0U, sink_->message_count());
// Send another wheel event, but in the reverse direction. The overscroll
// controller will not consume the event, because it is not triggering
// gesture-nav.
SimulateWheelEvent(-260, 0, 0, true);
EXPECT_EQ(1U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
// Since the overscroll mode has been reset, the next wheel event should reach
// the renderer.
SimulateWheelEvent(-20, 0, 0, true);
EXPECT_EQ(1U, sink_->message_count());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
}
// Tests that if a mouse-move event completes the overscroll gesture, future
// move events do reach the renderer.
TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) {
SetUpOverscrollEnvironment();
SimulateWheelEvent(5, 0, 0, true); // sent directly
SimulateWheelEvent(-1, 0, 0, true); // enqueued
SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event
SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event
SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK the first wheel event as not processed.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Receive ACK for the second (coalesced) event as not processed. This will
// start an overcroll gesture.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->current_mode());
EXPECT_EQ(0U, sink_->message_count());
// Send a mouse-move event. This should cancel the overscroll navigation
// (since the amount overscrolled is not above the threshold), and so the
// mouse-move should reach the renderer.
SimulateMouseMove(5, 10, 0);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
// Moving the mouse more should continue to send the events to the renderer.
SimulateMouseMove(5, 10, 0);
SendInputEventACK(WebInputEvent::MouseMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Now try with gestures.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureScrollUpdateEvent(300, -5, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
sink_->ClearMessages();
// Overscroll gesture is in progress. Send a mouse-move now. This should
// complete the gesture (because the amount overscrolled is above the
// threshold).
SimulateMouseMove(5, 10, 0);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Move mouse some more. The mouse-move events should reach the renderer.
SimulateMouseMove(5, 10, 0);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
}
// Tests that if a page scrolled, then the overscroll controller's states are
// reset after the end of the scroll.
TEST_F(RenderWidgetHostViewAuraOverscrollTest,
OverscrollStateResetsAfterScroll) {
SetUpOverscrollEnvironment();
SimulateWheelEvent(0, 5, 0, true); // sent directly
SimulateWheelEvent(0, 30, 0, true); // enqueued
SimulateWheelEvent(0, 40, 0, true); // coalesced into previous event
SimulateWheelEvent(0, 10, 0, true); // coalesced into previous event
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The first wheel event is consumed. Dispatches the queued wheel event.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_TRUE(ScrollStateIsContentScrolling());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The second wheel event is consumed.
SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED);
EXPECT_TRUE(ScrollStateIsContentScrolling());
// Touchpad scroll can end with a zero-velocity fling. But it is not
// dispatched, but it should still reset the overscroll controller state.
SimulateGestureFlingStartEvent(0.f, 0.f, blink::WebGestureDeviceTouchpad);
EXPECT_TRUE(ScrollStateIsUnknown());
EXPECT_EQ(0U, sink_->message_count());
SimulateWheelEvent(-5, 0, 0, true); // sent directly
SimulateWheelEvent(-60, 0, 0, true); // enqueued
SimulateWheelEvent(-100, 0, 0, true); // coalesced into previous event
EXPECT_TRUE(ScrollStateIsUnknown());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// The first wheel scroll did not scroll content. Overscroll should not start
// yet, since enough hasn't been scrolled.
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_TRUE(ScrollStateIsUnknown());
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
SendInputEventACK(WebInputEvent::MouseWheel,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_WEST, overscroll_mode());
EXPECT_TRUE(ScrollStateIsOverscrolling());
EXPECT_EQ(0U, sink_->message_count());
SimulateGestureFlingStartEvent(0.f, 0.f, blink::WebGestureDeviceTouchpad);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_WEST, overscroll_delegate()->completed_mode());
EXPECT_TRUE(ScrollStateIsUnknown());
EXPECT_EQ(0U, sink_->message_count());
}
TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollResetsOnBlur) {
SetUpOverscrollEnvironment();
// Start an overscroll with gesture scroll. In the middle of the scroll, blur
// the host.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureScrollUpdateEvent(300, -5, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
view_->OnWindowFocused(NULL, view_->GetAttachedWindow());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
EXPECT_EQ(0.f, overscroll_delegate()->delta_x());
EXPECT_EQ(0.f, overscroll_delegate()->delta_y());
sink_->ClearMessages();
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
// Start a scroll gesture again. This should correctly start the overscroll
// after the threshold.
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
SimulateGestureScrollUpdateEvent(300, -5, 0);
SendInputEventACK(WebInputEvent::GestureScrollUpdate,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode());
SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode());
EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode());
EXPECT_EQ(3U, sink_->message_count());
}
// Tests that when view initiated shutdown happens (i.e. RWHView is deleted
// before RWH), we clean up properly and don't leak the RWHVGuest.
TEST_F(RenderWidgetHostViewGuestAuraTest, GuestViewDoesNotLeak) {
TearDownEnvironment();
ASSERT_FALSE(guest_view_weak_.get());
}
// Tests that invalid touch events are consumed and handled
// synchronously.
TEST_F(RenderWidgetHostViewAuraTest,
InvalidEventsHaveSyncHandlingDisabled) {
view_->InitAsChild(NULL);
view_->Show();
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0,
ui::EventTimeForNow());
// Construct a move with a touch id which doesn't exist.
ui::TouchEvent invalid_move(ui::ET_TOUCH_MOVED, gfx::Point(30, 30), 1,
ui::EventTimeForNow());
view_->OnTouchEvent(&press);
view_->OnTouchEvent(&invalid_move);
// Valid press is handled asynchronously.
EXPECT_TRUE(press.synchronous_handling_disabled());
// Invalid move is handled synchronously, but is consumed.
EXPECT_FALSE(invalid_move.synchronous_handling_disabled());
EXPECT_TRUE(invalid_move.stopped_propagation());
}
// Checks key event codes.
TEST_F(RenderWidgetHostViewAuraTest, KeyEvent) {
view_->InitAsChild(NULL);
view_->Show();
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::KEY_A,
ui::EF_NONE);
view_->OnKeyEvent(&key_event);
const NativeWebKeyboardEvent* event = delegate_.last_event();
EXPECT_NE(nullptr, event);
if (event) {
EXPECT_EQ(key_event.key_code(), event->windowsKeyCode);
EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()),
event->nativeKeyCode);
}
}
} // namespace content
|