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/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "components/autofill/browser/credit_card.h" | 35 #include "components/autofill/browser/credit_card.h" |
36 #include "components/autofill/browser/personal_data_manager.h" | 36 #include "components/autofill/browser/personal_data_manager.h" |
37 #include "components/autofill/browser/test_autofill_external_delegate.h" | 37 #include "components/autofill/browser/test_autofill_external_delegate.h" |
38 #include "components/autofill/common/autofill_messages.h" | 38 #include "components/autofill/common/autofill_messages.h" |
39 #include "components/autofill/common/form_data.h" | 39 #include "components/autofill/common/form_data.h" |
40 #include "components/autofill/common/form_field_data.h" | 40 #include "components/autofill/common/form_field_data.h" |
41 #include "components/autofill/common/forms_seen_state.h" | 41 #include "components/autofill/common/forms_seen_state.h" |
42 #include "components/user_prefs/user_prefs.h" | 42 #include "components/user_prefs/user_prefs.h" |
43 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
44 #include "content/public/test/mock_render_process_host.h" | 44 #include "content/public/test/mock_render_process_host.h" |
45 #include "content/public/test/test_browser_thread.h" | |
46 #include "content/public/test/test_utils.h" | 45 #include "content/public/test/test_utils.h" |
47 #include "googleurl/src/gurl.h" | 46 #include "googleurl/src/gurl.h" |
48 #include "grit/component_resources.h" | 47 #include "grit/component_resources.h" |
49 #include "ipc/ipc_test_sink.h" | 48 #include "ipc/ipc_test_sink.h" |
50 #include "testing/gmock/include/gmock/gmock.h" | 49 #include "testing/gmock/include/gmock/gmock.h" |
51 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
54 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
55 #include "ui/gfx/rect.h" | 54 #include "ui/gfx/rect.h" |
56 | 55 |
57 using content::BrowserThread; | |
58 using content::WebContents; | 56 using content::WebContents; |
59 using testing::_; | 57 using testing::_; |
60 using WebKit::WebFormElement; | 58 using WebKit::WebFormElement; |
61 | 59 |
62 namespace autofill { | 60 namespace autofill { |
63 | 61 |
64 typedef PersonalDataManager::GUIDPair GUIDPair; | 62 typedef PersonalDataManager::GUIDPair GUIDPair; |
65 | 63 |
66 namespace { | 64 namespace { |
67 | 65 |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 std::string submitted_form_signature_; | 618 std::string submitted_form_signature_; |
621 std::vector<FieldTypeSet> expected_submitted_field_types_; | 619 std::vector<FieldTypeSet> expected_submitted_field_types_; |
622 | 620 |
623 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 621 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
624 }; | 622 }; |
625 | 623 |
626 } // namespace | 624 } // namespace |
627 | 625 |
628 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { | 626 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
629 public: | 627 public: |
630 AutofillManagerTest() | |
631 : ChromeRenderViewHostTestHarness(), | |
632 ui_thread_(BrowserThread::UI, &message_loop_), | |
633 file_thread_(BrowserThread::FILE), | |
634 io_thread_(BrowserThread::IO) { | |
635 } | |
636 | |
637 virtual ~AutofillManagerTest() { | |
638 } | |
639 | |
640 virtual void SetUp() OVERRIDE { | 628 virtual void SetUp() OVERRIDE { |
641 TestingProfile* profile = CreateProfile(); | 629 TestingProfile* profile = CreateProfile(); |
642 profile->CreateRequestContext(); | 630 profile->CreateRequestContext(); |
643 browser_context_.reset(profile); | 631 browser_context_.reset(profile); |
644 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 632 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
645 profile, TestPersonalDataManager::Build); | 633 profile, TestPersonalDataManager::Build); |
646 | 634 |
647 ChromeRenderViewHostTestHarness::SetUp(); | 635 ChromeRenderViewHostTestHarness::SetUp(); |
648 io_thread_.StartIOThread(); | |
649 | 636 |
650 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 637 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
651 | 638 |
652 personal_data_.SetBrowserContext(profile); | 639 personal_data_.SetBrowserContext(profile); |
653 autofill_manager_.reset(new TestAutofillManager( | 640 autofill_manager_.reset(new TestAutofillManager( |
654 web_contents(), | 641 web_contents(), |
655 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), | 642 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |
656 &personal_data_)); | 643 &personal_data_)); |
657 | |
658 file_thread_.Start(); | |
659 } | 644 } |
660 | 645 |
661 virtual void TearDown() OVERRIDE { | 646 virtual void TearDown() OVERRIDE { |
662 // Order of destruction is important as AutofillManager relies on | 647 // Order of destruction is important as AutofillManager relies on |
663 // PersonalDataManager to be around when it gets destroyed. Also, a real | 648 // PersonalDataManager to be around when it gets destroyed. Also, a real |
664 // AutofillManager is tied to the lifetime of the WebContents, so it must | 649 // AutofillManager is tied to the lifetime of the WebContents, so it must |
665 // be destroyed at the destruction of the WebContents. | 650 // be destroyed at the destruction of the WebContents. |
666 autofill_manager_.reset(); | 651 autofill_manager_.reset(); |
667 file_thread_.Stop(); | |
668 ChromeRenderViewHostTestHarness::TearDown(); | 652 ChromeRenderViewHostTestHarness::TearDown(); |
669 io_thread_.Stop(); | |
670 | 653 |
671 // Remove the BrowserContext so TestPersonalDataManager does not need to | 654 // Remove the BrowserContext so TestPersonalDataManager does not need to |
672 // care about removing self as an observer in destruction. | 655 // care about removing self as an observer in destruction. |
673 personal_data_.SetBrowserContext(NULL); | 656 personal_data_.SetBrowserContext(NULL); |
674 } | 657 } |
675 | 658 |
676 virtual TestingProfile* CreateProfile() { | 659 virtual TestingProfile* CreateProfile() { |
677 return new TestingProfile(); | 660 return new TestingProfile(); |
678 } | 661 } |
679 | 662 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 if (page_id) | 759 if (page_id) |
777 *page_id = autofill_param.a; | 760 *page_id = autofill_param.a; |
778 if (results) | 761 if (results) |
779 *results = autofill_param.b; | 762 *results = autofill_param.b; |
780 | 763 |
781 process()->sink().ClearMessages(); | 764 process()->sink().ClearMessages(); |
782 return true; | 765 return true; |
783 } | 766 } |
784 | 767 |
785 protected: | 768 protected: |
786 content::TestBrowserThread ui_thread_; | |
787 content::TestBrowserThread file_thread_; | |
788 content::TestBrowserThread io_thread_; | |
789 | |
790 scoped_ptr<TestAutofillManager> autofill_manager_; | 769 scoped_ptr<TestAutofillManager> autofill_manager_; |
791 TestPersonalDataManager personal_data_; | 770 TestPersonalDataManager personal_data_; |
792 | 771 |
793 // Used when we want an off the record profile. This will store the original | 772 // Used when we want an off the record profile. This will store the original |
794 // profile from which the off the record profile is derived. | 773 // profile from which the off the record profile is derived. |
795 scoped_ptr<Profile> other_browser_context_; | 774 scoped_ptr<Profile> other_browser_context_; |
796 | |
797 private: | |
798 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); | |
799 }; | 775 }; |
800 | 776 |
801 class TestFormStructure : public FormStructure { | 777 class TestFormStructure : public FormStructure { |
802 public: | 778 public: |
803 explicit TestFormStructure(const FormData& form) | 779 explicit TestFormStructure(const FormData& form) |
804 : FormStructure(form, std::string()) {} | 780 : FormStructure(form, std::string()) {} |
805 virtual ~TestFormStructure() {} | 781 virtual ~TestFormStructure() {} |
806 | 782 |
807 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, | 783 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, |
808 const std::vector<AutofillFieldType>& server_types) { | 784 const std::vector<AutofillFieldType>& server_types) { |
(...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3210 CreateTestAddressFormData(&form); | 3186 CreateTestAddressFormData(&form); |
3211 std::vector<FormData> forms(1, form); | 3187 std::vector<FormData> forms(1, form); |
3212 FormsSeen(forms); | 3188 FormsSeen(forms); |
3213 const FormFieldData& field = form.fields[0]; | 3189 const FormFieldData& field = form.fields[0]; |
3214 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3190 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3215 | 3191 |
3216 autofill_manager_->SetExternalDelegate(NULL); | 3192 autofill_manager_->SetExternalDelegate(NULL); |
3217 } | 3193 } |
3218 | 3194 |
3219 } // namespace autofill | 3195 } // namespace autofill |
OLD | NEW |