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

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 18068017: Change RenderViewHostTestHarness to create BrowserContext after thread startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 std::vector<int> autofill_unique_ids_; 727 std::vector<int> autofill_unique_ids_;
728 728
729 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); 729 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate);
730 }; 730 };
731 731
732 } // namespace 732 } // namespace
733 733
734 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { 734 class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
735 public: 735 public:
736 virtual void SetUp() OVERRIDE { 736 virtual void SetUp() OVERRIDE {
737 TestingProfile* profile = CreateProfile(); 737 ChromeRenderViewHostTestHarness::SetUp();
738 profile->CreateRequestContext(); 738
739 browser_context_.reset(profile);
740 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( 739 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
741 profile, TestPersonalDataManager::Build); 740 profile(), TestPersonalDataManager::Build);
742 741
743 ChromeRenderViewHostTestHarness::SetUp();
744 742
745 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 743 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents());
746 744
747 personal_data_.SetBrowserContext(profile); 745 personal_data_.SetBrowserContext(profile());
748 autofill_driver_.reset(new MockAutofillDriver(web_contents())); 746 autofill_driver_.reset(new MockAutofillDriver(web_contents()));
749 autofill_manager_.reset(new TestAutofillManager( 747 autofill_manager_.reset(new TestAutofillManager(
750 autofill_driver_.get(), 748 autofill_driver_.get(),
751 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), 749 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()),
752 &personal_data_)); 750 &personal_data_));
753 751
754 external_delegate_.reset(new TestAutofillExternalDelegate( 752 external_delegate_.reset(new TestAutofillExternalDelegate(
755 web_contents(), 753 web_contents(),
756 autofill_manager_.get(), 754 autofill_manager_.get(),
757 autofill_driver_.get())); 755 autofill_driver_.get()));
758 autofill_manager_->SetExternalDelegate(external_delegate_.get()); 756 autofill_manager_->SetExternalDelegate(external_delegate_.get());
759 } 757 }
760 758
761 virtual void TearDown() OVERRIDE { 759 virtual void TearDown() OVERRIDE {
762 // Order of destruction is important as AutofillManager relies on 760 // Order of destruction is important as AutofillManager relies on
763 // PersonalDataManager to be around when it gets destroyed. Also, a real 761 // PersonalDataManager to be around when it gets destroyed. Also, a real
764 // AutofillManager is tied to the lifetime of the WebContents, so it must 762 // AutofillManager is tied to the lifetime of the WebContents, so it must
765 // be destroyed at the destruction of the WebContents. 763 // be destroyed at the destruction of the WebContents.
766 autofill_manager_.reset(); 764 autofill_manager_.reset();
767 autofill_driver_.reset(); 765 autofill_driver_.reset();
768 ChromeRenderViewHostTestHarness::TearDown(); 766 ChromeRenderViewHostTestHarness::TearDown();
769 767
770 // Remove the BrowserContext so TestPersonalDataManager does not need to 768 // Remove the BrowserContext so TestPersonalDataManager does not need to
771 // care about removing self as an observer in destruction. 769 // care about removing self as an observer in destruction.
772 personal_data_.SetBrowserContext(NULL); 770 personal_data_.SetBrowserContext(NULL);
773 } 771 }
774 772
775 virtual TestingProfile* CreateProfile() { 773 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE {
776 return new TestingProfile(); 774 TestingProfile* profile = new TestingProfile();
775 profile->CreateRequestContext();
776 return profile;
777 } 777 }
778 778
779 void GetAutofillSuggestions(int query_id, 779 void GetAutofillSuggestions(int query_id,
780 const FormData& form, 780 const FormData& form,
781 const FormFieldData& field) { 781 const FormFieldData& field) {
782 autofill_manager_->OnQueryFormFieldAutofill(query_id, 782 autofill_manager_->OnQueryFormFieldAutofill(query_id,
783 form, 783 form,
784 field, 784 field,
785 gfx::Rect(), 785 gfx::Rect(),
786 false); 786 false);
(...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after
3267 forms.push_back(user_supplied); 3267 forms.push_back(user_supplied);
3268 3268
3269 // FormStructure should contain the same forms as before. 3269 // FormStructure should contain the same forms as before.
3270 DynamicFormsSeen(forms); 3270 DynamicFormsSeen(forms);
3271 form_structures = autofill_manager_->GetFormStructures(); 3271 form_structures = autofill_manager_->GetFormStructures();
3272 ASSERT_EQ(1U, form_structures.size()); 3272 ASSERT_EQ(1U, form_structures.size());
3273 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); 3273 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
3274 } 3274 }
3275 3275
3276 } // namespace autofill 3276 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698