Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Unified Diff: components/password_manager/core/browser/password_form_manager_unittest.cc

Issue 1260263002: Move ShouldFilterAutofillResult from ChromePasswordManagerClient to PasswordManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac fix Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/password_form_manager_unittest.cc
diff --git a/components/password_manager/core/browser/password_form_manager_unittest.cc b/components/password_manager/core/browser/password_form_manager_unittest.cc
index 500d81f3b1426d0c70d6212c6d749cfd39830468..fbd86885e7c9a8aea6f567a5f3e839c4606fc653 100644
--- a/components/password_manager/core/browser/password_form_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_form_manager_unittest.cc
@@ -23,6 +23,7 @@
#include "components/password_manager/core/browser/password_manager.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/core/browser/password_store.h"
+#include "components/password_manager/core/browser/store_result_filter.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/stub_password_manager_driver.h"
#include "components/password_manager/core/browser/test_password_store.h"
@@ -100,6 +101,11 @@ class MockPasswordManagerDriver : public StubPasswordManagerDriver {
NiceMock<MockAutofillManager> mock_autofill_manager_;
};
+class MockStoreResultFilter : public StoreResultFilter {
+ public:
+ MOCK_METHOD1(ShouldIgnore, bool(const autofill::PasswordForm& form));
+};
+
class TestPasswordManagerClient : public StubPasswordManagerClient {
public:
explicit TestPasswordManagerClient(PasswordStore* password_store)
@@ -109,19 +115,16 @@ class TestPasswordManagerClient : public StubPasswordManagerClient {
true);
}
- bool ShouldFilterAutofillResult(const autofill::PasswordForm& form) override {
- if (form == form_to_filter_)
- return true;
- return false;
+ scoped_ptr<StoreResultFilter> CreateStoreResultFilter() const override {
+ scoped_ptr<NiceMock<MockStoreResultFilter>> stub_filter(
+ new NiceMock<MockStoreResultFilter>);
+ ON_CALL(*stub_filter, ShouldIgnore(_)).WillByDefault(Return(false));
+ return stub_filter.Pass();
}
PrefService* GetPrefs() override { return &prefs_; }
PasswordStore* GetPasswordStore() const override { return password_store_; }
- void SetFormToFilter(const autofill::PasswordForm& form) {
- form_to_filter_ = form;
- }
-
MockPasswordManagerDriver* mock_driver() { return driver_.get(); }
base::WeakPtr<PasswordManagerDriver> driver() { return driver_->AsWeakPtr(); }
@@ -133,8 +136,6 @@ class TestPasswordManagerClient : public StubPasswordManagerClient {
void KillDriver() { driver_.reset(); }
private:
- autofill::PasswordForm form_to_filter_;
-
TestingPrefServiceSimple prefs_;
PasswordStore* password_store_;
scoped_ptr<MockPasswordManagerDriver> driver_;
@@ -246,8 +247,10 @@ class PasswordFormManagerTest : public testing::Test {
p->SanitizePossibleUsernames(form);
}
- bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) {
- return p->ShouldIgnoreResult(*form);
+ bool IgnoredResult(PasswordFormManager* p,
+ PasswordForm* form,
+ StoreResultFilter* filter) {
+ return p->ShouldIgnoreResult(*form, filter);
}
// Save saved_match() for observed_form() where |observed_form_data|,
@@ -589,17 +592,19 @@ TEST_F(PasswordFormManagerTest, TestIgnoreResult) {
// Make sure we don't match a PasswordForm if it was originally saved on
// an SSL-valid page and we are now on a page with invalid certificate.
saved_match()->ssl_valid = true;
- EXPECT_TRUE(IgnoredResult(&manager, saved_match()));
+ scoped_ptr<MockStoreResultFilter> filter(new MockStoreResultFilter);
+ EXPECT_TRUE(IgnoredResult(&manager, saved_match(), filter.get()));
saved_match()->ssl_valid = false;
// Different paths for action / origin are okay.
saved_match()->action = GURL("http://www.google.com/b/Login");
saved_match()->origin = GURL("http://www.google.com/foo");
- EXPECT_FALSE(IgnoredResult(&manager, saved_match()));
+ EXPECT_FALSE(IgnoredResult(&manager, saved_match(), filter.get()));
// Results should be ignored if the client requests it.
- client()->SetFormToFilter(*saved_match());
- EXPECT_TRUE(IgnoredResult(&manager, saved_match()));
+ PasswordForm filtered_form(*saved_match());
+ EXPECT_CALL(*filter, ShouldIgnore(filtered_form)).WillOnce(Return(true));
+ EXPECT_TRUE(IgnoredResult(&manager, saved_match(), filter.get()));
}
TEST_F(PasswordFormManagerTest, TestEmptyAction) {

Powered by Google App Engine
This is Rietveld 408576698