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

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_host_unittest.cc

Issue 9419033: Move creation of BrowserContext objects that live in content to content, instead of depending on th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 "base/file_path.h" 5 #include "base/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 "chrome/browser/safe_browsing/browser_feature_extractor.h" 8 #include "chrome/browser/safe_browsing/browser_feature_extractor.h"
9 #include "chrome/browser/safe_browsing/client_side_detection_host.h" 9 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
10 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 10 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 public: 152 public:
153 virtual void SetUp() { 153 virtual void SetUp() {
154 // Set custom profile object so that we can mock calls to IsOffTheRecord. 154 // Set custom profile object so that we can mock calls to IsOffTheRecord.
155 // This needs to happen before we call the parent SetUp() function. We use 155 // This needs to happen before we call the parent SetUp() function. We use
156 // a nice mock because other parts of the code are calling IsOffTheRecord. 156 // a nice mock because other parts of the code are calling IsOffTheRecord.
157 mock_profile_ = new NiceMock<MockTestingProfile>(); 157 mock_profile_ = new NiceMock<MockTestingProfile>();
158 browser_context_.reset(mock_profile_); 158 browser_context_.reset(mock_profile_);
159 159
160 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, 160 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI,
161 &message_loop_)); 161 &message_loop_));
162 file_user_blocking_thread_.reset(
163 new content::TestBrowserThread(BrowserThread::FILE_USER_BLOCKING,
164 &message_loop_));
162 // Note: we're starting a real IO thread to make sure our DCHECKs that 165 // Note: we're starting a real IO thread to make sure our DCHECKs that
163 // verify which thread is running are actually tested. 166 // verify which thread is running are actually tested.
164 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); 167 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
165 ASSERT_TRUE(io_thread_->Start()); 168 ASSERT_TRUE(io_thread_->Start());
166 169
167 TabContentsWrapperTestHarness::SetUp(); 170 TabContentsWrapperTestHarness::SetUp();
168 171
169 // Inject service classes. 172 // Inject service classes.
170 csd_service_.reset(new StrictMock<MockClientSideDetectionService>()); 173 csd_service_.reset(new StrictMock<MockClientSideDetectionService>());
171 sb_service_ = new StrictMock<MockSafeBrowsingService>(); 174 sb_service_ = new StrictMock<MockSafeBrowsingService>();
172 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( 175 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create(
173 contents_wrapper()->web_contents())); 176 contents_wrapper()->web_contents()));
174 csd_host_->set_client_side_detection_service(csd_service_.get()); 177 csd_host_->set_client_side_detection_service(csd_service_.get());
175 csd_host_->set_safe_browsing_service(sb_service_.get()); 178 csd_host_->set_safe_browsing_service(sb_service_.get());
176 // We need to create this here since we don't call 179 // We need to create this here since we don't call
177 // DidNavigateMainFramePostCommit in this test. 180 // DidNavigateMainFramePostCommit in this test.
178 csd_host_->browse_info_.reset(new BrowseInfo); 181 csd_host_->browse_info_.reset(new BrowseInfo);
179 } 182 }
180 183
181 virtual void TearDown() { 184 virtual void TearDown() {
182 // Delete the host object on the UI thread and release the 185 // Delete the host object on the UI thread and release the
183 // SafeBrowsingService. 186 // SafeBrowsingService.
184 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, 187 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE,
185 csd_host_.release()); 188 csd_host_.release());
186 sb_service_ = NULL; 189 sb_service_ = NULL;
187 message_loop_.RunAllPending(); 190 message_loop_.RunAllPending();
188 TabContentsWrapperTestHarness::TearDown(); 191 TabContentsWrapperTestHarness::TearDown();
189 io_thread_.reset(); 192 io_thread_.reset();
193 file_user_blocking_thread_.reset();
190 ui_thread_.reset(); 194 ui_thread_.reset();
191 } 195 }
192 196
193 void OnPhishingDetectionDone(const std::string& verdict_str) { 197 void OnPhishingDetectionDone(const std::string& verdict_str) {
194 csd_host_->OnPhishingDetectionDone(verdict_str); 198 csd_host_->OnPhishingDetectionDone(verdict_str);
195 } 199 }
196 200
197 void FlushIOMessageLoop() { 201 void FlushIOMessageLoop() {
198 // If there was a message posted on the IO thread to display the 202 // If there was a message posted on the IO thread to display the
199 // interstitial page we know that it would have been posted before 203 // interstitial page we know that it would have been posted before
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 287 }
284 288
285 protected: 289 protected:
286 scoped_ptr<ClientSideDetectionHost> csd_host_; 290 scoped_ptr<ClientSideDetectionHost> csd_host_;
287 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; 291 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_;
288 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; 292 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_;
289 MockTestingProfile* mock_profile_; // We don't own this object 293 MockTestingProfile* mock_profile_; // We don't own this object
290 294
291 private: 295 private:
292 scoped_ptr<content::TestBrowserThread> ui_thread_; 296 scoped_ptr<content::TestBrowserThread> ui_thread_;
297 scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_;
293 scoped_ptr<content::TestBrowserThread> io_thread_; 298 scoped_ptr<content::TestBrowserThread> io_thread_;
294 }; 299 };
295 300
296 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { 301 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) {
297 // Case 0: renderer sends an invalid verdict string that we're unable to 302 // Case 0: renderer sends an invalid verdict string that we're unable to
298 // parse. 303 // parse.
299 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 304 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
300 contents(), 305 contents(),
301 csd_service_.get()); 306 csd_service_.get());
302 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 307 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); 735 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get()));
731 EXPECT_EQ(url, resource.url); 736 EXPECT_EQ(url, resource.url);
732 EXPECT_EQ(url, resource.original_url); 737 EXPECT_EQ(url, resource.original_url);
733 resource.callback.Reset(); 738 resource.callback.Reset();
734 msg = process()->sink().GetFirstMessageMatching( 739 msg = process()->sink().GetFirstMessageMatching(
735 SafeBrowsingMsg_StartPhishingDetection::ID); 740 SafeBrowsingMsg_StartPhishingDetection::ID);
736 ASSERT_FALSE(msg); 741 ASSERT_FALSE(msg);
737 } 742 }
738 743
739 } // namespace safe_browsing 744 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698