Commit 15c9a651 authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding a preload setting check to SPS

Bug: 1141912
Change-Id: I0f19902b98bffffcf72422f0fe062c7dce33dc19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515020Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826438}
parent 12301e3f
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/location.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefetch/search_prefetch/field_trial_settings.h"
#include "chrome/browser/prefetch/search_prefetch/prefetched_response_container.h"
#include "chrome/browser/profiles/profile.h"
......@@ -148,6 +149,10 @@ bool SearchPrefetchService::MaybePrefetchURL(const GURL& url) {
if (!SearchPrefetchServicePrefetchingIsEnabled())
return false;
if (!chrome_browser_net::CanPreresolveAndPreconnectUI(profile_->GetPrefs())) {
return false;
}
auto* template_url_service =
TemplateURLServiceFactory::GetForProfile(profile_);
if (!template_url_service ||
......
......@@ -8,6 +8,7 @@
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefetch/search_prefetch/field_trial_settings.h"
#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service.h"
#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h"
......@@ -16,6 +17,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
......@@ -524,6 +526,22 @@ IN_PROC_BROWSER_TEST_F(SearchPrefetchServiceEnabledBrowserTest, BadURL) {
EXPECT_FALSE(search_prefetch_service->MaybePrefetchURL(prefetch_url));
}
IN_PROC_BROWSER_TEST_F(SearchPrefetchServiceEnabledBrowserTest,
PreloadDisabled) {
browser()->profile()->GetPrefs()->SetInteger(
prefs::kNetworkPredictionOptions,
chrome_browser_net::NETWORK_PREDICTION_NEVER);
auto* search_prefetch_service =
SearchPrefetchServiceFactory::GetForProfile(browser()->profile());
EXPECT_NE(nullptr, search_prefetch_service);
std::string search_terms = "prefetch_content";
GURL prefetch_url = GetSearchServerQueryURL(search_terms);
EXPECT_FALSE(search_prefetch_service->MaybePrefetchURL(prefetch_url));
}
IN_PROC_BROWSER_TEST_F(SearchPrefetchServiceEnabledBrowserTest,
BasicPrefetchServed) {
auto* search_prefetch_service =
......
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