Commit 0f922725 authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[SH] Handle Empty Referrer Case

The Search Engine check DCHECK's on empty URL. Empty Referrers exist,
so it's better to handle that case than DCHECK on it.

Bug: 1131107
Change-Id: Ic238ff86ccc6cee912baea37d8f549b99b685f50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480963Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818048}
parent 34dc74f3
......@@ -13,7 +13,8 @@ namespace shared_highlighting {
namespace {
TextFragmentLinkOpenSource GetLinkSource(const GURL& referrer) {
bool from_search_engine = SearchEngineUtils::GetEngineType(referrer) > 0;
bool from_search_engine =
referrer.is_valid() && SearchEngineUtils::GetEngineType(referrer) > 0;
return from_search_engine ? TextFragmentLinkOpenSource::kSearchEngine
: TextFragmentLinkOpenSource::kUnknown;
}
......
......@@ -26,15 +26,23 @@ TEST(SharedHighlightingMetricsTest, LogTextFragmentAmbiguousMatch) {
TEST(SharedHighlightingMetricsTest, LogTextFragmentLinkOpenSource) {
base::HistogramTester histogram_tester;
GURL search_engine_url = GURL("https://google.com");
GURL non_search_engine_url = GURL("https://example.com");
GURL search_engine_url("https://google.com");
LogTextFragmentLinkOpenSource(search_engine_url);
histogram_tester.ExpectBucketCount("TextFragmentAnchor.LinkOpenSource", 1, 1);
histogram_tester.ExpectBucketCount("TextFragmentAnchor.LinkOpenSource",
TextFragmentLinkOpenSource::kSearchEngine,
1);
GURL non_search_engine_url("https://example.com");
LogTextFragmentLinkOpenSource(non_search_engine_url);
histogram_tester.ExpectBucketCount("TextFragmentAnchor.LinkOpenSource", 0, 1);
histogram_tester.ExpectBucketCount("TextFragmentAnchor.LinkOpenSource",
TextFragmentLinkOpenSource::kUnknown, 1);
histogram_tester.ExpectTotalCount("TextFragmentAnchor.LinkOpenSource", 2);
GURL empty_gurl("");
LogTextFragmentLinkOpenSource(empty_gurl);
histogram_tester.ExpectBucketCount("TextFragmentAnchor.LinkOpenSource",
TextFragmentLinkOpenSource::kUnknown, 2);
histogram_tester.ExpectTotalCount("TextFragmentAnchor.LinkOpenSource", 3);
}
TEST(SharedHighlightingMetricsTest, LogTextFragmentMatchRate) {
......
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