| 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/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 10 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 other.feature_map_size() == arg.feature_map_size()); | 67 other.feature_map_size() == arg.feature_map_size()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Test that the callback is NULL when the verdict is not phishing. | 70 // Test that the callback is NULL when the verdict is not phishing. |
| 71 MATCHER(CallbackIsNull, "") { | 71 MATCHER(CallbackIsNull, "") { |
| 72 return arg.is_null(); | 72 return arg.is_null(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 ACTION(QuitUIMessageLoop) { | 75 ACTION(QuitUIMessageLoop) { |
| 76 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 MessageLoopForUI::current()->Quit(); | 77 base::MessageLoopForUI::current()->Quit(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // It's kind of insane that InvokeArgument doesn't work with callbacks, but it | 80 // It's kind of insane that InvokeArgument doesn't work with callbacks, but it |
| 81 // doesn't seem like it. | 81 // doesn't seem like it. |
| 82 ACTION_TEMPLATE(InvokeCallbackArgument, | 82 ACTION_TEMPLATE(InvokeCallbackArgument, |
| 83 HAS_1_TEMPLATE_PARAMS(int, k), | 83 HAS_1_TEMPLATE_PARAMS(int, k), |
| 84 AND_2_VALUE_PARAMS(p0, p1)) { | 84 AND_2_VALUE_PARAMS(p0, p1)) { |
| 85 ::std::tr1::get<k>(args).Run(p0, p1); | 85 ::std::tr1::get<k>(args).Run(p0, p1); |
| 86 } | 86 } |
| 87 | 87 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const BrowserFeatureExtractor::DoneCallback&)); | 168 const BrowserFeatureExtractor::DoneCallback&)); |
| 169 | 169 |
| 170 MOCK_METHOD2(ExtractMalwareFeatures, | 170 MOCK_METHOD2(ExtractMalwareFeatures, |
| 171 void(const BrowseInfo* info, | 171 void(const BrowseInfo* info, |
| 172 ClientMalwareRequest*)); | 172 ClientMalwareRequest*)); |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 // Helper function which quits the UI message loop from the IO message loop. | 175 // Helper function which quits the UI message loop from the IO message loop. |
| 176 void QuitUIMessageLoopFromIO() { | 176 void QuitUIMessageLoopFromIO() { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 178 BrowserThread::PostTask(BrowserThread::UI, | 178 BrowserThread::PostTask( |
| 179 FROM_HERE, | 179 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); |
| 180 MessageLoop::QuitClosure()); | |
| 181 } | 180 } |
| 182 } // namespace | 181 } // namespace |
| 183 | 182 |
| 184 class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { | 183 class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { |
| 185 public: | 184 public: |
| 186 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 185 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
| 187 | 186 |
| 188 virtual void SetUp() { | 187 virtual void SetUp() { |
| 189 // Set custom profile object so that we can mock calls to IsOffTheRecord. | 188 // 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 | 189 // This needs to happen before we call the parent SetUp() function. We use |
| (...skipping 24 matching lines...) Expand all Loading... |
| 215 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( | 214 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( |
| 216 web_contents())); | 215 web_contents())); |
| 217 csd_host_->set_client_side_detection_service(csd_service_.get()); | 216 csd_host_->set_client_side_detection_service(csd_service_.get()); |
| 218 csd_host_->set_safe_browsing_managers(ui_manager_, database_manager_); | 217 csd_host_->set_safe_browsing_managers(ui_manager_, database_manager_); |
| 219 // We need to create this here since we don't call | 218 // We need to create this here since we don't call |
| 220 // DidNavigateMainFramePostCommit in this test. | 219 // DidNavigateMainFramePostCommit in this test. |
| 221 csd_host_->browse_info_.reset(new BrowseInfo); | 220 csd_host_->browse_info_.reset(new BrowseInfo); |
| 222 } | 221 } |
| 223 | 222 |
| 224 static void RunAllPendingOnIO(base::WaitableEvent* event) { | 223 static void RunAllPendingOnIO(base::WaitableEvent* event) { |
| 225 MessageLoop::current()->RunUntilIdle(); | 224 base::MessageLoop::current()->RunUntilIdle(); |
| 226 event->Signal(); | 225 event->Signal(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 virtual void TearDown() { | 228 virtual void TearDown() { |
| 230 // Delete the host object on the UI thread and release the | 229 // Delete the host object on the UI thread and release the |
| 231 // SafeBrowsingService. | 230 // SafeBrowsingService. |
| 232 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, | 231 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, |
| 233 csd_host_.release()); | 232 csd_host_.release()); |
| 234 database_manager_ = NULL; | 233 database_manager_ = NULL; |
| 235 ui_manager_ = NULL; | 234 ui_manager_ = NULL; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 259 return csd_host_->browse_info_.get(); | 258 return csd_host_->browse_info_.get(); |
| 260 } | 259 } |
| 261 | 260 |
| 262 void FlushIOMessageLoop() { | 261 void FlushIOMessageLoop() { |
| 263 // If there was a message posted on the IO thread to display the | 262 // 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 | 263 // interstitial page we know that it would have been posted before |
| 265 // we put the quit message there. | 264 // we put the quit message there. |
| 266 BrowserThread::PostTask(BrowserThread::IO, | 265 BrowserThread::PostTask(BrowserThread::IO, |
| 267 FROM_HERE, | 266 FROM_HERE, |
| 268 base::Bind(&QuitUIMessageLoopFromIO)); | 267 base::Bind(&QuitUIMessageLoopFromIO)); |
| 269 MessageLoop::current()->Run(); | 268 base::MessageLoop::current()->Run(); |
| 270 } | 269 } |
| 271 | 270 |
| 272 void ExpectPreClassificationChecks(const GURL& url, | 271 void ExpectPreClassificationChecks(const GURL& url, |
| 273 const bool* is_private, | 272 const bool* is_private, |
| 274 const bool* is_incognito, | 273 const bool* is_incognito, |
| 275 const bool* match_csd_whitelist, | 274 const bool* match_csd_whitelist, |
| 276 const bool* get_valid_cached_result, | 275 const bool* get_valid_cached_result, |
| 277 const bool* is_in_cache, | 276 const bool* is_in_cache, |
| 278 const bool* over_report_limit) { | 277 const bool* over_report_limit) { |
| 279 if (is_private) { | 278 if (is_private) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 299 if (over_report_limit) { | 298 if (over_report_limit) { |
| 300 EXPECT_CALL(*csd_service_, OverReportLimit()) | 299 EXPECT_CALL(*csd_service_, OverReportLimit()) |
| 301 .WillOnce(Return(*over_report_limit)); | 300 .WillOnce(Return(*over_report_limit)); |
| 302 } | 301 } |
| 303 } | 302 } |
| 304 | 303 |
| 305 void WaitAndCheckPreClassificationChecks() { | 304 void WaitAndCheckPreClassificationChecks() { |
| 306 // Wait for CheckCsdWhitelist to be called if at all. | 305 // Wait for CheckCsdWhitelist to be called if at all. |
| 307 FlushIOMessageLoop(); | 306 FlushIOMessageLoop(); |
| 308 // Checks for CheckCache() to be called if at all. | 307 // Checks for CheckCache() to be called if at all. |
| 309 MessageLoop::current()->RunUntilIdle(); | 308 base::MessageLoop::current()->RunUntilIdle(); |
| 310 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 309 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 311 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 310 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 312 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); | 311 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); |
| 313 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); | 312 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); |
| 314 } | 313 } |
| 315 | 314 |
| 316 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { | 315 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { |
| 317 csd_host_->feature_extractor_.reset(extractor); | 316 csd_host_->feature_extractor_.reset(extractor); |
| 318 } | 317 } |
| 319 | 318 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 SendClientReportPhishingRequest( | 395 SendClientReportPhishingRequest( |
| 397 Pointee(PartiallyEqualVerdict(verdict)), _)) | 396 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 398 .WillOnce(SaveArg<1>(&cb)); | 397 .WillOnce(SaveArg<1>(&cb)); |
| 399 OnPhishingDetectionDone(verdict.SerializeAsString()); | 398 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 400 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 399 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 401 ASSERT_FALSE(cb.is_null()); | 400 ASSERT_FALSE(cb.is_null()); |
| 402 | 401 |
| 403 // Make sure DoDisplayBlockingPage is not going to be called. | 402 // Make sure DoDisplayBlockingPage is not going to be called. |
| 404 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); | 403 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); |
| 405 cb.Run(GURL(verdict.url()), false); | 404 cb.Run(GURL(verdict.url()), false); |
| 406 MessageLoop::current()->RunUntilIdle(); | 405 base::MessageLoop::current()->RunUntilIdle(); |
| 407 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 406 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 408 } | 407 } |
| 409 | 408 |
| 410 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { | 409 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
| 411 // Case 2: client thinks the page is phishing and so does the server but | 410 // Case 2: client thinks the page is phishing and so does the server but |
| 412 // showing the interstitial is disabled => no interstitial is shown. | 411 // showing the interstitial is disabled => no interstitial is shown. |
| 413 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 412 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 414 web_contents(), | 413 web_contents(), |
| 415 csd_service_.get()); | 414 csd_service_.get()); |
| 416 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 415 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 428 SendClientReportPhishingRequest( | 427 SendClientReportPhishingRequest( |
| 429 Pointee(PartiallyEqualVerdict(verdict)), _)) | 428 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 430 .WillOnce(SaveArg<1>(&cb)); | 429 .WillOnce(SaveArg<1>(&cb)); |
| 431 OnPhishingDetectionDone(verdict.SerializeAsString()); | 430 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 432 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 431 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 433 ASSERT_FALSE(cb.is_null()); | 432 ASSERT_FALSE(cb.is_null()); |
| 434 | 433 |
| 435 // Make sure DoDisplayBlockingPage is not going to be called. | 434 // Make sure DoDisplayBlockingPage is not going to be called. |
| 436 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); | 435 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)).Times(0); |
| 437 cb.Run(GURL(verdict.url()), false); | 436 cb.Run(GURL(verdict.url()), false); |
| 438 MessageLoop::current()->RunUntilIdle(); | 437 base::MessageLoop::current()->RunUntilIdle(); |
| 439 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 438 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 440 } | 439 } |
| 441 | 440 |
| 442 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { | 441 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
| 443 // Case 3: client thinks the page is phishing and so does the server. | 442 // Case 3: client thinks the page is phishing and so does the server. |
| 444 // We show an interstitial. | 443 // We show an interstitial. |
| 445 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 444 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 446 web_contents(), | 445 web_contents(), |
| 447 csd_service_.get()); | 446 csd_service_.get()); |
| 448 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 447 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 463 .WillOnce(SaveArg<1>(&cb)); | 462 .WillOnce(SaveArg<1>(&cb)); |
| 464 OnPhishingDetectionDone(verdict.SerializeAsString()); | 463 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 465 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 464 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 466 ASSERT_FALSE(cb.is_null()); | 465 ASSERT_FALSE(cb.is_null()); |
| 467 | 466 |
| 468 UnsafeResource resource; | 467 UnsafeResource resource; |
| 469 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) | 468 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) |
| 470 .WillOnce(SaveArg<0>(&resource)); | 469 .WillOnce(SaveArg<0>(&resource)); |
| 471 cb.Run(phishing_url, true); | 470 cb.Run(phishing_url, true); |
| 472 | 471 |
| 473 MessageLoop::current()->RunUntilIdle(); | 472 base::MessageLoop::current()->RunUntilIdle(); |
| 474 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 473 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 475 EXPECT_EQ(phishing_url, resource.url); | 474 EXPECT_EQ(phishing_url, resource.url); |
| 476 EXPECT_EQ(phishing_url, resource.original_url); | 475 EXPECT_EQ(phishing_url, resource.original_url); |
| 477 EXPECT_FALSE(resource.is_subresource); | 476 EXPECT_FALSE(resource.is_subresource); |
| 478 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); | 477 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); |
| 479 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), | 478 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), |
| 480 resource.render_process_host_id); | 479 resource.render_process_host_id); |
| 481 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), | 480 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 482 resource.render_view_id); | 481 resource.render_view_id); |
| 483 | 482 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 EXPECT_CALL(*csd_service_, | 540 EXPECT_CALL(*csd_service_, |
| 542 SendClientReportPhishingRequest( | 541 SendClientReportPhishingRequest( |
| 543 Pointee(PartiallyEqualVerdict(verdict)), _)) | 542 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 544 .WillOnce(DoAll(DeleteArg<0>(), | 543 .WillOnce(DoAll(DeleteArg<0>(), |
| 545 SaveArg<1>(&cb_other), | 544 SaveArg<1>(&cb_other), |
| 546 QuitUIMessageLoop())); | 545 QuitUIMessageLoop())); |
| 547 std::vector<GURL> redirect_chain; | 546 std::vector<GURL> redirect_chain; |
| 548 redirect_chain.push_back(other_phishing_url); | 547 redirect_chain.push_back(other_phishing_url); |
| 549 SetRedirectChain(redirect_chain); | 548 SetRedirectChain(redirect_chain); |
| 550 OnPhishingDetectionDone(verdict.SerializeAsString()); | 549 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 551 MessageLoop::current()->Run(); | 550 base::MessageLoop::current()->Run(); |
| 552 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 551 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 553 ASSERT_FALSE(cb_other.is_null()); | 552 ASSERT_FALSE(cb_other.is_null()); |
| 554 | 553 |
| 555 // We expect that the interstitial is shown for the second phishing URL and | 554 // We expect that the interstitial is shown for the second phishing URL and |
| 556 // not for the first phishing URL. | 555 // not for the first phishing URL. |
| 557 UnsafeResource resource; | 556 UnsafeResource resource; |
| 558 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) | 557 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) |
| 559 .WillOnce(SaveArg<0>(&resource)); | 558 .WillOnce(SaveArg<0>(&resource)); |
| 560 | 559 |
| 561 cb.Run(phishing_url, true); // Should have no effect. | 560 cb.Run(phishing_url, true); // Should have no effect. |
| 562 cb_other.Run(other_phishing_url, true); // Should show interstitial. | 561 cb_other.Run(other_phishing_url, true); // Should show interstitial. |
| 563 | 562 |
| 564 MessageLoop::current()->RunUntilIdle(); | 563 base::MessageLoop::current()->RunUntilIdle(); |
| 565 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 564 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 566 EXPECT_EQ(other_phishing_url, resource.url); | 565 EXPECT_EQ(other_phishing_url, resource.url); |
| 567 EXPECT_EQ(other_phishing_url, resource.original_url); | 566 EXPECT_EQ(other_phishing_url, resource.original_url); |
| 568 EXPECT_FALSE(resource.is_subresource); | 567 EXPECT_FALSE(resource.is_subresource); |
| 569 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); | 568 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, resource.threat_type); |
| 570 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), | 569 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), |
| 571 resource.render_process_host_id); | 570 resource.render_process_host_id); |
| 572 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), | 571 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 573 resource.render_view_id); | 572 resource.render_view_id); |
| 574 | 573 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 SetUnsafeResourceToCurrent(); | 619 SetUnsafeResourceToCurrent(); |
| 621 | 620 |
| 622 EXPECT_CALL(*csd_service_, | 621 EXPECT_CALL(*csd_service_, |
| 623 SendClientReportPhishingRequest( | 622 SendClientReportPhishingRequest( |
| 624 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 623 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
| 625 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 624 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
| 626 std::vector<GURL> redirect_chain; | 625 std::vector<GURL> redirect_chain; |
| 627 redirect_chain.push_back(url); | 626 redirect_chain.push_back(url); |
| 628 SetRedirectChain(redirect_chain); | 627 SetRedirectChain(redirect_chain); |
| 629 OnPhishingDetectionDone(verdict.SerializeAsString()); | 628 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 630 MessageLoop::current()->Run(); | 629 base::MessageLoop::current()->Run(); |
| 631 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 630 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 632 } | 631 } |
| 633 | 632 |
| 634 TEST_F(ClientSideDetectionHostTest, UpdateIPHostMap) { | 633 TEST_F(ClientSideDetectionHostTest, UpdateIPHostMap) { |
| 635 BrowseInfo* browse_info = GetBrowseInfo(); | 634 BrowseInfo* browse_info = GetBrowseInfo(); |
| 636 | 635 |
| 637 // Empty IP or host are skipped | 636 // Empty IP or host are skipped |
| 638 UpdateIPHostMap("250.10.10.10", std::string()); | 637 UpdateIPHostMap("250.10.10.10", std::string()); |
| 639 ASSERT_EQ(0U, browse_info->ips.size()); | 638 ASSERT_EQ(0U, browse_info->ips.size()); |
| 640 UpdateIPHostMap(std::string(), "google.com/"); | 639 UpdateIPHostMap(std::string(), "google.com/"); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 NULL); | 946 NULL); |
| 948 | 947 |
| 949 UnsafeResource resource; | 948 UnsafeResource resource; |
| 950 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) | 949 EXPECT_CALL(*ui_manager_, DoDisplayBlockingPage(_)) |
| 951 .WillOnce(SaveArg<0>(&resource)); | 950 .WillOnce(SaveArg<0>(&resource)); |
| 952 | 951 |
| 953 NavigateAndCommit(url); | 952 NavigateAndCommit(url); |
| 954 // Wait for CheckCsdWhitelist to be called on the IO thread. | 953 // Wait for CheckCsdWhitelist to be called on the IO thread. |
| 955 FlushIOMessageLoop(); | 954 FlushIOMessageLoop(); |
| 956 // Wait for CheckCache() to be called on the UI thread. | 955 // Wait for CheckCache() to be called on the UI thread. |
| 957 MessageLoop::current()->RunUntilIdle(); | 956 base::MessageLoop::current()->RunUntilIdle(); |
| 958 // Now we check that all expected functions were indeed called on the two | 957 // Now we check that all expected functions were indeed called on the two |
| 959 // service objects. | 958 // service objects. |
| 960 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 959 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 961 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 960 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 962 EXPECT_EQ(url, resource.url); | 961 EXPECT_EQ(url, resource.url); |
| 963 EXPECT_EQ(url, resource.original_url); | 962 EXPECT_EQ(url, resource.original_url); |
| 964 resource.callback.Reset(); | 963 resource.callback.Reset(); |
| 965 msg = process()->sink().GetFirstMessageMatching( | 964 msg = process()->sink().GetFirstMessageMatching( |
| 966 SafeBrowsingMsg_StartPhishingDetection::ID); | 965 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 967 ASSERT_FALSE(msg); | 966 ASSERT_FALSE(msg); |
| 968 } | 967 } |
| 969 | 968 |
| 970 } // namespace safe_browsing | 969 } // namespace safe_browsing |
| OLD | NEW |