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

Side by Side Diff: chrome/browser/autofill/autofill_interactive_uitest.cc

Issue 2048533002: Add code and key into the browser test key simulation methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix chromeos build Created 4 years, 6 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "content/public/test/browser_test_utils.h" 46 #include "content/public/test/browser_test_utils.h"
47 #include "content/public/test/test_renderer_host.h" 47 #include "content/public/test/test_renderer_host.h"
48 #include "content/public/test/test_utils.h" 48 #include "content/public/test/test_utils.h"
49 #include "net/base/net_errors.h" 49 #include "net/base/net_errors.h"
50 #include "net/test/embedded_test_server/embedded_test_server.h" 50 #include "net/test/embedded_test_server/embedded_test_server.h"
51 #include "net/url_request/test_url_fetcher_factory.h" 51 #include "net/url_request/test_url_fetcher_factory.h"
52 #include "net/url_request/url_request_status.h" 52 #include "net/url_request/url_request_status.h"
53 #include "testing/gmock/include/gmock/gmock.h" 53 #include "testing/gmock/include/gmock/gmock.h"
54 #include "testing/gtest/include/gtest/gtest.h" 54 #include "testing/gtest/include/gtest/gtest.h"
55 #include "ui/base/clipboard/scoped_clipboard_writer.h" 55 #include "ui/base/clipboard/scoped_clipboard_writer.h"
56 #include "ui/events/keycodes/keyboard_code_conversion.h"
56 #include "ui/events/keycodes/keyboard_codes.h" 57 #include "ui/events/keycodes/keyboard_codes.h"
57 58
58 using base::ASCIIToUTF16; 59 using base::ASCIIToUTF16;
59 60
60 namespace autofill { 61 namespace autofill {
61 62
62 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,"; 63 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,";
63 static const char kTestFormString[] = 64 static const char kTestFormString[] =
64 "<form action=\"http://www.example.com/\" method=\"POST\">" 65 "<form action=\"http://www.example.com/\" method=\"POST\">"
65 "<label for=\"firstname\">First name:</label>" 66 "<label for=\"firstname\">First name:</label>"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 AddTestProfile(browser(), profile); 280 AddTestProfile(browser(), profile);
280 } 281 }
281 282
282 // Populates a webpage form using autofill data and keypress events. 283 // Populates a webpage form using autofill data and keypress events.
283 // This function focuses the specified input field in the form, and then 284 // This function focuses the specified input field in the form, and then
284 // sends keypress events to the tab to cause the form to be populated. 285 // sends keypress events to the tab to cause the form to be populated.
285 void PopulateForm(const std::string& field_id) { 286 void PopulateForm(const std::string& field_id) {
286 std::string js("document.getElementById('" + field_id + "').focus();"); 287 std::string js("document.getElementById('" + field_id + "').focus();");
287 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), js)); 288 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), js));
288 289
289 SendKeyToPageAndWait(ui::VKEY_DOWN); 290 SendKeyToPageAndWait(ui::DomKey::ARROW_DOWN);
290 SendKeyToPopupAndWait(ui::VKEY_DOWN); 291 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
291 SendKeyToPopupAndWait(ui::VKEY_RETURN); 292 SendKeyToPopupAndWait(ui::DomKey::ENTER);
292 } 293 }
293 294
294 void ExpectFieldValue(const std::string& field_name, 295 void ExpectFieldValue(const std::string& field_name,
295 const std::string& expected_value) { 296 const std::string& expected_value) {
296 std::string value; 297 std::string value;
297 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 298 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
298 GetWebContents(), 299 GetWebContents(),
299 "window.domAutomationController.send(" 300 "window.domAutomationController.send("
300 " document.getElementById('" + field_name + "').value);", 301 " document.getElementById('" + field_name + "').value);",
301 &value)); 302 &value));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 ExpectFieldValue("lastname", "Waddams"); 420 ExpectFieldValue("lastname", "Waddams");
420 ExpectFieldValue("address1", "4120 Freidrich Lane"); 421 ExpectFieldValue("address1", "4120 Freidrich Lane");
421 ExpectFieldValue("address2", "Basement"); 422 ExpectFieldValue("address2", "Basement");
422 ExpectFieldValue("city", "Austin"); 423 ExpectFieldValue("city", "Austin");
423 ExpectFieldValue("state", "TX"); 424 ExpectFieldValue("state", "TX");
424 ExpectFieldValue("zip", "78744"); 425 ExpectFieldValue("zip", "78744");
425 ExpectFieldValue("country", "US"); 426 ExpectFieldValue("country", "US");
426 ExpectFieldValue("phone", "5125551234"); 427 ExpectFieldValue("phone", "5125551234");
427 } 428 }
428 429
429 void SendKeyToPageAndWait(ui::KeyboardCode key) { 430 void SendKeyToPageAndWait(ui::DomKey key) {
431 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key);
432 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code);
433 SendKeyToPageAndWait(key, code, key_code);
434 }
435
436 void SendKeyToPageAndWait(ui::DomKey key,
437 ui::DomCode code,
438 ui::KeyboardCode key_code) {
430 test_delegate_.Reset(); 439 test_delegate_.Reset();
431 content::SimulateKeyPress( 440 content::SimulateKeyPress(GetWebContents(), key, code, key_code, false,
432 GetWebContents(), key, false, false, false, false); 441 false, false, false);
433 test_delegate_.Wait(); 442 test_delegate_.Wait();
434 } 443 }
435 444
436 void PasteStringAndWait(const std::string& pastedata) { 445 void PasteStringAndWait(const std::string& pastedata) {
437 { 446 {
438 ui::ScopedClipboardWriter writer(ui::CLIPBOARD_TYPE_COPY_PASTE); 447 ui::ScopedClipboardWriter writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
439 writer.WriteText(base::ASCIIToUTF16(pastedata)); 448 writer.WriteText(base::ASCIIToUTF16(pastedata));
440 } 449 }
441 test_delegate_.Reset(); 450 test_delegate_.Reset();
442 GetWebContents()->Paste(); 451 GetWebContents()->Paste();
443 test_delegate_.WaitForTextChange(); 452 test_delegate_.WaitForTextChange();
444 } 453 }
445 454
446 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event) { 455 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event) {
447 return true; 456 return true;
448 } 457 }
449 458
450 void SendKeyToPopupAndWait(ui::KeyboardCode key) { 459 void SendKeyToPopupAndWait(ui::DomKey key) {
460 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key);
461 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code);
462 SendKeyToPopupAndWait(key, code, key_code);
463 }
464
465 void SendKeyToPopupAndWait(ui::DomKey key,
466 ui::DomCode code,
467 ui::KeyboardCode key_code) {
451 // Route popup-targeted key presses via the render view host. 468 // Route popup-targeted key presses via the render view host.
452 content::NativeWebKeyboardEvent event; 469 content::NativeWebKeyboardEvent event;
453 event.windowsKeyCode = key; 470 event.windowsKeyCode = key_code;
471 event.domCode = static_cast<int>(code);
472 event.domKey = key;
454 event.type = blink::WebKeyboardEvent::RawKeyDown; 473 event.type = blink::WebKeyboardEvent::RawKeyDown;
455 test_delegate_.Reset(); 474 test_delegate_.Reset();
456 // Install the key press event sink to ensure that any events that are not 475 // Install the key press event sink to ensure that any events that are not
457 // handled by the installed callbacks do not end up crashing the test. 476 // handled by the installed callbacks do not end up crashing the test.
458 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback( 477 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback(
459 key_press_event_sink_); 478 key_press_event_sink_);
460 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); 479 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event);
461 test_delegate_.Wait(); 480 test_delegate_.Wait();
462 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback( 481 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback(
463 key_press_event_sink_); 482 key_press_event_sink_);
464 } 483 }
465 484
485 void SendKeyToDataListPopup(ui::DomKey key) {
486 ui::KeyboardCode key_code = ui::NonPrintableDomKeyToKeyboardCode(key);
487 ui::DomCode code = ui::UsLayoutKeyboardCodeToDomCode(key_code);
488 SendKeyToDataListPopup(key, code, key_code);
489 }
490
466 // Datalist does not support autofill preview. There is no need to start 491 // Datalist does not support autofill preview. There is no need to start
467 // message loop for Datalist. 492 // message loop for Datalist.
468 void SendKeyToDataListPopup(ui::KeyboardCode key) { 493 void SendKeyToDataListPopup(ui::DomKey key,
494 ui::DomCode code,
495 ui::KeyboardCode key_code) {
469 // Route popup-targeted key presses via the render view host. 496 // Route popup-targeted key presses via the render view host.
470 content::NativeWebKeyboardEvent event; 497 content::NativeWebKeyboardEvent event;
471 event.windowsKeyCode = key; 498 event.windowsKeyCode = key_code;
499 event.domCode = static_cast<int>(code);
500 event.domKey = key;
472 event.type = blink::WebKeyboardEvent::RawKeyDown; 501 event.type = blink::WebKeyboardEvent::RawKeyDown;
473 // Install the key press event sink to ensure that any events that are not 502 // Install the key press event sink to ensure that any events that are not
474 // handled by the installed callbacks do not end up crashing the test. 503 // handled by the installed callbacks do not end up crashing the test.
475 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback( 504 GetRenderViewHost()->GetWidget()->AddKeyPressEventCallback(
476 key_press_event_sink_); 505 key_press_event_sink_);
477 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); 506 GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event);
478 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback( 507 GetRenderViewHost()->GetWidget()->RemoveKeyPressEventCallback(
479 key_press_event_sink_); 508 key_press_event_sink_);
480 } 509 }
481 510
482 void TryBasicFormFill() { 511 void TryBasicFormFill() {
483 FocusFirstNameField(); 512 FocusFirstNameField();
484 513
485 // Start filling the first name field with "M" and wait for the popup to be 514 // Start filling the first name field with "M" and wait for the popup to be
486 // shown. 515 // shown.
487 SendKeyToPageAndWait(ui::VKEY_M); 516 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
517 ui::VKEY_M);
488 518
489 // Press the down arrow to select the suggestion and preview the autofilled 519 // Press the down arrow to select the suggestion and preview the autofilled
490 // form. 520 // form.
491 SendKeyToPopupAndWait(ui::VKEY_DOWN); 521 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
492 522
493 // The previewed values should not be accessible to JavaScript. 523 // The previewed values should not be accessible to JavaScript.
494 ExpectFieldValue("firstname", "M"); 524 ExpectFieldValue("firstname", "M");
495 ExpectFieldValue("lastname", std::string()); 525 ExpectFieldValue("lastname", std::string());
496 ExpectFieldValue("address1", std::string()); 526 ExpectFieldValue("address1", std::string());
497 ExpectFieldValue("address2", std::string()); 527 ExpectFieldValue("address2", std::string());
498 ExpectFieldValue("city", std::string()); 528 ExpectFieldValue("city", std::string());
499 ExpectFieldValue("state", std::string()); 529 ExpectFieldValue("state", std::string());
500 ExpectFieldValue("zip", std::string()); 530 ExpectFieldValue("zip", std::string());
501 ExpectFieldValue("country", std::string()); 531 ExpectFieldValue("country", std::string());
502 ExpectFieldValue("phone", std::string()); 532 ExpectFieldValue("phone", std::string());
503 // TODO(isherman): It would be nice to test that the previewed values are 533 // TODO(isherman): It would be nice to test that the previewed values are
504 // displayed: http://crbug.com/57220 534 // displayed: http://crbug.com/57220
505 535
506 // Press Enter to accept the autofill suggestions. 536 // Press Enter to accept the autofill suggestions.
507 SendKeyToPopupAndWait(ui::VKEY_RETURN); 537 SendKeyToPopupAndWait(ui::DomKey::ENTER);
508 538
509 // The form should be filled. 539 // The form should be filled.
510 ExpectFilledTestForm(); 540 ExpectFilledTestForm();
511 } 541 }
512 542
513 AutofillManagerTestDelegateImpl* test_delegate() { return &test_delegate_; } 543 AutofillManagerTestDelegateImpl* test_delegate() { return &test_delegate_; }
514 544
515 private: 545 private:
516 AutofillManagerTestDelegateImpl test_delegate_; 546 AutofillManagerTestDelegateImpl test_delegate_;
517 547
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 588
559 // Load the test page. 589 // Load the test page.
560 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 590 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
561 GURL(std::string(kDataURIPrefix) + kTestFormString))); 591 GURL(std::string(kDataURIPrefix) + kTestFormString)));
562 592
563 // Focus a fillable field. 593 // Focus a fillable field.
564 FocusFirstNameField(); 594 FocusFirstNameField();
565 595
566 // Press the down arrow to initiate Autofill and wait for the popup to be 596 // Press the down arrow to initiate Autofill and wait for the popup to be
567 // shown. 597 // shown.
568 SendKeyToPageAndWait(ui::VKEY_DOWN); 598 SendKeyToPageAndWait(ui::DomKey::ARROW_DOWN);
569 599
570 // Press the down arrow to select the suggestion and preview the autofilled 600 // Press the down arrow to select the suggestion and preview the autofilled
571 // form. 601 // form.
572 SendKeyToPopupAndWait(ui::VKEY_DOWN); 602 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
573 603
574 // Press Enter to accept the autofill suggestions. 604 // Press Enter to accept the autofill suggestions.
575 SendKeyToPopupAndWait(ui::VKEY_RETURN); 605 SendKeyToPopupAndWait(ui::DomKey::ENTER);
576 606
577 // The form should be filled. 607 // The form should be filled.
578 ExpectFilledTestForm(); 608 ExpectFilledTestForm();
579 } 609 }
580 610
581 // crbug.com/516052 611 // crbug.com/516052
582 #if defined(OS_CHROMEOS) 612 #if defined(OS_CHROMEOS)
583 #define MAYBE_AutofillSelectViaTab DISABLED_AutofillSelectViaTab 613 #define MAYBE_AutofillSelectViaTab DISABLED_AutofillSelectViaTab
584 #else 614 #else
585 #define MAYBE_AutofillSelectViaTab AutofillSelectViaTab 615 #define MAYBE_AutofillSelectViaTab AutofillSelectViaTab
586 #endif 616 #endif
587 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, MAYBE_AutofillSelectViaTab) { 617 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, MAYBE_AutofillSelectViaTab) {
588 CreateTestProfile(); 618 CreateTestProfile();
589 619
590 // Load the test page. 620 // Load the test page.
591 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 621 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
592 GURL(std::string(kDataURIPrefix) + kTestFormString))); 622 GURL(std::string(kDataURIPrefix) + kTestFormString)));
593 623
594 // Focus a fillable field. 624 // Focus a fillable field.
595 FocusFirstNameField(); 625 FocusFirstNameField();
596 626
597 // Press the down arrow to initiate Autofill and wait for the popup to be 627 // Press the down arrow to initiate Autofill and wait for the popup to be
598 // shown. 628 // shown.
599 SendKeyToPageAndWait(ui::VKEY_DOWN); 629 SendKeyToPageAndWait(ui::DomKey::ARROW_DOWN);
600 630
601 // Press the down arrow to select the suggestion and preview the autofilled 631 // Press the down arrow to select the suggestion and preview the autofilled
602 // form. 632 // form.
603 SendKeyToPopupAndWait(ui::VKEY_DOWN); 633 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
604 634
605 // Press tab to accept the autofill suggestions. 635 // Press tab to accept the autofill suggestions.
606 SendKeyToPopupAndWait(ui::VKEY_TAB); 636 SendKeyToPopupAndWait(ui::DomKey::TAB);
607 637
608 // The form should be filled. 638 // The form should be filled.
609 ExpectFilledTestForm(); 639 ExpectFilledTestForm();
610 } 640 }
611 641
612 // crbug.com/516052 642 // crbug.com/516052
613 #if defined(OS_CHROMEOS) 643 #if defined(OS_CHROMEOS)
614 #define MAYBE_AutofillViaClick DISABLED_AutofillViaClick 644 #define MAYBE_AutofillViaClick DISABLED_AutofillViaClick
615 #else 645 #else
616 #define MAYBE_AutofillViaClick AutofillViaClick 646 #define MAYBE_AutofillViaClick AutofillViaClick
617 #endif 647 #endif
618 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, MAYBE_AutofillViaClick) { 648 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, MAYBE_AutofillViaClick) {
619 CreateTestProfile(); 649 CreateTestProfile();
620 650
621 // Load the test page. 651 // Load the test page.
622 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL( 652 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
623 browser(), GURL(std::string(kDataURIPrefix) + kTestFormString))); 653 browser(), GURL(std::string(kDataURIPrefix) + kTestFormString)));
624 // Focus a fillable field. 654 // Focus a fillable field.
625 ASSERT_NO_FATAL_FAILURE(FocusFirstNameField()); 655 ASSERT_NO_FATAL_FAILURE(FocusFirstNameField());
626 656
627 // Now click it. 657 // Now click it.
628 test_delegate()->Reset(); 658 test_delegate()->Reset();
629 ASSERT_NO_FATAL_FAILURE(ClickFirstNameField()); 659 ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
630 test_delegate()->Wait(); 660 test_delegate()->Wait();
631 661
632 // Press the down arrow to select the suggestion and preview the autofilled 662 // Press the down arrow to select the suggestion and preview the autofilled
633 // form. 663 // form.
634 SendKeyToPopupAndWait(ui::VKEY_DOWN); 664 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
635 665
636 // Press Enter to accept the autofill suggestions. 666 // Press Enter to accept the autofill suggestions.
637 SendKeyToPopupAndWait(ui::VKEY_RETURN); 667 SendKeyToPopupAndWait(ui::DomKey::ENTER);
638 668
639 // The form should be filled. 669 // The form should be filled.
640 ExpectFilledTestForm(); 670 ExpectFilledTestForm();
641 } 671 }
642 672
643 // Makes sure that the first click does *not* activate the popup. 673 // Makes sure that the first click does *not* activate the popup.
644 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DontAutofillForFirstClick) { 674 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DontAutofillForFirstClick) {
645 CreateTestProfile(); 675 CreateTestProfile();
646 676
647 // Load the test page. 677 // Load the test page.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, 726 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
697 MAYBE_OnDeleteValueAfterAutofill) { 727 MAYBE_OnDeleteValueAfterAutofill) {
698 CreateTestProfile(); 728 CreateTestProfile();
699 729
700 // Load the test page. 730 // Load the test page.
701 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 731 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
702 GURL(std::string(kDataURIPrefix) + kTestFormString))); 732 GURL(std::string(kDataURIPrefix) + kTestFormString)));
703 733
704 // Invoke and accept the Autofill popup and verify the form was filled. 734 // Invoke and accept the Autofill popup and verify the form was filled.
705 FocusFirstNameField(); 735 FocusFirstNameField();
706 SendKeyToPageAndWait(ui::VKEY_M); 736 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
707 SendKeyToPopupAndWait(ui::VKEY_DOWN); 737 ui::VKEY_M);
708 SendKeyToPopupAndWait(ui::VKEY_RETURN); 738 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
739 SendKeyToPopupAndWait(ui::DomKey::ENTER);
709 ExpectFilledTestForm(); 740 ExpectFilledTestForm();
710 741
711 // Delete the value of a filled field. 742 // Delete the value of a filled field.
712 ASSERT_TRUE(content::ExecuteScript( 743 ASSERT_TRUE(content::ExecuteScript(
713 GetRenderViewHost(), 744 GetRenderViewHost(),
714 "document.getElementById('firstname').value = '';")); 745 "document.getElementById('firstname').value = '';"));
715 ExpectFieldValue("firstname", ""); 746 ExpectFieldValue("firstname", "");
716 747
717 // Invoke and accept the Autofill popup and verify the field was filled. 748 // Invoke and accept the Autofill popup and verify the field was filled.
718 SendKeyToPageAndWait(ui::VKEY_M); 749 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
719 SendKeyToPopupAndWait(ui::VKEY_DOWN); 750 ui::VKEY_M);
720 SendKeyToPopupAndWait(ui::VKEY_RETURN); 751 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
752 SendKeyToPopupAndWait(ui::DomKey::ENTER);
721 ExpectFieldValue("firstname", "Milton"); 753 ExpectFieldValue("firstname", "Milton");
722 } 754 }
723 755
724 // Test that an input field is not rendered with the yellow autofilled 756 // Test that an input field is not rendered with the yellow autofilled
725 // background color when choosing an option from the datalist suggestion list. 757 // background color when choosing an option from the datalist suggestion list.
726 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) 758 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
727 // Flakily triggers and assert on Mac; flakily gets empty string instead 759 // Flakily triggers and assert on Mac; flakily gets empty string instead
728 // of "Adam" on ChromeOS. 760 // of "Adam" on ChromeOS.
729 // http://crbug.com/419868, http://crbug.com/595385. 761 // http://crbug.com/419868, http://crbug.com/595385.
730 #define MAYBE_OnSelectOptionFromDatalist DISABLED_OnSelectOptionFromDatalist 762 #define MAYBE_OnSelectOptionFromDatalist DISABLED_OnSelectOptionFromDatalist
(...skipping 12 matching lines...) Expand all
743 " <datalist id=\"dl\">" 775 " <datalist id=\"dl\">"
744 " <option value=\"Adam\"></option>" 776 " <option value=\"Adam\"></option>"
745 " <option value=\"Bob\"></option>" 777 " <option value=\"Bob\"></option>"
746 " <option value=\"Carl\"></option>" 778 " <option value=\"Carl\"></option>"
747 " </datalist>" 779 " </datalist>"
748 "</form>"))); 780 "</form>")));
749 std::string orginalcolor; 781 std::string orginalcolor;
750 GetFieldBackgroundColor("firstname", &orginalcolor); 782 GetFieldBackgroundColor("firstname", &orginalcolor);
751 783
752 FocusFirstNameField(); 784 FocusFirstNameField();
753 SendKeyToPageAndWait(ui::VKEY_DOWN); 785 SendKeyToPageAndWait(ui::DomKey::ARROW_DOWN);
754 SendKeyToDataListPopup(ui::VKEY_DOWN); 786 SendKeyToDataListPopup(ui::DomKey::ARROW_DOWN);
755 SendKeyToDataListPopup(ui::VKEY_RETURN); 787 SendKeyToDataListPopup(ui::DomKey::ENTER);
756 ExpectFieldValue("firstname", "Adam"); 788 ExpectFieldValue("firstname", "Adam");
757 std::string color; 789 std::string color;
758 GetFieldBackgroundColor("firstname", &color); 790 GetFieldBackgroundColor("firstname", &color);
759 EXPECT_EQ(color, orginalcolor); 791 EXPECT_EQ(color, orginalcolor);
760 } 792 }
761 793
762 // Test that a JavaScript oninput event is fired after auto-filling a form. 794 // Test that a JavaScript oninput event is fired after auto-filling a form.
763 // Flakily times out on ChromeOS http://crbug.com/585885 795 // Flakily times out on ChromeOS http://crbug.com/585885
764 #if defined(OS_CHROMEOS) 796 #if defined(OS_CHROMEOS)
765 #define MAYBE_OnInputAfterAutofill DISABLED_OnInputAfterAutofill 797 #define MAYBE_OnInputAfterAutofill DISABLED_OnInputAfterAutofill
(...skipping 26 matching lines...) Expand all
792 824
793 // Load the test page. 825 // Load the test page.
794 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 826 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
795 GURL(std::string(kDataURIPrefix) + kTestFormString + kOnInputScript))); 827 GURL(std::string(kDataURIPrefix) + kTestFormString + kOnInputScript)));
796 828
797 // Invoke Autofill. 829 // Invoke Autofill.
798 FocusFirstNameField(); 830 FocusFirstNameField();
799 831
800 // Start filling the first name field with "M" and wait for the popup to be 832 // Start filling the first name field with "M" and wait for the popup to be
801 // shown. 833 // shown.
802 SendKeyToPageAndWait(ui::VKEY_M); 834 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
835 ui::VKEY_M);
803 836
804 // Press the down arrow to select the suggestion and preview the autofilled 837 // Press the down arrow to select the suggestion and preview the autofilled
805 // form. 838 // form.
806 SendKeyToPopupAndWait(ui::VKEY_DOWN); 839 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
807 840
808 // Press Enter to accept the autofill suggestions. 841 // Press Enter to accept the autofill suggestions.
809 SendKeyToPopupAndWait(ui::VKEY_RETURN); 842 SendKeyToPopupAndWait(ui::DomKey::ENTER);
810 843
811 // The form should be filled. 844 // The form should be filled.
812 ExpectFilledTestForm(); 845 ExpectFilledTestForm();
813 846
814 bool focused_fired = false; 847 bool focused_fired = false;
815 bool unfocused_fired = false; 848 bool unfocused_fired = false;
816 bool changed_select_fired = false; 849 bool changed_select_fired = false;
817 bool unchanged_select_fired = false; 850 bool unchanged_select_fired = false;
818 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 851 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
819 GetRenderViewHost(), 852 GetRenderViewHost(),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 903
871 // Load the test page. 904 // Load the test page.
872 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 905 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
873 GURL(std::string(kDataURIPrefix) + kTestFormString + kOnChangeScript))); 906 GURL(std::string(kDataURIPrefix) + kTestFormString + kOnChangeScript)));
874 907
875 // Invoke Autofill. 908 // Invoke Autofill.
876 FocusFirstNameField(); 909 FocusFirstNameField();
877 910
878 // Start filling the first name field with "M" and wait for the popup to be 911 // Start filling the first name field with "M" and wait for the popup to be
879 // shown. 912 // shown.
880 SendKeyToPageAndWait(ui::VKEY_M); 913 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
914 ui::VKEY_M);
881 915
882 // Press the down arrow to select the suggestion and preview the autofilled 916 // Press the down arrow to select the suggestion and preview the autofilled
883 // form. 917 // form.
884 SendKeyToPopupAndWait(ui::VKEY_DOWN); 918 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
885 919
886 // Press Enter to accept the autofill suggestions. 920 // Press Enter to accept the autofill suggestions.
887 SendKeyToPopupAndWait(ui::VKEY_RETURN); 921 SendKeyToPopupAndWait(ui::DomKey::ENTER);
888 922
889 // The form should be filled. 923 // The form should be filled.
890 ExpectFilledTestForm(); 924 ExpectFilledTestForm();
891 925
892 bool focused_fired = false; 926 bool focused_fired = false;
893 bool unfocused_fired = false; 927 bool unfocused_fired = false;
894 bool changed_select_fired = false; 928 bool changed_select_fired = false;
895 bool unchanged_select_fired = false; 929 bool unchanged_select_fired = false;
896 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 930 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
897 GetRenderViewHost(), 931 GetRenderViewHost(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 "document.getElementById('country').onchange = recordSelectElementEvent;" 976 "document.getElementById('country').onchange = recordSelectElementEvent;"
943 "</script>"; 977 "</script>";
944 978
945 // Load the test page. 979 // Load the test page.
946 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 980 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
947 GURL(std::string(kDataURIPrefix) + kTestFormString + 981 GURL(std::string(kDataURIPrefix) + kTestFormString +
948 kInputFiresBeforeChangeScript))); 982 kInputFiresBeforeChangeScript)));
949 983
950 // Invoke and accept the Autofill popup and verify the form was filled. 984 // Invoke and accept the Autofill popup and verify the form was filled.
951 FocusFirstNameField(); 985 FocusFirstNameField();
952 SendKeyToPageAndWait(ui::VKEY_M); 986 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
953 SendKeyToPopupAndWait(ui::VKEY_DOWN); 987 ui::VKEY_M);
954 SendKeyToPopupAndWait(ui::VKEY_RETURN); 988 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
989 SendKeyToPopupAndWait(ui::DomKey::ENTER);
955 ExpectFilledTestForm(); 990 ExpectFilledTestForm();
956 991
957 int num_input_element_events = -1; 992 int num_input_element_events = -1;
958 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( 993 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
959 GetRenderViewHost(), 994 GetRenderViewHost(),
960 "domAutomationController.send(inputElementEvents.length);", 995 "domAutomationController.send(inputElementEvents.length);",
961 &num_input_element_events)); 996 &num_input_element_events));
962 EXPECT_EQ(2, num_input_element_events); 997 EXPECT_EQ(2, num_input_element_events);
963 998
964 std::vector<std::string> input_element_events; 999 std::vector<std::string> input_element_events;
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 MAYBE_DisableAutocompleteWhileFilling) { 1688 MAYBE_DisableAutocompleteWhileFilling) {
1654 CreateTestProfile(); 1689 CreateTestProfile();
1655 1690
1656 // Load the test page. 1691 // Load the test page.
1657 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 1692 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
1658 GURL(std::string(kDataURIPrefix) + kTestFormString))); 1693 GURL(std::string(kDataURIPrefix) + kTestFormString)));
1659 1694
1660 // Invoke Autofill: Start filling the first name field with "M" and wait for 1695 // Invoke Autofill: Start filling the first name field with "M" and wait for
1661 // the popup to be shown. 1696 // the popup to be shown.
1662 FocusFirstNameField(); 1697 FocusFirstNameField();
1663 SendKeyToPageAndWait(ui::VKEY_M); 1698 SendKeyToPageAndWait(ui::DomKey::FromCharacter('M'), ui::DomCode::US_M,
1699 ui::VKEY_M);
1664 1700
1665 // Now that the popup with suggestions is showing, disable autocomplete for 1701 // Now that the popup with suggestions is showing, disable autocomplete for
1666 // the active field. 1702 // the active field.
1667 ASSERT_TRUE(content::ExecuteScript( 1703 ASSERT_TRUE(content::ExecuteScript(
1668 GetRenderViewHost(), 1704 GetRenderViewHost(),
1669 "document.querySelector('input').autocomplete = 'off';")); 1705 "document.querySelector('input').autocomplete = 'off';"));
1670 1706
1671 // Press the down arrow to select the suggestion and attempt to preview the 1707 // Press the down arrow to select the suggestion and attempt to preview the
1672 // autofilled form. 1708 // autofilled form.
1673 SendKeyToPopupAndWait(ui::VKEY_DOWN); 1709 SendKeyToPopupAndWait(ui::DomKey::ARROW_DOWN);
1674 } 1710 }
1675 1711
1676 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, 1712 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
1677 PastedPasswordIsSaved) { 1713 PastedPasswordIsSaved) {
1678 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), 1714 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
1679 GURL(std::string(kDataURIPrefix) + kTestPasswordFormString))); 1715 GURL(std::string(kDataURIPrefix) + kTestPasswordFormString)));
1680 ASSERT_TRUE(content::ExecuteScript( 1716 ASSERT_TRUE(content::ExecuteScript(
1681 GetRenderViewHost(), 1717 GetRenderViewHost(),
1682 "document.getElementById('user').value = 'user';")); 1718 "document.getElementById('user').value = 'user';"));
1683 FocusFieldByName("password"); 1719 FocusFieldByName("password");
1684 PasteStringAndWait("foobar"); 1720 PasteStringAndWait("foobar");
1685 } 1721 }
1686 1722
1687 } // namespace autofill 1723 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698