| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 explicit TestAutofillExternalDelegate(AutofillManager* autofill_manager, | 527 explicit TestAutofillExternalDelegate(AutofillManager* autofill_manager, |
| 528 AutofillDriver* autofill_driver) | 528 AutofillDriver* autofill_driver) |
| 529 : AutofillExternalDelegate(autofill_manager, autofill_driver), | 529 : AutofillExternalDelegate(autofill_manager, autofill_driver), |
| 530 on_query_seen_(false), | 530 on_query_seen_(false), |
| 531 on_suggestions_returned_seen_(false) {} | 531 on_suggestions_returned_seen_(false) {} |
| 532 ~TestAutofillExternalDelegate() override {} | 532 ~TestAutofillExternalDelegate() override {} |
| 533 | 533 |
| 534 void OnQuery(int query_id, | 534 void OnQuery(int query_id, |
| 535 const FormData& form, | 535 const FormData& form, |
| 536 const FormFieldData& field, | 536 const FormFieldData& field, |
| 537 const gfx::RectF& bounds, | 537 const gfx::RectF& bounds) override { |
| 538 bool display_warning) override { | |
| 539 on_query_seen_ = true; | 538 on_query_seen_ = true; |
| 540 on_suggestions_returned_seen_ = false; | 539 on_suggestions_returned_seen_ = false; |
| 541 } | 540 } |
| 542 | 541 |
| 543 void OnSuggestionsReturned( | 542 void OnSuggestionsReturned( |
| 544 int query_id, | 543 int query_id, |
| 545 const std::vector<Suggestion>& suggestions) override { | 544 const std::vector<Suggestion>& suggestions) override { |
| 546 on_suggestions_returned_seen_ = true; | 545 on_suggestions_returned_seen_ = true; |
| 547 query_id_ = query_id; | 546 query_id_ = query_id; |
| 548 suggestions_ = suggestions; | 547 suggestions_ = suggestions; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 | 644 |
| 646 // Remove the AutofillWebDataService so TestPersonalDataManager does not | 645 // Remove the AutofillWebDataService so TestPersonalDataManager does not |
| 647 // need to care about removing self as an observer in destruction. | 646 // need to care about removing self as an observer in destruction. |
| 648 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL)); | 647 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL)); |
| 649 personal_data_.SetPrefService(NULL); | 648 personal_data_.SetPrefService(NULL); |
| 650 } | 649 } |
| 651 | 650 |
| 652 void GetAutofillSuggestions(int query_id, | 651 void GetAutofillSuggestions(int query_id, |
| 653 const FormData& form, | 652 const FormData& form, |
| 654 const FormFieldData& field) { | 653 const FormFieldData& field) { |
| 655 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 654 autofill_manager_->OnQueryFormFieldAutofill(query_id, form, field, |
| 656 form, | 655 gfx::Rect()); |
| 657 field, | |
| 658 gfx::Rect(), | |
| 659 false); | |
| 660 } | 656 } |
| 661 | 657 |
| 662 void GetAutofillSuggestions(const FormData& form, | 658 void GetAutofillSuggestions(const FormData& form, |
| 663 const FormFieldData& field) { | 659 const FormFieldData& field) { |
| 664 GetAutofillSuggestions(kDefaultPageID, form, field); | 660 GetAutofillSuggestions(kDefaultPageID, form, field); |
| 665 } | 661 } |
| 666 | 662 |
| 667 void AutocompleteSuggestionsReturned( | 663 void AutocompleteSuggestionsReturned( |
| 668 const std::vector<base::string16>& result) { | 664 const std::vector<base::string16>& result) { |
| 669 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); | 665 autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); |
| (...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2441 suggestions.push_back(ASCIIToUTF16("Jay")); | 2437 suggestions.push_back(ASCIIToUTF16("Jay")); |
| 2442 suggestions.push_back(ASCIIToUTF16("Jason")); | 2438 suggestions.push_back(ASCIIToUTF16("Jason")); |
| 2443 AutocompleteSuggestionsReturned(suggestions); | 2439 AutocompleteSuggestionsReturned(suggestions); |
| 2444 | 2440 |
| 2445 external_delegate_->CheckSuggestions( | 2441 external_delegate_->CheckSuggestions( |
| 2446 kDefaultPageID, | 2442 kDefaultPageID, |
| 2447 Suggestion("Jay", "", "", 0), | 2443 Suggestion("Jay", "", "", 0), |
| 2448 Suggestion("Jason", "", "", 0)); | 2444 Suggestion("Jason", "", "", 0)); |
| 2449 } | 2445 } |
| 2450 | 2446 |
| 2451 // Duplicate of the below test with the respect-autocomplete-off-autofill | 2447 TEST_F(AutofillManagerTest, AutocompleteOffRespectedForAutocomplete) { |
| 2452 // switch. | |
| 2453 TEST_F(AutofillManagerTest, AutocompleteOffRespected) { | |
| 2454 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 2455 switches::kRespectAutocompleteOffForAutofill); | |
| 2456 | |
| 2457 TestAutofillClient client; | 2448 TestAutofillClient client; |
| 2458 autofill_manager_.reset( | 2449 autofill_manager_.reset( |
| 2459 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | 2450 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
| 2460 autofill_manager_->set_autofill_enabled(false); | |
| 2461 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | |
| 2462 | |
| 2463 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | |
| 2464 autocomplete_history_manager.reset( | |
| 2465 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | |
| 2466 autofill_manager_->autocomplete_history_manager_ = | |
| 2467 autocomplete_history_manager.Pass(); | |
| 2468 MockAutocompleteHistoryManager* m = static_cast< | |
| 2469 MockAutocompleteHistoryManager*>( | |
| 2470 autofill_manager_->autocomplete_history_manager_.get()); | |
| 2471 EXPECT_CALL(*m, | |
| 2472 OnGetAutocompleteSuggestions(_, _, _, _, _)).Times(0); | |
| 2473 | |
| 2474 // Set up our form data. | |
| 2475 FormData form; | |
| 2476 test::CreateTestAddressFormData(&form); | |
| 2477 std::vector<FormData> forms(1, form); | |
| 2478 FormsSeen(forms); | |
| 2479 FormFieldData* field = &form.fields[0]; | |
| 2480 field->should_autocomplete = false; | |
| 2481 GetAutofillSuggestions(form, *field); | |
| 2482 } | |
| 2483 | |
| 2484 TEST_F(AutofillManagerTest, AutocompleteOffRespectedWithFlag) { | |
| 2485 TestAutofillClient client; | |
| 2486 autofill_manager_.reset( | |
| 2487 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); | |
| 2488 autofill_manager_->set_autofill_enabled(false); | 2451 autofill_manager_->set_autofill_enabled(false); |
| 2489 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 2452 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 2490 | 2453 |
| 2491 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | 2454 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; |
| 2492 autocomplete_history_manager.reset( | 2455 autocomplete_history_manager.reset( |
| 2493 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); | 2456 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); |
| 2494 autofill_manager_->autocomplete_history_manager_ = | 2457 autofill_manager_->autocomplete_history_manager_ = |
| 2495 autocomplete_history_manager.Pass(); | 2458 autocomplete_history_manager.Pass(); |
| 2496 MockAutocompleteHistoryManager* m = static_cast< | 2459 MockAutocompleteHistoryManager* m = static_cast< |
| 2497 MockAutocompleteHistoryManager*>( | 2460 MockAutocompleteHistoryManager*>( |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3170 | 3133 |
| 3171 external_delegate_->CheckSuggestions( | 3134 external_delegate_->CheckSuggestions( |
| 3172 kDefaultPageID, | 3135 kDefaultPageID, |
| 3173 Suggestion( | 3136 Suggestion( |
| 3174 "Visa\xC2\xA0\xE2\x8B\xAF" | 3137 "Visa\xC2\xA0\xE2\x8B\xAF" |
| 3175 "3456", | 3138 "3456", |
| 3176 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); | 3139 "04/12", kVisaCard, autofill_manager_->GetPackedCreditCardID(4))); |
| 3177 } | 3140 } |
| 3178 | 3141 |
| 3179 } // namespace autofill | 3142 } // namespace autofill |
| OLD | NEW |