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

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

Issue 715733002: [Android] Show autofill popup after animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string.h> 5 #include <string.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "chrome/test/base/chrome_render_view_test.h" 10 #include "chrome/test/base/chrome_render_view_test.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (available) { 78 if (available) {
79 ASSERT_EQ(1u, password_generation_->messages().size()); 79 ASSERT_EQ(1u, password_generation_->messages().size());
80 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 80 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
81 password_generation_->messages()[0]->type()); 81 password_generation_->messages()[0]->type());
82 } else { 82 } else {
83 EXPECT_EQ(0u, password_generation_->messages().size()); 83 EXPECT_EQ(0u, password_generation_->messages().size());
84 } 84 }
85 password_generation_->clear_messages(); 85 password_generation_->clear_messages();
86 } 86 }
87 87
88 void LoadHTMLWithUserGesture(const char* html) {
89 LoadHTML(html);
90
91 // Enable show-ime event when element is focused by indicating that a user
92 // gesture has been processed since load.
93 EXPECT_TRUE(SimulateElementClick("dummy"));
94 }
95
88 private: 96 private:
89 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTest); 97 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgentTest);
90 }; 98 };
91 99
92 const char kSigninFormHTML[] = 100 const char kSigninFormHTML[] =
93 "<FORM name = 'blah' action = 'http://www.random.com/'> " 101 "<FORM name = 'blah' action = 'http://www.random.com/'> "
94 " <INPUT type = 'text' id = 'username'/> " 102 " <INPUT type = 'text' id = 'username'/> "
95 " <INPUT type = 'password' id = 'password'/> " 103 " <INPUT type = 'password' id = 'password'/> "
104 " <INPUT type = 'button' id = 'dummy'/> "
96 " <INPUT type = 'submit' value = 'LOGIN' />" 105 " <INPUT type = 'submit' value = 'LOGIN' />"
97 "</FORM>"; 106 "</FORM>";
98 107
99 const char kAccountCreationFormHTML[] = 108 const char kAccountCreationFormHTML[] =
100 "<FORM name = 'blah' action = 'http://www.random.com/'> " 109 "<FORM name = 'blah' action = 'http://www.random.com/'> "
101 " <INPUT type = 'text' id = 'username'/> " 110 " <INPUT type = 'text' id = 'username'/> "
102 " <INPUT type = 'password' id = 'first_password' " 111 " <INPUT type = 'password' id = 'first_password' "
103 " autocomplete = 'off' size = 5/>" 112 " autocomplete = 'off' size = 5/>"
104 " <INPUT type = 'password' id = 'second_password' size = 5/> " 113 " <INPUT type = 'password' id = 'second_password' size = 5/> "
105 " <INPUT type = 'text' id = 'address'/> " 114 " <INPUT type = 'text' id = 'address'/> "
115 " <INPUT type = 'button' id = 'dummy'/> "
106 " <INPUT type = 'submit' value = 'LOGIN' />" 116 " <INPUT type = 'submit' value = 'LOGIN' />"
107 "</FORM>"; 117 "</FORM>";
108 118
119 const char kDisabledElementAccountCreationFormHTML[] =
120 "<FORM name = 'blah' action = 'http://www.random.com/'> "
121 " <INPUT type = 'text' id = 'username'/> "
122 " <INPUT type = 'password' id = 'first_password' "
123 " autocomplete = 'off' size = 5/>"
124 " <INPUT type = 'password' id = 'second_password' size = 5/> "
125 " <INPUT type = 'text' id = 'address'/> "
126 " <INPUT type = 'text' id = 'disabled' disabled/> "
127 " <INPUT type = 'button' id = 'dummy'/> "
128 " <INPUT type = 'submit' value = 'LOGIN' />"
129 "</FORM>";
130
109 const char kHiddenPasswordAccountCreationFormHTML[] = 131 const char kHiddenPasswordAccountCreationFormHTML[] =
110 "<FORM name = 'blah' action = 'http://www.random.com/'> " 132 "<FORM name = 'blah' action = 'http://www.random.com/'> "
111 " <INPUT type = 'text' id = 'username'/> " 133 " <INPUT type = 'text' id = 'username'/> "
112 " <INPUT type = 'password' id = 'first_password'/> " 134 " <INPUT type = 'password' id = 'first_password'/> "
113 " <INPUT type = 'password' id = 'second_password' style='display:none'/> " 135 " <INPUT type = 'password' id = 'second_password' style='display:none'/> "
136 " <INPUT type = 'button' id = 'dummy'/> "
114 " <INPUT type = 'submit' value = 'LOGIN' />" 137 " <INPUT type = 'submit' value = 'LOGIN' />"
115 "</FORM>"; 138 "</FORM>";
116 139
117 const char kInvalidActionAccountCreationFormHTML[] = 140 const char kInvalidActionAccountCreationFormHTML[] =
118 "<FORM name = 'blah' action = 'invalid'> " 141 "<FORM name = 'blah' action = 'invalid'> "
119 " <INPUT type = 'text' id = 'username'/> " 142 " <INPUT type = 'text' id = 'username'/> "
120 " <INPUT type = 'password' id = 'first_password'/> " 143 " <INPUT type = 'password' id = 'first_password'/> "
121 " <INPUT type = 'password' id = 'second_password'/> " 144 " <INPUT type = 'password' id = 'second_password'/> "
145 " <INPUT type = 'button' id = 'dummy'/> "
122 " <INPUT type = 'submit' value = 'LOGIN' />" 146 " <INPUT type = 'submit' value = 'LOGIN' />"
123 "</FORM>"; 147 "</FORM>";
124 148
125 const char kMultipleAccountCreationFormHTML[] = 149 const char kMultipleAccountCreationFormHTML[] =
126 "<FORM name = 'login' action = 'http://www.random.com/'> " 150 "<FORM name = 'login' action = 'http://www.random.com/'> "
127 " <INPUT type = 'text' id = 'random'/> " 151 " <INPUT type = 'text' id = 'random'/> "
128 " <INPUT type = 'text' id = 'username'/> " 152 " <INPUT type = 'text' id = 'username'/> "
129 " <INPUT type = 'password' id = 'password'/> " 153 " <INPUT type = 'password' id = 'password'/> "
154 " <INPUT type = 'button' id = 'dummy'/> "
130 " <INPUT type = 'submit' value = 'LOGIN' />" 155 " <INPUT type = 'submit' value = 'LOGIN' />"
131 "</FORM>" 156 "</FORM>"
132 "<FORM name = 'signup' action = 'http://www.random.com/signup'> " 157 "<FORM name = 'signup' action = 'http://www.random.com/signup'> "
133 " <INPUT type = 'text' id = 'username'/> " 158 " <INPUT type = 'text' id = 'username'/> "
134 " <INPUT type = 'password' id = 'first_password' " 159 " <INPUT type = 'password' id = 'first_password' "
135 " autocomplete = 'off' size = 5/>" 160 " autocomplete = 'off' size = 5/>"
136 " <INPUT type = 'password' id = 'second_password' size = 5/> " 161 " <INPUT type = 'password' id = 'second_password' size = 5/> "
137 " <INPUT type = 'text' id = 'address'/> " 162 " <INPUT type = 'text' id = 'address'/> "
138 " <INPUT type = 'submit' value = 'LOGIN' />" 163 " <INPUT type = 'submit' value = 'LOGIN' />"
139 "</FORM>"; 164 "</FORM>";
140 165
141 const char ChangeDetectionScript[] = 166 const char ChangeDetectionScript[] =
142 "<script>" 167 "<script>"
143 " firstOnChangeCalled = false;" 168 " firstOnChangeCalled = false;"
144 " secondOnChangeCalled = false;" 169 " secondOnChangeCalled = false;"
145 " document.getElementById('first_password').onchange = function() {" 170 " document.getElementById('first_password').onchange = function() {"
146 " firstOnChangeCalled = true;" 171 " firstOnChangeCalled = true;"
147 " };" 172 " };"
148 " document.getElementById('second_password').onchange = function() {" 173 " document.getElementById('second_password').onchange = function() {"
149 " secondOnChangeCalled = true;" 174 " secondOnChangeCalled = true;"
150 " };" 175 " };"
151 "</script>"; 176 "</script>";
152 177
153 TEST_F(PasswordGenerationAgentTest, DetectionTest) { 178 TEST_F(PasswordGenerationAgentTest, DetectionTest) {
154 // Don't shown the icon for non account creation forms. 179 // Don't shown the icon for non account creation forms.
155 LoadHTML(kSigninFormHTML); 180 LoadHTMLWithUserGesture(kSigninFormHTML);
156 ExpectPasswordGenerationAvailable("password", false); 181 ExpectPasswordGenerationAvailable("password", false);
157 182
158 // We don't show the decoration yet because the feature isn't enabled. 183 // We don't show the decoration yet because the feature isn't enabled.
159 LoadHTML(kAccountCreationFormHTML); 184 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
160 ExpectPasswordGenerationAvailable("first_password", false); 185 ExpectPasswordGenerationAvailable("first_password", false);
161 186
162 // Pretend like We have received message indicating site is not blacklisted, 187 // Pretend like We have received message indicating site is not blacklisted,
163 // and we have received message indicating the form is classified as 188 // and we have received message indicating the form is classified as
164 // ACCOUNT_CREATION_FORM form Autofill server. We should show the icon. 189 // ACCOUNT_CREATION_FORM form Autofill server. We should show the icon.
165 LoadHTML(kAccountCreationFormHTML); 190 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
166 SetNotBlacklistedMessage(kAccountCreationFormHTML); 191 SetNotBlacklistedMessage(kAccountCreationFormHTML);
167 SetAccountCreationFormsDetectedMessage(0); 192 SetAccountCreationFormsDetectedMessage(0);
168 ExpectPasswordGenerationAvailable("first_password", true); 193 ExpectPasswordGenerationAvailable("first_password", true);
169 194
170 // Hidden fields are not treated differently. 195 // Hidden fields are not treated differently.
171 LoadHTML(kHiddenPasswordAccountCreationFormHTML); 196 LoadHTMLWithUserGesture(kHiddenPasswordAccountCreationFormHTML);
172 SetNotBlacklistedMessage(kHiddenPasswordAccountCreationFormHTML); 197 SetNotBlacklistedMessage(kHiddenPasswordAccountCreationFormHTML);
173 SetAccountCreationFormsDetectedMessage(0); 198 SetAccountCreationFormsDetectedMessage(0);
174 ExpectPasswordGenerationAvailable("first_password", true); 199 ExpectPasswordGenerationAvailable("first_password", true);
175 200
176 // This doesn't trigger because the form action is invalid. 201 // This doesn't trigger because the form action is invalid.
177 LoadHTML(kInvalidActionAccountCreationFormHTML); 202 LoadHTMLWithUserGesture(kInvalidActionAccountCreationFormHTML);
178 SetNotBlacklistedMessage(kInvalidActionAccountCreationFormHTML); 203 SetNotBlacklistedMessage(kInvalidActionAccountCreationFormHTML);
179 SetAccountCreationFormsDetectedMessage(0); 204 SetAccountCreationFormsDetectedMessage(0);
180 ExpectPasswordGenerationAvailable("first_password", false); 205 ExpectPasswordGenerationAvailable("first_password", false);
181 } 206 }
182 207
183 TEST_F(PasswordGenerationAgentTest, FillTest) { 208 TEST_F(PasswordGenerationAgentTest, FillTest) {
184 // Make sure that we are enabled before loading HTML. 209 // Make sure that we are enabled before loading HTML.
185 std::string html = std::string(kAccountCreationFormHTML) + 210 std::string html = std::string(kAccountCreationFormHTML) +
186 ChangeDetectionScript; 211 ChangeDetectionScript;
187 LoadHTML(html.c_str()); 212 LoadHTMLWithUserGesture(html.c_str());
188 SetNotBlacklistedMessage(html.c_str()); 213 SetNotBlacklistedMessage(html.c_str());
189 SetAccountCreationFormsDetectedMessage(0); 214 SetAccountCreationFormsDetectedMessage(0);
190 215
191 WebDocument document = GetMainFrame()->document(); 216 WebDocument document = GetMainFrame()->document();
192 WebElement element = 217 WebElement element =
193 document.getElementById(WebString::fromUTF8("first_password")); 218 document.getElementById(WebString::fromUTF8("first_password"));
194 ASSERT_FALSE(element.isNull()); 219 ASSERT_FALSE(element.isNull());
195 WebInputElement first_password_element = element.to<WebInputElement>(); 220 WebInputElement first_password_element = element.to<WebInputElement>();
196 element = document.getElementById(WebString::fromUTF8("second_password")); 221 element = document.getElementById(WebString::fromUTF8("second_password"));
197 ASSERT_FALSE(element.isNull()); 222 ASSERT_FALSE(element.isNull());
(...skipping 29 matching lines...) Expand all
227 252
228 // Focus moved to the next input field. 253 // Focus moved to the next input field.
229 // TODO(zysxqn): Change this back to the address element once Bug 90224 254 // TODO(zysxqn): Change this back to the address element once Bug 90224
230 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed. 255 // https://bugs.webkit.org/show_bug.cgi?id=90224 has been fixed.
231 element = document.getElementById(WebString::fromUTF8("first_password")); 256 element = document.getElementById(WebString::fromUTF8("first_password"));
232 ASSERT_FALSE(element.isNull()); 257 ASSERT_FALSE(element.isNull());
233 EXPECT_EQ(element, document.focusedElement()); 258 EXPECT_EQ(element, document.focusedElement());
234 } 259 }
235 260
236 TEST_F(PasswordGenerationAgentTest, EditingTest) { 261 TEST_F(PasswordGenerationAgentTest, EditingTest) {
237 LoadHTML(kAccountCreationFormHTML); 262 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
238 SetNotBlacklistedMessage(kAccountCreationFormHTML); 263 SetNotBlacklistedMessage(kAccountCreationFormHTML);
239 SetAccountCreationFormsDetectedMessage(0); 264 SetAccountCreationFormsDetectedMessage(0);
240 265
241 WebDocument document = GetMainFrame()->document(); 266 WebDocument document = GetMainFrame()->document();
242 WebElement element = 267 WebElement element =
243 document.getElementById(WebString::fromUTF8("first_password")); 268 document.getElementById(WebString::fromUTF8("first_password"));
244 ASSERT_FALSE(element.isNull()); 269 ASSERT_FALSE(element.isNull());
245 WebInputElement first_password_element = element.to<WebInputElement>(); 270 WebInputElement first_password_element = element.to<WebInputElement>();
246 element = document.getElementById(WebString::fromUTF8("second_password")); 271 element = document.getElementById(WebString::fromUTF8("second_password"));
247 ASSERT_FALSE(element.isNull()); 272 ASSERT_FALSE(element.isNull());
(...skipping 29 matching lines...) Expand all
277 // textFieldDidChange posts a task, so we need to wait until it's been 302 // textFieldDidChange posts a task, so we need to wait until it's been
278 // processed. 303 // processed.
279 base::MessageLoop::current()->RunUntilIdle(); 304 base::MessageLoop::current()->RunUntilIdle();
280 EXPECT_EQ(empty_password, first_password_element.value()); 305 EXPECT_EQ(empty_password, first_password_element.value());
281 EXPECT_EQ(empty_password, second_password_element.value()); 306 EXPECT_EQ(empty_password, second_password_element.value());
282 } 307 }
283 308
284 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) { 309 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) {
285 // Did not receive not blacklisted message. Don't show password generation 310 // Did not receive not blacklisted message. Don't show password generation
286 // icon. 311 // icon.
287 LoadHTML(kAccountCreationFormHTML); 312 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
288 SetAccountCreationFormsDetectedMessage(0); 313 SetAccountCreationFormsDetectedMessage(0);
289 ExpectPasswordGenerationAvailable("first_password", false); 314 ExpectPasswordGenerationAvailable("first_password", false);
290 315
291 // Receive one not blacklisted message for non account creation form. Don't 316 // Receive one not blacklisted message for non account creation form. Don't
292 // show password generation icon. 317 // show password generation icon.
293 LoadHTML(kAccountCreationFormHTML); 318 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
294 SetNotBlacklistedMessage(kSigninFormHTML); 319 SetNotBlacklistedMessage(kSigninFormHTML);
295 SetAccountCreationFormsDetectedMessage(0); 320 SetAccountCreationFormsDetectedMessage(0);
296 ExpectPasswordGenerationAvailable("first_password", false); 321 ExpectPasswordGenerationAvailable("first_password", false);
297 322
298 // Receive one not blackliste message for account creation form. Show password 323 // Receive one not blacklisted message for account creation form. Show
299 // generation icon. 324 // password generation icon.
300 LoadHTML(kAccountCreationFormHTML); 325 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
301 SetNotBlacklistedMessage(kAccountCreationFormHTML); 326 SetNotBlacklistedMessage(kAccountCreationFormHTML);
302 SetAccountCreationFormsDetectedMessage(0); 327 SetAccountCreationFormsDetectedMessage(0);
303 ExpectPasswordGenerationAvailable("first_password", true); 328 ExpectPasswordGenerationAvailable("first_password", true);
304 329
305 // Receive two not blacklisted messages, one is for account creation form and 330 // Receive two not blacklisted messages, one is for account creation form and
306 // the other is not. Show password generation icon. 331 // the other is not. Show password generation icon.
307 LoadHTML(kAccountCreationFormHTML); 332 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
308 SetNotBlacklistedMessage(kAccountCreationFormHTML); 333 SetNotBlacklistedMessage(kAccountCreationFormHTML);
309 SetNotBlacklistedMessage(kSigninFormHTML); 334 SetNotBlacklistedMessage(kSigninFormHTML);
310 SetAccountCreationFormsDetectedMessage(0); 335 SetAccountCreationFormsDetectedMessage(0);
311 ExpectPasswordGenerationAvailable("first_password", true); 336 ExpectPasswordGenerationAvailable("first_password", true);
312 } 337 }
313 338
314 TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) { 339 TEST_F(PasswordGenerationAgentTest, AccountCreationFormsDetectedTest) {
315 // Did not receive account creation forms detected messege. Don't show 340 // Did not receive account creation forms detected message. Don't show
316 // password generation icon. 341 // password generation icon.
317 LoadHTML(kAccountCreationFormHTML); 342 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
318 SetNotBlacklistedMessage(kAccountCreationFormHTML); 343 SetNotBlacklistedMessage(kAccountCreationFormHTML);
319 ExpectPasswordGenerationAvailable("first_password", false); 344 ExpectPasswordGenerationAvailable("first_password", false);
320 345
321 // Receive the account creation forms detected message. Show password 346 // Receive the account creation forms detected message. Show password
322 // generation icon. 347 // generation icon.
323 LoadHTML(kAccountCreationFormHTML); 348 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
324 SetNotBlacklistedMessage(kAccountCreationFormHTML); 349 SetNotBlacklistedMessage(kAccountCreationFormHTML);
325 SetAccountCreationFormsDetectedMessage(0); 350 SetAccountCreationFormsDetectedMessage(0);
326 ExpectPasswordGenerationAvailable("first_password", true); 351 ExpectPasswordGenerationAvailable("first_password", true);
327 } 352 }
328 353
329 TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) { 354 TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) {
330 base::HistogramTester histogram_tester; 355 base::HistogramTester histogram_tester;
331 356
332 LoadHTML(kAccountCreationFormHTML); 357 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
333 SetNotBlacklistedMessage(kAccountCreationFormHTML); 358 SetNotBlacklistedMessage(kAccountCreationFormHTML);
334 SetAccountCreationFormsDetectedMessage(0); 359 SetAccountCreationFormsDetectedMessage(0);
335 ExpectPasswordGenerationAvailable("first_password", true); 360 ExpectPasswordGenerationAvailable("first_password", true);
336 361
337 WebDocument document = GetMainFrame()->document(); 362 WebDocument document = GetMainFrame()->document();
338 WebElement element = 363 WebElement element =
339 document.getElementById(WebString::fromUTF8("first_password")); 364 document.getElementById(WebString::fromUTF8("first_password"));
340 ASSERT_FALSE(element.isNull()); 365 ASSERT_FALSE(element.isNull());
341 WebInputElement first_password_element = element.to<WebInputElement>(); 366 WebInputElement first_password_element = element.to<WebInputElement>();
342 367
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 password_generation_->clear_messages(); 415 password_generation_->clear_messages();
391 416
392 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, 417 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
393 // so no messages are sent. 418 // so no messages are sent.
394 ExecuteJavaScript("document.getElementById('username').focus();"); 419 ExecuteJavaScript("document.getElementById('username').focus();");
395 EXPECT_EQ(0u, password_generation_->messages().size()); 420 EXPECT_EQ(0u, password_generation_->messages().size());
396 password_generation_->clear_messages(); 421 password_generation_->clear_messages();
397 422
398 // Focusing the password field will bring up the generation UI again. 423 // Focusing the password field will bring up the generation UI again.
399 ExecuteJavaScript("document.getElementById('first_password').focus();"); 424 ExecuteJavaScript("document.getElementById('first_password').focus();");
400 EXPECT_EQ(1u, password_generation_->messages().size()); 425 ASSERT_EQ(1u, password_generation_->messages().size());
401 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 426 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
402 password_generation_->messages()[0]->type()); 427 password_generation_->messages()[0]->type());
403 password_generation_->clear_messages(); 428 password_generation_->clear_messages();
404 429
405 // Loading a different page triggers UMA stat upload. Verify that only one 430 // Loading a different page triggers UMA stat upload. Verify that only one
406 // display event is sent even though 431 // display event is sent even though
407 LoadHTML(kSigninFormHTML); 432 LoadHTMLWithUserGesture(kSigninFormHTML);
408 433
409 histogram_tester.ExpectBucketCount( 434 histogram_tester.ExpectBucketCount(
410 "PasswordGeneration.Event", 435 "PasswordGeneration.Event",
411 autofill::password_generation::GENERATION_POPUP_SHOWN, 436 autofill::password_generation::GENERATION_POPUP_SHOWN,
412 1); 437 1);
413 } 438 }
414 439
415 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) { 440 TEST_F(PasswordGenerationAgentTest, DynamicFormTest) {
416 LoadHTML(kSigninFormHTML); 441 LoadHTMLWithUserGesture(kSigninFormHTML);
417 SetNotBlacklistedMessage(kSigninFormHTML); 442 SetNotBlacklistedMessage(kSigninFormHTML);
418 443
419 ExecuteJavaScript( 444 ExecuteJavaScript(
420 "var form = document.createElement('form');" 445 "var form = document.createElement('form');"
421 "var username = document.createElement('input');" 446 "var username = document.createElement('input');"
422 "username.type = 'text';" 447 "username.type = 'text';"
423 "username.id = 'dynamic_username';" 448 "username.id = 'dynamic_username';"
424 "var first_password = document.createElement('input');" 449 "var first_password = document.createElement('input');"
425 "first_password.type = 'password';" 450 "first_password.type = 'password';"
426 "first_password.id = 'first_password';" 451 "first_password.id = 'first_password';"
427 "first_password.name = 'first_password';" 452 "first_password.name = 'first_password';"
428 "var second_password = document.createElement('input');" 453 "var second_password = document.createElement('input');"
429 "second_password.type = 'password';" 454 "second_password.type = 'password';"
430 "second_password.id = 'second_password';" 455 "second_password.id = 'second_password';"
431 "second_password.name = 'second_password';" 456 "second_password.name = 'second_password';"
432 "form.appendChild(username);" 457 "form.appendChild(username);"
433 "form.appendChild(first_password);" 458 "form.appendChild(first_password);"
434 "form.appendChild(second_password);" 459 "form.appendChild(second_password);"
435 "document.body.appendChild(form);"); 460 "document.body.appendChild(form);");
436 ProcessPendingMessages(); 461 ProcessPendingMessages();
437 462
438 // This needs to come after the DOM has been modified. 463 // This needs to come after the DOM has been modified.
439 SetAccountCreationFormsDetectedMessage(1); 464 SetAccountCreationFormsDetectedMessage(1);
440 465
441 // TODO(gcasto): I'm slighty worried about flakes in this test where 466 // TODO(gcasto): I'm slightly worried about flakes in this test where
442 // didAssociateFormControls() isn't called. If this turns out to be a problem 467 // didAssociateFormControls() isn't called. If this turns out to be a problem
443 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though 468 // adding a call to OnDynamicFormsSeen(GetMainFrame()) will fix it, though
444 // it will weaken the test. 469 // it will weaken the test.
445 ExpectPasswordGenerationAvailable("first_password", true); 470 ExpectPasswordGenerationAvailable("first_password", true);
446 } 471 }
447 472
448 TEST_F(PasswordGenerationAgentTest, MultiplePasswordFormsTest) { 473 TEST_F(PasswordGenerationAgentTest, MultiplePasswordFormsTest) {
449 // If two forms on the page looks like possible account creation forms, make 474 // If two forms on the page looks like possible account creation forms, make
450 // sure to trigger on the one that is specified from Autofill. 475 // sure to trigger on the one that is specified from Autofill.
451 LoadHTML(kMultipleAccountCreationFormHTML); 476 LoadHTMLWithUserGesture(kMultipleAccountCreationFormHTML);
452 SetNotBlacklistedMessage(kMultipleAccountCreationFormHTML); 477 SetNotBlacklistedMessage(kMultipleAccountCreationFormHTML);
453 478
454 // Should trigger on the second form. 479 // Should trigger on the second form.
455 SetAccountCreationFormsDetectedMessage(1); 480 SetAccountCreationFormsDetectedMessage(1);
456 481
457 ExpectPasswordGenerationAvailable("password", false); 482 ExpectPasswordGenerationAvailable("password", false);
458 ExpectPasswordGenerationAvailable("first_password", true); 483 ExpectPasswordGenerationAvailable("first_password", true);
459 } 484 }
460 485
461 TEST_F(PasswordGenerationAgentTest, MessagesAfterAccountSignupFormFound) { 486 TEST_F(PasswordGenerationAgentTest, MessagesAfterAccountSignupFormFound) {
462 LoadHTML(kAccountCreationFormHTML); 487 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
463 SetNotBlacklistedMessage(kAccountCreationFormHTML); 488 SetNotBlacklistedMessage(kAccountCreationFormHTML);
464 SetAccountCreationFormsDetectedMessage(0); 489 SetAccountCreationFormsDetectedMessage(0);
465 490
466 // Generation should be enabled. 491 // Generation should be enabled.
467 ExpectPasswordGenerationAvailable("first_password", true); 492 ExpectPasswordGenerationAvailable("first_password", true);
468 493
469 // Extra not blacklisted messages can be sent. Make sure that they are handled 494 // Extra not blacklisted messages can be sent. Make sure that they are handled
470 // correctly (generation should still be available). 495 // correctly (generation should still be available).
471 SetNotBlacklistedMessage(kAccountCreationFormHTML); 496 SetNotBlacklistedMessage(kAccountCreationFormHTML);
472 497
473 // Need to focus another field first for verification to work. 498 // Need to focus another field first for verification to work.
474 ExpectPasswordGenerationAvailable("second_password", false); 499 ExpectPasswordGenerationAvailable("second_password", false);
475 ExpectPasswordGenerationAvailable("first_password", true); 500 ExpectPasswordGenerationAvailable("first_password", true);
476 } 501 }
477 502
503 // Losing focus should not trigger a password generation popup.
504 TEST_F(PasswordGenerationAgentTest, BlurTest) {
505 LoadHTMLWithUserGesture(kDisabledElementAccountCreationFormHTML);
506 SetNotBlacklistedMessage(kDisabledElementAccountCreationFormHTML);
507 SetAccountCreationFormsDetectedMessage(0);
508
509 // Focus on the first password field: password generation popup should show
510 // up.
511 ExpectPasswordGenerationAvailable("first_password", true);
512
513 // Remove focus from everywhere by clicking an unfocusable element: password
514 // generation popup should not show up.
515 EXPECT_TRUE(SimulateElementClick("disabled"));
516 EXPECT_EQ(0u, password_generation_->messages().size());
517 }
518
478 } // namespace autofill 519 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/page_click_tracker_browsertest.cc ('k') | components/autofill/content/renderer/autofill_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698