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

Unified Diff: chrome/browser/ui/passwords/password_manager_presenter_unittest.cc

Issue 489103004: Allow editing passwords in settings/passwords (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added one more test. Modified the comments and the string. Created 6 years, 4 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: 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..1a68a9ece72a513afb86c3c6edd8296fbf089b8d 100644
--- a/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc
+++ b/chrome/browser/ui/passwords/password_manager_presenter_unittest.cc
@@ -2,6 +2,8 @@
// 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/memory/ref_counted.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"
@@ -13,7 +15,9 @@
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
+using testing::AllOf;
using testing::Eq;
+using testing::Field;
using testing::Property;
class MockPasswordUIView : public PasswordUIView {
@@ -57,6 +61,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 +71,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);
};
@@ -82,20 +96,18 @@ void PasswordManagerPresenterTest::AddPasswordEntry(
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);
+ 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 +157,99 @@ TEST_F(PasswordManagerPresenterTest, UIControllerIsCalled) {
UpdateLists();
}
+TEST_F(PasswordManagerPresenterTest, CallAddPassword) {
+ GURL basic_origin("http://host.com");
+ base::string16 username = base::ASCIIToUTF16("username");
+ base::string16 password = base::ASCIIToUTF16("password");
+ EXPECT_CALL(
+ *GetPasswordStore(),
+ AddLogin(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/path?query=v#ref");
+ EXPECT_CALL(
+ *GetPasswordStore(),
+ AddLogin(AllOf(
+ Field(&autofill::PasswordForm::signon_realm, Eq("https://host.com/")),
+ Field(&autofill::PasswordForm::origin,
+ Eq(GURL("https://host.com/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");
+ std::string username1 = "username";
+ AddPasswordEntry(origin1, username1, "password");
+ GURL origin2("https://example.com");
+ std::string username2 = "testname";
+ AddPasswordEntry(origin2, username2, "abcd");
+
+ base::string16 new_password = base::ASCIIToUTF16("testpassword");
+ EXPECT_CALL(
+ *GetPasswordStore(),
+ UpdateLogin(AllOf(
+ Field(&autofill::PasswordForm::origin, Eq(origin1)),
+ Field(&autofill::PasswordForm::username_value,
+ Eq(base::ASCIIToUTF16(username1))),
+ Field(&autofill::PasswordForm::password_value,
+ Eq(new_password)))));
+ GetPasswordManagerPresenter()->UpdatePassword(0, new_password);
+
+ base::string16 new_password_again = base::ASCIIToUTF16("testpassword_again");
+ EXPECT_CALL(
+ *GetPasswordStore(),
+ UpdateLogin(AllOf(
+ Field(&autofill::PasswordForm::origin, Eq(origin1)),
+ Field(&autofill::PasswordForm::username_value,
+ Eq(base::ASCIIToUTF16(username1))),
+ Field(&autofill::PasswordForm::password_value,
+ Eq(new_password_again)))));
+ GetPasswordManagerPresenter()->UpdatePassword(0, new_password_again);
+
+ base::string16 another_password = base::ASCIIToUTF16("mypassword");
+ EXPECT_CALL(
+ *GetPasswordStore(),
+ UpdateLogin(AllOf(
+ Field(&autofill::PasswordForm::origin, Eq(origin2)),
+ Field(&autofill::PasswordForm::username_value,
+ Eq(base::ASCIIToUTF16(username2))),
+ Field(&autofill::PasswordForm::password_value,
+ Eq(another_password)))));
+ GetPasswordManagerPresenter()->UpdatePassword(1, another_password);
+}
+
+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"
+ };
+ for (size_t i = 0; i < arraysize(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) {
+ EXPECT_FALSE(PasswordManagerPresenter::CheckOriginValidityForAdding(
+ GURL(kInvalidOrigins[i])));
+ }
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698