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

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

Issue 1494373003: [Autofill] Send Autofill upload when active form loses focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/time/time.h" 6 #include "base/time/time.h"
7 #include "chrome/test/base/chrome_render_view_test.h" 7 #include "chrome/test/base/chrome_render_view_test.h"
8 #include "components/autofill/content/common/autofill_messages.h" 8 #include "components/autofill/content/common/autofill_messages.h"
9 #include "components/autofill/content/renderer/autofill_agent.h" 9 #include "components/autofill/content/renderer/autofill_agent.h"
10 #include "components/autofill/core/common/form_data.h" 10 #include "components/autofill/core/common/form_data.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // Form still visible. 380 // Form still visible.
381 381
382 // Simulate an Ajax request completing. 382 // Simulate an Ajax request completing.
383 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded(); 383 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded();
384 ProcessPendingMessages(); 384 ProcessPendingMessages();
385 385
386 // No submission messages sent. 386 // No submission messages sent.
387 VerifyNoSubmitMessagesReceived(render_thread_.get()); 387 VerifyNoSubmitMessagesReceived(render_thread_.get());
388 } 388 }
389 389
390 // Test that a FocusNoLongerOnForm message is sent if focus goes from an
391 // interacted form to an element outside the form.
392 TEST_F(FormAutocompleteTest,
393 InteractedFormNoLongerFocused_FocusNoLongerOnForm) {
394 // Load a form.
395 LoadHTML(
396 "<html><input type='text' id='different'/>"
397 "<form id='myForm' action='http://example.com/blade.php'>"
398 "<input name='fname' id='fname' value='Bob'/>"
399 "<input name='lname' value='Deckard'/><input type=submit></form></html>");
400
401 // Simulate user input so that the form is "remembered".
402 WebDocument document = GetMainFrame()->document();
403 WebElement element = document.getElementById(WebString::fromUTF8("fname"));
404 ASSERT_FALSE(element.isNull());
405 WebInputElement fname_element = element.to<WebInputElement>();
406 SimulateUserInputChangeForElement(&fname_element, std::string("Rick"));
407
408 // Change focus to a different node outside the form.
409 WebElement different =
410 document.getElementById(WebString::fromUTF8("different"));
411 SetFocused(different);
412
413 ProcessPendingMessages();
414
415 const IPC::Message* focus_no_longer_on_form_message =
416 render_thread_->sink().GetFirstMessageMatching(
417 AutofillHostMsg_FocusNoLongerOnForm::ID);
418 EXPECT_TRUE(focus_no_longer_on_form_message != NULL);
vabr (Chromium) 2015/12/07 09:47:33 nit: NULL -> nullptr, or drop the "!= NULL" comple
Mathieu 2015/12/07 14:23:07 Done.
419 }
420
421 // Test that a FocusNoLongerOnForm message is sent if focus goes from one
422 // interacted form to another.
423 TEST_F(FormAutocompleteTest, InteractingInDifferentForms_FocusNoLongerOnForm) {
424 // Load a form.
425 LoadHTML(
426 "<html><form id='myForm' action='http://example.com/blade.php'>"
427 "<input name='fname' id='fname' value='Bob'/>"
428 "<input name='lname' value='Deckard'/><input type=submit></form>"
429 "<form id='myForm2' action='http://example.com/runner.php'>"
430 "<input name='fname' id='fname2' value='Bob'/>"
431 "<input name='lname' value='Deckard'/><input type=submit></form></html>");
432
433 // Simulate user input in the first form so that the form is "remembered".
434 WebDocument document = GetMainFrame()->document();
435 WebElement element = document.getElementById(WebString::fromUTF8("fname"));
436 ASSERT_FALSE(element.isNull());
437 WebInputElement fname_element = element.to<WebInputElement>();
438 SimulateUserInputChangeForElement(&fname_element, std::string("Rick"));
439
440 // Simulate user input in the second form so that a "no longer focused"
441 // message is sent for the first form.
442 document = GetMainFrame()->document();
443 element = document.getElementById(WebString::fromUTF8("fname2"));
444 ASSERT_FALSE(element.isNull());
445 fname_element = element.to<WebInputElement>();
446 SimulateUserInputChangeForElement(&fname_element, std::string("John"));
447
448 ProcessPendingMessages();
449
450 const IPC::Message* focus_no_longer_on_form_message =
451 render_thread_->sink().GetFirstMessageMatching(
452 AutofillHostMsg_FocusNoLongerOnForm::ID);
453 EXPECT_TRUE(focus_no_longer_on_form_message != NULL);
vabr (Chromium) 2015/12/07 09:47:33 Consider my comment for line 418 here as well.
Mathieu 2015/12/07 14:23:07 Done.
454 }
455
390 // Tests that submitting a form that has autocomplete="off" generates 456 // Tests that submitting a form that has autocomplete="off" generates
391 // WillSubmitForm and FormSubmitted messages. 457 // WillSubmitForm and FormSubmitted messages.
392 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { 458 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
393 // Load a form. 459 // Load a form.
394 LoadHTML("<html><form id='myForm' autocomplete='off'>" 460 LoadHTML("<html><form id='myForm' autocomplete='off'>"
395 "<input name='fname' value='Rick'/>" 461 "<input name='fname' value='Rick'/>"
396 "<input name='lname' value='Deckard'/>" 462 "<input name='lname' value='Deckard'/>"
397 "</form></html>"); 463 "</form></html>");
398 464
399 // Submit the form. 465 // Submit the form.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 508
443 // Submit the form. 509 // Submit the form.
444 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); 510 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();");
445 ProcessPendingMessages(); 511 ProcessPendingMessages();
446 512
447 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard", 513 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard",
448 true /* expect_submitted_message */); 514 true /* expect_submitted_message */);
449 } 515 }
450 516
451 } // namespace autofill 517 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698