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

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 4985003: Revert 66214 - Display a warning when autofill is disabled for a website.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/form_structure.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
9 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
10 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
11 #include "base/string16.h" 10 #include "base/string16.h"
12 #include "base/tuple.h" 11 #include "base/tuple.h"
13 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/autofill/autofill_common_test.h" 13 #include "chrome/browser/autofill/autofill_common_test.h"
15 #include "chrome/browser/autofill/autofill_manager.h" 14 #include "chrome/browser/autofill/autofill_manager.h"
16 #include "chrome/browser/autofill/autofill_profile.h" 15 #include "chrome/browser/autofill/autofill_profile.h"
17 #include "chrome/browser/autofill/credit_card.h" 16 #include "chrome/browser/autofill/credit_card.h"
18 #include "chrome/browser/autofill/personal_data_manager.h" 17 #include "chrome/browser/autofill/personal_data_manager.h"
19 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
21 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 20 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
22 #include "chrome/browser/tab_contents/test_tab_contents.h" 21 #include "chrome/browser/tab_contents/test_tab_contents.h"
23 #include "chrome/common/ipc_test_sink.h" 22 #include "chrome/common/ipc_test_sink.h"
24 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
25 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
26 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
27 #include "grit/generated_resources.h"
28 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
29 #include "webkit/glue/form_data.h" 27 #include "webkit/glue/form_data.h"
30 #include "webkit/glue/form_field.h" 28 #include "webkit/glue/form_field.h"
31 29
32 using webkit_glue::FormData; 30 using webkit_glue::FormData;
33 31
34 typedef Tuple5<int, 32 typedef Tuple5<int,
35 std::vector<string16>, 33 std::vector<string16>,
36 std::vector<string16>, 34 std::vector<string16>,
37 std::vector<string16>, 35 std::vector<string16>,
(...skipping 16 matching lines...) Expand all
54 if (!(*it)->Label().compare(ASCIIToUTF16(label))) 52 if (!(*it)->Label().compare(ASCIIToUTF16(label)))
55 return *it; 53 return *it;
56 } 54 }
57 return NULL; 55 return NULL;
58 } 56 }
59 57
60 void AddProfile(AutoFillProfile* profile) { 58 void AddProfile(AutoFillProfile* profile) {
61 web_profiles_->push_back(profile); 59 web_profiles_->push_back(profile);
62 } 60 }
63 61
64 void ClearAutoFillProfiles() {
65 web_profiles_.reset();
66 }
67
68 void ClearCreditCards() {
69 credit_cards_.reset();
70 }
71
72 private: 62 private:
73 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { 63 void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) {
74 AutoFillProfile* profile = new AutoFillProfile; 64 AutoFillProfile* profile = new AutoFillProfile;
75 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron", 65 autofill_test::SetProfileInfo(profile, "Home", "Elvis", "Aaron",
76 "Presley", "theking@gmail.com", "RCA", 66 "Presley", "theking@gmail.com", "RCA",
77 "3734 Elvis Presley Blvd.", "Apt. 10", 67 "3734 Elvis Presley Blvd.", "Apt. 10",
78 "Memphis", "Tennessee", "38116", "USA", 68 "Memphis", "Tennessee", "38116", "USA",
79 "12345678901", ""); 69 "12345678901", "");
80 profile->set_guid("00000000-0000-0000-0000-000000000001"); 70 profile->set_guid("00000000-0000-0000-0000-000000000001");
81 profiles->push_back(profile); 71 profiles->push_back(profile);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 credit_cards->push_back(credit_card); 103 credit_cards->push_back(credit_card);
114 } 104 }
115 105
116 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 106 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
117 }; 107 };
118 108
119 class TestAutoFillManager : public AutoFillManager { 109 class TestAutoFillManager : public AutoFillManager {
120 public: 110 public:
121 TestAutoFillManager(TabContents* tab_contents, 111 TestAutoFillManager(TabContents* tab_contents,
122 TestPersonalDataManager* personal_manager) 112 TestPersonalDataManager* personal_manager)
123 : AutoFillManager(tab_contents, NULL), 113 : AutoFillManager(tab_contents, NULL) {
124 autofill_enabled_(true) {
125 test_personal_data_ = personal_manager; 114 test_personal_data_ = personal_manager;
126 set_personal_data_manager(personal_manager); 115 set_personal_data_manager(personal_manager);
127 // Download manager requests are disabled for purposes of this unit-test. 116 // Download manager requests are disabled for purposes of this unit-test.
128 // These request are tested in autofill_download_unittest.cc. 117 // These request are tested in autofill_download_unittest.cc.
129 set_disable_download_manager_requests(true); 118 set_disable_download_manager_requests(true);
130 } 119 }
131 120
132 virtual bool IsAutoFillEnabled() const { return autofill_enabled_; } 121 virtual bool IsAutoFillEnabled() const { return true; }
133
134 void set_autofill_enabled(bool autofill_enabled) {
135 autofill_enabled_ = autofill_enabled;
136 }
137 122
138 AutoFillProfile* GetLabeledProfile(const char* label) { 123 AutoFillProfile* GetLabeledProfile(const char* label) {
139 return test_personal_data_->GetLabeledProfile(label); 124 return test_personal_data_->GetLabeledProfile(label);
140 } 125 }
141 126
142 void AddProfile(AutoFillProfile* profile) { 127 void AddProfile(AutoFillProfile* profile) {
143 test_personal_data_->AddProfile(profile); 128 test_personal_data_->AddProfile(profile);
144 } 129 }
145 130
146 private: 131 private:
147 TestPersonalDataManager* test_personal_data_; 132 TestPersonalDataManager* test_personal_data_;
148 bool autofill_enabled_;
149 133
150 DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager); 134 DISALLOW_COPY_AND_ASSIGN(TestAutoFillManager);
151 }; 135 };
152 136
153 // Populates |form| with data corresponding to a simple address form. 137 // Populates |form| with data corresponding to a simple address form.
154 // Note that this actually appends fields to the form data, which can be useful 138 // Note that this actually appends fields to the form data, which can be useful
155 // for building up more complex test forms. 139 // for building up more complex test forms.
156 void CreateTestAddressFormData(FormData* form) { 140 void CreateTestAddressFormData(FormData* form) {
157 form->name = ASCIIToUTF16("MyForm"); 141 form->name = ASCIIToUTF16("MyForm");
158 form->method = ASCIIToUTF16("POST"); 142 form->method = ASCIIToUTF16("POST");
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 forms.push_back(form); 286 forms.push_back(form);
303 autofill_manager_->FormsSeen(forms); 287 autofill_manager_->FormsSeen(forms);
304 288
305 // The page ID sent to the AutoFillManager from the RenderView, used to send 289 // The page ID sent to the AutoFillManager from the RenderView, used to send
306 // an IPC message back to the renderer. 290 // an IPC message back to the renderer.
307 const int kPageID = 1; 291 const int kPageID = 1;
308 292
309 webkit_glue::FormField field; 293 webkit_glue::FormField field;
310 autofill_test::CreateTestFormField( 294 autofill_test::CreateTestFormField(
311 "First Name", "firstname", "", "text", &field); 295 "First Name", "firstname", "", "text", &field);
312 rvh()->ResetAutoFillState(kPageID); 296 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
313 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
314 297
315 // No suggestions provided, so send an empty vector as the results. 298 // No suggestions provided, so send an empty vector as the results.
316 // This triggers the combined message send. 299 // This triggers the combined message send.
317 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 300 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
318 301
319 // Test that we sent the right message to the renderer. 302 // Test that we sent the right message to the renderer.
320 int page_id = 0; 303 int page_id = 0;
321 std::vector<string16> values; 304 std::vector<string16> values;
322 std::vector<string16> labels; 305 std::vector<string16> labels;
323 std::vector<string16> icons; 306 std::vector<string16> icons;
324 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 307 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
325 &icons)); 308 &icons));
326 EXPECT_EQ(kPageID, page_id); 309 EXPECT_EQ(kPageID, page_id);
327 ASSERT_EQ(2U, values.size()); 310 ASSERT_EQ(2U, values.size());
(...skipping 20 matching lines...) Expand all
348 forms.push_back(form); 331 forms.push_back(form);
349 autofill_manager_->FormsSeen(forms); 332 autofill_manager_->FormsSeen(forms);
350 333
351 // The page ID sent to the AutoFillManager from the RenderView, used to send 334 // The page ID sent to the AutoFillManager from the RenderView, used to send
352 // an IPC message back to the renderer. 335 // an IPC message back to the renderer.
353 const int kPageID = 1; 336 const int kPageID = 1;
354 337
355 webkit_glue::FormField field; 338 webkit_glue::FormField field;
356 autofill_test::CreateTestFormField( 339 autofill_test::CreateTestFormField(
357 "First Name", "firstname", "E", "text", &field); 340 "First Name", "firstname", "E", "text", &field);
358 rvh()->ResetAutoFillState(kPageID); 341 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
359 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
360 342
361 // No suggestions provided, so send an empty vector as the results. 343 // No suggestions provided, so send an empty vector as the results.
362 // This triggers the combined message send. 344 // This triggers the combined message send.
363 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 345 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
364 346
365 // Test that we sent the right message to the renderer. 347 // Test that we sent the right message to the renderer.
366 int page_id = 0; 348 int page_id = 0;
367 std::vector<string16> values; 349 std::vector<string16> values;
368 std::vector<string16> labels; 350 std::vector<string16> labels;
369 std::vector<string16> icons; 351 std::vector<string16> icons;
370 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 352 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
371 &icons)); 353 &icons));
372 EXPECT_EQ(kPageID, page_id); 354 EXPECT_EQ(kPageID, page_id);
373 ASSERT_EQ(1U, values.size()); 355 ASSERT_EQ(1U, values.size());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 std::vector<FormData> forms; 387 std::vector<FormData> forms;
406 forms.push_back(form); 388 forms.push_back(form);
407 autofill_manager_->FormsSeen(forms); 389 autofill_manager_->FormsSeen(forms);
408 390
409 // The page ID sent to the AutoFillManager from the RenderView, used to send 391 // The page ID sent to the AutoFillManager from the RenderView, used to send
410 // an IPC message back to the renderer. 392 // an IPC message back to the renderer.
411 const int kPageID = 1; 393 const int kPageID = 1;
412 394
413 autofill_test::CreateTestFormField( 395 autofill_test::CreateTestFormField(
414 "Username", "username", "", "text", &field); 396 "Username", "username", "", "text", &field);
415 rvh()->ResetAutoFillState(kPageID);
416 EXPECT_FALSE( 397 EXPECT_FALSE(
417 autofill_manager_->GetAutoFillSuggestions(false, field)); 398 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
418 }
419
420 // Test that we return no suggestions when autofill is disabled.
421 TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
422 FormData form;
423 CreateTestAddressFormData(&form);
424
425 // Set up our FormStructures.
426 std::vector<FormData> forms;
427 forms.push_back(form);
428 autofill_manager_->FormsSeen(forms);
429
430 // Disable AutoFill.
431 autofill_manager_->set_autofill_enabled(false);
432
433 // The page ID sent to the AutoFillManager from the RenderView, used to send
434 // an IPC message back to the renderer.
435 const int kPageID = 1;
436
437 webkit_glue::FormField field;
438 autofill_test::CreateTestFormField(
439 "First Name", "firstname", "", "text", &field);
440 rvh()->ResetAutoFillState(kPageID);
441 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
442 }
443
444 // Test that we return a warning explaining that autofill suggestions are
445 // unavailable when the form method is GET rather than POST.
446 TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
447 FormData form;
448 CreateTestAddressFormData(&form);
449 form.method = ASCIIToUTF16("GET");
450
451 // Set up our FormStructures.
452 std::vector<FormData> forms;
453 forms.push_back(form);
454 autofill_manager_->FormsSeen(forms);
455
456 // The page ID sent to the AutoFillManager from the RenderView, used to send
457 // an IPC message back to the renderer.
458 const int kPageID = 1;
459
460 webkit_glue::FormField field;
461 autofill_test::CreateTestFormField(
462 "First Name", "firstname", "", "text", &field);
463 rvh()->ResetAutoFillState(kPageID);
464 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
465
466 // No suggestions provided, so send an empty vector as the results.
467 // This triggers the combined message send.
468 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
469
470 // Test that we sent the right message to the renderer.
471 int page_id = 0;
472 std::vector<string16> values;
473 std::vector<string16> labels;
474 std::vector<string16> icons;
475 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
476 &icons));
477 EXPECT_EQ(kPageID, page_id);
478 ASSERT_EQ(1U, values.size());
479 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED),
480 values[0]);
481 ASSERT_EQ(1U, labels.size());
482 EXPECT_EQ(string16(), labels[0]);
483 ASSERT_EQ(1U, icons.size());
484 EXPECT_EQ(string16(), icons[0]);
485
486 // Now add some Autocomplete suggestions. We should return the autocomplete
487 // suggestions and the warning; these will be culled by the renderer.
488 process()->sink().ClearMessages();
489 const int kPageID2 = 2;
490 rvh()->ResetAutoFillState(kPageID2);
491 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
492
493 std::vector<string16> suggestions;
494 suggestions.push_back(ASCIIToUTF16("Jay"));
495 suggestions.push_back(ASCIIToUTF16("Jason"));
496 rvh()->AutocompleteSuggestionsReturned(suggestions);
497
498 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
499 &icons));
500 EXPECT_EQ(kPageID2, page_id);
501 ASSERT_EQ(3U, values.size());
502 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED),
503 values[0]);
504 EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]);
505 EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]);
506 ASSERT_EQ(3U, labels.size());
507 EXPECT_EQ(string16(), labels[0]);
508 EXPECT_EQ(string16(), labels[1]);
509 EXPECT_EQ(string16(), labels[2]);
510 ASSERT_EQ(3U, icons.size());
511 EXPECT_EQ(string16(), icons[0]);
512 EXPECT_EQ(string16(), icons[1]);
513 EXPECT_EQ(string16(), icons[2]);
514
515 // Now clear the test profiles and try again -- we shouldn't return a warning.
516 test_personal_data_->ClearAutoFillProfiles();
517 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
518 } 399 }
519 400
520 // Test that we return all credit card profile suggestions when all form fields 401 // Test that we return all credit card profile suggestions when all form fields
521 // are empty. 402 // are empty.
522 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) { 403 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
523 FormData form; 404 FormData form;
524 CreateTestCreditCardFormData(&form, true); 405 CreateTestCreditCardFormData(&form, true);
525 406
526 // Set up our FormStructures. 407 // Set up our FormStructures.
527 std::vector<FormData> forms; 408 std::vector<FormData> forms;
528 forms.push_back(form); 409 forms.push_back(form);
529 autofill_manager_->FormsSeen(forms); 410 autofill_manager_->FormsSeen(forms);
530 411
531 // The page ID sent to the AutoFillManager from the RenderView, used to send 412 // The page ID sent to the AutoFillManager from the RenderView, used to send
532 // an IPC message back to the renderer. 413 // an IPC message back to the renderer.
533 const int kPageID = 1; 414 const int kPageID = 1;
534 415
535 webkit_glue::FormField field; 416 webkit_glue::FormField field;
536 autofill_test::CreateTestFormField( 417 autofill_test::CreateTestFormField(
537 "Card Number", "cardnumber", "", "text", &field); 418 "Card Number", "cardnumber", "", "text", &field);
538 rvh()->ResetAutoFillState(kPageID); 419 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
539 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
540 420
541 // No suggestions provided, so send an empty vector as the results. 421 // No suggestions provided, so send an empty vector as the results.
542 // This triggers the combined message send. 422 // This triggers the combined message send.
543 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 423 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
544 424
545 // Test that we sent the right message to the renderer. 425 // Test that we sent the right message to the renderer.
546 int page_id = 0; 426 int page_id = 0;
547 std::vector<string16> values; 427 std::vector<string16> values;
548 std::vector<string16> labels; 428 std::vector<string16> labels;
549 std::vector<string16> icons; 429 std::vector<string16> icons;
550 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 430 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
551 &icons)); 431 &icons));
552 EXPECT_EQ(kPageID, page_id); 432 EXPECT_EQ(kPageID, page_id);
553 ASSERT_EQ(2U, values.size()); 433 ASSERT_EQ(2U, values.size());
(...skipping 18 matching lines...) Expand all
572 forms.push_back(form); 452 forms.push_back(form);
573 autofill_manager_->FormsSeen(forms); 453 autofill_manager_->FormsSeen(forms);
574 454
575 // The page ID sent to the AutoFillManager from the RenderView, used to send 455 // The page ID sent to the AutoFillManager from the RenderView, used to send
576 // an IPC message back to the renderer. 456 // an IPC message back to the renderer.
577 const int kPageID = 1; 457 const int kPageID = 1;
578 458
579 webkit_glue::FormField field; 459 webkit_glue::FormField field;
580 autofill_test::CreateTestFormField( 460 autofill_test::CreateTestFormField(
581 "Card Number", "cardnumber", "4", "text", &field); 461 "Card Number", "cardnumber", "4", "text", &field);
582 rvh()->ResetAutoFillState(kPageID); 462 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
583 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
584 463
585 // No suggestions provided, so send an empty vector as the results. 464 // No suggestions provided, so send an empty vector as the results.
586 // This triggers the combined message send. 465 // This triggers the combined message send.
587 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 466 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
588 467
589 // Test that we sent the right message to the renderer. 468 // Test that we sent the right message to the renderer.
590 int page_id = 0; 469 int page_id = 0;
591 std::vector<string16> values; 470 std::vector<string16> values;
592 std::vector<string16> labels; 471 std::vector<string16> labels;
593 std::vector<string16> icons; 472 std::vector<string16> icons;
594 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 473 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
595 &icons)); 474 &icons));
596 EXPECT_EQ(kPageID, page_id); 475 EXPECT_EQ(kPageID, page_id);
597 ASSERT_EQ(1U, values.size()); 476 ASSERT_EQ(1U, values.size());
(...skipping 15 matching lines...) Expand all
613 forms.push_back(form); 492 forms.push_back(form);
614 autofill_manager_->FormsSeen(forms); 493 autofill_manager_->FormsSeen(forms);
615 494
616 // The page ID sent to the AutoFillManager from the RenderView, used to send 495 // The page ID sent to the AutoFillManager from the RenderView, used to send
617 // an IPC message back to the renderer. 496 // an IPC message back to the renderer.
618 const int kPageID = 1; 497 const int kPageID = 1;
619 498
620 webkit_glue::FormField field; 499 webkit_glue::FormField field;
621 autofill_test::CreateTestFormField( 500 autofill_test::CreateTestFormField(
622 "Name on Card", "nameoncard", "", "text", &field); 501 "Name on Card", "nameoncard", "", "text", &field);
623 rvh()->ResetAutoFillState(kPageID); 502 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
624 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
625 503
626 // No suggestions provided, so send an empty vector as the results. 504 // No suggestions provided, so send an empty vector as the results.
627 // This triggers the combined message send. 505 // This triggers the combined message send.
628 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 506 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
629 507
630 // Test that we sent the right message to the renderer. 508 // Test that we sent the right message to the renderer.
631 int page_id = 0; 509 int page_id = 0;
632 std::vector<string16> values; 510 std::vector<string16> values;
633 std::vector<string16> labels; 511 std::vector<string16> labels;
634 std::vector<string16> icons; 512 std::vector<string16> icons;
635 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 513 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
636 &icons)); 514 &icons));
637 EXPECT_EQ(kPageID, page_id); 515 EXPECT_EQ(kPageID, page_id);
638 ASSERT_EQ(2U, values.size()); 516 ASSERT_EQ(2U, values.size());
639 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]); 517 EXPECT_EQ(ASCIIToUTF16("Elvis Presley"), values[0]);
640 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]); 518 EXPECT_EQ(ASCIIToUTF16("Buddy Holly"), values[1]);
641 ASSERT_EQ(2U, labels.size()); 519 ASSERT_EQ(2U, labels.size());
642 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); 520 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]);
643 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); 521 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]);
644 ASSERT_EQ(2U, icons.size()); 522 ASSERT_EQ(2U, icons.size());
645 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); 523 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]);
646 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); 524 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]);
647 } 525 }
648 526
649 // Test that we return a warning explaining that credit card profile suggestions 527 // Test that we return no credit card profile suggestions when the form is not
650 // are unavailable when the form is not https. 528 // https.
651 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) { 529 TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
652 FormData form; 530 FormData form;
653 CreateTestCreditCardFormData(&form, false); 531 CreateTestCreditCardFormData(&form, false);
654 532
655 // Set up our FormStructures. 533 // Set up our FormStructures.
656 std::vector<FormData> forms; 534 std::vector<FormData> forms;
657 forms.push_back(form); 535 forms.push_back(form);
658 autofill_manager_->FormsSeen(forms); 536 autofill_manager_->FormsSeen(forms);
659 537
660 // The page ID sent to the AutoFillManager from the RenderView, used to send 538 // The page ID sent to the AutoFillManager from the RenderView, used to send
661 // an IPC message back to the renderer. 539 // an IPC message back to the renderer.
662 const int kPageID = 1; 540 const int kPageID = 1;
663 541
664 webkit_glue::FormField field; 542 webkit_glue::FormField field;
665 autofill_test::CreateTestFormField( 543 autofill_test::CreateTestFormField(
666 "Card Number", "cardnumber", "", "text", &field); 544 "Card Number", "cardnumber", "", "text", &field);
667 rvh()->ResetAutoFillState(kPageID); 545 EXPECT_FALSE(
668 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); 546 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
669
670 // No suggestions provided, so send an empty vector as the results.
671 // This triggers the combined message send.
672 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
673
674 // Test that we sent the right message to the renderer.
675 int page_id = 0;
676 std::vector<string16> values;
677 std::vector<string16> labels;
678 std::vector<string16> icons;
679 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
680 &icons));
681 EXPECT_EQ(kPageID, page_id);
682 ASSERT_EQ(1U, values.size());
683 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
684 values[0]);
685 ASSERT_EQ(1U, labels.size());
686 EXPECT_EQ(string16(), labels[0]);
687 ASSERT_EQ(1U, icons.size());
688 EXPECT_EQ(string16(), icons[0]);
689
690 // Now add some Autocomplete suggestions. We should show the autocomplete
691 // suggestions and the warning.
692 process()->sink().ClearMessages();
693 const int kPageID2 = 2;
694 rvh()->ResetAutoFillState(kPageID2);
695 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
696
697 std::vector<string16> suggestions;
698 suggestions.push_back(ASCIIToUTF16("Jay"));
699 suggestions.push_back(ASCIIToUTF16("Jason"));
700 rvh()->AutocompleteSuggestionsReturned(suggestions);
701
702 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
703 &icons));
704 EXPECT_EQ(kPageID2, page_id);
705 ASSERT_EQ(3U, values.size());
706 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
707 values[0]);
708 EXPECT_EQ(ASCIIToUTF16("Jay"), values[1]);
709 EXPECT_EQ(ASCIIToUTF16("Jason"), values[2]);
710 ASSERT_EQ(3U, labels.size());
711 EXPECT_EQ(string16(), labels[0]);
712 EXPECT_EQ(string16(), labels[1]);
713 EXPECT_EQ(string16(), labels[2]);
714 ASSERT_EQ(3U, icons.size());
715 EXPECT_EQ(string16(), icons[0]);
716 EXPECT_EQ(string16(), icons[1]);
717 EXPECT_EQ(string16(), icons[2]);
718
719 // Clear the test credit cards and try again -- we shouldn't return a warning.
720 test_personal_data_->ClearCreditCards();
721 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
722 } 547 }
723 548
724 // Test that we return profile and credit card suggestions for combined forms. 549 // Test that we return profile and credit card suggestions for combined forms.
725 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) { 550 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
726 FormData form; 551 FormData form;
727 CreateTestAddressFormData(&form); 552 CreateTestAddressFormData(&form);
728 CreateTestCreditCardFormData(&form, true); 553 CreateTestCreditCardFormData(&form, true);
729 554
730 // Set up our FormStructures. 555 // Set up our FormStructures.
731 std::vector<FormData> forms; 556 std::vector<FormData> forms;
732 forms.push_back(form); 557 forms.push_back(form);
733 autofill_manager_->FormsSeen(forms); 558 autofill_manager_->FormsSeen(forms);
734 559
735 // The page ID sent to the AutoFillManager from the RenderView, used to send 560 // The page ID sent to the AutoFillManager from the RenderView, used to send
736 // an IPC message back to the renderer. 561 // an IPC message back to the renderer.
737 const int kPageID = 1; 562 const int kPageID = 1;
738 563
739 webkit_glue::FormField field; 564 webkit_glue::FormField field;
740 autofill_test::CreateTestFormField( 565 autofill_test::CreateTestFormField(
741 "First Name", "firstname", "", "text", &field); 566 "First Name", "firstname", "", "text", &field);
742 rvh()->ResetAutoFillState(kPageID); 567 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
743 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
744 568
745 // No suggestions provided, so send an empty vector as the results. 569 // No suggestions provided, so send an empty vector as the results.
746 // This triggers the combined message send. 570 // This triggers the combined message send.
747 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 571 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
748 572
749 // Test that we sent the right address suggestions to the renderer. 573 // Test that we sent the right address suggestions to the renderer.
750 int page_id = 0; 574 int page_id = 0;
751 std::vector<string16> values; 575 std::vector<string16> values;
752 std::vector<string16> labels; 576 std::vector<string16> labels;
753 std::vector<string16> icons; 577 std::vector<string16> icons;
754 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 578 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
755 &icons)); 579 &icons));
756 EXPECT_EQ(kPageID, page_id); 580 EXPECT_EQ(kPageID, page_id);
757 ASSERT_EQ(2U, values.size()); 581 ASSERT_EQ(2U, values.size());
758 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); 582 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
759 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); 583 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
760 ASSERT_EQ(2U, labels.size()); 584 ASSERT_EQ(2U, labels.size());
761 // Inferred labels now include full first relevant field, which in this case 585 // Inferred labels now include full first relevant field, which in this case
762 // the address #1. 586 // the address #1.
763 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); 587 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
764 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); 588 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]);
765 ASSERT_EQ(2U, icons.size()); 589 ASSERT_EQ(2U, icons.size());
766 EXPECT_EQ(string16(), icons[0]); 590 EXPECT_EQ(string16(), icons[0]);
767 EXPECT_EQ(string16(), icons[1]); 591 EXPECT_EQ(string16(), icons[1]);
768 592
769 process()->sink().ClearMessages(); 593 process()->sink().ClearMessages();
770 autofill_test::CreateTestFormField( 594 autofill_test::CreateTestFormField(
771 "Card Number", "cardnumber", "", "text", &field); 595 "Card Number", "cardnumber", "", "text", &field);
772 rvh()->ResetAutoFillState(kPageID); 596 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
773 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
774 597
775 // No suggestions provided, so send an empty vector as the results. 598 // No suggestions provided, so send an empty vector as the results.
776 // This triggers the combined message send. 599 // This triggers the combined message send.
777 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 600 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
778 601
779 // Test that we sent the credit card suggestions to the renderer. 602 // Test that we sent the credit card suggestions to the renderer.
780 page_id = 0; 603 page_id = 0;
781 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 604 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
782 &icons)); 605 &icons));
783 EXPECT_EQ(kPageID, page_id); 606 EXPECT_EQ(kPageID, page_id);
784 ASSERT_EQ(2U, values.size()); 607 ASSERT_EQ(2U, values.size());
785 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]); 608 EXPECT_EQ(ASCIIToUTF16("************3456"), values[0]);
786 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]); 609 EXPECT_EQ(ASCIIToUTF16("************8765"), values[1]);
787 ASSERT_EQ(2U, labels.size()); 610 ASSERT_EQ(2U, labels.size());
788 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]); 611 EXPECT_EQ(ASCIIToUTF16("*3456"), labels[0]);
789 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]); 612 EXPECT_EQ(ASCIIToUTF16("*8765"), labels[1]);
790 ASSERT_EQ(2U, icons.size()); 613 ASSERT_EQ(2U, icons.size());
791 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]); 614 EXPECT_EQ(ASCIIToUTF16("visaCC"), icons[0]);
792 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]); 615 EXPECT_EQ(ASCIIToUTF16("masterCardCC"), icons[1]);
793 } 616 }
794 617
795 // Test that for non-https forms with both address and credit card fields, we 618 // Test that for non-https forms with both address and credit card fields, we
796 // only return address suggestions. Instead of credit card suggestions, we 619 // only return address suggestions.
797 // should return a warning explaining that credit card profile suggestions are
798 // unavailable when the form is not https.
799 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) { 620 TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
800 FormData form; 621 FormData form;
801 CreateTestAddressFormData(&form); 622 CreateTestAddressFormData(&form);
802 CreateTestCreditCardFormData(&form, false); 623 CreateTestCreditCardFormData(&form, false);
803 624
804 // Set up our FormStructures. 625 // Set up our FormStructures.
805 std::vector<FormData> forms; 626 std::vector<FormData> forms;
806 forms.push_back(form); 627 forms.push_back(form);
807 autofill_manager_->FormsSeen(forms); 628 autofill_manager_->FormsSeen(forms);
808 629
809 // The page ID sent to the AutoFillManager from the RenderView, used to send 630 // The page ID sent to the AutoFillManager from the RenderView, used to send
810 // an IPC message back to the renderer. 631 // an IPC message back to the renderer.
811 const int kPageID = 1; 632 const int kPageID = 1;
812 633
813 webkit_glue::FormField field; 634 webkit_glue::FormField field;
814 autofill_test::CreateTestFormField( 635 autofill_test::CreateTestFormField(
815 "First Name", "firstname", "", "text", &field); 636 "First Name", "firstname", "", "text", &field);
816 rvh()->ResetAutoFillState(kPageID); 637 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
817 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
818 638
819 // No suggestions provided, so send an empty vector as the results. 639 // No suggestions provided, so send an empty vector as the results.
820 // This triggers the combined message send. 640 // This triggers the combined message send.
821 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 641 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
822 642
823 // Test that we sent the right address suggestions to the renderer. 643 // Test that we sent the right address suggestions to the renderer.
824 int page_id = 0; 644 int page_id = 0;
825 std::vector<string16> values; 645 std::vector<string16> values;
826 std::vector<string16> labels; 646 std::vector<string16> labels;
827 std::vector<string16> icons; 647 std::vector<string16> icons;
828 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 648 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
829 &icons)); 649 &icons));
830 EXPECT_EQ(kPageID, page_id); 650 EXPECT_EQ(kPageID, page_id);
831 ASSERT_EQ(2U, values.size()); 651 ASSERT_EQ(2U, values.size());
832 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]); 652 EXPECT_EQ(ASCIIToUTF16("Elvis"), values[0]);
833 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]); 653 EXPECT_EQ(ASCIIToUTF16("Charles"), values[1]);
834 ASSERT_EQ(2U, labels.size()); 654 ASSERT_EQ(2U, labels.size());
835 // Inferred labels now include full first relevant field, which in this case 655 // Inferred labels now include full first relevant field, which in this case
836 // the address #1. 656 // the address #1.
837 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]); 657 EXPECT_EQ(ASCIIToUTF16("3734 Elvis Presley Blvd."), labels[0]);
838 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]); 658 EXPECT_EQ(ASCIIToUTF16("123 Apple St."), labels[1]);
839 ASSERT_EQ(2U, icons.size()); 659 ASSERT_EQ(2U, icons.size());
840 EXPECT_EQ(string16(), icons[0]); 660 EXPECT_EQ(string16(), icons[0]);
841 EXPECT_EQ(string16(), icons[1]); 661 EXPECT_EQ(string16(), icons[1]);
842 662
843 process()->sink().ClearMessages();
844 autofill_test::CreateTestFormField( 663 autofill_test::CreateTestFormField(
845 "Card Number", "cardnumber", "", "text", &field); 664 "Card Number", "cardnumber", "", "text", &field);
846 rvh()->ResetAutoFillState(kPageID); 665 EXPECT_FALSE(
847 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field)); 666 autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
848
849 // No suggestions provided, so send an empty vector as the results.
850 // This triggers the combined message send.
851 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
852
853 // Test that we sent the right message to the renderer.
854 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
855 &icons));
856 EXPECT_EQ(kPageID, page_id);
857 ASSERT_EQ(1U, values.size());
858 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
859 values[0]);
860 ASSERT_EQ(1U, labels.size());
861 EXPECT_EQ(string16(), labels[0]);
862 ASSERT_EQ(1U, icons.size());
863 EXPECT_EQ(string16(), icons[0]);
864
865 // Clear the test credit cards and try again -- we shouldn't return a warning.
866 test_personal_data_->ClearCreditCards();
867 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(false, field));
868 } 667 }
869 668
870 // Test that we correctly combine autofill and autocomplete suggestions. 669 // Test that we correctly combine autofill and autocomplete suggestions.
871 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) { 670 TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) {
872 FormData form; 671 FormData form;
873 CreateTestAddressFormData(&form); 672 CreateTestAddressFormData(&form);
874 673
875 // Set up our FormStructures. 674 // Set up our FormStructures.
876 std::vector<FormData> forms; 675 std::vector<FormData> forms;
877 forms.push_back(form); 676 forms.push_back(form);
878 autofill_manager_->FormsSeen(forms); 677 autofill_manager_->FormsSeen(forms);
879 678
880 // The page ID sent to the AutoFillManager from the RenderView, used to send 679 // The page ID sent to the AutoFillManager from the RenderView, used to send
881 // an IPC message back to the renderer. 680 // an IPC message back to the renderer.
882 const int kPageID = 1; 681 const int kPageID = 1;
883 682
884 webkit_glue::FormField field; 683 webkit_glue::FormField field;
885 autofill_test::CreateTestFormField( 684 autofill_test::CreateTestFormField(
886 "First Name", "firstname", "", "text", &field); 685 "First Name", "firstname", "", "text", &field);
887 rvh()->ResetAutoFillState(kPageID); 686 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, false, field));
888 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(false, field));
889 687
890 // Add some Autocomplete suggestions. 688 // Add some Autocomplete suggestions.
891 // This triggers the combined message send. 689 // This triggers the combined message send.
892 std::vector<string16> suggestions; 690 std::vector<string16> suggestions;
893 suggestions.push_back(ASCIIToUTF16("Jay")); 691 suggestions.push_back(ASCIIToUTF16("Jay"));
894 suggestions.push_back(ASCIIToUTF16("Jason")); 692 suggestions.push_back(ASCIIToUTF16("Jason"));
895 rvh()->AutocompleteSuggestionsReturned(suggestions); 693 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions);
896 694
897 // Test that we sent the right message to the renderer. 695 // Test that we sent the right message to the renderer.
898 int page_id = 0; 696 int page_id = 0;
899 std::vector<string16> values; 697 std::vector<string16> values;
900 std::vector<string16> labels; 698 std::vector<string16> labels;
901 std::vector<string16> icons; 699 std::vector<string16> icons;
902 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 700 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
903 &icons)); 701 &icons));
904 EXPECT_EQ(kPageID, page_id); 702 EXPECT_EQ(kPageID, page_id);
905 ASSERT_EQ(4U, values.size()); 703 ASSERT_EQ(4U, values.size());
(...skipping 24 matching lines...) Expand all
930 forms.push_back(form); 728 forms.push_back(form);
931 autofill_manager_->FormsSeen(forms); 729 autofill_manager_->FormsSeen(forms);
932 730
933 // The page ID sent to the AutoFillManager from the RenderView, used to send 731 // The page ID sent to the AutoFillManager from the RenderView, used to send
934 // an IPC message back to the renderer. 732 // an IPC message back to the renderer.
935 const int kPageID = 1; 733 const int kPageID = 1;
936 734
937 webkit_glue::FormField field; 735 webkit_glue::FormField field;
938 autofill_test::CreateTestFormField( 736 autofill_test::CreateTestFormField(
939 "First Name", "firstname", "", "text", &field); 737 "First Name", "firstname", "", "text", &field);
940 rvh()->ResetAutoFillState(kPageID); 738 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field));
941 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field));
942 739
943 // No suggestions provided, so send an empty vector as the results. 740 // No suggestions provided, so send an empty vector as the results.
944 // This triggers the combined message send. 741 // This triggers the combined message send.
945 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 742 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
946 743
947 // Test that we sent the right message to the renderer. 744 // Test that we sent the right message to the renderer.
948 int page_id = 0; 745 int page_id = 0;
949 std::vector<string16> values; 746 std::vector<string16> values;
950 std::vector<string16> labels; 747 std::vector<string16> labels;
951 std::vector<string16> icons; 748 std::vector<string16> icons;
952 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 749 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
953 &icons)); 750 &icons));
954 EXPECT_EQ(kPageID, page_id); 751 EXPECT_EQ(kPageID, page_id);
955 ASSERT_EQ(2U, values.size()); 752 ASSERT_EQ(2U, values.size());
(...skipping 18 matching lines...) Expand all
974 forms.push_back(form); 771 forms.push_back(form);
975 autofill_manager_->FormsSeen(forms); 772 autofill_manager_->FormsSeen(forms);
976 773
977 // The page ID sent to the AutoFillManager from the RenderView, used to send 774 // The page ID sent to the AutoFillManager from the RenderView, used to send
978 // an IPC message back to the renderer. 775 // an IPC message back to the renderer.
979 const int kPageID = 1; 776 const int kPageID = 1;
980 777
981 webkit_glue::FormField field; 778 webkit_glue::FormField field;
982 autofill_test::CreateTestFormField( 779 autofill_test::CreateTestFormField(
983 "Some Field", "somefield", "", "text", &field); 780 "Some Field", "somefield", "", "text", &field);
984 rvh()->ResetAutoFillState(kPageID); 781 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field));
985 EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(true, field));
986 782
987 // Add some Autocomplete suggestions. 783 // Add some Autocomplete suggestions.
988 // This triggers the combined message send. 784 // This triggers the combined message send.
989 std::vector<string16> suggestions; 785 std::vector<string16> suggestions;
990 suggestions.push_back(ASCIIToUTF16("one")); 786 suggestions.push_back(ASCIIToUTF16("one"));
991 suggestions.push_back(ASCIIToUTF16("two")); 787 suggestions.push_back(ASCIIToUTF16("two"));
992 rvh()->AutocompleteSuggestionsReturned(suggestions); 788 rvh()->AutocompleteSuggestionsReturned(kPageID, suggestions);
993 789
994 // Test that we sent the right message to the renderer. 790 // Test that we sent the right message to the renderer.
995 int page_id = 0; 791 int page_id = 0;
996 std::vector<string16> values; 792 std::vector<string16> values;
997 std::vector<string16> labels; 793 std::vector<string16> labels;
998 std::vector<string16> icons; 794 std::vector<string16> icons;
999 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 795 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
1000 &icons)); 796 &icons));
1001 EXPECT_EQ(kPageID, page_id); 797 EXPECT_EQ(kPageID, page_id);
1002 ASSERT_EQ(2U, values.size()); 798 ASSERT_EQ(2U, values.size());
(...skipping 24 matching lines...) Expand all
1027 "", "", "", "", "", "", "", ""); 823 "", "", "", "", "", "", "", "");
1028 autofill_manager_->AddProfile(profile); 824 autofill_manager_->AddProfile(profile);
1029 825
1030 // The page ID sent to the AutoFillManager from the RenderView, used to send 826 // The page ID sent to the AutoFillManager from the RenderView, used to send
1031 // an IPC message back to the renderer. 827 // an IPC message back to the renderer.
1032 const int kPageID = 1; 828 const int kPageID = 1;
1033 829
1034 webkit_glue::FormField field; 830 webkit_glue::FormField field;
1035 autofill_test::CreateTestFormField( 831 autofill_test::CreateTestFormField(
1036 "First Name", "firstname", "", "text", &field); 832 "First Name", "firstname", "", "text", &field);
1037 rvh()->ResetAutoFillState(kPageID); 833 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field));
1038 EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(true, field));
1039 834
1040 // No suggestions provided, so send an empty vector as the results. 835 // No suggestions provided, so send an empty vector as the results.
1041 // This triggers the combined message send. 836 // This triggers the combined message send.
1042 rvh()->AutocompleteSuggestionsReturned(std::vector<string16>()); 837 rvh()->AutocompleteSuggestionsReturned(kPageID, std::vector<string16>());
1043 838
1044 // Test that we sent the right message to the renderer. 839 // Test that we sent the right message to the renderer.
1045 int page_id = 0; 840 int page_id = 0;
1046 std::vector<string16> values; 841 std::vector<string16> values;
1047 std::vector<string16> labels; 842 std::vector<string16> labels;
1048 std::vector<string16> icons; 843 std::vector<string16> icons;
1049 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, 844 EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels,
1050 &icons)); 845 &icons));
1051 EXPECT_EQ(kPageID, page_id); 846 EXPECT_EQ(kPageID, page_id);
1052 ASSERT_EQ(2U, values.size()); 847 ASSERT_EQ(2U, values.size());
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( 1373 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
1579 prefs::kAutoFillAuxiliaryProfilesEnabled)); 1374 prefs::kAutoFillAuxiliaryProfilesEnabled));
1580 profile()->GetPrefs()->SetBoolean( 1375 profile()->GetPrefs()->SetBoolean(
1581 prefs::kAutoFillAuxiliaryProfilesEnabled, true); 1376 prefs::kAutoFillAuxiliaryProfilesEnabled, true);
1582 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); 1377 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled);
1583 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( 1378 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
1584 prefs::kAutoFillAuxiliaryProfilesEnabled)); 1379 prefs::kAutoFillAuxiliaryProfilesEnabled));
1585 #endif 1380 #endif
1586 } 1381 }
1587 1382
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698