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
|
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/containers/flat_set.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
#include "components/google/core/common/google_util.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/optimization_guide/core/hints_component_info.h"
#include "components/optimization_guide/core/hints_component_util.h"
#include "components/optimization_guide/core/optimization_guide_constants.h"
#include "components/optimization_guide/core/optimization_guide_enums.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/optimization_guide/core/optimization_guide_store.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/optimization_guide/core/optimization_hints_component_update_listener.h"
#include "components/optimization_guide/core/test_hints_component_creator.h"
#include "components/optimization_guide/core/top_host_provider.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/prefs/pref_service.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/variations/hashing.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_base.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/network_connection_change_simulator.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "third_party/blink/public/common/features.h"
namespace {
// Fetch and calculate the total number of samples from all the bins for
// |histogram_name|. Note: from some browertests run (such as chromeos) there
// might be two profiles created, and this will return the total sample count
// across profiles.
int GetTotalHistogramSamples(const base::HistogramTester* histogram_tester,
const std::string& histogram_name) {
std::vector<base::Bucket> buckets =
histogram_tester->GetAllSamples(histogram_name);
int total = 0;
for (const auto& bucket : buckets)
total += bucket.count;
return total;
}
// Retries fetching |histogram_name| until it contains at least |count| samples.
int RetryForHistogramUntilCountReached(
const base::HistogramTester* histogram_tester,
const std::string& histogram_name,
int count) {
int total = 0;
while (true) {
base::ThreadPoolInstance::Get()->FlushForTesting();
base::RunLoop().RunUntilIdle();
total = GetTotalHistogramSamples(histogram_tester, histogram_name);
if (total >= count)
return total;
content::FetchHistogramsFromChildProcesses();
metrics::SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
base::RunLoop().RunUntilIdle();
}
}
enum class HintsFetcherRemoteResponseType {
kSuccessful = 0,
kUnsuccessful = 1,
kMalformed = 2,
kHung = 3,
};
constexpr char kGoogleHost[] = "www.google.com";
// Modifies |relative_url|:
// Scheme of the returned URL matches the scheme of the |server|.
// Host of the returned URL matches kGoogleHost.
// Port number of the returned URL matches the port at which |server| is
// listening.
// Path of the returned URL is set to |relative_url|.
GURL GetURLWithGoogleHost(net::EmbeddedTestServer* server,
const std::string& relative_url) {
GURL server_base_url = server->base_url();
GURL base_url =
GURL(base::StrCat({server_base_url.scheme(), "://", kGoogleHost, ":",
server_base_url.port()}));
EXPECT_TRUE(base_url.is_valid()) << base_url.possibly_invalid_spec();
return base_url.Resolve(relative_url);
}
} // namespace
// This test class sets up everything but does not enable any
// HintsFetcher-related features. The parameter selects whether the
// OptimizationGuideKeyedService is enabled (tests should pass in the same way
// for both cases).
class HintsFetcherDisabledBrowserTest : public InProcessBrowserTest {
public:
HintsFetcherDisabledBrowserTest() = default;
~HintsFetcherDisabledBrowserTest() override = default;
void SetUpOnMainThread() override {
content::NetworkConnectionChangeSimulator().SetConnectionType(
network::mojom::ConnectionType::CONNECTION_2G);
// Ensure that kGoogleHost resolves to the localhost where the embedded test
// server is listening.
host_resolver()->AddRule("*", "127.0.0.1");
ukm_recorder_ = std::make_unique<ukm::TestAutoSetUkmRecorder>();
InProcessBrowserTest::SetUpOnMainThread();
}
void SetUp() override {
origin_server_.reset(
new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
origin_server_->ServeFilesFromSourceDirectory("chrome/test/data/previews");
ASSERT_TRUE(origin_server_->Start());
https_url_ = origin_server_->GetURL("/hint_setup.html");
ASSERT_TRUE(https_url().SchemeIs(url::kHttpsScheme));
search_results_page_url_ =
GetURLWithGoogleHost(origin_server_.get(), "/search_results_page.html");
ASSERT_TRUE(search_results_page_url_.is_valid() &&
search_results_page_url_.SchemeIs(url::kHttpsScheme) &&
google_util::IsGoogleHostname(search_results_page_url_.host(),
google_util::DISALLOW_SUBDOMAIN));
hints_server_.reset(
new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
hints_server_->ServeFilesFromSourceDirectory("chrome/test/data/previews");
hints_server_->RegisterRequestHandler(base::BindRepeating(
&HintsFetcherDisabledBrowserTest::HandleGetHintsRequest,
base::Unretained(this)));
ASSERT_TRUE(hints_server_->Start());
param_feature_list_.InitWithFeatures(
{blink::features::kNavigationPredictor}, {});
InProcessBrowserTest::SetUp();
}
void SetUpCommandLine(base::CommandLine* cmd) override {
cmd->AppendSwitch("ignore-certificate-errors");
cmd->AppendSwitch("purge_hint_cache_store");
cmd->AppendSwitch(optimization_guide::switches::
kDisableCheckingUserPermissionsForTesting);
// Set up OptimizationGuideServiceURL, this does not enable HintsFetching,
// only provides the URL.
cmd->AppendSwitchASCII(
optimization_guide::switches::kOptimizationGuideServiceGetHintsURL,
hints_server_
->GetURL(GURL(optimization_guide::
kOptimizationGuideServiceGetHintsDefaultURL)
.host(),
"/")
.spec());
cmd->AppendSwitchASCII("host-rules", "MAP * 127.0.0.1");
cmd->AppendSwitchASCII("force-variation-ids", "4");
cmd->AppendSwitchASCII(optimization_guide::switches::kFetchHintsOverride,
"example1.com, example2.com");
cmd->AppendSwitch(optimization_guide::switches::kFetchHintsOverrideTimer);
}
// Creates hint data for the |hint_setup_url|'s so that the fetching of the
// hints is triggered.
void SetUpComponentUpdateHints(const GURL& hint_setup_url) {
const optimization_guide::HintsComponentInfo& component_info =
test_hints_component_creator_.CreateHintsComponentInfoWithPageHints(
optimization_guide::proto::NOSCRIPT, {hint_setup_url.host()}, "*");
base::HistogramTester histogram_tester;
optimization_guide::OptimizationHintsComponentUpdateListener::GetInstance()
->MaybeUpdateHintsComponent(component_info);
RetryForHistogramUntilCountReached(
&histogram_tester,
optimization_guide::kComponentHintsUpdatedResultHistogramString, 1);
}
void SetNetworkConnectionOffline() {
content::NetworkConnectionChangeSimulator().SetConnectionType(
network::mojom::ConnectionType::CONNECTION_NONE);
}
void SetResponseType(HintsFetcherRemoteResponseType response_type) {
response_type_ = response_type;
}
// Seeds the Site Engagement Service with two HTTP and two HTTPS sites for the
// current profile.
void SeedSiteEngagementService() {
auto* service = site_engagement::SiteEngagementService::Get(
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext()));
GURL https_url1("https://images.google.com/");
service->AddPointsForTesting(https_url1, 15);
GURL https_url2("https://news.google.com/");
service->AddPointsForTesting(https_url2, 3);
GURL http_url1("http://photos.google.com/");
service->AddPointsForTesting(http_url1, 21);
GURL http_url2("http://maps.google.com/");
service->AddPointsForTesting(http_url2, 2);
}
void SetTopHostBlacklistState(
optimization_guide::prefs::HintsFetcherTopHostBlacklistState
blacklist_state) {
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext())
->GetPrefs()
->SetInteger(
optimization_guide::prefs::kHintsFetcherTopHostBlacklistState,
static_cast<int>(blacklist_state));
}
void LoadHintsForUrl(const GURL& url) {
base::HistogramTester histogram_tester;
// Navigate to |url| to prime the OptimizationGuide hints for the
// url's host and ensure that they have been loaded from the store (via
// histogram) prior to the navigation that tests functionality.
ui_test_utils::NavigateToURL(browser(), url);
RetryForHistogramUntilCountReached(
&histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
}
// Returns the count of top hosts that are blacklisted by reading the relevant
// pref.
size_t GetTopHostBlacklistSize() const {
PrefService* pref_service = browser()->profile()->GetPrefs();
const base::DictionaryValue* top_host_blacklist =
pref_service->GetDictionary(
optimization_guide::prefs::kHintsFetcherTopHostBlacklist);
return top_host_blacklist->size();
}
// Adds |host_count| HTTPS origins to site engagement service.
void AddHostsToSiteEngagementService(size_t host_count) {
auto* service = site_engagement::SiteEngagementService::Get(
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext()));
for (size_t i = 0; i < host_count; ++i) {
GURL https_url("https://myfavoritesite" + base::NumberToString(i) +
".com/");
service->AddPointsForTesting(https_url, 15);
}
}
// Returns the number of hosts known to the site engagement service. The value
// is obtained by querying the site engagement service.
size_t GetCountHostsKnownToSiteEngagementService() const {
auto* service = site_engagement::SiteEngagementService::Get(
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext()));
return service->GetAllDetails().size();
}
const GURL& https_url() const { return https_url_; }
const base::HistogramTester* GetHistogramTester() {
return &histogram_tester_;
}
const GURL& search_results_page_url() const {
return search_results_page_url_;
}
void SetExpectedHintsRequestForHostsAndUrls(
const base::flat_set<std::string>& hosts_or_urls) {
base::AutoLock lock(lock_);
expect_hints_request_for_hosts_and_urls_ = hosts_or_urls;
}
size_t count_hints_requests_received() {
base::AutoLock lock(lock_);
return count_hints_requests_received_;
}
void WaitUntilHintsFetcherRequestReceived() {
while (true) {
{
// Acquire the |lock_| inside to avoid starving other consumers of the
// lock.
base::AutoLock lock(lock_);
if (count_hints_requests_received_ > 0)
return;
}
base::RunLoop().RunUntilIdle();
}
}
void ResetCountHintsRequestsReceived() {
base::AutoLock lock(lock_);
count_hints_requests_received_ = 0;
}
// Wait for page layout to happen. This is needed in some tests since the
// anchor elements are extracted from the webpage after page layout finishes.
void WaitForPageLayout() {
const char* entry_name =
ukm::builders::NavigationPredictorPageLinkMetrics::kEntryName;
if (ukm_recorder_->GetEntriesByName(entry_name).empty()) {
base::RunLoop run_loop;
ukm_recorder_->SetOnAddEntryCallback(entry_name, run_loop.QuitClosure());
run_loop.Run();
}
}
protected:
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<net::EmbeddedTestServer> origin_server_;
std::unique_ptr<net::EmbeddedTestServer> hints_server_;
HintsFetcherRemoteResponseType response_type_ =
HintsFetcherRemoteResponseType::kSuccessful;
private:
std::unique_ptr<net::test_server::HttpResponse> HandleOriginRequest(
const net::test_server::HttpRequest& request) {
EXPECT_EQ(request.method, net::test_server::METHOD_GET);
std::unique_ptr<net::test_server::BasicHttpResponse> response;
response.reset(new net::test_server::BasicHttpResponse);
response->set_code(net::HTTP_OK);
return std::move(response);
}
std::unique_ptr<net::test_server::HttpResponse> HandleGetHintsRequest(
const net::test_server::HttpRequest& request) {
base::AutoLock lock(lock_);
++count_hints_requests_received_;
std::unique_ptr<net::test_server::BasicHttpResponse> response;
response.reset(new net::test_server::BasicHttpResponse);
// If the request is a GET, it corresponds to a navigation so return a
// normal response.
EXPECT_EQ(request.method, net::test_server::METHOD_POST);
EXPECT_NE(request.headers.end(), request.headers.find("X-Client-Data"));
optimization_guide::proto::GetHintsRequest hints_request;
EXPECT_TRUE(hints_request.ParseFromString(request.content));
EXPECT_FALSE(hints_request.hosts().empty() && hints_request.urls().empty());
EXPECT_GE(optimization_guide::features::
MaxHostsForOptimizationGuideServiceHintsFetch(),
static_cast<size_t>(hints_request.hosts().size()));
// Only verify the hints if there are hosts in the request.
if (!hints_request.hosts().empty())
VerifyHintsMatchExpectedHostsAndUrls(hints_request);
if (response_type_ == HintsFetcherRemoteResponseType::kSuccessful) {
response->set_code(net::HTTP_OK);
optimization_guide::proto::GetHintsResponse get_hints_response;
optimization_guide::proto::Hint* hint = get_hints_response.add_hints();
hint->set_key_representation(optimization_guide::proto::HOST);
hint->set_key(https_url_.host());
optimization_guide::proto::PageHint* page_hint = hint->add_page_hints();
page_hint->set_page_pattern("page pattern");
std::string serialized_request;
get_hints_response.SerializeToString(&serialized_request);
response->set_content(serialized_request);
} else if (response_type_ ==
HintsFetcherRemoteResponseType::kUnsuccessful) {
response->set_code(net::HTTP_NOT_FOUND);
} else if (response_type_ == HintsFetcherRemoteResponseType::kMalformed) {
response->set_code(net::HTTP_OK);
std::string serialized_request = "Not a proto";
response->set_content(serialized_request);
} else if (response_type_ == HintsFetcherRemoteResponseType::kHung) {
return std::make_unique<net::test_server::HungResponse>();
} else {
NOTREACHED();
}
return std::move(response);
}
// Verifies that the hosts present in |hints_request| match the expected set
// of hosts present in |expect_hints_request_for_hosts_|. The ordering of the
// hosts in not matched.
void VerifyHintsMatchExpectedHostsAndUrls(
const optimization_guide::proto::GetHintsRequest& hints_request) const {
if (!expect_hints_request_for_hosts_and_urls_)
return;
base::flat_set<std::string> hosts_and_urls_requested;
for (const auto& host : hints_request.hosts())
hosts_and_urls_requested.insert(host.host());
for (const auto& url : hints_request.urls()) {
// TODO(crbug/1051365): Remove normalization step once nav predictor
// provides predictable URLs.
hosts_and_urls_requested.insert(GURL(url.url()).GetAsReferrer().spec());
}
EXPECT_EQ(expect_hints_request_for_hosts_and_urls_.value().size(),
hosts_and_urls_requested.size());
for (const auto& host_or_url :
expect_hints_request_for_hosts_and_urls_.value()) {
hosts_and_urls_requested.erase(host_or_url);
}
EXPECT_EQ(0u, hosts_and_urls_requested.size());
// We only expect 1 field trial to be allowed and sent up.
EXPECT_EQ(1, hints_request.active_field_trials_size());
EXPECT_EQ(variations::HashName(
"scoped_feature_list_trial_for_OptimizationHintsFetching"),
hints_request.active_field_trials(0).name_hash());
}
void TearDownOnMainThread() override {
EXPECT_TRUE(origin_server_->ShutdownAndWaitUntilComplete());
EXPECT_TRUE(hints_server_->ShutdownAndWaitUntilComplete());
InProcessBrowserTest::TearDownOnMainThread();
}
base::test::ScopedFeatureList param_feature_list_;
GURL https_url_;
GURL search_results_page_url_;
base::HistogramTester histogram_tester_;
optimization_guide::testing::TestHintsComponentCreator
test_hints_component_creator_;
base::Lock lock_;
// Guarded by |lock_|.
// Count of hints requests received so far by |hints_server_|.
size_t count_hints_requests_received_ = 0;
// Guarded by |lock_|. Set of hosts and URLs for which a hints request is
// expected to arrive. This set is verified to match with the set of hosts and
// URLs present in the hints request. If null, then the verification is not
// done.
base::Optional<base::flat_set<std::string>>
expect_hints_request_for_hosts_and_urls_;
std::unique_ptr<ukm::TestAutoSetUkmRecorder> ukm_recorder_;
DISALLOW_COPY_AND_ASSIGN(HintsFetcherDisabledBrowserTest);
};
// This test class enables OnePlatform Hints.
class HintsFetcherBrowserTest : public HintsFetcherDisabledBrowserTest {
public:
HintsFetcherBrowserTest() = default;
~HintsFetcherBrowserTest() override = default;
void SetUp() override {
// Enable OptimizationHintsFetching with |kRemoteOptimizationGuideFetching|.
scoped_feature_list_.InitWithFeaturesAndParameters(
{
{optimization_guide::features::kOptimizationHints, {}},
{optimization_guide::features::kRemoteOptimizationGuideFetching,
{{"max_concurrent_page_navigation_fetches", "2"}}},
{optimization_guide::features::kOptimizationHintsFieldTrials,
{{"allowed_field_trial_names",
"scoped_feature_list_trial_for_OptimizationHintsFetching"}}},
},
{});
// Call to inherited class to match same set up with feature flags added.
HintsFetcherDisabledBrowserTest::SetUp();
}
void SetUpOnMainThread() override {
// Register an optimization type, so hints will be fetched at page
// navigation.
OptimizationGuideKeyedServiceFactory::GetForProfile(
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext()))
->RegisterOptimizationTypes({optimization_guide::proto::NOSCRIPT});
HintsFetcherDisabledBrowserTest::SetUpOnMainThread();
}
optimization_guide::TopHostProvider* top_host_provider() {
OptimizationGuideKeyedService* keyed_service =
OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile());
return keyed_service->GetTopHostProvider();
}
private:
DISALLOW_COPY_AND_ASSIGN(HintsFetcherBrowserTest);
};
// This test creates new browser with no profile and loads a random page with
// the feature flags for OptimizationHintsFetching. We confirm that the
// TopHostProvider is called and does not crash by checking UMA
// histograms for the total number of TopEngagementSites and
// the total number of sites returned controlled by the experiments flag
// |max_oneplatform_update_hosts|.
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherEnabled) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherDisabledBrowserTest, HintsFetcherDisabled) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Expect that the histogram for HintsFetcher to be 0 because the OnePlatform
// is not enabled.
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 0);
}
// This test creates a new browser and seeds the Site Engagement Service with
// both HTTP and HTTPS sites. The test confirms that top host provider
// is called to provide a list of hosts to HintsFetcher only returns hosts with
// a HTTPS scheme. We verify this with the UMA histogram logged when the
// GetHintsRequest is made to the remote Optimization Guide Service.
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, TopHostProviderHTTPSOnly) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Adds two HTTP and two HTTPS sites into the Site Engagement Service.
SeedSiteEngagementService();
// This forces the hint cache to be initialized and hints to be fetched.
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample as
// Hints Fetching is enabled. This also ensures that the histograms have been
// updated to verify the correct number of hosts that hints will be requested
// for.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
// Only the 2 HTTPS hosts should be requested hints for.
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 2, 1);
EXPECT_EQ(0u, GetTopHostBlacklistSize());
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherFetchedHintsLoaded) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
GURL url = https_url();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1),
1);
LoadHintsForUrl(https_url());
ui_test_utils::NavigateToURL(browser(), https_url());
// Verifies that the fetched hint is just used in memory and nothing is
// loaded.
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintCache.HintType.Loaded", 0);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesSuccessful) {
SetResponseType(HintsFetcherRemoteResponseType::kSuccessful);
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
// Wait until histograms have been updated before performing checks for
// correct behavior based on the response.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesUnsuccessful) {
SetResponseType(HintsFetcherRemoteResponseType::kUnsuccessful);
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
// Wait until histograms have been updated before performing checks for
// correct behavior based on the response.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status",
net::HTTP_NOT_FOUND, 1);
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 0);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesMalformed) {
SetResponseType(HintsFetcherRemoteResponseType::kMalformed);
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
// Wait until histograms have been updated before performing checks for
// correct behavior based on the response.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 0);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcherWithResponsesUnsuccessfulAtNavigationTime) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
SetResponseType(HintsFetcherRemoteResponseType::kUnsuccessful);
// Set the ECT to force a fetch at navigation time.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
ui_test_utils::NavigateToURL(browser(), GURL("https://unsuccessful.com/"));
// We expect that we requested hints for 1 URL.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.UrlCount", 1),
1);
}
IN_PROC_BROWSER_TEST_F(
HintsFetcherBrowserTest,
HintsFetcherWithResponsesHungShouldRecordWhenActiveRequestCanceled) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
SetResponseType(HintsFetcherRemoteResponseType::kHung);
// Set the ECT to force a fetch at navigation time.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
ui_test_utils::NavigateToURL(browser(), GURL("https://hung.com/1"));
ui_test_utils::NavigateToURL(browser(), GURL("https://hung.com/2"));
ui_test_utils::NavigateToURL(browser(), GURL("https://hung.com/3"));
// We expect that one request was canceled.
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.ActiveRequestCanceled."
"PageNavigation",
1, 1);
}
// TODO(crbug.com/1166906):
// HintsFetcherBrowserTest.HintsFetcherClearFetchedHints is flaky on Windows and
// Linux.
#if defined(OS_WIN) || defined(OS_LINUX)
#define MAYBE_HintsFetcherClearFetchedHints \
DISABLED_HintsFetcherClearFetchedHints
#else
#define MAYBE_HintsFetcherClearFetchedHints HintsFetcherClearFetchedHints
#endif // defined(OS_WIN) || defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
MAYBE_HintsFetcherClearFetchedHints) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
GURL url = https_url();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as OnePlatform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1),
1);
LoadHintsForUrl(https_url());
ui_test_utils::NavigateToURL(browser(), https_url());
// Verifies that the fetched hint is used in-memory and no hint is loaded
// from store.
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintCache.HintType.Loaded", 0);
// Wipe the browser history - clear all the fetched hints.
browser()->profile()->Wipe();
// Try to load the same hint to confirm fetched hints are no longer there.
LoadHintsForUrl(https_url());
ui_test_utils::NavigateToURL(browser(), https_url());
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintCache.HintType.Loaded",
static_cast<int>(optimization_guide::OptimizationGuideStore::
StoreEntryType::kComponentHint),
1);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherOverrideTimer) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
GURL url = https_url();
base::CommandLine::ForCurrentProcess()->RemoveSwitch(
optimization_guide::switches::kFetchHintsOverride);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
optimization_guide::switches::kFetchHintsOverrideTimer);
SeedSiteEngagementService();
// Set the blacklist state to initialized so the sites in the engagement
// service will be used and not blacklisted on the first GetTopHosts request.
SetTopHostBlacklistState(optimization_guide::prefs::
HintsFetcherTopHostBlacklistState::kInitialized);
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as OnePlatform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
// There should be 2 sites in the engagement service.
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 2, 1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
// There should have been 1 hint returned in the response.
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
LoadHintsForUrl(https_url());
ui_test_utils::NavigateToURL(browser(), https_url());
// Verifies that the fetched hint is used from memory and no hints are loaded.
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintCache.HintType.Loaded", 0);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherNetworkOffline) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
GURL url = https_url();
base::CommandLine::ForCurrentProcess()->RemoveSwitch(
optimization_guide::switches::kFetchHintsOverride);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
optimization_guide::switches::kFetchHintsOverrideTimer);
// Set the network to be offline.
SetNetworkConnectionOffline();
// Set the blacklist state to initialized so the sites in the engagement
// service will be used and not blacklisted on the first GetTopHosts
// request.
SeedSiteEngagementService();
// Set the blacklist state to initialized so the sites in the engagement
// service will be used and not blacklisted on the first GetTopHosts request.
SetTopHostBlacklistState(optimization_guide::prefs::
HintsFetcherTopHostBlacklistState::kInitialized);
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// No HintsFetch should occur because the connection is offline.
histogram_tester->ExpectTotalCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 0);
}
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, HintsFetcherFetches) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as hints fetching is enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
}
// Test that the hints are fetched at the time of the navigation.
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_ECT) {
{
base::HistogramTester histogram_tester;
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
RetryForHistogramUntilCountReached(
&histogram_tester,
optimization_guide::kComponentHintsUpdatedResultHistogramString, 1);
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(
RetryForHistogramUntilCountReached(
&histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
&histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK,
1);
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
EXPECT_EQ(1u, count_hints_requests_received());
}
// Change ECT to a low value. Hints should be fetched at the time of
// navigation.
{
base::HistogramTester histogram_tester;
ukm::TestAutoSetUkmRecorder ukm_recorder;
ResetCountHintsRequestsReceived();
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
// Navigate to a host not in the seeded site engagement service; it
// should be recorded as covered by the hints fetcher due to the race.
base::flat_set<std::string> expected_request_2g;
std::string host_2g("https://unseenhost_2g.com/");
expected_request_2g.insert(GURL(host_2g).host());
expected_request_2g.insert(GURL(host_2g).spec());
SetExpectedHintsRequestForHostsAndUrls(expected_request_2g);
ui_test_utils::NavigateToURL(browser(), GURL(host_2g));
EXPECT_EQ(1u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
&histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
// Navigate away so metrics are recorded.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
ui_test_utils::NavigateToURL(browser(), GURL("http://nohints.com/"));
auto entries = ukm_recorder.GetEntriesByName(
ukm::builders::OptimizationGuide::kEntryName);
EXPECT_EQ(1u, entries.size());
auto* entry = entries[0];
EXPECT_TRUE(ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchRequestLatencyName));
EXPECT_TRUE(ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName));
ukm_recorder.ExpectEntryMetric(
entry,
ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName,
static_cast<int>(optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHostAndURL));
}
// Change ECT to unknown. Hints should not be fetched at the time of
// navigation as the ECT is unknown so the fetcher should not race.
{
base::HistogramTester histogram_tester;
ResetCountHintsRequestsReceived();
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
base::flat_set<std::string> expected_request_unknown;
std::string host_unknown_ect("https://unseenhost_unknown_ect.com/");
expected_request_unknown.insert((GURL(host_unknown_ect).host()));
expected_request_unknown.insert((GURL(host_unknown_ect).spec()));
SetExpectedHintsRequestForHostsAndUrls(expected_request_unknown);
ui_test_utils::NavigateToURL(browser(), GURL(host_unknown_ect));
EXPECT_EQ(0u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
&histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
// Navigate away so metrics are recorded.
base::HistogramTester prev_nav_histogram_tester;
ukm::TestAutoSetUkmRecorder prev_nav_ukm_recorder;
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
ui_test_utils::NavigateToURL(browser(), GURL("http://nohints.com/"));
auto entries = prev_nav_ukm_recorder.GetEntriesByName(
ukm::builders::OptimizationGuide::kEntryName);
EXPECT_EQ(1u, entries.size());
auto* entry = entries[0];
EXPECT_FALSE(prev_nav_ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchRequestLatencyName));
EXPECT_FALSE(prev_nav_ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName));
}
// Change ECT back to a low value. Hints should be fetched at the time of
// navigation.
{
base::HistogramTester histogram_tester;
ResetCountHintsRequestsReceived();
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_3G);
// Navigate to a host not in the seeded site engagement service; it
// should be recorded as not covered by the hints fetcher.
base::flat_set<std::string> expected_request_3g;
std::string host_3g("https://unseenhost_3g.com/");
expected_request_3g.insert(GURL(host_3g).host());
expected_request_3g.insert(GURL(host_3g).spec());
SetExpectedHintsRequestForHostsAndUrls(expected_request_3g);
ui_test_utils::NavigateToURL(browser(), GURL(host_3g));
EXPECT_EQ(1u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
&histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
// Navigate away so metrics are recorded.
base::HistogramTester prev_nav_histogram_tester;
ukm::TestAutoSetUkmRecorder prev_nav_ukm_recorder;
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
ui_test_utils::NavigateToURL(browser(), GURL("http://nohints.com/"));
auto entries = prev_nav_ukm_recorder.GetEntriesByName(
ukm::builders::OptimizationGuide::kEntryName);
EXPECT_EQ(1u, entries.size());
auto* entry = entries[0];
EXPECT_TRUE(prev_nav_ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchRequestLatencyName));
EXPECT_TRUE(prev_nav_ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName));
prev_nav_ukm_recorder.ExpectEntryMetric(
entry,
ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName,
static_cast<int>(optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHostAndURL));
}
// Navigate again to a webpage with the
// same host. Hints should be available at the time of
// navigation.
{
base::HistogramTester histogram_tester;
ResetCountHintsRequestsReceived();
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_3G);
// Navigate to a host that was recently fetched. It
// should be recorded as covered by the hints fetcher.
base::flat_set<std::string> expected_request_3g;
std::string host_3g("https://unseenhost_3g.com");
expected_request_3g.insert(GURL(host_3g).host());
expected_request_3g.insert(GURL(host_3g).spec());
SetExpectedHintsRequestForHostsAndUrls(expected_request_3g);
ui_test_utils::NavigateToURL(browser(),
GURL("https://unseenhost_3g.com/test1.html"));
// With URL-keyed Hints, every unique URL navigated to will result in a
// hints fetch if racing is enabled and allowed.
EXPECT_EQ(1u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
&histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
// Navigate away so metrics are recorded.
base::HistogramTester prev_nav_histogram_tester;
ukm::TestAutoSetUkmRecorder prev_nav_ukm_recorder;
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
ui_test_utils::NavigateToURL(browser(), GURL("http://nohints.com/"));
auto entries = prev_nav_ukm_recorder.GetEntriesByName(
ukm::builders::OptimizationGuide::kEntryName);
EXPECT_EQ(1u, entries.size());
auto* entry = entries[0];
EXPECT_TRUE(prev_nav_ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchRequestLatencyName));
EXPECT_TRUE(prev_nav_ukm_recorder.EntryHasMetric(
entry, ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName));
prev_nav_ukm_recorder.ExpectEntryMetric(
entry,
ukm::builders::OptimizationGuide::
kNavigationHintsFetchAttemptStatusName,
static_cast<int>(optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHostAndURL));
}
}
// Test that the hints are fetched at the time of the navigation.
IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_URLKeyedNotRefetched) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
RetryForHistogramUntilCountReached(
histogram_tester,
optimization_guide::kComponentHintsUpdatedResultHistogramString, 1);
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
EXPECT_EQ(1u, count_hints_requests_received());
// Setting the connection type to be slow so the page navigation race fetch
// is initiated.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
std::string full_url("https://foo.com/test/");
{
// Navigate to a host not in the seeded site engagement service; it
// should be recorded as a race for both the host and the URL.
base::flat_set<std::string> expected_request;
expected_request.insert(GURL(full_url).host());
expected_request.insert(GURL(full_url).spec());
SetExpectedHintsRequestForHostsAndUrls(expected_request);
ui_test_utils::NavigateToURL(browser(), GURL(full_url));
EXPECT_EQ(2u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus",
optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHostAndURL,
1);
}
// Navigate again to the same webpage, no race should occur.
{
// Navigate to a host that was recently fetched. It
// should be recorded as covered by the hints fetcher.
base::flat_set<std::string> expected_request;
SetExpectedHintsRequestForHostsAndUrls(expected_request);
ui_test_utils::NavigateToURL(browser(), GURL(full_url));
// With URL-keyed Hints, every unique URL navigated to will result in a
// hints fetch if racing is enabled and allowed.
EXPECT_EQ(2u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
2);
// Only the host will be attempted to race, the fetcher should block the
// host from being fetched.
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus",
optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHost,
1);
}
// Incognito page loads should not initiate any fetches.
{
base::HistogramTester incognito_histogram_tester;
// Instantiate off the record Optimization Guide Service.
OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()->GetPrimaryOTRProfile())
->RegisterOptimizationTypes({optimization_guide::proto::NOSCRIPT});
Browser* otr_browser = CreateIncognitoBrowser(browser()->profile());
ui_test_utils::NavigateToURL(otr_browser, GURL(full_url));
// Make sure no additional hints requests were received.
RetryForHistogramUntilCountReached(
&incognito_histogram_tester,
optimization_guide::kLoadedHintLocalHistogramString, 1);
EXPECT_EQ(2u, count_hints_requests_received());
incognito_histogram_tester.ExpectTotalCount(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus", 0);
}
}
// Test that the hints are fetched at the time of the navigation.
IN_PROC_BROWSER_TEST_F(
HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_FetchWithNewlyRegisteredOptType) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
RetryForHistogramUntilCountReached(
histogram_tester,
optimization_guide::kComponentHintsUpdatedResultHistogramString, 1);
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
EXPECT_EQ(1u, count_hints_requests_received());
// Setting the connection type to be slow so the page navigation race fetch
// is initiated.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
std::string full_url("https://foo.com/test/");
{
// Navigate to a host not in the seeded site engagement service; it
// should be recorded as a race for both the host and the URL.
base::flat_set<std::string> expected_request;
expected_request.insert(GURL(full_url).host());
expected_request.insert(GURL(full_url).spec());
SetExpectedHintsRequestForHostsAndUrls(expected_request);
ui_test_utils::NavigateToURL(browser(), GURL(full_url));
EXPECT_EQ(2u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus",
optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHostAndURL,
1);
}
OptimizationGuideKeyedServiceFactory::GetForProfile(
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext()))
->RegisterOptimizationTypes(
{optimization_guide::proto::COMPRESS_PUBLIC_IMAGES});
// Navigate again to the same webpage, the race should occur because the
// hints have been cleared.
{
// Navigate to a host that was recently fetched. It
// should be recorded as covered by the hints fetcher.
base::flat_set<std::string> expected_request;
expected_request.insert(GURL(full_url).host());
SetExpectedHintsRequestForHostsAndUrls(expected_request);
ui_test_utils::NavigateToURL(browser(), GURL(full_url));
// With URL-keyed Hints, every unique URL navigated to will result in a
// hints fetch if racing is enabled and allowed.
EXPECT_EQ(3u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
2);
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus",
optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHost,
1);
}
}
// Test that the hints are fetched at the time of the navigation.
IN_PROC_BROWSER_TEST_F(
HintsFetcherBrowserTest,
HintsFetcher_NavigationFetch_CacheNotClearedOnLaunchedOptTypes) {
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
RetryForHistogramUntilCountReached(
histogram_tester,
optimization_guide::kComponentHintsUpdatedResultHistogramString, 1);
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
EXPECT_EQ(1u, count_hints_requests_received());
// Setting the connection type to be slow so the page navigation race fetch
// is initiated.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
std::string full_url("https://foo.com/test/");
{
// Navigate to a host not in the seeded site engagement service; it
// should be recorded as a race for both the host and the URL.
base::flat_set<std::string> expected_request;
expected_request.insert(GURL(full_url).host());
expected_request.insert(GURL(full_url).spec());
SetExpectedHintsRequestForHostsAndUrls(expected_request);
ui_test_utils::NavigateToURL(browser(), GURL(full_url));
EXPECT_EQ(2u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus",
optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHostAndURL,
1);
}
OptimizationGuideKeyedServiceFactory::GetForProfile(
Profile::FromBrowserContext(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetBrowserContext()))
->RegisterOptimizationTypes(
{optimization_guide::proto::DEFER_ALL_SCRIPT});
// Navigate again to the same webpage, no race should occur.
{
// Navigate to a host that was recently fetched. It
// should be recorded as covered by the hints fetcher.
base::flat_set<std::string> expected_request;
SetExpectedHintsRequestForHostsAndUrls(expected_request);
ui_test_utils::NavigateToURL(browser(), GURL(full_url));
// With URL-keyed Hints, every unique URL navigated to will result in a
// hints fetch if racing is enabled and allowed.
EXPECT_EQ(2u, count_hints_requests_received());
RetryForHistogramUntilCountReached(
histogram_tester, optimization_guide::kLoadedHintLocalHistogramString,
2);
// Only the host will be attempted to race, the fetcher should block the
// host from being fetched.
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus",
optimization_guide::RaceNavigationFetchAttemptStatus::
kRaceNavigationFetchHost,
1);
}
}
class HintsFetcherChangeDefaultBlacklistSizeBrowserTest
: public HintsFetcherBrowserTest {
public:
HintsFetcherChangeDefaultBlacklistSizeBrowserTest() = default;
~HintsFetcherChangeDefaultBlacklistSizeBrowserTest() override = default;
void SetUp() override {
base::FieldTrialParams optimization_hints_fetching_params;
optimization_hints_fetching_params["top_host_blacklist_size_multiplier"] =
"5";
scoped_feature_list_.InitWithFeaturesAndParameters(
{
/* vector of enabled features along with params */
{optimization_guide::features::kRemoteOptimizationGuideFetching,
{optimization_hints_fetching_params}},
{optimization_guide::features::kOptimizationHints, {}},
},
{/* disabled_features */});
// Call to inherited class to match same set up with feature flags added.
HintsFetcherDisabledBrowserTest::SetUp();
}
void SetUpCommandLine(base::CommandLine* cmd) override {
cmd->AppendSwitch("enable-spdy-proxy-auth");
cmd->AppendSwitch("purge_hint_cache_store");
// Set up OptimizationGuideServiceURL, this does not enable HintsFetching,
// only provides the URL.
cmd->AppendSwitchASCII(
optimization_guide::switches::kOptimizationGuideServiceGetHintsURL,
hints_server_->base_url().spec());
cmd->AppendSwitch(optimization_guide::switches::
kDisableCheckingUserPermissionsForTesting);
}
private:
DISALLOW_COPY_AND_ASSIGN(HintsFetcherChangeDefaultBlacklistSizeBrowserTest);
};
// Changes the default size of the top host blacklist using finch. Also, sets
// the count of hosts previously engaged to a large number and verifies that the
// top host blacklist is correctly populated.
IN_PROC_BROWSER_TEST_F(HintsFetcherChangeDefaultBlacklistSizeBrowserTest,
ChangeDefaultBlacklistSize) {
AddHostsToSiteEngagementService(120u);
const size_t engaged_hosts = GetCountHostsKnownToSiteEngagementService();
EXPECT_EQ(120u, engaged_hosts);
// Ensure everything within the site engagement service fits within the top
// host blacklist size.
ASSERT_LE(
engaged_hosts,
optimization_guide::features::MaxHintsFetcherTopHostBlacklistSize());
SetTopHostBlacklistState(
optimization_guide::prefs::HintsFetcherTopHostBlacklistState::
kNotInitialized);
ASSERT_TRUE(top_host_provider());
std::vector<std::string> top_hosts = top_host_provider()->GetTopHosts();
EXPECT_EQ(0u, top_hosts.size());
top_hosts = top_host_provider()->GetTopHosts();
EXPECT_EQ(0u, top_hosts.size());
// Everything HTTPS origin within the site engagement service should now be
// in the blacklist.
EXPECT_EQ(engaged_hosts, GetTopHostBlacklistSize());
}
class HintsFetcherSearchPageBrowserTest : public HintsFetcherBrowserTest {
void SetUpCommandLine(base::CommandLine* cmd) override {
cmd->AppendSwitch(optimization_guide::switches::
kDisableFetchingHintsAtNavigationStartForTesting);
cmd->AppendSwitch("ignore-certificate-errors");
HintsFetcherBrowserTest::SetUpCommandLine(cmd);
}
};
IN_PROC_BROWSER_TEST_F(HintsFetcherSearchPageBrowserTest,
HintsFetcher_SRP_Slow_Connection) {
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
const base::HistogramTester* histogram_tester = GetHistogramTester();
// Whitelist NoScript for https_url()'s' host.
SetUpComponentUpdateHints(https_url());
// Expect that the browser initialization will record at least one sample
// in each of the following histograms as One Platform Hints are enabled.
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1),
1);
EXPECT_GE(RetryForHistogramUntilCountReached(
histogram_tester,
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", 1),
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.Status", net::HTTP_OK, 1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.NetErrorCode", net::OK,
1);
histogram_tester->ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HintCount", 1, 1);
// Populate expected hosts with hosts contained in the html response of
// search_results_page_url(). example2.com is contained in the HTML
// response, but hints for example2.com must not be fetched since they
// were pushed via kFetchHintsOverride switch above.
base::flat_set<std::string> expected_hosts_and_urls;
// Unique hosts.
expected_hosts_and_urls.insert(GURL("https://foo.com").host());
expected_hosts_and_urls.insert(GURL("https://example.com").host());
expected_hosts_and_urls.insert(GURL("https://example3.com").host());
// Unique URLs.
expected_hosts_and_urls.insert("https://foo.com/");
expected_hosts_and_urls.insert(
"https://foo.com/simple_page_with_anchors.html");
expected_hosts_and_urls.insert("https://example.com/foo.html");
expected_hosts_and_urls.insert("https://example.com/bar.html");
expected_hosts_and_urls.insert("https://example.com/baz.html");
expected_hosts_and_urls.insert("https://example2.com/foo.html");
expected_hosts_and_urls.insert("https://example3.com/foo.html");
SetExpectedHintsRequestForHostsAndUrls(expected_hosts_and_urls);
histogram_tester->ExpectTotalCount(
optimization_guide::kLoadedHintLocalHistogramString, 0);
// Navigate to a host not in the seeded site engagement service; it
// should be recorded as not covered by the hints fetcher.
ResetCountHintsRequestsReceived();
ui_test_utils::NavigateToURL(browser(), search_results_page_url());
WaitForPageLayout();
RetryForHistogramUntilCountReached(
histogram_tester,
"AnchorElementMetrics.Visible.NumberOfAnchorElementsAfterMerge", 1);
WaitUntilHintsFetcherRequestReceived();
EXPECT_EQ(1u, count_hints_requests_received());
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 3, 1);
histogram_tester->ExpectBucketCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.UrlCount", 7, 1);
}
|