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

Side by Side Diff: chrome/renderer/autofill/password_generation_manager_browsertest.cc

Issue 10222017: Make password generation switched by a preference in chrome settings rather than a command line fla… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/autofill_messages.h" 8 #include "chrome/common/autofill_messages.h"
9 #include "chrome/renderer/autofill/password_generation_manager.h" 9 #include "chrome/renderer/autofill/password_generation_manager.h"
10 #include "chrome/test/base/chrome_render_view_test.h" 10 #include "chrome/test/base/chrome_render_view_test.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 ASSERT_FALSE(element.isNull()); 105 ASSERT_FALSE(element.isNull());
106 WebInputElement first_password_element = element.to<WebInputElement>(); 106 WebInputElement first_password_element = element.to<WebInputElement>();
107 EXPECT_EQ(0u, generation_manager_->messages().size()); 107 EXPECT_EQ(0u, generation_manager_->messages().size());
108 element = document.getElementById(WebString::fromUTF8("second_password")); 108 element = document.getElementById(WebString::fromUTF8("second_password"));
109 ASSERT_FALSE(element.isNull()); 109 ASSERT_FALSE(element.isNull());
110 WebInputElement second_password_element = element.to<WebInputElement>(); 110 WebInputElement second_password_element = element.to<WebInputElement>();
111 EXPECT_EQ(0u, generation_manager_->messages().size()); 111 EXPECT_EQ(0u, generation_manager_->messages().size());
112 SetFocused(first_password_element.to<WebNode>()); 112 SetFocused(first_password_element.to<WebNode>());
113 EXPECT_EQ(0u, generation_manager_->messages().size()); 113 EXPECT_EQ(0u, generation_manager_->messages().size());
114 114
115 // Pretend like sync was enabled. 115 // Pretend like sync and password generation was enabled.
116 AutofillMsg_PasswordGenerationEnabled msg(0, true); 116 AutofillMsg_PasswordSyncEnabled msg1(0, true);
117 generation_manager_->OnMessageReceived(msg); 117 AutofillMsg_PasswordGenerationEnabled msg2(0, true);
118 generation_manager_->OnMessageReceived(msg1);
119 generation_manager_->OnMessageReceived(msg2);
118 120
119 // Now we will send a message once the first password feld is focused. 121 // Now we will send a message once the first password feld is focused.
120 LoadHTML(kAccountCreationFormHTML); 122 LoadHTML(kAccountCreationFormHTML);
121 document = GetMainFrame()->document(); 123 document = GetMainFrame()->document();
122 element = document.getElementById(WebString::fromUTF8("first_password")); 124 element = document.getElementById(WebString::fromUTF8("first_password"));
123 ASSERT_FALSE(element.isNull()); 125 ASSERT_FALSE(element.isNull());
124 first_password_element = element.to<WebInputElement>(); 126 first_password_element = element.to<WebInputElement>();
125 EXPECT_EQ(0u, generation_manager_->messages().size()); 127 EXPECT_EQ(0u, generation_manager_->messages().size());
126 element = document.getElementById(WebString::fromUTF8("second_password")); 128 element = document.getElementById(WebString::fromUTF8("second_password"));
127 ASSERT_FALSE(element.isNull()); 129 ASSERT_FALSE(element.isNull());
128 second_password_element = element.to<WebInputElement>(); 130 second_password_element = element.to<WebInputElement>();
129 EXPECT_EQ(0u, generation_manager_->messages().size()); 131 EXPECT_EQ(0u, generation_manager_->messages().size());
130 SetFocused(first_password_element.to<WebNode>()); 132 SetFocused(first_password_element.to<WebNode>());
131 EXPECT_EQ(1u, generation_manager_->messages().size()); 133 EXPECT_EQ(1u, generation_manager_->messages().size());
132 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 134 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
133 generation_manager_->messages()[0]->type()); 135 generation_manager_->messages()[0]->type());
134 } 136 }
135 137
136 TEST_F(PasswordGenerationManagerTest, FillTest) { 138 TEST_F(PasswordGenerationManagerTest, FillTest) {
137 // Make sure that we are enabled before loading HTML. 139 // Make sure that we are enabled before loading HTML.
140 AutofillMsg_PasswordSyncEnabled sync_msg(0, true);
141 generation_manager_->OnMessageReceived(sync_msg);
138 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true); 142 AutofillMsg_PasswordGenerationEnabled enabled_msg(0, true);
139 generation_manager_->OnMessageReceived(enabled_msg); 143 generation_manager_->OnMessageReceived(enabled_msg);
140 LoadHTML(kAccountCreationFormHTML); 144 LoadHTML(kAccountCreationFormHTML);
141 145
142 WebDocument document = GetMainFrame()->document(); 146 WebDocument document = GetMainFrame()->document();
143 WebElement element = 147 WebElement element =
144 document.getElementById(WebString::fromUTF8("first_password")); 148 document.getElementById(WebString::fromUTF8("first_password"));
145 ASSERT_FALSE(element.isNull()); 149 ASSERT_FALSE(element.isNull());
146 WebInputElement first_password_element = element.to<WebInputElement>(); 150 WebInputElement first_password_element = element.to<WebInputElement>();
147 element = document.getElementById(WebString::fromUTF8("second_password")); 151 element = document.getElementById(WebString::fromUTF8("second_password"));
148 ASSERT_FALSE(element.isNull()); 152 ASSERT_FALSE(element.isNull());
149 WebInputElement second_password_element = element.to<WebInputElement>(); 153 WebInputElement second_password_element = element.to<WebInputElement>();
150 154
151 // Both password fields should be empty. 155 // Both password fields should be empty.
152 EXPECT_TRUE(first_password_element.value().isNull()); 156 EXPECT_TRUE(first_password_element.value().isNull());
153 EXPECT_TRUE(second_password_element.value().isNull()); 157 EXPECT_TRUE(second_password_element.value().isNull());
154 158
155 string16 password = ASCIIToUTF16("random_password"); 159 string16 password = ASCIIToUTF16("random_password");
156 AutofillMsg_GeneratedPasswordAccepted msg(0, password); 160 AutofillMsg_GeneratedPasswordAccepted msg(0, password);
157 generation_manager_->OnMessageReceived(msg); 161 generation_manager_->OnMessageReceived(msg);
158 162
159 // Password fields are filled out and set as being autofilled. 163 // Password fields are filled out and set as being autofilled.
160 EXPECT_EQ(password, first_password_element.value()); 164 EXPECT_EQ(password, first_password_element.value());
161 EXPECT_EQ(password, second_password_element.value()); 165 EXPECT_EQ(password, second_password_element.value());
162 EXPECT_TRUE(first_password_element.isAutofilled()); 166 EXPECT_TRUE(first_password_element.isAutofilled());
163 EXPECT_TRUE(second_password_element.isAutofilled()); 167 EXPECT_TRUE(second_password_element.isAutofilled());
164 } 168 }
165 169
166 } // namespace autofill 170 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698