Commit 8c5868ca authored by Justin DeWitt's avatar Justin DeWitt Committed by Commit Bot

[EoS] Add URL canonicalization in the catalog validator.

This makes blacklisting work even when the URL is well formed but not
canonical, for example if the trailing slash is missing.

Bug: 902626
Change-Id: Ibced76fd3ad19248d50fc088cc3e54f7ee5ef9af
Reviewed-on: https://chromium-review.googlesource.com/c/1336511Reviewed-by: default avatarPeter Williamson <petewil@chromium.org>
Commit-Queue: Justin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608420}
parent 24615339
......@@ -172,6 +172,11 @@ std::unique_ptr<Catalog> ValidateCatalog(std::unique_ptr<Catalog> catalog) {
// Add the site into the category we are working on.
Site* new_site = new_category->add_sites();
new_site->Swap(&site);
// We want to use a canonicalized URL in the database so that blacklisting
// will always work. Typically this will cause a trailing slash to be
// added if it's missing.
new_site->set_site_url(url.spec());
}
// Collect UMA if the last site was removed from the category, or there were
......
......@@ -492,4 +492,37 @@ TEST_F(ExploreSitesServiceImplTest, UnparseableCatalogHistograms) {
ExploreSitesCatalogError::kParseFailure, 1);
}
TEST_F(ExploreSitesServiceImplTest, BlacklistNonCanonicalUrls) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(chrome::android::kExploreSites);
service()->UpdateCatalogFromNetwork(
false /*is_immediate_fetch*/, kAcceptLanguages,
base::BindOnce(&ExploreSitesServiceImplTest::UpdateCatalogDoneCallback,
base::Unretained(this)));
// Simulate fetching using the test loader factory and test data.
SimulateFetcherData(test_data());
// Wait for callback to get called.
PumpLoop();
ASSERT_TRUE(success());
ASSERT_EQ(1, callback_count());
service()->GetCatalog(base::BindOnce(
&ExploreSitesServiceImplTest::CatalogCallback, base::Unretained(this)));
PumpLoop();
ValidateTestCatalog();
// This will fail if canonicalization does not work correctly because
// kSite1Url is the canonicalized version of the URL inserted in to the
// database.
service()->BlacklistSite(kSite1Url);
PumpLoop();
service()->GetCatalog(base::BindOnce(
&ExploreSitesServiceImplTest::CatalogCallback, base::Unretained(this)));
PumpLoop();
EXPECT_EQ(1U, database_categories()->at(0).sites.size());
}
} // namespace explore_sites
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