diff options
author | vabr@chromium.org <vabr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-09 12:51:36 +0000 |
---|---|---|
committer | vabr@chromium.org <vabr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-09 12:51:36 +0000 |
commit | 8e3ece94aabefde09746f13032f1da9fd8ec1516 (patch) | |
tree | e3f221c2964a72033f88485a4cea8256de2ceba9 /components | |
parent | e7b86aaedb74d6322504963c35f9a6bb8f58b1f7 (diff) | |
download | chromium_src-8e3ece94aabefde09746f13032f1da9fd8ec1516.zip chromium_src-8e3ece94aabefde09746f13032f1da9fd8ec1516.tar.gz chromium_src-8e3ece94aabefde09746f13032f1da9fd8ec1516.tar.bz2 |
Password manager internals page: Introduce logger in browser
Password manager internals page serves as a debugging output from the process of observing submitted password forms and offering the user to save the password. The user will be able to grab the debugging info and pass it onto the Chrome developers to help investigate issues.
This CL introduces:
1) SavePasswordProgressLogger, a collection of methods to easily format logs and scrub privacy sensitive information out of them.
2) BrowserSavePasswordProgressLogger, a specialization of the Logger for the browser part of the password management code.
More context in the design doc: https://docs.google.com/document/d/1ArDhTo0w-8tOPiTwqM1gG6ZGqODo8UTpXlJjjnCNK4s/edit?usp=sharing
Follow-up CLs will introduce the renderer specialization of the Logger, and actual logging calls.
BUG=347927
TBR=blundell@chromium.org
Review URL: https://codereview.chromium.org/216183008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
12 files changed, 538 insertions, 13 deletions
diff --git a/components/autofill.gypi b/components/autofill.gypi index dd2d78a..c2e54d1 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -74,6 +74,8 @@ 'autofill/core/common/password_form_fill_data.h', 'autofill/core/common/password_generation_util.cc', 'autofill/core/common/password_generation_util.h', + 'autofill/core/common/save_password_progress_logger.cc', + 'autofill/core/common/save_password_progress_logger.h', 'autofill/core/common/web_element_descriptor.cc', 'autofill/core/common/web_element_descriptor.h', ], diff --git a/components/autofill/core/common/save_password_progress_logger.cc b/components/autofill/core/common/save_password_progress_logger.cc new file mode 100644 index 0000000..cdb8dd7 --- /dev/null +++ b/components/autofill/core/common/save_password_progress_logger.cc @@ -0,0 +1,138 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/autofill/core/common/save_password_progress_logger.h" + +#include "base/json/json_writer.h" +#include "base/logging.h" +#include "base/numerics/safe_conversions.h" +#include "base/values.h" +#include "components/autofill/core/common/password_form.h" + +using base::checked_cast; +using base::Value; +using base::DictionaryValue; +using base::FundamentalValue; +using base::StringValue; + +namespace autofill { + +namespace { + +// Removes privacy sensitive parts of |url| (currently all but host and scheme). +std::string ScrubURL(const GURL& url) { + if (url.is_valid()) + return url.GetWithEmptyPath().spec(); + return std::string(); +} + +std::string FormSchemeToString(PasswordForm::Scheme scheme) { + switch (scheme) { + case PasswordForm::SCHEME_HTML: + return "HTML"; + case PasswordForm::SCHEME_BASIC: + return "BASIC"; + case PasswordForm::SCHEME_DIGEST: + return "DIGEST"; + case PasswordForm::SCHEME_OTHER: + return "OTHER"; + } + NOTREACHED(); // Win compilers don't believe this is unreachable. + return std::string(); +} + +StringValue DecisionToStringValue( + SavePasswordProgressLogger::Decision decision) { + switch (decision) { + case SavePasswordProgressLogger::DECISION_SAVE: + return StringValue("SAVE the password"); + case SavePasswordProgressLogger::DECISION_ASK: + return StringValue("ASK the user whether to save the password"); + case SavePasswordProgressLogger::DECISION_DROP: + return StringValue("DROP the password"); + } + NOTREACHED(); // Win compilers don't believe this is unreachable. + return StringValue(std::string()); +} + +} // namespace + +SavePasswordProgressLogger::SavePasswordProgressLogger() {} + +SavePasswordProgressLogger::~SavePasswordProgressLogger() {} + +void SavePasswordProgressLogger::LogPasswordForm(const std::string& message, + const PasswordForm& form) { + DictionaryValue log; + // Do not use the "<<" operator for PasswordForms, because it also prints + // passwords. Also, that operator is only for testing. + log.SetString("scheme", FormSchemeToString(form.scheme)); + log.SetString("signon realm", ScrubURL(GURL(form.signon_realm))); + log.SetString("original signon realm", + ScrubURL(GURL(form.original_signon_realm))); + log.SetString("origin", ScrubURL(form.origin)); + log.SetString("action", ScrubURL(form.action)); + log.SetString("username element", form.username_element); + log.SetString("password element", form.password_element); + log.SetBoolean("password autocomplete set", form.password_autocomplete_set); + log.SetString("old password element", form.old_password_element); + log.SetBoolean("ssl valid", form.ssl_valid); + log.SetBoolean("password generated", + form.type == PasswordForm::TYPE_GENERATED); + log.SetInteger("times used", form.times_used); + log.SetBoolean("use additional authentication", + form.use_additional_authentication); + log.SetBoolean("is PSL match", form.IsPublicSuffixMatch()); + LogValue(message, log); +} + +void SavePasswordProgressLogger::LogHTMLForm(const std::string& message, + const std::string& name_or_id, + const std::string& method, + const GURL& action) { + DictionaryValue log; + log.SetString("name_or_id", name_or_id); + log.SetString("method", method); + log.SetString("action", ScrubURL(action)); + LogValue(message, log); +} + +void SavePasswordProgressLogger::LogURL(const std::string& message, + const GURL& url) { + LogValue(message, StringValue(ScrubURL(url))); +} + +void SavePasswordProgressLogger::LogBoolean(const std::string& message, + bool value) { + LogValue(message, FundamentalValue(value)); +} + +void SavePasswordProgressLogger::LogNumber(const std::string& message, + int value) { + LogValue(message, FundamentalValue(value)); +} + +void SavePasswordProgressLogger::LogNumber(const std::string& message, + size_t value) { + LogValue(message, FundamentalValue(checked_cast<int, size_t>(value))); +} + +void SavePasswordProgressLogger::LogFinalDecision(Decision decision) { + LogValue("Final decision taken", DecisionToStringValue(decision)); +} + +void SavePasswordProgressLogger::LogMessage(const std::string& message) { + LogValue("Message", StringValue(message)); +} + +void SavePasswordProgressLogger::LogValue(const std::string& name, + const Value& log) { + std::string log_string; + bool conversion_to_string_successful = base::JSONWriter::WriteWithOptions( + &log, base::JSONWriter::OPTIONS_PRETTY_PRINT, &log_string); + DCHECK(conversion_to_string_successful); + SendLog(name + ": " + log_string); +} + +} // namespace autofill diff --git a/components/autofill/core/common/save_password_progress_logger.h b/components/autofill/core/common/save_password_progress_logger.h new file mode 100644 index 0000000..63f1075 --- /dev/null +++ b/components/autofill/core/common/save_password_progress_logger.h @@ -0,0 +1,74 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_ +#define COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_ + +#include <string> + +#include "url/gurl.h" + +namespace base { +class Value; +} + +namespace autofill { + +struct PasswordForm; + +// When logging decisions made by password management code about whether to +// offer user-entered credentials for saving or not, do use this class. It +// offers a suite of convenience methods to format and scrub logs. The methods +// have built-in privacy protections (never include a password, scrub URLs), so +// that the result is appropriate for display on the internals page. +// +// To use this class, the method SendLog needs to be overriden to send the logs +// for display as appropriate. +// +// TODO(vabr): Logically, this class belongs to the password_manager component. +// But the PasswordAutofillAgent needs to use it, so until that agent is in a +// third component, shared by autofill and password_manager, this helper needs +// to stay in autofill as well. +class SavePasswordProgressLogger { + public: + // All three possible decisions about saving a password. Call LogFinalDecision + // as soon as one is taken by the password management code. + enum Decision { DECISION_SAVE, DECISION_ASK, DECISION_DROP }; + + SavePasswordProgressLogger(); + virtual ~SavePasswordProgressLogger(); + + // Logging: specialized methods (for logging forms, URLs, etc.) take care of + // proper removing of sensitive data where appropriate. + void LogPasswordForm(const std::string& message, + const autofill::PasswordForm& form); + void LogHTMLForm(const std::string& message, + const std::string& name_or_id, + const std::string& method, + const GURL& action); + void LogURL(const std::string& message, const GURL& url); + void LogWhetherObjectExists(const std::string& message, const void* object); + void LogBoolean(const std::string& message, bool value); + void LogNumber(const std::string& message, int value); + void LogNumber(const std::string& message, size_t value); + void LogFinalDecision(Decision decision); + // Do not use LogMessage when there is an appropriate specialized method + // above. LogMessage performs no scrubbing of sensitive data. + void LogMessage(const std::string& message); + + protected: + // Sends |log| immediately for display. + virtual void SendLog(const std::string& log) = 0; + + private: + // Takes a structured |log|, converts it to a string suitable for plain text + // output, adds the |name| as a caption, and sends out via SendLog. + void LogValue(const std::string& name, const base::Value& log); + + DISALLOW_COPY_AND_ASSIGN(SavePasswordProgressLogger); +}; + +} // namespace autofill + +#endif // COMPONENTS_AUTOFILL_CORE_COMMON_SAVE_PASSWORD_PROGRESS_LOGGER_H_ diff --git a/components/autofill/core/common/save_password_progress_logger_unittest.cc b/components/autofill/core/common/save_password_progress_logger_unittest.cc new file mode 100644 index 0000000..9c09505 --- /dev/null +++ b/components/autofill/core/common/save_password_progress_logger_unittest.cc @@ -0,0 +1,153 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/autofill/core/common/save_password_progress_logger.h" + +#include <limits> + +#include "base/bind.h" +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" +#include "components/autofill/core/common/password_form.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +using base::UTF8ToUTF16; + +namespace autofill { + +namespace { + +const char kTestString[] = "Test"; + +class TestLogger : public SavePasswordProgressLogger { + public: + bool LogsContainSubstring(const std::string& substring) { + return accumulated_log_.find(substring) != std::string::npos; + } + + std::string accumulated_log() { return accumulated_log_; } + + private: + virtual void SendLog(const std::string& log) OVERRIDE { + accumulated_log_.append(log); + } + + std::string accumulated_log_; +}; + +}; // namespace + +TEST(SavePasswordProgressLoggerTest, LogPasswordForm) { + TestLogger logger; + PasswordForm form; + form.action = GURL("http://example.org/verysecret?verysecret"); + form.password_value = UTF8ToUTF16("verysecret"); + form.username_value = UTF8ToUTF16("verysecret"); + logger.LogPasswordForm(kTestString, form); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("http://example.org")); + EXPECT_FALSE(logger.LogsContainSubstring("verysecret")); +} + +TEST(SavePasswordProgressLoggerTest, LogHTMLForm) { + TestLogger logger; + logger.LogHTMLForm(kTestString, + "form_name", + "form_method", + GURL("http://example.org/verysecret?verysecret")); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("form_name")); + EXPECT_TRUE(logger.LogsContainSubstring("form_method")); + EXPECT_TRUE(logger.LogsContainSubstring("http://example.org")); + EXPECT_FALSE(logger.LogsContainSubstring("verysecret")); +} + +TEST(SavePasswordProgressLoggerTest, LogURL) { + TestLogger logger; + logger.LogURL(kTestString, GURL("http://example.org/verysecret?verysecret")); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("http://example.org")); + EXPECT_FALSE(logger.LogsContainSubstring("verysecret")); +} + +TEST(SavePasswordProgressLoggerTest, LogBooleanTrue) { + TestLogger logger; + logger.LogBoolean(kTestString, true); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("true")); +} + +TEST(SavePasswordProgressLoggerTest, LogBooleanFalse) { + TestLogger logger; + logger.LogBoolean(kTestString, false); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("false")); +} + +TEST(SavePasswordProgressLoggerTest, LogSignedNumber) { + TestLogger logger; + int signed_number = -12345; + logger.LogNumber(kTestString, signed_number); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("-12345")); +} + +TEST(SavePasswordProgressLoggerTest, LogUnsignedNumber) { + TestLogger logger; + size_t unsigned_number = 654321; + logger.LogNumber(kTestString, unsigned_number); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); + EXPECT_TRUE(logger.LogsContainSubstring("654321")); +} + +TEST(SavePasswordProgressLoggerTest, LogFinalDecisionSave) { + TestLogger logger; + logger.LogFinalDecision(SavePasswordProgressLogger::DECISION_SAVE); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring("SAVE")); +} + +TEST(SavePasswordProgressLoggerTest, LogFinalDecisionAsk) { + TestLogger logger; + logger.LogFinalDecision(SavePasswordProgressLogger::DECISION_ASK); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring("ASK")); +} + +TEST(SavePasswordProgressLoggerTest, LogFinalDecisionDrop) { + TestLogger logger; + logger.LogFinalDecision(SavePasswordProgressLogger::DECISION_DROP); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring("DROP")); +} + +TEST(SavePasswordProgressLoggerTest, LogMessage) { + TestLogger logger; + logger.LogMessage(kTestString); + SCOPED_TRACE(testing::Message() << "Log string = [" + << logger.accumulated_log() << "]"); + EXPECT_TRUE(logger.LogsContainSubstring(kTestString)); +} + +} // namespace autofill diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 956e14b..0576db7 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -63,6 +63,7 @@ 'autofill/core/common/form_data_unittest.cc', 'autofill/core/common/form_field_data_unittest.cc', 'autofill/core/common/password_form_fill_data_unittest.cc', + 'autofill/core/common/save_password_progress_logger_unittest.cc', 'cloud_devices/printer_description_unittest.cc', 'dom_distiller/core/article_entry_unittest.cc', 'dom_distiller/core/distiller_unittest.cc', @@ -92,6 +93,7 @@ 'os_crypt/ie7_password_win_unittest.cc', 'os_crypt/keychain_password_mac_unittest.mm', 'os_crypt/os_crypt_unittest.cc', + 'password_manager/core/browser/browser_save_password_progress_logger_unittest.cc', 'password_manager/core/browser/login_database_unittest.cc', 'password_manager/core/browser/password_form_manager_unittest.cc', 'password_manager/core/browser/password_generation_manager_unittest.cc', diff --git a/components/password_manager.gypi b/components/password_manager.gypi index cb1c04b..0c26b73 100644 --- a/components/password_manager.gypi +++ b/components/password_manager.gypi @@ -20,6 +20,8 @@ '..', ], 'sources': [ + 'password_manager/core/browser/browser_save_password_progress_logger.cc', + 'password_manager/core/browser/browser_save_password_progress_logger.h', 'password_manager/core/browser/login_database.cc', 'password_manager/core/browser/login_database.h', 'password_manager/core/browser/login_database_mac.cc', @@ -104,6 +106,8 @@ 'password_manager/core/browser/mock_password_store.h', 'password_manager/core/browser/password_form_data.cc', 'password_manager/core/browser/password_form_data.h', + 'password_manager/core/browser/stub_password_manager_client.cc', + 'password_manager/core/browser/stub_password_manager_client.h', 'password_manager/core/browser/test_password_store.cc', 'password_manager/core/browser/test_password_store.h', ], diff --git a/components/password_manager/core/browser/browser_save_password_progress_logger.cc b/components/password_manager/core/browser/browser_save_password_progress_logger.cc new file mode 100644 index 0000000..1994646 --- /dev/null +++ b/components/password_manager/core/browser/browser_save_password_progress_logger.cc @@ -0,0 +1,23 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/password_manager/core/browser/browser_save_password_progress_logger.h" + +#include "components/password_manager/core/browser/password_manager_client.h" + +namespace password_manager { + +BrowserSavePasswordProgressLogger::BrowserSavePasswordProgressLogger( + PasswordManagerClient* client) + : client_(client) { + DCHECK(client_); +} + +BrowserSavePasswordProgressLogger::~BrowserSavePasswordProgressLogger() {} + +void BrowserSavePasswordProgressLogger::SendLog(const std::string& log) { + client_->LogSavePasswordProgress(log); +} + +} // namespace password_manager diff --git a/components/password_manager/core/browser/browser_save_password_progress_logger.h b/components/password_manager/core/browser/browser_save_password_progress_logger.h new file mode 100644 index 0000000..8740635 --- /dev/null +++ b/components/password_manager/core/browser/browser_save_password_progress_logger.h @@ -0,0 +1,38 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_BROWSER_SAVE_PASSWORD_PROGRESS_LOGGER_H_ +#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_BROWSER_SAVE_PASSWORD_PROGRESS_LOGGER_H_ + +#include <string> + +#include "components/autofill/core/common/save_password_progress_logger.h" + +class PasswordManagerClient; + +namespace password_manager { + +// This is the SavePasswordProgressLogger specialization for the browser code, +// where the PasswordManagerClient can be directly called. +class BrowserSavePasswordProgressLogger + : public autofill::SavePasswordProgressLogger { + public: + explicit BrowserSavePasswordProgressLogger(PasswordManagerClient* client); + virtual ~BrowserSavePasswordProgressLogger(); + + protected: + // autofill::SavePasswordProgressLogger: + virtual void SendLog(const std::string& log) OVERRIDE; + + private: + // The PasswordManagerClient to which logs can be sent for display. The client + // must outlive this logger. + PasswordManagerClient* const client_; + + DISALLOW_COPY_AND_ASSIGN(BrowserSavePasswordProgressLogger); +}; + +} // namespace password_manager + +#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_BROWSER_SAVE_PASSWORD_PROGRESS_LOGGER_H_ diff --git a/components/password_manager/core/browser/browser_save_password_progress_logger_unittest.cc b/components/password_manager/core/browser/browser_save_password_progress_logger_unittest.cc new file mode 100644 index 0000000..8693e6a --- /dev/null +++ b/components/password_manager/core/browser/browser_save_password_progress_logger_unittest.cc @@ -0,0 +1,40 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/password_manager/core/browser/browser_save_password_progress_logger.h" + +#include "components/password_manager/core/browser/stub_password_manager_client.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace password_manager { + +namespace { + +const char kTestText[] = "test"; + +// The only purpose of TestLogger is to expose SendLog for the test. +class TestLogger : public BrowserSavePasswordProgressLogger { + public: + TestLogger(PasswordManagerClient* client) + : BrowserSavePasswordProgressLogger(client) {} + + using BrowserSavePasswordProgressLogger::SendLog; +}; + +class MockPasswordManagerClient : public StubPasswordManagerClient { + public: + MOCK_METHOD1(LogSavePasswordProgress, void(const std::string& text)); +}; + +} // namespace + +TEST(BrowserSavePasswordProgressLoggerTest, SendLog) { + MockPasswordManagerClient client; + TestLogger logger(&client); + EXPECT_CALL(client, LogSavePasswordProgress(kTestText)).Times(1); + logger.SendLog(kTestText); +} + +} // namespace password_manager diff --git a/components/password_manager/core/browser/password_manager_unittest.cc b/components/password_manager/core/browser/password_manager_unittest.cc index 44a5f39..a788cd5 100644 --- a/components/password_manager/core/browser/password_manager_unittest.cc +++ b/components/password_manager/core/browser/password_manager_unittest.cc @@ -12,9 +12,9 @@ #include "base/strings/utf_string_conversions.h" #include "components/password_manager/core/browser/mock_password_store.h" #include "components/password_manager/core/browser/password_manager.h" -#include "components/password_manager/core/browser/password_manager_client.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/stub_password_manager_client.h" #include "components/password_manager/core/common/password_manager_pref_names.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,6 +23,8 @@ class PasswordGenerationManager; using autofill::PasswordForm; using base::ASCIIToUTF16; +// TODO(vabr): Remove the next line once http://crbug.com/348523 is fixed. +using password_manager::StubPasswordManagerClient; using testing::_; using testing::AnyNumber; using testing::DoAll; @@ -36,23 +38,12 @@ class AutofillManager; namespace { -class MockPasswordManagerClient : public PasswordManagerClient { +class MockPasswordManagerClient : public StubPasswordManagerClient { public: MOCK_METHOD1(PromptUserToSavePassword, void(PasswordFormManager*)); MOCK_METHOD0(GetPasswordStore, PasswordStore*()); MOCK_METHOD0(GetPrefs, PrefService*()); MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); - MOCK_METHOD1(GetProbabilityForExperiment, - base::FieldTrial::Probability(const std::string&)); - - // The following is required because GMock does not support move-only - // parameters. - MOCK_METHOD1(AuthenticateAutofillAndFillFormPtr, - void(autofill::PasswordFormFillData* fill_data)); - virtual void AuthenticateAutofillAndFillForm( - scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE { - return AuthenticateAutofillAndFillFormPtr(fill_data.release()); - } }; class MockPasswordManagerDriver : public PasswordManagerDriver { diff --git a/components/password_manager/core/browser/stub_password_manager_client.cc b/components/password_manager/core/browser/stub_password_manager_client.cc new file mode 100644 index 0000000..9fd666a --- /dev/null +++ b/components/password_manager/core/browser/stub_password_manager_client.cc @@ -0,0 +1,25 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/password_manager/core/browser/stub_password_manager_client.h" + +namespace password_manager { + +StubPasswordManagerClient::StubPasswordManagerClient() {} + +StubPasswordManagerClient::~StubPasswordManagerClient() {} + +void StubPasswordManagerClient::PromptUserToSavePassword( + PasswordFormManager* form_to_save) {} + +void StubPasswordManagerClient::AuthenticateAutofillAndFillForm( + scoped_ptr<autofill::PasswordFormFillData> fill_data) {} + +PrefService* StubPasswordManagerClient::GetPrefs() { return NULL; } + +PasswordStore* StubPasswordManagerClient::GetPasswordStore() { return NULL; } + +PasswordManagerDriver* StubPasswordManagerClient::GetDriver() { return NULL; } + +} // namespace password_manager diff --git a/components/password_manager/core/browser/stub_password_manager_client.h b/components/password_manager/core/browser/stub_password_manager_client.h new file mode 100644 index 0000000..bf00387 --- /dev/null +++ b/components/password_manager/core/browser/stub_password_manager_client.h @@ -0,0 +1,35 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STUB_PASSWORD_MANAGER_CLIENT_H_ +#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STUB_PASSWORD_MANAGER_CLIENT_H_ + +#include "components/password_manager/core/browser/password_manager_client.h" + +namespace password_manager { + +// Use this class as a base for mock or test clients to avoid stubbing +// uninteresting pure virtual methods. All the implemented methods are just +// trivial stubs. Do NOT use in production, only use in tests. +class StubPasswordManagerClient : public PasswordManagerClient { + public: + StubPasswordManagerClient(); + virtual ~StubPasswordManagerClient(); + + // PasswordManagerClient: + virtual void PromptUserToSavePassword(PasswordFormManager* form_to_save) + OVERRIDE; + virtual void AuthenticateAutofillAndFillForm( + scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE; + virtual PrefService* GetPrefs() OVERRIDE; + virtual PasswordStore* GetPasswordStore() OVERRIDE; + virtual PasswordManagerDriver* GetDriver() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(StubPasswordManagerClient); +}; + +} // namespace password_manager + +#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STUB_PASSWORD_MANAGER_CLIENT_H_ |