Commit f40ee7e4 authored by Joe DeBlasio's avatar Joe DeBlasio Committed by Commit Bot

[Simplified domains] Add feature parameter for keyword heuristic.

This CL just adds a feature parameter to tune whether or not to use the keyword
heuristic for eTLD+1 elision. The param defaults to true so that
manually-opted-in users get the full elision behavior.

Fixed: 1122309
Change-Id: I334305d9ada6044dadbdf39d283253aae51d26f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378739Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Commit-Queue: Joe DeBlasio <jdeblasio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802058}
parent fd4febfa
...@@ -18,6 +18,8 @@ namespace { ...@@ -18,6 +18,8 @@ namespace {
const base::FeatureParam<int> kMaximumUnelidedHostnameLength{ const base::FeatureParam<int> kMaximumUnelidedHostnameLength{
&omnibox::kMaybeElideToRegistrableDomain, "max_unelided_host_length", 25}; &omnibox::kMaybeElideToRegistrableDomain, "max_unelided_host_length", 25};
const base::FeatureParam<bool> kEnableKeywordBasedElision{
&omnibox::kMaybeElideToRegistrableDomain, "enable_keyword_elision", true};
} // namespace } // namespace
...@@ -42,7 +44,8 @@ bool ShouldElideToRegistrableDomain(const GURL& url) { ...@@ -42,7 +44,8 @@ bool ShouldElideToRegistrableDomain(const GURL& url) {
// Hostnames using sensitive keywords (typically, brandnames) are often social // Hostnames using sensitive keywords (typically, brandnames) are often social
// engineering, and thus should only show the registrable domain. // engineering, and thus should only show the registrable domain.
auto eTLD_plus_one = GetETLDPlusOne(host); auto eTLD_plus_one = GetETLDPlusOne(host);
if (HostnameContainsKeyword(url, eTLD_plus_one, top500_domains::kTopKeywords, if (kEnableKeywordBasedElision.Get() &&
HostnameContainsKeyword(url, eTLD_plus_one, top500_domains::kTopKeywords,
top500_domains::kNumTopKeywords)) { top500_domains::kNumTopKeywords)) {
return true; return true;
} }
......
...@@ -15,14 +15,20 @@ namespace test { ...@@ -15,14 +15,20 @@ namespace test {
#include "components/url_formatter/spoof_checks/common_words/common_words_test-inc.cc" #include "components/url_formatter/spoof_checks/common_words/common_words_test-inc.cc"
} }
namespace {
// Note: This number is arbitrary; we just need to be able to build
// hostnames that are reliably shorter/longer than the limit.
const char* kMaxUnelidedHostLengthParam = "20";
} // namespace
class UrlElisionPolicyTest : public testing::Test { class UrlElisionPolicyTest : public testing::Test {
public: public:
UrlElisionPolicyTest() { UrlElisionPolicyTest() {
scoped_feature_list_.InitWithFeaturesAndParameters( scoped_feature_list_.InitWithFeaturesAndParameters(
{{omnibox::kMaybeElideToRegistrableDomain, {{omnibox::kMaybeElideToRegistrableDomain,
// Note: This number is arbitrary; we just need to be able to build {{"max_unelided_host_length", kMaxUnelidedHostLengthParam}}}},
// hostnames that are reliably shorter/longer than the limit.
{{"max_unelided_host_length", "20"}}}},
{}); {});
url_formatter::common_words::SetCommonWordDAFSAForTesting( url_formatter::common_words::SetCommonWordDAFSAForTesting(
test::kDafsa, sizeof(test::kDafsa)); test::kDafsa, sizeof(test::kDafsa));
...@@ -98,3 +104,39 @@ TEST_F(UrlElisionPolicyTest, ElidesKeywordedDomainsAppropriately) { ...@@ -98,3 +104,39 @@ TEST_F(UrlElisionPolicyTest, ElidesKeywordedDomainsAppropriately) {
EXPECT_FALSE( EXPECT_FALSE(
ShouldElideToRegistrableDomain(GURL("ftp://google.login.com/xyz"))); ShouldElideToRegistrableDomain(GURL("ftp://google.login.com/xyz")));
} }
class UrlElisionKeywordPolicyTest : public UrlElisionPolicyTest,
public testing::WithParamInterface<bool> {
public:
UrlElisionKeywordPolicyTest() {
if (!GetParam()) {
scoped_feature_list_.InitWithFeaturesAndParameters(
{{omnibox::kMaybeElideToRegistrableDomain,
{{"max_unelided_host_length", kMaxUnelidedHostLengthParam}}}},
{});
} else {
scoped_feature_list_.InitWithFeaturesAndParameters(
{{omnibox::kMaybeElideToRegistrableDomain,
{{"max_unelided_host_length", kMaxUnelidedHostLengthParam},
{"enable_keyword_elision", "false"}}}},
{});
}
}
~UrlElisionKeywordPolicyTest() override = default;
bool IsKeywordElisionEnabled() { return !GetParam(); }
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(UrlElisionKeywordPolicyTest);
};
INSTANTIATE_TEST_SUITE_P(All, UrlElisionKeywordPolicyTest, testing::Bool());
// Verify that keyword elision follows the feature parameter.
TEST_P(UrlElisionKeywordPolicyTest, ElidesOnKeywords) {
EXPECT_EQ(IsKeywordElisionEnabled(),
ShouldElideToRegistrableDomain(GURL("http://google-evil.com/xyz")));
}
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