| OLD | NEW |
| 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 Loading... |
| 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 // By default this is set to false. Turn it on as if we are in canary or | 214 // By default this is set to false. Turn it on as if we are in canary or |
| 224 // dev channel | 215 // dev channel |
| 225 csd_host_->malware_report_enabled_ = true; | 216 csd_host_->malware_report_enabled_ = true; |
| 226 } | 217 } |
| 227 | 218 |
| 228 static void RunAllPendingOnIO(base::WaitableEvent* event) { | |
| 229 base::MessageLoop::current()->RunUntilIdle(); | |
| 230 event->Signal(); | |
| 231 } | |
| 232 | |
| 233 virtual void TearDown() { | 219 virtual void TearDown() { |
| 234 // Delete the host object on the UI thread and release the | 220 // Delete the host object on the UI thread and release the |
| 235 // SafeBrowsingService. | 221 // SafeBrowsingService. |
| 236 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, | 222 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, |
| 237 csd_host_.release()); | 223 csd_host_.release()); |
| 238 database_manager_ = NULL; | 224 database_manager_ = NULL; |
| 239 ui_manager_ = NULL; | 225 ui_manager_ = NULL; |
| 240 message_loop_.RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
| 241 ChromeRenderViewHostTestHarness::TearDown(); | 227 ChromeRenderViewHostTestHarness::TearDown(); |
| 242 | |
| 243 // Let the tasks on the IO thread run to avoid memory leaks. | |
| 244 base::WaitableEvent done(false, false); | |
| 245 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 246 base::Bind(RunAllPendingOnIO, &done)); | |
| 247 done.Wait(); | |
| 248 io_thread_.reset(); | |
| 249 message_loop_.RunUntilIdle(); | |
| 250 file_user_blocking_thread_.reset(); | |
| 251 ui_thread_.reset(); | |
| 252 } | 228 } |
| 253 | 229 |
| 254 void OnPhishingDetectionDone(const std::string& verdict_str) { | 230 void OnPhishingDetectionDone(const std::string& verdict_str) { |
| 255 csd_host_->OnPhishingDetectionDone(verdict_str); | 231 csd_host_->OnPhishingDetectionDone(verdict_str); |
| 256 } | 232 } |
| 257 | 233 |
| 258 void UpdateIPHostMap(const std::string& ip, const std::string& host) { | 234 void UpdateIPHostMap(const std::string& ip, const std::string& host) { |
| 259 csd_host_->UpdateIPHostMap(ip, host); | 235 csd_host_->UpdateIPHostMap(ip, host); |
| 260 } | 236 } |
| 261 | 237 |
| 262 BrowseInfo* GetBrowseInfo() { | 238 BrowseInfo* GetBrowseInfo() { |
| 263 return csd_host_->browse_info_.get(); | 239 return csd_host_->browse_info_.get(); |
| 264 } | 240 } |
| 265 | 241 |
| 266 void FlushIOMessageLoop() { | |
| 267 // If there was a message posted on the IO thread to display the | |
| 268 // interstitial page we know that it would have been posted before | |
| 269 // we put the quit message there. | |
| 270 BrowserThread::PostTask(BrowserThread::IO, | |
| 271 FROM_HERE, | |
| 272 base::Bind(&QuitUIMessageLoopFromIO)); | |
| 273 base::MessageLoop::current()->Run(); | |
| 274 } | |
| 275 | |
| 276 void ExpectPreClassificationChecks(const GURL& url, | 242 void ExpectPreClassificationChecks(const GURL& url, |
| 277 const bool* is_private, | 243 const bool* is_private, |
| 278 const bool* is_incognito, | 244 const bool* is_incognito, |
| 279 const bool* match_csd_whitelist, | 245 const bool* match_csd_whitelist, |
| 280 const bool* get_valid_cached_result, | 246 const bool* get_valid_cached_result, |
| 281 const bool* is_in_cache, | 247 const bool* is_in_cache, |
| 282 const bool* over_report_limit) { | 248 const bool* over_report_limit) { |
| 283 if (is_private) { | 249 if (is_private) { |
| 284 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) | 250 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) |
| 285 .WillOnce(Return(*is_private)); | 251 .WillOnce(Return(*is_private)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 300 if (is_in_cache) { | 266 if (is_in_cache) { |
| 301 EXPECT_CALL(*csd_service_, IsInCache(url)).WillOnce(Return(*is_in_cache)); | 267 EXPECT_CALL(*csd_service_, IsInCache(url)).WillOnce(Return(*is_in_cache)); |
| 302 } | 268 } |
| 303 if (over_report_limit) { | 269 if (over_report_limit) { |
| 304 EXPECT_CALL(*csd_service_, OverPhishingReportLimit()) | 270 EXPECT_CALL(*csd_service_, OverPhishingReportLimit()) |
| 305 .WillOnce(Return(*over_report_limit)); | 271 .WillOnce(Return(*over_report_limit)); |
| 306 } | 272 } |
| 307 } | 273 } |
| 308 | 274 |
| 309 void WaitAndCheckPreClassificationChecks() { | 275 void WaitAndCheckPreClassificationChecks() { |
| 310 // Wait for CheckCsdWhitelist to be called if at all. | 276 // Wait for CheckCsdWhitelist and CheckCache() to be called if at all. |
| 311 FlushIOMessageLoop(); | 277 base::RunLoop().RunUntilIdle(); |
| 312 // Checks for CheckCache() to be called if at all. | |
| 313 base::MessageLoop::current()->RunUntilIdle(); | |
| 314 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 278 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 315 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 279 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 316 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); | 280 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); |
| 317 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); | 281 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); |
| 318 } | 282 } |
| 319 | 283 |
| 320 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { | 284 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { |
| 321 csd_host_->feature_extractor_.reset(extractor); | 285 csd_host_->feature_extractor_.reset(extractor); |
| 322 } | 286 } |
| 323 | 287 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 352 EXPECT_EQ(resource.render_view_id, | 316 EXPECT_EQ(resource.render_view_id, |
| 353 csd_host_->unsafe_resource_->render_view_id); | 317 csd_host_->unsafe_resource_->render_view_id); |
| 354 } | 318 } |
| 355 | 319 |
| 356 protected: | 320 protected: |
| 357 scoped_ptr<ClientSideDetectionHost> csd_host_; | 321 scoped_ptr<ClientSideDetectionHost> csd_host_; |
| 358 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; | 322 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; |
| 359 scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_; | 323 scoped_refptr<StrictMock<MockSafeBrowsingUIManager> > ui_manager_; |
| 360 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_; | 324 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > database_manager_; |
| 361 MockTestingProfile* mock_profile_; // We don't own this object | 325 MockTestingProfile* mock_profile_; // We don't own this object |
| 362 | |
| 363 private: | |
| 364 scoped_ptr<content::TestBrowserThread> ui_thread_; | |
| 365 scoped_ptr<content::TestBrowserThread> file_user_blocking_thread_; | |
| 366 scoped_ptr<content::TestBrowserThread> io_thread_; | |
| 367 }; | 326 }; |
| 368 | 327 |
| 369 | 328 |
| 370 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { | 329 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { |
| 371 // Case 0: renderer sends an invalid verdict string that we're unable to | 330 // Case 0: renderer sends an invalid verdict string that we're unable to |
| 372 // parse. | 331 // parse. |
| 373 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 332 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 374 web_contents(), | 333 web_contents(), |
| 375 csd_service_.get()); | 334 csd_service_.get()); |
| 376 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 335 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 400 SendClientReportPhishingRequest( | 359 SendClientReportPhishingRequest( |
| 401 Pointee(PartiallyEqualVerdict(verdict)), _)) | 360 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 402 .WillOnce(SaveArg<1>(&cb)); | 361 .WillOnce(SaveArg<1>(&cb)); |
| 403 OnPhishingDetectionDone(verdict.SerializeAsString()); | 362 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 404 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 363 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 405 ASSERT_FALSE(cb.is_null()); | 364 ASSERT_FALSE(cb.is_null()); |
| 406 | 365 |
| 407 // Make sure DoDisplayBlockingPage is not going to be called. | 366 // Make sure DoDisplayBlockingPage is not going to be called. |
| 408 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); | 367 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); |
| 409 cb.Run(GURL(verdict.url()), false); | 368 cb.Run(GURL(verdict.url()), false); |
| 410 base::MessageLoop::current()->RunUntilIdle(); | 369 base::RunLoop().RunUntilIdle(); |
| 411 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 370 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 412 } | 371 } |
| 413 | 372 |
| 414 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { | 373 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
| 415 // Case 2: client thinks the page is phishing and so does the server but | 374 // Case 2: client thinks the page is phishing and so does the server but |
| 416 // showing the interstitial is disabled => no interstitial is shown. | 375 // showing the interstitial is disabled => no interstitial is shown. |
| 417 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 376 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 418 web_contents(), | 377 web_contents(), |
| 419 csd_service_.get()); | 378 csd_service_.get()); |
| 420 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 379 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 432 SendClientReportPhishingRequest( | 391 SendClientReportPhishingRequest( |
| 433 Pointee(PartiallyEqualVerdict(verdict)), _)) | 392 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 434 .WillOnce(SaveArg<1>(&cb)); | 393 .WillOnce(SaveArg<1>(&cb)); |
| 435 OnPhishingDetectionDone(verdict.SerializeAsString()); | 394 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 436 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 395 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 437 ASSERT_FALSE(cb.is_null()); | 396 ASSERT_FALSE(cb.is_null()); |
| 438 | 397 |
| 439 // Make sure DoDisplayBlockingPage is not going to be called. | 398 // Make sure DoDisplayBlockingPage is not going to be called. |
| 440 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); | 399 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); |
| 441 cb.Run(GURL(verdict.url()), false); | 400 cb.Run(GURL(verdict.url()), false); |
| 442 base::MessageLoop::current()->RunUntilIdle(); | 401 base::RunLoop().RunUntilIdle(); |
| 443 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 402 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 444 } | 403 } |
| 445 | 404 |
| 446 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { | 405 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
| 447 // Case 3: client thinks the page is phishing and so does the server. | 406 // Case 3: client thinks the page is phishing and so does the server. |
| 448 // We show an interstitial. | 407 // We show an interstitial. |
| 449 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 408 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 450 web_contents(), | 409 web_contents(), |
| 451 csd_service_.get()); | 410 csd_service_.get()); |
| 452 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 411 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 467 .WillOnce(SaveArg<1>(&cb)); | 426 .WillOnce(SaveArg<1>(&cb)); |
| 468 OnPhishingDetectionDone(verdict.SerializeAsString()); | 427 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 469 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 428 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 470 ASSERT_FALSE(cb.is_null()); | 429 ASSERT_FALSE(cb.is_null()); |
| 471 | 430 |
| 472 UnsafeResource resource; | 431 UnsafeResource resource; |
| 473 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) | 432 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) |
| 474 .WillOnce(SaveArg<0>(&resource)); | 433 .WillOnce(SaveArg<0>(&resource)); |
| 475 cb.Run(phishing_url, true); | 434 cb.Run(phishing_url, true); |
| 476 | 435 |
| 477 base::MessageLoop::current()->RunUntilIdle(); | 436 base::RunLoop().RunUntilIdle(); |
| 478 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 437 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 479 EXPECT_EQ(phishing_url, resource.url); | 438 EXPECT_EQ(phishing_url, resource.url); |
| 480 EXPECT_EQ(phishing_url, resource.original_url); | 439 EXPECT_EQ(phishing_url, resource.original_url); |
| 481 EXPECT_FALSE(resource.is_subresource); | 440 EXPECT_FALSE(resource.is_subresource); |
| 482 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); | 441 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); |
| 483 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), | 442 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), |
| 484 resource.render_process_host_id); | 443 resource.render_process_host_id); |
| 485 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), | 444 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 486 resource.render_view_id); | 445 resource.render_view_id); |
| 487 | 446 |
| 488 // Make sure the client object will be deleted. | 447 // Make sure the client object will be deleted. |
| 489 BrowserThread::PostTask( | 448 BrowserThread::PostTask( |
| 490 BrowserThread::IO, | 449 BrowserThread::IO, |
| 491 FROM_HERE, | 450 FROM_HERE, |
| 492 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | 451 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, |
| 493 ui_manager_, resource.callback)); | 452 ui_manager_, resource.callback)); |
| 494 // Since the CsdClient object will be deleted on the UI thread I need | |
| 495 // to run the UI message loop. Post a task to stop the UI message loop | |
| 496 // after the client object destructor is called. | |
| 497 FlushIOMessageLoop(); | |
| 498 } | 453 } |
| 499 | 454 |
| 500 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { | 455 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { |
| 501 // Case 4 & 5: client thinks a page is phishing then navigates to | 456 // Case 4 & 5: client thinks a page is phishing then navigates to |
| 502 // another page which is also considered phishing by the client | 457 // another page which is also considered phishing by the client |
| 503 // before the server responds with a verdict. After a while the | 458 // before the server responds with a verdict. After a while the |
| 504 // server responds for both requests with a phishing verdict. Only | 459 // server responds for both requests with a phishing verdict. Only |
| 505 // a single interstitial is shown for the second URL. | 460 // a single interstitial is shown for the second URL. |
| 506 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 461 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 507 web_contents(), | 462 web_contents(), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 513 |
| 559 // We expect that the interstitial is shown for the second phishing URL and | 514 // We expect that the interstitial is shown for the second phishing URL and |
| 560 // not for the first phishing URL. | 515 // not for the first phishing URL. |
| 561 UnsafeResource resource; | 516 UnsafeResource resource; |
| 562 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) | 517 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) |
| 563 .WillOnce(SaveArg<0>(&resource)); | 518 .WillOnce(SaveArg<0>(&resource)); |
| 564 | 519 |
| 565 cb.Run(phishing_url, true); // Should have no effect. | 520 cb.Run(phishing_url, true); // Should have no effect. |
| 566 cb_other.Run(other_phishing_url, true); // Should show interstitial. | 521 cb_other.Run(other_phishing_url, true); // Should show interstitial. |
| 567 | 522 |
| 568 base::MessageLoop::current()->RunUntilIdle(); | 523 base::RunLoop().RunUntilIdle(); |
| 569 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 524 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 570 EXPECT_EQ(other_phishing_url, resource.url); | 525 EXPECT_EQ(other_phishing_url, resource.url); |
| 571 EXPECT_EQ(other_phishing_url, resource.original_url); | 526 EXPECT_EQ(other_phishing_url, resource.original_url); |
| 572 EXPECT_FALSE(resource.is_subresource); | 527 EXPECT_FALSE(resource.is_subresource); |
| 573 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); | 528 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); |
| 574 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), | 529 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), |
| 575 resource.render_process_host_id); | 530 resource.render_process_host_id); |
| 576 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), | 531 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 577 resource.render_view_id); | 532 resource.render_view_id); |
| 578 | 533 |
| 579 // Make sure the client object will be deleted. | 534 // Make sure the client object will be deleted. |
| 580 BrowserThread::PostTask( | 535 BrowserThread::PostTask( |
| 581 BrowserThread::IO, | 536 BrowserThread::IO, |
| 582 FROM_HERE, | 537 FROM_HERE, |
| 583 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | 538 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, |
| 584 ui_manager_, resource.callback)); | 539 ui_manager_, resource.callback)); |
| 585 // Since the CsdClient object will be deleted on the UI thread I need | |
| 586 // to run the UI message loop. Post a task to stop the UI message loop | |
| 587 // after the client object destructor is called. | |
| 588 FlushIOMessageLoop(); | |
| 589 } | 540 } |
| 590 | 541 |
| 591 TEST_F(ClientSideDetectionHostTest, | 542 TEST_F(ClientSideDetectionHostTest, |
| 592 OnPhishingDetectionDoneVerdictNotPhishing) { | 543 OnPhishingDetectionDoneVerdictNotPhishing) { |
| 593 // Case 6: renderer sends a verdict string that isn't phishing. | 544 // Case 6: renderer sends a verdict string that isn't phishing. |
| 594 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 545 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 595 web_contents(), | 546 web_contents(), |
| 596 csd_service_.get()); | 547 csd_service_.get()); |
| 597 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 548 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 598 | 549 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 // with no start classification message. | 899 // with no start classification message. |
| 949 url = GURL("http://host8.com/"); | 900 url = GURL("http://host8.com/"); |
| 950 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL, | 901 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL, |
| 951 NULL); | 902 NULL); |
| 952 | 903 |
| 953 UnsafeResource resource; | 904 UnsafeResource resource; |
| 954 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) | 905 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) |
| 955 .WillOnce(SaveArg<0>(&resource)); | 906 .WillOnce(SaveArg<0>(&resource)); |
| 956 | 907 |
| 957 NavigateAndCommit(url); | 908 NavigateAndCommit(url); |
| 958 // Wait for CheckCsdWhitelist to be called on the IO thread. | 909 // Wait for CheckCsdWhitelist and CheckCache() to be called. |
| 959 FlushIOMessageLoop(); | 910 base::RunLoop().RunUntilIdle(); |
| 960 // Wait for CheckCache() to be called on the UI thread. | |
| 961 base::MessageLoop::current()->RunUntilIdle(); | |
| 962 // Now we check that all expected functions were indeed called on the two | 911 // Now we check that all expected functions were indeed called on the two |
| 963 // service objects. | 912 // service objects. |
| 964 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 913 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 965 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 914 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 966 EXPECT_EQ(url, resource.url); | 915 EXPECT_EQ(url, resource.url); |
| 967 EXPECT_EQ(url, resource.original_url); | 916 EXPECT_EQ(url, resource.original_url); |
| 968 resource.callback.Reset(); | 917 resource.callback.Reset(); |
| 969 msg = process()->sink().GetFirstMessageMatching( | 918 msg = process()->sink().GetFirstMessageMatching( |
| 970 SafeBrowsingMsg_StartPhishingDetection::ID); | 919 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 971 ASSERT_FALSE(msg); | 920 ASSERT_FALSE(msg); |
| 972 } | 921 } |
| 973 | 922 |
| 974 } // namespace safe_browsing | 923 } // namespace safe_browsing |
| OLD | NEW |