| OLD | NEW |
| 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 <tuple> | 5 #include <tuple> |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // messages with the form fields. | 203 // messages with the form fields. |
| 204 TEST_F(FormAutocompleteTest, NormalFormSubmit) { | 204 TEST_F(FormAutocompleteTest, NormalFormSubmit) { |
| 205 // Load a form. | 205 // Load a form. |
| 206 LoadHTML( | 206 LoadHTML( |
| 207 "<html><form id='myForm' action='about:blank'>" | 207 "<html><form id='myForm' action='about:blank'>" |
| 208 "<input name='fname' value='Rick'/>" | 208 "<input name='fname' value='Rick'/>" |
| 209 "<input name='lname' value='Deckard'/></form></html>"); | 209 "<input name='lname' value='Deckard'/></form></html>"); |
| 210 | 210 |
| 211 // Submit the form. | 211 // Submit the form. |
| 212 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 212 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 213 ProcessPendingMessages(); | 213 base::RunLoop().RunUntilIdle(); |
| 214 | 214 |
| 215 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 215 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 216 true /* expect_submitted_message */); | 216 true /* expect_submitted_message */); |
| 217 } | 217 } |
| 218 | 218 |
| 219 // Tests that submitting a form that prevents the submit event from propagating | 219 // Tests that submitting a form that prevents the submit event from propagating |
| 220 // will only send the WillSubmitForm message. | 220 // will only send the WillSubmitForm message. |
| 221 TEST_F(FormAutocompleteTest, SubmitEventPrevented) { | 221 TEST_F(FormAutocompleteTest, SubmitEventPrevented) { |
| 222 // Load a form. | 222 // Load a form. |
| 223 LoadHTML( | 223 LoadHTML( |
| 224 "<html><form id='myForm'><input name='fname' value='Rick'/>" | 224 "<html><form id='myForm'><input name='fname' value='Rick'/>" |
| 225 "<input name='lname' value='Deckard'/><input type=submit></form>" | 225 "<input name='lname' value='Deckard'/><input type=submit></form>" |
| 226 "</html>"); | 226 "</html>"); |
| 227 | 227 |
| 228 // Submit the form. | 228 // Submit the form. |
| 229 ExecuteJavaScriptForTests( | 229 ExecuteJavaScriptForTests( |
| 230 "var form = document.forms[0];" | 230 "var form = document.forms[0];" |
| 231 "form.onsubmit = function(event) { event.preventDefault(); };" | 231 "form.onsubmit = function(event) { event.preventDefault(); };" |
| 232 "document.querySelector('input[type=submit]').click();"); | 232 "document.querySelector('input[type=submit]').click();"); |
| 233 ProcessPendingMessages(); | 233 base::RunLoop().RunUntilIdle(); |
| 234 | 234 |
| 235 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 235 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 236 false /* expect_submitted_message */); | 236 false /* expect_submitted_message */); |
| 237 } | 237 } |
| 238 | 238 |
| 239 // Tests that completing an Ajax request and having the form disappear will | 239 // Tests that completing an Ajax request and having the form disappear will |
| 240 // trigger submission from Autofill's point of view. | 240 // trigger submission from Autofill's point of view. |
| 241 TEST_F(FormAutocompleteTest, AjaxSucceeded_NoLongerVisible) { | 241 TEST_F(FormAutocompleteTest, AjaxSucceeded_NoLongerVisible) { |
| 242 // Load a form. | 242 // Load a form. |
| 243 LoadHTML( | 243 LoadHTML( |
| 244 "<html><form id='myForm' action='http://example.com/blade.php'>" | 244 "<html><form id='myForm' action='http://example.com/blade.php'>" |
| 245 "<input name='fname' id='fname' value='Bob'/>" | 245 "<input name='fname' id='fname' value='Bob'/>" |
| 246 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); | 246 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); |
| 247 | 247 |
| 248 // Simulate user input so that the form is "remembered". | 248 // Simulate user input so that the form is "remembered". |
| 249 WebDocument document = GetMainFrame()->GetDocument(); | 249 WebDocument document = GetMainFrame()->GetDocument(); |
| 250 WebElement element = document.GetElementById(WebString::FromUTF8("fname")); | 250 WebElement element = document.GetElementById(WebString::FromUTF8("fname")); |
| 251 ASSERT_FALSE(element.IsNull()); | 251 ASSERT_FALSE(element.IsNull()); |
| 252 WebInputElement fname_element = element.To<WebInputElement>(); | 252 WebInputElement fname_element = element.To<WebInputElement>(); |
| 253 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); | 253 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 254 | 254 |
| 255 // Simulate removing the form just before the ajax request completes. | 255 // Simulate removing the form just before the ajax request completes. |
| 256 ExecuteJavaScriptForTests( | 256 ExecuteJavaScriptForTests( |
| 257 "var element = document.getElementById('myForm');" | 257 "var element = document.getElementById('myForm');" |
| 258 "element.parentNode.removeChild(element);"); | 258 "element.parentNode.removeChild(element);"); |
| 259 | 259 |
| 260 // Simulate an Ajax request completing. | 260 // Simulate an Ajax request completing. |
| 261 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 261 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 262 ProcessPendingMessages(); | 262 base::RunLoop().RunUntilIdle(); |
| 263 | 263 |
| 264 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 264 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 265 true /* expect_submitted_message */); | 265 true /* expect_submitted_message */); |
| 266 } | 266 } |
| 267 | 267 |
| 268 // Tests that completing an Ajax request and having the form with a specific | 268 // Tests that completing an Ajax request and having the form with a specific |
| 269 // action disappear will trigger submission from Autofill's point of view, even | 269 // action disappear will trigger submission from Autofill's point of view, even |
| 270 // if there is another form with the same data but different action on the page. | 270 // if there is another form with the same data but different action on the page. |
| 271 TEST_F(FormAutocompleteTest, | 271 TEST_F(FormAutocompleteTest, |
| 272 AjaxSucceeded_NoLongerVisible_DifferentActionsSameData) { | 272 AjaxSucceeded_NoLongerVisible_DifferentActionsSameData) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 286 WebInputElement fname_element = element.To<WebInputElement>(); | 286 WebInputElement fname_element = element.To<WebInputElement>(); |
| 287 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); | 287 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 288 | 288 |
| 289 // Simulate removing the form just before the ajax request completes. | 289 // Simulate removing the form just before the ajax request completes. |
| 290 ExecuteJavaScriptForTests( | 290 ExecuteJavaScriptForTests( |
| 291 "var element = document.getElementById('myForm');" | 291 "var element = document.getElementById('myForm');" |
| 292 "element.parentNode.removeChild(element);"); | 292 "element.parentNode.removeChild(element);"); |
| 293 | 293 |
| 294 // Simulate an Ajax request completing. | 294 // Simulate an Ajax request completing. |
| 295 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 295 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 296 ProcessPendingMessages(); | 296 base::RunLoop().RunUntilIdle(); |
| 297 | 297 |
| 298 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 298 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 299 true /* expect_submitted_message */); | 299 true /* expect_submitted_message */); |
| 300 } | 300 } |
| 301 | 301 |
| 302 // Tests that completing an Ajax request and having the form with no action | 302 // Tests that completing an Ajax request and having the form with no action |
| 303 // specified disappear will trigger submission from Autofill's point of view, | 303 // specified disappear will trigger submission from Autofill's point of view, |
| 304 // even if there is still another form with no action in the page. It will | 304 // even if there is still another form with no action in the page. It will |
| 305 // compare field data within the forms. | 305 // compare field data within the forms. |
| 306 // TODO(kolos) Re-enable when the implementation of IsFormVisible is on-par | 306 // TODO(kolos) Re-enable when the implementation of IsFormVisible is on-par |
| (...skipping 20 matching lines...) Expand all Loading... |
| 327 WebInputElement fname_element = element.To<WebInputElement>(); | 327 WebInputElement fname_element = element.To<WebInputElement>(); |
| 328 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); | 328 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 329 | 329 |
| 330 // Simulate removing the form just before the ajax request completes. | 330 // Simulate removing the form just before the ajax request completes. |
| 331 ExecuteJavaScriptForTests( | 331 ExecuteJavaScriptForTests( |
| 332 "var element = document.getElementById('myForm');" | 332 "var element = document.getElementById('myForm');" |
| 333 "element.parentNode.removeChild(element);"); | 333 "element.parentNode.removeChild(element);"); |
| 334 | 334 |
| 335 // Simulate an Ajax request completing. | 335 // Simulate an Ajax request completing. |
| 336 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 336 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 337 ProcessPendingMessages(); | 337 base::RunLoop().RunUntilIdle(); |
| 338 | 338 |
| 339 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 339 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 340 true /* expect_submitted_message */); | 340 true /* expect_submitted_message */); |
| 341 } | 341 } |
| 342 | 342 |
| 343 // Tests that completing an Ajax request and having the form with no action | 343 // Tests that completing an Ajax request and having the form with no action |
| 344 // specified disappear will trigger submission from Autofill's point of view. | 344 // specified disappear will trigger submission from Autofill's point of view. |
| 345 TEST_F(FormAutocompleteTest, AjaxSucceeded_NoLongerVisible_NoAction) { | 345 TEST_F(FormAutocompleteTest, AjaxSucceeded_NoLongerVisible_NoAction) { |
| 346 // Load a form. | 346 // Load a form. |
| 347 LoadHTML( | 347 LoadHTML( |
| 348 "<html><form id='myForm'>" | 348 "<html><form id='myForm'>" |
| 349 "<input name='fname' id='fname' value='Bob'/>" | 349 "<input name='fname' id='fname' value='Bob'/>" |
| 350 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); | 350 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); |
| 351 | 351 |
| 352 // Simulate user input so that the form is "remembered". | 352 // Simulate user input so that the form is "remembered". |
| 353 WebDocument document = GetMainFrame()->GetDocument(); | 353 WebDocument document = GetMainFrame()->GetDocument(); |
| 354 WebElement element = document.GetElementById(WebString::FromUTF8("fname")); | 354 WebElement element = document.GetElementById(WebString::FromUTF8("fname")); |
| 355 ASSERT_FALSE(element.IsNull()); | 355 ASSERT_FALSE(element.IsNull()); |
| 356 WebInputElement fname_element = element.To<WebInputElement>(); | 356 WebInputElement fname_element = element.To<WebInputElement>(); |
| 357 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); | 357 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 358 | 358 |
| 359 // Simulate removing the form just before the ajax request completes. | 359 // Simulate removing the form just before the ajax request completes. |
| 360 ExecuteJavaScriptForTests("var element = document.getElementById('myForm');" | 360 ExecuteJavaScriptForTests("var element = document.getElementById('myForm');" |
| 361 "element.parentNode.removeChild(element);"); | 361 "element.parentNode.removeChild(element);"); |
| 362 | 362 |
| 363 // Simulate an Ajax request completing. | 363 // Simulate an Ajax request completing. |
| 364 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 364 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 365 ProcessPendingMessages(); | 365 base::RunLoop().RunUntilIdle(); |
| 366 | 366 |
| 367 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 367 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 368 true /* expect_submitted_message */); | 368 true /* expect_submitted_message */); |
| 369 } | 369 } |
| 370 | 370 |
| 371 // Tests that completing an Ajax request but leaving a form visible will not | 371 // Tests that completing an Ajax request but leaving a form visible will not |
| 372 // trigger submission from Autofill's point of view. | 372 // trigger submission from Autofill's point of view. |
| 373 TEST_F(FormAutocompleteTest, AjaxSucceeded_StillVisible) { | 373 TEST_F(FormAutocompleteTest, AjaxSucceeded_StillVisible) { |
| 374 // Load a form. | 374 // Load a form. |
| 375 LoadHTML( | 375 LoadHTML( |
| 376 "<html><form id='myForm' action='http://example.com/blade.php'>" | 376 "<html><form id='myForm' action='http://example.com/blade.php'>" |
| 377 "<input name='fname' id='fname' value='Bob'/>" | 377 "<input name='fname' id='fname' value='Bob'/>" |
| 378 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); | 378 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); |
| 379 | 379 |
| 380 // Simulate user input so that the form is "remembered". | 380 // Simulate user input so that the form is "remembered". |
| 381 WebDocument document = GetMainFrame()->GetDocument(); | 381 WebDocument document = GetMainFrame()->GetDocument(); |
| 382 WebElement element = document.GetElementById(WebString::FromUTF8("fname")); | 382 WebElement element = document.GetElementById(WebString::FromUTF8("fname")); |
| 383 ASSERT_FALSE(element.IsNull()); | 383 ASSERT_FALSE(element.IsNull()); |
| 384 WebInputElement fname_element = element.To<WebInputElement>(); | 384 WebInputElement fname_element = element.To<WebInputElement>(); |
| 385 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); | 385 SimulateUserInputChangeForElement(&fname_element, std::string("Rick")); |
| 386 | 386 |
| 387 // Simulate an Ajax request completing. | 387 // Simulate an Ajax request completing. |
| 388 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 388 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 389 ProcessPendingMessages(); | 389 base::RunLoop().RunUntilIdle(); |
| 390 | 390 |
| 391 // No submission messages sent. | 391 // No submission messages sent. |
| 392 VerifyNoSubmitMessagesReceived(fake_driver_); | 392 VerifyNoSubmitMessagesReceived(fake_driver_); |
| 393 } | 393 } |
| 394 | 394 |
| 395 // Tests that completing an Ajax request without any prior form interaction | 395 // Tests that completing an Ajax request without any prior form interaction |
| 396 // does not trigger form submission from Autofill's point of view. | 396 // does not trigger form submission from Autofill's point of view. |
| 397 TEST_F(FormAutocompleteTest, AjaxSucceeded_NoFormInteractionInvisible) { | 397 TEST_F(FormAutocompleteTest, AjaxSucceeded_NoFormInteractionInvisible) { |
| 398 // Load a form. | 398 // Load a form. |
| 399 LoadHTML( | 399 LoadHTML( |
| 400 "<html><form id='myForm' action='http://example.com/blade.php'>" | 400 "<html><form id='myForm' action='http://example.com/blade.php'>" |
| 401 "<input name='fname' id='fname' value='Bob'/>" | 401 "<input name='fname' id='fname' value='Bob'/>" |
| 402 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); | 402 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); |
| 403 | 403 |
| 404 // No form interaction. | 404 // No form interaction. |
| 405 | 405 |
| 406 // Simulate removing the form just before the ajax request completes. | 406 // Simulate removing the form just before the ajax request completes. |
| 407 ExecuteJavaScriptForTests("var element = document.getElementById('myForm');" | 407 ExecuteJavaScriptForTests("var element = document.getElementById('myForm');" |
| 408 "element.parentNode.removeChild(element);"); | 408 "element.parentNode.removeChild(element);"); |
| 409 | 409 |
| 410 // Simulate an Ajax request completing without prior user interaction. | 410 // Simulate an Ajax request completing without prior user interaction. |
| 411 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 411 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 412 ProcessPendingMessages(); | 412 base::RunLoop().RunUntilIdle(); |
| 413 | 413 |
| 414 // No submission messages sent. | 414 // No submission messages sent. |
| 415 VerifyNoSubmitMessagesReceived(fake_driver_); | 415 VerifyNoSubmitMessagesReceived(fake_driver_); |
| 416 } | 416 } |
| 417 | 417 |
| 418 // Tests that completing an Ajax request after having autofilled a form, | 418 // Tests that completing an Ajax request after having autofilled a form, |
| 419 // with the form disappearing, will trigger submission from Autofill's | 419 // with the form disappearing, will trigger submission from Autofill's |
| 420 // point of view. | 420 // point of view. |
| 421 TEST_F(FormAutocompleteTest, AjaxSucceeded_FilledFormIsInvisible) { | 421 TEST_F(FormAutocompleteTest, AjaxSucceeded_FilledFormIsInvisible) { |
| 422 // Load a form. | 422 // Load a form. |
| 423 LoadHTML( | 423 LoadHTML( |
| 424 "<html><form id='myForm' action='http://example.com/blade.php'>" | 424 "<html><form id='myForm' action='http://example.com/blade.php'>" |
| 425 "<input name='fname' id='fname'/>" | 425 "<input name='fname' id='fname'/>" |
| 426 "<input name='lname'/></form></html>"); | 426 "<input name='lname'/></form></html>"); |
| 427 | 427 |
| 428 // Simulate filling a form using Autofill. | 428 // Simulate filling a form using Autofill. |
| 429 SimulateOnFillForm(autofill_agent_, GetMainFrame()); | 429 SimulateOnFillForm(autofill_agent_, GetMainFrame()); |
| 430 | 430 |
| 431 // Simulate removing the form just before the ajax request completes. | 431 // Simulate removing the form just before the ajax request completes. |
| 432 ExecuteJavaScriptForTests("var element = document.getElementById('myForm');" | 432 ExecuteJavaScriptForTests("var element = document.getElementById('myForm');" |
| 433 "element.parentNode.removeChild(element);"); | 433 "element.parentNode.removeChild(element);"); |
| 434 | 434 |
| 435 // Simulate an Ajax request completing. | 435 // Simulate an Ajax request completing. |
| 436 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 436 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 437 ProcessPendingMessages(); | 437 base::RunLoop().RunUntilIdle(); |
| 438 | 438 |
| 439 VerifyReceivedRendererMessages(fake_driver_, "John", "Smith", | 439 VerifyReceivedRendererMessages(fake_driver_, "John", "Smith", |
| 440 true /* expect_submitted_message */); | 440 true /* expect_submitted_message */); |
| 441 } | 441 } |
| 442 | 442 |
| 443 // Tests that completing an Ajax request after having autofilled a form, | 443 // Tests that completing an Ajax request after having autofilled a form, |
| 444 // without the form disappearing, will not trigger submission from Autofill's | 444 // without the form disappearing, will not trigger submission from Autofill's |
| 445 // point of view. | 445 // point of view. |
| 446 TEST_F(FormAutocompleteTest, AjaxSucceeded_FilledFormStillVisible) { | 446 TEST_F(FormAutocompleteTest, AjaxSucceeded_FilledFormStillVisible) { |
| 447 // Load a form. | 447 // Load a form. |
| 448 LoadHTML( | 448 LoadHTML( |
| 449 "<html><form id='myForm' action='http://example.com/blade.php'>" | 449 "<html><form id='myForm' action='http://example.com/blade.php'>" |
| 450 "<input name='fname' id='fname' value='Rick'/>" | 450 "<input name='fname' id='fname' value='Rick'/>" |
| 451 "<input name='lname' value='Deckard'/></form></html>"); | 451 "<input name='lname' value='Deckard'/></form></html>"); |
| 452 | 452 |
| 453 // Simulate filling a form using Autofill. | 453 // Simulate filling a form using Autofill. |
| 454 SimulateOnFillForm(autofill_agent_, GetMainFrame()); | 454 SimulateOnFillForm(autofill_agent_, GetMainFrame()); |
| 455 | 455 |
| 456 // Form still visible. | 456 // Form still visible. |
| 457 | 457 |
| 458 // Simulate an Ajax request completing. | 458 // Simulate an Ajax request completing. |
| 459 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 459 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 460 ProcessPendingMessages(); | 460 base::RunLoop().RunUntilIdle(); |
| 461 | 461 |
| 462 // No submission messages sent. | 462 // No submission messages sent. |
| 463 VerifyNoSubmitMessagesReceived(fake_driver_); | 463 VerifyNoSubmitMessagesReceived(fake_driver_); |
| 464 } | 464 } |
| 465 | 465 |
| 466 // Tests that completing an Ajax request without a form present will still | 466 // Tests that completing an Ajax request without a form present will still |
| 467 // trigger submission, if all the inputs the user has modified disappear. | 467 // trigger submission, if all the inputs the user has modified disappear. |
| 468 TEST_F(FormAutocompleteTest, AjaxSucceeded_FormlessElements) { | 468 TEST_F(FormAutocompleteTest, AjaxSucceeded_FormlessElements) { |
| 469 // Load a "form." Note that kRequiredFieldsForUpload fields are required | 469 // Load a "form." Note that kRequiredFieldsForUpload fields are required |
| 470 // for the formless logic to trigger, so we add a throwaway third field. | 470 // for the formless logic to trigger, so we add a throwaway third field. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 481 WebInputElement fname_element = element.To<WebInputElement>(); | 481 WebInputElement fname_element = element.To<WebInputElement>(); |
| 482 SimulateUserInputChangeForElement(&fname_element, std::string("Kirby")); | 482 SimulateUserInputChangeForElement(&fname_element, std::string("Kirby")); |
| 483 | 483 |
| 484 // Remove element from view. | 484 // Remove element from view. |
| 485 ExecuteJavaScriptForTests( | 485 ExecuteJavaScriptForTests( |
| 486 "var element = document.getElementById('fname');" | 486 "var element = document.getElementById('fname');" |
| 487 "element.style.display = 'none';"); | 487 "element.style.display = 'none';"); |
| 488 | 488 |
| 489 // Simulate AJAX request. | 489 // Simulate AJAX request. |
| 490 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); | 490 static_cast<blink::WebAutofillClient*>(autofill_agent_)->AjaxSucceeded(); |
| 491 ProcessPendingMessages(); | 491 base::RunLoop().RunUntilIdle(); |
| 492 | 492 |
| 493 VerifyReceivedRendererMessages(fake_driver_, "Kirby", "Puckett", | 493 VerifyReceivedRendererMessages(fake_driver_, "Kirby", "Puckett", |
| 494 /* expect_submitted_message = */ true); | 494 /* expect_submitted_message = */ true); |
| 495 } | 495 } |
| 496 | 496 |
| 497 // Unit test for CollectFormlessElements. | 497 // Unit test for CollectFormlessElements. |
| 498 TEST_F(FormAutocompleteTest, CollectFormlessElements) { | 498 TEST_F(FormAutocompleteTest, CollectFormlessElements) { |
| 499 LoadHTML( | 499 LoadHTML( |
| 500 "<html><title>Checkout</title></head>" | 500 "<html><title>Checkout</title></head>" |
| 501 "<input type='text' name='text_input'/>" | 501 "<input type='text' name='text_input'/>" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { | 591 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { |
| 592 // Load a form. | 592 // Load a form. |
| 593 LoadHTML( | 593 LoadHTML( |
| 594 "<html><form id='myForm' autocomplete='off' action='about:blank'>" | 594 "<html><form id='myForm' autocomplete='off' action='about:blank'>" |
| 595 "<input name='fname' value='Rick'/>" | 595 "<input name='fname' value='Rick'/>" |
| 596 "<input name='lname' value='Deckard'/>" | 596 "<input name='lname' value='Deckard'/>" |
| 597 "</form></html>"); | 597 "</form></html>"); |
| 598 | 598 |
| 599 // Submit the form. | 599 // Submit the form. |
| 600 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 600 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 601 ProcessPendingMessages(); | 601 base::RunLoop().RunUntilIdle(); |
| 602 | 602 |
| 603 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 603 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 604 true /* expect_submitted_message */); | 604 true /* expect_submitted_message */); |
| 605 } | 605 } |
| 606 | 606 |
| 607 // Tests that fields with autocomplete off are submitted. | 607 // Tests that fields with autocomplete off are submitted. |
| 608 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { | 608 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { |
| 609 // Load a form. | 609 // Load a form. |
| 610 LoadHTML( | 610 LoadHTML( |
| 611 "<html><form id='myForm' action='about:blank'>" | 611 "<html><form id='myForm' action='about:blank'>" |
| 612 "<input name='fname' value='Rick'/>" | 612 "<input name='fname' value='Rick'/>" |
| 613 "<input name='lname' value='Deckard' autocomplete='off'/>" | 613 "<input name='lname' value='Deckard' autocomplete='off'/>" |
| 614 "</form></html>"); | 614 "</form></html>"); |
| 615 | 615 |
| 616 // Submit the form. | 616 // Submit the form. |
| 617 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 617 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 618 ProcessPendingMessages(); | 618 base::RunLoop().RunUntilIdle(); |
| 619 | 619 |
| 620 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 620 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 621 true /* expect_submitted_message */); | 621 true /* expect_submitted_message */); |
| 622 } | 622 } |
| 623 | 623 |
| 624 // Tests that submitting a form that has been dynamically set as autocomplete | 624 // Tests that submitting a form that has been dynamically set as autocomplete |
| 625 // off generates WillSubmitForm and FormSubmitted messages. | 625 // off generates WillSubmitForm and FormSubmitted messages. |
| 626 // Note: We previously did the opposite, for bug http://crbug.com/36520 | 626 // Note: We previously did the opposite, for bug http://crbug.com/36520 |
| 627 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { | 627 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { |
| 628 LoadHTML( | 628 LoadHTML( |
| 629 "<html><form id='myForm' action='about:blank'>" | 629 "<html><form id='myForm' action='about:blank'>" |
| 630 "<input name='fname' value='Rick'/>" | 630 "<input name='fname' value='Rick'/>" |
| 631 "<input name='lname' value='Deckard'/></form></html>"); | 631 "<input name='lname' value='Deckard'/></form></html>"); |
| 632 | 632 |
| 633 WebElement element = | 633 WebElement element = |
| 634 GetMainFrame()->GetDocument().GetElementById(blink::WebString("myForm")); | 634 GetMainFrame()->GetDocument().GetElementById(blink::WebString("myForm")); |
| 635 ASSERT_FALSE(element.IsNull()); | 635 ASSERT_FALSE(element.IsNull()); |
| 636 blink::WebFormElement form = element.To<blink::WebFormElement>(); | 636 blink::WebFormElement form = element.To<blink::WebFormElement>(); |
| 637 EXPECT_TRUE(form.AutoComplete()); | 637 EXPECT_TRUE(form.AutoComplete()); |
| 638 | 638 |
| 639 // Dynamically mark the form as autocomplete off. | 639 // Dynamically mark the form as autocomplete off. |
| 640 ExecuteJavaScriptForTests( | 640 ExecuteJavaScriptForTests( |
| 641 "document.getElementById('myForm')." | 641 "document.getElementById('myForm')." |
| 642 "setAttribute('autocomplete', 'off');"); | 642 "setAttribute('autocomplete', 'off');"); |
| 643 ProcessPendingMessages(); | 643 base::RunLoop().RunUntilIdle(); |
| 644 EXPECT_FALSE(form.AutoComplete()); | 644 EXPECT_FALSE(form.AutoComplete()); |
| 645 | 645 |
| 646 // Submit the form. | 646 // Submit the form. |
| 647 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 647 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 648 ProcessPendingMessages(); | 648 base::RunLoop().RunUntilIdle(); |
| 649 | 649 |
| 650 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 650 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 651 true /* expect_submitted_message */); | 651 true /* expect_submitted_message */); |
| 652 } | 652 } |
| 653 | 653 |
| 654 } // namespace autofill | 654 } // namespace autofill |
| OLD | NEW |