| 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" |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 610 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 611 }; | 611 }; |
| 612 | 612 |
| 613 } // namespace | 613 } // namespace |
| 614 | 614 |
| 615 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { | 615 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
| 616 public: | 616 public: |
| 617 AutofillManagerTest() | 617 AutofillManagerTest() |
| 618 : ChromeRenderViewHostTestHarness(), | 618 : ChromeRenderViewHostTestHarness(), |
| 619 ui_thread_(BrowserThread::UI, &message_loop_), | 619 ui_thread_(BrowserThread::UI, &message_loop_), |
| 620 file_thread_(BrowserThread::FILE) { | 620 file_thread_(BrowserThread::FILE), |
| 621 io_thread_(BrowserThread::IO) { |
| 621 } | 622 } |
| 622 | 623 |
| 623 virtual ~AutofillManagerTest() { | 624 virtual ~AutofillManagerTest() { |
| 624 } | 625 } |
| 625 | 626 |
| 626 virtual void SetUp() OVERRIDE { | 627 virtual void SetUp() OVERRIDE { |
| 627 Profile* profile = new TestingProfile(); | 628 TestingProfile* profile = new TestingProfile(); |
| 629 profile->CreateRequestContext(); |
| 628 browser_context_.reset(profile); | 630 browser_context_.reset(profile); |
| 629 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 631 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 630 profile, TestPersonalDataManager::Build); | 632 profile, TestPersonalDataManager::Build); |
| 631 | 633 |
| 632 ChromeRenderViewHostTestHarness::SetUp(); | 634 ChromeRenderViewHostTestHarness::SetUp(); |
| 635 io_thread_.StartIOThread(); |
| 633 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 636 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 634 personal_data_.SetBrowserContext(profile); | 637 personal_data_.SetBrowserContext(profile); |
| 635 autofill_manager_ = new TestAutofillManager( | 638 autofill_manager_ = new TestAutofillManager( |
| 636 web_contents(), | 639 web_contents(), |
| 637 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 640 TabAutofillManagerDelegate::FromWebContents(web_contents()), |
| 638 &personal_data_); | 641 &personal_data_); |
| 639 | 642 |
| 640 file_thread_.Start(); | 643 file_thread_.Start(); |
| 641 } | 644 } |
| 642 | 645 |
| 643 virtual void TearDown() OVERRIDE { | 646 virtual void TearDown() OVERRIDE { |
| 644 // Order of destruction is important as AutofillManager relies on | 647 // Order of destruction is important as AutofillManager relies on |
| 645 // PersonalDataManager to be around when it gets destroyed. Also, a real | 648 // PersonalDataManager to be around when it gets destroyed. Also, a real |
| 646 // 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 |
| 647 // be destroyed at the destruction of the WebContents. | 650 // be destroyed at the destruction of the WebContents. |
| 648 autofill_manager_ = NULL; | 651 autofill_manager_ = NULL; |
| 649 file_thread_.Stop(); | 652 file_thread_.Stop(); |
| 650 ChromeRenderViewHostTestHarness::TearDown(); | 653 ChromeRenderViewHostTestHarness::TearDown(); |
| 654 io_thread_.Stop(); |
| 651 } | 655 } |
| 652 | 656 |
| 653 void UpdatePasswordGenerationState(bool new_renderer) { | 657 void UpdatePasswordGenerationState(bool new_renderer) { |
| 654 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); | 658 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); |
| 655 } | 659 } |
| 656 | 660 |
| 657 void GetAutofillSuggestions(int query_id, | 661 void GetAutofillSuggestions(int query_id, |
| 658 const FormData& form, | 662 const FormData& form, |
| 659 const FormFieldData& field) { | 663 const FormFieldData& field) { |
| 660 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 664 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 if (results) | 743 if (results) |
| 740 *results = autofill_param.b; | 744 *results = autofill_param.b; |
| 741 | 745 |
| 742 process()->sink().ClearMessages(); | 746 process()->sink().ClearMessages(); |
| 743 return true; | 747 return true; |
| 744 } | 748 } |
| 745 | 749 |
| 746 protected: | 750 protected: |
| 747 content::TestBrowserThread ui_thread_; | 751 content::TestBrowserThread ui_thread_; |
| 748 content::TestBrowserThread file_thread_; | 752 content::TestBrowserThread file_thread_; |
| 753 content::TestBrowserThread io_thread_; |
| 749 | 754 |
| 750 scoped_refptr<TestAutofillManager> autofill_manager_; | 755 scoped_refptr<TestAutofillManager> autofill_manager_; |
| 751 TestPersonalDataManager personal_data_; | 756 TestPersonalDataManager personal_data_; |
| 752 | 757 |
| 753 // Used when we want an off the record profile. This will store the original | 758 // Used when we want an off the record profile. This will store the original |
| 754 // profile from which the off the record profile is derived. | 759 // profile from which the off the record profile is derived. |
| 755 scoped_ptr<Profile> other_browser_context_; | 760 scoped_ptr<Profile> other_browser_context_; |
| 756 | 761 |
| 757 private: | 762 private: |
| 758 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); | 763 DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest); |
| 759 }; | 764 }; |
| 760 | 765 |
| 761 class TestFormStructure : public FormStructure { | 766 class TestFormStructure : public FormStructure { |
| 762 public: | 767 public: |
| 763 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} | 768 explicit TestFormStructure(const FormData& form) |
| 769 : FormStructure(form, std::string()) {} |
| 764 virtual ~TestFormStructure() {} | 770 virtual ~TestFormStructure() {} |
| 765 | 771 |
| 766 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, | 772 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, |
| 767 const std::vector<AutofillFieldType>& server_types) { | 773 const std::vector<AutofillFieldType>& server_types) { |
| 768 ASSERT_EQ(field_count(), heuristic_types.size()); | 774 ASSERT_EQ(field_count(), heuristic_types.size()); |
| 769 ASSERT_EQ(field_count(), server_types.size()); | 775 ASSERT_EQ(field_count(), server_types.size()); |
| 770 | 776 |
| 771 for (size_t i = 0; i < field_count(); ++i) { | 777 for (size_t i = 0; i < field_count(); ++i) { |
| 772 AutofillField* form_field = field(i); | 778 AutofillField* form_field = field(i); |
| 773 ASSERT_TRUE(form_field); | 779 ASSERT_TRUE(form_field); |
| (...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 // Test that the form signature for an uploaded form always matches the form | 2674 // Test that the form signature for an uploaded form always matches the form |
| 2669 // signature from the query. | 2675 // signature from the query. |
| 2670 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { | 2676 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { |
| 2671 // Set up our form data. | 2677 // Set up our form data. |
| 2672 FormData form; | 2678 FormData form; |
| 2673 CreateTestAddressFormData(&form); | 2679 CreateTestAddressFormData(&form); |
| 2674 std::vector<FormData> forms(1, form); | 2680 std::vector<FormData> forms(1, form); |
| 2675 FormsSeen(forms); | 2681 FormsSeen(forms); |
| 2676 | 2682 |
| 2677 // Cache the expected form signature. | 2683 // Cache the expected form signature. |
| 2678 std::string signature = FormStructure(form).FormSignature(); | 2684 std::string signature = FormStructure(form, std::string()).FormSignature(); |
| 2679 | 2685 |
| 2680 // Change the structure of the form prior to submission. | 2686 // Change the structure of the form prior to submission. |
| 2681 // Websites would typically invoke JavaScript either on page load or on form | 2687 // Websites would typically invoke JavaScript either on page load or on form |
| 2682 // submit to achieve this. | 2688 // submit to achieve this. |
| 2683 form.fields.pop_back(); | 2689 form.fields.pop_back(); |
| 2684 FormFieldData field = form.fields[3]; | 2690 FormFieldData field = form.fields[3]; |
| 2685 form.fields[3] = form.fields[7]; | 2691 form.fields[3] = form.fields[7]; |
| 2686 form.fields[7] = field; | 2692 form.fields[7] = field; |
| 2687 | 2693 |
| 2688 // Simulate form submission. | 2694 // Simulate form submission. |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3237 | 3243 |
| 3238 FormData form; | 3244 FormData form; |
| 3239 CreateTestAddressFormData(&form); | 3245 CreateTestAddressFormData(&form); |
| 3240 std::vector<FormData> forms(1, form); | 3246 std::vector<FormData> forms(1, form); |
| 3241 FormsSeen(forms); | 3247 FormsSeen(forms); |
| 3242 const FormFieldData& field = form.fields[0]; | 3248 const FormFieldData& field = form.fields[0]; |
| 3243 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3249 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3244 | 3250 |
| 3245 autofill_manager_->SetExternalDelegate(NULL); | 3251 autofill_manager_->SetExternalDelegate(NULL); |
| 3246 } | 3252 } |
| OLD | NEW |