Index: chrome/browser/ui/passwords/password_manager_presenter_unittest.cc |
diff --git a/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc b/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc |
index 1cee3092e502b9b5c821f1dce7b020c307dee802..2001a9c81c422ad79355557f3dcfe35bd7e4b73e 100644 |
--- a/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc |
+++ b/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/macros.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/password_manager/mock_password_store_service.h" |
#include "chrome/browser/password_manager/password_store_factory.h" |
@@ -14,6 +15,7 @@ |
using base::ASCIIToUTF16; |
using testing::Eq; |
+using testing::Field; |
using testing::Property; |
class MockPasswordUIView : public PasswordUIView { |
@@ -57,6 +59,9 @@ class PasswordManagerPresenterTest : public testing::Test { |
PasswordStoreFactory::GetInstance()->SetTestingFactory( |
&profile_, MockPasswordStoreService::Build); |
mock_controller_.reset(new MockPasswordUIView(&profile_)); |
+ mock_store_ = static_cast<password_manager::MockPasswordStore*>( |
+ PasswordStoreFactory::GetForProfile(&profile_, |
+ Profile::EXPLICIT_ACCESS).get()); |
} |
void AddPasswordEntry(const GURL& origin, |
const std::string& user_name, |
@@ -64,10 +69,17 @@ class PasswordManagerPresenterTest : public testing::Test { |
void AddPasswordException(const GURL& origin); |
void UpdateLists(); |
MockPasswordUIView* GetUIController() { return mock_controller_.get(); } |
+ PasswordManagerPresenter* GetPasswordManagerPresenter() { |
+ return mock_controller_->GetPasswordManagerPresenter(); |
+ } |
+ password_manager::MockPasswordStore* GetPasswordStore() { |
+ return mock_store_.get(); |
+ } |
private: |
TestingProfile profile_; |
scoped_ptr<MockPasswordUIView> mock_controller_; |
+ scoped_refptr<password_manager::MockPasswordStore> mock_store_; |
DISALLOW_COPY_AND_ASSIGN(PasswordManagerPresenterTest); |
}; |
@@ -78,24 +90,22 @@ void PasswordManagerPresenterTest::AddPasswordEntry( |
const std::string& password) { |
autofill::PasswordForm* form = new autofill::PasswordForm(); |
form->origin = origin; |
- form->username_element = base::ASCIIToUTF16("Email"); |
- form->username_value = base::ASCIIToUTF16(user_name); |
- form->password_element = base::ASCIIToUTF16("Passwd"); |
- form->password_value = base::ASCIIToUTF16(password); |
- mock_controller_->GetPasswordManagerPresenter()->password_list_ |
- .push_back(form); |
+ form->username_element = ASCIIToUTF16("Email"); |
+ form->username_value = ASCIIToUTF16(user_name); |
+ form->password_element = ASCIIToUTF16("Passwd"); |
+ form->password_value = ASCIIToUTF16(password); |
+ GetPasswordManagerPresenter()->password_list_.push_back(form); |
} |
void PasswordManagerPresenterTest::AddPasswordException(const GURL& origin) { |
autofill::PasswordForm* form = new autofill::PasswordForm(); |
form->origin = origin; |
- mock_controller_->GetPasswordManagerPresenter()->password_exception_list_ |
- .push_back(form); |
+ GetPasswordManagerPresenter()->password_exception_list_.push_back(form); |
} |
void PasswordManagerPresenterTest::UpdateLists() { |
- mock_controller_->GetPasswordManagerPresenter()->SetPasswordList(); |
- mock_controller_->GetPasswordManagerPresenter()->SetPasswordExceptionList(); |
+ GetPasswordManagerPresenter()->SetPasswordList(); |
+ GetPasswordManagerPresenter()->SetPasswordExceptionList(); |
} |
namespace { |
@@ -145,4 +155,106 @@ TEST_F(PasswordManagerPresenterTest, UIControllerIsCalled) { |
UpdateLists(); |
} |
+// AddPassword and UpdatePassword are never called on Android. |
+#if !defined(OS_ANDROID) |
+TEST_F(PasswordManagerPresenterTest, CallAddPassword) { |
+ GURL basic_origin("http://host.com"); |
+ base::string16 username = ASCIIToUTF16("username"); |
+ base::string16 password = ASCIIToUTF16("password"); |
+ EXPECT_CALL( |
+ *GetPasswordStore(), |
+ AddLogin(testing::AllOf( |
+ Field(&autofill::PasswordForm::signon_realm, Eq(basic_origin.spec())), |
+ Field(&autofill::PasswordForm::origin, Eq(basic_origin)), |
+ Field(&autofill::PasswordForm::username_value, Eq(username)), |
+ Field(&autofill::PasswordForm::password_value, Eq(password)), |
+ Field(&autofill::PasswordForm::ssl_valid, Eq(false))))); |
+ GetPasswordManagerPresenter()->AddPassword(basic_origin, username, password); |
+ |
+ GURL complex_origin("https://foo:bar@host.com:1234/path?query=v#ref"); |
+ EXPECT_CALL( |
+ *GetPasswordStore(), |
+ AddLogin(testing::AllOf( |
+ Field(&autofill::PasswordForm::signon_realm, |
+ Eq("https://host.com:1234/")), |
+ Field(&autofill::PasswordForm::origin, |
+ Eq(GURL("https://host.com:1234/path"))), |
+ Field(&autofill::PasswordForm::username_value, Eq(username)), |
+ Field(&autofill::PasswordForm::password_value, Eq(password)), |
+ Field(&autofill::PasswordForm::ssl_valid, Eq(true))))); |
+ GetPasswordManagerPresenter()->AddPassword(complex_origin, |
+ username, |
+ password); |
+} |
+ |
+TEST_F(PasswordManagerPresenterTest, CallUpdatePassword) { |
+ GURL origin1("http://host.com"); |
+ static const char kUsername1[] = "username"; |
+ AddPasswordEntry(origin1, kUsername1, "password"); |
+ GURL origin2("https://example.com"); |
+ static const char kUsername2[] = "testname"; |
+ AddPasswordEntry(origin2, kUsername2, "abcd"); |
+ |
+ base::string16 new_password = ASCIIToUTF16("testpassword"); |
+ EXPECT_CALL( |
+ *GetPasswordStore(), |
+ UpdateLogin(testing::AllOf( |
+ Field(&autofill::PasswordForm::origin, Eq(origin1)), |
+ Field(&autofill::PasswordForm::username_value, |
+ Eq(ASCIIToUTF16(kUsername1))), |
+ Field(&autofill::PasswordForm::password_value, |
+ Eq(new_password))))); |
+ GetPasswordManagerPresenter()->UpdatePassword(0, new_password); |
+ |
+ base::string16 new_password_again = ASCIIToUTF16("testpassword_again"); |
+ EXPECT_CALL( |
+ *GetPasswordStore(), |
+ UpdateLogin(testing::AllOf( |
+ Field(&autofill::PasswordForm::origin, Eq(origin1)), |
+ Field(&autofill::PasswordForm::username_value, |
+ Eq(ASCIIToUTF16(kUsername1))), |
+ Field(&autofill::PasswordForm::password_value, |
+ Eq(new_password_again))))); |
+ GetPasswordManagerPresenter()->UpdatePassword(0, new_password_again); |
+ |
+ base::string16 another_password = ASCIIToUTF16("mypassword"); |
+ EXPECT_CALL( |
+ *GetPasswordStore(), |
+ UpdateLogin(testing::AllOf( |
+ Field(&autofill::PasswordForm::origin, Eq(origin2)), |
+ Field(&autofill::PasswordForm::username_value, |
+ Eq(ASCIIToUTF16(kUsername2))), |
+ Field(&autofill::PasswordForm::password_value, |
+ Eq(another_password))))); |
+ GetPasswordManagerPresenter()->UpdatePassword(1, another_password); |
+} |
+#endif // !defined(OS_ANDROID) |
+ |
+TEST(PasswordManagerPresenterTestSimple, CallCheckOriginValidityForAdding) { |
+ static const char* const kValidOrigins[] = { |
+ "http://host.com", |
+ "http://host.com/path", |
+ "https://host.com", |
+ "https://foo:bar@host.com/path?query=v#ref", |
+ "https://foo:bar@host.com:1234/path?query=v#ref" |
+ }; |
+ for (size_t i = 0; i < arraysize(kValidOrigins); ++i) { |
+ SCOPED_TRACE(kValidOrigins[i]); |
+ EXPECT_TRUE(PasswordManagerPresenter::CheckOriginValidityForAdding( |
+ GURL(kValidOrigins[i]))); |
+ } |
+ |
+ static const char* const kInvalidOrigins[] = { |
+ "noscheme", |
+ "invalidscheme:host.com", |
+ "ftp://ftp.host.com", |
+ "about:test" |
+ }; |
+ for (size_t i = 0; i < arraysize(kInvalidOrigins); ++i) { |
+ SCOPED_TRACE(kInvalidOrigins[i]); |
+ EXPECT_FALSE(PasswordManagerPresenter::CheckOriginValidityForAdding( |
+ GURL(kInvalidOrigins[i]))); |
+ } |
+} |
+ |
} // namespace |