[cr146] Parametrize LocalhostAccessBrowserTest with kLocal/kLoopback.
Chromium change: https://chromium.googlesource.com/chromium/src/+/ee3ddffc74cb5 commit ee3ddffc74cb5c45d253cc20bdb2c66f03ac0853 Author: Hubert Chao <hchao@chromium.org> Date: Fri Jan 23 11:47:34 2026 -0800 [LNA] fix url address space to take into account localhost overrides Change-Id: Ic498cbb88f68618af699631fb6579a23c5510ebc Bug: 465915380
This commit is contained in:
@@ -52,7 +52,9 @@ constexpr char kSimplePage[] = "/simple.html";
|
||||
|
||||
} // namespace
|
||||
|
||||
class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
class LocalhostAccessBrowserTest
|
||||
: public InProcessBrowserTest,
|
||||
public testing::WithParamInterface<network::mojom::IPAddressSpace> {
|
||||
public:
|
||||
LocalhostAccessBrowserTest() {
|
||||
feature_list_.InitWithFeaturesAndParameters(
|
||||
@@ -113,10 +115,8 @@ class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
mock_cert_verifier_.SetUpCommandLine(command_line);
|
||||
network::AddIpAddressSpaceOverridesToCommandLine(
|
||||
{network::GenerateIpAddressSpaceOverride(*https_server_),
|
||||
// This will cause LOCAL_NETWORK prompt instead of the LOOPBACK_NETWORK
|
||||
// prompt for localhost.
|
||||
network::GenerateIpAddressSpaceOverride(
|
||||
*localhost_server_, network::mojom::IPAddressSpace::kLocal)},
|
||||
network::GenerateIpAddressSpaceOverride(*localhost_server_,
|
||||
GetParam())},
|
||||
*command_line);
|
||||
}
|
||||
|
||||
@@ -182,16 +182,27 @@ class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
ASSERT_EQ(expected, EvalJs(contents(), insert_image));
|
||||
}
|
||||
|
||||
ContentSettingsType GetContentSettingsType() {
|
||||
return GetParam() == network::mojom::IPAddressSpace::kLocal
|
||||
? ContentSettingsType::LOCAL_NETWORK
|
||||
: ContentSettingsType::LOOPBACK_NETWORK;
|
||||
}
|
||||
|
||||
permissions::RequestType GetRequestType() {
|
||||
return GetParam() == network::mojom::IPAddressSpace::kLocal
|
||||
? permissions::RequestType::kLocalNetwork
|
||||
: permissions::RequestType::kLoopbackNetwork;
|
||||
}
|
||||
|
||||
void CheckCurrentStatusIs(ContentSetting content_setting) {
|
||||
EXPECT_EQ(
|
||||
content_settings()->GetContentSetting(
|
||||
embedding_url_, embedding_url_, ContentSettingsType::LOCAL_NETWORK),
|
||||
content_setting);
|
||||
EXPECT_EQ(content_settings()->GetContentSetting(
|
||||
embedding_url_, embedding_url_, GetContentSettingsType()),
|
||||
content_setting);
|
||||
}
|
||||
|
||||
void SetCurrentStatus(ContentSetting content_setting) {
|
||||
content_settings()->SetContentSettingDefaultScope(
|
||||
embedding_url_, embedding_url_, ContentSettingsType::LOCAL_NETWORK,
|
||||
embedding_url_, embedding_url_, GetContentSettingsType(),
|
||||
content_setting);
|
||||
}
|
||||
|
||||
@@ -210,8 +221,7 @@ class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
InsertImage(localhost_url.spec(), true);
|
||||
// Make sure prompt came up.
|
||||
EXPECT_EQ(1, prompt_factory()->show_count());
|
||||
EXPECT_TRUE(prompt_factory()->RequestTypeSeen(
|
||||
permissions::RequestType::kLocalNetwork));
|
||||
EXPECT_TRUE(prompt_factory()->RequestTypeSeen(GetRequestType()));
|
||||
// Check that the relevant content settings are now ALLOWed.
|
||||
CheckCurrentStatusIs(ContentSetting::CONTENT_SETTING_ALLOW);
|
||||
// Access to localhost resources should be allowed.
|
||||
@@ -236,8 +246,7 @@ class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
InsertImage(localhost_url.spec(), false);
|
||||
// Make sure prompt came up.
|
||||
EXPECT_EQ(1, prompt_factory()->show_count());
|
||||
EXPECT_TRUE(prompt_factory()->RequestTypeSeen(
|
||||
permissions::RequestType::kLocalNetwork));
|
||||
EXPECT_TRUE(prompt_factory()->RequestTypeSeen(GetRequestType()));
|
||||
// Check that the relevant content settings are now DENY.
|
||||
CheckCurrentStatusIs(ContentSetting::CONTENT_SETTING_BLOCK);
|
||||
// Access to localhost resources should be denied.
|
||||
@@ -263,8 +272,7 @@ class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
// Make sure prompts came up (when dismissed there are 2 prompts of the same
|
||||
// type).
|
||||
EXPECT_EQ(2, prompt_factory()->show_count());
|
||||
EXPECT_TRUE(prompt_factory()->RequestTypeSeen(
|
||||
permissions::RequestType::kLocalNetwork));
|
||||
EXPECT_TRUE(prompt_factory()->RequestTypeSeen(GetRequestType()));
|
||||
// Check that the relevant content settings are still ASK.
|
||||
CheckCurrentStatusIs(ContentSetting::CONTENT_SETTING_ASK);
|
||||
// Access to localhost resources should be prompted again.
|
||||
@@ -307,7 +315,7 @@ class LocalhostAccessBrowserTest : public InProcessBrowserTest {
|
||||
std::unique_ptr<permissions::MockPermissionPromptFactory> prompt_factory_;
|
||||
};
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, Localhost) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, Localhost) {
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
const auto& target_url =
|
||||
@@ -321,7 +329,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, Localhost) {
|
||||
CheckAskAndDismissFlow(target_url);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, DotLocalhost) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, DotLocalhost) {
|
||||
std::string test_domain = "test.localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
const auto& target_url =
|
||||
@@ -335,7 +343,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, DotLocalhost) {
|
||||
CheckAskAndDismissFlow(target_url);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, OneTwoSeven) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, OneTwoSeven) {
|
||||
std::string test_domain = "127.0.0.1";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
const auto& target_url =
|
||||
@@ -349,7 +357,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, OneTwoSeven) {
|
||||
CheckAskAndDismissFlow(target_url);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, IncognitoModeInheritAllow) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, IncognitoModeInheritAllow) {
|
||||
// Allowed permission for a website is ASK in incognito.
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
@@ -363,7 +371,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, IncognitoModeInheritAllow) {
|
||||
CheckCurrentStatusIs(ContentSetting::CONTENT_SETTING_ASK);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, IncognitoModeInheritBlock) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, IncognitoModeInheritBlock) {
|
||||
// Blocked permission for a website is ASK in incognito.
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
@@ -377,7 +385,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, IncognitoModeInheritBlock) {
|
||||
CheckCurrentStatusIs(ContentSetting::CONTENT_SETTING_ASK);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, IncognitoModeDoesNotLeak) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, IncognitoModeDoesNotLeak) {
|
||||
// Permission set in Incognito does not leak back to normal mode.
|
||||
Browser* original_browser = browser();
|
||||
Browser* incognito_browser = CreateIncognitoBrowser();
|
||||
@@ -394,7 +402,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, IncognitoModeDoesNotLeak) {
|
||||
CheckCurrentStatusIs(ContentSetting::CONTENT_SETTING_ASK);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, NoPermissionPrompt) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, NoPermissionPrompt) {
|
||||
// No permission prompt is shown when we request non-localhost domain.
|
||||
std::string test_domain = "b.com";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
@@ -403,7 +411,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, NoPermissionPrompt) {
|
||||
}
|
||||
|
||||
// Test that WebSocket connections to localhost are blocked/allowed.
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, WebSocket) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, WebSocket) {
|
||||
// Start a WebSocket server.
|
||||
auto ws_url = net::test_server::GetWebSocketURL(
|
||||
*localhost_server_, "localhost", "/echo-with-no-extension");
|
||||
@@ -439,7 +447,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, WebSocket) {
|
||||
// Test that service worker connections are blocked/allowed correctly.
|
||||
// Service workers making requests to localhost subresources should be allowed
|
||||
// if the page has the ALLOW content setting, and blocked otherwise.
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, ServiceWorker) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, ServiceWorker) {
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ =
|
||||
https_server_->GetURL(kTestEmbeddingDomain, "/navigator/simple.html");
|
||||
@@ -468,7 +476,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, ServiceWorker) {
|
||||
|
||||
// Test that localhost connections blocked by adblock are still blocked
|
||||
// without permission prompt.
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, AdblockRule) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, AdblockRule) {
|
||||
// Add adblock rule to block localhost.
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
@@ -481,7 +489,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, AdblockRule) {
|
||||
}
|
||||
|
||||
// Test that badfiltering a localhost adblock rule makes permission come up.
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, AdblockRuleBadfilter) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, AdblockRuleBadfilter) {
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
const auto& target_url =
|
||||
@@ -495,7 +503,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, AdblockRuleBadfilter) {
|
||||
}
|
||||
|
||||
// Test that different hosts under the same eTLD+1 can prompt.
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, WebsitePartOfETLDP1) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, WebsitePartOfETLDP1) {
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(
|
||||
base::StrCat({"test1.", kTestEmbeddingDomain}), kSimplePage);
|
||||
@@ -509,7 +517,7 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, WebsitePartOfETLDP1) {
|
||||
|
||||
// Test that localhost connections blocked by adblock are still blocked
|
||||
// without permission prompt, and exceptioned domains cause permission prompt.
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, AdblockRuleException) {
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTest, AdblockRuleException) {
|
||||
// Add adblock rule to block localhost.
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
@@ -522,6 +530,12 @@ IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTest, AdblockRuleException) {
|
||||
CheckAskAndAcceptFlow(target_url);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
,
|
||||
LocalhostAccessBrowserTest,
|
||||
testing::Values(network::mojom::IPAddressSpace::kLocal,
|
||||
network::mojom::IPAddressSpace::kLoopback));
|
||||
|
||||
class LocalhostAccessBrowserTestFeatureDisabled
|
||||
: public LocalhostAccessBrowserTest {
|
||||
public:
|
||||
@@ -533,10 +547,16 @@ class LocalhostAccessBrowserTestFeatureDisabled
|
||||
}
|
||||
};
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(LocalhostAccessBrowserTestFeatureDisabled,
|
||||
IN_PROC_BROWSER_TEST_P(LocalhostAccessBrowserTestFeatureDisabled,
|
||||
NoPermissionPrompt) {
|
||||
std::string test_domain = "localhost";
|
||||
embedding_url_ = https_server_->GetURL(kTestEmbeddingDomain, kSimplePage);
|
||||
const auto& target_url = https_server_->GetURL(test_domain, kTestTargetPath);
|
||||
CheckNoPromptFlow(true, target_url);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
,
|
||||
LocalhostAccessBrowserTestFeatureDisabled,
|
||||
testing::Values(network::mojom::IPAddressSpace::kLocal,
|
||||
network::mojom::IPAddressSpace::kLoopback));
|
||||
|
||||
Reference in New Issue
Block a user