Commit 05a56d5b authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Move testing of Loading Predictor optimization guide to unit tests

This also re-enables the browser tests since the flakes were mostly tied
to the UMA histogram reporting.

Bug: 1060966,1060397
Change-Id: I67a1dfafa5d220e3a2165981e4bd4a6812174aa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134645
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756093}
parent 473cb61e
......@@ -1541,6 +1541,14 @@ class LoadingPredictorBrowserTestWithOptimizationGuide
}
}
void SetUpOnMainThread() override {
// Wait until command line hints have been processed before proceeding with
// tests.
RetryForHistogramUntilCountReached(
histogram_tester_, "OptimizationGuide.UpdateComponentHints.Result", 1);
LoadingPredictorBrowserTest::SetUpOnMainThread();
}
void SetUpCommandLine(base::CommandLine* command_line) override {
// TODO(crbug/1035698): Make this simpler when Optimization Guide has better
// test support.
......@@ -1585,6 +1593,7 @@ class LoadingPredictorBrowserTestWithOptimizationGuide
}
private:
base::HistogramTester histogram_tester_;
base::test::ScopedFeatureList feature_list_;
base::test::ScopedFeatureList local_predictions_feature_list_;
};
......@@ -1600,9 +1609,9 @@ INSTANTIATE_TEST_SUITE_P(,
#define DISABLE_ON_WIN_MAC_CHROMEOS(x) x
#endif
IN_PROC_BROWSER_TEST_P(
LoadingPredictorBrowserTestWithOptimizationGuide,
DISABLED_NavigationHasLocalPredictionNoOptimizationHint) {
IN_PROC_BROWSER_TEST_P(LoadingPredictorBrowserTestWithOptimizationGuide,
DISABLE_ON_WIN_MAC_CHROMEOS(
NavigationHasLocalPredictionNoOptimizationHint)) {
// Navigate the first time to fill the predictor's database and the HTTP
// cache.
GURL url = embedded_test_server()->GetURL(
......@@ -1613,8 +1622,6 @@ IN_PROC_BROWSER_TEST_P(
ui_test_utils::NavigateToURL(browser(), url);
ResetNetworkState();
base::HistogramTester histogram_tester;
auto observer = NavigateToURLAsync(url);
EXPECT_TRUE(observer->WaitForRequestStart());
for (auto* const host : kHtmlSubresourcesHosts) {
......@@ -1641,20 +1648,12 @@ IN_PROC_BROWSER_TEST_P(
connection_tracker()->GetAcceptedSocketCount());
// No reads since all resources should be cached.
EXPECT_EQ(0u, connection_tracker()->GetReadSocketCount());
if (IsLocalPredictionEnabled()) {
histogram_tester.ExpectTotalCount(
"LoadingPredictor.OptimizationHintsReceiveStatus", 0);
} else {
histogram_tester.ExpectTotalCount(
"LoadingPredictor.OptimizationHintsReceiveStatus", 1);
}
}
// TODO(crbug.com/1060966): Tests are flakey.
IN_PROC_BROWSER_TEST_P(
LoadingPredictorBrowserTestWithOptimizationGuide,
DISABLED_NavigationWithBothLocalPredictionAndOptimizationHint) {
DISABLE_ON_WIN_MAC_CHROMEOS(
NavigationWithBothLocalPredictionAndOptimizationHint)) {
base::HistogramTester histogram_tester;
GURL url = embedded_test_server()->GetURL(
......@@ -1705,32 +1704,12 @@ IN_PROC_BROWSER_TEST_P(
EXPECT_TRUE(preconnect_manager_observer()->HasOriginAttemptedToPreconnect(
expected_origin));
}
if (IsLocalPredictionEnabled()) {
histogram_tester.ExpectUniqueSample(
"LoadingPredictor.OptimizationHintsReceiveStatus",
OptimizationHintsReceiveStatus::kAfterNavigationFinish, 1);
} else {
// We expect one for the setup navigation and one for the navigation we care
// about.
histogram_tester.ExpectTotalCount(
"LoadingPredictor.OptimizationHintsReceiveStatus", 2);
// We expect the hints to arrive before navigation for the navigation we
// care about.
histogram_tester.ExpectBucketCount(
"LoadingPredictor.OptimizationHintsReceiveStatus",
OptimizationHintsReceiveStatus::kBeforeNavigationFinish, 1);
// We expect the decision to arrive at finish for the setup navigation.
histogram_tester.ExpectBucketCount(
"LoadingPredictor.OptimizationHintsReceiveStatus",
OptimizationHintsReceiveStatus::kAfterNavigationFinish, 1);
}
}
// crbug.com/1060966
IN_PROC_BROWSER_TEST_P(
LoadingPredictorBrowserTestWithOptimizationGuide,
DISABLED_NavigationWithNoLocalPredictionsButHasOptimizationHint) {
DISABLE_ON_WIN_MAC_CHROMEOS(
NavigationWithNoLocalPredictionsButHasOptimizationHint)) {
{
base::HistogramTester histogram_tester;
......@@ -1798,30 +1777,13 @@ IN_PROC_BROWSER_TEST_P(
"LoadingPredictor.PreconnectLearningPrecision.OptimizationGuide", 0, 1);
histogram_tester.ExpectUniqueSample(
"LoadingPredictor.PreconnectLearningCount.OptimizationGuide", 2, 1);
// We expect one for the final navigation and one for the navigation we care
// about.
histogram_tester.ExpectTotalCount(
"LoadingPredictor.OptimizationHintsReceiveStatus", 2);
// We expect the hints to arrive before navigation for the navigation we
// care about.
histogram_tester.ExpectBucketCount(
"LoadingPredictor.OptimizationHintsReceiveStatus",
OptimizationHintsReceiveStatus::kBeforeNavigationFinish, 1);
// We expect the decision to arrive at finish for the navigation we do not
// have hints for.
histogram_tester.ExpectBucketCount(
"LoadingPredictor.OptimizationHintsReceiveStatus",
OptimizationHintsReceiveStatus::kAfterNavigationFinish, 1);
}
}
// TODO(crbug.com/1060966): Tests are flakey.
IN_PROC_BROWSER_TEST_P(
LoadingPredictorBrowserTestWithOptimizationGuide,
DISABLED_OptimizationGuidePredictionsNotAppliedForAlreadyCommittedNavigation) {
base::HistogramTester histogram_tester;
DISABLE_ON_WIN_MAC_CHROMEOS(
OptimizationGuidePredictionsNotAppliedForAlreadyCommittedNavigation)) {
GURL url = embedded_test_server()->GetURL("hints.com", "/simple.html");
url::Origin origin = url::Origin::Create(url);
net::NetworkIsolationKey network_isolation_key(origin, origin);
......@@ -1833,17 +1795,11 @@ IN_PROC_BROWSER_TEST_P(
"subresource.com", network_isolation_key));
EXPECT_FALSE(preconnect_manager_observer()->HasHostBeenLookedUp(
"otheresource.com", network_isolation_key));
histogram_tester.ExpectUniqueSample(
"LoadingPredictor.OptimizationHintsReceiveStatus",
OptimizationHintsReceiveStatus::kAfterNavigationFinish, 1);
}
IN_PROC_BROWSER_TEST_P(LoadingPredictorBrowserTestWithOptimizationGuide,
DISABLE_ON_WIN_MAC_CHROMEOS(
OptimizationGuidePredictionsNotAppliedForRedirect)) {
base::HistogramTester histogram_tester;
GURL destination_url =
embedded_test_server()->GetURL("otherhost.com", "/cachetime");
GURL redirecting_url = embedded_test_server()->GetURL(
......@@ -1859,11 +1815,6 @@ IN_PROC_BROWSER_TEST_P(LoadingPredictorBrowserTestWithOptimizationGuide,
"subresource.com", network_isolation_key));
EXPECT_FALSE(preconnect_manager_observer()->HasHostBeenLookedUp(
"otheresource.com", network_isolation_key));
// We cannot force when the hint comes back, so we make sure that we at least
// received something back from the optimization guide instead.
histogram_tester.ExpectTotalCount(
"LoadingPredictor.OptimizationHintsReceiveStatus", 1);
}
class LoadingPredictorBrowserTestWithNoLocalPredictions
......
......@@ -308,8 +308,12 @@ void LoadingPredictorTabHelper::OnOptimizationGuideDecision(
if (decision != optimization_guide::OptimizationGuideDecision::kTrue)
return;
if (!metadata.loading_predictor_metadata())
if (!metadata.loading_predictor_metadata()) {
// Metadata is not applicable, so just log an unknown decision.
last_optimization_guide_prediction_->decision =
optimization_guide::OptimizationGuideDecision::kUnknown;
return;
}
PreconnectPrediction prediction;
url::Origin main_frame_origin =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment