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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jyasskin's comments\ Created 7 years, 7 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/stringprintf.h" 9 #include "base/stringprintf.h"
9 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
10 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" 11 #include "chrome/browser/safe_browsing/browser_feature_extractor.h"
11 #include "chrome/browser/safe_browsing/client_side_detection_host.h" 12 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
12 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 13 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
13 #include "chrome/browser/safe_browsing/database_manager.h" 14 #include "chrome/browser/safe_browsing/database_manager.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/browser/safe_browsing/ui_manager.h" 16 #include "chrome/browser/safe_browsing/ui_manager.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/safe_browsing/csd.pb.h" 18 #include "chrome/common/safe_browsing/csd.pb.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 public: 186 public:
186 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; 187 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
187 188
188 virtual void SetUp() { 189 virtual void SetUp() {
189 // Set custom profile object so that we can mock calls to IsOffTheRecord. 190 // Set custom profile object so that we can mock calls to IsOffTheRecord.
190 // This needs to happen before we call the parent SetUp() function. We use 191 // This needs to happen before we call the parent SetUp() function. We use
191 // a nice mock because other parts of the code are calling IsOffTheRecord. 192 // a nice mock because other parts of the code are calling IsOffTheRecord.
192 mock_profile_ = new NiceMock<MockTestingProfile>(); 193 mock_profile_ = new NiceMock<MockTestingProfile>();
193 browser_context_.reset(mock_profile_); 194 browser_context_.reset(mock_profile_);
194 195
195 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI,
196 &message_loop_));
197 file_user_blocking_thread_.reset(
198 new content::TestBrowserThread(BrowserThread::FILE_USER_BLOCKING,
199 &message_loop_));
200 // Note: we're starting a real IO thread to make sure our DCHECKs that
201 // verify which thread is running are actually tested.
202 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
203 ASSERT_TRUE(io_thread_->Start());
204
205 ChromeRenderViewHostTestHarness::SetUp(); 196 ChromeRenderViewHostTestHarness::SetUp();
206 197
207 // Inject service classes. 198 // Inject service classes.
208 csd_service_.reset(new StrictMock<MockClientSideDetectionService>()); 199 csd_service_.reset(new StrictMock<MockClientSideDetectionService>());
209 // Only used for initializing mock objects. 200 // Only used for initializing mock objects.
210 SafeBrowsingService* sb_service = 201 SafeBrowsingService* sb_service =
211 SafeBrowsingService::CreateSafeBrowsingService(); 202 SafeBrowsingService::CreateSafeBrowsingService();
212 database_manager_ = 203 database_manager_ =
213 new StrictMock<MockSafeBrowsingDatabaseManager>(sb_service); 204 new StrictMock<MockSafeBrowsingDatabaseManager>(sb_service);
214 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>(sb_service); 205 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>(sb_service);
215 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( 206 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create(
216 web_contents())); 207 web_contents()));
217 csd_host_->set_client_side_detection_service(csd_service_.get()); 208 csd_host_->set_client_side_detection_service(csd_service_.get());
218 csd_host_->set_safe_browsing_managers(ui_manager_, database_manager_); 209 csd_host_->set_safe_browsing_managers(ui_manager_, database_manager_);
219 // We need to create this here since we don't call 210 // We need to create this here since we don't call
220 // DidNavigateMainFramePostCommit in this test. 211 // DidNavigateMainFramePostCommit in this test.
221 csd_host_->browse_info_.reset(new BrowseInfo); 212 csd_host_->browse_info_.reset(new BrowseInfo);
222 } 213 }
223 214
224 static void RunAllPendingOnIO(base::WaitableEvent* event) {
225 MessageLoop::current()->RunUntilIdle();
226 event->Signal();
227 }
228
229 virtual void TearDown() { 215 virtual void TearDown() {
230 // Delete the host object on the UI thread and release the 216 // Delete the host object on the UI thread and release the
231 // SafeBrowsingService. 217 // SafeBrowsingService.
232 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, 218 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE,
233 csd_host_.release()); 219 csd_host_.release());
234 database_manager_ = NULL; 220 database_manager_ = NULL;
235 ui_manager_ = NULL; 221 ui_manager_ = NULL;
236 message_loop_.RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
237 ChromeRenderViewHostTestHarness::TearDown(); 223 ChromeRenderViewHostTestHarness::TearDown();
238
239 // Let the tasks on the IO thread run to avoid memory leaks.
240 base::WaitableEvent done(false, false);
241 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
242 base::Bind(RunAllPendingOnIO, &done));
243 done.Wait();
244 io_thread_.reset();
245 message_loop_.RunUntilIdle();
246 file_user_blocking_thread_.reset();
247 ui_thread_.reset();
248 } 224 }
249 225
250 void OnPhishingDetectionDone(const std::string& verdict_str) { 226 void OnPhishingDetectionDone(const std::string& verdict_str) {
251 csd_host_->OnPhishingDetectionDone(verdict_str); 227 csd_host_->OnPhishingDetectionDone(verdict_str);
252 } 228 }
253 229
254 void UpdateIPHostMap(const std::string& ip, const std::string& host) { 230 void UpdateIPHostMap(const std::string& ip, const std::string& host) {
255 csd_host_->UpdateIPHostMap(ip, host); 231 csd_host_->UpdateIPHostMap(ip, host);
256 } 232 }
257 233
258 BrowseInfo* GetBrowseInfo() { 234 BrowseInfo* GetBrowseInfo() {
259 return csd_host_->browse_info_.get(); 235 return csd_host_->browse_info_.get();
260 } 236 }
261 237
262 void FlushIOMessageLoop() {
263 // If there was a message posted on the IO thread to display the
264 // interstitial page we know that it would have been posted before
265 // we put the quit message there.
266 BrowserThread::PostTask(BrowserThread::IO,
267 FROM_HERE,
268 base::Bind(&QuitUIMessageLoopFromIO));
269 MessageLoop::current()->Run();
270 }
271
272 void ExpectPreClassificationChecks(const GURL& url, 238 void ExpectPreClassificationChecks(const GURL& url,
273 const bool* is_private, 239 const bool* is_private,
274 const bool* is_incognito, 240 const bool* is_incognito,
275 const bool* match_csd_whitelist, 241 const bool* match_csd_whitelist,
276 const bool* get_valid_cached_result, 242 const bool* get_valid_cached_result,
277 const bool* is_in_cache, 243 const bool* is_in_cache,
278 const bool* over_report_limit) { 244 const bool* over_report_limit) {
279 if (is_private) { 245 if (is_private) {
280 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) 246 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_))
281 .WillOnce(Return(*is_private)); 247 .WillOnce(Return(*is_private));
(...skipping 14 matching lines...) Expand all
296 if (is_in_cache) { 262 if (is_in_cache) {
297 EXPECT_CALL(*csd_service_, IsInCache(url)).WillOnce(Return(*is_in_cache)); 263 EXPECT_CALL(*csd_service_, IsInCache(url)).WillOnce(Return(*is_in_cache));
298 } 264 }
299 if (over_report_limit) { 265 if (over_report_limit) {
300 EXPECT_CALL(*csd_service_, OverPhishingReportLimit()) 266 EXPECT_CALL(*csd_service_, OverPhishingReportLimit())
301 .WillOnce(Return(*over_report_limit)); 267 .WillOnce(Return(*over_report_limit));
302 } 268 }
303 } 269 }
304 270
305 void WaitAndCheckPreClassificationChecks() { 271 void WaitAndCheckPreClassificationChecks() {
306 // Wait for CheckCsdWhitelist to be called if at all. 272 // Wait for CheckCsdWhitelist and CheckCache() to be called if at all.
307 FlushIOMessageLoop(); 273 base::RunLoop().RunUntilIdle();
308 // Checks for CheckCache() to be called if at all.
309 MessageLoop::current()->RunUntilIdle();
310 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 274 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
311 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 275 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
312 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); 276 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get()));
313 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); 277 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_));
314 } 278 }
315 279
316 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { 280 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) {
317 csd_host_->feature_extractor_.reset(extractor); 281 csd_host_->feature_extractor_.reset(extractor);
318 } 282 }
319 283
(...skipping 28 matching lines...) Expand all
348 EXPECT_EQ(resource.render_view_id, 312 EXPECT_EQ(resource.render_view_id,
349 csd_host_->unsafe_resource_->render_view_id); 313 csd_host_->unsafe_resource_->render_view_id);
350 } 314 }
351 315
352 protected: 316 protected:
353 scoped_ptr<ClientSideDetectionHost> csd_host_; 317 scoped_ptr<ClientSideDetectionHost> csd_host_;
354 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; 318 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_;
355 scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_; 319 scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_;
356 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_; 320 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_;
357 MockTestingProfile* mock_profile_; // We don't own this object 321 MockTestingProfile* mock_profile_; // We don't own this object
358
359 private:
360 scoped_ptr<content::TestBrowserThread> ui_thread_;
361 scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_;
362 scoped_ptr<content::TestBrowserThread> io_thread_;
363 }; 322 };
364 323
365 324
366 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { 325 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) {
367 // Case 0: renderer sends an invalid verdict string that we're unable to 326 // Case 0: renderer sends an invalid verdict string that we're unable to
368 // parse. 327 // parse.
369 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 328 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
370 web_contents(), 329 web_contents(),
371 csd_service_.get()); 330 csd_service_.get());
372 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 331 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
(...skipping 23 matching lines...) Expand all
396 SendClientReportPhishingRequest( 355 SendClientReportPhishingRequest(
397 Pointee(PartiallyEqualVerdict(verdict)), _)) 356 Pointee(PartiallyEqualVerdict(verdict)), _))
398 .WillOnce(SaveArg<1>(&cb)); 357 .WillOnce(SaveArg<1>(&cb));
399 OnPhishingDetectionDone(verdict.SerializeAsString()); 358 OnPhishingDetectionDone(verdict.SerializeAsString());
400 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 359 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
401 ASSERT_FALSE(cb.is_null()); 360 ASSERT_FALSE(cb.is_null());
402 361
403 // Make sure DoDisplayBlockingPage is not going to be called. 362 // Make sure DoDisplayBlockingPage is not going to be called.
404 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); 363 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0);
405 cb.Run(GURL(verdict.url()), false); 364 cb.Run(GURL(verdict.url()), false);
406 MessageLoop::current()->RunUntilIdle(); 365 base::RunLoop().RunUntilIdle();
407 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 366 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
408 } 367 }
409 368
410 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { 369 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) {
411 // Case 2: client thinks the page is phishing and so does the server but 370 // Case 2: client thinks the page is phishing and so does the server but
412 // showing the interstitial is disabled => no interstitial is shown. 371 // showing the interstitial is disabled => no interstitial is shown.
413 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 372 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
414 web_contents(), 373 web_contents(),
415 csd_service_.get()); 374 csd_service_.get());
416 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 375 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
(...skipping 11 matching lines...) Expand all
428 SendClientReportPhishingRequest( 387 SendClientReportPhishingRequest(
429 Pointee(PartiallyEqualVerdict(verdict)), _)) 388 Pointee(PartiallyEqualVerdict(verdict)), _))
430 .WillOnce(SaveArg<1>(&cb)); 389 .WillOnce(SaveArg<1>(&cb));
431 OnPhishingDetectionDone(verdict.SerializeAsString()); 390 OnPhishingDetectionDone(verdict.SerializeAsString());
432 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 391 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
433 ASSERT_FALSE(cb.is_null()); 392 ASSERT_FALSE(cb.is_null());
434 393
435 // Make sure DoDisplayBlockingPage is not going to be called. 394 // Make sure DoDisplayBlockingPage is not going to be called.
436 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); 395 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0);
437 cb.Run(GURL(verdict.url()), false); 396 cb.Run(GURL(verdict.url()), false);
438 MessageLoop::current()->RunUntilIdle(); 397 base::RunLoop().RunUntilIdle();
439 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 398 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
440 } 399 }
441 400
442 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { 401 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) {
443 // Case 3: client thinks the page is phishing and so does the server. 402 // Case 3: client thinks the page is phishing and so does the server.
444 // We show an interstitial. 403 // We show an interstitial.
445 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 404 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
446 web_contents(), 405 web_contents(),
447 csd_service_.get()); 406 csd_service_.get());
448 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 407 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
(...skipping 14 matching lines...) Expand all
463 .WillOnce(SaveArg<1>(&cb)); 422 .WillOnce(SaveArg<1>(&cb));
464 OnPhishingDetectionDone(verdict.SerializeAsString()); 423 OnPhishingDetectionDone(verdict.SerializeAsString());
465 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 424 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
466 ASSERT_FALSE(cb.is_null()); 425 ASSERT_FALSE(cb.is_null());
467 426
468 UnsafeResource resource; 427 UnsafeResource resource;
469 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) 428 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_))
470 .WillOnce(SaveArg<0>(&resource)); 429 .WillOnce(SaveArg<0>(&resource));
471 cb.Run(phishing_url, true); 430 cb.Run(phishing_url, true);
472 431
473 MessageLoop::current()->RunUntilIdle(); 432 base::RunLoop().RunUntilIdle();
474 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 433 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
475 EXPECT_EQ(phishing_url, resource.url); 434 EXPECT_EQ(phishing_url, resource.url);
476 EXPECT_EQ(phishing_url, resource.original_url); 435 EXPECT_EQ(phishing_url, resource.original_url);
477 EXPECT_FALSE(resource.is_subresource); 436 EXPECT_FALSE(resource.is_subresource);
478 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); 437 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type);
479 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), 438 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(),
480 resource.render_process_host_id); 439 resource.render_process_host_id);
481 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), 440 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(),
482 resource.render_view_id); 441 resource.render_view_id);
483 442
484 // Make sure the client object will be deleted. 443 // Make sure the client object will be deleted.
485 BrowserThread::PostTask( 444 BrowserThread::PostTask(
486 BrowserThread::IO, 445 BrowserThread::IO,
487 FROM_HERE, 446 FROM_HERE,
488 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, 447 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete,
489 ui_manager_, resource.callback)); 448 ui_manager_, resource.callback));
490 // Since the CsdClient object will be deleted on the UI thread I need
491 // to run the UI message loop. Post a task to stop the UI message loop
492 // after the client object destructor is called.
493 FlushIOMessageLoop();
494 } 449 }
495 450
496 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { 451 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) {
497 // Case 4 & 5: client thinks a page is phishing then navigates to 452 // Case 4 & 5: client thinks a page is phishing then navigates to
498 // another page which is also considered phishing by the client 453 // another page which is also considered phishing by the client
499 // before the server responds with a verdict. After a while the 454 // before the server responds with a verdict. After a while the
500 // server responds for both requests with a phishing verdict. Only 455 // server responds for both requests with a phishing verdict. Only
501 // a single interstitial is shown for the second URL. 456 // a single interstitial is shown for the second URL.
502 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 457 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
503 web_contents(), 458 web_contents(),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 509
555 // We expect that the interstitial is shown for the second phishing URL and 510 // We expect that the interstitial is shown for the second phishing URL and
556 // not for the first phishing URL. 511 // not for the first phishing URL.
557 UnsafeResource resource; 512 UnsafeResource resource;
558 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) 513 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_))
559 .WillOnce(SaveArg<0>(&resource)); 514 .WillOnce(SaveArg<0>(&resource));
560 515
561 cb.Run(phishing_url, true); // Should have no effect. 516 cb.Run(phishing_url, true); // Should have no effect.
562 cb_other.Run(other_phishing_url, true); // Should show interstitial. 517 cb_other.Run(other_phishing_url, true); // Should show interstitial.
563 518
564 MessageLoop::current()->RunUntilIdle(); 519 base::RunLoop().RunUntilIdle();
565 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 520 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
566 EXPECT_EQ(other_phishing_url, resource.url); 521 EXPECT_EQ(other_phishing_url, resource.url);
567 EXPECT_EQ(other_phishing_url, resource.original_url); 522 EXPECT_EQ(other_phishing_url, resource.original_url);
568 EXPECT_FALSE(resource.is_subresource); 523 EXPECT_FALSE(resource.is_subresource);
569 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); 524 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type);
570 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), 525 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(),
571 resource.render_process_host_id); 526 resource.render_process_host_id);
572 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), 527 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(),
573 resource.render_view_id); 528 resource.render_view_id);
574 529
575 // Make sure the client object will be deleted. 530 // Make sure the client object will be deleted.
576 BrowserThread::PostTask( 531 BrowserThread::PostTask(
577 BrowserThread::IO, 532 BrowserThread::IO,
578 FROM_HERE, 533 FROM_HERE,
579 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, 534 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete,
580 ui_manager_, resource.callback)); 535 ui_manager_, resource.callback));
581 // Since the CsdClient object will be deleted on the UI thread I need
582 // to run the UI message loop. Post a task to stop the UI message loop
583 // after the client object destructor is called.
584 FlushIOMessageLoop();
585 } 536 }
586 537
587 TEST_F(ClientSideDetectionHostTest, 538 TEST_F(ClientSideDetectionHostTest,
588 OnPhishingDetectionDoneVerdictNotPhishing) { 539 OnPhishingDetectionDoneVerdictNotPhishing) {
589 // Case 6: renderer sends a verdict string that isn't phishing. 540 // Case 6: renderer sends a verdict string that isn't phishing.
590 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( 541 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
591 web_contents(), 542 web_contents(),
592 csd_service_.get()); 543 csd_service_.get());
593 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 544 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
594 545
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 // with no start classification message. 895 // with no start classification message.
945 url = GURL("http://host8.com/"); 896 url = GURL("http://host8.com/");
946 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL, 897 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL,
947 NULL); 898 NULL);
948 899
949 UnsafeResource resource; 900 UnsafeResource resource;
950 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) 901 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_))
951 .WillOnce(SaveArg<0>(&resource)); 902 .WillOnce(SaveArg<0>(&resource));
952 903
953 NavigateAndCommit(url); 904 NavigateAndCommit(url);
954 // Wait for CheckCsdWhitelist to be called on the IO thread. 905 // Wait for CheckCsdWhitelist and CheckCache() to be called.
955 FlushIOMessageLoop(); 906 base::RunLoop().RunUntilIdle();
956 // Wait for CheckCache() to be called on the UI thread.
957 MessageLoop::current()->RunUntilIdle();
958 // Now we check that all expected functions were indeed called on the two 907 // Now we check that all expected functions were indeed called on the two
959 // service objects. 908 // service objects.
960 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 909 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
961 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); 910 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get()));
962 EXPECT_EQ(url, resource.url); 911 EXPECT_EQ(url, resource.url);
963 EXPECT_EQ(url, resource.original_url); 912 EXPECT_EQ(url, resource.original_url);
964 resource.callback.Reset(); 913 resource.callback.Reset();
965 msg = process()->sink().GetFirstMessageMatching( 914 msg = process()->sink().GetFirstMessageMatching(
966 SafeBrowsingMsg_StartPhishingDetection::ID); 915 SafeBrowsingMsg_StartPhishingDetection::ID);
967 ASSERT_FALSE(msg); 916 ASSERT_FALSE(msg);
968 } 917 }
969 918
970 } // namespace safe_browsing 919 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698