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 25 matching lines...) Expand all Loading... |
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/browser/test_autofill_manager_delegate.h" | 38 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
39 #include "components/autofill/common/autofill_messages.h" | 39 #include "components/autofill/common/autofill_messages.h" |
40 #include "components/autofill/common/form_data.h" | 40 #include "components/autofill/common/form_data.h" |
41 #include "components/autofill/common/form_field_data.h" | 41 #include "components/autofill/common/form_field_data.h" |
42 #include "components/autofill/common/forms_seen_state.h" | 42 #include "components/autofill/common/forms_seen_state.h" |
43 #include "components/user_prefs/user_prefs.h" | 43 #include "components/user_prefs/user_prefs.h" |
44 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
45 #include "content/public/test/mock_render_process_host.h" | 45 #include "content/public/test/mock_render_process_host.h" |
46 #include "content/public/test/test_browser_thread.h" | |
47 #include "content/public/test/test_utils.h" | 46 #include "content/public/test/test_utils.h" |
48 #include "googleurl/src/gurl.h" | 47 #include "googleurl/src/gurl.h" |
49 #include "grit/component_resources.h" | 48 #include "grit/component_resources.h" |
50 #include "ipc/ipc_test_sink.h" | 49 #include "ipc/ipc_test_sink.h" |
51 #include "testing/gmock/include/gmock/gmock.h" | 50 #include "testing/gmock/include/gmock/gmock.h" |
52 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
54 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
55 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
56 #include "ui/gfx/rect.h" | 55 #include "ui/gfx/rect.h" |
57 | 56 |
58 using content::BrowserThread; | |
59 using content::WebContents; | 57 using content::WebContents; |
60 using testing::_; | 58 using testing::_; |
61 using WebKit::WebFormElement; | 59 using WebKit::WebFormElement; |
62 | 60 |
63 namespace autofill { | 61 namespace autofill { |
64 | 62 |
65 typedef PersonalDataManager::GUIDPair GUIDPair; | 63 typedef PersonalDataManager::GUIDPair GUIDPair; |
66 | 64 |
67 namespace { | 65 namespace { |
68 | 66 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 load_time, | 547 load_time, |
550 interaction_time, | 548 interaction_time, |
551 submission_time); | 549 submission_time); |
552 } | 550 } |
553 | 551 |
554 virtual void OnMaybeShowAutocheckoutBubble( | 552 virtual void OnMaybeShowAutocheckoutBubble( |
555 const FormData& form, | 553 const FormData& form, |
556 const gfx::RectF& bounding_box) OVERRIDE { | 554 const gfx::RectF& bounding_box) OVERRIDE { |
557 AutofillManager::OnMaybeShowAutocheckoutBubble(form, bounding_box); | 555 AutofillManager::OnMaybeShowAutocheckoutBubble(form, bounding_box); |
558 // Needed for AutocheckoutManager to post task on IO thread. | 556 // Needed for AutocheckoutManager to post task on IO thread. |
559 content::RunAllPendingInMessageLoop(BrowserThread::IO); | 557 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); |
560 } | 558 } |
561 | 559 |
562 // Resets the MessageLoopRunner so that it can wait for an asynchronous form | 560 // Resets the MessageLoopRunner so that it can wait for an asynchronous form |
563 // submission to complete. | 561 // submission to complete. |
564 void ResetMessageLoopRunner() { | 562 void ResetMessageLoopRunner() { |
565 message_loop_runner_ = new content::MessageLoopRunner(); | 563 message_loop_runner_ = new content::MessageLoopRunner(); |
566 } | 564 } |
567 | 565 |
568 // Wait for the asynchronous OnFormSubmitted() call to complete. | 566 // Wait for the asynchronous OnFormSubmitted() call to complete. |
569 void WaitForAsyncFormSubmit() { | 567 void WaitForAsyncFormSubmit() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 std::string submitted_form_signature_; | 641 std::string submitted_form_signature_; |
644 std::vector<FieldTypeSet> expected_submitted_field_types_; | 642 std::vector<FieldTypeSet> expected_submitted_field_types_; |
645 | 643 |
646 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 644 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
647 }; | 645 }; |
648 | 646 |
649 } // namespace | 647 } // namespace |
650 | 648 |
651 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { | 649 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
652 public: | 650 public: |
653 AutofillManagerTest() | |
654 : ChromeRenderViewHostTestHarness(), | |
655 ui_thread_(BrowserThread::UI, &message_loop_), | |
656 file_thread_(BrowserThread::FILE), | |
657 io_thread_(BrowserThread::IO) { | |
658 } | |
659 | |
660 virtual ~AutofillManagerTest() { | |
661 } | |
662 | |
663 virtual void SetUp() OVERRIDE { | 651 virtual void SetUp() OVERRIDE { |
664 TestingProfile* profile = CreateProfile(); | 652 TestingProfile* profile = CreateProfile(); |
665 profile->CreateRequestContext(); | 653 profile->CreateRequestContext(); |
666 browser_context_.reset(profile); | 654 browser_context_.reset(profile); |
667 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 655 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
668 profile, TestPersonalDataManager::Build); | 656 profile, TestPersonalDataManager::Build); |
669 | 657 |
670 ChromeRenderViewHostTestHarness::SetUp(); | 658 ChromeRenderViewHostTestHarness::SetUp(); |
671 io_thread_.StartIOThread(); | |
672 | 659 |
673 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 660 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
674 | 661 |
675 personal_data_.SetBrowserContext(profile); | 662 personal_data_.SetBrowserContext(profile); |
676 autofill_manager_.reset(new TestAutofillManager( | 663 autofill_manager_.reset(new TestAutofillManager( |
677 web_contents(), | 664 web_contents(), |
678 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), | 665 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |
679 &personal_data_)); | 666 &personal_data_)); |
680 | |
681 file_thread_.Start(); | |
682 } | 667 } |
683 | 668 |
684 virtual void TearDown() OVERRIDE { | 669 virtual void TearDown() OVERRIDE { |
685 // Order of destruction is important as AutofillManager relies on | 670 // Order of destruction is important as AutofillManager relies on |
686 // PersonalDataManager to be around when it gets destroyed. Also, a real | 671 // PersonalDataManager to be around when it gets destroyed. Also, a real |
687 // AutofillManager is tied to the lifetime of the WebContents, so it must | 672 // AutofillManager is tied to the lifetime of the WebContents, so it must |
688 // be destroyed at the destruction of the WebContents. | 673 // be destroyed at the destruction of the WebContents. |
689 autofill_manager_.reset(); | 674 autofill_manager_.reset(); |
690 file_thread_.Stop(); | |
691 ChromeRenderViewHostTestHarness::TearDown(); | 675 ChromeRenderViewHostTestHarness::TearDown(); |
692 io_thread_.Stop(); | |
693 | 676 |
694 // Remove the BrowserContext so TestPersonalDataManager does not need to | 677 // Remove the BrowserContext so TestPersonalDataManager does not need to |
695 // care about removing self as an observer in destruction. | 678 // care about removing self as an observer in destruction. |
696 personal_data_.SetBrowserContext(NULL); | 679 personal_data_.SetBrowserContext(NULL); |
697 } | 680 } |
698 | 681 |
699 virtual TestingProfile* CreateProfile() { | 682 virtual TestingProfile* CreateProfile() { |
700 return new TestingProfile(); | 683 return new TestingProfile(); |
701 } | 684 } |
702 | 685 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 if (page_id) | 782 if (page_id) |
800 *page_id = autofill_param.a; | 783 *page_id = autofill_param.a; |
801 if (results) | 784 if (results) |
802 *results = autofill_param.b; | 785 *results = autofill_param.b; |
803 | 786 |
804 process()->sink().ClearMessages(); | 787 process()->sink().ClearMessages(); |
805 return true; | 788 return true; |
806 } | 789 } |
807 | 790 |
808 protected: | 791 protected: |
809 content::TestBrowserThread ui_thread_; | |
810 content::TestBrowserThread file_thread_; | |
811 content::TestBrowserThread io_thread_; | |
812 | |
813 scoped_ptr<TestAutofillManager> autofill_manager_; | 792 scoped_ptr<TestAutofillManager> autofill_manager_; |
814 TestPersonalDataManager personal_data_; | 793 TestPersonalDataManager personal_data_; |
815 | 794 |
816 // Used when we want an off the record profile. This will store the original | 795 // Used when we want an off the record profile. This will store the original |
817 // profile from which the off the record profile is derived. | 796 // profile from which the off the record profile is derived. |
818 scoped_ptr<Profile> other_browser_context_; | 797 scoped_ptr<Profile> other_browser_context_; |
819 | |
820 private: | |
821 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); | |
822 }; | 798 }; |
823 | 799 |
824 class TestFormStructure : public FormStructure { | 800 class TestFormStructure : public FormStructure { |
825 public: | 801 public: |
826 explicit TestFormStructure(const FormData& form) | 802 explicit TestFormStructure(const FormData& form) |
827 : FormStructure(form, std::string()) {} | 803 : FormStructure(form, std::string()) {} |
828 virtual ~TestFormStructure() {} | 804 virtual ~TestFormStructure() {} |
829 | 805 |
830 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, | 806 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, |
831 const std::vector<AutofillFieldType>& server_types) { | 807 const std::vector<AutofillFieldType>& server_types) { |
(...skipping 2472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3304 CreateTestAddressFormData(&form); | 3280 CreateTestAddressFormData(&form); |
3305 std::vector<FormData> forms(1, form); | 3281 std::vector<FormData> forms(1, form); |
3306 FormsSeen(forms); | 3282 FormsSeen(forms); |
3307 const FormFieldData& field = form.fields[0]; | 3283 const FormFieldData& field = form.fields[0]; |
3308 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3284 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3309 | 3285 |
3310 autofill_manager_->SetExternalDelegate(NULL); | 3286 autofill_manager_->SetExternalDelegate(NULL); |
3311 } | 3287 } |
3312 | 3288 |
3313 } // namespace autofill | 3289 } // namespace autofill |
OLD | NEW |