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
3 // found in the LICENSE file.
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/files/file_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/rand_util.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h"
18 #include "chrome/browser/autofill/autofill_uitest_util.h"
19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/infobars/infobar_service.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/translate/chrome_translate_client.h"
23 #include "chrome/browser/translate/translate_service.h"
24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/render_messages.h"
27 #include "chrome/test/base/in_process_browser_test.h"
28 #include "chrome/test/base/interactive_test_utils.h"
29 #include "chrome/test/base/test_switches.h"
30 #include "chrome/test/base/ui_test_utils.h"
31 #include "components/autofill/content/browser/content_autofill_driver.h"
32 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
33 #include "components/autofill/core/browser/autofill_manager.h"
34 #include "components/autofill/core/browser/autofill_manager_test_delegate.h"
35 #include "components/autofill/core/browser/autofill_profile.h"
36 #include "components/autofill/core/browser/autofill_test_utils.h"
37 #include "components/autofill/core/browser/validation.h"
38 #include "components/infobars/core/infobar.h"
39 #include "components/translate/core/browser/translate_infobar_delegate.h"
40 #include "content/public/browser/navigation_controller.h"
41 #include "content/public/browser/notification_observer.h"
42 #include "content/public/browser/notification_registrar.h"
43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/render_view_host.h"
45 #include "content/public/browser/render_widget_host.h"
46 #include "content/public/browser/web_contents.h"
47 #include "content/public/test/browser_test_utils.h"
48 #include "content/public/test/test_renderer_host.h"
49 #include "net/url_request/test_url_fetcher_factory.h"
50 #include "testing/gmock/include/gmock/gmock.h"
51 #include "testing/gtest/include/gtest/gtest.h"
52 #include "ui/events/keycodes/keyboard_codes.h"
54 using base::ASCIIToUTF16
;
58 static const char kDataURIPrefix
[] = "data:text/html;charset=utf-8,";
59 static const char kTestFormString
[] =
60 "<form action=\"http://www.example.com/\" method=\"POST\">"
61 "<label for=\"firstname\">First name:</label>"
62 " <input type=\"text\" id=\"firstname\""
63 " onfocus=\"domAutomationController.send(true)\"><br>"
64 "<label for=\"lastname\">Last name:</label>"
65 " <input type=\"text\" id=\"lastname\"><br>"
66 "<label for=\"address1\">Address line 1:</label>"
67 " <input type=\"text\" id=\"address1\"><br>"
68 "<label for=\"address2\">Address line 2:</label>"
69 " <input type=\"text\" id=\"address2\"><br>"
70 "<label for=\"city\">City:</label>"
71 " <input type=\"text\" id=\"city\"><br>"
72 "<label for=\"state\">State:</label>"
73 " <select id=\"state\">"
74 " <option value=\"\" selected=\"yes\">--</option>"
75 " <option value=\"CA\">California</option>"
76 " <option value=\"TX\">Texas</option>"
78 "<label for=\"zip\">ZIP code:</label>"
79 " <input type=\"text\" id=\"zip\"><br>"
80 "<label for=\"country\">Country:</label>"
81 " <select id=\"country\">"
82 " <option value=\"\" selected=\"yes\">--</option>"
83 " <option value=\"CA\">Canada</option>"
84 " <option value=\"US\">United States</option>"
86 "<label for=\"phone\">Phone number:</label>"
87 " <input type=\"text\" id=\"phone\"><br>"
91 // AutofillManagerTestDelegateImpl --------------------------------------------
93 class AutofillManagerTestDelegateImpl
94 : public autofill::AutofillManagerTestDelegate
{
96 AutofillManagerTestDelegateImpl() {}
97 ~AutofillManagerTestDelegateImpl() override
{}
99 // autofill::AutofillManagerTestDelegate:
100 void DidPreviewFormData() override
{
101 ASSERT_TRUE(loop_runner_
->loop_running());
102 loop_runner_
->Quit();
105 void DidFillFormData() override
{
106 ASSERT_TRUE(loop_runner_
->loop_running());
107 loop_runner_
->Quit();
110 void DidShowSuggestions() override
{
111 ASSERT_TRUE(loop_runner_
->loop_running());
112 loop_runner_
->Quit();
116 loop_runner_
= new content::MessageLoopRunner();
124 scoped_refptr
<content::MessageLoopRunner
> loop_runner_
;
126 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTestDelegateImpl
);
129 // AutofillInteractiveTest ----------------------------------------------------
131 class AutofillInteractiveTest
: public InProcessBrowserTest
{
133 AutofillInteractiveTest() :
134 key_press_event_sink_(
135 base::Bind(&AutofillInteractiveTest::HandleKeyPressEvent
,
136 base::Unretained(this))) {}
137 ~AutofillInteractiveTest() override
{}
139 // InProcessBrowserTest:
140 void SetUpOnMainThread() override
{
141 // Don't want Keychain coming up on Mac.
142 test::DisableSystemServices(browser()->profile()->GetPrefs());
144 // Inject the test delegate into the AutofillManager.
145 content::WebContents
* web_contents
= GetWebContents();
146 ContentAutofillDriver
* autofill_driver
=
147 ContentAutofillDriverFactory::FromWebContents(web_contents
)
148 ->DriverForFrame(web_contents
->GetMainFrame());
149 AutofillManager
* autofill_manager
= autofill_driver
->autofill_manager();
150 autofill_manager
->SetTestDelegate(&test_delegate_
);
152 // If the mouse happened to be over where the suggestions are shown, then
153 // the preview will show up and will fail the tests. We need to give it a
154 // point that's within the browser frame, or else the method hangs.
155 gfx::Point
reset_mouse(GetWebContents()->GetContainerBounds().origin());
156 reset_mouse
= gfx::Point(reset_mouse
.x() + 5, reset_mouse
.y() + 5);
157 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(reset_mouse
));
160 void TearDownOnMainThread() override
{
161 // Make sure to close any showing popups prior to tearing down the UI.
162 content::WebContents
* web_contents
= GetWebContents();
163 AutofillManager
* autofill_manager
=
164 ContentAutofillDriverFactory::FromWebContents(web_contents
)
165 ->DriverForFrame(web_contents
->GetMainFrame())
166 ->autofill_manager();
167 autofill_manager
->client()->HideAutofillPopup();
170 content::WebContents
* GetWebContents() {
171 return browser()->tab_strip_model()->GetActiveWebContents();
174 content::RenderViewHost
* GetRenderViewHost() {
175 return GetWebContents()->GetRenderViewHost();
178 void CreateTestProfile() {
179 AutofillProfile profile
;
180 test::SetProfileInfo(
181 &profile
, "Milton", "C.", "Waddams",
182 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane",
183 "Basement", "Austin", "Texas", "78744", "US", "5125551234");
185 AddTestProfile(browser(), profile
);
188 // Populates a webpage form using autofill data and keypress events.
189 // This function focuses the specified input field in the form, and then
190 // sends keypress events to the tab to cause the form to be populated.
191 void PopulateForm(const std::string
& field_id
) {
192 std::string
js("document.getElementById('" + field_id
+ "').focus();");
193 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), js
));
195 SendKeyToPageAndWait(ui::VKEY_DOWN
);
196 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
197 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
200 void ExpectFieldValue(const std::string
& field_name
,
201 const std::string
& expected_value
) {
203 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
205 "window.domAutomationController.send("
206 " document.getElementById('" + field_name
+ "').value);",
208 EXPECT_EQ(expected_value
, value
);
211 void GetFieldBackgroundColor(const std::string
& field_name
,
212 std::string
* color
) {
213 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
215 "window.domAutomationController.send("
216 " document.defaultView.getComputedStyle(document.getElementById('" +
217 field_name
+ "')).backgroundColor);",
221 void SimulateURLFetch(bool success
) {
222 net::TestURLFetcher
* fetcher
= url_fetcher_factory_
.GetFetcherByID(0);
223 ASSERT_TRUE(fetcher
);
224 net::URLRequestStatus status
;
225 status
.set_status(success
? net::URLRequestStatus::SUCCESS
:
226 net::URLRequestStatus::FAILED
);
228 std::string script
= " var google = {};"
229 "google.translate = (function() {"
231 " TranslateService: function() {"
233 " isAvailable : function() {"
236 " restore : function() {"
239 " getDetectedLanguage : function() {"
242 " translatePage : function(originalLang, targetLang,"
243 " onTranslateProgress) {"
244 " document.getElementsByTagName(\"body\")[0].innerHTML = '" +
245 std::string(kTestFormString
) +
247 " onTranslateProgress(100, true, false);"
253 "cr.googleTranslate.onTranslateElementLoad();";
255 fetcher
->set_url(fetcher
->GetOriginalURL());
256 fetcher
->set_status(status
);
257 fetcher
->set_response_code(success
? 200 : 500);
258 fetcher
->SetResponseString(script
);
259 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
262 void FocusFirstNameField() {
264 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
266 "if (document.readyState === 'complete')"
267 " document.getElementById('firstname').focus();"
269 " domAutomationController.send(false);",
274 // Simulates a click on the middle of the DOM element with the given |id|.
275 void ClickElementWithId(const std::string
& id
) {
277 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
279 "var bounds = document.getElementById('" +
281 "').getBoundingClientRect();"
282 "domAutomationController.send("
283 " Math.floor(bounds.left + bounds.width / 2));",
286 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
288 "var bounds = document.getElementById('" +
290 "').getBoundingClientRect();"
291 "domAutomationController.send("
292 " Math.floor(bounds.top + bounds.height / 2));",
294 content::SimulateMouseClickAt(GetWebContents(),
296 blink::WebMouseEvent::ButtonLeft
,
300 void ClickFirstNameField() {
301 ASSERT_NO_FATAL_FAILURE(ClickElementWithId("firstname"));
304 // Make a pointless round trip to the renderer, giving the popup a chance to
305 // show if it's going to. If it does show, an assert in
306 // AutofillManagerTestDelegateImpl will trigger.
307 void MakeSurePopupDoesntAppear() {
309 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
310 GetRenderViewHost(), "domAutomationController.send(42)", &unused
));
313 void ExpectFilledTestForm() {
314 ExpectFieldValue("firstname", "Milton");
315 ExpectFieldValue("lastname", "Waddams");
316 ExpectFieldValue("address1", "4120 Freidrich Lane");
317 ExpectFieldValue("address2", "Basement");
318 ExpectFieldValue("city", "Austin");
319 ExpectFieldValue("state", "TX");
320 ExpectFieldValue("zip", "78744");
321 ExpectFieldValue("country", "US");
322 ExpectFieldValue("phone", "5125551234");
325 void SendKeyToPageAndWait(ui::KeyboardCode key
) {
326 test_delegate_
.Reset();
327 content::SimulateKeyPress(
328 GetWebContents(), key
, false, false, false, false);
329 test_delegate_
.Wait();
332 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent
& event
) {
336 void SendKeyToPopupAndWait(ui::KeyboardCode key
) {
337 // Route popup-targeted key presses via the render view host.
338 content::NativeWebKeyboardEvent event
;
339 event
.windowsKeyCode
= key
;
340 event
.type
= blink::WebKeyboardEvent::RawKeyDown
;
341 test_delegate_
.Reset();
342 // Install the key press event sink to ensure that any events that are not
343 // handled by the installed callbacks do not end up crashing the test.
344 GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_
);
345 GetRenderViewHost()->ForwardKeyboardEvent(event
);
346 test_delegate_
.Wait();
347 GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_
);
350 // Datalist does not support autofill preview. There is no need to start
351 // message loop for Datalist.
352 void SendKeyToDataListPopup(ui::KeyboardCode key
) {
353 // Route popup-targeted key presses via the render view host.
354 content::NativeWebKeyboardEvent event
;
355 event
.windowsKeyCode
= key
;
356 event
.type
= blink::WebKeyboardEvent::RawKeyDown
;
357 // Install the key press event sink to ensure that any events that are not
358 // handled by the installed callbacks do not end up crashing the test.
359 GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_
);
360 GetRenderViewHost()->ForwardKeyboardEvent(event
);
361 GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_
);
364 void TryBasicFormFill() {
365 FocusFirstNameField();
367 // Start filling the first name field with "M" and wait for the popup to be
369 SendKeyToPageAndWait(ui::VKEY_M
);
371 // Press the down arrow to select the suggestion and preview the autofilled
373 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
375 // The previewed values should not be accessible to JavaScript.
376 ExpectFieldValue("firstname", "M");
377 ExpectFieldValue("lastname", std::string());
378 ExpectFieldValue("address1", std::string());
379 ExpectFieldValue("address2", std::string());
380 ExpectFieldValue("city", std::string());
381 ExpectFieldValue("state", std::string());
382 ExpectFieldValue("zip", std::string());
383 ExpectFieldValue("country", std::string());
384 ExpectFieldValue("phone", std::string());
385 // TODO(isherman): It would be nice to test that the previewed values are
386 // displayed: http://crbug.com/57220
388 // Press Enter to accept the autofill suggestions.
389 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
391 // The form should be filled.
392 ExpectFilledTestForm();
395 AutofillManagerTestDelegateImpl
* test_delegate() { return &test_delegate_
; }
398 AutofillManagerTestDelegateImpl test_delegate_
;
400 net::TestURLFetcherFactory url_fetcher_factory_
;
402 // KeyPressEventCallback that serves as a sink to ensure that every key press
403 // event the tests create and have the WebContents forward is handled by some
404 // key press event callback. It is necessary to have this sinkbecause if no
405 // key press event callback handles the event (at least on Mac), a DCHECK
406 // ends up going off that the |event| doesn't have an |os_event| associated
408 content::RenderWidgetHost::KeyPressEventCallback key_press_event_sink_
;
410 DISALLOW_COPY_AND_ASSIGN(AutofillInteractiveTest
);
413 // Test that basic form fill is working.
414 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, BasicFormFill
) {
417 // Load the test page.
418 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
419 GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
425 // Test that form filling can be initiated by pressing the down arrow.
426 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, AutofillViaDownArrow
) {
429 // Load the test page.
430 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
431 GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
433 // Focus a fillable field.
434 FocusFirstNameField();
436 // Press the down arrow to initiate Autofill and wait for the popup to be
438 SendKeyToPageAndWait(ui::VKEY_DOWN
);
440 // Press the down arrow to select the suggestion and preview the autofilled
442 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
444 // Press Enter to accept the autofill suggestions.
445 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
447 // The form should be filled.
448 ExpectFilledTestForm();
451 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, AutofillSelectViaTab
) {
454 // Load the test page.
455 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
456 GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
458 // Focus a fillable field.
459 FocusFirstNameField();
461 // Press the down arrow to initiate Autofill and wait for the popup to be
463 SendKeyToPageAndWait(ui::VKEY_DOWN
);
465 // Press the down arrow to select the suggestion and preview the autofilled
467 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
469 // Press tab to accept the autofill suggestions.
470 SendKeyToPopupAndWait(ui::VKEY_TAB
);
472 // The form should be filled.
473 ExpectFilledTestForm();
476 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, AutofillViaClick
) {
479 // Load the test page.
480 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
481 browser(), GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
482 // Focus a fillable field.
483 ASSERT_NO_FATAL_FAILURE(FocusFirstNameField());
486 test_delegate()->Reset();
487 ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
488 test_delegate()->Wait();
490 // Press the down arrow to select the suggestion and preview the autofilled
492 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
494 // Press Enter to accept the autofill suggestions.
495 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
497 // The form should be filled.
498 ExpectFilledTestForm();
501 // Makes sure that the first click does *not* activate the popup.
502 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, DontAutofillForFirstClick
) {
505 // Load the test page.
506 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
507 browser(), GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
509 // Click the first name field while it's out of focus, then twiddle our thumbs
510 // a bit. If a popup were to show, it would hit the asserts in
511 // AutofillManagerTestDelegateImpl while we're wasting time.
512 ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
513 ASSERT_NO_FATAL_FAILURE(MakeSurePopupDoesntAppear());
515 // The second click should activate the popup since the first click focused
517 test_delegate()->Reset();
518 ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
519 test_delegate()->Wait();
522 // Makes sure that clicking outside the focused field doesn't activate
524 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, DontAutofillForOutsideClick
) {
527 // Load the test page.
528 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
530 GURL(std::string(kDataURIPrefix
) + kTestFormString
+
531 "<button disabled id='disabled-button'>Cant click this</button>")));
533 ASSERT_NO_FATAL_FAILURE(FocusFirstNameField());
535 // Clicking a disabled button will generate a mouse event but focus doesn't
536 // change. This tests that autofill can handle a mouse event outside a focused
537 // input *without* showing the popup.
538 ASSERT_NO_FATAL_FAILURE(ClickElementWithId("disabled-button"));
539 ASSERT_NO_FATAL_FAILURE(MakeSurePopupDoesntAppear());
541 test_delegate()->Reset();
542 ASSERT_NO_FATAL_FAILURE(ClickFirstNameField());
543 test_delegate()->Wait();
546 // Test that a field is still autofillable after the previously autofilled
548 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, OnDeleteValueAfterAutofill
) {
551 // Load the test page.
552 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
553 GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
555 // Invoke and accept the Autofill popup and verify the form was filled.
556 FocusFirstNameField();
557 SendKeyToPageAndWait(ui::VKEY_M
);
558 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
559 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
560 ExpectFilledTestForm();
562 // Delete the value of a filled field.
563 ASSERT_TRUE(content::ExecuteScript(
565 "document.getElementById('firstname').value = '';"));
566 ExpectFieldValue("firstname", "");
568 // Invoke and accept the Autofill popup and verify the field was filled.
569 SendKeyToPageAndWait(ui::VKEY_M
);
570 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
571 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
572 ExpectFieldValue("firstname", "Milton");
575 // Test that an input field is not rendered with the yellow autofilled
576 // background color when choosing an option from the datalist suggestion list.
577 #if defined(OS_MACOSX)
578 // Flakily triggers and assert on Mac.
579 // http://crbug.com/419868
580 #define MAYBE_OnSelectOptionFromDatalist DISABLED_OnSelectOptionFromDatalist
582 #define MAYBE_OnSelectOptionFromDatalist OnSelectOptionFromDatalist
584 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
585 MAYBE_OnSelectOptionFromDatalist
) {
586 // Load the test page.
587 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(
589 GURL(std::string(kDataURIPrefix
) +
590 "<form action=\"http://www.example.com/\" method=\"POST\">"
591 " <input list=\"dl\" type=\"search\" id=\"firstname\""
592 " onfocus=\"domAutomationController.send(true)\"><br>"
593 " <datalist id=\"dl\">"
594 " <option value=\"Adam\"></option>"
595 " <option value=\"Bob\"></option>"
596 " <option value=\"Carl\"></option>"
599 std::string orginalcolor
;
600 GetFieldBackgroundColor("firstname", &orginalcolor
);
602 FocusFirstNameField();
603 SendKeyToPageAndWait(ui::VKEY_DOWN
);
604 SendKeyToDataListPopup(ui::VKEY_DOWN
);
605 SendKeyToDataListPopup(ui::VKEY_RETURN
);
606 ExpectFieldValue("firstname", "Adam");
608 GetFieldBackgroundColor("firstname", &color
);
609 EXPECT_EQ(color
, orginalcolor
);
612 // Test that a JavaScript oninput event is fired after auto-filling a form.
613 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, OnInputAfterAutofill
) {
616 const char kOnInputScript
[] =
618 "focused_fired = false;"
619 "unfocused_fired = false;"
620 "changed_select_fired = false;"
621 "unchanged_select_fired = false;"
622 "document.getElementById('firstname').oninput = function() {"
623 " focused_fired = true;"
625 "document.getElementById('lastname').oninput = function() {"
626 " unfocused_fired = true;"
628 "document.getElementById('state').oninput = function() {"
629 " changed_select_fired = true;"
631 "document.getElementById('country').oninput = function() {"
632 " unchanged_select_fired = true;"
634 "document.getElementById('country').value = 'US';"
637 // Load the test page.
638 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
639 GURL(std::string(kDataURIPrefix
) + kTestFormString
+ kOnInputScript
)));
642 FocusFirstNameField();
644 // Start filling the first name field with "M" and wait for the popup to be
646 SendKeyToPageAndWait(ui::VKEY_M
);
648 // Press the down arrow to select the suggestion and preview the autofilled
650 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
652 // Press Enter to accept the autofill suggestions.
653 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
655 // The form should be filled.
656 ExpectFilledTestForm();
658 bool focused_fired
= false;
659 bool unfocused_fired
= false;
660 bool changed_select_fired
= false;
661 bool unchanged_select_fired
= false;
662 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
664 "domAutomationController.send(focused_fired);",
666 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
668 "domAutomationController.send(unfocused_fired);",
670 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
672 "domAutomationController.send(changed_select_fired);",
673 &changed_select_fired
));
674 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
676 "domAutomationController.send(unchanged_select_fired);",
677 &unchanged_select_fired
));
678 EXPECT_TRUE(focused_fired
);
679 EXPECT_TRUE(unfocused_fired
);
680 EXPECT_TRUE(changed_select_fired
);
681 EXPECT_FALSE(unchanged_select_fired
);
684 // Test that a JavaScript onchange event is fired after auto-filling a form.
685 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, OnChangeAfterAutofill
) {
688 const char kOnChangeScript
[] =
690 "focused_fired = false;"
691 "unfocused_fired = false;"
692 "changed_select_fired = false;"
693 "unchanged_select_fired = false;"
694 "document.getElementById('firstname').onchange = function() {"
695 " focused_fired = true;"
697 "document.getElementById('lastname').onchange = function() {"
698 " unfocused_fired = true;"
700 "document.getElementById('state').onchange = function() {"
701 " changed_select_fired = true;"
703 "document.getElementById('country').onchange = function() {"
704 " unchanged_select_fired = true;"
706 "document.getElementById('country').value = 'US';"
709 // Load the test page.
710 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
711 GURL(std::string(kDataURIPrefix
) + kTestFormString
+ kOnChangeScript
)));
714 FocusFirstNameField();
716 // Start filling the first name field with "M" and wait for the popup to be
718 SendKeyToPageAndWait(ui::VKEY_M
);
720 // Press the down arrow to select the suggestion and preview the autofilled
722 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
724 // Press Enter to accept the autofill suggestions.
725 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
727 // The form should be filled.
728 ExpectFilledTestForm();
730 bool focused_fired
= false;
731 bool unfocused_fired
= false;
732 bool changed_select_fired
= false;
733 bool unchanged_select_fired
= false;
734 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
736 "domAutomationController.send(focused_fired);",
738 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
740 "domAutomationController.send(unfocused_fired);",
742 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
744 "domAutomationController.send(changed_select_fired);",
745 &changed_select_fired
));
746 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
748 "domAutomationController.send(unchanged_select_fired);",
749 &unchanged_select_fired
));
750 EXPECT_TRUE(focused_fired
);
751 EXPECT_TRUE(unfocused_fired
);
752 EXPECT_TRUE(changed_select_fired
);
753 EXPECT_FALSE(unchanged_select_fired
);
756 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, InputFiresBeforeChange
) {
759 const char kInputFiresBeforeChangeScript
[] =
761 "inputElementEvents = [];"
762 "function recordInputElementEvent(e) {"
763 " if (e.target.tagName != 'INPUT') throw 'only <input> tags allowed';"
764 " inputElementEvents.push(e.type);"
766 "selectElementEvents = [];"
767 "function recordSelectElementEvent(e) {"
768 " if (e.target.tagName != 'SELECT') throw 'only <select> tags allowed';"
769 " selectElementEvents.push(e.type);"
771 "document.getElementById('lastname').oninput = recordInputElementEvent;"
772 "document.getElementById('lastname').onchange = recordInputElementEvent;"
773 "document.getElementById('country').oninput = recordSelectElementEvent;"
774 "document.getElementById('country').onchange = recordSelectElementEvent;"
777 // Load the test page.
778 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
779 GURL(std::string(kDataURIPrefix
) + kTestFormString
+
780 kInputFiresBeforeChangeScript
)));
782 // Invoke and accept the Autofill popup and verify the form was filled.
783 FocusFirstNameField();
784 SendKeyToPageAndWait(ui::VKEY_M
);
785 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
786 SendKeyToPopupAndWait(ui::VKEY_RETURN
);
787 ExpectFilledTestForm();
789 int num_input_element_events
= -1;
790 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
792 "domAutomationController.send(inputElementEvents.length);",
793 &num_input_element_events
));
794 EXPECT_EQ(2, num_input_element_events
);
796 std::vector
<std::string
> input_element_events
;
797 input_element_events
.resize(2);
799 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
801 "domAutomationController.send(inputElementEvents[0]);",
802 &input_element_events
[0]));
803 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
805 "domAutomationController.send(inputElementEvents[1]);",
806 &input_element_events
[1]));
808 EXPECT_EQ("input", input_element_events
[0]);
809 EXPECT_EQ("change", input_element_events
[1]);
811 int num_select_element_events
= -1;
812 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
814 "domAutomationController.send(selectElementEvents.length);",
815 &num_select_element_events
));
816 EXPECT_EQ(2, num_select_element_events
);
818 std::vector
<std::string
> select_element_events
;
819 select_element_events
.resize(2);
821 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
823 "domAutomationController.send(selectElementEvents[0]);",
824 &select_element_events
[0]));
825 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
827 "domAutomationController.send(selectElementEvents[1]);",
828 &select_element_events
[1]));
830 EXPECT_EQ("input", select_element_events
[0]);
831 EXPECT_EQ("change", select_element_events
[1]);
834 // Test that we can autofill forms distinguished only by their |id| attribute.
835 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
836 AutofillFormsDistinguishedById
) {
839 // Load the test page.
840 const std::string kURL
=
841 std::string(kDataURIPrefix
) + kTestFormString
+
843 "var mainForm = document.forms[0];"
844 "mainForm.id = 'mainForm';"
845 "var newForm = document.createElement('form');"
846 "newForm.action = mainForm.action;"
847 "newForm.method = mainForm.method;"
848 "newForm.id = 'newForm';"
849 "mainForm.parentNode.insertBefore(newForm, mainForm);"
851 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), GURL(kURL
)));
857 // Test that we properly autofill forms with repeated fields.
858 // In the wild, the repeated fields are typically either email fields
859 // (duplicated for "confirmation"); or variants that are hot-swapped via
860 // JavaScript, with only one actually visible at any given time.
861 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, AutofillFormWithRepeatedField
) {
864 // Load the test page.
865 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
866 GURL(std::string(kDataURIPrefix
) +
867 "<form action=\"http://www.example.com/\" method=\"POST\">"
868 "<label for=\"firstname\">First name:</label>"
869 " <input type=\"text\" id=\"firstname\""
870 " onfocus=\"domAutomationController.send(true)\"><br>"
871 "<label for=\"lastname\">Last name:</label>"
872 " <input type=\"text\" id=\"lastname\"><br>"
873 "<label for=\"address1\">Address line 1:</label>"
874 " <input type=\"text\" id=\"address1\"><br>"
875 "<label for=\"address2\">Address line 2:</label>"
876 " <input type=\"text\" id=\"address2\"><br>"
877 "<label for=\"city\">City:</label>"
878 " <input type=\"text\" id=\"city\"><br>"
879 "<label for=\"state\">State:</label>"
880 " <select id=\"state\">"
881 " <option value=\"\" selected=\"yes\">--</option>"
882 " <option value=\"CA\">California</option>"
883 " <option value=\"TX\">Texas</option>"
885 "<label for=\"state_freeform\" style=\"display:none\">State:</label>"
886 " <input type=\"text\" id=\"state_freeform\""
887 " style=\"display:none\"><br>"
888 "<label for=\"zip\">ZIP code:</label>"
889 " <input type=\"text\" id=\"zip\"><br>"
890 "<label for=\"country\">Country:</label>"
891 " <select id=\"country\">"
892 " <option value=\"\" selected=\"yes\">--</option>"
893 " <option value=\"CA\">Canada</option>"
894 " <option value=\"US\">United States</option>"
896 "<label for=\"phone\">Phone number:</label>"
897 " <input type=\"text\" id=\"phone\"><br>"
902 ExpectFieldValue("state_freeform", std::string());
905 // Test that we properly autofill forms with non-autofillable fields.
906 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
907 AutofillFormWithNonAutofillableField
) {
910 // Load the test page.
911 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
912 GURL(std::string(kDataURIPrefix
) +
913 "<form action=\"http://www.example.com/\" method=\"POST\">"
914 "<label for=\"firstname\">First name:</label>"
915 " <input type=\"text\" id=\"firstname\""
916 " onfocus=\"domAutomationController.send(true)\"><br>"
917 "<label for=\"middlename\">Middle name:</label>"
918 " <input type=\"text\" id=\"middlename\" autocomplete=\"off\" /><br>"
919 "<label for=\"lastname\">Last name:</label>"
920 " <input type=\"text\" id=\"lastname\"><br>"
921 "<label for=\"address1\">Address line 1:</label>"
922 " <input type=\"text\" id=\"address1\"><br>"
923 "<label for=\"address2\">Address line 2:</label>"
924 " <input type=\"text\" id=\"address2\"><br>"
925 "<label for=\"city\">City:</label>"
926 " <input type=\"text\" id=\"city\"><br>"
927 "<label for=\"state\">State:</label>"
928 " <select id=\"state\">"
929 " <option value=\"\" selected=\"yes\">--</option>"
930 " <option value=\"CA\">California</option>"
931 " <option value=\"TX\">Texas</option>"
933 "<label for=\"zip\">ZIP code:</label>"
934 " <input type=\"text\" id=\"zip\"><br>"
935 "<label for=\"country\">Country:</label>"
936 " <select id=\"country\">"
937 " <option value=\"\" selected=\"yes\">--</option>"
938 " <option value=\"CA\">Canada</option>"
939 " <option value=\"US\">United States</option>"
941 "<label for=\"phone\">Phone number:</label>"
942 " <input type=\"text\" id=\"phone\"><br>"
949 // Test that we can Autofill dynamically generated forms.
950 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, DynamicFormFill
) {
953 // Load the test page.
954 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
955 GURL(std::string(kDataURIPrefix
) +
956 "<form id=\"form\" action=\"http://www.example.com/\""
957 " method=\"POST\"></form>"
959 "function AddElement(name, label) {"
960 " var form = document.getElementById('form');"
962 " var label_text = document.createTextNode(label);"
963 " var label_element = document.createElement('label');"
964 " label_element.setAttribute('for', name);"
965 " label_element.appendChild(label_text);"
966 " form.appendChild(label_element);"
968 " if (name === 'state' || name === 'country') {"
969 " var select_element = document.createElement('select');"
970 " select_element.setAttribute('id', name);"
971 " select_element.setAttribute('name', name);"
973 " /* Add an empty selected option. */"
974 " var default_option = new Option('--', '', true);"
975 " select_element.appendChild(default_option);"
977 " /* Add the other options. */"
978 " if (name == 'state') {"
979 " var option1 = new Option('California', 'CA');"
980 " select_element.appendChild(option1);"
981 " var option2 = new Option('Texas', 'TX');"
982 " select_element.appendChild(option2);"
984 " var option1 = new Option('Canada', 'CA');"
985 " select_element.appendChild(option1);"
986 " var option2 = new Option('United States', 'US');"
987 " select_element.appendChild(option2);"
990 " form.appendChild(select_element);"
992 " var input_element = document.createElement('input');"
993 " input_element.setAttribute('id', name);"
994 " input_element.setAttribute('name', name);"
996 " /* Add the onfocus listener to the 'firstname' field. */"
997 " if (name === 'firstname') {"
998 " input_element.onfocus = function() {"
999 " domAutomationController.send(true);"
1003 " form.appendChild(input_element);"
1006 " form.appendChild(document.createElement('br'));"
1009 "function BuildForm() {"
1011 " ['firstname', 'First name:'],"
1012 " ['lastname', 'Last name:'],"
1013 " ['address1', 'Address line 1:'],"
1014 " ['address2', 'Address line 2:'],"
1015 " ['city', 'City:'],"
1016 " ['state', 'State:'],"
1017 " ['zip', 'ZIP code:'],"
1018 " ['country', 'Country:'],"
1019 " ['phone', 'Phone number:'],"
1022 " for (var i = 0; i < elements.length; i++) {"
1023 " var name = elements[i][0];"
1024 " var label = elements[i][1];"
1025 " AddElement(name, label);"
1030 // Dynamically construct the form.
1031 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), "BuildForm();"));
1037 // Test that form filling works after reloading the current page.
1038 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, AutofillAfterReload
) {
1039 CreateTestProfile();
1041 // Load the test page.
1042 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
1043 GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
1046 content::WebContents
* web_contents
= GetWebContents();
1047 web_contents
->GetController().Reload(false);
1048 content::WaitForLoadStop(web_contents
);
1054 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, AutofillAfterTranslate
) {
1055 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
1056 if (TranslateService::IsTranslateBubbleEnabled())
1059 CreateTestProfile();
1061 GURL
url(std::string(kDataURIPrefix
) +
1062 "<form action=\"http://www.example.com/\" method=\"POST\">"
1063 "<label for=\"fn\">なまえ</label>"
1064 " <input type=\"text\" id=\"fn\""
1065 " onfocus=\"domAutomationController.send(true)\""
1067 "<label for=\"ln\">みょうじ</label>"
1068 " <input type=\"text\" id=\"ln\"><br>"
1069 "<label for=\"a1\">Address line 1:</label>"
1070 " <input type=\"text\" id=\"a1\"><br>"
1071 "<label for=\"a2\">Address line 2:</label>"
1072 " <input type=\"text\" id=\"a2\"><br>"
1073 "<label for=\"ci\">City:</label>"
1074 " <input type=\"text\" id=\"ci\"><br>"
1075 "<label for=\"st\">State:</label>"
1076 " <select id=\"st\">"
1077 " <option value=\"\" selected=\"yes\">--</option>"
1078 " <option value=\"CA\">California</option>"
1079 " <option value=\"TX\">Texas</option>"
1081 "<label for=\"z\">ZIP code:</label>"
1082 " <input type=\"text\" id=\"z\"><br>"
1083 "<label for=\"co\">Country:</label>"
1084 " <select id=\"co\">"
1085 " <option value=\"\" selected=\"yes\">--</option>"
1086 " <option value=\"CA\">Canada</option>"
1087 " <option value=\"US\">United States</option>"
1089 "<label for=\"ph\">Phone number:</label>"
1090 " <input type=\"text\" id=\"ph\"><br>"
1092 // Add additional Japanese characters to ensure the translate bar
1094 "我々は重要な、興味深いものになるが、時折状況が発生するため苦労や痛みは"
1095 "彼にいくつかの素晴らしいを調達することができます。それから、いくつかの利");
1097 content::WindowedNotificationObserver
infobar_observer(
1098 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
1099 content::NotificationService::AllSources());
1100 ASSERT_NO_FATAL_FAILURE(
1101 ui_test_utils::NavigateToURL(browser(), url
));
1103 // Wait for the translation bar to appear and get it.
1104 infobar_observer
.Wait();
1105 InfoBarService
* infobar_service
=
1106 InfoBarService::FromWebContents(GetWebContents());
1107 translate::TranslateInfoBarDelegate
* delegate
=
1108 infobar_service
->infobar_at(0)->delegate()->AsTranslateInfoBarDelegate();
1109 ASSERT_TRUE(delegate
);
1110 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE
,
1111 delegate
->translate_step());
1113 // Simulate translation button press.
1114 delegate
->Translate();
1116 content::WindowedNotificationObserver
translation_observer(
1117 chrome::NOTIFICATION_PAGE_TRANSLATED
,
1118 content::NotificationService::AllSources());
1120 // Simulate the translate script being retrieved.
1121 // Pass fake google.translate lib as the translate script.
1122 SimulateURLFetch(true);
1124 // Simulate the render notifying the translation has been done.
1125 translation_observer
.Wait();
1130 // Test phone fields parse correctly from a given profile.
1131 // The high level key presses execute the following: Select the first text
1132 // field, invoke the autofill popup list, select the first profile within the
1133 // list, and commit to the profile to populate the form.
1134 // Flakily times out on windows. http://crbug.com/390564
1136 #define MAYBE_ComparePhoneNumbers DISABLED_ComparePhoneNumbers
1138 #define MAYBE_ComparePhoneNumbers ComparePhoneNumbers
1140 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, MAYBE_ComparePhoneNumbers
) {
1141 ASSERT_TRUE(test_server()->Start());
1143 AutofillProfile profile
;
1144 profile
.SetRawInfo(NAME_FIRST
, ASCIIToUTF16("Bob"));
1145 profile
.SetRawInfo(NAME_LAST
, ASCIIToUTF16("Smith"));
1146 profile
.SetRawInfo(ADDRESS_HOME_LINE1
, ASCIIToUTF16("1234 H St."));
1147 profile
.SetRawInfo(ADDRESS_HOME_CITY
, ASCIIToUTF16("San Jose"));
1148 profile
.SetRawInfo(ADDRESS_HOME_STATE
, ASCIIToUTF16("CA"));
1149 profile
.SetRawInfo(ADDRESS_HOME_ZIP
, ASCIIToUTF16("95110"));
1150 profile
.SetRawInfo(PHONE_HOME_WHOLE_NUMBER
, ASCIIToUTF16("1-408-555-4567"));
1151 SetTestProfile(browser(), profile
);
1153 GURL url
= test_server()->GetURL("files/autofill/form_phones.html");
1154 ui_test_utils::NavigateToURL(browser(), url
);
1155 PopulateForm("NAME_FIRST");
1157 ExpectFieldValue("NAME_FIRST", "Bob");
1158 ExpectFieldValue("NAME_LAST", "Smith");
1159 ExpectFieldValue("ADDRESS_HOME_LINE1", "1234 H St.");
1160 ExpectFieldValue("ADDRESS_HOME_CITY", "San Jose");
1161 ExpectFieldValue("ADDRESS_HOME_STATE", "CA");
1162 ExpectFieldValue("ADDRESS_HOME_ZIP", "95110");
1163 ExpectFieldValue("PHONE_HOME_WHOLE_NUMBER", "14085554567");
1164 ExpectFieldValue("PHONE_HOME_CITY_CODE-1", "408");
1165 ExpectFieldValue("PHONE_HOME_CITY_CODE-2", "408");
1166 ExpectFieldValue("PHONE_HOME_NUMBER", "5554567");
1167 ExpectFieldValue("PHONE_HOME_NUMBER_3-1", "555");
1168 ExpectFieldValue("PHONE_HOME_NUMBER_3-2", "555");
1169 ExpectFieldValue("PHONE_HOME_NUMBER_4-1", "4567");
1170 ExpectFieldValue("PHONE_HOME_NUMBER_4-2", "4567");
1171 ExpectFieldValue("PHONE_HOME_EXT-1", std::string());
1172 ExpectFieldValue("PHONE_HOME_EXT-2", std::string());
1173 ExpectFieldValue("PHONE_HOME_COUNTRY_CODE-1", "1");
1176 // Test that Autofill does not fill in read-only fields.
1177 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, NoAutofillForReadOnlyFields
) {
1178 ASSERT_TRUE(test_server()->Start());
1180 std::string
addr_line1("1234 H St.");
1182 AutofillProfile profile
;
1183 profile
.SetRawInfo(NAME_FIRST
, ASCIIToUTF16("Bob"));
1184 profile
.SetRawInfo(NAME_LAST
, ASCIIToUTF16("Smith"));
1185 profile
.SetRawInfo(EMAIL_ADDRESS
, ASCIIToUTF16("bsmith@gmail.com"));
1186 profile
.SetRawInfo(ADDRESS_HOME_LINE1
, ASCIIToUTF16(addr_line1
));
1187 profile
.SetRawInfo(ADDRESS_HOME_CITY
, ASCIIToUTF16("San Jose"));
1188 profile
.SetRawInfo(ADDRESS_HOME_STATE
, ASCIIToUTF16("CA"));
1189 profile
.SetRawInfo(ADDRESS_HOME_ZIP
, ASCIIToUTF16("95110"));
1190 profile
.SetRawInfo(COMPANY_NAME
, ASCIIToUTF16("Company X"));
1191 profile
.SetRawInfo(PHONE_HOME_WHOLE_NUMBER
, ASCIIToUTF16("408-871-4567"));
1192 SetTestProfile(browser(), profile
);
1194 GURL url
= test_server()->GetURL("files/autofill/read_only_field_test.html");
1195 ui_test_utils::NavigateToURL(browser(), url
);
1196 PopulateForm("firstname");
1198 ExpectFieldValue("email", std::string());
1199 ExpectFieldValue("address", addr_line1
);
1202 // Test form is fillable from a profile after form was reset.
1204 // 1. Fill form using a saved profile.
1205 // 2. Reset the form.
1206 // 3. Fill form using a saved profile.
1207 // Flakily times out: http://crbug.com/270341
1208 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
, DISABLED_FormFillableOnReset
) {
1209 ASSERT_TRUE(test_server()->Start());
1211 CreateTestProfile();
1213 GURL url
= test_server()->GetURL("files/autofill/autofill_test_form.html");
1214 ui_test_utils::NavigateToURL(browser(), url
);
1215 PopulateForm("NAME_FIRST");
1217 ASSERT_TRUE(content::ExecuteScript(
1218 GetWebContents(), "document.getElementById('testform').reset()"));
1220 PopulateForm("NAME_FIRST");
1222 ExpectFieldValue("NAME_FIRST", "Milton");
1223 ExpectFieldValue("NAME_LAST", "Waddams");
1224 ExpectFieldValue("EMAIL_ADDRESS", "red.swingline@initech.com");
1225 ExpectFieldValue("ADDRESS_HOME_LINE1", "4120 Freidrich Lane");
1226 ExpectFieldValue("ADDRESS_HOME_CITY", "Austin");
1227 ExpectFieldValue("ADDRESS_HOME_STATE", "Texas");
1228 ExpectFieldValue("ADDRESS_HOME_ZIP", "78744");
1229 ExpectFieldValue("ADDRESS_HOME_COUNTRY", "United States");
1230 ExpectFieldValue("PHONE_HOME_WHOLE_NUMBER", "5125551234");
1233 // Test Autofill distinguishes a middle initial in a name.
1234 // Flakily times out: http://crbug.com/270341
1235 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
1236 DISABLED_DistinguishMiddleInitialWithinName
) {
1237 ASSERT_TRUE(test_server()->Start());
1239 CreateTestProfile();
1241 GURL url
= test_server()->GetURL(
1242 "files/autofill/autofill_middleinit_form.html");
1243 ui_test_utils::NavigateToURL(browser(), url
);
1244 PopulateForm("NAME_FIRST");
1246 ExpectFieldValue("NAME_MIDDLE", "C");
1249 // Test forms with multiple email addresses are filled properly.
1250 // Entire form should be filled with one user gesture.
1251 // Flakily times out: http://crbug.com/270341
1252 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
1253 DISABLED_MultipleEmailFilledByOneUserGesture
) {
1254 ASSERT_TRUE(test_server()->Start());
1256 std::string
email("bsmith@gmail.com");
1258 AutofillProfile profile
;
1259 profile
.SetRawInfo(NAME_FIRST
, ASCIIToUTF16("Bob"));
1260 profile
.SetRawInfo(NAME_LAST
, ASCIIToUTF16("Smith"));
1261 profile
.SetRawInfo(EMAIL_ADDRESS
, ASCIIToUTF16(email
));
1262 profile
.SetRawInfo(PHONE_HOME_WHOLE_NUMBER
, ASCIIToUTF16("4088714567"));
1263 SetTestProfile(browser(), profile
);
1265 GURL url
= test_server()->GetURL(
1266 "files/autofill/autofill_confirmemail_form.html");
1267 ui_test_utils::NavigateToURL(browser(), url
);
1268 PopulateForm("NAME_FIRST");
1270 ExpectFieldValue("EMAIL_CONFIRM", email
);
1271 // TODO(isherman): verify entire form.
1274 // http://crbug.com/281527
1275 #if defined(OS_MACOSX)
1276 #define MAYBE_FormFillLatencyAfterSubmit FormFillLatencyAfterSubmit
1278 #define MAYBE_FormFillLatencyAfterSubmit DISABLED_FormFillLatencyAfterSubmit
1280 // Test latency time on form submit with lots of stored Autofill profiles.
1281 // This test verifies when a profile is selected from the Autofill dictionary
1282 // that consists of thousands of profiles, the form does not hang after being
1284 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
1285 MAYBE_FormFillLatencyAfterSubmit
) {
1286 ASSERT_TRUE(test_server()->Start());
1288 std::vector
<std::string
> cities
;
1289 cities
.push_back("San Jose");
1290 cities
.push_back("San Francisco");
1291 cities
.push_back("Sacramento");
1292 cities
.push_back("Los Angeles");
1294 std::vector
<std::string
> streets
;
1295 streets
.push_back("St");
1296 streets
.push_back("Ave");
1297 streets
.push_back("Ln");
1298 streets
.push_back("Ct");
1300 const int kNumProfiles
= 1500;
1301 base::Time start_time
= base::Time::Now();
1302 std::vector
<AutofillProfile
> profiles
;
1303 for (int i
= 0; i
< kNumProfiles
; i
++) {
1304 AutofillProfile profile
;
1305 base::string16
name(base::IntToString16(i
));
1306 base::string16
email(name
+ ASCIIToUTF16("@example.com"));
1307 base::string16 street
= ASCIIToUTF16(
1308 base::IntToString(base::RandInt(0, 10000)) + " " +
1309 streets
[base::RandInt(0, streets
.size() - 1)]);
1310 base::string16 city
=
1311 ASCIIToUTF16(cities
[base::RandInt(0, cities
.size() - 1)]);
1312 base::string16
zip(base::IntToString16(base::RandInt(0, 10000)));
1313 profile
.SetRawInfo(NAME_FIRST
, name
);
1314 profile
.SetRawInfo(EMAIL_ADDRESS
, email
);
1315 profile
.SetRawInfo(ADDRESS_HOME_LINE1
, street
);
1316 profile
.SetRawInfo(ADDRESS_HOME_CITY
, city
);
1317 profile
.SetRawInfo(ADDRESS_HOME_STATE
, ASCIIToUTF16("CA"));
1318 profile
.SetRawInfo(ADDRESS_HOME_ZIP
, zip
);
1319 profile
.SetRawInfo(ADDRESS_HOME_COUNTRY
, ASCIIToUTF16("US"));
1320 profiles
.push_back(profile
);
1322 SetTestProfiles(browser(), &profiles
);
1323 // TODO(isherman): once we're sure this test doesn't timeout on any bots, this
1325 LOG(INFO
) << "Created " << kNumProfiles
<< " profiles in " <<
1326 (base::Time::Now() - start_time
).InSeconds() << " seconds.";
1328 GURL url
= test_server()->GetURL(
1329 "files/autofill/latency_after_submit_test.html");
1330 ui_test_utils::NavigateToURL(browser(), url
);
1331 PopulateForm("NAME_FIRST");
1333 content::WindowedNotificationObserver
load_stop_observer(
1334 content::NOTIFICATION_LOAD_STOP
,
1335 content::Source
<content::NavigationController
>(
1336 &GetWebContents()->GetController()));
1338 ASSERT_TRUE(content::ExecuteScript(
1339 GetRenderViewHost(),
1340 "document.getElementById('testform').submit();"));
1341 // This will ensure the test didn't hang.
1342 load_stop_observer
.Wait();
1345 // Test that Chrome doesn't crash when autocomplete is disabled while the user
1346 // is interacting with the form. This is a regression test for
1347 // http://crbug.com/160476
1348 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest
,
1349 DisableAutocompleteWhileFilling
) {
1350 CreateTestProfile();
1352 // Load the test page.
1353 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
1354 GURL(std::string(kDataURIPrefix
) + kTestFormString
)));
1356 // Invoke Autofill: Start filling the first name field with "M" and wait for
1357 // the popup to be shown.
1358 FocusFirstNameField();
1359 SendKeyToPageAndWait(ui::VKEY_M
);
1361 // Now that the popup with suggestions is showing, disable autocomplete for
1362 // the active field.
1363 ASSERT_TRUE(content::ExecuteScript(
1364 GetRenderViewHost(),
1365 "document.querySelector('input').autocomplete = 'off';"));
1367 // Press the down arrow to select the suggestion and attempt to preview the
1369 SendKeyToPopupAndWait(ui::VKEY_DOWN
);
1372 } // namespace autofill