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
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/webid/fedcm_account_selection_view_desktop.h"
#include <memory>
#include <string>
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
#include "chrome/browser/ui/views/webid/account_selection_bubble_view.h"
#include "chrome/browser/ui/views/webid/account_selection_view_test_base.h"
#include "chrome/browser/ui/webid/identity_ui_utils.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/tabs/public/mock_tab_interface.h"
#include "content/public/browser/identity_request_dialog_controller.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/test/mock_input_event_activation_protector.h"
#include "url/gurl.h"
namespace webid {
using LoginState = content::IdentityRequestAccount::LoginState;
using SignInMode = content::IdentityRequestAccount::SignInMode;
using TokenError = content::IdentityCredentialTokenError;
using DismissReason = content::IdentityRequestDialogController::DismissReason;
class FedCmAccountSelectionViewDesktopTest;
// Mock AccountSelectionViewBase which tracks state.
class TestAccountSelectionView : public AccountSelectionViewBase,
public views::WidgetDelegate {
public:
explicit TestAccountSelectionView(FedCmAccountSelectionView* owner)
: AccountSelectionViewBase(
owner,
/*url_loader_factory=*/nullptr,
content::RelyingPartyData(/*rp_for_display=*/u"",
/*iframe_for_display=*/u""),
/*device_scale_factor=*/1.f) {
// This matches behavior of the production code, which implicitly passes
// ownership of the view to the widget via DialogDelegate superclass.
SetOwnedByWidget(OwnedByWidgetPassKey());
}
enum class SheetType {
kAccountPicker,
kConfirmAccount,
kVerifying,
kFailure,
kError,
kRequestPermission,
kLoading,
};
~TestAccountSelectionView() override = default;
TestAccountSelectionView(const TestAccountSelectionView&) = delete;
TestAccountSelectionView& operator=(const TestAccountSelectionView&) = delete;
void ShowMultiAccountPicker(
const std::vector<IdentityRequestAccountPtr>& accounts,
const std::vector<IdentityProviderDataPtr>& idp_list,
const gfx::Image& rp_icon,
bool show_back_button) override {
show_back_button_ = show_back_button;
sheet_type_ = SheetType::kAccountPicker;
account_ids_.clear();
for (const auto& account : accounts) {
account_ids_.push_back(account->id);
}
}
void ShowVerifyingSheet(const IdentityRequestAccountPtr& account,
const std::u16string& title) override {
sheet_type_ = SheetType::kVerifying;
account_ids_ = {account->id};
show_back_button_ = false;
}
void ShowSingleAccountConfirmDialog(const IdentityRequestAccountPtr& account,
bool show_back_button) override {
show_back_button_ = show_back_button;
sheet_type_ = SheetType::kConfirmAccount;
account_ids_ = {account->id};
}
void ShowFailureDialog(
const std::u16string& idp_for_display,
const content::IdentityProviderMetadata& idp_metadata) override {
sheet_type_ = SheetType::kFailure;
account_ids_ = {};
show_back_button_ = false;
}
void ShowErrorDialog(const std::u16string& idp_for_display,
const content::IdentityProviderMetadata& idp_metadata,
const std::optional<TokenError>& error) override {
sheet_type_ = SheetType::kError;
account_ids_ = {};
show_back_button_ = false;
}
void ShowRequestPermissionDialog(
const IdentityRequestAccountPtr& account) override {
show_back_button_ = true;
sheet_type_ = SheetType::kRequestPermission;
account_ids_ = {account->id};
}
std::string GetDialogTitle() const override { return std::string(); }
std::optional<std::string> GetDialogSubtitle() const override {
return std::nullopt;
}
bool show_back_button_{false};
std::optional<SheetType> sheet_type_{SheetType::kLoading};
std::vector<std::string> account_ids_;
};
namespace {
constexpr char16_t kTopFrameEtldPlusOne[] = u"top-frame-example.com";
constexpr char kIdpEtldPlusOne[] = "idp-example.com";
constexpr char kConfigUrl[] = "https://idp-example.com/fedcm.json";
constexpr char kLoginUrl[] = "https://idp-example.com/login";
constexpr char kAccountId1[] = "account_id1";
constexpr char kAccountId2[] = "account_id2";
// Mock version of FedCmModalDialogView for injection during tests.
class MockFedCmModalDialogView : public FedCmModalDialogView {
public:
explicit MockFedCmModalDialogView(content::WebContents* web_contents,
FedCmModalDialogView::Observer* observer)
: FedCmModalDialogView(web_contents, observer) {}
~MockFedCmModalDialogView() override = default;
MockFedCmModalDialogView(const MockFedCmModalDialogView&) = delete;
MockFedCmModalDialogView& operator=(const MockFedCmModalDialogView&) = delete;
content::WebContents* ShowPopupWindow(const GURL& url,
bool user_close_cancels_flow) override {
user_close_cancels_flow_ = user_close_cancels_flow;
++show_popup_window_count_;
return nullptr;
}
bool UserCloseCancelsFlow() override { return user_close_cancels_flow_; }
void SetCustomYPosition(int y) override { ++set_custom_y_position_count_; }
void SetActiveModeSheetType(webid::SheetType) override {
++set_active_mode_sheet_type_count_;
}
MOCK_METHOD(void, ClosePopupWindow, (), (override));
MOCK_METHOD(void, ResizeAndFocusPopupWindow, (), (override));
bool user_close_cancels_flow_ = false;
int show_popup_window_count_ = 0;
int set_custom_y_position_count_ = 0;
int set_active_mode_sheet_type_count_ = 0;
};
class FakeTabInterface : public tabs::MockTabInterface {
public:
explicit FakeTabInterface(content::WebContents* contents)
: contents_(contents) {}
content::WebContents* GetContents() const override { return contents_; }
void SetIsActivated(bool active) { is_activated = active; }
bool IsActivated() const override { return is_activated; }
bool CanShowModalUI() const override { return true; }
private:
raw_ptr<content::WebContents> contents_;
bool is_activated = true;
};
// Test FedCmAccountSelectionView which uses TestAccountSelectionView.
class TestFedCmAccountSelectionView : public FedCmAccountSelectionView {
public:
TestFedCmAccountSelectionView(Delegate* delegate,
tabs::TabInterface* tab,
FedCmAccountSelectionViewDesktopTest* test)
: FedCmAccountSelectionView(delegate, tab), test_(test) {
auto input_protector =
std::make_unique<views::MockInputEventActivationProtector>();
ON_CALL(*input_protector, IsPossiblyUnintendedInteraction)
.WillByDefault(testing::Return(false));
SetInputEventActivationProtectorForTesting(std::move(input_protector));
}
TestFedCmAccountSelectionView(const TestFedCmAccountSelectionView&) = delete;
TestFedCmAccountSelectionView& operator=(
const TestFedCmAccountSelectionView&) = delete;
blink::mojom::RpContext GetRpContext() { return rp_context_; }
size_t num_dialogs_{0u};
bool can_fit_in_web_contents_{true};
bool dialog_position_updated_{false};
TestAccountSelectionView* GetTestView() {
return static_cast<TestAccountSelectionView*>(account_selection_view());
}
MockFedCmModalDialogView* GetPopupWindow() {
return static_cast<MockFedCmModalDialogView*>(GetPopupWindowForTesting());
}
protected:
AccountSelectionViewBase* CreateDialogView(
bool has_modal_support,
const content::RelyingPartyData& rp_data,
const std::optional<std::u16string>& idp_title,
blink::mojom::RpContext rp_context,
blink::mojom::RpMode rp_mode,
DialogType* out_dialog_type) override {
++num_dialogs_;
rp_context_ = rp_context;
if (rp_mode == blink::mojom::RpMode::kActive && has_modal_support) {
*out_dialog_type = FedCmAccountSelectionView::DialogType::MODAL;
} else {
*out_dialog_type = FedCmAccountSelectionView::DialogType::BUBBLE;
}
return new TestAccountSelectionView(this);
}
bool CanFitInWebContents() override { return can_fit_in_web_contents_; }
void UpdateDialogPosition() override { dialog_position_updated_ = true; }
std::unique_ptr<views::Widget> CreateDialogWidget() override;
std::unique_ptr<FedCmModalDialogView> CreatePopupWindow() override;
private:
blink::mojom::RpContext rp_context_;
raw_ptr<FedCmAccountSelectionViewDesktopTest> test_;
};
// Stub AccountSelectionView::Delegate.
class StubAccountSelectionViewDelegate : public AccountSelectionView::Delegate {
public:
explicit StubAccountSelectionViewDelegate(content::WebContents* web_contents)
: web_contents_(web_contents) {}
~StubAccountSelectionViewDelegate() override = default;
StubAccountSelectionViewDelegate(const StubAccountSelectionViewDelegate&) =
delete;
StubAccountSelectionViewDelegate& operator=(
const StubAccountSelectionViewDelegate&) = delete;
void OnAccountSelected(
const GURL&,
const std::string&,
const content::IdentityRequestAccount::LoginState&) override {}
void OnDismiss(DismissReason dismiss_reason) override {
dismiss_reason_ = dismiss_reason;
if (on_dismiss_) {
std::move(on_dismiss_).Run();
}
}
void OnLoginToIdP(const GURL& idp_config_url,
const GURL& idp_login_url) override {}
void OnMoreDetails() override {}
void OnAccountsDisplayed() override {}
gfx::NativeView GetNativeView() override { return gfx::NativeView(); }
content::WebContents* GetWebContents() override { return web_contents_; }
std::optional<DismissReason> GetDismissReason() { return dismiss_reason_; }
void SetOnDismissClosure(base::OnceClosure on_dismiss) {
on_dismiss_ = std::move(on_dismiss);
}
private:
raw_ptr<content::WebContents> web_contents_;
std::optional<DismissReason> dismiss_reason_;
base::OnceClosure on_dismiss_;
};
content::RelyingPartyData GetRpData() {
return content::RelyingPartyData(kTopFrameEtldPlusOne,
/*iframe_for_display=*/u"");
}
} // namespace
class FedCmAccountSelectionViewDesktopTest : public ChromeViewsTestBase {
public:
void SetUp() override {
ChromeViewsTestBase::SetUp();
test_web_contents_ =
content::WebContentsTester::CreateTestWebContents(&profile_, nullptr);
tab_interface_ =
std::make_unique<FakeTabInterface>(test_web_contents_.get());
delegate_ = std::make_unique<StubAccountSelectionViewDelegate>(
test_web_contents_.get());
histogram_tester_ = std::make_unique<base::HistogramTester>();
idp_data_ = CreateIdentityProviderData();
accounts_ = {CreateAccount(idp_data_)};
new_accounts_ = {CreateAccount(idp_data_)};
}
IdentityProviderDataPtr CreateIdentityProviderData(
bool has_login_status_mismatch = false,
const std::vector<content::IdentityRequestDialogDisclosureField>&
disclosure_fields = kDefaultDisclosureFields) {
return base::MakeRefCounted<content::IdentityProviderData>(
/*idp_for_display=*/"", content::IdentityProviderMetadata(),
content::ClientMetadata(GURL(), GURL(), GURL(), gfx::Image()),
blink::mojom::RpContext::kSignIn, /*format=*/std::nullopt,
disclosure_fields, has_login_status_mismatch);
}
IdentityRequestAccountPtr CreateAccount(
IdentityProviderDataPtr idp,
LoginState idp_claimed_login_state = LoginState::kSignUp,
LoginState browser_trusted_login_state = LoginState::kSignUp,
std::string account_id = kAccountId1) {
IdentityRequestAccountPtr account = base::MakeRefCounted<Account>(
account_id, "", "", "", "", "", GURL(), "", "",
/*login_hints=*/std::vector<std::string>(),
/*domain_hints=*/std::vector<std::string>(),
/*labels=*/std::vector<std::string>(),
/*login_state=*/idp_claimed_login_state,
/*browser_trusted_login_state=*/browser_trusted_login_state);
if (idp_claimed_login_state == LoginState::kSignUp) {
account->fields = idp->disclosure_fields;
}
account->identity_provider = std::move(idp);
return account;
}
std::vector<IdentityRequestAccountPtr> CreateAccounts(
const std::vector<std::pair<std::string, LoginState>>& account_infos,
IdentityProviderDataPtr idp_data) {
std::vector<IdentityRequestAccountPtr> accounts;
for (const auto& account_info : account_infos) {
accounts.emplace_back(base::MakeRefCounted<Account>(
account_info.first, "", "", "", "", "", GURL(), "", "",
/*login_hints=*/std::vector<std::string>(),
/*domain_hints=*/std::vector<std::string>(),
/*labels=*/std::vector<std::string>(),
/*login_state=*/account_info.second,
/*browser_trusted_login_state=*/account_info.second));
if (account_info.second == LoginState::kSignUp) {
accounts.back()->fields = idp_data->disclosure_fields;
}
accounts.back()->identity_provider = idp_data;
}
return accounts;
}
std::unique_ptr<TestFedCmAccountSelectionView> CreateAndShow(
const std::vector<IdentityRequestAccountPtr>& accounts,
blink::mojom::RpMode rp_mode = blink::mojom::RpMode::kPassive) {
auto controller = std::make_unique<TestFedCmAccountSelectionView>(
delegate_.get(), tab_interface_.get(), this);
Show(*controller, accounts, rp_mode);
return controller;
}
void Show(TestFedCmAccountSelectionView& controller,
const std::vector<IdentityRequestAccountPtr>& accounts,
blink::mojom::RpMode rp_mode,
const std::vector<IdentityRequestAccountPtr>& new_accounts =
std::vector<IdentityRequestAccountPtr>()) {
controller.Show(content::RelyingPartyData(kTopFrameEtldPlusOne,
/*iframe_for_display=*/u""),
{idp_data_}, accounts, rp_mode, new_accounts);
}
std::unique_ptr<TestFedCmAccountSelectionView> CreateAndShowMismatchDialog(
blink::mojom::RpContext rp_context = blink::mojom::RpContext::kSignIn,
blink::mojom::RpMode rp_mode = blink::mojom::RpMode::kPassive) {
auto controller = std::make_unique<TestFedCmAccountSelectionView>(
delegate_.get(), tab_interface_.get(), this);
controller->ShowFailureDialog(GetRpData(), kIdpEtldPlusOne, rp_context,
rp_mode, content::IdentityProviderMetadata());
EXPECT_EQ(TestAccountSelectionView::SheetType::kFailure,
controller->GetTestView()->sheet_type_);
return controller;
}
std::unique_ptr<TestFedCmAccountSelectionView> CreateAndShowErrorDialog(
blink::mojom::RpContext rp_context = blink::mojom::RpContext::kSignIn,
blink::mojom::RpMode rp_mode = blink::mojom::RpMode::kPassive) {
auto controller = std::make_unique<TestFedCmAccountSelectionView>(
delegate_.get(), tab_interface_.get(), this);
controller->ShowErrorDialog(GetRpData(), kIdpEtldPlusOne, rp_context,
rp_mode, content::IdentityProviderMetadata(),
/*error=*/std::nullopt);
EXPECT_EQ(TestAccountSelectionView::SheetType::kError,
controller->GetTestView()->sheet_type_);
return controller;
}
std::unique_ptr<TestFedCmAccountSelectionView> CreateAndShowLoadingDialog(
blink::mojom::RpContext rp_context = blink::mojom::RpContext::kSignIn,
blink::mojom::RpMode rp_mode = blink::mojom::RpMode::kActive) {
auto controller = std::make_unique<TestFedCmAccountSelectionView>(
delegate_.get(), tab_interface_.get(), this);
controller->ShowLoadingDialog(GetRpData(), kIdpEtldPlusOne, rp_context,
rp_mode);
EXPECT_EQ(TestAccountSelectionView::SheetType::kLoading,
controller->GetTestView()->sheet_type_);
return controller;
}
std::unique_ptr<TestFedCmAccountSelectionView> CreateAndShowVerifyingDialog(
const IdentityRequestAccountPtr& account,
Account::SignInMode sign_in_mode,
blink::mojom::RpMode rp_mode) {
auto controller = std::make_unique<TestFedCmAccountSelectionView>(
delegate_.get(), tab_interface_.get(), this);
controller->ShowVerifyingDialog(GetRpData(), {idp_data_}, account,
sign_in_mode, rp_mode);
return controller;
}
void CreateAndShowPopupWindow(TestFedCmAccountSelectionView& controller) {
int show_count = controller.GetPopupWindow()
? controller.GetPopupWindow()->show_popup_window_count_
: 0;
controller.ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kPassive);
EXPECT_EQ(controller.GetPopupWindow()->show_popup_window_count_,
show_count + 1);
}
std::unique_ptr<TestFedCmAccountSelectionView> CreateAndShowMultiIdp(
const std::vector<IdentityProviderDataPtr>& idp_list,
const std::vector<IdentityRequestAccountPtr>& accounts,
blink::mojom::RpMode rp_mode) {
auto controller = std::make_unique<TestFedCmAccountSelectionView>(
delegate_.get(), tab_interface_.get(), this);
controller->Show(content::RelyingPartyData(kTopFrameEtldPlusOne,
/*iframe_for_display=*/u""),
idp_list, accounts, rp_mode,
/*new_accounts=*/std::vector<IdentityRequestAccountPtr>());
return controller;
}
void OpenLoginToIdpPopup(TestFedCmAccountSelectionView* controller) {
controller->OnLoginToIdP(GURL(kConfigUrl), GURL(kLoginUrl),
CreateMouseEvent());
CreateAndShowPopupWindow(*controller);
}
std::unique_ptr<TestFedCmAccountSelectionView>
CreateAndShowAccountsModalThroughPopupWindow(
const std::vector<IdentityRequestAccountPtr>& all_accounts,
const std::vector<IdentityRequestAccountPtr>& new_accounts) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
// Emulate the login to IdP flow.
OpenLoginToIdpPopup(controller.get());
// Emulate user completing the sign-in flow and IdP prompts closing the
// pop-up window and sending new accounts.
controller->CloseModalDialog();
Show(*controller, all_accounts, blink::mojom::RpMode::kActive,
new_accounts);
return controller;
}
std::unique_ptr<TestFedCmAccountSelectionView>
CreateAndShowAccountsThroughUseAnotherAccount(
const std::vector<std::pair<std::string, LoginState>>& old_account_infos,
const std::vector<std::pair<std::string, LoginState>>& new_account_infos,
blink::mojom::RpMode rp_mode = blink::mojom::RpMode::kPassive) {
accounts_ = CreateAccounts(old_account_infos, idp_data_);
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, rp_mode);
// Emulate the user clicking "use another account button".
OpenLoginToIdpPopup(controller.get());
// Emulate user completing the sign-in flow and IdP prompts closing the
// pop-up window and sending new accounts.
controller->CloseModalDialog();
new_accounts_ = CreateAccounts(new_account_infos, idp_data_);
std::vector<std::pair<std::string, LoginState>> combined_account_infos =
old_account_infos;
for (const auto& account_info : new_account_infos) {
if (std::find(combined_account_infos.begin(),
combined_account_infos.end(),
account_info) != combined_account_infos.end()) {
continue;
}
combined_account_infos.emplace_back(account_info);
}
const std::vector<IdentityRequestAccountPtr> combined_accounts =
CreateAccounts(combined_account_infos, idp_data_);
Show(*controller, combined_accounts, rp_mode, new_accounts_);
return controller;
}
ui::MouseEvent CreateMouseEvent() {
return ui::MouseEvent(ui::EventType::kMousePressed, gfx::Point(),
gfx::Point(), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0);
}
void TabWillEnterBackground(TestFedCmAccountSelectionView* view) {
view->TabWillEnterBackground(tab_interface_.get());
tab_interface_->SetIsActivated(false);
}
void TabForegrounded(TestFedCmAccountSelectionView* view) {
tab_interface_->SetIsActivated(true);
view->TabForegrounded(tab_interface_.get());
}
content::WebContents* test_web_contents() { return test_web_contents_.get(); }
protected:
TestingProfile profile_;
// This enables uses of TestWebContents.
content::RenderViewHostTestEnabler test_render_host_factories_;
std::unique_ptr<content::WebContents> test_web_contents_;
std::unique_ptr<FakeTabInterface> tab_interface_;
std::unique_ptr<views::Widget> dialog_widget_;
std::unique_ptr<StubAccountSelectionViewDelegate> delegate_;
std::unique_ptr<base::HistogramTester> histogram_tester_;
IdentityProviderDataPtr idp_data_;
std::vector<IdentityRequestAccountPtr> accounts_;
std::vector<IdentityRequestAccountPtr> new_accounts_;
};
namespace {
std::unique_ptr<views::Widget>
TestFedCmAccountSelectionView::CreateDialogWidget() {
views::Widget::InitParams params =
test_->CreateParams(views::Widget::InitParams::CLIENT_OWNS_WIDGET,
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.delegate = GetTestView();
return test_->CreateTestWidget(std::move(params));
}
std::unique_ptr<FedCmModalDialogView>
TestFedCmAccountSelectionView::CreatePopupWindow() {
return std::make_unique<MockFedCmModalDialogView>(test_->test_web_contents(),
this);
}
} // namespace
TEST_F(FedCmAccountSelectionViewDesktopTest, SingleAccountFlow) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
TEST_F(FedCmAccountSelectionViewDesktopTest, MultipleAccountFlowReturning) {
accounts_ = CreateAccounts(
{{kAccountId1, LoginState::kSignIn}, {kAccountId2, LoginState::kSignIn}},
idp_data_);
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
TEST_F(FedCmAccountSelectionViewDesktopTest, MultipleAccountFlowBack) {
accounts_ = CreateAccounts(
{{kAccountId1, LoginState::kSignUp}, {kAccountId2, LoginState::kSignUp}},
idp_data_);
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnBackButtonClicked();
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[1], CreateMouseEvent());
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
controller->OnAccountSelected(accounts_[1], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
}
// Test transitioning from IdP sign-in status mismatch failure dialog to regular
// sign-in dialog.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusMismatchDialogToSigninFlow) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
EXPECT_EQ(TestAccountSelectionView::SheetType::kFailure,
controller->GetTestView()->sheet_type_);
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
controller->OnAccountSelected(new_accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_EQ(1u, controller->num_dialogs_);
}
// Test transitioning from IdP sign-in status mismatch failure dialog to regular
// sign-in dialog while the dialog is hidden. This emulates a user signing
// into the IdP in a different tab.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusMismatchDialogToSigninFlowHidden) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
EXPECT_EQ(TestAccountSelectionView::SheetType::kFailure,
controller->GetTestView()->sheet_type_);
// If the user switched tabs to sign-into the IdP, Show() may be called while
// the associated FedCM tab is inactive. Show() should not show the
// views::Widget in this case.
TabWillEnterBackground(controller.get());
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
TabForegrounded(controller.get());
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_EQ(1u, controller->num_dialogs_);
}
TEST_F(FedCmAccountSelectionViewDesktopTest, AutoReauthnSingleAccountFlow) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowVerifyingDialog(accounts_[0], Account::SignInMode::kAuto,
blink::mojom::RpMode::kPassive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
namespace {
// AccountSelectionViewDelegate which deletes the FedCmAccountSelectionView in
// OnAccountSelected().
class ViewDeletingAccountSelectionViewDelegate
: public StubAccountSelectionViewDelegate {
public:
explicit ViewDeletingAccountSelectionViewDelegate(
content::WebContents* web_contents)
: StubAccountSelectionViewDelegate(web_contents) {}
~ViewDeletingAccountSelectionViewDelegate() override = default;
ViewDeletingAccountSelectionViewDelegate(
const ViewDeletingAccountSelectionViewDelegate&) = delete;
ViewDeletingAccountSelectionViewDelegate& operator=(
const ViewDeletingAccountSelectionViewDelegate&) = delete;
void SetView(std::unique_ptr<FedCmAccountSelectionView> view) {
view_ = std::move(view);
}
void OnAccountSelected(
const GURL&,
const std::string&,
const content::IdentityRequestAccount::LoginState&) override {
view_.reset();
}
private:
std::unique_ptr<FedCmAccountSelectionView> view_;
};
} // namespace
TEST_F(FedCmAccountSelectionViewDesktopTest, AccountSelectedDeletesView) {
delegate_ = std::make_unique<ViewDeletingAccountSelectionViewDelegate>(
test_web_contents_.get());
ViewDeletingAccountSelectionViewDelegate* view_deleting_delegate =
static_cast<ViewDeletingAccountSelectionViewDelegate*>(delegate_.get());
accounts_ = {
CreateAccount(idp_data_, LoginState::kSignIn, LoginState::kSignIn)};
TestFedCmAccountSelectionView* view = nullptr;
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
view = controller.get();
view_deleting_delegate->SetView(std::move(controller));
}
// Destroys FedCmAccountSelectionView. Should not cause crash.
view->OnAccountSelected(accounts_[0], CreateMouseEvent());
}
TEST_F(FedCmAccountSelectionViewDesktopTest, ClickProtection) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
// Use a mock input protector to more easily test. The protector rejects the
// first input and accepts any subsequent input.
auto input_protector =
std::make_unique<views::MockInputEventActivationProtector>();
EXPECT_CALL(*input_protector, IsPossiblyUnintendedInteraction)
.WillOnce(testing::Return(true))
.WillRepeatedly(testing::Return(false));
controller->SetInputEventActivationProtectorForTesting(
std::move(input_protector));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
// Nothing should change after first account selected.
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
// Should show verifying sheet after first account selected.
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that when the auth re-authn dialog is closed, the relevant metric is
// recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest, CloseAutoReauthnSheetMetric) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowVerifyingDialog(accounts_[0], Account::SignInMode::kAuto,
blink::mojom::RpMode::kPassive);
histogram_tester_->ExpectTotalCount("Blink.FedCm.ClosedSheetType.Desktop", 0);
controller->OnCloseButtonClicked(CreateMouseEvent());
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.ClosedSheetType.Desktop",
static_cast<int>(webid::SheetType::AUTO_REAUTHN), 1);
}
// Tests that when the mismatch dialog is closed through the close icon, the
// relevant metric is recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest,
MismatchDialogDismissedByCloseIconMetric) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult", 0);
// Emulate user clicking the close icon.
controller->GetDialogWidget()->CloseWithReason(
views::Widget::ClosedReason::kCloseButtonClicked);
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult",
static_cast<int>(FedCmAccountSelectionView::MismatchDialogResult::
kDismissedByCloseIcon),
1);
}
// Tests that when the mismatch dialog is closed through means other than the
// close icon, the relevant metric is recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest,
MismatchDialogDismissedForOtherReasonsMetric) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult", 0);
// Emulate user closing the mismatch dialog for an unspecified reason.
controller->GetDialogWidget()->CloseWithReason(
views::Widget::ClosedReason::kUnspecified);
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult",
static_cast<int>(FedCmAccountSelectionView::MismatchDialogResult::
kDismissedForOtherReasons),
1);
}
// Tests that when FedCmAccountSelectionView is destroyed while the mismatch
// dialog is open, the relevant metric is recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest, MismatchDialogDestroyedMetric) {
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult", 0);
}
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult",
static_cast<int>(FedCmAccountSelectionView::MismatchDialogResult::
kDismissedForOtherReasons),
1);
}
// Tests that when the continue button on the mismatch dialog is clicked, the
// relevant metric is recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest,
MismatchDialogContinueClickedMetric) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult", 0);
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult",
static_cast<int>(
FedCmAccountSelectionView::MismatchDialogResult::kContinued),
1);
}
// Tests that when the continue button on the mismatch dialog is clicked and
// then FedCmAccountSelectionView is destroyed, we record only the metric for
// the continue button being clicked.
TEST_F(FedCmAccountSelectionViewDesktopTest,
MismatchDialogContinueClickedThenDestroyedMetric) {
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult", 0);
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
}
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.MismatchDialogResult",
static_cast<int>(
FedCmAccountSelectionView::MismatchDialogResult::kContinued),
1);
}
// Test transitioning from IdP sign-in status mismatch dialog to regular sign-in
// dialog. This emulates a user signing into the IdP in a pop-up window and the
// pop-up window closes PRIOR to the mismatch dialog being updated to a regular
// sign-in dialog.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusPopupClosedBeforeAccountsPopulated) {
{
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
// When pop-up window is shown, mismatch dialog should be hidden.
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user completing the sign-in flow and IdP prompts closing the
// pop-up window.
controller->CloseModalDialog();
// Mismatch dialog should remain hidden because it has not been updated to
// an accounts dialog yet.
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus."
"IdpClosePopupToBrowserShowAccountsDuration",
0);
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult", 0);
// Emulate IdP sending the IdP sign-in status header which updates the
// mismatch dialog to an accounts dialog.
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
// Accounts dialog should now be visible. One account is logged in, so no
// back button is shown.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
}
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.IdpClosePopupToBrowserShowAccountsDuration",
1);
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult",
static_cast<int>(FedCmAccountSelectionView::PopupWindowResult::
kAccountsReceivedAndPopupClosedByIdp),
1);
}
// Test transitioning from IdP sign-in status mismatch dialog to regular sign-in
// dialog. This emulates a user signing into the IdP in a pop-up window and the
// pop-up window closes AFTER the mismatch dialog has been updated to a regular
// sign-in dialog.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusPopupClosedAfterAccountsPopulated) {
{
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
// When pop-up window is shown, mismatch dialog should be hidden.
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate IdP sending the IdP sign-in status header which updates the
// mismatch dialog to an accounts dialog.
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
// Accounts dialog should remain hidden because the pop-up window has not
// been closed yet.
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus."
"IdpClosePopupToBrowserShowAccountsDuration",
0);
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult", 0);
// Emulate IdP closing the pop-up window.
controller->CloseModalDialog();
// Accounts dialog should now be visible.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus."
"IdpClosePopupToBrowserShowAccountsDuration",
1);
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult",
static_cast<int>(FedCmAccountSelectionView::PopupWindowResult::
kAccountsReceivedAndPopupClosedByIdp),
1);
}
// Test that when user opens a pop-up window to complete the IDP sign-in flow,
// we record the appropriate metric when accounts are received but
// IdentityProvider.close() is not called.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusAccountsReceivedAndNoPopupClosedByIdpMetric) {
{
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
// Emulate IdP sending the IdP sign-in status header which updates the
// failure dialog to an accounts dialog.
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult", 0);
}
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult",
static_cast<int>(FedCmAccountSelectionView::PopupWindowResult::
kAccountsReceivedAndPopupNotClosedByIdp),
1);
}
// Test that when user opens a pop-up window to complete the IDP sign-in flow,
// we record the appropriate metric when accounts are not received but
// IdentityProvider.close() is called.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusAccountsNotReceivedAndPopupClosedByIdpMetric) {
{
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
// Emulate IdentityProvider.close() being called in the pop-up window.
controller->CloseModalDialog();
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult", 0);
}
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult",
static_cast<int>(FedCmAccountSelectionView::PopupWindowResult::
kAccountsNotReceivedAndPopupClosedByIdp),
1);
}
// Test that when user opens a pop-up window to complete the IDP sign-in flow,
// we record the appropriate metric when accounts are not received and
// IdentityProvider.close() is not called.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusAccountsNotReceivedAndNoPopupClosedByIdpMetric) {
{
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
histogram_tester_->ExpectTotalCount(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult", 0);
}
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.IdpSigninStatus.PopupWindowResult",
static_cast<int>(FedCmAccountSelectionView::PopupWindowResult::
kAccountsNotReceivedAndPopupNotClosedByIdp),
1);
}
// Test closing the IdP sign-in pop-up window through IdentityProvider.close()
// should not close the widget.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusPopupClosedViaIdentityProviderClose) {
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
CreateAndShowPopupWindow(*controller);
// Emulate IdentityProvider.close() being called in the pop-up window.
controller->CloseModalDialog();
// Widget should not be closed.
EXPECT_FALSE(controller->GetDialogWidget()->IsClosed());
}
// Test closing the IdP sign-in pop-up window through means other than
// IdentityProvider.close() should also close the widget.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusPopupClosedViaPopupDestroyed) {
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
CreateAndShowPopupWindow(*controller);
// Emulate user closing the pop-up window.
controller->GetPopupWindowForTesting()->WebContentsDestroyed();
// Widget should be closed.
EXPECT_FALSE(controller->GetDialogWidget());
}
// Test that the mismatch dialog can be shown again after the pop-up window is
// closed.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusMismatchDialogReshown) {
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
CreateAndShowPopupWindow(*controller);
// Mismatch dialog should be hidden because pop-up window is open.
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate IdentityProvider.close() being called in the pop-up window.
controller->CloseModalDialog();
// Mismatch dialog should remain hidden because it has not been updated to an
// accounts dialog yet.
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate another mismatch so we need to show the mismatch dialog again.
controller->ShowFailureDialog(
GetRpData(), kIdpEtldPlusOne, blink::mojom::RpContext::kSignIn,
blink::mojom::RpMode::kPassive, content::IdentityProviderMetadata());
// Mismatch dialog is visible again.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Tests that RP context is properly set for the mismatch UI.
TEST_F(FedCmAccountSelectionViewDesktopTest, MismatchDialogWithRpContext) {
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kSignIn);
}
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog(blink::mojom::RpContext::kSignUp);
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kSignUp);
}
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog(blink::mojom::RpContext::kContinue);
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kContinue);
}
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog(blink::mojom::RpContext::kUse);
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kUse);
}
}
// Tests the following
// 1. pop-up window is closed
// 2. visibility changes to hidden e.g. user navigates to different tab
// 3. Show() is invoked
// 4. widget should remain hidden
// 5. visibility changes to visible e.g. user navigates back to same tab
// 6. widget should now be visible
TEST_F(FedCmAccountSelectionViewDesktopTest,
BubbleWidgetAfterPopupRemainsHiddenAfterAccountsFetched) {
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
// Emulate IdP closing the pop-up window.
controller->CloseModalDialog();
TabWillEnterBackground(controller.get());
// Emulate IdP sending the IdP sign-in status header which updates the
// mismatch dialog to an accounts dialog.
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
TabForegrounded(controller.get());
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
}
// Tests the following
// 1. pop-up window is closed
// 2. visibility changes to hidden e.g. user navigates to different tab
// 3. visibility changes to visible e.g. user navigates back to same tab
// 4. widget should remain hidden
// 5. Show() is invoked
// 6. widget should now be visible
TEST_F(FedCmAccountSelectionViewDesktopTest,
BubbleWidgetAfterPopupRemainsHiddenBeforeAccountsFetched) {
// Trigger IdP sign-in status mismatch dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
// Emulate IdP closing the pop-up window.
controller->CloseModalDialog();
// Switch to a different tab and then switch back to the same tab. The widget
// should remain hidden because the mismatch dialog has not been updated into
// an accounts dialog yet.
TabWillEnterBackground(controller.get());
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
TabForegrounded(controller.get());
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate IdP sending the IdP sign-in status header which updates the
// mismatch dialog to an accounts dialog.
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
// The widget should now be visible.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
}
// Test transitioning from IdP sign-in status mismatch failure dialog to regular
// sign-in dialog where two accounts are logged in at once.
TEST_F(FedCmAccountSelectionViewDesktopTest,
IdpSigninStatusMismatchMultiAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMismatchDialog();
accounts_ = CreateAccounts(
{{kAccountId1, LoginState::kSignUp}, {kAccountId2, LoginState::kSignUp}},
idp_data_);
new_accounts_ = accounts_;
Show(*controller, accounts_, blink::mojom::RpMode::kPassive, new_accounts_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
// Should have only shown both accounts.
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
// There are no other accounts, so back button should not be present.
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
controller->OnAccountSelected(new_accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
controller->OnAccountSelected(new_accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
EXPECT_EQ(1u, controller->num_dialogs_);
}
// Test the use another account flow, resulting in the new account being shown
// after logging in.
TEST_F(FedCmAccountSelectionViewDesktopTest, UseAnotherAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsThroughUseAnotherAccount(
/*old_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*new_account_infos=*/{{kAccountId2, LoginState::kSignUp}});
// Only the newly logged in account is shown in the latest dialog.
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
// Back button must be showing since there are multiple accounts.
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
// Clicking the back button shows all the accounts.
controller->OnBackButtonClicked();
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
}
// Test the use another account flow when signing into the same account that the
// user started with.
TEST_F(FedCmAccountSelectionViewDesktopTest, UseAnotherAccountForSameAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsThroughUseAnotherAccount(
/*old_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*new_account_infos=*/{{kAccountId1, LoginState::kSignUp}});
// Only the newly logged in account is shown in the latest dialog.
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
// Back button must NOT be showing since there is only one account.
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
}
// Test the use another account flow, resulting in account chooser UI if it's a
// returning account.
TEST_F(FedCmAccountSelectionViewDesktopTest,
UseAnotherAccountForReturningAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsThroughUseAnotherAccount(
/*old_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*new_account_infos=*/{{kAccountId2, LoginState::kSignIn}});
// The account chooser UI is NOT skipped.
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
}
// Test the use another account flow in a modal, resulting in the new account
// being shown after logging in.
TEST_F(FedCmAccountSelectionViewDesktopTest, UseAnotherAccountModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsThroughUseAnotherAccount(
/*old_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*new_account_infos=*/{{kAccountId2, LoginState::kSignUp}},
/*rp_mode=*/blink::mojom::RpMode::kActive);
// The permission UI is NOT skipped.
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
}
// Test the use another account flow in a modal when signing into the same
// account that the user started with.
TEST_F(FedCmAccountSelectionViewDesktopTest,
UseAnotherAccountModalForSameAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsThroughUseAnotherAccount(
/*old_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*new_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*rp_mode=*/blink::mojom::RpMode::kActive);
// The permission UI is NOT skipped.
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Test the use another account flow in a modal, resulting in no account chooser
// UI if it's a returning account.
TEST_F(FedCmAccountSelectionViewDesktopTest,
UseAnotherAccountModalForReturningAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsThroughUseAnotherAccount(
/*old_account_infos=*/{{kAccountId1, LoginState::kSignUp}},
/*new_account_infos=*/{{kAccountId2, LoginState::kSignIn}},
/*rp_mode=*/blink::mojom::RpMode::kActive);
// The account chooser UI is skipped.
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
}
// Test the logged-out LoginStatus flow in a modal, resulting in account
// chooser UI if it's a returning account.
TEST_F(FedCmAccountSelectionViewDesktopTest,
LoginStatusLoggedOutModalForReturningAccount) {
accounts_ = {
CreateAccount(idp_data_, LoginState::kSignIn, LoginState::kSignIn)};
new_accounts_ = accounts_;
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsModalThroughPopupWindow(accounts_, new_accounts_);
// The account chooser UI is NOT skipped if user signed in from LOADING state.
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
}
// Test the logged-out LoginStatus flow in a modal, resulting in showing account
// chooser UI if it's a non-returning account.
TEST_F(FedCmAccountSelectionViewDesktopTest,
LoginStatusLoggedOutModalForNonReturningAccount) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsModalThroughPopupWindow(accounts_, new_accounts_);
// The permission UI is NOT skipped.
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Test the browser trusted login state controls whether to skip the account
// chooser UI when in conflict with login state.
TEST_F(FedCmAccountSelectionViewDesktopTest,
BrowserTrustedLoginStateTakesPrecedenceOverLoginState) {
accounts_ = {
CreateAccount(idp_data_, /*idp_claimed_login_state=*/LoginState::kSignIn,
/*browser_trusted_login_state=*/LoginState::kSignUp)};
new_accounts_ = accounts_;
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsModalThroughPopupWindow(accounts_, new_accounts_);
// The account chooser UI is NOT skipped. Normally, this is permission UI but
// because we do not want to show disclosure UI without disclosure text, we
// show the account chooser UI instead.
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
}
// Test user triggering the use another account flow twice in a modal, without
// closing the pop-up from the first use another account flow.
TEST_F(FedCmAccountSelectionViewDesktopTest, UseAnotherAccountTwiceModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
// Emulate the user clicking "use another account button".
OpenLoginToIdpPopup(controller.get());
// Modal remains visible.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate the user clicking "use another account button" again. This should
// not crash.
OpenLoginToIdpPopup(controller.get());
}
// Test user triggering the use another account flow twice in a modal, with
// closing the pop-up from the first use another account flow.
TEST_F(FedCmAccountSelectionViewDesktopTest,
UseAnotherAccountCloseThenReopenModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
// Emulate the user clicking "use another account button".
OpenLoginToIdpPopup(controller.get());
// Modal remains visible.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate user closing the pop-up window.
controller->GetPopupWindowForTesting()->WebContentsDestroyed();
// Modal remains visible.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate the user clicking "use another account button" again. This should
// not crash.
OpenLoginToIdpPopup(controller.get());
}
// Test user triggering the use another account flow then clicking on the cancel
// button in the modal without completing the use other account flow.
TEST_F(FedCmAccountSelectionViewDesktopTest, UseAnotherAccountThenCancel) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
// Emulate the user clicking "use another account button".
OpenLoginToIdpPopup(controller.get());
// Modal remains visible.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate the user clicking "cancel" button. This should close the widget.
controller->OnCloseButtonClicked(CreateMouseEvent());
EXPECT_FALSE(controller->GetDialogWidget());
}
// Tests that the error dialog can be shown.
TEST_F(FedCmAccountSelectionViewDesktopTest, ErrorDialogShown) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog();
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Tests that RP context is properly set for the error dialog.
TEST_F(FedCmAccountSelectionViewDesktopTest, ErrorDialogWithRpContext) {
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog();
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kSignIn);
}
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog(blink::mojom::RpContext::kSignUp);
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kSignUp);
}
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog(blink::mojom::RpContext::kContinue);
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kContinue);
}
{
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog(blink::mojom::RpContext::kUse);
EXPECT_EQ(controller->GetRpContext(), blink::mojom::RpContext::kUse);
}
}
// Tests the flow for when the "got it" button on the error dialog is clicked.
TEST_F(FedCmAccountSelectionViewDesktopTest, ErrorDialogGotItClicked) {
// Trigger error dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog();
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate user clicking on "got it" button in the error dialog.
controller->OnGotIt(CreateMouseEvent());
// Widget should be dismissed.
StubAccountSelectionViewDelegate* delegate =
static_cast<StubAccountSelectionViewDelegate*>(delegate_.get());
EXPECT_EQ(delegate->GetDismissReason(), DismissReason::kGotItButton);
}
// Tests the flow for when the "more details" button on the error dialog is
// clicked.
TEST_F(FedCmAccountSelectionViewDesktopTest, ErrorDialogMoreDetailsClicked) {
// Trigger error dialog.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowErrorDialog();
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate user clicking on "more details" button in the error dialog.
controller->OnMoreDetails(CreateMouseEvent());
CreateAndShowPopupWindow(*controller);
// Widget should be dismissed.
StubAccountSelectionViewDelegate* delegate =
static_cast<StubAccountSelectionViewDelegate*>(delegate_.get());
EXPECT_EQ(delegate->GetDismissReason(), DismissReason::kMoreDetailsButton);
}
TEST_F(FedCmAccountSelectionViewDesktopTest, MultiIdpWithOneIdpMismatch) {
std::vector<IdentityProviderDataPtr> idp_list = {
CreateIdentityProviderData(),
CreateIdentityProviderData(/*has_login_status_mismatch*/ true)};
std::vector<IdentityRequestAccountPtr> accounts = {
CreateAccount(idp_list[0])};
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMultiIdp(idp_list, accounts, blink::mojom::RpMode::kPassive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
TEST_F(FedCmAccountSelectionViewDesktopTest,
MultiIdpWithSingleReturningAccount) {
std::vector<IdentityProviderDataPtr> idp_list = {
CreateIdentityProviderData(), CreateIdentityProviderData(),
CreateIdentityProviderData(/*has_login_status_mismatch=*/true)};
std::vector<IdentityRequestAccountPtr> accounts = {
CreateAccount(idp_list[0], LoginState::kSignIn, LoginState::kSignIn),
CreateAccount(idp_list[1], LoginState::kSignUp, LoginState::kSignUp,
kAccountId2)};
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMultiIdp(idp_list, accounts, blink::mojom::RpMode::kPassive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
// Simulate second account picked.
controller->OnAccountSelected(accounts[1], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
// Simulate 'back' clicked: now in multi account picker.
controller->OnBackButtonClicked();
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
// Simulate account picked
controller->OnAccountSelected(accounts[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that closing the dialog when a single returning account is shown does
// not cause a crash.
TEST_F(FedCmAccountSelectionViewDesktopTest,
MultiIdpWithSingleReturningAccountClose) {
std::vector<IdentityProviderDataPtr> idp_list = {
CreateIdentityProviderData(), CreateIdentityProviderData(),
CreateIdentityProviderData(/*has_login_status_mismatch=*/true)};
std::vector<IdentityRequestAccountPtr> accounts = {
CreateAccount(idp_list[0], LoginState::kSignIn, LoginState::kSignIn),
CreateAccount(idp_list[1], LoginState::kSignUp, LoginState::kSignUp,
kAccountId2)};
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMultiIdp(idp_list, accounts, blink::mojom::RpMode::kPassive);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
// Simulate the dialog being closed.
controller->OnCloseButtonClicked(CreateMouseEvent());
}
// Tests that if a pop-up window is opened in active mode, closing the
// pop-up window triggers the dismiss callback.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ActiveModePopupCloseTriggersDismissCallback) {
// Show modal mismatch dialog.
auto controller = CreateAndShowMismatchDialog(
blink::mojom::RpContext::kSignIn, blink::mojom::RpMode::kActive);
// Emulate user clicking on a button to sign in with an IDP via active mode.
controller->ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kActive);
EXPECT_EQ(controller->GetPopupWindow()->show_popup_window_count_, 1);
// Emulate user closing the pop-up window.
controller->GetPopupWindowForTesting()->WebContentsDestroyed();
// Widget should be dismissed.
StubAccountSelectionViewDelegate* delegate =
static_cast<StubAccountSelectionViewDelegate*>(delegate_.get());
EXPECT_EQ(delegate->GetDismissReason(), DismissReason::kOther);
// Reset the widget explicitly since no widget was shown. Otherwise, the test
// will complain that a widget is still open.
dialog_widget_.reset();
}
TEST_F(FedCmAccountSelectionViewDesktopTest, MultiIdpMismatchAndShow) {
std::vector<IdentityProviderDataPtr> idp_list = {
CreateIdentityProviderData(),
CreateIdentityProviderData(/*has_login_status_mismatch=*/true)};
std::vector<IdentityRequestAccountPtr> accounts = {
CreateAccount(idp_list[0])};
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowMultiIdp(idp_list, accounts, blink::mojom::RpMode::kPassive);
// Emulate user clicking on "Continue" button in the mismatch dialog.
OpenLoginToIdpPopup(controller.get());
controller->CloseModalDialog();
// The backend will pass the accounts reordered.
std::vector<IdentityRequestAccountPtr> new_accounts = {CreateAccount(
idp_list[1], LoginState::kSignUp, LoginState::kSignUp, kAccountId2)};
std::vector<IdentityRequestAccountPtr> all_accounts = new_accounts;
all_accounts.emplace_back(accounts[0]);
Show(*controller, all_accounts, blink::mojom::RpMode::kActive, new_accounts);
// Should show only the new account, with a back button for other account.
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
ASSERT_TRUE(controller->GetTestView()->show_back_button_);
controller->OnBackButtonClicked();
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2, kAccountId1));
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(1u, controller->num_dialogs_);
}
// Tests that if a single account chooser is opened in active mode mode,
// selecting an account shows the request permission sheet. Then, confirming the
// account on the request permission sheet shows the verifying sheet.
TEST_F(FedCmAccountSelectionViewDesktopTest, SingleAccountFlowModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that if a multiple account chooser is opened in active mode mode,
// selecting an account shows the request permission sheet. Then, confirming the
// account on the request permission sheet shows the verifying sheet.
TEST_F(FedCmAccountSelectionViewDesktopTest, MultipleAccountFlowModal) {
accounts_ = CreateAccounts(
{{kAccountId1, LoginState::kSignUp}, {kAccountId2, LoginState::kSignUp}},
idp_data_);
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that if a single account chooser is opened in active mode mode,
// selecting a returning account shows the verifying sheet.
TEST_F(FedCmAccountSelectionViewDesktopTest, SingleAccountFlowReturningModal) {
accounts_ = {
CreateAccount(idp_data_, LoginState::kSignIn, LoginState::kSignIn)};
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that if a multiple account chooser is opened in active mode mode,
// selecting a returning account shows the verifying sheet.
TEST_F(FedCmAccountSelectionViewDesktopTest,
MultipleAccountFlowReturningModal) {
accounts_ = CreateAccounts(
{{kAccountId1, LoginState::kSignIn}, {kAccountId2, LoginState::kSignUp}},
idp_data_);
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that if a single account chooser is opened in active mode mode,
// clicking the back button in the request permission dialog returns the user to
// the single account chooser.
TEST_F(FedCmAccountSelectionViewDesktopTest, SingleAccountFlowBackModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnBackButtonClicked();
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that if a multiple account chooser is opened in active mode mode,
// clicking the back button in the request permission dialog returns the user to
// the multiple account chooser.
TEST_F(FedCmAccountSelectionViewDesktopTest, MultipleAccountFlowBackModal) {
accounts_ = CreateAccounts(
{{kAccountId1, LoginState::kSignUp}, {kAccountId2, LoginState::kSignUp}},
idp_data_);
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnBackButtonClicked();
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1, kAccountId2));
controller->OnAccountSelected(accounts_[1], CreateMouseEvent());
EXPECT_TRUE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
controller->OnAccountSelected(accounts_[1], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId2));
}
// Tests that auto re-authn works in active mode.
TEST_F(FedCmAccountSelectionViewDesktopTest,
AutoReauthnSingleAccountFlowModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
controller->ShowVerifyingDialog(GetRpData(), {idp_data_}, accounts_[0],
Account::SignInMode::kAuto,
blink::mojom::RpMode::kActive);
// Did not recreate the dialog.
EXPECT_EQ(1u, controller->num_dialogs_);
// Verifying UI is not shown.
EXPECT_EQ(TestAccountSelectionView::SheetType::kLoading,
controller->GetTestView()->sheet_type_);
EXPECT_TRUE(controller->GetTestView()->account_ids_.empty());
}
// Tests that the user can dismiss the loading modal.
TEST_F(FedCmAccountSelectionViewDesktopTest, DismissLoadingModal) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
controller->OnCloseButtonClicked(CreateMouseEvent());
}
// Tests that the loading modal is not hidden when a pop-up window is displayed.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ActiveModeLoadingModalNotHiddenDuringLoginToIdP) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate user clicking on a button to sign in with an IDP via active mode.
controller->ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kActive);
EXPECT_EQ(controller->GetPopupWindow()->show_popup_window_count_, 1);
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Tests that opening an IDP sign-in pop-up during the loading modal, then
// closing the pop-up, does not crash. (This simulates the user triggering a
// active mode, then an IDP sign-in pop-up shows up because the user is logged
// out)
TEST_F(FedCmAccountSelectionViewDesktopTest,
CloseIdpSigninPopupDuringLoadingState) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
delegate_->SetOnDismissClosure(
base::BindOnce(&std::unique_ptr<TestFedCmAccountSelectionView>::reset,
base::Unretained(&controller), nullptr));
CreateAndShowPopupWindow(*controller);
// This should not crash.
controller->CloseModalDialog();
}
// Tests that opening a popup after a verifying sheet, then closing the popup,
// notifies the observer.
TEST_F(FedCmAccountSelectionViewDesktopTest,
UserClosingPopupAfterVerifyingSheetShouldNotify) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
CreateAndShowPopupWindow(*controller);
controller->GetPopupWindowForTesting()->WebContentsDestroyed();
EXPECT_EQ(delegate_->GetDismissReason(), DismissReason::kOther);
}
// Tests that opening a popup after a verifying sheet, then closing the popup
// programmatically, does not notify the observer.
TEST_F(FedCmAccountSelectionViewDesktopTest,
CodeClosingPopupAfterVerifyingSheetShouldNotNotify) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
CreateAndShowPopupWindow(*controller);
controller->CloseModalDialog();
EXPECT_FALSE(delegate_->GetDismissReason().has_value());
}
// Tests that if the dialog skips requesting permission, the verifying sheet is
// shown.
TEST_F(FedCmAccountSelectionViewDesktopTest,
SkipRequestPermissionShowsVerifying) {
idp_data_->disclosure_fields = {};
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kPassive);
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that if IDP supports add account, the correct sheet type is shown
// depending on the number of accounts and the rp mode.
TEST_F(FedCmAccountSelectionViewDesktopTest, SupportAddAccount) {
idp_data_->idp_metadata.supports_add_account = true;
std::vector<IdentityRequestAccountPtr> multiple_accounts = CreateAccounts(
{{kAccountId1, LoginState::kSignIn}, {kAccountId2, LoginState::kSignIn}},
idp_data_);
{
// Single account passive mode.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kPassive);
// We do not support add account on passive mode, so should show single
// account dialog.
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
}
{
// Multiple account passive mode.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(multiple_accounts, blink::mojom::RpMode::kPassive);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
}
{
// Single account active mode.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
}
{
// Multiple account active mode.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(multiple_accounts, blink::mojom::RpMode::kActive);
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
}
}
// Tests that the correct account chooser result metrics are recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest, AccountChooserResultMetric) {
auto CheckForSampleAndReset([&](webid::AccountChooserResult result) {
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.Button.AccountChooserResult", static_cast<int>(result), 1);
histogram_tester_ = std::make_unique<base::HistogramTester>();
});
// The AccountChooserResult metric is recorded in OnDismiss, therefore, we
// check for the histogram after the TestFedCmAccountSelectionView goes out
// of scope.
{
// User clicks on account row.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
}
CheckForSampleAndReset(webid::AccountChooserResult::kAccountRow);
{
// User clicks on cancel button.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnCloseButtonClicked(CreateMouseEvent());
}
CheckForSampleAndReset(webid::AccountChooserResult::kCancelButton);
{
// User clicks on use other account button.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnLoginToIdP(GURL(kConfigUrl), GURL(kLoginUrl),
CreateMouseEvent());
}
CheckForSampleAndReset(webid::AccountChooserResult::kUseOtherAccountButton);
{
// User closes the tab or window.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
}
CheckForSampleAndReset(webid::AccountChooserResult::kTabClosed);
{
// Returning user signing in via IDP sign-in pop-up when signed-out should
// record a sample.
std::vector<IdentityRequestAccountPtr> accounts = {
CreateAccount(idp_data_, LoginState::kSignIn, LoginState::kSignIn)};
std::vector<IdentityRequestAccountPtr> new_accounts = accounts;
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsModalThroughPopupWindow(accounts, new_accounts);
// User is shown the account chooser.
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
controller->OnAccountSelected(new_accounts[0], CreateMouseEvent());
}
CheckForSampleAndReset(webid::AccountChooserResult::kAccountRow);
{
// Non-returning user signing in via IDP sign-in pop-up should not record a
// sample.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsModalThroughPopupWindow(accounts_, new_accounts_);
// User is shown the request permission dialog, skipping the account
// chooser.
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
}
histogram_tester_->ExpectTotalCount("Blink.FedCm.Button.AccountChooserResult",
0);
{
// passive mode should not record a sample.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kPassive);
}
histogram_tester_->ExpectTotalCount("Blink.FedCm.Button.AccountChooserResult",
0);
}
// Tests that for active modes, going from an accounts dialog to an error dialog
// does not reset the account selection view since the error UI has a modal.
TEST_F(FedCmAccountSelectionViewDesktopTest,
AccountsToErrorActiveModeDoesNotResetView) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->ShowErrorDialog(
GetRpData(), kIdpEtldPlusOne, blink::mojom::RpContext::kSignIn,
blink::mojom::RpMode::kActive, content::IdentityProviderMetadata(),
/*error=*/std::nullopt);
// Did not recreate the dialog.
EXPECT_EQ(1u, controller->num_dialogs_);
}
// Tests that for active modes, going from a loading dialog to an accounts
// dialog does not reset the account selection view. This is important because
// the accounts dialog reuses the header from the loading dialog.
TEST_F(FedCmAccountSelectionViewDesktopTest,
LoadingToAccountsActiveModeReusesView) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
Show(*controller, accounts_, blink::mojom::RpMode::kActive);
// Did not recreate the dialog.
EXPECT_EQ(1u, controller->num_dialogs_);
}
// Tests that resizing web contents would update the dialog visibility depending
// on whether the dialog can fit within the web contents.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ResizeWebContentsChangesDialogVisibility) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate that the web contents is too small to fit the dialog, hiding the
// dialog.
controller->can_fit_in_web_contents_ = false;
controller->PrimaryMainFrameWasResized(/*width_changed=*/true);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate that the web contents is big enough to fit the dialog, showing the
// dialog.
controller->can_fit_in_web_contents_ = true;
controller->PrimaryMainFrameWasResized(/*width_changed=*/true);
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Tests that resizing web contents in different web contents visibility
// scenarios would update the dialog visibility correctly depending on whether
// the dialog can fit within the web contents or whether the web contents where
// the dialog is contained is visible.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ResizeWebContentsWithWindowVisibilityChanges) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
// Emulate user changing tabs, hiding the dialog.
TabWillEnterBackground(controller.get());
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user resizing the window, making the web contents too small to fit
// the dialog. The dialog should remain hidden.
controller->can_fit_in_web_contents_ = false;
controller->PrimaryMainFrameWasResized(/*width_changed=*/true);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user changing back to the tab containing the dialog. The dialog
// should remain hidden because the web contents is still too small to fit the
// dialog.
TabForegrounded(controller.get());
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user resizing the window, making the web contents is big enough to
// fit the dialog. The dialog should now be visible.
controller->can_fit_in_web_contents_ = true;
controller->PrimaryMainFrameWasResized(/*width_changed=*/true);
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
// Emulate user resizing the window, making the web contents too small to fit
// the dialog. The dialog should be hidden.
controller->can_fit_in_web_contents_ = false;
controller->PrimaryMainFrameWasResized(/*width_changed=*/false);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user changing tabs, the dialog should remain hidden.
TabWillEnterBackground(controller.get());
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user resizing the window, making the web contents big enough to fit
// the dialog. The dialog should remain hidden because the user is on a
// different tab.
controller->can_fit_in_web_contents_ = true;
controller->PrimaryMainFrameWasResized(/*width_changed=*/false);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user changing back to the tab containing the dialog. The dialog
// should now be visible.
TabForegrounded(controller.get());
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Tests that changing visibility from hidden to visible, also updates the
// dialog position. This is needed in case the web contents was resized while
// hidden.
TEST_F(FedCmAccountSelectionViewDesktopTest,
VisibilityChangesUpdatesDialogPosition) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
controller->dialog_position_updated_ = false;
// Emulate user changing tabs, hiding the dialog.
TabWillEnterBackground(controller.get());
EXPECT_FALSE(controller->dialog_position_updated_);
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user changing back to the tab containing the dialog, updating the
// dialog position.
TabForegrounded(controller.get());
EXPECT_TRUE(controller->dialog_position_updated_);
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Test that the fields API (request_permission={}) correctly hides the
// disclosure UI after logging in through the popup when logged out.
TEST_F(FedCmAccountSelectionViewDesktopTest,
RequestPermissionFalseAndNewIdpDataDisclosureText) {
idp_data_->disclosure_fields = {};
for (auto& account : accounts_) {
account->fields = {};
}
for (auto& account : new_accounts_) {
account->fields = {};
}
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowAccountsModalThroughPopupWindow(accounts_, new_accounts_);
// The account chooser UI is NOT skipped if user signed in from LOADING state.
EXPECT_EQ(TestAccountSelectionView::SheetType::kAccountPicker,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
// This should use the multi account picker, which does not show the
// disclosure text.
EXPECT_EQ(FedCmAccountSelectionView::State::MULTI_ACCOUNT_PICKER,
controller->state_);
}
// Tests that a loading state pop-up opened during a active mode sets a custom Y
// position. This is so that the pop-up covers the loading modal dialog to
// direct user attention towards the pop-up.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ActiveModeLoadingStatePopupSetsCustomYPosition) {
auto controller = CreateAndShowLoadingDialog();
// Open loading state pop-up and expect it to call `SetCustomYPosition`.
controller->ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kActive);
EXPECT_EQ(controller->GetPopupWindow()->show_popup_window_count_, 1);
EXPECT_EQ(controller->GetPopupWindow()->set_custom_y_position_count_, 1);
// Reset the widget explicitly since no widget was shown. Otherwise, the test
// will complain that a widget is still open.
dialog_widget_.reset();
}
// Tests that a use other account pop-up opened during a active mode does not
// set a custom Y position.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ActiveModeUseOtherAccountPopupDoesNotSetCustomYPosition) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
// Open use other account pop-up and expect it to not call
// `SetCustomYPosition`.
controller->ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kActive);
EXPECT_EQ(controller->GetPopupWindow()->show_popup_window_count_, 1);
EXPECT_EQ(controller->GetPopupWindow()->set_custom_y_position_count_, 0);
// Reset the widget explicitly since no widget was shown. Otherwise, the test
// will complain that a widget is still open.
dialog_widget_.reset();
}
// Tests that a loading state pop-up opened during a active mode should call
// `SetActiveModeSheetType`.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ActiveModeLoadingStatePopupSetsActiveModeSheetType) {
auto controller = CreateAndShowLoadingDialog();
// Open loading state pop-up and expect it to call `SetActiveModeSheetType`.
controller->ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kActive);
EXPECT_EQ(controller->GetPopupWindow()->show_popup_window_count_, 1);
EXPECT_EQ(controller->GetPopupWindow()->set_active_mode_sheet_type_count_, 1);
// Reset the widget explicitly since no widget was shown. Otherwise, the test
// will complain that a widget is still open.
dialog_widget_.reset();
}
// Tests that a use other account pop-up opened during a active mode should call
// `SetActiveModeSheetType`.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ActiveModeUseOtherAccountPopupSetsActiveModeSheetType) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
// Open use other account pop-up and expect it to call
// `SetActiveModeSheetType`.
controller->ShowModalDialog(GURL(u"https://example.com"),
blink::mojom::RpMode::kActive);
EXPECT_EQ(controller->GetPopupWindow()->show_popup_window_count_, 1);
EXPECT_EQ(controller->GetPopupWindow()->set_active_mode_sheet_type_count_, 1);
// Reset the widget explicitly since no widget was shown. Otherwise, the test
// will complain that a widget is still open.
dialog_widget_.reset();
}
// Tests that resizing the window updates the modal dialog position.
TEST_F(FedCmAccountSelectionViewDesktopTest,
ResizingWindowUpdatesModalDialogPosition) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->PrimaryMainFrameWasResized(/*width_changed=*/true);
EXPECT_TRUE(controller->dialog_position_updated_);
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
// Tests that closing the use other account button does not close a FedCM
// passive mode dialog.
TEST_F(FedCmAccountSelectionViewDesktopTest,
PassiveModeCloseUseOtherAccountDoesNotCloseDialog) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_);
// This is choose another account since there are accounts being shown.
OpenLoginToIdpPopup(controller.get());
// The dialog is not closed but is hidden.
EXPECT_FALSE(controller->GetDialogWidget()->IsClosed());
EXPECT_FALSE(controller->GetDialogWidget()->IsVisible());
// Emulate user closing the pop-up window.
controller->GetPopupWindowForTesting()->WebContentsDestroyed();
// Dialog should reappear once the popup window is destroyed.
EXPECT_TRUE(controller->GetDialogWidget()->IsVisible());
}
TEST_F(FedCmAccountSelectionViewDesktopTest, ClickProtectionNoModalSpinner) {
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
// Use a mock input protector to more easily test. The protector rejects the
// first input and accepts any subsequent input.
auto input_protector =
std::make_unique<views::MockInputEventActivationProtector>();
EXPECT_CALL(*input_protector, IsPossiblyUnintendedInteraction)
.WillOnce(testing::Return(true))
.WillRepeatedly(testing::Return(false));
controller->SetInputEventActivationProtectorForTesting(
std::move(input_protector));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
// Nothing should change after first account selected.
EXPECT_FALSE(controller->GetTestView()->show_back_button_);
EXPECT_EQ(TestAccountSelectionView::SheetType::kConfirmAccount,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
// Should show verifying sheet after first account selected.
EXPECT_EQ(TestAccountSelectionView::SheetType::kRequestPermission,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
EXPECT_EQ(TestAccountSelectionView::SheetType::kVerifying,
controller->GetTestView()->sheet_type_);
EXPECT_THAT(controller->GetTestView()->account_ids_,
testing::ElementsAre(kAccountId1));
}
// Tests that the correct loading dialog result metrics are recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest, LoadingDialogResultMetric) {
auto CheckForSampleAndReset([&](webid::LoadingDialogResult result) {
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.Button.LoadingDialogResult", static_cast<int>(result), 1);
histogram_tester_ = std::make_unique<base::HistogramTester>();
});
// The LoadingDialogResult metric is recorded in OnDismiss, therefore, we
// check for the histogram after the TestFedCmAccountSelectionView goes out
// of scope.
{
// User proceeds with existing accounts.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
Show(*controller, accounts_, blink::mojom::RpMode::kActive);
}
CheckForSampleAndReset(webid::LoadingDialogResult::kProceed);
{
// User proceeds with auto re-authn.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
accounts_ = {
CreateAccount(idp_data_, LoginState::kSignIn, LoginState::kSignIn)};
Show(*controller, accounts_, blink::mojom::RpMode::kActive);
}
CheckForSampleAndReset(webid::LoadingDialogResult::kProceed);
{
// User proceeds by completing login to IDP flow.
CreateAndShowAccountsModalThroughPopupWindow(accounts_, new_accounts_);
}
CheckForSampleAndReset(webid::LoadingDialogResult::kProceedThroughPopup);
{
// User clicks on cancel button.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShowLoadingDialog();
controller->OnCloseButtonClicked(CreateMouseEvent());
}
CheckForSampleAndReset(webid::LoadingDialogResult::kCancel);
{
// Tab or window is destroyed.
CreateAndShowLoadingDialog();
}
CheckForSampleAndReset(webid::LoadingDialogResult::kDestroy);
}
// Tests that the correct disclosure dialog result metrics are recorded.
TEST_F(FedCmAccountSelectionViewDesktopTest, DisclosureDialogResultMetric) {
auto CheckForSampleAndReset(
[&](webid::DisclosureDialogResult result) {
histogram_tester_->ExpectUniqueSample(
"Blink.FedCm.Button.DisclosureDialogResult",
static_cast<int>(result), 1);
histogram_tester_ = std::make_unique<base::HistogramTester>();
});
{
// User proceeds with an account.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
}
CheckForSampleAndReset(webid::DisclosureDialogResult::kContinue);
{
// User clicks on cancel button.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
controller->OnCloseButtonClicked(CreateMouseEvent());
}
CheckForSampleAndReset(webid::DisclosureDialogResult::kCancel);
{
// User clicks on back button.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
controller->OnBackButtonClicked();
}
CheckForSampleAndReset(webid::DisclosureDialogResult::kBack);
{
// Tab or window is destroyed.
std::unique_ptr<TestFedCmAccountSelectionView> controller =
CreateAndShow(accounts_, blink::mojom::RpMode::kActive);
controller->OnAccountSelected(accounts_[0], CreateMouseEvent());
}
CheckForSampleAndReset(webid::DisclosureDialogResult::kDestroy);
}
} // namespace webid
|