Index: chrome/browser/password_manager/password_generation_manager_unittest.cc |
diff --git a/chrome/browser/password_manager/password_generation_manager_unittest.cc b/chrome/browser/password_manager/password_generation_manager_unittest.cc |
index 22f20509b4193d10dc2fa2f48c55561ca7f752ba..b344c6a3b74d549f55c64ad363bee01348f0ba9f 100644 |
--- a/chrome/browser/password_manager/password_generation_manager_unittest.cc |
+++ b/chrome/browser/password_manager/password_generation_manager_unittest.cc |
@@ -13,8 +13,12 @@ |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
#include "chrome/test/base/testing_profile.h" |
+#include "components/autofill/core/browser/autofill_field.h" |
+#include "components/autofill/core/browser/form_structure.h" |
+#include "components/autofill/core/common/form_data.h" |
#include "content/public/test/test_browser_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
class TestPasswordGenerationManager : public PasswordGenerationManager { |
public: |
@@ -27,16 +31,32 @@ class TestPasswordGenerationManager : public PasswordGenerationManager { |
sent_states_.push_back(enabled); |
} |
+ virtual void SendAccountCreationFormsToRenderer( |
+ content::RenderViewHost* host, |
+ const std::vector<GURL>& origins) OVERRIDE { |
+ sent_account_creation_forms_.insert( |
+ sent_account_creation_forms_.begin(), origins.begin(), origins.end()); |
+ } |
+ |
const std::vector<bool>& GetSentStates() { |
return sent_states_; |
} |
+ const std::vector<GURL>& GetSentAccountCreationForms() { |
+ return sent_account_creation_forms_; |
+ } |
+ |
void ClearSentStates() { |
sent_states_.clear(); |
} |
+ void ClearSentAccountCreationForms() { |
+ sent_account_creation_forms_.clear(); |
+ } |
+ |
private: |
std::vector<bool> sent_states_; |
+ std::vector<GURL> sent_account_creation_forms_; |
DISALLOW_COPY_AND_ASSIGN(TestPasswordGenerationManager); |
}; |
@@ -59,6 +79,11 @@ class PasswordGenerationManagerTest : public ChromeRenderViewHostTestHarness { |
password_generation_manager_->UpdateState(NULL, new_renderer); |
} |
+ void DetectAccountCreationForms( |
+ const std::vector<autofill::FormStructure*>& forms) { |
+ password_generation_manager_->DetectAccountCreationForms(forms); |
+ } |
+ |
scoped_ptr<TestPasswordGenerationManager> password_generation_manager_; |
}; |
@@ -180,6 +205,39 @@ TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncState) { |
password_generation_manager_->ClearSentStates(); |
} |
+TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) { |
+ autofill::FormData data; |
+ data.origin = GURL("http://www.yahoo.com/login/"); |
+ autofill::FormStructure form1(data, ""); |
+ autofill::AutofillField* field = new autofill::AutofillField(); |
+ field->set_server_type(autofill::EMAIL_ADDRESS); |
+ |
+ form1.fields_.push_back(field); |
Garrett Casto
2013/08/29 22:45:13
You should probably construct a FormData and then
zysxqn
2013/09/03 23:00:20
Done.
|
+ field = new autofill::AutofillField(); |
+ field->set_server_type(autofill::PASSWORD); |
+ form1.fields_.push_back(field); |
+ std::vector<autofill::FormStructure*> forms; |
+ forms.push_back(&form1); |
+ data.origin = GURL("http://accounts.yahoo.com/"); |
+ autofill::FormStructure form2(data, ""); |
+ field = new autofill::AutofillField(); |
+ field->set_server_type(autofill::EMAIL_ADDRESS); |
+ form2.fields_.push_back(field); |
+ field = new autofill::AutofillField(); |
+ field->set_server_type(autofill::ACCOUNT_CREATION_PASSWORD); |
+ form2.fields_.push_back(field); |
+ field = new autofill::AutofillField(); |
+ field->set_server_type(autofill::PASSWORD); |
+ form2.fields_.push_back(field); |
+ forms.push_back(&form2); |
+ |
+ DetectAccountCreationForms(forms); |
+ EXPECT_EQ(1u, |
+ password_generation_manager_->GetSentAccountCreationForms().size()); |
+ EXPECT_EQ(GURL("http://accounts.yahoo.com/"), |
+ password_generation_manager_->GetSentAccountCreationForms()[0]); |
+} |
+ |
TEST_F(IncognitoPasswordGenerationManagerTest, |
UpdatePasswordSyncStateIncognito) { |
// Disable password manager by going incognito, and enable syncing. The |