1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webauthn/passkey_updated_confirmation_controller.h"
#include <memory>
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate_mock.h"
#include "components/password_manager/core/browser/manage_passwords_referrer.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
using ::testing::Return;
constexpr char kUIDismissalReasonMetric[] = "PasswordManager.UIDismissalReason";
constexpr char kRpId[] = "touhou.example.com";
class PasskeyUpdatedConfirmationControllerTest : public ::testing::Test {
public:
~PasskeyUpdatedConfirmationControllerTest() override = default;
void SetUp() override {
mock_delegate_ =
std::make_unique<testing::NiceMock<PasswordsModelDelegateMock>>();
}
PasswordsModelDelegateMock* delegate() { return mock_delegate_.get(); }
PasskeyUpdatedConfirmationController* controller() {
return controller_.get();
}
void CreateController() {
EXPECT_CALL(*delegate(), OnBubbleShown());
controller_ = std::make_unique<PasskeyUpdatedConfirmationController>(
mock_delegate_->AsWeakPtr(),
password_manager::metrics_util::AUTOMATIC_PASSKEY_UPDATED_CONFIRMATION,
kRpId);
ASSERT_TRUE(testing::Mock::VerifyAndClearExpectations(delegate()));
}
void DestroyController() { controller_.reset(); }
private:
std::unique_ptr<PasswordsModelDelegateMock> mock_delegate_;
std::unique_ptr<PasskeyUpdatedConfirmationController> controller_;
};
TEST_F(PasskeyUpdatedConfirmationControllerTest, DestroyImplicictly) {
CreateController();
EXPECT_CALL(*delegate(), OnBubbleHidden());
}
TEST_F(PasskeyUpdatedConfirmationControllerTest,
OnGooglePasswordManagerButtonClicked) {
base::HistogramTester histogram_tester;
CreateController();
EXPECT_CALL(*delegate(),
NavigateToPasswordDetailsPageInPasswordManager(
kRpId, password_manager::ManagePasswordsReferrer::
kPasskeyUpdatedConfirmationBubble));
controller()->OnGooglePasswordManagerLinkClicked();
DestroyController();
histogram_tester.ExpectUniqueSample(
kUIDismissalReasonMetric, password_manager::metrics_util::CLICKED_MANAGE,
1);
}
} // namespace
|