Skip to content

Commit

Permalink
Ensure SSLInfo is set for navigations that go through StreamingSearch…
Browse files Browse the repository at this point in the history
…PrefetchURLLoader

(cherry picked from commit e123d34)

Bug: b/207355686, 1314783
Change-Id: Ie4b3fb76ed4a065857d02efebd000972f624fd68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3569132
Auto-Submit: Carlos IL <carlosil@chromium.org>
Reviewed-by: Ryan Sturm <ryansturm@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#990650}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3584507
Commit-Queue: Carlos IL <carlosil@chromium.org>
Reviewed-by: Prudhvikumar Bommana <pbommana@google.com>
Commit-Queue: Prudhvikumar Bommana <pbommana@google.com>
Owners-Override: Prudhvikumar Bommana <pbommana@google.com>
Cr-Commit-Position: refs/branch-heads/4951@{#708}
Cr-Branched-From: 27de622-refs/heads/main@{#982481}
  • Loading branch information
carlosjoan91 authored and Chromium LUCI CQ committed Apr 12, 2022
1 parent f1359aa commit 25b39d0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
Expand Up @@ -22,6 +22,7 @@
#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
Expand Down Expand Up @@ -1903,6 +1904,83 @@ IN_PROC_BROWSER_TEST_P(SearchPrefetchServiceEnabledBrowserTest,
SearchPrefetchEligibilityReason::kErrorBackoff, 1);
}

IN_PROC_BROWSER_TEST_P(SearchPrefetchServiceEnabledBrowserTest,
PrefetchSecureSecurityState) {
if (!GetParam()) {
return;
}
set_delayed_response(true);
std::string search_terms = kOmniboxSuggestPrefetchQuery;

// Trigger an omnibox suggest fetch that has a prefetch hint.
AutocompleteInput input(
base::ASCIIToUTF16(search_terms), metrics::OmniboxEventProto::BLANK,
ChromeAutocompleteSchemeClassifier(browser()->profile()));
LocationBar* location_bar = browser()->window()->GetLocationBar();
OmniboxView* omnibox = location_bar->GetOmniboxView();
AutocompleteController* autocomplete_controller =
omnibox->model()->autocomplete_controller();

// Prevent the stop timer from killing the hints fetch early.
autocomplete_controller->SetStartStopTimerDurationForTesting(
base::Seconds(10));
autocomplete_controller->Start(input);

ui_test_utils::WaitForAutocompleteDone(browser());
EXPECT_TRUE(autocomplete_controller->done());
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(GetWebContents());
omnibox->model()->AcceptInput(WindowOpenDisposition::CURRENT_TAB);

content::WaitForLoadStop(GetWebContents());

auto inner_html = GetDocumentInnerHTML();

// Check we are on the prefetched page, and the security level is correct.
EXPECT_FALSE(base::Contains(inner_html, "regular"));
EXPECT_TRUE(base::Contains(inner_html, "prefetch"));
EXPECT_EQ(helper->GetSecurityLevel(), security_state::SECURE);
}

IN_PROC_BROWSER_TEST_P(SearchPrefetchServiceEnabledBrowserTest,
PrefetchFallbackSecureSecurityState) {
if (!GetParam()) {
return;
}

set_delayed_response(true);
std::string search_terms = kOmniboxErrorQuery;

// Trigger an omnibox suggest fetch that has a prefetch hint.
AutocompleteInput input(
base::ASCIIToUTF16(search_terms), metrics::OmniboxEventProto::BLANK,
ChromeAutocompleteSchemeClassifier(browser()->profile()));
LocationBar* location_bar = browser()->window()->GetLocationBar();
OmniboxView* omnibox = location_bar->GetOmniboxView();
AutocompleteController* autocomplete_controller =
omnibox->model()->autocomplete_controller();

// Prevent the stop timer from killing the hints fetch early.
autocomplete_controller->SetStartStopTimerDurationForTesting(
base::Seconds(10));
autocomplete_controller->Start(input);

ui_test_utils::WaitForAutocompleteDone(browser());
EXPECT_TRUE(autocomplete_controller->done());
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(GetWebContents());
omnibox->model()->AcceptInput(WindowOpenDisposition::CURRENT_TAB);

content::WaitForLoadStop(GetWebContents());

auto inner_html = GetDocumentInnerHTML();

// Check we fell back to the regular page, and the security level is correct.
EXPECT_TRUE(base::Contains(inner_html, "regular"));
EXPECT_FALSE(base::Contains(inner_html, "prefetch"));
EXPECT_EQ(helper->GetSecurityLevel(), security_state::SECURE);
}

IN_PROC_BROWSER_TEST_P(SearchPrefetchServiceEnabledBrowserTest,
OmniboxNavigateToNonMatchingEntryStreamingCancels) {
set_hang_requests_after_start(true);
Expand Down
Expand Up @@ -75,10 +75,12 @@ StreamingSearchPrefetchURLLoader::StreamingSearchPrefetchURLLoader(
auto url_loader_factory = profile->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess();

uint32_t options = network::mojom::kURLLoadOptionNone;
options |= network::mojom::kURLLoadOptionSendSSLInfoWithResponse;
// Create a network service URL loader with passed in params.
url_loader_factory->CreateLoaderAndStart(
network_url_loader_.BindNewPipeAndPassReceiver(), 0,
network::mojom::kURLLoadOptionNone, *resource_request,
network_url_loader_.BindNewPipeAndPassReceiver(), 0, options,
*resource_request,
url_loader_receiver_.BindNewPipeAndPassRemote(
base::ThreadTaskRunnerHandle::Get()),
net::MutableNetworkTrafficAnnotationTag(network_traffic_annotation_));
Expand Down Expand Up @@ -511,11 +513,12 @@ void StreamingSearchPrefetchURLLoader::Fallback() {

auto url_loader_factory = profile_->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess();

uint32_t options = network::mojom::kURLLoadOptionNone;
options |= network::mojom::kURLLoadOptionSendSSLInfoWithResponse;
// Create a network service URL loader with passed in params.
url_loader_factory->CreateLoaderAndStart(
network_url_loader_.BindNewPipeAndPassReceiver(), 0,
network::mojom::kURLLoadOptionNone, *resource_request_,
network_url_loader_.BindNewPipeAndPassReceiver(), 0, options,
*resource_request_,
url_loader_receiver_.BindNewPipeAndPassRemote(
base::ThreadTaskRunnerHandle::Get()),
net::MutableNetworkTrafficAnnotationTag(network_traffic_annotation_));
Expand Down

0 comments on commit 25b39d0

Please sign in to comment.