Skip to content

Commit

Permalink
Skip password_manager_util in credential unittests
Browse files Browse the repository at this point in the history
This patch means skip password_manager_utils
by creating one instance of that cleaner
and using a mock CredentialsCleaner::Observer.

Bug: 889983
Change-Id: I246133064540887c06104c85c97fad1ba7b7aed9
Reviewed-on: https://chromium-review.googlesource.com/c/1257495
Reviewed-by: Vaclav Brozek <vabr@chromium.org>
Commit-Queue: Jaeyong Bae <jdragon.bae@gmail.com>
Cr-Commit-Position: refs/heads/master@{#596521}
  • Loading branch information
jdragonbae authored and Commit Bot committed Oct 4, 2018
1 parent 837b3c2 commit 88f4fec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "components/password_manager/core/browser/blacklisted_duplicates_cleaner.h"

#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_task_environment.h"
Expand All @@ -13,10 +12,21 @@
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace password_manager {

class MockCredentialsCleanerObserver : public CredentialsCleaner::Observer {
public:
MockCredentialsCleanerObserver() = default;
~MockCredentialsCleanerObserver() override = default;
MOCK_METHOD0(CleaningCompleted, void());

private:
DISALLOW_COPY_AND_ASSIGN(MockCredentialsCleanerObserver);
};

class BlacklistedDuplicatesCleanerTest : public ::testing::Test {
public:
BlacklistedDuplicatesCleanerTest() = default;
Expand Down Expand Up @@ -88,8 +98,11 @@ TEST_F(BlacklistedDuplicatesCleanerTest, RemoveBlacklistedDuplicates) {
prefs()->registry()->RegisterBooleanPref(
prefs::kCredentialsWithWrongSignonRealmRemoved, true);

password_manager_util::RemoveUselessCredentials(store(), prefs(), 0,
base::NullCallback());
MockCredentialsCleanerObserver observer;
auto cleaner =
std::make_unique<BlacklistedDuplicatesCleaner>(store(), prefs());
EXPECT_CALL(observer, CleaningCompleted);
cleaner->StartCleaning(&observer);
scoped_task_environment.RunUntilIdle();

// Check that one of the next two forms was removed.
Expand All @@ -101,8 +114,9 @@ TEST_F(BlacklistedDuplicatesCleanerTest, RemoveBlacklistedDuplicates) {
EXPECT_FALSE(
prefs()->GetBoolean(prefs::kDuplicatedBlacklistedCredentialsRemoved));

password_manager_util::RemoveUselessCredentials(store(), prefs(), 0,
base::NullCallback());
cleaner = std::make_unique<BlacklistedDuplicatesCleaner>(store(), prefs());
EXPECT_CALL(observer, CleaningCompleted);
cleaner->StartCleaning(&observer);
scoped_task_environment.RunUntilIdle();
EXPECT_TRUE(
prefs()->GetBoolean(prefs::kDuplicatedBlacklistedCredentialsRemoved));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "components/password_manager/core/browser/invalid_realm_credential_cleaner.h"

#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_task_environment.h"
Expand All @@ -13,6 +12,7 @@
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace password_manager {
Expand Down Expand Up @@ -54,11 +54,6 @@ const GURL kOrigins[] = {GURL("https://example.org/path-0/"),
const base::string16 kUsernames[] = {base::ASCIIToUTF16("user0"),
base::ASCIIToUTF16("user1")};

// TODO(http://crbug.com/889983): This callback is needed to be passed to
// function that does the clean-up, but is not used. Remove it once the function
// is skipped.
auto null_callback = base::NullCallback();

bool StoreContains(TestPasswordStore* store,
const autofill::PasswordForm& form) {
const auto it = store->stored_passwords().find(form.signon_realm);
Expand Down Expand Up @@ -93,6 +88,16 @@ MigrationFormsPair GetCredentialsFrom(bool is_blacklisted,

} // namespace

class MockCredentialsCleanerObserver : public CredentialsCleaner::Observer {
public:
MockCredentialsCleanerObserver() = default;
~MockCredentialsCleanerObserver() override = default;
MOCK_METHOD0(CleaningCompleted, void());

private:
DISALLOW_COPY_AND_ASSIGN(MockCredentialsCleanerObserver);
};

// This test checks that HTML credentials are correctly removed for the case
// when both (HTTP and HTTPS credentials) are blacklisted, or both are not
// blacklsited.
Expand Down Expand Up @@ -218,8 +223,10 @@ TEST(InvalidRealmCredentialCleanerTest,
prefs.registry()->RegisterBooleanPref(
prefs::kCredentialsWithWrongSignonRealmRemoved, false);

password_manager_util::RemoveUselessCredentials(password_store, &prefs, 0,
null_callback);
MockCredentialsCleanerObserver observer;
InvalidRealmCredentialCleaner cleaner(password_store, &prefs);
EXPECT_CALL(observer, CleaningCompleted);
cleaner.StartCleaning(&observer);
scoped_task_environment.RunUntilIdle();

EXPECT_EQ(StoreContains(password_store.get(), https_form),
Expand Down Expand Up @@ -358,8 +365,10 @@ TEST(InvalidRealmCredentialCleanerTest,
prefs.registry()->RegisterBooleanPref(
prefs::kCredentialsWithWrongSignonRealmRemoved, false);

password_manager_util::RemoveUselessCredentials(password_store, &prefs, 0,
null_callback);
MockCredentialsCleanerObserver observer;
InvalidRealmCredentialCleaner cleaner(password_store, &prefs);
EXPECT_CALL(observer, CleaningCompleted);
cleaner.StartCleaning(&observer);
scoped_task_environment.RunUntilIdle();

EXPECT_NE(StoreContains(password_store.get(), https_form),
Expand Down Expand Up @@ -398,8 +407,10 @@ TEST(InvalidRealmCredentialCleanerTest,
prefs.registry()->RegisterBooleanPref(
prefs::kCredentialsWithWrongSignonRealmRemoved, false);

password_manager_util::RemoveUselessCredentials(password_store, &prefs, 0,
null_callback);
MockCredentialsCleanerObserver observer;
InvalidRealmCredentialCleaner cleaner(password_store, &prefs);
EXPECT_CALL(observer, CleaningCompleted);
cleaner.StartCleaning(&observer);
scoped_task_environment.RunUntilIdle();

// Check that credentials were not deleted.
Expand Down

0 comments on commit 88f4fec

Please sign in to comment.