Commit c8b4bee5 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Only instantiate Well Known Throttle for Main Frame

This change modifies the WellKnownChangePasswordNavigationThrottle to
only be instantiated for main frame navigations.

Fixed: 1127520
Change-Id: Ia63ecaa4a2411a578956049797cb722012339ddc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410382Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806688}
parent e645bb4c
......@@ -71,7 +71,7 @@ WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(
// password url first. We should only check the feature flag when the feature
// would be used. Otherwise the we would not see a difference between control
// and experiment groups on the dashboards.
if (IsWellKnownChangePasswordUrl(url) &&
if (handle->IsInMainFrame() && IsWellKnownChangePasswordUrl(url) &&
base::FeatureList::IsEnabled(
password_manager::features::kWellKnownChangePassword)) {
return base::WrapUnique(
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h"
......@@ -7,7 +7,10 @@
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/mock_navigation_handle.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......@@ -22,6 +25,14 @@ class WellKnownChangePasswordNavigationThrottleTest
password_manager::features::kWellKnownChangePassword, flag_enabled);
}
void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
content::RenderFrameHostTester::For(main_rfh())
->InitializeRenderFrameIfNeeded();
subframe_ = content::RenderFrameHostTester::For(main_rfh())
->AppendChild("subframe");
}
~WellKnownChangePasswordNavigationThrottleTest() override = default;
std::unique_ptr<WellKnownChangePasswordNavigationThrottle>
......@@ -31,8 +42,16 @@ class WellKnownChangePasswordNavigationThrottleTest
&handle);
}
std::unique_ptr<WellKnownChangePasswordNavigationThrottle>
CreateNavigationThrottleForUrlAndSubframe(const GURL& url) {
content::MockNavigationHandle handle(url, subframe_);
return WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(
&handle);
}
private:
base::test::ScopedFeatureList scoped_features_;
content::RenderFrameHost* subframe_ = nullptr;
};
TEST_P(WellKnownChangePasswordNavigationThrottleTest,
......@@ -48,7 +67,7 @@ TEST_P(WellKnownChangePasswordNavigationThrottleTest,
}
TEST_P(WellKnownChangePasswordNavigationThrottleTest,
NeverCreateNavigationThrottle) {
NeverCreateNavigationThrottle_DifferentUrl) {
GURL url("https://google.com/.well-known/time");
EXPECT_FALSE(CreateNavigationThrottleForUrl(url));
......@@ -62,6 +81,19 @@ TEST_P(WellKnownChangePasswordNavigationThrottleTest,
EXPECT_FALSE(CreateNavigationThrottleForUrl(url));
}
// A WellKnownChangePasswordNavigationThrottle should never be created for a
// navigation initiated by a subframe.
TEST_P(WellKnownChangePasswordNavigationThrottleTest,
NeverCreateNavigationThrottle_Subframe) {
// change-password url without trailing slash
GURL url("https://google.com/.well-known/change-password");
EXPECT_EQ(CreateNavigationThrottleForUrlAndSubframe(url), nullptr);
// change-password url with trailing slash
url = GURL("https://google.com/.well-known/change-password/");
EXPECT_EQ(CreateNavigationThrottleForUrlAndSubframe(url), nullptr);
}
INSTANTIATE_TEST_SUITE_P(All,
WellKnownChangePasswordNavigationThrottleTest,
testing::Bool());
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