OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
| 7 #include "app/l10n_util.h" |
7 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
9 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
10 #include "base/string16.h" | 11 #include "base/string16.h" |
11 #include "base/tuple.h" | 12 #include "base/tuple.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/autofill_common_test.h" | 14 #include "chrome/browser/autofill/autofill_common_test.h" |
14 #include "chrome/browser/autofill/autofill_manager.h" | 15 #include "chrome/browser/autofill/autofill_manager.h" |
15 #include "chrome/browser/autofill/autofill_profile.h" | 16 #include "chrome/browser/autofill/autofill_profile.h" |
16 #include "chrome/browser/autofill/credit_card.h" | 17 #include "chrome/browser/autofill/credit_card.h" |
17 #include "chrome/browser/autofill/personal_data_manager.h" | 18 #include "chrome/browser/autofill/personal_data_manager.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
20 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 21 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
21 #include "chrome/browser/tab_contents/test_tab_contents.h" | 22 #include "chrome/browser/tab_contents/test_tab_contents.h" |
22 #include "chrome/common/ipc_test_sink.h" | 23 #include "chrome/common/ipc_test_sink.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "grit/generated_resources.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "webkit/glue/form_data.h" | 29 #include "webkit/glue/form_data.h" |
28 #include "webkit/glue/form_field.h" | 30 #include "webkit/glue/form_field.h" |
29 | 31 |
30 using webkit_glue::FormData; | 32 using webkit_glue::FormData; |
31 | 33 |
32 typedef Tuple5<int, | 34 typedef Tuple5<int, |
33 std::vector<string16>, | 35 std::vector<string16>, |
34 std::vector<string16>, | 36 std::vector<string16>, |
35 std::vector<string16>, | 37 std::vector<string16>, |
(...skipping 16 matching lines...) Expand all Loading... |
52 if (!(*it)->Label().compare(ASCIIToUTF16(label))) | 54 if (!(*it)->Label().compare(ASCIIToUTF16(label))) |
53 return *it; | 55 return *it; |
54 } | 56 } |
55 return NULL; | 57 return NULL; |
56 } | 58 } |
57 | 59 |
58 void AddProfile(AutoFillProfile* profile) { | 60 void AddProfile(AutoFillProfile* profile) { |
59 web_profiles_->push_back(profile); | 61 web_profiles_->push_back(profile); |
60 } | 62 } |
61 | 63 |
| 64 void ClearAutoFillProfiles() { |
| 65 web_profiles_.clear(); |
| 66 } |
| 67 |
| 68 void ClearCreditCards() { |
| 69 credit_cards_.clear(); |
| 70 } |
| 71 |
62 private: | 72 private: |
63 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { | 73 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { |
64 AutoFillProfile* profile = new AutoFillProfile; | 74 AutoFillProfile* profile = new AutoFillProfile; |
65 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron", | 75 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron", |
66 "Presley", "theking@gmail.com", "RCA", | 76 "Presley", "theking@gmail.com", "RCA", |
67 "3734 Elvis Presley Blvd.", "Apt. 10", | 77 "3734 Elvis Presley Blvd.", "Apt. 10", |
68 "Memphis", "Tennessee", "38116", "USA", | 78 "Memphis", "Tennessee", "38116", "USA", |
69 "12345678901", ""); | 79 "12345678901", ""); |
70 profile->set_guid("00000000-0000-0000-0000-000000000001"); | 80 profile->set_guid("00000000-0000-0000-0000-000000000001"); |
71 profiles->push_back(profile); | 81 profiles->push_back(profile); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 forms.push_back(form); | 296 forms.push_back(form); |
287 autofill_manager_->FormsSeen(forms); | 297 autofill_manager_->FormsSeen(forms); |
288 | 298 |
289 // The page ID sent to the AutoFillManager from the RenderView, used to send | 299 // The page ID sent to the AutoFillManager from the RenderView, used to send |
290 // an IPC message back to the renderer. | 300 // an IPC message back to the renderer. |
291 const int kPageID = 1; | 301 const int kPageID = 1; |
292 | 302 |
293 webkit_glue::FormField field; | 303 webkit_glue::FormField field; |
294 autofill_test::CreateTestFormField( | 304 autofill_test::CreateTestFormField( |
295 "First Name", "firstname", "", "text", &field); | 305 "First Name", "firstname", "", "text", &field); |
296 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 306 rvh()->ResetAutoFillState(kPageID, false); |
| 307 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
297 | 308 |
298 // No suggestions provided, so send an empty vector as the results. | 309 // No suggestions provided, so send an empty vector as the results. |
299 // This triggers the combined message send. | 310 // This triggers the combined message send. |
300 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 311 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
301 | 312 |
302 // Test that we sent the right message to the renderer. | 313 // Test that we sent the right message to the renderer. |
303 int page_id = 0; | 314 int page_id = 0; |
304 std::vector<string16> values; | 315 std::vector<string16> values; |
305 std::vector<string16> labels; | 316 std::vector<string16> labels; |
306 std::vector<string16> icons; | 317 std::vector<string16> icons; |
307 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 318 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
308 &icons)); | 319 &icons)); |
309 EXPECT_EQ(kPageID, page_id); | 320 EXPECT_EQ(kPageID, page_id); |
310 ASSERT_EQ(2U, values.size()); | 321 ASSERT_EQ(2U, values.size()); |
(...skipping 20 matching lines...) Expand all Loading... |
331 forms.push_back(form); | 342 forms.push_back(form); |
332 autofill_manager_->FormsSeen(forms); | 343 autofill_manager_->FormsSeen(forms); |
333 | 344 |
334 // The page ID sent to the AutoFillManager from the RenderView, used to send | 345 // The page ID sent to the AutoFillManager from the RenderView, used to send |
335 // an IPC message back to the renderer. | 346 // an IPC message back to the renderer. |
336 const int kPageID = 1; | 347 const int kPageID = 1; |
337 | 348 |
338 webkit_glue::FormField field; | 349 webkit_glue::FormField field; |
339 autofill_test::CreateTestFormField( | 350 autofill_test::CreateTestFormField( |
340 "First Name", "firstname", "E", "text", &field); | 351 "First Name", "firstname", "E", "text", &field); |
341 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 352 rvh()->ResetAutoFillState(kPageID, false); |
| 353 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
342 | 354 |
343 // No suggestions provided, so send an empty vector as the results. | 355 // No suggestions provided, so send an empty vector as the results. |
344 // This triggers the combined message send. | 356 // This triggers the combined message send. |
345 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 357 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
346 | 358 |
347 // Test that we sent the right message to the renderer. | 359 // Test that we sent the right message to the renderer. |
348 int page_id = 0; | 360 int page_id = 0; |
349 std::vector<string16> values; | 361 std::vector<string16> values; |
350 std::vector<string16> labels; | 362 std::vector<string16> labels; |
351 std::vector<string16> icons; | 363 std::vector<string16> icons; |
352 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 364 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
353 &icons)); | 365 &icons)); |
354 EXPECT_EQ(kPageID, page_id); | 366 EXPECT_EQ(kPageID, page_id); |
355 ASSERT_EQ(1U, values.size()); | 367 ASSERT_EQ(1U, values.size()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 std::vector<FormData> forms; | 399 std::vector<FormData> forms; |
388 forms.push_back(form); | 400 forms.push_back(form); |
389 autofill_manager_->FormsSeen(forms); | 401 autofill_manager_->FormsSeen(forms); |
390 | 402 |
391 // The page ID sent to the AutoFillManager from the RenderView, used to send | 403 // The page ID sent to the AutoFillManager from the RenderView, used to send |
392 // an IPC message back to the renderer. | 404 // an IPC message back to the renderer. |
393 const int kPageID = 1; | 405 const int kPageID = 1; |
394 | 406 |
395 autofill_test::CreateTestFormField( | 407 autofill_test::CreateTestFormField( |
396 "Username", "username", "", "text", &field); | 408 "Username", "username", "", "text", &field); |
| 409 rvh()->ResetAutoFillState(kPageID, false); |
397 EXPECT_FALSE( | 410 EXPECT_FALSE( |
398 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 411 autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 412 } |
| 413 |
| 414 // Test that we return a warning explaining that autofill suggestions are |
| 415 // unavailable when the website specifies autocomplete="off". |
| 416 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabled) { |
| 417 FormData form; |
| 418 CreateTestAddressFormData(&form); |
| 419 |
| 420 // Set up our FormStructures. |
| 421 std::vector<FormData> forms; |
| 422 forms.push_back(form); |
| 423 autofill_manager_->FormsSeen(forms); |
| 424 |
| 425 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 426 // an IPC message back to the renderer. |
| 427 const int kPageID = 1; |
| 428 |
| 429 webkit_glue::FormField field; |
| 430 autofill_test::CreateTestFormField( |
| 431 "First Name", "firstname", "", "text", &field); |
| 432 rvh()->ResetAutoFillState(kPageID, true); |
| 433 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, true)); |
| 434 |
| 435 // No suggestions provided, so send an empty vector as the results. |
| 436 // This triggers the combined message send. |
| 437 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 438 |
| 439 // Test that we sent the right message to the renderer. |
| 440 int page_id = 0; |
| 441 std::vector<string16> values; |
| 442 std::vector<string16> labels; |
| 443 std::vector<string16> icons; |
| 444 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 445 &icons)); |
| 446 EXPECT_EQ(kPageID, page_id); |
| 447 ASSERT_EQ(1U, values.size()); |
| 448 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED), |
| 449 values[0]); |
| 450 ASSERT_EQ(1U, labels.size()); |
| 451 EXPECT_EQ(string16(), labels[0]); |
| 452 ASSERT_EQ(1U, icons.size()); |
| 453 EXPECT_EQ(string16(), icons[0]); |
| 454 |
| 455 // Clear the test profiles and try again -- we shouldn't return a warning. |
| 456 process()->sink().ClearMessages(); |
| 457 const int kPageID2 = 2; |
| 458 rvh()->ResetAutoFillState(kPageID2, true); |
| 459 |
| 460 test_personal_data_->ClearAutoFillProfiles(); |
| 461 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, true)); |
| 462 |
| 463 // Now add some Autocomplete suggestions. We should now return the same |
| 464 // warning as before. |
| 465 std::vector<string16> suggestions; |
| 466 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 467 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 468 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 469 |
| 470 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 471 &icons)); |
| 472 EXPECT_EQ(kPageID2, page_id); |
| 473 ASSERT_EQ(1U, values.size()); |
| 474 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED), |
| 475 values[0]); |
| 476 ASSERT_EQ(1U, labels.size()); |
| 477 EXPECT_EQ(string16(), labels[0]); |
| 478 ASSERT_EQ(1U, icons.size()); |
| 479 EXPECT_EQ(string16(), icons[0]); |
| 480 } |
| 481 |
| 482 // Test that we return a warning explaining that autofill suggestions are |
| 483 // unavailable when the form method is GET rather than POST. |
| 484 TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) { |
| 485 FormData form; |
| 486 CreateTestAddressFormData(&form); |
| 487 form.method = ASCIIToUTF16("GET"); |
| 488 |
| 489 // Set up our FormStructures. |
| 490 std::vector<FormData> forms; |
| 491 forms.push_back(form); |
| 492 autofill_manager_->FormsSeen(forms); |
| 493 |
| 494 // The page ID sent to the AutoFillManager from the RenderView, used to send |
| 495 // an IPC message back to the renderer. |
| 496 const int kPageID = 1; |
| 497 |
| 498 webkit_glue::FormField field; |
| 499 autofill_test::CreateTestFormField( |
| 500 "First Name", "firstname", "", "text", &field); |
| 501 rvh()->ResetAutoFillState(kPageID, false); |
| 502 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 503 |
| 504 // No suggestions provided, so send an empty vector as the results. |
| 505 // This triggers the combined message send. |
| 506 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 507 |
| 508 // Test that we sent the right message to the renderer. |
| 509 int page_id = 0; |
| 510 std::vector<string16> values; |
| 511 std::vector<string16> labels; |
| 512 std::vector<string16> icons; |
| 513 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 514 &icons)); |
| 515 EXPECT_EQ(kPageID, page_id); |
| 516 ASSERT_EQ(1U, values.size()); |
| 517 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_AUTOFILL_DISABLED), |
| 518 values[0]); |
| 519 ASSERT_EQ(1U, labels.size()); |
| 520 EXPECT_EQ(string16(), labels[0]); |
| 521 ASSERT_EQ(1U, icons.size()); |
| 522 EXPECT_EQ(string16(), icons[0]); |
| 523 |
| 524 // Clear the test profiles and try again -- we shouldn't return a warning. |
| 525 process()->sink().ClearMessages(); |
| 526 const int kPageID2 = 2; |
| 527 rvh()->ResetAutoFillState(kPageID2, false); |
| 528 |
| 529 test_personal_data_->ClearAutoFillProfiles(); |
| 530 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 531 |
| 532 // Now add some Autocomplete suggestions. We should show the autocomplete |
| 533 // suggestions rather than the warning. |
| 534 std::vector<string16> suggestions; |
| 535 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 536 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 537 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 538 |
| 539 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 540 &icons)); |
| 541 EXPECT_EQ(kPageID2, page_id); |
| 542 ASSERT_EQ(2U, values.size()); |
| 543 EXPECT_EQ(ASCIIToUTF16("Jay"), values[0]); |
| 544 EXPECT_EQ(ASCIIToUTF16("Jason"), values[1]); |
| 545 ASSERT_EQ(2U, labels.size()); |
| 546 EXPECT_EQ(string16(), labels[0]); |
| 547 EXPECT_EQ(string16(), labels[1]); |
| 548 ASSERT_EQ(2U, icons.size()); |
| 549 EXPECT_EQ(string16(), icons[0]); |
| 550 EXPECT_EQ(string16(), icons[1]); |
399 } | 551 } |
400 | 552 |
401 // Test that we return all credit card profile suggestions when all form fields | 553 // Test that we return all credit card profile suggestions when all form fields |
402 // are empty. | 554 // are empty. |
403 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { | 555 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { |
404 FormData form; | 556 FormData form; |
405 CreateTestCreditCardFormData(&form, true); | 557 CreateTestCreditCardFormData(&form, true); |
406 | 558 |
407 // Set up our FormStructures. | 559 // Set up our FormStructures. |
408 std::vector<FormData> forms; | 560 std::vector<FormData> forms; |
409 forms.push_back(form); | 561 forms.push_back(form); |
410 autofill_manager_->FormsSeen(forms); | 562 autofill_manager_->FormsSeen(forms); |
411 | 563 |
412 // The page ID sent to the AutoFillManager from the RenderView, used to send | 564 // The page ID sent to the AutoFillManager from the RenderView, used to send |
413 // an IPC message back to the renderer. | 565 // an IPC message back to the renderer. |
414 const int kPageID = 1; | 566 const int kPageID = 1; |
415 | 567 |
416 webkit_glue::FormField field; | 568 webkit_glue::FormField field; |
417 autofill_test::CreateTestFormField( | 569 autofill_test::CreateTestFormField( |
418 "Card Number", "cardnumber", "", "text", &field); | 570 "Card Number", "cardnumber", "", "text", &field); |
419 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 571 rvh()->ResetAutoFillState(kPageID, false); |
| 572 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
420 | 573 |
421 // No suggestions provided, so send an empty vector as the results. | 574 // No suggestions provided, so send an empty vector as the results. |
422 // This triggers the combined message send. | 575 // This triggers the combined message send. |
423 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 576 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
424 | 577 |
425 // Test that we sent the right message to the renderer. | 578 // Test that we sent the right message to the renderer. |
426 int page_id = 0; | 579 int page_id = 0; |
427 std::vector<string16> values; | 580 std::vector<string16> values; |
428 std::vector<string16> labels; | 581 std::vector<string16> labels; |
429 std::vector<string16> icons; | 582 std::vector<string16> icons; |
430 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 583 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
431 &icons)); | 584 &icons)); |
432 EXPECT_EQ(kPageID, page_id); | 585 EXPECT_EQ(kPageID, page_id); |
433 ASSERT_EQ(2U, values.size()); | 586 ASSERT_EQ(2U, values.size()); |
(...skipping 18 matching lines...) Expand all Loading... |
452 forms.push_back(form); | 605 forms.push_back(form); |
453 autofill_manager_->FormsSeen(forms); | 606 autofill_manager_->FormsSeen(forms); |
454 | 607 |
455 // The page ID sent to the AutoFillManager from the RenderView, used to send | 608 // The page ID sent to the AutoFillManager from the RenderView, used to send |
456 // an IPC message back to the renderer. | 609 // an IPC message back to the renderer. |
457 const int kPageID = 1; | 610 const int kPageID = 1; |
458 | 611 |
459 webkit_glue::FormField field; | 612 webkit_glue::FormField field; |
460 autofill_test::CreateTestFormField( | 613 autofill_test::CreateTestFormField( |
461 "Card Number", "cardnumber", "4", "text", &field); | 614 "Card Number", "cardnumber", "4", "text", &field); |
462 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 615 rvh()->ResetAutoFillState(kPageID, false); |
| 616 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
463 | 617 |
464 // No suggestions provided, so send an empty vector as the results. | 618 // No suggestions provided, so send an empty vector as the results. |
465 // This triggers the combined message send. | 619 // This triggers the combined message send. |
466 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 620 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
467 | 621 |
468 // Test that we sent the right message to the renderer. | 622 // Test that we sent the right message to the renderer. |
469 int page_id = 0; | 623 int page_id = 0; |
470 std::vector<string16> values; | 624 std::vector<string16> values; |
471 std::vector<string16> labels; | 625 std::vector<string16> labels; |
472 std::vector<string16> icons; | 626 std::vector<string16> icons; |
473 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 627 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
474 &icons)); | 628 &icons)); |
475 EXPECT_EQ(kPageID, page_id); | 629 EXPECT_EQ(kPageID, page_id); |
476 ASSERT_EQ(1U, values.size()); | 630 ASSERT_EQ(1U, values.size()); |
(...skipping 15 matching lines...) Expand all Loading... |
492 forms.push_back(form); | 646 forms.push_back(form); |
493 autofill_manager_->FormsSeen(forms); | 647 autofill_manager_->FormsSeen(forms); |
494 | 648 |
495 // The page ID sent to the AutoFillManager from the RenderView, used to send | 649 // The page ID sent to the AutoFillManager from the RenderView, used to send |
496 // an IPC message back to the renderer. | 650 // an IPC message back to the renderer. |
497 const int kPageID = 1; | 651 const int kPageID = 1; |
498 | 652 |
499 webkit_glue::FormField field; | 653 webkit_glue::FormField field; |
500 autofill_test::CreateTestFormField( | 654 autofill_test::CreateTestFormField( |
501 "Name on Card", "nameoncard", "", "text", &field); | 655 "Name on Card", "nameoncard", "", "text", &field); |
502 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 656 rvh()->ResetAutoFillState(kPageID, false); |
| 657 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
503 | 658 |
504 // No suggestions provided, so send an empty vector as the results. | 659 // No suggestions provided, so send an empty vector as the results. |
505 // This triggers the combined message send. | 660 // This triggers the combined message send. |
506 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 661 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
507 | 662 |
508 // Test that we sent the right message to the renderer. | 663 // Test that we sent the right message to the renderer. |
509 int page_id = 0; | 664 int page_id = 0; |
510 std::vector<string16> values; | 665 std::vector<string16> values; |
511 std::vector<string16> labels; | 666 std::vector<string16> labels; |
512 std::vector<string16> icons; | 667 std::vector<string16> icons; |
513 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 668 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
514 &icons)); | 669 &icons)); |
515 EXPECT_EQ(kPageID, page_id); | 670 EXPECT_EQ(kPageID, page_id); |
516 ASSERT_EQ(2U, values.size()); | 671 ASSERT_EQ(2U, values.size()); |
517 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); | 672 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); |
518 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); | 673 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); |
519 ASSERT_EQ(2U, labels.size()); | 674 ASSERT_EQ(2U, labels.size()); |
520 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); | 675 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); |
521 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); | 676 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); |
522 ASSERT_EQ(2U, icons.size()); | 677 ASSERT_EQ(2U, icons.size()); |
523 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); | 678 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); |
524 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); | 679 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); |
525 } | 680 } |
526 | 681 |
527 // Test that we return no credit card profile suggestions when the form is not | 682 // Test that we return a warning explaining that credit card profile suggestions |
528 // https. | 683 // are unavailable when the form is not https. |
529 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { | 684 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { |
530 FormData form; | 685 FormData form; |
531 CreateTestCreditCardFormData(&form, false); | 686 CreateTestCreditCardFormData(&form, false); |
532 | 687 |
533 // Set up our FormStructures. | 688 // Set up our FormStructures. |
534 std::vector<FormData> forms; | 689 std::vector<FormData> forms; |
535 forms.push_back(form); | 690 forms.push_back(form); |
536 autofill_manager_->FormsSeen(forms); | 691 autofill_manager_->FormsSeen(forms); |
537 | 692 |
538 // The page ID sent to the AutoFillManager from the RenderView, used to send | 693 // The page ID sent to the AutoFillManager from the RenderView, used to send |
539 // an IPC message back to the renderer. | 694 // an IPC message back to the renderer. |
540 const int kPageID = 1; | 695 const int kPageID = 1; |
541 | 696 |
542 webkit_glue::FormField field; | 697 webkit_glue::FormField field; |
543 autofill_test::CreateTestFormField( | 698 autofill_test::CreateTestFormField( |
544 "Card Number", "cardnumber", "", "text", &field); | 699 "Card Number", "cardnumber", "", "text", &field); |
545 EXPECT_FALSE( | 700 rvh()->ResetAutoFillState(kPageID, false); |
546 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 701 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 702 |
| 703 // No suggestions provided, so send an empty vector as the results. |
| 704 // This triggers the combined message send. |
| 705 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 706 |
| 707 // Test that we sent the right message to the renderer. |
| 708 int page_id = 0; |
| 709 std::vector<string16> values; |
| 710 std::vector<string16> labels; |
| 711 std::vector<string16> icons; |
| 712 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 713 &icons)); |
| 714 EXPECT_EQ(kPageID, page_id); |
| 715 ASSERT_EQ(1U, values.size()); |
| 716 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 717 values[0]); |
| 718 ASSERT_EQ(1U, labels.size()); |
| 719 EXPECT_EQ(string16(), labels[0]); |
| 720 ASSERT_EQ(1U, icons.size()); |
| 721 EXPECT_EQ(string16(), icons[0]); |
| 722 |
| 723 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 724 process()->sink().ClearMessages(); |
| 725 const int kPageID2 = 2; |
| 726 rvh()->ResetAutoFillState(kPageID2, false); |
| 727 |
| 728 test_personal_data_->ClearCreditCards(); |
| 729 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 730 |
| 731 // Now add some Autocomplete suggestions. We should show the autocomplete |
| 732 // suggestions rather than the warning. |
| 733 std::vector<string16> suggestions; |
| 734 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 735 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 736 rvh()->AutocompleteSuggestionsReturned(suggestions); |
| 737 |
| 738 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 739 &icons)); |
| 740 EXPECT_EQ(kPageID2, page_id); |
| 741 ASSERT_EQ(2U, values.size()); |
| 742 EXPECT_EQ(ASCIIToUTF16("Jay"), values[0]); |
| 743 EXPECT_EQ(ASCIIToUTF16("Jason"), values[1]); |
| 744 ASSERT_EQ(2U, labels.size()); |
| 745 EXPECT_EQ(string16(), labels[0]); |
| 746 EXPECT_EQ(string16(), labels[1]); |
| 747 ASSERT_EQ(2U, icons.size()); |
| 748 EXPECT_EQ(string16(), icons[0]); |
| 749 EXPECT_EQ(string16(), icons[1]); |
547 } | 750 } |
548 | 751 |
549 // Test that we return profile and credit card suggestions for combined forms. | 752 // Test that we return profile and credit card suggestions for combined forms. |
550 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { | 753 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { |
551 FormData form; | 754 FormData form; |
552 CreateTestAddressFormData(&form); | 755 CreateTestAddressFormData(&form); |
553 CreateTestCreditCardFormData(&form, true); | 756 CreateTestCreditCardFormData(&form, true); |
554 | 757 |
555 // Set up our FormStructures. | 758 // Set up our FormStructures. |
556 std::vector<FormData> forms; | 759 std::vector<FormData> forms; |
557 forms.push_back(form); | 760 forms.push_back(form); |
558 autofill_manager_->FormsSeen(forms); | 761 autofill_manager_->FormsSeen(forms); |
559 | 762 |
560 // The page ID sent to the AutoFillManager from the RenderView, used to send | 763 // The page ID sent to the AutoFillManager from the RenderView, used to send |
561 // an IPC message back to the renderer. | 764 // an IPC message back to the renderer. |
562 const int kPageID = 1; | 765 const int kPageID = 1; |
563 | 766 |
564 webkit_glue::FormField field; | 767 webkit_glue::FormField field; |
565 autofill_test::CreateTestFormField( | 768 autofill_test::CreateTestFormField( |
566 "First Name", "firstname", "", "text", &field); | 769 "First Name", "firstname", "", "text", &field); |
567 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 770 rvh()->ResetAutoFillState(kPageID, false); |
| 771 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
568 | 772 |
569 // No suggestions provided, so send an empty vector as the results. | 773 // No suggestions provided, so send an empty vector as the results. |
570 // This triggers the combined message send. | 774 // This triggers the combined message send. |
571 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 775 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
572 | 776 |
573 // Test that we sent the right address suggestions to the renderer. | 777 // Test that we sent the right address suggestions to the renderer. |
574 int page_id = 0; | 778 int page_id = 0; |
575 std::vector<string16> values; | 779 std::vector<string16> values; |
576 std::vector<string16> labels; | 780 std::vector<string16> labels; |
577 std::vector<string16> icons; | 781 std::vector<string16> icons; |
578 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 782 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
579 &icons)); | 783 &icons)); |
580 EXPECT_EQ(kPageID, page_id); | 784 EXPECT_EQ(kPageID, page_id); |
581 ASSERT_EQ(2U, values.size()); | 785 ASSERT_EQ(2U, values.size()); |
582 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); | 786 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); |
583 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); | 787 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); |
584 ASSERT_EQ(2U, labels.size()); | 788 ASSERT_EQ(2U, labels.size()); |
585 // Inferred labels now include full first relevant field, which in this case | 789 // Inferred labels now include full first relevant field, which in this case |
586 // the address #1. | 790 // the address #1. |
587 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); | 791 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); |
588 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); | 792 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); |
589 ASSERT_EQ(2U, icons.size()); | 793 ASSERT_EQ(2U, icons.size()); |
590 EXPECT_EQ(string16(), icons[0]); | 794 EXPECT_EQ(string16(), icons[0]); |
591 EXPECT_EQ(string16(), icons[1]); | 795 EXPECT_EQ(string16(), icons[1]); |
592 | 796 |
593 process()->sink().ClearMessages(); | 797 process()->sink().ClearMessages(); |
594 autofill_test::CreateTestFormField( | 798 autofill_test::CreateTestFormField( |
595 "Card Number", "cardnumber", "", "text", &field); | 799 "Card Number", "cardnumber", "", "text", &field); |
596 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 800 rvh()->ResetAutoFillState(kPageID, false); |
| 801 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
597 | 802 |
598 // No suggestions provided, so send an empty vector as the results. | 803 // No suggestions provided, so send an empty vector as the results. |
599 // This triggers the combined message send. | 804 // This triggers the combined message send. |
600 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 805 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
601 | 806 |
602 // Test that we sent the credit card suggestions to the renderer. | 807 // Test that we sent the credit card suggestions to the renderer. |
603 page_id = 0; | 808 page_id = 0; |
604 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 809 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
605 &icons)); | 810 &icons)); |
606 EXPECT_EQ(kPageID, page_id); | 811 EXPECT_EQ(kPageID, page_id); |
607 ASSERT_EQ(2U, values.size()); | 812 ASSERT_EQ(2U, values.size()); |
608 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); | 813 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); |
609 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); | 814 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); |
610 ASSERT_EQ(2U, labels.size()); | 815 ASSERT_EQ(2U, labels.size()); |
611 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); | 816 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); |
612 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); | 817 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); |
613 ASSERT_EQ(2U, icons.size()); | 818 ASSERT_EQ(2U, icons.size()); |
614 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); | 819 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); |
615 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); | 820 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); |
616 } | 821 } |
617 | 822 |
618 // Test that for non-https forms with both address and credit card fields, we | 823 // Test that for non-https forms with both address and credit card fields, we |
619 // only return address suggestions. | 824 // only return address suggestions. Instead of credit card suggestions, we |
| 825 // should return a warning explaining that credit card profile suggestions are |
| 826 // unavailable when the form is not https. |
620 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { | 827 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { |
621 FormData form; | 828 FormData form; |
622 CreateTestAddressFormData(&form); | 829 CreateTestAddressFormData(&form); |
623 CreateTestCreditCardFormData(&form, false); | 830 CreateTestCreditCardFormData(&form, false); |
624 | 831 |
625 // Set up our FormStructures. | 832 // Set up our FormStructures. |
626 std::vector<FormData> forms; | 833 std::vector<FormData> forms; |
627 forms.push_back(form); | 834 forms.push_back(form); |
628 autofill_manager_->FormsSeen(forms); | 835 autofill_manager_->FormsSeen(forms); |
629 | 836 |
630 // The page ID sent to the AutoFillManager from the RenderView, used to send | 837 // The page ID sent to the AutoFillManager from the RenderView, used to send |
631 // an IPC message back to the renderer. | 838 // an IPC message back to the renderer. |
632 const int kPageID = 1; | 839 const int kPageID = 1; |
633 | 840 |
634 webkit_glue::FormField field; | 841 webkit_glue::FormField field; |
635 autofill_test::CreateTestFormField( | 842 autofill_test::CreateTestFormField( |
636 "First Name", "firstname", "", "text", &field); | 843 "First Name", "firstname", "", "text", &field); |
637 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 844 rvh()->ResetAutoFillState(kPageID, false); |
| 845 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
638 | 846 |
639 // No suggestions provided, so send an empty vector as the results. | 847 // No suggestions provided, so send an empty vector as the results. |
640 // This triggers the combined message send. | 848 // This triggers the combined message send. |
641 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 849 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
642 | 850 |
643 // Test that we sent the right address suggestions to the renderer. | 851 // Test that we sent the right address suggestions to the renderer. |
644 int page_id = 0; | 852 int page_id = 0; |
645 std::vector<string16> values; | 853 std::vector<string16> values; |
646 std::vector<string16> labels; | 854 std::vector<string16> labels; |
647 std::vector<string16> icons; | 855 std::vector<string16> icons; |
648 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 856 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
649 &icons)); | 857 &icons)); |
650 EXPECT_EQ(kPageID, page_id); | 858 EXPECT_EQ(kPageID, page_id); |
651 ASSERT_EQ(2U, values.size()); | 859 ASSERT_EQ(2U, values.size()); |
652 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); | 860 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); |
653 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); | 861 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); |
654 ASSERT_EQ(2U, labels.size()); | 862 ASSERT_EQ(2U, labels.size()); |
655 // Inferred labels now include full first relevant field, which in this case | 863 // Inferred labels now include full first relevant field, which in this case |
656 // the address #1. | 864 // the address #1. |
657 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); | 865 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); |
658 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); | 866 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); |
659 ASSERT_EQ(2U, icons.size()); | 867 ASSERT_EQ(2U, icons.size()); |
660 EXPECT_EQ(string16(), icons[0]); | 868 EXPECT_EQ(string16(), icons[0]); |
661 EXPECT_EQ(string16(), icons[1]); | 869 EXPECT_EQ(string16(), icons[1]); |
662 | 870 |
| 871 process()->sink().ClearMessages(); |
663 autofill_test::CreateTestFormField( | 872 autofill_test::CreateTestFormField( |
664 "Card Number", "cardnumber", "", "text", &field); | 873 "Card Number", "cardnumber", "", "text", &field); |
665 EXPECT_FALSE( | 874 rvh()->ResetAutoFillState(kPageID, false); |
666 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 875 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
| 876 |
| 877 // No suggestions provided, so send an empty vector as the results. |
| 878 // This triggers the combined message send. |
| 879 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
| 880 |
| 881 // Test that we sent the right message to the renderer. |
| 882 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
| 883 &icons)); |
| 884 EXPECT_EQ(kPageID, page_id); |
| 885 ASSERT_EQ(1U, values.size()); |
| 886 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 887 values[0]); |
| 888 ASSERT_EQ(1U, labels.size()); |
| 889 EXPECT_EQ(string16(), labels[0]); |
| 890 ASSERT_EQ(1U, icons.size()); |
| 891 EXPECT_EQ(string16(), icons[0]); |
| 892 |
| 893 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 894 test_personal_data_->ClearCreditCards(); |
| 895 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
667 } | 896 } |
668 | 897 |
669 // Test that we correctly combine autofill and autocomplete suggestions. | 898 // Test that we correctly combine autofill and autocomplete suggestions. |
670 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { | 899 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { |
671 FormData form; | 900 FormData form; |
672 CreateTestAddressFormData(&form); | 901 CreateTestAddressFormData(&form); |
673 | 902 |
674 // Set up our FormStructures. | 903 // Set up our FormStructures. |
675 std::vector<FormData> forms; | 904 std::vector<FormData> forms; |
676 forms.push_back(form); | 905 forms.push_back(form); |
677 autofill_manager_->FormsSeen(forms); | 906 autofill_manager_->FormsSeen(forms); |
678 | 907 |
679 // The page ID sent to the AutoFillManager from the RenderView, used to send | 908 // The page ID sent to the AutoFillManager from the RenderView, used to send |
680 // an IPC message back to the renderer. | 909 // an IPC message back to the renderer. |
681 const int kPageID = 1; | 910 const int kPageID = 1; |
682 | 911 |
683 webkit_glue::FormField field; | 912 webkit_glue::FormField field; |
684 autofill_test::CreateTestFormField( | 913 autofill_test::CreateTestFormField( |
685 "First Name", "firstname", "", "text", &field); | 914 "First Name", "firstname", "", "text", &field); |
686 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field)); | 915 rvh()->ResetAutoFillState(kPageID, false); |
| 916 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field, false)); |
687 | 917 |
688 // Add some Autocomplete suggestions. | 918 // Add some Autocomplete suggestions. |
689 // This triggers the combined message send. | 919 // This triggers the combined message send. |
690 std::vector<string16> suggestions; | 920 std::vector<string16> suggestions; |
691 suggestions.push_back(ASCIIToUTF16("Jay")); | 921 suggestions.push_back(ASCIIToUTF16("Jay")); |
692 suggestions.push_back(ASCIIToUTF16("Jason")); | 922 suggestions.push_back(ASCIIToUTF16("Jason")); |
693 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions); | 923 rvh()->AutocompleteSuggestionsReturned(suggestions); |
694 | 924 |
695 // Test that we sent the right message to the renderer. | 925 // Test that we sent the right message to the renderer. |
696 int page_id = 0; | 926 int page_id = 0; |
697 std::vector<string16> values; | 927 std::vector<string16> values; |
698 std::vector<string16> labels; | 928 std::vector<string16> labels; |
699 std::vector<string16> icons; | 929 std::vector<string16> icons; |
700 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 930 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
701 &icons)); | 931 &icons)); |
702 EXPECT_EQ(kPageID, page_id); | 932 EXPECT_EQ(kPageID, page_id); |
703 ASSERT_EQ(4U, values.size()); | 933 ASSERT_EQ(4U, values.size()); |
(...skipping 24 matching lines...) Expand all Loading... |
728 forms.push_back(form); | 958 forms.push_back(form); |
729 autofill_manager_->FormsSeen(forms); | 959 autofill_manager_->FormsSeen(forms); |
730 | 960 |
731 // The page ID sent to the AutoFillManager from the RenderView, used to send | 961 // The page ID sent to the AutoFillManager from the RenderView, used to send |
732 // an IPC message back to the renderer. | 962 // an IPC message back to the renderer. |
733 const int kPageID = 1; | 963 const int kPageID = 1; |
734 | 964 |
735 webkit_glue::FormField field; | 965 webkit_glue::FormField field; |
736 autofill_test::CreateTestFormField( | 966 autofill_test::CreateTestFormField( |
737 "First Name", "firstname", "", "text", &field); | 967 "First Name", "firstname", "", "text", &field); |
738 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 968 rvh()->ResetAutoFillState(kPageID, false); |
| 969 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field, false)); |
739 | 970 |
740 // No suggestions provided, so send an empty vector as the results. | 971 // No suggestions provided, so send an empty vector as the results. |
741 // This triggers the combined message send. | 972 // This triggers the combined message send. |
742 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 973 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
743 | 974 |
744 // Test that we sent the right message to the renderer. | 975 // Test that we sent the right message to the renderer. |
745 int page_id = 0; | 976 int page_id = 0; |
746 std::vector<string16> values; | 977 std::vector<string16> values; |
747 std::vector<string16> labels; | 978 std::vector<string16> labels; |
748 std::vector<string16> icons; | 979 std::vector<string16> icons; |
749 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 980 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
750 &icons)); | 981 &icons)); |
751 EXPECT_EQ(kPageID, page_id); | 982 EXPECT_EQ(kPageID, page_id); |
752 ASSERT_EQ(2U, values.size()); | 983 ASSERT_EQ(2U, values.size()); |
(...skipping 18 matching lines...) Expand all Loading... |
771 forms.push_back(form); | 1002 forms.push_back(form); |
772 autofill_manager_->FormsSeen(forms); | 1003 autofill_manager_->FormsSeen(forms); |
773 | 1004 |
774 // The page ID sent to the AutoFillManager from the RenderView, used to send | 1005 // The page ID sent to the AutoFillManager from the RenderView, used to send |
775 // an IPC message back to the renderer. | 1006 // an IPC message back to the renderer. |
776 const int kPageID = 1; | 1007 const int kPageID = 1; |
777 | 1008 |
778 webkit_glue::FormField field; | 1009 webkit_glue::FormField field; |
779 autofill_test::CreateTestFormField( | 1010 autofill_test::CreateTestFormField( |
780 "Some Field", "somefield", "", "text", &field); | 1011 "Some Field", "somefield", "", "text", &field); |
781 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 1012 rvh()->ResetAutoFillState(kPageID, false); |
| 1013 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(true, field, false)); |
782 | 1014 |
783 // Add some Autocomplete suggestions. | 1015 // Add some Autocomplete suggestions. |
784 // This triggers the combined message send. | 1016 // This triggers the combined message send. |
785 std::vector<string16> suggestions; | 1017 std::vector<string16> suggestions; |
786 suggestions.push_back(ASCIIToUTF16("one")); | 1018 suggestions.push_back(ASCIIToUTF16("one")); |
787 suggestions.push_back(ASCIIToUTF16("two")); | 1019 suggestions.push_back(ASCIIToUTF16("two")); |
788 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions); | 1020 rvh()->AutocompleteSuggestionsReturned(suggestions); |
789 | 1021 |
790 // Test that we sent the right message to the renderer. | 1022 // Test that we sent the right message to the renderer. |
791 int page_id = 0; | 1023 int page_id = 0; |
792 std::vector<string16> values; | 1024 std::vector<string16> values; |
793 std::vector<string16> labels; | 1025 std::vector<string16> labels; |
794 std::vector<string16> icons; | 1026 std::vector<string16> icons; |
795 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 1027 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
796 &icons)); | 1028 &icons)); |
797 EXPECT_EQ(kPageID, page_id); | 1029 EXPECT_EQ(kPageID, page_id); |
798 ASSERT_EQ(2U, values.size()); | 1030 ASSERT_EQ(2U, values.size()); |
(...skipping 24 matching lines...) Expand all Loading... |
823 "", "", "", "", "", "", "", ""); | 1055 "", "", "", "", "", "", "", ""); |
824 autofill_manager_->AddProfile(profile); | 1056 autofill_manager_->AddProfile(profile); |
825 | 1057 |
826 // The page ID sent to the AutoFillManager from the RenderView, used to send | 1058 // The page ID sent to the AutoFillManager from the RenderView, used to send |
827 // an IPC message back to the renderer. | 1059 // an IPC message back to the renderer. |
828 const int kPageID = 1; | 1060 const int kPageID = 1; |
829 | 1061 |
830 webkit_glue::FormField field; | 1062 webkit_glue::FormField field; |
831 autofill_test::CreateTestFormField( | 1063 autofill_test::CreateTestFormField( |
832 "First Name", "firstname", "", "text", &field); | 1064 "First Name", "firstname", "", "text", &field); |
833 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field)); | 1065 rvh()->ResetAutoFillState(kPageID, false); |
| 1066 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field, false)); |
834 | 1067 |
835 // No suggestions provided, so send an empty vector as the results. | 1068 // No suggestions provided, so send an empty vector as the results. |
836 // This triggers the combined message send. | 1069 // This triggers the combined message send. |
837 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>()); | 1070 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); |
838 | 1071 |
839 // Test that we sent the right message to the renderer. | 1072 // Test that we sent the right message to the renderer. |
840 int page_id = 0; | 1073 int page_id = 0; |
841 std::vector<string16> values; | 1074 std::vector<string16> values; |
842 std::vector<string16> labels; | 1075 std::vector<string16> labels; |
843 std::vector<string16> icons; | 1076 std::vector<string16> icons; |
844 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, | 1077 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, |
845 &icons)); | 1078 &icons)); |
846 EXPECT_EQ(kPageID, page_id); | 1079 EXPECT_EQ(kPageID, page_id); |
847 ASSERT_EQ(2U, values.size()); | 1080 ASSERT_EQ(2U, values.size()); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1606 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1374 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1607 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1375 profile()->GetPrefs()->SetBoolean( | 1608 profile()->GetPrefs()->SetBoolean( |
1376 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1609 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
1377 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1610 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
1378 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1611 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1379 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1612 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1380 #endif | 1613 #endif |
1381 } | 1614 } |
1382 | 1615 |
OLD | NEW |