Commit d3e7c52d authored by Christopher Thompson's avatar Christopher Thompson Committed by Commit Bot

Change typed scoring for HTTP-to-HTTPS redirects

This CL follows on crrev.com/c/1002890, which added a new
|incremented_omnibox_typed_score| column to the visits database.

Modifies the interface to HistoryBackend::AddPageVisit() to take a
boolean |should_increment_typed_count| parameter, and moves the
decision on whether the |typed_count| should be incremented into the
caller HistoryBackend::AddPage().

When there are redirects, AddPage() now checks if the first redirect
is a simple HTTP to HTTPS redirect (that is, only the scheme if the
URL changes, along with the addition or removal of trivial subdomains
such as "www." or "m."), and if it is counts the HTTPS URL typed for
incrementing the omnibox score, rather than the initial HTTP URL. This
will cause the omnibox to learn to suggest the HTTPS URL directly.

A followup CL will rename |typed_count| and related terms to
|omnibox_typed_score| to clarify their meaning.

Bug: 542484
Change-Id: I5edac0fd24f30230000b0fc7258e8c48b6a2e78c
Reviewed-on: https://chromium-review.googlesource.com/1048826Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Commit-Queue: Christopher Thompson <cthomp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565395}
parent 24721cda
......@@ -41,6 +41,8 @@
#include "components/history/core/browser/page_usage_data.h"
#include "components/history/core/browser/url_utils.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h"
#include "components/url_formatter/url_formatter.h"
#include "net/base/escape.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "sql/error_delegate_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
......@@ -119,6 +121,17 @@ bool AreIconTypesEquivalent(favicon_base::IconType type_a,
} // namespace
base::string16 FormatUrlForRedirectComparison(const GURL& url) {
url::Replacements<char> remove_port;
remove_port.ClearPort();
return url_formatter::FormatUrl(
url.ReplaceComponents(remove_port),
url_formatter::kFormatUrlOmitHTTP | url_formatter::kFormatUrlOmitHTTPS |
url_formatter::kFormatUrlOmitUsernamePassword |
url_formatter::kFormatUrlOmitTrivialSubdomains,
net::UnescapeRule::NONE, nullptr, nullptr, nullptr);
}
QueuedHistoryDBTask::QueuedHistoryDBTask(
std::unique_ptr<HistoryDBTask> task,
scoped_refptr<base::SingleThreadTaskRunner> origin_loop,
......@@ -505,8 +518,9 @@ void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
ui::PAGE_TRANSITION_CHAIN_END);
// No redirect case (one element means just the page itself).
last_ids = AddPageVisit(request.url, request.time, last_ids.second, t,
request.hidden, request.visit_source);
last_ids =
AddPageVisit(request.url, request.time, last_ids.second, t,
request.hidden, request.visit_source, IsTypedIncrement(t));
// Update the segment for this visit. KEYWORD_GENERATED visits should not
// result in changing most visited, so we don't update segments (most
......@@ -577,6 +591,21 @@ void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
}
}
bool transfer_typed_credit_from_first_to_second_url = false;
if (redirects.size() > 1) {
// Check if the first redirect is the same as the original URL but
// upgraded to HTTPS. This ignores the port numbers (in case of
// non-standard HTTP or HTTPS ports) and trivial subdomains (e.g., "www."
// or "m.").
if (IsTypedIncrement(request_transition) &&
redirects[0].SchemeIs(url::kHttpScheme) &&
redirects[1].SchemeIs(url::kHttpsScheme) &&
FormatUrlForRedirectComparison(redirects[0]) ==
FormatUrlForRedirectComparison(redirects[1])) {
transfer_typed_credit_from_first_to_second_url = true;
}
}
for (size_t redirect_index = 0; redirect_index < redirects.size();
redirect_index++) {
ui::PageTransition t = ui::PageTransitionFromInt(
......@@ -587,12 +616,20 @@ void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
t = ui::PageTransitionFromInt(t | ui::PAGE_TRANSITION_CHAIN_END);
}
bool should_increment_typed_count = IsTypedIncrement(t);
if (transfer_typed_credit_from_first_to_second_url) {
if (redirect_index == 0)
should_increment_typed_count = false;
else if (redirect_index == 1)
should_increment_typed_count = true;
}
// Record all redirect visits with the same timestamp. We don't display
// them anyway, and if we ever decide to, we can reconstruct their order
// from the redirect chain.
last_ids =
AddPageVisit(redirects[redirect_index], request.time, last_ids.second,
t, request.hidden, request.visit_source);
last_ids = AddPageVisit(
redirects[redirect_index], request.time, last_ids.second, t,
request.hidden, request.visit_source, should_increment_typed_count);
if (t & ui::PAGE_TRANSITION_CHAIN_START) {
if (request.consider_for_ntp_most_visited) {
......@@ -788,9 +825,8 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
VisitID referring_visit,
ui::PageTransition transition,
bool hidden,
VisitSource visit_source) {
const bool typed_increment = IsTypedIncrement(transition);
VisitSource visit_source,
bool should_increment_typed_count) {
if (!host_ranks_.empty() && visit_source == SOURCE_BROWSED &&
(transition & ui::PAGE_TRANSITION_CHAIN_END)) {
RecordTopHostsMetrics(url);
......@@ -803,7 +839,7 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
// Update of an existing row.
if (!ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD))
url_info.set_visit_count(url_info.visit_count() + 1);
if (typed_increment)
if (should_increment_typed_count)
url_info.set_typed_count(url_info.typed_count() + 1);
if (url_info.last_visit() < time)
url_info.set_last_visit(time);
......@@ -816,7 +852,7 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
} else {
// Addition of a new row.
url_info.set_visit_count(1);
url_info.set_typed_count(typed_increment ? 1 : 0);
url_info.set_typed_count(should_increment_typed_count ? 1 : 0);
url_info.set_last_visit(time);
url_info.set_hidden(hidden);
......@@ -830,7 +866,7 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
// Add the visit with the time to the database.
VisitRow visit_info(url_id, time, referring_visit, transition, 0,
typed_increment);
should_increment_typed_count);
VisitID visit_id = db_->AddVisit(&visit_info, visit_source);
if (visit_info.visit_time < first_recorded_time_)
......@@ -1038,7 +1074,7 @@ bool HistoryBackend::AddVisits(const GURL& url,
visit != visits.end(); ++visit) {
if (!AddPageVisit(url, visit->first, 0, visit->second,
!ui::PageTransitionIsMainFrame(visit->second),
visit_source)
visit_source, IsTypedIncrement(visit->second))
.first) {
return false;
}
......
......@@ -61,6 +61,10 @@ class URLDatabase;
// the thumbnail database.
static const size_t kMaxFaviconBitmapsPerIconURL = 8;
// Returns a formatted version of |url| with the HTTP/HTTPS scheme, port,
// username/password, and any trivial subdomains (e.g., "www.", "m.") removed.
base::string16 FormatUrlForRedirectComparison(const GURL& url);
// Keeps track of a queued HistoryDBTask. This class lives solely on the
// DB thread.
class QueuedHistoryDBTask {
......@@ -630,7 +634,8 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
VisitID referring_visit,
ui::PageTransition transition,
bool hidden,
VisitSource visit_source);
VisitSource visit_source,
bool should_increment_typed_count);
// Returns a redirect chain in |redirects| for the VisitID
// |cur_visit|. |cur_visit| is assumed to be valid. Assumes that
......
......@@ -1236,7 +1236,7 @@ TEST_F(HistoryBackendTest, StripUsernamePasswordTest) {
url, base::Time::Now(), 0,
ui::PageTransitionFromInt(
ui::PageTransitionGetQualifier(ui::PAGE_TRANSITION_TYPED)),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, true);
// Fetch the row information about stripped url from history db.
VisitVector visits;
......@@ -1257,7 +1257,7 @@ TEST_F(HistoryBackendTest, AddPageVisitBackForward) {
// Visit the url after typing it.
backend_->AddPageVisit(url, base::Time::Now(), 0, ui::PAGE_TRANSITION_TYPED,
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, true);
// Ensure both the typed count and visit count are 1.
VisitVector visits;
......@@ -1272,7 +1272,7 @@ TEST_F(HistoryBackendTest, AddPageVisitBackForward) {
url, base::Time::Now(), 0,
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
ui::PAGE_TRANSITION_FORWARD_BACK),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
// Ensure the typed count is still 1 but the visit count is 2.
id = backend_->db()->GetRowForURL(url, &row);
......@@ -1292,12 +1292,12 @@ TEST_F(HistoryBackendTest, AddPageVisitRedirectBackForward) {
// Visit a typed URL with a redirect.
backend_->AddPageVisit(url1, base::Time::Now(), 0, ui::PAGE_TRANSITION_TYPED,
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, true);
backend_->AddPageVisit(
url2, base::Time::Now(), 0,
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
ui::PAGE_TRANSITION_CLIENT_REDIRECT),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
// Ensure the redirected URL does not count as typed.
VisitVector visits;
......@@ -1313,7 +1313,7 @@ TEST_F(HistoryBackendTest, AddPageVisitRedirectBackForward) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
ui::PAGE_TRANSITION_FORWARD_BACK |
ui::PAGE_TRANSITION_CLIENT_REDIRECT),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
// Ensure the typed count is still 1 but the visit count is 2.
id = backend_->db()->GetRowForURL(url2, &row);
......@@ -1332,13 +1332,13 @@ TEST_F(HistoryBackendTest, AddPageVisitSource) {
// Assume visiting the url from an externsion.
backend_->AddPageVisit(url, base::Time::Now(), 0, ui::PAGE_TRANSITION_TYPED,
false, history::SOURCE_EXTENSION);
false, history::SOURCE_EXTENSION, true);
// Assume the url is imported from Firefox.
backend_->AddPageVisit(url, base::Time::Now(), 0, ui::PAGE_TRANSITION_TYPED,
false, history::SOURCE_FIREFOX_IMPORTED);
false, history::SOURCE_FIREFOX_IMPORTED, true);
// Assume this url is also synced.
backend_->AddPageVisit(url, base::Time::Now(), 0, ui::PAGE_TRANSITION_TYPED,
false, history::SOURCE_SYNCED);
false, history::SOURCE_SYNCED, true);
// Fetch the row information about the url from history db.
VisitVector visits;
......@@ -1387,7 +1387,7 @@ TEST_F(HistoryBackendTest, AddPageVisitNotLastVisit) {
url, recent_time, 0,
ui::PageTransitionFromInt(
ui::PageTransitionGetQualifier(ui::PAGE_TRANSITION_TYPED)),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
// Add to the url a visit with older time (could be syncing from another
// client, etc.).
......@@ -1395,7 +1395,7 @@ TEST_F(HistoryBackendTest, AddPageVisitNotLastVisit) {
url, older_time, 0,
ui::PageTransitionFromInt(
ui::PageTransitionGetQualifier(ui::PAGE_TRANSITION_TYPED)),
false, history::SOURCE_SYNCED);
false, history::SOURCE_SYNCED, false);
// Fetch the row information about url from history db.
VisitVector visits;
......@@ -1421,11 +1421,11 @@ TEST_F(HistoryBackendTest, AddPageVisitFiresNotificationWithCorrectDetails) {
// Visit two distinct URLs, the second one twice.
backend_->AddPageVisit(url1, base::Time::Now(), 0, ui::PAGE_TRANSITION_LINK,
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
for (int i = 0; i < 2; ++i) {
backend_->AddPageVisit(url2, base::Time::Now(), 0,
ui::PAGE_TRANSITION_TYPED, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, true);
}
URLRow stored_row1, stored_row2;
......@@ -3266,7 +3266,7 @@ TEST_F(HistoryBackendTest, TopHosts) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
EXPECT_THAT(backend_->TopHosts(3),
......@@ -3285,7 +3285,7 @@ TEST_F(HistoryBackendTest, TopHosts_ElidePortAndScheme) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
EXPECT_THAT(backend_->TopHosts(3), ElementsAre(std::make_pair("cnn.com", 3)));
......@@ -3302,7 +3302,7 @@ TEST_F(HistoryBackendTest, TopHosts_ElideWWW) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
EXPECT_THAT(backend_->TopHosts(3),
......@@ -3321,7 +3321,7 @@ TEST_F(HistoryBackendTest, TopHosts_OnlyLast30Days) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
backend_->AddPageVisit(
GURL("http://www.oracle.com/"),
......@@ -3329,7 +3329,7 @@ TEST_F(HistoryBackendTest, TopHosts_OnlyLast30Days) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
EXPECT_THAT(backend_->TopHosts(3),
ElementsAre(std::make_pair("cnn.com", 2),
......@@ -3350,7 +3350,7 @@ TEST_F(HistoryBackendTest, TopHosts_MaxNumHosts) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
EXPECT_THAT(backend_->TopHosts(2),
......@@ -3375,7 +3375,7 @@ TEST_F(HistoryBackendTest, TopHosts_IgnoreUnusualURLs) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
EXPECT_THAT(backend_->TopHosts(5), ElementsAre(std::make_pair("cnn.com", 3)));
......@@ -3405,7 +3405,7 @@ TEST_F(HistoryBackendTest, HostRankIfAvailable) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
EXPECT_EQ(kMaxTopHosts,
......@@ -3433,7 +3433,7 @@ TEST_F(HistoryBackendTest, RecordTopHostsMetrics) {
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_CHAIN_START |
ui::PAGE_TRANSITION_CHAIN_END),
false, history::SOURCE_BROWSED);
false, history::SOURCE_BROWSED, false);
}
// Compute host_ranks_ for RecordTopHostsMetrics.
......@@ -3448,7 +3448,7 @@ TEST_F(HistoryBackendTest, RecordTopHostsMetrics) {
for (const GURL& url : urls) {
backend_->AddPageVisit(url, base::Time::Now(), 0,
ui::PAGE_TRANSITION_CHAIN_END, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
}
EXPECT_THAT(histogram.GetAllSamples("History.TopHostsVisitsByRank"),
......@@ -3463,22 +3463,22 @@ TEST_F(HistoryBackendTest, GetCountsAndLastVisitForOrigins) {
backend_->AddPageVisit(GURL("http://cnn.com/intl"), yesterday, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
backend_->AddPageVisit(GURL("http://cnn.com/us"), last_week, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
backend_->AddPageVisit(GURL("http://cnn.com/ny"), now, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
backend_->AddPageVisit(GURL("https://cnn.com/intl"), yesterday, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
backend_->AddPageVisit(GURL("http://cnn.com:8080/path"), yesterday, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
backend_->AddPageVisit(GURL("http://dogtopia.com/pups?q=poods"), now, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
std::set<GURL> origins;
origins.insert(GURL("http://cnn.com/"));
......@@ -3492,7 +3492,7 @@ TEST_F(HistoryBackendTest, GetCountsAndLastVisitForOrigins) {
origins.insert(GURL("http://notpresent.com/"));
backend_->AddPageVisit(GURL("http://cnn.com/"), tomorrow, 0,
ui::PAGE_TRANSITION_LINK, false,
history::SOURCE_BROWSED);
history::SOURCE_BROWSED, false);
EXPECT_THAT(
backend_->GetCountsAndLastVisitForOrigins(origins),
......@@ -3858,6 +3858,128 @@ TEST_F(HistoryBackendTest, DatabaseError) {
base::RunLoop().RunUntilIdle();
}
// Tests that a typed navigation which results in a redirect from HTTP to HTTPS
// will cause the HTTPS URL to accrue the typed count, and the HTTP URL to not.
TEST_F(HistoryBackendTest, RedirectScoring) {
// Non-typed navigations should not increase the count for either.
const char* redirect1[] = {"http://foo1.com/page1.html",
"https://foo1.com/page1.html", nullptr};
AddRedirectChainWithTransitionAndTime(redirect1, 0, ui::PAGE_TRANSITION_LINK,
base::Time::Now());
URLRow url_row;
ASSERT_TRUE(backend_->GetURL(GURL("http://foo1.com/page1.html"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo1.com/page1.html"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
// Typed navigation with a redirect from HTTP to HTTPS should count for the
// HTTPS URL.
AddRedirectChainWithTransitionAndTime(redirect1, 1, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://foo1.com/page1.html"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo1.com/page1.html"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
// The HTTPS URL should accrue the typed count, even if it adds a trivial
// subdomain.
const char* redirect2[] = {"http://foo2.com", "https://www.foo2.com",
nullptr};
AddRedirectChainWithTransitionAndTime(redirect2, 2, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://foo2.com"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://www.foo2.com"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
// The HTTPS URL should accrue the typed count, even if it removes a trivial
// subdomain.
const char* redirect3[] = {"http://m.foo3.com", "https://foo3.com", nullptr};
AddRedirectChainWithTransitionAndTime(redirect3, 3, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://m.foo3.com"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo3.com"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
// A typed navigation redirecting to a different URL (not simply HTTP to HTTPS
// with trivial subdomain changes) should have the first URL accrue the typed
// count, not the second.
const char* redirect4[] = {"http://foo4.com", "https://foo4.com/page1.html",
nullptr};
AddRedirectChainWithTransitionAndTime(redirect4, 4, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://foo4.com"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo4.com/page1.html"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
const char* redirect5[] = {"http://bar.com", "https://baz.com", nullptr};
AddRedirectChainWithTransitionAndTime(redirect5, 5, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://bar.com"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://baz.com"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
// A typed navigation redirecting from HTTPS to HTTP should have the first URL
// accrue the typed count, not the second.
const char* redirect6[] = {"https://foo6.com", "http://foo6.com", nullptr};
AddRedirectChainWithTransitionAndTime(redirect6, 6, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo6.com"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("http://foo6.com"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
// A long redirect chain where the first redirect is HTTP to HTTPS should
// count for the second URL (not the first or later URLs).
const char* redirect7[] = {"http://foo7.com", "https://foo7.com",
"https://foo7.com/page1.html", nullptr};
AddRedirectChainWithTransitionAndTime(redirect7, 7, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://foo7.com"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo7.com"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo7.com/page1.html"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
// A typed navigation redirecting from HTTP to HTTPS but using non-standard
// port numbers should have the HTTPS URL accrue the typed count.
const char* redirect8[] = {"http://foo8.com:1234", "https://foo8.com:9876",
nullptr};
AddRedirectChainWithTransitionAndTime(redirect8, 8, ui::PAGE_TRANSITION_TYPED,
base::Time::Now());
ASSERT_TRUE(backend_->GetURL(GURL("http://foo8.com:1234"), &url_row));
EXPECT_EQ(0, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(GURL("https://foo8.com:9876"), &url_row));
EXPECT_EQ(1, url_row.typed_count());
}
// Tests that a typed navigation will accrue the typed count even when a client
// redirect from HTTP to HTTPS occurs.
TEST_F(HistoryBackendTest, ClientRedirectScoring) {
const GURL typed_url("http://foo.com");
const GURL redirected_url("https://foo.com");
// Initial typed page visit, with no server redirects.
HistoryAddPageArgs request(typed_url, base::Time::Now(), nullptr, 0, GURL(),
{}, ui::PAGE_TRANSITION_TYPED, false,
history::SOURCE_BROWSED, false, true);
backend_->AddPage(request);
// Client redirect to HTTPS (non-user initiated).
AddClientRedirect(typed_url, redirected_url, /*did_replace=*/true,
base::Time::Now(), /*transition1=*/nullptr,
/*transition2=*/nullptr);
URLRow url_row;
ASSERT_TRUE(backend_->GetURL(typed_url, &url_row));
EXPECT_EQ(1, url_row.typed_count());
ASSERT_TRUE(backend_->GetURL(redirected_url, &url_row));
EXPECT_EQ(0, url_row.typed_count());
}
// Common implementation for the two tests below, given that the only difference
// between them is the type of the notification sent out.
void InMemoryHistoryBackendTest::TestAddingAndChangingURLRows(
......@@ -4094,4 +4216,22 @@ TEST_F(HistoryBackendTest, QueryMostVisitedURLs) {
MostVisitedURL(GURL("http://example5.com"), kSomeTitle)));
}
TEST(FormatUrlForRedirectComparisonTest, TestUrlFormatting) {
// Tests that the formatter removes HTTPS scheme, port, username/password,
// and trivial "www." subdomain. Domain and path are left unchanged.
GURL url1("https://foo:bar@www.baz.com:4443/path1.html");
EXPECT_EQ(base::ASCIIToUTF16("baz.com/path1.html"),
FormatUrlForRedirectComparison(url1));
// Tests that the formatter removes the HTTP scheme.
GURL url2("http://www.baz.com");
EXPECT_EQ(base::ASCIIToUTF16("baz.com/"),
FormatUrlForRedirectComparison(url2));
// Tests that the formatter removes repeated trivial subdomains.
GURL url3("http://m.www.www.baz.com/");
EXPECT_EQ(base::ASCIIToUTF16("baz.com/"),
FormatUrlForRedirectComparison(url3));
}
} // namespace history
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