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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_host_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 (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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ClientMalwareRequest*)); 173 ClientMalwareRequest*));
174 }; 174 };
175 175
176 } // namespace 176 } // namespace
177 177
178 class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { 178 class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness {
179 public: 179 public:
180 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; 180 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
181 181
182 virtual void SetUp() { 182 virtual void SetUp() {
183 // Set custom profile object so that we can mock calls to IsOffTheRecord.
184 // This needs to happen before we call the parent SetUp() function. We use
185 // a nice mock because other parts of the code are calling IsOffTheRecord.
186 mock_profile_ = new NiceMock<MockTestingProfile>();
187 browser_context_.reset(mock_profile_);
188
189 ChromeRenderViewHostTestHarness::SetUp(); 183 ChromeRenderViewHostTestHarness::SetUp();
190 184
191 // Inject service classes. 185 // Inject service classes.
192 csd_service_.reset(new StrictMock<MockClientSideDetectionService>()); 186 csd_service_.reset(new StrictMock<MockClientSideDetectionService>());
193 // Only used for initializing mock objects. 187 // Only used for initializing mock objects.
194 SafeBrowsingService* sb_service = 188 SafeBrowsingService* sb_service =
195 SafeBrowsingService::CreateSafeBrowsingService(); 189 SafeBrowsingService::CreateSafeBrowsingService();
196 database_manager_ = 190 database_manager_ =
197 new StrictMock<MockSafeBrowsingDatabaseManager>(sb_service); 191 new StrictMock<MockSafeBrowsingDatabaseManager>(sb_service);
198 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>(sb_service); 192 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>(sb_service);
(...skipping 15 matching lines...) Expand all
214 // Delete the host object on the UI thread and release the 208 // Delete the host object on the UI thread and release the
215 // SafeBrowsingService. 209 // SafeBrowsingService.
216 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, 210 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE,
217 csd_host_.release()); 211 csd_host_.release());
218 database_manager_ = NULL; 212 database_manager_ = NULL;
219 ui_manager_ = NULL; 213 ui_manager_ = NULL;
220 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
221 ChromeRenderViewHostTestHarness::TearDown(); 215 ChromeRenderViewHostTestHarness::TearDown();
222 } 216 }
223 217
218 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE {
219 // Set custom profile object so that we can mock calls to IsOffTheRecord.
220 // This needs to happen before we call the parent SetUp() function. We use
221 // a nice mock because other parts of the code are calling IsOffTheRecord.
222 mock_profile_ = new NiceMock<MockTestingProfile>();
223 return mock_profile_;
224 }
225
224 void OnPhishingDetectionDone(const std::string& verdict_str) { 226 void OnPhishingDetectionDone(const std::string& verdict_str) {
225 csd_host_->OnPhishingDetectionDone(verdict_str); 227 csd_host_->OnPhishingDetectionDone(verdict_str);
226 } 228 }
227 229
228 void UpdateIPHostMap(const std::string& ip, const std::string& host) { 230 void UpdateIPHostMap(const std::string& ip, const std::string& host) {
229 csd_host_->UpdateIPHostMap(ip, host); 231 csd_host_->UpdateIPHostMap(ip, host);
230 } 232 }
231 233
232 BrowseInfo* GetBrowseInfo() { 234 BrowseInfo* GetBrowseInfo() {
233 return csd_host_->browse_info_.get(); 235 return csd_host_->browse_info_.get();
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 910 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
909 EXPECT_EQ(url, resource.url); 911 EXPECT_EQ(url, resource.url);
910 EXPECT_EQ(url, resource.original_url); 912 EXPECT_EQ(url, resource.original_url);
911 resource.callback.Reset(); 913 resource.callback.Reset();
912 msg = process()->sink().GetFirstMessageMatching( 914 msg = process()->sink().GetFirstMessageMatching(
913 SafeBrowsingMsg_StartPhishingDetection::ID); 915 SafeBrowsingMsg_StartPhishingDetection::ID);
914 ASSERT_FALSE(msg); 916 ASSERT_FALSE(msg);
915 } 917 }
916 918
917 } // namespace safe_browsing 919 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698