Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 11867025: Download autocheckout whitelist and enable autocheckout for whitelisted sites only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = CreateProfile(); 628 TestingProfile* profile = CreateProfile();
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 virtual TestingProfile* CreateProfile() { 657 virtual TestingProfile* CreateProfile() {
654 return new TestingProfile(); 658 return new TestingProfile();
655 } 659 }
656 660
657 void UpdatePasswordGenerationState(bool new_renderer) { 661 void UpdatePasswordGenerationState(bool new_renderer) {
658 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer); 662 autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer);
659 } 663 }
660 664
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 IncognitoAutofillManagerTest : public AutofillManagerTest { 766 class IncognitoAutofillManagerTest : public AutofillManagerTest {
762 public: 767 public:
763 IncognitoAutofillManagerTest() {} 768 IncognitoAutofillManagerTest() {}
764 virtual ~IncognitoAutofillManagerTest() {} 769 virtual ~IncognitoAutofillManagerTest() {}
765 770
766 virtual TestingProfile* CreateProfile() OVERRIDE { 771 virtual TestingProfile* CreateProfile() OVERRIDE {
767 // Create an incognito profile. 772 // Create an incognito profile.
768 TestingProfile::Builder builder; 773 TestingProfile::Builder builder;
769 builder.SetOffTheRecord(); 774 builder.SetOffTheRecord();
770 return builder.Build().release(); 775 return builder.Build().release();
771 } 776 }
772 }; 777 };
773 778
774 class TestFormStructure : public FormStructure { 779 class TestFormStructure : public FormStructure {
775 public: 780 public:
776 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} 781 explicit TestFormStructure(const FormData& form)
782 : FormStructure(form, std::string()) {}
777 virtual ~TestFormStructure() {} 783 virtual ~TestFormStructure() {}
778 784
779 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, 785 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types,
780 const std::vector<AutofillFieldType>& server_types) { 786 const std::vector<AutofillFieldType>& server_types) {
781 ASSERT_EQ(field_count(), heuristic_types.size()); 787 ASSERT_EQ(field_count(), heuristic_types.size());
782 ASSERT_EQ(field_count(), server_types.size()); 788 ASSERT_EQ(field_count(), server_types.size());
783 789
784 for (size_t i = 0; i < field_count(); ++i) { 790 for (size_t i = 0; i < field_count(); ++i) {
785 AutofillField* form_field = field(i); 791 AutofillField* form_field = field(i);
786 ASSERT_TRUE(form_field); 792 ASSERT_TRUE(form_field);
(...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after
2631 // Test that the form signature for an uploaded form always matches the form 2637 // Test that the form signature for an uploaded form always matches the form
2632 // signature from the query. 2638 // signature from the query.
2633 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) { 2639 TEST_F(AutofillManagerTest, FormSubmittedWithDifferentFields) {
2634 // Set up our form data. 2640 // Set up our form data.
2635 FormData form; 2641 FormData form;
2636 CreateTestAddressFormData(&form); 2642 CreateTestAddressFormData(&form);
2637 std::vector<FormData> forms(1, form); 2643 std::vector<FormData> forms(1, form);
2638 FormsSeen(forms); 2644 FormsSeen(forms);
2639 2645
2640 // Cache the expected form signature. 2646 // Cache the expected form signature.
2641 std::string signature = FormStructure(form).FormSignature(); 2647 std::string signature = FormStructure(form, std::string()).FormSignature();
2642 2648
2643 // Change the structure of the form prior to submission. 2649 // Change the structure of the form prior to submission.
2644 // Websites would typically invoke JavaScript either on page load or on form 2650 // Websites would typically invoke JavaScript either on page load or on form
2645 // submit to achieve this. 2651 // submit to achieve this.
2646 form.fields.pop_back(); 2652 form.fields.pop_back();
2647 FormFieldData field = form.fields[3]; 2653 FormFieldData field = form.fields[3];
2648 form.fields[3] = form.fields[7]; 2654 form.fields[3] = form.fields[7];
2649 form.fields[7] = field; 2655 form.fields[7] = field;
2650 2656
2651 // Simulate form submission. 2657 // Simulate form submission.
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 3221
3216 FormData form; 3222 FormData form;
3217 CreateTestAddressFormData(&form); 3223 CreateTestAddressFormData(&form);
3218 std::vector<FormData> forms(1, form); 3224 std::vector<FormData> forms(1, form);
3219 FormsSeen(forms); 3225 FormsSeen(forms);
3220 const FormFieldData& field = form.fields[0]; 3226 const FormFieldData& field = form.fields[0];
3221 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 3227 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
3222 3228
3223 autofill_manager_->SetExternalDelegate(NULL); 3229 autofill_manager_->SetExternalDelegate(NULL);
3224 } 3230 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/autofill_merge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698