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

Unified Diff: components/autofill/core/browser/password_autofill_manager_unittest.cc

Issue 79103002: Abstracted AcceptPasswordAutofillSuggestion IPC out of core Autofill code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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/autofill/core/browser/password_autofill_manager_unittest.cc
diff --git a/components/autofill/core/browser/password_autofill_manager_unittest.cc b/components/autofill/core/browser/password_autofill_manager_unittest.cc
index 96ce202e614f5f935f097e841c876913abf8568f..f65e10dc6c9ef6755dc078a12148b0bffaf17fae 100644
--- a/components/autofill/core/browser/password_autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/password_autofill_manager_unittest.cc
@@ -3,8 +3,11 @@
// found in the LICENSE file.
#include "base/compiler_specific.h"
+#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/password_autofill_manager.h"
+#include "components/autofill/core/browser/test_autofill_driver.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
// The name of the username/password element in the form.
@@ -17,11 +20,25 @@ const char kAlicePassword[] = "password";
namespace autofill {
+class MockAutofillDriver : public TestAutofillDriver {
+ public:
+ MockAutofillDriver() : TestAutofillDriver(NULL) {}
+ MOCK_METHOD1(RendererShouldAcceptPasswordAutofillSuggestion,
+ void(const base::string16&));
Ilya Sherman 2013/11/22 00:26:29 nit: Please leave a blank line after this one.
jif-google 2013/11/22 12:21:44 Done.
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
+};
Ilya Sherman 2013/11/22 00:26:29 nit: Please tuck this into an anonymous namespace.
jif-google 2013/11/22 12:21:44 Done.
+
class PasswordAutofillManagerTest : public testing::Test {
protected:
- PasswordAutofillManagerTest() : password_autofill_manager_(NULL) {}
+ PasswordAutofillManagerTest() {}
virtual void SetUp() OVERRIDE {
+
Ilya Sherman 2013/11/22 00:26:29 nit: Spurious blank line.
jif-google 2013/11/22 12:21:44 Done.
+ autofill_driver_.reset(new MockAutofillDriver());
+ password_autofill_manager_.reset(
+ new PasswordAutofillManager(autofill_driver_.get()));
+
// Add a preferred login and an additional login to the FillData.
base::string16 username1 = ASCIIToUTF16(kAliceUsername);
base::string16 password1 = ASCIIToUTF16(kAlicePassword);
@@ -35,12 +52,16 @@ class PasswordAutofillManagerTest : public testing::Test {
password_field.value = password1;
fill_data_.basic_data.fields.push_back(password_field);
- password_autofill_manager_.AddPasswordFormMapping(username_field_,
+ password_autofill_manager_.get()->AddPasswordFormMapping(username_field_,
Ilya Sherman 2013/11/22 00:26:29 nit: No need for ".get()" to dereference a smart p
jif-google 2013/11/22 12:21:44 Done.
fill_data_);
}
+ MockAutofillDriver* autofill_driver() {
+ return autofill_driver_.get();
+ }
+
PasswordAutofillManager* password_autofill_manager() {
- return &password_autofill_manager_;
+ return password_autofill_manager_.get();
}
const FormFieldData& username_field() { return username_field_; }
@@ -49,12 +70,21 @@ class PasswordAutofillManagerTest : public testing::Test {
PasswordFormFillData fill_data_;
FormFieldData username_field_;
- PasswordAutofillManager password_autofill_manager_;
+ base::MessageLoop message_loop_;
blundell 2013/11/21 17:08:45 Comment on why this is needed (i.e., because the S
jif-google 2013/11/22 12:21:44 Done.
+ scoped_ptr<MockAutofillDriver> autofill_driver_;
blundell 2013/11/21 17:08:45 Nit: Do these have to be scoped_ptrs rather than o
Ilya Sherman 2013/11/22 00:26:29 +1
jif-google 2013/11/22 12:21:44 No. Fixed.
jif-google 2013/11/22 12:21:44 Done.
+ scoped_ptr<PasswordAutofillManager> password_autofill_manager_;
};
TEST_F(PasswordAutofillManagerTest, DidAcceptAutofillSuggestion) {
+ EXPECT_CALL(*autofill_driver(),
+ RendererShouldAcceptPasswordAutofillSuggestion(
+ ASCIIToUTF16(kAliceUsername)));
EXPECT_TRUE(password_autofill_manager()->DidAcceptAutofillSuggestion(
username_field(), ASCIIToUTF16(kAliceUsername)));
+
+ EXPECT_CALL(*autofill_driver(),
+ RendererShouldAcceptPasswordAutofillSuggestion(
+ ASCIIToUTF16(kInvalidUsername))).Times(0);
EXPECT_FALSE(password_autofill_manager()->DidAcceptAutofillSuggestion(
username_field(), ASCIIToUTF16(kInvalidUsername)));

Powered by Google App Engine
This is Rietveld 408576698