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

Side by Side Diff: chrome/browser/search_engines/template_url_service_test_util.cc

Issue 16154031: Un-refcount AutofillWebData and TokenWebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on ToT Created 7 years, 6 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 "chrome/browser/search_engines/template_url_service_test_util.h" 5 #include "chrome/browser/search_engines/template_url_service_test_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "chrome/browser/google/google_url_tracker.h" 12 #include "chrome/browser/google/google_url_tracker.h"
13 #include "chrome/browser/search_engines/search_terms_data.h" 13 #include "chrome/browser/search_engines/search_terms_data.h"
14 #include "chrome/browser/search_engines/template_url_service.h" 14 #include "chrome/browser/search_engines/template_url_service.h"
15 #include "chrome/browser/search_engines/template_url_service_factory.h" 15 #include "chrome/browser/search_engines/template_url_service_factory.h"
16 #include "chrome/browser/webdata/web_data_service_factory.h" 16 #include "chrome/browser/webdata/web_data_service_factory.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/automation/value_conversion_util.h" 19 #include "chrome/test/automation/value_conversion_util.h"
20 #include "chrome/test/base/testing_pref_service_syncable.h" 20 #include "chrome/test/base/testing_pref_service_syncable.h"
21 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
22 #include "components/webdata/common/web_data_service_test_util.h"
23 #include "components/webdata/common/web_database_service.h"
22 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 28
27 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
28 #include "chrome/browser/google/google_util_chromeos.h" 30 #include "chrome/browser/google/google_util_chromeos.h"
29 #endif 31 #endif
30 32
31 using content::BrowserThread; 33 using content::BrowserThread;
(...skipping 15 matching lines...) Expand all
47 // pending requests on the thread. 49 // pending requests on the thread.
48 BrowserThread::PostTask( 50 BrowserThread::PostTask(
49 identifier, 51 identifier,
50 FROM_HERE, 52 FROM_HERE,
51 base::Bind(&QuitCallback, base::MessageLoop::current())); 53 base::Bind(&QuitCallback, base::MessageLoop::current()));
52 base::MessageLoop::current()->Run(); 54 base::MessageLoop::current()->Run();
53 } 55 }
54 56
55 } // namespace 57 } // namespace
56 58
59 class MockWebDataServiceWrapperDB : public MockWebDataServiceWrapper {
60 public:
61 static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
62 return new MockWebDataServiceWrapperDB(static_cast<Profile*>(profile));
63 }
64
65 explicit MockWebDataServiceWrapperDB(Profile* profile)
66 : MockWebDataServiceWrapper(NULL, NULL, NULL) {
67 base::FilePath profile_path = profile->GetPath();
68 base::FilePath path = profile_path.AppendASCII("TestWebDB");
69 web_database_ = new WebDatabaseService(path);
70 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable()));
71 fake_web_data_ = new WebDataService(
72 web_database_, WebDataServiceBase::ProfileErrorCallback());
73 fake_web_data_->Init();
74 }
75
76 virtual void Shutdown() OVERRIDE {
77 fake_web_data_->ShutdownDatabase();
78 }
79
80 private:
81 scoped_refptr<WebDatabaseService> web_database_;
82 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperDB);
83 };
84
57 // Trivial subclass of TemplateURLService that records the last invocation of 85 // Trivial subclass of TemplateURLService that records the last invocation of
58 // SetKeywordSearchTermsForURL. 86 // SetKeywordSearchTermsForURL.
59 class TestingTemplateURLService : public TemplateURLService { 87 class TestingTemplateURLService : public TemplateURLService {
60 public: 88 public:
61 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { 89 static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
62 return new TestingTemplateURLService(static_cast<Profile*>(profile)); 90 return new TestingTemplateURLService(static_cast<Profile*>(profile));
63 } 91 }
64 92
65 explicit TestingTemplateURLService(Profile* profile) 93 explicit TestingTemplateURLService(Profile* profile)
66 : TemplateURLService(profile) { 94 : TemplateURLService(profile) {
(...skipping 26 matching lines...) Expand all
93 } 121 }
94 122
95 TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() { 123 TemplateURLServiceTestUtil::~TemplateURLServiceTestUtil() {
96 } 124 }
97 125
98 void TemplateURLServiceTestUtil::SetUp() { 126 void TemplateURLServiceTestUtil::SetUp() {
99 // Make unique temp directory. 127 // Make unique temp directory.
100 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 128 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
101 profile_.reset(new TestingProfile(temp_dir_.path())); 129 profile_.reset(new TestingProfile(temp_dir_.path()));
102 db_thread_.Start(); 130 db_thread_.Start();
103 profile_->CreateWebDataService(); 131
132 WebDataServiceFactory::GetInstance()->SetTestingFactory(
133 profile_.get(), MockWebDataServiceWrapperDB::Build);
104 134
105 TemplateURLService* service = static_cast<TemplateURLService*>( 135 TemplateURLService* service = static_cast<TemplateURLService*>(
106 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 136 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
107 profile_.get(), TestingTemplateURLService::Build)); 137 profile_.get(), TestingTemplateURLService::Build));
108 service->AddObserver(this); 138 service->AddObserver(this);
109 139
110 #if defined(OS_CHROMEOS) 140 #if defined(OS_CHROMEOS)
111 google_util::chromeos::ClearBrandForCurrentSession(); 141 google_util::chromeos::ClearBrandForCurrentSession();
112 #endif 142 #endif
113 } 143 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return profile_.get(); 309 return profile_.get();
280 } 310 }
281 311
282 void TemplateURLServiceTestUtil::StartIOThread() { 312 void TemplateURLServiceTestUtil::StartIOThread() {
283 io_thread_.StartIOThread(); 313 io_thread_.StartIOThread();
284 } 314 }
285 315
286 void TemplateURLServiceTestUtil::PumpLoop() { 316 void TemplateURLServiceTestUtil::PumpLoop() {
287 message_loop_.RunUntilIdle(); 317 message_loop_.RunUntilIdle();
288 } 318 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover.cc ('k') | chrome/browser/signin/token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698