Move TranslateStep enum into the Translate component core code.
[chromium-blink-merge.git] / chrome / browser / autofill / autofill_interactive_uitest.cc
blobf49ece24ac0b1203eb143c5a16832a3aedbf4339
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.
5 #include <string>
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/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/personal_data_manager_factory.h"
19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
21 #include "chrome/browser/infobars/infobar.h"
22 #include "chrome/browser/infobars/infobar_manager.h"
23 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/translate/translate_infobar_delegate.h"
26 #include "chrome/browser/translate/translate_service.h"
27 #include "chrome/browser/translate/translate_tab_helper.h"
28 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/common/render_messages.h"
32 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/test_switches.h"
34 #include "chrome/test/base/ui_test_utils.h"
35 #include "components/autofill/content/browser/content_autofill_driver.h"
36 #include "components/autofill/core/browser/autofill_manager.h"
37 #include "components/autofill/core/browser/autofill_manager_test_delegate.h"
38 #include "components/autofill/core/browser/autofill_profile.h"
39 #include "components/autofill/core/browser/autofill_test_utils.h"
40 #include "components/autofill/core/browser/personal_data_manager.h"
41 #include "components/autofill/core/browser/personal_data_manager_observer.h"
42 #include "components/autofill/core/browser/validation.h"
43 #include "content/public/browser/navigation_controller.h"
44 #include "content/public/browser/notification_observer.h"
45 #include "content/public/browser/notification_registrar.h"
46 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/render_view_host.h"
48 #include "content/public/browser/render_widget_host.h"
49 #include "content/public/browser/web_contents.h"
50 #include "content/public/test/browser_test_utils.h"
51 #include "content/public/test/test_renderer_host.h"
52 #include "content/public/test/test_utils.h"
53 #include "net/url_request/test_url_fetcher_factory.h"
54 #include "testing/gmock/include/gmock/gmock.h"
55 #include "testing/gtest/include/gtest/gtest.h"
56 #include "ui/events/keycodes/keyboard_codes.h"
58 using base::ASCIIToUTF16;
60 namespace autofill {
62 static const char kDataURIPrefix[] = "data:text/html;charset=utf-8,";
63 static const char kTestFormString[] =
64 "<form action=\"http://www.example.com/\" method=\"POST\">"
65 "<label for=\"firstname\">First name:</label>"
66 " <input type=\"text\" id=\"firstname\""
67 " onfocus=\"domAutomationController.send(true)\"><br>"
68 "<label for=\"lastname\">Last name:</label>"
69 " <input type=\"text\" id=\"lastname\"><br>"
70 "<label for=\"address1\">Address line 1:</label>"
71 " <input type=\"text\" id=\"address1\"><br>"
72 "<label for=\"address2\">Address line 2:</label>"
73 " <input type=\"text\" id=\"address2\"><br>"
74 "<label for=\"city\">City:</label>"
75 " <input type=\"text\" id=\"city\"><br>"
76 "<label for=\"state\">State:</label>"
77 " <select id=\"state\">"
78 " <option value=\"\" selected=\"yes\">--</option>"
79 " <option value=\"CA\">California</option>"
80 " <option value=\"TX\">Texas</option>"
81 " </select><br>"
82 "<label for=\"zip\">ZIP code:</label>"
83 " <input type=\"text\" id=\"zip\"><br>"
84 "<label for=\"country\">Country:</label>"
85 " <select id=\"country\">"
86 " <option value=\"\" selected=\"yes\">--</option>"
87 " <option value=\"CA\">Canada</option>"
88 " <option value=\"US\">United States</option>"
89 " </select><br>"
90 "<label for=\"phone\">Phone number:</label>"
91 " <input type=\"text\" id=\"phone\"><br>"
92 "</form>";
95 // AutofillManagerTestDelegateImpl --------------------------------------------
97 class AutofillManagerTestDelegateImpl
98 : public autofill::AutofillManagerTestDelegate {
99 public:
100 AutofillManagerTestDelegateImpl() {}
101 virtual ~AutofillManagerTestDelegateImpl() {}
103 // autofill::AutofillManagerTestDelegate:
104 virtual void DidPreviewFormData() OVERRIDE {
105 loop_runner_->Quit();
108 virtual void DidFillFormData() OVERRIDE {
109 loop_runner_->Quit();
112 virtual void DidShowSuggestions() OVERRIDE {
113 loop_runner_->Quit();
116 void Reset() {
117 loop_runner_ = new content::MessageLoopRunner();
120 void Wait() {
121 loop_runner_->Run();
124 private:
125 scoped_refptr<content::MessageLoopRunner> loop_runner_;
127 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTestDelegateImpl);
131 // WindowedPersonalDataManagerObserver ----------------------------------------
133 class WindowedPersonalDataManagerObserver
134 : public PersonalDataManagerObserver,
135 public content::NotificationObserver {
136 public:
137 explicit WindowedPersonalDataManagerObserver(Browser* browser)
138 : alerted_(false),
139 has_run_message_loop_(false),
140 browser_(browser),
141 infobar_service_(NULL) {
142 PersonalDataManagerFactory::GetForProfile(browser_->profile())->
143 AddObserver(this);
144 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
145 content::NotificationService::AllSources());
148 virtual ~WindowedPersonalDataManagerObserver() {
149 if (infobar_service_) {
150 InfoBarManager* infobar_manager = infobar_service_->infobar_manager();
151 while (infobar_manager->infobar_count() > 0) {
152 infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(0));
157 // PersonalDataManagerObserver:
158 virtual void OnPersonalDataChanged() OVERRIDE {
159 if (has_run_message_loop_) {
160 base::MessageLoopForUI::current()->Quit();
161 has_run_message_loop_ = false;
163 alerted_ = true;
166 virtual void OnInsufficientFormData() OVERRIDE {
167 OnPersonalDataChanged();
170 // content::NotificationObserver:
171 virtual void Observe(int type,
172 const content::NotificationSource& source,
173 const content::NotificationDetails& details) OVERRIDE {
174 infobar_service_ = InfoBarService::FromWebContents(
175 browser_->tab_strip_model()->GetActiveWebContents());
176 infobar_service_->infobar_manager()->infobar_at(0)->delegate()
177 ->AsConfirmInfoBarDelegate()->Accept();
180 void Wait() {
181 if (!alerted_) {
182 has_run_message_loop_ = true;
183 content::RunMessageLoop();
185 PersonalDataManagerFactory::GetForProfile(browser_->profile())->
186 RemoveObserver(this);
189 private:
190 bool alerted_;
191 bool has_run_message_loop_;
192 Browser* browser_;
193 content::NotificationRegistrar registrar_;
194 InfoBarService* infobar_service_;
196 DISALLOW_COPY_AND_ASSIGN(WindowedPersonalDataManagerObserver);
199 // AutofillInteractiveTest ----------------------------------------------------
201 class AutofillInteractiveTest : public InProcessBrowserTest {
202 protected:
203 AutofillInteractiveTest() :
204 key_press_event_sink_(
205 base::Bind(&AutofillInteractiveTest::HandleKeyPressEvent,
206 base::Unretained(this))) {}
207 virtual ~AutofillInteractiveTest() {}
209 // InProcessBrowserTest:
210 virtual void SetUpOnMainThread() OVERRIDE {
211 TranslateService::SetUseInfobar(true);
213 // Don't want Keychain coming up on Mac.
214 test::DisableSystemServices(browser()->profile()->GetPrefs());
216 // Inject the test delegate into the AutofillManager.
217 content::WebContents* web_contents = GetWebContents();
218 ContentAutofillDriver* autofill_driver =
219 ContentAutofillDriver::FromWebContents(web_contents);
220 AutofillManager* autofill_manager = autofill_driver->autofill_manager();
221 autofill_manager->SetTestDelegate(&test_delegate_);
224 virtual void CleanUpOnMainThread() OVERRIDE {
225 // Make sure to close any showing popups prior to tearing down the UI.
226 content::WebContents* web_contents = GetWebContents();
227 AutofillManager* autofill_manager = ContentAutofillDriver::FromWebContents(
228 web_contents)->autofill_manager();
229 autofill_manager->delegate()->HideAutofillPopup();
232 PersonalDataManager* GetPersonalDataManager() {
233 return PersonalDataManagerFactory::GetForProfile(browser()->profile());
236 content::WebContents* GetWebContents() {
237 return browser()->tab_strip_model()->GetActiveWebContents();
240 content::RenderViewHost* GetRenderViewHost() {
241 return GetWebContents()->GetRenderViewHost();
244 void CreateTestProfile() {
245 AutofillProfile profile;
246 test::SetProfileInfo(
247 &profile, "Milton", "C.", "Waddams",
248 "red.swingline@initech.com", "Initech", "4120 Freidrich Lane",
249 "Basement", "Austin", "Texas", "78744", "US", "5125551234");
251 WindowedPersonalDataManagerObserver observer(browser());
252 GetPersonalDataManager()->AddProfile(profile);
254 // AddProfile is asynchronous. Wait for it to finish before continuing the
255 // tests.
256 observer.Wait();
259 void SetProfiles(std::vector<AutofillProfile>* profiles) {
260 WindowedPersonalDataManagerObserver observer(browser());
261 GetPersonalDataManager()->SetProfiles(profiles);
262 observer.Wait();
265 void SetProfile(const AutofillProfile& profile) {
266 std::vector<AutofillProfile> profiles;
267 profiles.push_back(profile);
268 SetProfiles(&profiles);
271 // Populates a webpage form using autofill data and keypress events.
272 // This function focuses the specified input field in the form, and then
273 // sends keypress events to the tab to cause the form to be populated.
274 void PopulateForm(const std::string& field_id) {
275 std::string js("document.getElementById('" + field_id + "').focus();");
276 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), js));
278 SendKeyToPageAndWait(ui::VKEY_DOWN);
279 SendKeyToPopupAndWait(ui::VKEY_DOWN);
280 SendKeyToPopupAndWait(ui::VKEY_RETURN);
283 void ExpectFieldValue(const std::string& field_name,
284 const std::string& expected_value) {
285 std::string value;
286 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
287 GetWebContents(),
288 "window.domAutomationController.send("
289 " document.getElementById('" + field_name + "').value);",
290 &value));
291 EXPECT_EQ(expected_value, value);
294 void SimulateURLFetch(bool success) {
295 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
296 ASSERT_TRUE(fetcher);
297 net::URLRequestStatus status;
298 status.set_status(success ? net::URLRequestStatus::SUCCESS :
299 net::URLRequestStatus::FAILED);
301 std::string script = " var google = {};"
302 "google.translate = (function() {"
303 " return {"
304 " TranslateService: function() {"
305 " return {"
306 " isAvailable : function() {"
307 " return true;"
308 " },"
309 " restore : function() {"
310 " return;"
311 " },"
312 " getDetectedLanguage : function() {"
313 " return \"ja\";"
314 " },"
315 " translatePage : function(originalLang, targetLang,"
316 " onTranslateProgress) {"
317 " document.getElementsByTagName(\"body\")[0].innerHTML = '" +
318 std::string(kTestFormString) +
319 " ';"
320 " onTranslateProgress(100, true, false);"
321 " }"
322 " };"
323 " }"
324 " };"
325 "})();"
326 "cr.googleTranslate.onTranslateElementLoad();";
328 fetcher->set_url(fetcher->GetOriginalURL());
329 fetcher->set_status(status);
330 fetcher->set_response_code(success ? 200 : 500);
331 fetcher->SetResponseString(script);
332 fetcher->delegate()->OnURLFetchComplete(fetcher);
335 void FocusFirstNameField() {
336 bool result = false;
337 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
338 GetRenderViewHost(),
339 "if (document.readyState === 'complete')"
340 " document.getElementById('firstname').focus();"
341 "else"
342 " domAutomationController.send(false);",
343 &result));
344 ASSERT_TRUE(result);
347 void ExpectFilledTestForm() {
348 ExpectFieldValue("firstname", "Milton");
349 ExpectFieldValue("lastname", "Waddams");
350 ExpectFieldValue("address1", "4120 Freidrich Lane");
351 ExpectFieldValue("address2", "Basement");
352 ExpectFieldValue("city", "Austin");
353 ExpectFieldValue("state", "TX");
354 ExpectFieldValue("zip", "78744");
355 ExpectFieldValue("country", "US");
356 ExpectFieldValue("phone", "5125551234");
359 void SendKeyToPageAndWait(ui::KeyboardCode key) {
360 test_delegate_.Reset();
361 content::SimulateKeyPress(
362 GetWebContents(), key, false, false, false, false);
363 test_delegate_.Wait();
366 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event) {
367 return true;
370 void SendKeyToPopupAndWait(ui::KeyboardCode key) {
371 // Route popup-targeted key presses via the render view host.
372 content::NativeWebKeyboardEvent event;
373 event.windowsKeyCode = key;
374 event.type = blink::WebKeyboardEvent::RawKeyDown;
375 test_delegate_.Reset();
376 // Install the key press event sink to ensure that any events that are not
377 // handled by the installed callbacks do not end up crashing the test.
378 GetRenderViewHost()->AddKeyPressEventCallback(key_press_event_sink_);
379 GetRenderViewHost()->ForwardKeyboardEvent(event);
380 test_delegate_.Wait();
381 GetRenderViewHost()->RemoveKeyPressEventCallback(key_press_event_sink_);
384 void TryBasicFormFill() {
385 FocusFirstNameField();
387 // Start filling the first name field with "M" and wait for the popup to be
388 // shown.
389 SendKeyToPageAndWait(ui::VKEY_M);
391 // Press the down arrow to select the suggestion and preview the autofilled
392 // form.
393 SendKeyToPopupAndWait(ui::VKEY_DOWN);
395 // The previewed values should not be accessible to JavaScript.
396 ExpectFieldValue("firstname", "M");
397 ExpectFieldValue("lastname", std::string());
398 ExpectFieldValue("address1", std::string());
399 ExpectFieldValue("address2", std::string());
400 ExpectFieldValue("city", std::string());
401 ExpectFieldValue("state", std::string());
402 ExpectFieldValue("zip", std::string());
403 ExpectFieldValue("country", std::string());
404 ExpectFieldValue("phone", std::string());
405 // TODO(isherman): It would be nice to test that the previewed values are
406 // displayed: http://crbug.com/57220
408 // Press Enter to accept the autofill suggestions.
409 SendKeyToPopupAndWait(ui::VKEY_RETURN);
411 // The form should be filled.
412 ExpectFilledTestForm();
415 private:
416 AutofillManagerTestDelegateImpl test_delegate_;
418 net::TestURLFetcherFactory url_fetcher_factory_;
420 // KeyPressEventCallback that serves as a sink to ensure that every key press
421 // event the tests create and have the WebContents forward is handled by some
422 // key press event callback. It is necessary to have this sinkbecause if no
423 // key press event callback handles the event (at least on Mac), a DCHECK
424 // ends up going off that the |event| doesn't have an |os_event| associated
425 // with it.
426 content::RenderWidgetHost::KeyPressEventCallback key_press_event_sink_;
428 DISALLOW_COPY_AND_ASSIGN(AutofillInteractiveTest);
431 // Test that basic form fill is working.
432 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, BasicFormFill) {
433 CreateTestProfile();
435 // Load the test page.
436 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
437 GURL(std::string(kDataURIPrefix) + kTestFormString)));
439 // Invoke Autofill.
440 TryBasicFormFill();
443 // Test that form filling can be initiated by pressing the down arrow.
444 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillViaDownArrow) {
445 CreateTestProfile();
447 // Load the test page.
448 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
449 GURL(std::string(kDataURIPrefix) + kTestFormString)));
451 // Focus a fillable field.
452 FocusFirstNameField();
454 // Press the down arrow to initiate Autofill and wait for the popup to be
455 // shown.
456 SendKeyToPageAndWait(ui::VKEY_DOWN);
458 // Press the down arrow to select the suggestion and preview the autofilled
459 // form.
460 SendKeyToPopupAndWait(ui::VKEY_DOWN);
462 // Press Enter to accept the autofill suggestions.
463 SendKeyToPopupAndWait(ui::VKEY_RETURN);
465 // The form should be filled.
466 ExpectFilledTestForm();
469 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillSelectViaTab) {
470 CreateTestProfile();
472 // Load the test page.
473 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
474 GURL(std::string(kDataURIPrefix) + kTestFormString)));
476 // Focus a fillable field.
477 FocusFirstNameField();
479 // Press the down arrow to initiate Autofill and wait for the popup to be
480 // shown.
481 SendKeyToPageAndWait(ui::VKEY_DOWN);
483 // Press the down arrow to select the suggestion and preview the autofilled
484 // form.
485 SendKeyToPopupAndWait(ui::VKEY_DOWN);
487 // Press tab to accept the autofill suggestions.
488 SendKeyToPopupAndWait(ui::VKEY_TAB);
490 // The form should be filled.
491 ExpectFilledTestForm();
494 // Test that a JavaScript oninput event is fired after auto-filling a form.
495 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnInputAfterAutofill) {
496 CreateTestProfile();
498 const char kOnInputScript[] =
499 "<script>"
500 "focused_fired = false;"
501 "unfocused_fired = false;"
502 "changed_select_fired = false;"
503 "unchanged_select_fired = false;"
504 "document.getElementById('firstname').oninput = function() {"
505 " focused_fired = true;"
506 "};"
507 "document.getElementById('lastname').oninput = function() {"
508 " unfocused_fired = true;"
509 "};"
510 "document.getElementById('state').oninput = function() {"
511 " changed_select_fired = true;"
512 "};"
513 "document.getElementById('country').oninput = function() {"
514 " unchanged_select_fired = true;"
515 "};"
516 "document.getElementById('country').value = 'US';"
517 "</script>";
519 // Load the test page.
520 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
521 GURL(std::string(kDataURIPrefix) + kTestFormString + kOnInputScript)));
523 // Invoke Autofill.
524 FocusFirstNameField();
526 // Start filling the first name field with "M" and wait for the popup to be
527 // shown.
528 SendKeyToPageAndWait(ui::VKEY_M);
530 // Press the down arrow to select the suggestion and preview the autofilled
531 // form.
532 SendKeyToPopupAndWait(ui::VKEY_DOWN);
534 // Press Enter to accept the autofill suggestions.
535 SendKeyToPopupAndWait(ui::VKEY_RETURN);
537 // The form should be filled.
538 ExpectFilledTestForm();
540 bool focused_fired = false;
541 bool unfocused_fired = false;
542 bool changed_select_fired = false;
543 bool unchanged_select_fired = false;
544 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
545 GetRenderViewHost(),
546 "domAutomationController.send(focused_fired);",
547 &focused_fired));
548 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
549 GetRenderViewHost(),
550 "domAutomationController.send(unfocused_fired);",
551 &unfocused_fired));
552 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
553 GetRenderViewHost(),
554 "domAutomationController.send(changed_select_fired);",
555 &changed_select_fired));
556 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
557 GetRenderViewHost(),
558 "domAutomationController.send(unchanged_select_fired);",
559 &unchanged_select_fired));
560 EXPECT_TRUE(focused_fired);
561 EXPECT_TRUE(unfocused_fired);
562 EXPECT_TRUE(changed_select_fired);
563 EXPECT_FALSE(unchanged_select_fired);
566 // Test that a JavaScript onchange event is fired after auto-filling a form.
567 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, OnChangeAfterAutofill) {
568 CreateTestProfile();
570 const char kOnChangeScript[] =
571 "<script>"
572 "focused_fired = false;"
573 "unfocused_fired = false;"
574 "changed_select_fired = false;"
575 "unchanged_select_fired = false;"
576 "document.getElementById('firstname').onchange = function() {"
577 " focused_fired = true;"
578 "};"
579 "document.getElementById('lastname').onchange = function() {"
580 " unfocused_fired = true;"
581 "};"
582 "document.getElementById('state').onchange = function() {"
583 " changed_select_fired = true;"
584 "};"
585 "document.getElementById('country').onchange = function() {"
586 " unchanged_select_fired = true;"
587 "};"
588 "document.getElementById('country').value = 'US';"
589 "</script>";
591 // Load the test page.
592 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
593 GURL(std::string(kDataURIPrefix) + kTestFormString + kOnChangeScript)));
595 // Invoke Autofill.
596 FocusFirstNameField();
598 // Start filling the first name field with "M" and wait for the popup to be
599 // shown.
600 SendKeyToPageAndWait(ui::VKEY_M);
602 // Press the down arrow to select the suggestion and preview the autofilled
603 // form.
604 SendKeyToPopupAndWait(ui::VKEY_DOWN);
606 // Press Enter to accept the autofill suggestions.
607 SendKeyToPopupAndWait(ui::VKEY_RETURN);
609 // The form should be filled.
610 ExpectFilledTestForm();
612 bool focused_fired = false;
613 bool unfocused_fired = false;
614 bool changed_select_fired = false;
615 bool unchanged_select_fired = false;
616 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
617 GetRenderViewHost(),
618 "domAutomationController.send(focused_fired);",
619 &focused_fired));
620 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
621 GetRenderViewHost(),
622 "domAutomationController.send(unfocused_fired);",
623 &unfocused_fired));
624 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
625 GetRenderViewHost(),
626 "domAutomationController.send(changed_select_fired);",
627 &changed_select_fired));
628 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
629 GetRenderViewHost(),
630 "domAutomationController.send(unchanged_select_fired);",
631 &unchanged_select_fired));
632 EXPECT_TRUE(focused_fired);
633 EXPECT_TRUE(unfocused_fired);
634 EXPECT_TRUE(changed_select_fired);
635 EXPECT_FALSE(unchanged_select_fired);
638 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, InputFiresBeforeChange) {
639 CreateTestProfile();
641 const char kInputFiresBeforeChangeScript[] =
642 "<script>"
643 "inputElementEvents = [];"
644 "function recordInputElementEvent(e) {"
645 " if (e.target.tagName != 'INPUT') throw 'only <input> tags allowed';"
646 " inputElementEvents.push(e.type);"
648 "selectElementEvents = [];"
649 "function recordSelectElementEvent(e) {"
650 " if (e.target.tagName != 'SELECT') throw 'only <select> tags allowed';"
651 " selectElementEvents.push(e.type);"
653 "document.getElementById('lastname').oninput = recordInputElementEvent;"
654 "document.getElementById('lastname').onchange = recordInputElementEvent;"
655 "document.getElementById('country').oninput = recordSelectElementEvent;"
656 "document.getElementById('country').onchange = recordSelectElementEvent;"
657 "</script>";
659 // Load the test page.
660 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
661 GURL(std::string(kDataURIPrefix) + kTestFormString +
662 kInputFiresBeforeChangeScript)));
664 // Invoke and accept the Autofill popup and verify the form was filled.
665 FocusFirstNameField();
666 SendKeyToPageAndWait(ui::VKEY_M);
667 SendKeyToPopupAndWait(ui::VKEY_DOWN);
668 SendKeyToPopupAndWait(ui::VKEY_RETURN);
669 ExpectFilledTestForm();
671 int num_input_element_events = -1;
672 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
673 GetRenderViewHost(),
674 "domAutomationController.send(inputElementEvents.length);",
675 &num_input_element_events));
676 EXPECT_EQ(2, num_input_element_events);
678 std::vector<std::string> input_element_events;
679 input_element_events.resize(2);
681 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
682 GetRenderViewHost(),
683 "domAutomationController.send(inputElementEvents[0]);",
684 &input_element_events[0]));
685 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
686 GetRenderViewHost(),
687 "domAutomationController.send(inputElementEvents[1]);",
688 &input_element_events[1]));
690 EXPECT_EQ("input", input_element_events[0]);
691 EXPECT_EQ("change", input_element_events[1]);
693 int num_select_element_events = -1;
694 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
695 GetRenderViewHost(),
696 "domAutomationController.send(selectElementEvents.length);",
697 &num_select_element_events));
698 EXPECT_EQ(2, num_select_element_events);
700 std::vector<std::string> select_element_events;
701 select_element_events.resize(2);
703 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
704 GetRenderViewHost(),
705 "domAutomationController.send(selectElementEvents[0]);",
706 &select_element_events[0]));
707 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
708 GetRenderViewHost(),
709 "domAutomationController.send(selectElementEvents[1]);",
710 &select_element_events[1]));
712 EXPECT_EQ("input", select_element_events[0]);
713 EXPECT_EQ("change", select_element_events[1]);
716 // Test that we can autofill forms distinguished only by their |id| attribute.
717 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
718 AutofillFormsDistinguishedById) {
719 CreateTestProfile();
721 // Load the test page.
722 const std::string kURL =
723 std::string(kDataURIPrefix) + kTestFormString +
724 "<script>"
725 "var mainForm = document.forms[0];"
726 "mainForm.id = 'mainForm';"
727 "var newForm = document.createElement('form');"
728 "newForm.action = mainForm.action;"
729 "newForm.method = mainForm.method;"
730 "newForm.id = 'newForm';"
731 "mainForm.parentNode.insertBefore(newForm, mainForm);"
732 "</script>";
733 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(), GURL(kURL)));
735 // Invoke Autofill.
736 TryBasicFormFill();
739 // Test that we properly autofill forms with repeated fields.
740 // In the wild, the repeated fields are typically either email fields
741 // (duplicated for "confirmation"); or variants that are hot-swapped via
742 // JavaScript, with only one actually visible at any given time.
743 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillFormWithRepeatedField) {
744 CreateTestProfile();
746 // Load the test page.
747 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
748 GURL(std::string(kDataURIPrefix) +
749 "<form action=\"http://www.example.com/\" method=\"POST\">"
750 "<label for=\"firstname\">First name:</label>"
751 " <input type=\"text\" id=\"firstname\""
752 " onfocus=\"domAutomationController.send(true)\"><br>"
753 "<label for=\"lastname\">Last name:</label>"
754 " <input type=\"text\" id=\"lastname\"><br>"
755 "<label for=\"address1\">Address line 1:</label>"
756 " <input type=\"text\" id=\"address1\"><br>"
757 "<label for=\"address2\">Address line 2:</label>"
758 " <input type=\"text\" id=\"address2\"><br>"
759 "<label for=\"city\">City:</label>"
760 " <input type=\"text\" id=\"city\"><br>"
761 "<label for=\"state\">State:</label>"
762 " <select id=\"state\">"
763 " <option value=\"\" selected=\"yes\">--</option>"
764 " <option value=\"CA\">California</option>"
765 " <option value=\"TX\">Texas</option>"
766 " </select><br>"
767 "<label for=\"state_freeform\" style=\"display:none\">State:</label>"
768 " <input type=\"text\" id=\"state_freeform\""
769 " style=\"display:none\"><br>"
770 "<label for=\"zip\">ZIP code:</label>"
771 " <input type=\"text\" id=\"zip\"><br>"
772 "<label for=\"country\">Country:</label>"
773 " <select id=\"country\">"
774 " <option value=\"\" selected=\"yes\">--</option>"
775 " <option value=\"CA\">Canada</option>"
776 " <option value=\"US\">United States</option>"
777 " </select><br>"
778 "<label for=\"phone\">Phone number:</label>"
779 " <input type=\"text\" id=\"phone\"><br>"
780 "</form>")));
782 // Invoke Autofill.
783 TryBasicFormFill();
784 ExpectFieldValue("state_freeform", std::string());
787 // Test that we properly autofill forms with non-autofillable fields.
788 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
789 AutofillFormWithNonAutofillableField) {
790 CreateTestProfile();
792 // Load the test page.
793 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
794 GURL(std::string(kDataURIPrefix) +
795 "<form action=\"http://www.example.com/\" method=\"POST\">"
796 "<label for=\"firstname\">First name:</label>"
797 " <input type=\"text\" id=\"firstname\""
798 " onfocus=\"domAutomationController.send(true)\"><br>"
799 "<label for=\"middlename\">Middle name:</label>"
800 " <input type=\"text\" id=\"middlename\" autocomplete=\"off\" /><br>"
801 "<label for=\"lastname\">Last name:</label>"
802 " <input type=\"text\" id=\"lastname\"><br>"
803 "<label for=\"address1\">Address line 1:</label>"
804 " <input type=\"text\" id=\"address1\"><br>"
805 "<label for=\"address2\">Address line 2:</label>"
806 " <input type=\"text\" id=\"address2\"><br>"
807 "<label for=\"city\">City:</label>"
808 " <input type=\"text\" id=\"city\"><br>"
809 "<label for=\"state\">State:</label>"
810 " <select id=\"state\">"
811 " <option value=\"\" selected=\"yes\">--</option>"
812 " <option value=\"CA\">California</option>"
813 " <option value=\"TX\">Texas</option>"
814 " </select><br>"
815 "<label for=\"zip\">ZIP code:</label>"
816 " <input type=\"text\" id=\"zip\"><br>"
817 "<label for=\"country\">Country:</label>"
818 " <select id=\"country\">"
819 " <option value=\"\" selected=\"yes\">--</option>"
820 " <option value=\"CA\">Canada</option>"
821 " <option value=\"US\">United States</option>"
822 " </select><br>"
823 "<label for=\"phone\">Phone number:</label>"
824 " <input type=\"text\" id=\"phone\"><br>"
825 "</form>")));
827 // Invoke Autofill.
828 TryBasicFormFill();
831 // Test that we can Autofill dynamically generated forms.
832 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DynamicFormFill) {
833 CreateTestProfile();
835 // Load the test page.
836 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
837 GURL(std::string(kDataURIPrefix) +
838 "<form id=\"form\" action=\"http://www.example.com/\""
839 " method=\"POST\"></form>"
840 "<script>"
841 "function AddElement(name, label) {"
842 " var form = document.getElementById('form');"
844 " var label_text = document.createTextNode(label);"
845 " var label_element = document.createElement('label');"
846 " label_element.setAttribute('for', name);"
847 " label_element.appendChild(label_text);"
848 " form.appendChild(label_element);"
850 " if (name === 'state' || name === 'country') {"
851 " var select_element = document.createElement('select');"
852 " select_element.setAttribute('id', name);"
853 " select_element.setAttribute('name', name);"
855 " /* Add an empty selected option. */"
856 " var default_option = new Option('--', '', true);"
857 " select_element.appendChild(default_option);"
859 " /* Add the other options. */"
860 " if (name == 'state') {"
861 " var option1 = new Option('California', 'CA');"
862 " select_element.appendChild(option1);"
863 " var option2 = new Option('Texas', 'TX');"
864 " select_element.appendChild(option2);"
865 " } else {"
866 " var option1 = new Option('Canada', 'CA');"
867 " select_element.appendChild(option1);"
868 " var option2 = new Option('United States', 'US');"
869 " select_element.appendChild(option2);"
870 " }"
872 " form.appendChild(select_element);"
873 " } else {"
874 " var input_element = document.createElement('input');"
875 " input_element.setAttribute('id', name);"
876 " input_element.setAttribute('name', name);"
878 " /* Add the onfocus listener to the 'firstname' field. */"
879 " if (name === 'firstname') {"
880 " input_element.onfocus = function() {"
881 " domAutomationController.send(true);"
882 " };"
883 " }"
885 " form.appendChild(input_element);"
886 " }"
888 " form.appendChild(document.createElement('br'));"
889 "};"
891 "function BuildForm() {"
892 " var elements = ["
893 " ['firstname', 'First name:'],"
894 " ['lastname', 'Last name:'],"
895 " ['address1', 'Address line 1:'],"
896 " ['address2', 'Address line 2:'],"
897 " ['city', 'City:'],"
898 " ['state', 'State:'],"
899 " ['zip', 'ZIP code:'],"
900 " ['country', 'Country:'],"
901 " ['phone', 'Phone number:'],"
902 " ];"
904 " for (var i = 0; i < elements.length; i++) {"
905 " var name = elements[i][0];"
906 " var label = elements[i][1];"
907 " AddElement(name, label);"
908 " }"
909 "};"
910 "</script>")));
912 // Dynamically construct the form.
913 ASSERT_TRUE(content::ExecuteScript(GetRenderViewHost(), "BuildForm();"));
915 // Invoke Autofill.
916 TryBasicFormFill();
919 // Test that form filling works after reloading the current page.
920 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterReload) {
921 CreateTestProfile();
923 // Load the test page.
924 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
925 GURL(std::string(kDataURIPrefix) + kTestFormString)));
927 // Reload the page.
928 content::WebContents* web_contents = GetWebContents();
929 web_contents->GetController().Reload(false);
930 content::WaitForLoadStop(web_contents);
932 // Invoke Autofill.
933 TryBasicFormFill();
936 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterTranslate) {
937 CreateTestProfile();
939 GURL url(std::string(kDataURIPrefix) +
940 "<form action=\"http://www.example.com/\" method=\"POST\">"
941 "<label for=\"fn\">なまえ</label>"
942 " <input type=\"text\" id=\"fn\""
943 " onfocus=\"domAutomationController.send(true)\""
944 "><br>"
945 "<label for=\"ln\">みょうじ</label>"
946 " <input type=\"text\" id=\"ln\"><br>"
947 "<label for=\"a1\">Address line 1:</label>"
948 " <input type=\"text\" id=\"a1\"><br>"
949 "<label for=\"a2\">Address line 2:</label>"
950 " <input type=\"text\" id=\"a2\"><br>"
951 "<label for=\"ci\">City:</label>"
952 " <input type=\"text\" id=\"ci\"><br>"
953 "<label for=\"st\">State:</label>"
954 " <select id=\"st\">"
955 " <option value=\"\" selected=\"yes\">--</option>"
956 " <option value=\"CA\">California</option>"
957 " <option value=\"TX\">Texas</option>"
958 " </select><br>"
959 "<label for=\"z\">ZIP code:</label>"
960 " <input type=\"text\" id=\"z\"><br>"
961 "<label for=\"co\">Country:</label>"
962 " <select id=\"co\">"
963 " <option value=\"\" selected=\"yes\">--</option>"
964 " <option value=\"CA\">Canada</option>"
965 " <option value=\"US\">United States</option>"
966 " </select><br>"
967 "<label for=\"ph\">Phone number:</label>"
968 " <input type=\"text\" id=\"ph\"><br>"
969 "</form>"
970 // Add additional Japanese characters to ensure the translate bar
971 // will appear.
972 "我々は重要な、興味深いものになるが、時折状況が発生するため苦労や痛みは"
973 "彼にいくつかの素晴らしいを調達することができます。それから、いくつかの利");
975 content::WindowedNotificationObserver infobar_observer(
976 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
977 content::NotificationService::AllSources());
978 ASSERT_NO_FATAL_FAILURE(
979 ui_test_utils::NavigateToURL(browser(), url));
981 // Wait for the translation bar to appear and get it.
982 infobar_observer.Wait();
983 InfoBarManager* infobar_manager =
984 InfoBarService::FromWebContents(GetWebContents())->infobar_manager();
985 TranslateInfoBarDelegate* delegate =
986 infobar_manager->infobar_at(0)->delegate()->AsTranslateInfoBarDelegate();
987 ASSERT_TRUE(delegate);
988 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE,
989 delegate->translate_step());
991 // Simulate translation button press.
992 delegate->Translate();
994 content::WindowedNotificationObserver translation_observer(
995 chrome::NOTIFICATION_PAGE_TRANSLATED,
996 content::NotificationService::AllSources());
998 // Simulate the translate script being retrieved.
999 // Pass fake google.translate lib as the translate script.
1000 SimulateURLFetch(true);
1002 // Simulate the render notifying the translation has been done.
1003 translation_observer.Wait();
1005 TryBasicFormFill();
1008 // Test phone fields parse correctly from a given profile.
1009 // The high level key presses execute the following: Select the first text
1010 // field, invoke the autofill popup list, select the first profile within the
1011 // list, and commit to the profile to populate the form.
1012 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ComparePhoneNumbers) {
1013 ASSERT_TRUE(test_server()->Start());
1015 AutofillProfile profile;
1016 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
1017 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1018 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1234 H St."));
1019 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose"));
1020 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1021 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
1022 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1-408-555-4567"));
1023 SetProfile(profile);
1025 GURL url = test_server()->GetURL("files/autofill/form_phones.html");
1026 ui_test_utils::NavigateToURL(browser(), url);
1027 PopulateForm("NAME_FIRST");
1029 ExpectFieldValue("NAME_FIRST", "Bob");
1030 ExpectFieldValue("NAME_LAST", "Smith");
1031 ExpectFieldValue("ADDRESS_HOME_LINE1", "1234 H St.");
1032 ExpectFieldValue("ADDRESS_HOME_CITY", "San Jose");
1033 ExpectFieldValue("ADDRESS_HOME_STATE", "CA");
1034 ExpectFieldValue("ADDRESS_HOME_ZIP", "95110");
1035 ExpectFieldValue("PHONE_HOME_WHOLE_NUMBER", "14085554567");
1036 ExpectFieldValue("PHONE_HOME_CITY_CODE-1", "408");
1037 ExpectFieldValue("PHONE_HOME_CITY_CODE-2", "408");
1038 ExpectFieldValue("PHONE_HOME_NUMBER", "5554567");
1039 ExpectFieldValue("PHONE_HOME_NUMBER_3-1", "555");
1040 ExpectFieldValue("PHONE_HOME_NUMBER_3-2", "555");
1041 ExpectFieldValue("PHONE_HOME_NUMBER_4-1", "4567");
1042 ExpectFieldValue("PHONE_HOME_NUMBER_4-2", "4567");
1043 ExpectFieldValue("PHONE_HOME_EXT-1", std::string());
1044 ExpectFieldValue("PHONE_HOME_EXT-2", std::string());
1045 ExpectFieldValue("PHONE_HOME_COUNTRY_CODE-1", "1");
1048 // Test that Autofill does not fill in read-only fields.
1049 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, NoAutofillForReadOnlyFields) {
1050 ASSERT_TRUE(test_server()->Start());
1052 std::string addr_line1("1234 H St.");
1054 AutofillProfile profile;
1055 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
1056 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1057 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("bsmith@gmail.com"));
1058 profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16(addr_line1));
1059 profile.SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("San Jose"));
1060 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1061 profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
1062 profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Company X"));
1063 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567"));
1064 SetProfile(profile);
1066 GURL url = test_server()->GetURL("files/autofill/read_only_field_test.html");
1067 ui_test_utils::NavigateToURL(browser(), url);
1068 PopulateForm("firstname");
1070 ExpectFieldValue("email", std::string());
1071 ExpectFieldValue("address", addr_line1);
1074 // Test form is fillable from a profile after form was reset.
1075 // Steps:
1076 // 1. Fill form using a saved profile.
1077 // 2. Reset the form.
1078 // 3. Fill form using a saved profile.
1079 // Flakily times out: http://crbug.com/270341
1080 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, DISABLED_FormFillableOnReset) {
1081 ASSERT_TRUE(test_server()->Start());
1083 CreateTestProfile();
1085 GURL url = test_server()->GetURL("files/autofill/autofill_test_form.html");
1086 ui_test_utils::NavigateToURL(browser(), url);
1087 PopulateForm("NAME_FIRST");
1089 ASSERT_TRUE(content::ExecuteScript(
1090 GetWebContents(), "document.getElementById('testform').reset()"));
1092 PopulateForm("NAME_FIRST");
1094 ExpectFieldValue("NAME_FIRST", "Milton");
1095 ExpectFieldValue("NAME_LAST", "Waddams");
1096 ExpectFieldValue("EMAIL_ADDRESS", "red.swingline@initech.com");
1097 ExpectFieldValue("ADDRESS_HOME_LINE1", "4120 Freidrich Lane");
1098 ExpectFieldValue("ADDRESS_HOME_CITY", "Austin");
1099 ExpectFieldValue("ADDRESS_HOME_STATE", "Texas");
1100 ExpectFieldValue("ADDRESS_HOME_ZIP", "78744");
1101 ExpectFieldValue("ADDRESS_HOME_COUNTRY", "United States");
1102 ExpectFieldValue("PHONE_HOME_WHOLE_NUMBER", "5125551234");
1105 // Test Autofill distinguishes a middle initial in a name.
1106 // Flakily times out: http://crbug.com/270341
1107 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
1108 DISABLED_DistinguishMiddleInitialWithinName) {
1109 ASSERT_TRUE(test_server()->Start());
1111 CreateTestProfile();
1113 GURL url = test_server()->GetURL(
1114 "files/autofill/autofill_middleinit_form.html");
1115 ui_test_utils::NavigateToURL(browser(), url);
1116 PopulateForm("NAME_FIRST");
1118 ExpectFieldValue("NAME_MIDDLE", "C");
1121 // Test forms with multiple email addresses are filled properly.
1122 // Entire form should be filled with one user gesture.
1123 // Flakily times out: http://crbug.com/270341
1124 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
1125 DISABLED_MultipleEmailFilledByOneUserGesture) {
1126 ASSERT_TRUE(test_server()->Start());
1128 std::string email("bsmith@gmail.com");
1130 AutofillProfile profile;
1131 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Bob"));
1132 profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
1133 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(email));
1134 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567"));
1135 SetProfile(profile);
1137 GURL url = test_server()->GetURL(
1138 "files/autofill/autofill_confirmemail_form.html");
1139 ui_test_utils::NavigateToURL(browser(), url);
1140 PopulateForm("NAME_FIRST");
1142 ExpectFieldValue("EMAIL_CONFIRM", email);
1143 // TODO(isherman): verify entire form.
1146 // http://crbug.com/281527
1147 #if defined(OS_MACOSX)
1148 #define MAYBE_FormFillLatencyAfterSubmit FormFillLatencyAfterSubmit
1149 #else
1150 #define MAYBE_FormFillLatencyAfterSubmit DISABLED_FormFillLatencyAfterSubmit
1151 #endif
1152 // Test latency time on form submit with lots of stored Autofill profiles.
1153 // This test verifies when a profile is selected from the Autofill dictionary
1154 // that consists of thousands of profiles, the form does not hang after being
1155 // submitted.
1156 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
1157 MAYBE_FormFillLatencyAfterSubmit) {
1158 ASSERT_TRUE(test_server()->Start());
1160 std::vector<std::string> cities;
1161 cities.push_back("San Jose");
1162 cities.push_back("San Francisco");
1163 cities.push_back("Sacramento");
1164 cities.push_back("Los Angeles");
1166 std::vector<std::string> streets;
1167 streets.push_back("St");
1168 streets.push_back("Ave");
1169 streets.push_back("Ln");
1170 streets.push_back("Ct");
1172 const int kNumProfiles = 1500;
1173 base::Time start_time = base::Time::Now();
1174 std::vector<AutofillProfile> profiles;
1175 for (int i = 0; i < kNumProfiles; i++) {
1176 AutofillProfile profile;
1177 base::string16 name(base::IntToString16(i));
1178 base::string16 email(name + ASCIIToUTF16("@example.com"));
1179 base::string16 street = ASCIIToUTF16(
1180 base::IntToString(base::RandInt(0, 10000)) + " " +
1181 streets[base::RandInt(0, streets.size() - 1)]);
1182 base::string16 city =
1183 ASCIIToUTF16(cities[base::RandInt(0, cities.size() - 1)]);
1184 base::string16 zip(base::IntToString16(base::RandInt(0, 10000)));
1185 profile.SetRawInfo(NAME_FIRST, name);
1186 profile.SetRawInfo(EMAIL_ADDRESS, email);
1187 profile.SetRawInfo(ADDRESS_HOME_LINE1, street);
1188 profile.SetRawInfo(ADDRESS_HOME_CITY, city);
1189 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
1190 profile.SetRawInfo(ADDRESS_HOME_ZIP, zip);
1191 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
1192 profiles.push_back(profile);
1194 SetProfiles(&profiles);
1195 // TODO(isherman): once we're sure this test doesn't timeout on any bots, this
1196 // can be removd.
1197 LOG(INFO) << "Created " << kNumProfiles << " profiles in " <<
1198 (base::Time::Now() - start_time).InSeconds() << " seconds.";
1200 GURL url = test_server()->GetURL(
1201 "files/autofill/latency_after_submit_test.html");
1202 ui_test_utils::NavigateToURL(browser(), url);
1203 PopulateForm("NAME_FIRST");
1205 content::WindowedNotificationObserver load_stop_observer(
1206 content::NOTIFICATION_LOAD_STOP,
1207 content::Source<content::NavigationController>(
1208 &GetWebContents()->GetController()));
1210 ASSERT_TRUE(content::ExecuteScript(
1211 GetRenderViewHost(),
1212 "document.getElementById('testform').submit();"));
1213 // This will ensure the test didn't hang.
1214 load_stop_observer.Wait();
1217 // Test that Chrome doesn't crash when autocomplete is disabled while the user
1218 // is interacting with the form. This is a regression test for
1219 // http://crbug.com/160476
1220 IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
1221 DisableAutocompleteWhileFilling) {
1222 CreateTestProfile();
1224 // Load the test page.
1225 ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
1226 GURL(std::string(kDataURIPrefix) + kTestFormString)));
1228 // Invoke Autofill: Start filling the first name field with "M" and wait for
1229 // the popup to be shown.
1230 FocusFirstNameField();
1231 SendKeyToPageAndWait(ui::VKEY_M);
1233 // Now that the popup with suggestions is showing, disable autocomplete for
1234 // the active field.
1235 ASSERT_TRUE(content::ExecuteScript(
1236 GetRenderViewHost(),
1237 "document.querySelector('input').autocomplete = 'off';"));
1239 // Press the down arrow to select the suggestion and attempt to preview the
1240 // autofilled form.
1241 SendKeyToPopupAndWait(ui::VKEY_DOWN);
1244 } // namespace autofill