chromium/components/safe_browsing/core/browser/password_protection/password_reuse_detection_manager_unittest.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/safe_browsing/core/browser/password_protection/password_reuse_detection_manager.h"

#include <array>
#include <optional>

#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/password_manager/core/browser/mock_password_reuse_manager.h"
#include "components/safe_browsing/core/browser/password_protection/stub_password_reuse_detection_manager_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
#include "url/gurl.h"

_;
AnyNumber;

namespace safe_browsing {

namespace {

constexpr size_t kMaxNumberOfCharactersToStore =;

class MockPasswordReuseDetectionManagerClient
    : public StubPasswordReuseDetectionManagerClient {};

class PasswordReuseDetectionManagerTest : public ::testing::Test {};

// Verify that CheckReuse is called on each key pressed event with an argument
// equal to the last 30 keystrokes typed after the last main frame navigation.
TEST_F(PasswordReuseDetectionManagerTest, CheckReuseCalled) {}

// Verify that the keystroke buffer is cleared after 10 seconds of user
// inactivity.
TEST_F(PasswordReuseDetectionManagerTest,
       CheckThatBufferClearedAfterInactivity) {}

// Verify that the keystroke buffer is cleared after user presses enter.
TEST_F(PasswordReuseDetectionManagerTest, CheckThatBufferClearedAfterEnter) {}

// Verify that after reuse found, no reuse checking happens till next main frame
// navigation.
TEST_F(PasswordReuseDetectionManagerTest, NoReuseCheckingAfterReuseFound) {}

// Verify that keystroke buffer is cleared only on cross host navigation.
TEST_F(PasswordReuseDetectionManagerTest, DidNavigateMainFrame) {}

// Verify that CheckReuse is called on a paste event.
TEST_F(PasswordReuseDetectionManagerTest, CheckReuseCalledOnPaste) {}

TEST_F(PasswordReuseDetectionManagerTest,
       CheckReuseCalledOnPasteTwiceProduceNoDuplicates) {}

#if BUILDFLAG(IS_ANDROID)
TEST_F(PasswordReuseDetectionManagerTest,
       CheckReusedCalledWithUncommittedText) {
  EXPECT_CALL(client_, GetPasswordReuseManager())
      .WillRepeatedly(testing::Return(&reuse_manager_));
  PasswordReuseDetectionManager manager(&client_);
  GURL test_url("https://www.example.com");
  manager.DidNavigateMainFrame(test_url);

  std::u16string init_text = u"init_text";
  std::u16string uncommitted_text = u"uncommitted_text";
  std::u16string committed_text = u"committed_text";

  EXPECT_CALL(reuse_manager_,
              CheckReuse(init_text, test_url.DeprecatedGetOriginAsURL().spec(),
                         &manager));
  manager.OnKeyPressedCommitted(init_text);
  EXPECT_CALL(reuse_manager_,
              CheckReuse(init_text + uncommitted_text,
                         test_url.DeprecatedGetOriginAsURL().spec(), &manager));
  manager.OnKeyPressedUncommitted(uncommitted_text);
  // Uncommitted text should not be stored.
  EXPECT_CALL(reuse_manager_,
              CheckReuse(init_text + committed_text,
                         test_url.DeprecatedGetOriginAsURL().spec(), &manager));
  manager.OnKeyPressedCommitted(committed_text);
}
#endif

}  // namespace

}  // namespace safe_browsing