| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/tuple.h" | 15 #include "base/tuple.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/autocomplete_history_manager.h" | 17 #include "chrome/browser/autocomplete_history_manager.h" |
| 18 #include "chrome/browser/autofill/autofill_common_test.h" | 18 #include "chrome/browser/autofill/autofill_common_test.h" |
| 19 #include "chrome/browser/autofill/autofill_manager.h" | 19 #include "chrome/browser/autofill/autofill_manager.h" |
| 20 #include "chrome/browser/autofill/autofill_profile.h" | 20 #include "chrome/browser/autofill/autofill_profile.h" |
| 21 #include "chrome/browser/autofill/credit_card.h" | 21 #include "chrome/browser/autofill/credit_card.h" |
| 22 #include "chrome/browser/autofill/personal_data_manager.h" | 22 #include "chrome/browser/autofill/personal_data_manager.h" |
| 23 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 23 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 24 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 24 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 29 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 30 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 30 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 31 #include "chrome/common/autofill_messages.h" | 31 #include "chrome/common/autofill_messages.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/test/mock_render_process_host.h" | 36 #include "content/public/test/mock_render_process_host.h" |
| 37 #include "content/public/test/test_browser_thread.h" | 37 #include "content/public/test/test_browser_thread.h" |
| 38 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
| 39 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 40 #include "ipc/ipc_test_sink.h" | 40 #include "ipc/ipc_test_sink.h" |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 572 |
| 573 std::string submitted_form_signature_; | 573 std::string submitted_form_signature_; |
| 574 std::vector<FieldTypeSet> expected_submitted_field_types_; | 574 std::vector<FieldTypeSet> expected_submitted_field_types_; |
| 575 std::vector<bool> sent_states_; | 575 std::vector<bool> sent_states_; |
| 576 | 576 |
| 577 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 577 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 578 }; | 578 }; |
| 579 | 579 |
| 580 } // namespace | 580 } // namespace |
| 581 | 581 |
| 582 class AutofillManagerTest : public TabContentsWrapperTestHarness { | 582 class AutofillManagerTest : public TabContentsTestHarness { |
| 583 public: | 583 public: |
| 584 typedef AutofillManager::GUIDPair GUIDPair; | 584 typedef AutofillManager::GUIDPair GUIDPair; |
| 585 | 585 |
| 586 AutofillManagerTest() | 586 AutofillManagerTest() |
| 587 : TabContentsWrapperTestHarness(), | 587 : TabContentsTestHarness(), |
| 588 ui_thread_(BrowserThread::UI, &message_loop_), | 588 ui_thread_(BrowserThread::UI, &message_loop_), |
| 589 file_thread_(BrowserThread::FILE) { | 589 file_thread_(BrowserThread::FILE) { |
| 590 } | 590 } |
| 591 | 591 |
| 592 virtual ~AutofillManagerTest() { | 592 virtual ~AutofillManagerTest() { |
| 593 // Order of destruction is important as AutofillManager relies on | 593 // Order of destruction is important as AutofillManager relies on |
| 594 // PersonalDataManager to be around when it gets destroyed. | 594 // PersonalDataManager to be around when it gets destroyed. |
| 595 autofill_manager_ = NULL; | 595 autofill_manager_ = NULL; |
| 596 } | 596 } |
| 597 | 597 |
| 598 virtual void SetUp() OVERRIDE { | 598 virtual void SetUp() OVERRIDE { |
| 599 Profile* profile = new TestingProfile(); | 599 Profile* profile = new TestingProfile(); |
| 600 browser_context_.reset(profile); | 600 browser_context_.reset(profile); |
| 601 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 601 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 602 profile, TestPersonalDataManager::Build); | 602 profile, TestPersonalDataManager::Build); |
| 603 | 603 |
| 604 TabContentsWrapperTestHarness::SetUp(); | 604 TabContentsTestHarness::SetUp(); |
| 605 autofill_manager_ = new TestAutofillManager(contents_wrapper(), | 605 autofill_manager_ = new TestAutofillManager(tab_contents(), |
| 606 &personal_data_); | 606 &personal_data_); |
| 607 | 607 |
| 608 file_thread_.Start(); | 608 file_thread_.Start(); |
| 609 } | 609 } |
| 610 | 610 |
| 611 virtual void TearDown() OVERRIDE { | 611 virtual void TearDown() OVERRIDE { |
| 612 file_thread_.Stop(); | 612 file_thread_.Stop(); |
| 613 TabContentsWrapperTestHarness::TearDown(); | 613 TabContentsTestHarness::TearDown(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void UpdatePasswordGenerationState(bool new_renderer) { | 616 void UpdatePasswordGenerationState(bool new_renderer) { |
| 617 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); | 617 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 618 } | 618 } |
| 619 | 619 |
| 620 void GetAutofillSuggestions(int query_id, | 620 void GetAutofillSuggestions(int query_id, |
| 621 const webkit::forms::FormData& form, | 621 const webkit::forms::FormData& form, |
| 622 const webkit::forms::FormField& field) { | 622 const webkit::forms::FormField& field) { |
| 623 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 623 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| 624 form, | 624 form, |
| 625 field, | 625 field, |
| 626 gfx::Rect(), | 626 gfx::Rect(), |
| 627 false); | 627 false); |
| 628 } | 628 } |
| 629 | 629 |
| 630 void GetAutofillSuggestions(const webkit::forms::FormData& form, | 630 void GetAutofillSuggestions(const webkit::forms::FormData& form, |
| 631 const webkit::forms::FormField& field) { | 631 const webkit::forms::FormField& field) { |
| 632 GetAutofillSuggestions(kDefaultPageID, form, field); | 632 GetAutofillSuggestions(kDefaultPageID, form, field); |
| 633 } | 633 } |
| 634 | 634 |
| 635 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { | 635 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { |
| 636 contents_wrapper()->autocomplete_history_manager()-> | 636 tab_contents()->autocomplete_history_manager()-> |
| 637 SendSuggestions(&result); | 637 SendSuggestions(&result); |
| 638 } | 638 } |
| 639 | 639 |
| 640 void FormsSeen(const std::vector<webkit::forms::FormData>& forms) { | 640 void FormsSeen(const std::vector<webkit::forms::FormData>& forms) { |
| 641 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 641 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void FormSubmitted(const FormData& form) { | 644 void FormSubmitted(const FormData& form) { |
| 645 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 645 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
| 646 autofill_manager_->WaitForAsyncFormSubmit(); | 646 autofill_manager_->WaitForAsyncFormSubmit(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 674 *page_id = autofill_param.a; | 674 *page_id = autofill_param.a; |
| 675 if (values) | 675 if (values) |
| 676 *values = autofill_param.b; | 676 *values = autofill_param.b; |
| 677 if (labels) | 677 if (labels) |
| 678 *labels = autofill_param.c; | 678 *labels = autofill_param.c; |
| 679 if (icons) | 679 if (icons) |
| 680 *icons = autofill_param.d; | 680 *icons = autofill_param.d; |
| 681 if (unique_ids) | 681 if (unique_ids) |
| 682 *unique_ids = autofill_param.e; | 682 *unique_ids = autofill_param.e; |
| 683 | 683 |
| 684 contents_wrapper()->autocomplete_history_manager()->CancelPendingQuery(); | 684 tab_contents()->autocomplete_history_manager()->CancelPendingQuery(); |
| 685 process()->sink().ClearMessages(); | 685 process()->sink().ClearMessages(); |
| 686 return true; | 686 return true; |
| 687 } | 687 } |
| 688 | 688 |
| 689 bool GetAutofillFormDataFilledMessage(int *page_id, FormData* results) { | 689 bool GetAutofillFormDataFilledMessage(int *page_id, FormData* results) { |
| 690 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; | 690 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; |
| 691 const IPC::Message* message = | 691 const IPC::Message* message = |
| 692 process()->sink().GetFirstMessageMatching(kMsgID); | 692 process()->sink().GetFirstMessageMatching(kMsgID); |
| 693 if (!message) | 693 if (!message) |
| 694 return false; | 694 return false; |
| (...skipping 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3090 const gfx::Rect& bounds) OVERRIDE {} | 3090 const gfx::Rect& bounds) OVERRIDE {} |
| 3091 | 3091 |
| 3092 private: | 3092 private: |
| 3093 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 3093 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 3094 }; | 3094 }; |
| 3095 | 3095 |
| 3096 } // namespace | 3096 } // namespace |
| 3097 | 3097 |
| 3098 // Test our external delegate is called at the right time. | 3098 // Test our external delegate is called at the right time. |
| 3099 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 3099 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
| 3100 MockAutofillExternalDelegate external_delegate(contents_wrapper(), | 3100 MockAutofillExternalDelegate external_delegate(tab_contents(), |
| 3101 autofill_manager_); | 3101 autofill_manager_); |
| 3102 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); | 3102 EXPECT_CALL(external_delegate, OnQuery(_, _, _, _, _)); |
| 3103 autofill_manager_->SetExternalDelegate(&external_delegate); | 3103 autofill_manager_->SetExternalDelegate(&external_delegate); |
| 3104 | 3104 |
| 3105 FormData form; | 3105 FormData form; |
| 3106 CreateTestAddressFormData(&form); | 3106 CreateTestAddressFormData(&form); |
| 3107 std::vector<FormData> forms(1, form); | 3107 std::vector<FormData> forms(1, form); |
| 3108 FormsSeen(forms); | 3108 FormsSeen(forms); |
| 3109 const FormField& field = form.fields[0]; | 3109 const FormField& field = form.fields[0]; |
| 3110 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3110 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3111 | 3111 |
| 3112 autofill_manager_->SetExternalDelegate(NULL); | 3112 autofill_manager_->SetExternalDelegate(NULL); |
| 3113 } | 3113 } |
| 3114 | 3114 |
| 3115 #if defined(OS_ANDROID) || defined(TOOLKIT_GTK) | 3115 #if defined(OS_ANDROID) || defined(TOOLKIT_GTK) |
| 3116 // OS_ANDROID defines an external delegate, but prerequisites for | 3116 // OS_ANDROID defines an external delegate, but prerequisites for |
| 3117 // landing autofill_external_delegate_android.cc in the Chromium tree | 3117 // landing autofill_external_delegate_android.cc in the Chromium tree |
| 3118 // have not themselves landed. | 3118 // have not themselves landed. |
| 3119 | 3119 |
| 3120 // Turn on the external delegate. Recreate a WebContents. Make sure | 3120 // Turn on the external delegate. Recreate a WebContents. Make sure |
| 3121 // an external delegate was set in the proper structures. | 3121 // an external delegate was set in the proper structures. |
| 3122 TEST_F(AutofillManagerTest, TestTabContentsWithExternalDelegate) { | 3122 TEST_F(AutofillManagerTest, TestTabContentsWithExternalDelegate) { |
| 3123 CommandLine::ForCurrentProcess()->AppendSwitch( | 3123 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3124 switches::kExternalAutofillPopup); | 3124 switches::kExternalAutofillPopup); |
| 3125 | 3125 |
| 3126 // Setting the contents creates a new TabContentsWrapper. | 3126 // Setting the contents creates a new TabContentsWrapper. |
| 3127 WebContents* contents = CreateTestWebContents(); | 3127 WebContents* contents = CreateTestWebContents(); |
| 3128 SetContents(contents); | 3128 SetContents(contents); |
| 3129 | 3129 |
| 3130 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); | 3130 AutofillManager* autofill_manager = tab_contents()->autofill_manager(); |
| 3131 EXPECT_TRUE(autofill_manager->external_delegate()); | 3131 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 3132 | 3132 |
| 3133 AutocompleteHistoryManager* autocomplete_history_manager = | 3133 AutocompleteHistoryManager* autocomplete_history_manager = |
| 3134 contents_wrapper()->autocomplete_history_manager(); | 3134 tab_contents()->autocomplete_history_manager(); |
| 3135 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3135 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 3136 } | 3136 } |
| 3137 | 3137 |
| 3138 #endif // OS_ANDROID | 3138 #endif // OS_ANDROID |
| OLD | NEW |