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

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

Issue 1026493002: Allow only a user gesture to trigger autofill popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not layout frame. Created 5 years, 8 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"
11 #include "components/autofill/content/common/autofill_messages.h" 11 #include "components/autofill/content/common/autofill_messages.h"
12 #include "components/autofill/content/renderer/autofill_agent.h" 12 #include "components/autofill/content/renderer/autofill_agent.h"
13 #include "components/autofill/content/renderer/form_autofill_util.h" 13 #include "components/autofill/content/renderer/form_autofill_util.h"
14 #include "components/autofill/content/renderer/test_password_generation_agent.h" 14 #include "components/autofill/content/renderer/test_password_generation_agent.h"
15 #include "components/autofill/core/common/form_data.h" 15 #include "components/autofill/core/common/form_data.h"
16 #include "components/autofill/core/common/password_generation_util.h" 16 #include "components/autofill/core/common/password_generation_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" 20 #include "third_party/WebKit/public/web/WebLocalFrame.h"
21 #include "third_party/WebKit/public/web/WebWidget.h" 21 #include "third_party/WebKit/public/web/WebWidget.h"
22 #include "ui/events/keycodes/keyboard_codes.h"
22 23
23 using blink::WebDocument; 24 using blink::WebDocument;
24 using blink::WebElement; 25 using blink::WebElement;
25 using blink::WebInputElement; 26 using blink::WebInputElement;
26 using blink::WebNode; 27 using blink::WebNode;
27 using blink::WebString; 28 using blink::WebString;
28 29
29 namespace autofill { 30 namespace autofill {
30 31
31 class PasswordGenerationAgentTest : public ChromeRenderViewTest { 32 class PasswordGenerationAgentTest : public ChromeRenderViewTest {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 303
303 base::string16 password = base::ASCIIToUTF16("random_password"); 304 base::string16 password = base::ASCIIToUTF16("random_password");
304 AutofillMsg_GeneratedPasswordAccepted msg(0, password); 305 AutofillMsg_GeneratedPasswordAccepted msg(0, password);
305 password_generation_->OnMessageReceived(msg); 306 password_generation_->OnMessageReceived(msg);
306 307
307 // Passwords start out the same. 308 // Passwords start out the same.
308 EXPECT_EQ(password, first_password_element.value()); 309 EXPECT_EQ(password, first_password_element.value());
309 EXPECT_EQ(password, second_password_element.value()); 310 EXPECT_EQ(password, second_password_element.value());
310 311
311 // After editing the first field they are still the same. 312 // After editing the first field they are still the same.
312 base::string16 edited_password = base::ASCIIToUTF16("edited_password"); 313 std::string edited_password_ascii = "edited_password";
313 first_password_element.setValue(edited_password); 314 SimulateUserInputChangeForElement(&first_password_element,
314 // Cast to WebAutofillClient where textFieldDidChange() is public. 315 edited_password_ascii);
315 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange( 316 base::string16 edited_password = base::ASCIIToUTF16(edited_password_ascii);
316 first_password_element);
317 // textFieldDidChange posts a task, so we need to wait until it's been
318 // processed.
319 base::MessageLoop::current()->RunUntilIdle();
320 EXPECT_EQ(edited_password, first_password_element.value()); 317 EXPECT_EQ(edited_password, first_password_element.value());
321 EXPECT_EQ(edited_password, second_password_element.value()); 318 EXPECT_EQ(edited_password, second_password_element.value());
322 319
323 // Verify that password mirroring works correctly even when the password 320 // Verify that password mirroring works correctly even when the password
324 // is deleted. 321 // is deleted.
325 base::string16 empty_password; 322 SimulateUserInputChangeForElement(&first_password_element, std::string());
326 first_password_element.setValue(empty_password); 323 EXPECT_EQ(base::string16(), first_password_element.value());
327 // Cast to WebAutofillClient where textFieldDidChange() is public. 324 EXPECT_EQ(base::string16(), second_password_element.value());
328 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
329 first_password_element);
330 // textFieldDidChange posts a task, so we need to wait until it's been
331 // processed.
332 base::MessageLoop::current()->RunUntilIdle();
333 EXPECT_EQ(empty_password, first_password_element.value());
334 EXPECT_EQ(empty_password, second_password_element.value());
335 } 325 }
336 326
337 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) { 327 TEST_F(PasswordGenerationAgentTest, BlacklistedTest) {
338 // Did not receive not blacklisted message. Don't show password generation 328 // Did not receive not blacklisted message. Don't show password generation
339 // icon. 329 // icon.
340 LoadHTMLWithUserGesture(kAccountCreationFormHTML); 330 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
341 SetAccountCreationFormsDetectedMessage(0); 331 SetAccountCreationFormsDetectedMessage(0);
342 ExpectPasswordGenerationAvailable("first_password", false); 332 ExpectPasswordGenerationAvailable("first_password", false);
343 333
344 // Receive one not blacklisted message for non account creation form. Don't 334 // Receive one not blacklisted message for non account creation form. Don't
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 SetAccountCreationFormsDetectedMessage(0); 377 SetAccountCreationFormsDetectedMessage(0);
388 ExpectPasswordGenerationAvailable("first_password", true); 378 ExpectPasswordGenerationAvailable("first_password", true);
389 379
390 WebDocument document = GetMainFrame()->document(); 380 WebDocument document = GetMainFrame()->document();
391 WebElement element = 381 WebElement element =
392 document.getElementById(WebString::fromUTF8("first_password")); 382 document.getElementById(WebString::fromUTF8("first_password"));
393 ASSERT_FALSE(element.isNull()); 383 ASSERT_FALSE(element.isNull());
394 WebInputElement first_password_element = element.to<WebInputElement>(); 384 WebInputElement first_password_element = element.to<WebInputElement>();
395 385
396 // Make a password just under maximum offer size. 386 // Make a password just under maximum offer size.
397 first_password_element.setValue( 387 SimulateUserInputChangeForElement(
398 base::ASCIIToUTF16( 388 &first_password_element,
399 std::string(password_generation_->kMaximumOfferSize - 1, 'a'))); 389 std::string(password_generation_->kMaximumOfferSize - 1, 'a'));
400 // Cast to WebAutofillClient where textFieldDidChange() is public.
401 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
402 first_password_element);
403 // textFieldDidChange posts a task, so we need to wait until it's been
404 // processed.
405 base::MessageLoop::current()->RunUntilIdle();
406 // There should now be a message to show the UI. 390 // There should now be a message to show the UI.
407 ASSERT_EQ(1u, password_generation_->messages().size()); 391 ASSERT_EQ(1u, password_generation_->messages().size());
408 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 392 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
409 password_generation_->messages()[0]->type()); 393 password_generation_->messages()[0]->type());
410 password_generation_->clear_messages(); 394 password_generation_->clear_messages();
411 395
412 // Simulate a user typing a password just over maximum offer size. 396 // Simulate a user typing a password just over maximum offer size.
413 first_password_element.setValue( 397 SimulateUserTypingASCIICharacter('a', false);
414 base::ASCIIToUTF16( 398 SimulateUserTypingASCIICharacter('a', true);
415 std::string(password_generation_->kMaximumOfferSize + 1, 'a')));
416 // Cast to WebAutofillClient where textFieldDidChange() is public.
417 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
418 first_password_element);
419 // textFieldDidChange posts a task, so we need to wait until it's been
420 // processed.
421 base::MessageLoop::current()->RunUntilIdle();
422 // There should now be a message to hide the UI. 399 // There should now be a message to hide the UI.
423 ASSERT_EQ(1u, password_generation_->messages().size()); 400 ASSERT_EQ(1u, password_generation_->messages().size());
424 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID, 401 EXPECT_EQ(AutofillHostMsg_HidePasswordGenerationPopup::ID,
425 password_generation_->messages()[0]->type()); 402 password_generation_->messages()[0]->type());
426 password_generation_->clear_messages(); 403 password_generation_->clear_messages();
427 404
428 // Simulate the user deleting characters. The generation popup should be shown 405 // Simulate the user deleting characters. The generation popup should be shown
429 // again. 406 // again.
430 first_password_element.setValue( 407 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true);
431 base::ASCIIToUTF16(
432 std::string(password_generation_->kMaximumOfferSize, 'a')));
433 // Cast to WebAutofillClient where textFieldDidChange() is public.
434 static_cast<blink::WebAutofillClient*>(autofill_agent_)->textFieldDidChange(
435 first_password_element);
436 // textFieldDidChange posts a task, so we need to wait until it's been
437 // processed.
438 base::MessageLoop::current()->RunUntilIdle();
439 // There should now be a message to show the UI. 408 // There should now be a message to show the UI.
440 ASSERT_EQ(1u, password_generation_->messages().size()); 409 ASSERT_EQ(1u, password_generation_->messages().size());
441 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID, 410 EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
442 password_generation_->messages()[0]->type()); 411 password_generation_->messages()[0]->type());
443 password_generation_->clear_messages(); 412 password_generation_->clear_messages();
444 413
445 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent, 414 // Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
446 // so no messages are sent. 415 // so no messages are sent.
447 ExecuteJavaScript("document.getElementById('username').focus();"); 416 ExecuteJavaScript("document.getElementById('username').focus();");
448 EXPECT_EQ(0u, password_generation_->messages().size()); 417 EXPECT_EQ(0u, password_generation_->messages().size());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 527
559 ExpectPasswordGenerationAvailable("first_password", false); 528 ExpectPasswordGenerationAvailable("first_password", false);
560 529
561 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML); 530 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML);
562 SetNotBlacklistedMessage(kNewPasswordAutocompleteAttributeFormHTML); 531 SetNotBlacklistedMessage(kNewPasswordAutocompleteAttributeFormHTML);
563 532
564 ExpectPasswordGenerationAvailable("first_password", false); 533 ExpectPasswordGenerationAvailable("first_password", false);
565 } 534 }
566 535
567 } // namespace autofill 536 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/password_autofill_agent_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