diff --git a/components/content_settings/core/common/host_indexed_content_settings_unittest.cc b/components/content_settings/core/common/host_indexed_content_settings_unittest.cc index 7ddfd8f5f9952..0fb29d15509c7 100644 --- a/components/content_settings/core/common/host_indexed_content_settings_unittest.cc +++ b/components/content_settings/core/common/host_indexed_content_settings_unittest.cc @@ -297,6 +297,40 @@ TEST_F(HostIndexedContentSettingsTest, CheckIPAddressesMatchIsBlock) { EXPECT_THAT(ToVector(index), testing::ContainerEq(test_settings)); } +// POC: When the primary URL is an IP literal and the rule is indexed by its +// secondary host (because primary pattern is a full wildcard), the +// subdomain-walk is wrongly skipped because FindInHostToContentSettings() +// keys the IP-vs-hostname decision on primary_url instead of the host being +// looked up. The indexed lookup therefore diverges from the linear-scan +// reference semantics (ContentSettingsPattern::Matches). +TEST_F(HostIndexedContentSettingsTest, + POC_IPPrimaryWithSecondaryDomainWildcardSubdomain) { + ContentSettingsForOneType settings = { + CreateSetting("*", "[*.]toplevel.com", CONTENT_SETTING_BLOCK)}; + HostIndexedContentSettings index = FromVector(settings); + + GURL ip_primary("http://192.168.1.2/"); + GURL sub_secondary("http://sub.toplevel.com/"); + GURL exact_secondary("http://toplevel.com/"); + + // Reference semantics: both patterns match. + ContentSettingsPattern primary_pat = ContentSettingsPattern::FromString("*"); + ContentSettingsPattern secondary_pat = + ContentSettingsPattern::FromString("[*.]toplevel.com"); + ASSERT_TRUE(primary_pat.Matches(ip_primary)); + ASSERT_TRUE(secondary_pat.Matches(sub_secondary)); + + // Exact-host secondary is found even with IP primary (direct lookup). + EXPECT_NE(index.Find(ip_primary, exact_secondary), nullptr) + << "control: exact secondary host should be found"; + + // BUG: strict-subdomain secondary is NOT found when primary is an IP, + // because primary_url.HostIsIPAddress() suppresses the subdomain walk + // even though the host being walked is secondary_url.host(). + EXPECT_NE(index.Find(ip_primary, sub_secondary), nullptr) + << "indexed lookup diverges from linear Matches() semantics"; +} + TEST_F(HostIndexedContentSettingsTest, CheckIPAddressesNoMatch) { GURL test_primary_url("http://192.168.1.2/"); GURL test_secondary_url("http://toplevel.com");