| 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/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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 // It's kind of insane that InvokeArgument doesn't work with callbacks, but it | 81 // It's kind of insane that InvokeArgument doesn't work with callbacks, but it |
| 82 // doesn't seem like it. | 82 // doesn't seem like it. |
| 83 ACTION_TEMPLATE(InvokeCallbackArgument, | 83 ACTION_TEMPLATE(InvokeCallbackArgument, |
| 84 HAS_1_TEMPLATE_PARAMS(int, k), | 84 HAS_1_TEMPLATE_PARAMS(int, k), |
| 85 AND_2_VALUE_PARAMS(p0, p1)) { | 85 AND_2_VALUE_PARAMS(p0, p1)) { |
| 86 ::std::tr1::get<k>(args).Run(p0, p1); | 86 ::std::tr1::get<k>(args).Run(p0, p1); |
| 87 } | 87 } |
| 88 | 88 |
| 89 ACTION_P(InvokeMalwareCallback, verdict) { |
| 90 scoped_ptr<ClientMalwareRequest> request(::std::tr1::get<1>(args)); |
| 91 request->CopyFrom(*verdict); |
| 92 ::std::tr1::get<2>(args).Run(true, request.Pass()); |
| 93 } |
| 94 |
| 89 void EmptyUrlCheckCallback(bool processed) { | 95 void EmptyUrlCheckCallback(bool processed) { |
| 90 } | 96 } |
| 91 | 97 |
| 92 class MockClientSideDetectionService : public ClientSideDetectionService { | 98 class MockClientSideDetectionService : public ClientSideDetectionService { |
| 93 public: | 99 public: |
| 94 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} | 100 MockClientSideDetectionService() : ClientSideDetectionService(NULL) {} |
| 95 virtual ~MockClientSideDetectionService() {}; | 101 virtual ~MockClientSideDetectionService() {}; |
| 96 | 102 |
| 97 MOCK_METHOD2(SendClientReportPhishingRequest, | 103 MOCK_METHOD2(SendClientReportPhishingRequest, |
| 98 void(ClientPhishingRequest*, | 104 void(ClientPhishingRequest*, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 private: | 138 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); | 139 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); |
| 134 }; | 140 }; |
| 135 | 141 |
| 136 class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { | 142 class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { |
| 137 public: | 143 public: |
| 138 explicit MockSafeBrowsingDatabaseManager(SafeBrowsingService* service) | 144 explicit MockSafeBrowsingDatabaseManager(SafeBrowsingService* service) |
| 139 : SafeBrowsingDatabaseManager(service) { } | 145 : SafeBrowsingDatabaseManager(service) { } |
| 140 | 146 |
| 141 MOCK_METHOD1(MatchCsdWhitelistUrl, bool(const GURL&)); | 147 MOCK_METHOD1(MatchCsdWhitelistUrl, bool(const GURL&)); |
| 148 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); |
| 142 | 149 |
| 143 protected: | 150 protected: |
| 144 virtual ~MockSafeBrowsingDatabaseManager() {} | 151 virtual ~MockSafeBrowsingDatabaseManager() {} |
| 145 | 152 |
| 146 private: | 153 private: |
| 147 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); | 154 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); |
| 148 }; | 155 }; |
| 149 | 156 |
| 150 class MockTestingProfile : public TestingProfile { | 157 class MockTestingProfile : public TestingProfile { |
| 151 public: | 158 public: |
| 152 MockTestingProfile() {} | 159 MockTestingProfile() {} |
| 153 virtual ~MockTestingProfile() {} | 160 virtual ~MockTestingProfile() {} |
| 154 | 161 |
| 155 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 162 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 156 }; | 163 }; |
| 157 | 164 |
| 158 class MockBrowserFeatureExtractor : public BrowserFeatureExtractor { | 165 class MockBrowserFeatureExtractor : public BrowserFeatureExtractor { |
| 159 public: | 166 public: |
| 160 explicit MockBrowserFeatureExtractor( | 167 explicit MockBrowserFeatureExtractor( |
| 161 WebContents* tab, | 168 WebContents* tab, |
| 162 ClientSideDetectionService* service) | 169 ClientSideDetectionHost* host) |
| 163 : BrowserFeatureExtractor(tab, service) {} | 170 : BrowserFeatureExtractor(tab, host) {} |
| 164 virtual ~MockBrowserFeatureExtractor() {} | 171 virtual ~MockBrowserFeatureExtractor() {} |
| 165 | 172 |
| 166 MOCK_METHOD3(ExtractFeatures, | 173 MOCK_METHOD3(ExtractFeatures, |
| 167 void(const BrowseInfo* info, | 174 void(const BrowseInfo*, |
| 168 ClientPhishingRequest*, | 175 ClientPhishingRequest*, |
| 169 const BrowserFeatureExtractor::DoneCallback&)); | 176 const BrowserFeatureExtractor::DoneCallback&)); |
| 170 | 177 |
| 171 MOCK_METHOD2(ExtractMalwareFeatures, | 178 MOCK_METHOD3(ExtractMalwareFeatures, |
| 172 void(const BrowseInfo* info, | 179 void(BrowseInfo*, |
| 173 ClientMalwareRequest*)); | 180 ClientMalwareRequest*, |
| 181 const BrowserFeatureExtractor::MalwareDoneCallback&)); |
| 174 }; | 182 }; |
| 175 | 183 |
| 176 } // namespace | 184 } // namespace |
| 177 | 185 |
| 178 class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { | 186 class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { |
| 179 public: | 187 public: |
| 180 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 188 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
| 181 | 189 |
| 182 virtual void SetUp() { | 190 virtual void SetUp() { |
| 183 ChromeRenderViewHostTestHarness::SetUp(); | 191 ChromeRenderViewHostTestHarness::SetUp(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // Crashes on Blink canary bots: http://crbug.com/299149 | 333 // Crashes on Blink canary bots: http://crbug.com/299149 |
| 326 TEST_F(ClientSideDetectionHostTest, | 334 TEST_F(ClientSideDetectionHostTest, |
| 327 DISABLED_OnPhishingDetectionDoneInvalidVerdict) { | 335 DISABLED_OnPhishingDetectionDoneInvalidVerdict) { |
| 328 #else | 336 #else |
| 329 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { | 337 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) { |
| 330 #endif | 338 #endif |
| 331 // Case 0: renderer sends an invalid verdict string that we're unable to | 339 // Case 0: renderer sends an invalid verdict string that we're unable to |
| 332 // parse. | 340 // parse. |
| 333 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 341 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 334 web_contents(), | 342 web_contents(), |
| 335 csd_service_.get()); | 343 csd_host_.get()); |
| 336 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 344 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 337 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 345 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| 338 OnPhishingDetectionDone("Invalid Protocol Buffer"); | 346 OnPhishingDetectionDone("Invalid Protocol Buffer"); |
| 339 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 347 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| 340 } | 348 } |
| 341 | 349 |
| 342 #if defined(OS_WIN) | 350 #if defined(OS_WIN) |
| 343 // Fails on Blink canary bots: http://crbug.com/299149 | 351 // Fails on Blink canary bots: http://crbug.com/299149 |
| 344 TEST_F(ClientSideDetectionHostTest, | 352 TEST_F(ClientSideDetectionHostTest, |
| 345 DISABLED_OnPhishingDetectionDoneNotPhishing) { | 353 DISABLED_OnPhishingDetectionDoneNotPhishing) { |
| 346 #else | 354 #else |
| 347 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { | 355 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { |
| 348 #endif | 356 #endif |
| 349 // Case 1: client thinks the page is phishing. The server does not agree. | 357 // Case 1: client thinks the page is phishing. The server does not agree. |
| 350 // No interstitial is shown. | 358 // No interstitial is shown. |
| 351 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 359 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 352 web_contents(), | 360 web_contents(), |
| 353 csd_service_.get()); | 361 csd_host_.get()); |
| 354 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 362 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 355 | 363 |
| 356 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 364 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
| 357 ClientPhishingRequest verdict; | 365 ClientPhishingRequest verdict; |
| 358 verdict.set_url("http://phishingurl.com/"); | 366 verdict.set_url("http://phishingurl.com/"); |
| 359 verdict.set_client_score(1.0f); | 367 verdict.set_client_score(1.0f); |
| 360 verdict.set_is_phishing(true); | 368 verdict.set_is_phishing(true); |
| 361 | 369 |
| 362 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 370 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| 363 .WillOnce(DoAll(DeleteArg<1>(), | 371 .WillOnce(DoAll(DeleteArg<1>(), |
| 364 InvokeCallbackArgument<2>(true, &verdict))); | 372 InvokeCallbackArgument<2>(true, &verdict))); |
| 365 EXPECT_CALL(*csd_service_, | 373 EXPECT_CALL(*csd_service_, |
| 366 SendClientReportPhishingRequest( | 374 SendClientReportPhishingRequest( |
| 367 Pointee(PartiallyEqualVerdict(verdict)), _)) | 375 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 368 .WillOnce(SaveArg<1>(&cb)); | 376 .WillOnce(SaveArg<1>(&cb)); |
| 369 OnPhishingDetectionDone(verdict.SerializeAsString()); | 377 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 370 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 378 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 371 ASSERT_FALSE(cb.is_null()); | 379 ASSERT_FALSE(cb.is_null()); |
| 372 | 380 |
| 373 // Make sure DoDisplayBlockingPage is not going to be called. | 381 // Make sure DoDisplayBlockingPage is not going to be called. |
| 374 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); | 382 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); |
| 375 cb.Run(GURL(verdict.url()), false); | 383 cb.Run(GURL(verdict.url()), false); |
| 376 base::RunLoop().RunUntilIdle(); | 384 base::RunLoop().RunUntilIdle(); |
| 377 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 385 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 378 } | 386 } |
| 379 | 387 |
| 380 #if defined(OS_WIN) | 388 #if defined(OS_WIN) |
| 381 // Fails on Blink canary bots: http://crbug.com/299149 | 389 // Fails on Blink canary bots: http://crbug.com/299149 |
| 382 TEST_F(ClientSideDetectionHostTest, DISABLED_OnPhishingDetectionDoneDisabled) { | 390 TEST_F(ClientSideDetectionHostTest, DISABLED_OnPhishingDetectionDoneDisabled) { |
| 383 #else | 391 #else |
| 384 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { | 392 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
| 385 #endif | 393 #endif |
| 386 // Case 2: client thinks the page is phishing and so does the server but | 394 // Case 2: client thinks the page is phishing and so does the server but |
| 387 // showing the interstitial is disabled => no interstitial is shown. | 395 // showing the interstitial is disabled => no interstitial is shown. |
| 388 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 396 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 389 web_contents(), | 397 web_contents(), |
| 390 csd_service_.get()); | 398 csd_host_.get()); |
| 391 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 399 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 392 | 400 |
| 393 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 401 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
| 394 ClientPhishingRequest verdict; | 402 ClientPhishingRequest verdict; |
| 395 verdict.set_url("http://phishingurl.com/"); | 403 verdict.set_url("http://phishingurl.com/"); |
| 396 verdict.set_client_score(1.0f); | 404 verdict.set_client_score(1.0f); |
| 397 verdict.set_is_phishing(true); | 405 verdict.set_is_phishing(true); |
| 398 | 406 |
| 399 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 407 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| 400 .WillOnce(DoAll(DeleteArg<1>(), | 408 .WillOnce(DoAll(DeleteArg<1>(), |
| 401 InvokeCallbackArgument<2>(true, &verdict))); | 409 InvokeCallbackArgument<2>(true, &verdict))); |
| 402 EXPECT_CALL(*csd_service_, | 410 EXPECT_CALL(*csd_service_, |
| 403 SendClientReportPhishingRequest( | 411 SendClientReportPhishingRequest( |
| 404 Pointee(PartiallyEqualVerdict(verdict)), _)) | 412 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 405 .WillOnce(SaveArg<1>(&cb)); | 413 .WillOnce(SaveArg<1>(&cb)); |
| 406 OnPhishingDetectionDone(verdict.SerializeAsString()); | 414 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 407 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 415 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 408 ASSERT_FALSE(cb.is_null()); | 416 ASSERT_FALSE(cb.is_null()); |
| 409 | 417 |
| 410 // Make sure DoDisplayBlockingPage is not going to be called. | 418 // Make sure DoDisplayBlockingPage is not going to be called. |
| 411 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); | 419 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); |
| 412 cb.Run(GURL(verdict.url()), false); | 420 cb.Run(GURL(verdict.url()), false); |
| 413 base::RunLoop().RunUntilIdle(); | 421 base::RunLoop().RunUntilIdle(); |
| 414 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 422 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 415 } | 423 } |
| 416 | 424 |
| 417 #if defined(OS_WIN) | 425 #if defined(OS_WIN) |
| 418 // Fails on Blink canary bots: http://crbug.com/299149 | 426 // Fails on Blink canary bots: http://crbug.com/299149 |
| 419 TEST_F(ClientSideDetectionHostTest, | 427 TEST_F(ClientSideDetectionHostTest, |
| 420 DISABLED_OnPhishingDetectionDoneShowInterstitial) { | 428 DISABLED_OnPhishingDetectionDoneShowInterstitial) { |
| 421 #else | 429 #else |
| 422 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { | 430 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
| 423 #endif | 431 #endif |
| 424 // Case 3: client thinks the page is phishing and so does the server. | 432 // Case 3: client thinks the page is phishing and so does the server. |
| 425 // We show an interstitial. | 433 // We show an interstitial. |
| 426 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 434 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 427 web_contents(), | 435 web_contents(), |
| 428 csd_service_.get()); | 436 csd_host_.get()); |
| 429 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 437 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 430 | 438 |
| 431 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 439 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
| 432 GURL phishing_url("http://phishingurl.com/"); | 440 GURL phishing_url("http://phishingurl.com/"); |
| 433 ClientPhishingRequest verdict; | 441 ClientPhishingRequest verdict; |
| 434 verdict.set_url(phishing_url.spec()); | 442 verdict.set_url(phishing_url.spec()); |
| 435 verdict.set_client_score(1.0f); | 443 verdict.set_client_score(1.0f); |
| 436 verdict.set_is_phishing(true); | 444 verdict.set_is_phishing(true); |
| 437 | 445 |
| 438 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 446 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| 439 .WillOnce(DoAll(DeleteArg<1>(), | 447 .WillOnce(DoAll(DeleteArg<1>(), |
| 440 InvokeCallbackArgument<2>(true, &verdict))); | 448 InvokeCallbackArgument<2>(true, &verdict))); |
| 441 EXPECT_CALL(*csd_service_, | 449 EXPECT_CALL(*csd_service_, |
| 442 SendClientReportPhishingRequest( | 450 SendClientReportPhishingRequest( |
| 443 Pointee(PartiallyEqualVerdict(verdict)), _)) | 451 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 444 .WillOnce(SaveArg<1>(&cb)); | 452 .WillOnce(SaveArg<1>(&cb)); |
| 445 OnPhishingDetectionDone(verdict.SerializeAsString()); | 453 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 454 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 446 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 455 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 447 ASSERT_FALSE(cb.is_null()); | 456 ASSERT_FALSE(cb.is_null()); |
| 448 | 457 |
| 449 UnsafeResource resource; | 458 UnsafeResource resource; |
| 450 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 459 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
| 451 .WillOnce(SaveArg<0>(&resource)); | 460 .WillOnce(SaveArg<0>(&resource)); |
| 452 cb.Run(phishing_url, true); | 461 cb.Run(phishing_url, true); |
| 453 | 462 |
| 454 base::RunLoop().RunUntilIdle(); | 463 base::RunLoop().RunUntilIdle(); |
| 455 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 464 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 477 #else | 486 #else |
| 478 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { | 487 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { |
| 479 #endif | 488 #endif |
| 480 // Case 4 & 5: client thinks a page is phishing then navigates to | 489 // Case 4 & 5: client thinks a page is phishing then navigates to |
| 481 // another page which is also considered phishing by the client | 490 // another page which is also considered phishing by the client |
| 482 // before the server responds with a verdict. After a while the | 491 // before the server responds with a verdict. After a while the |
| 483 // server responds for both requests with a phishing verdict. Only | 492 // server responds for both requests with a phishing verdict. Only |
| 484 // a single interstitial is shown for the second URL. | 493 // a single interstitial is shown for the second URL. |
| 485 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 494 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 486 web_contents(), | 495 web_contents(), |
| 487 csd_service_.get()); | 496 csd_host_.get()); |
| 488 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 497 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 489 | 498 |
| 490 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 499 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
| 491 GURL phishing_url("http://phishingurl.com/"); | 500 GURL phishing_url("http://phishingurl.com/"); |
| 492 ClientPhishingRequest verdict; | 501 ClientPhishingRequest verdict; |
| 493 verdict.set_url(phishing_url.spec()); | 502 verdict.set_url(phishing_url.spec()); |
| 494 verdict.set_client_score(1.0f); | 503 verdict.set_client_score(1.0f); |
| 495 verdict.set_is_phishing(true); | 504 verdict.set_is_phishing(true); |
| 496 | 505 |
| 497 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 506 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| 498 .WillOnce(DoAll(DeleteArg<1>(), | 507 .WillOnce(DoAll(DeleteArg<1>(), |
| 499 InvokeCallbackArgument<2>(true, &verdict))); | 508 InvokeCallbackArgument<2>(true, &verdict))); |
| 500 EXPECT_CALL(*csd_service_, | 509 EXPECT_CALL(*csd_service_, |
| 501 SendClientReportPhishingRequest( | 510 SendClientReportPhishingRequest( |
| 502 Pointee(PartiallyEqualVerdict(verdict)), _)) | 511 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 503 .WillOnce(SaveArg<1>(&cb)); | 512 .WillOnce(SaveArg<1>(&cb)); |
| 504 OnPhishingDetectionDone(verdict.SerializeAsString()); | 513 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 514 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 505 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 515 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 506 ASSERT_FALSE(cb.is_null()); | 516 ASSERT_FALSE(cb.is_null()); |
| 507 | 517 |
| 508 // Set this back to a normal browser feature extractor since we're using | 518 // Set this back to a normal browser feature extractor since we're using |
| 509 // NavigateAndCommit() and it's easier to use the real thing than setting up | 519 // NavigateAndCommit() and it's easier to use the real thing than setting up |
| 510 // mock expectations. | 520 // mock expectations. |
| 511 SetFeatureExtractor(new BrowserFeatureExtractor(web_contents(), | 521 SetFeatureExtractor(new BrowserFeatureExtractor(web_contents(), |
| 512 csd_service_.get())); | 522 csd_host_.get())); |
| 513 GURL other_phishing_url("http://other_phishing_url.com/bla"); | 523 GURL other_phishing_url("http://other_phishing_url.com/bla"); |
| 514 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, | 524 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, |
| 515 &kFalse, &kFalse, &kFalse); | 525 &kFalse, &kFalse, &kFalse); |
| 516 // We navigate away. The callback cb should be revoked. | 526 // We navigate away. The callback cb should be revoked. |
| 517 NavigateAndCommit(other_phishing_url); | 527 NavigateAndCommit(other_phishing_url); |
| 518 // Wait for the pre-classification checks to finish for other_phishing_url. | 528 // Wait for the pre-classification checks to finish for other_phishing_url. |
| 519 WaitAndCheckPreClassificationChecks(); | 529 WaitAndCheckPreClassificationChecks(); |
| 520 | 530 |
| 521 ClientSideDetectionService::ClientReportPhishingRequestCallback cb_other; | 531 ClientSideDetectionService::ClientReportPhishingRequestCallback cb_other; |
| 522 verdict.set_url(other_phishing_url.spec()); | 532 verdict.set_url(other_phishing_url.spec()); |
| 523 verdict.set_client_score(0.8f); | 533 verdict.set_client_score(0.8f); |
| 524 EXPECT_CALL(*csd_service_, | 534 EXPECT_CALL(*csd_service_, |
| 525 SendClientReportPhishingRequest( | 535 SendClientReportPhishingRequest( |
| 526 Pointee(PartiallyEqualVerdict(verdict)), _)) | 536 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 527 .WillOnce(DoAll(DeleteArg<0>(), | 537 .WillOnce(DoAll(DeleteArg<0>(), |
| 528 SaveArg<1>(&cb_other), | 538 SaveArg<1>(&cb_other), |
| 529 QuitUIMessageLoop())); | 539 QuitUIMessageLoop())); |
| 530 std::vector<GURL> redirect_chain; | 540 std::vector<GURL> redirect_chain; |
| 531 redirect_chain.push_back(other_phishing_url); | 541 redirect_chain.push_back(other_phishing_url); |
| 532 SetRedirectChain(redirect_chain); | 542 SetRedirectChain(redirect_chain); |
| 533 OnPhishingDetectionDone(verdict.SerializeAsString()); | 543 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 534 base::MessageLoop::current()->Run(); | 544 base::MessageLoop::current()->Run(); |
| 545 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 535 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 546 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 536 ASSERT_FALSE(cb_other.is_null()); | 547 ASSERT_FALSE(cb_other.is_null()); |
| 537 | 548 |
| 538 // We expect that the interstitial is shown for the second phishing URL and | 549 // We expect that the interstitial is shown for the second phishing URL and |
| 539 // not for the first phishing URL. | 550 // not for the first phishing URL. |
| 540 UnsafeResource resource; | 551 UnsafeResource resource; |
| 541 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 552 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
| 542 .WillOnce(SaveArg<0>(&resource)); | 553 .WillOnce(SaveArg<0>(&resource)); |
| 543 | 554 |
| 544 cb.Run(phishing_url, true); // Should have no effect. | 555 cb.Run(phishing_url, true); // Should have no effect. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 567 // Fails on Blink canary bots: http://crbug.com/299149 | 578 // Fails on Blink canary bots: http://crbug.com/299149 |
| 568 TEST_F(ClientSideDetectionHostTest, | 579 TEST_F(ClientSideDetectionHostTest, |
| 569 DISABLED_OnPhishingDetectionDoneVerdictNotPhishing) { | 580 DISABLED_OnPhishingDetectionDoneVerdictNotPhishing) { |
| 570 #else | 581 #else |
| 571 TEST_F(ClientSideDetectionHostTest, | 582 TEST_F(ClientSideDetectionHostTest, |
| 572 OnPhishingDetectionDoneVerdictNotPhishing) { | 583 OnPhishingDetectionDoneVerdictNotPhishing) { |
| 573 #endif | 584 #endif |
| 574 // Case 6: renderer sends a verdict string that isn't phishing. | 585 // Case 6: renderer sends a verdict string that isn't phishing. |
| 575 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 586 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 576 web_contents(), | 587 web_contents(), |
| 577 csd_service_.get()); | 588 csd_host_.get()); |
| 578 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 589 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 579 | 590 |
| 580 ClientPhishingRequest verdict; | 591 ClientPhishingRequest verdict; |
| 581 verdict.set_url("http://not-phishing.com/"); | 592 verdict.set_url("http://not-phishing.com/"); |
| 582 verdict.set_client_score(0.1f); | 593 verdict.set_client_score(0.1f); |
| 583 verdict.set_is_phishing(false); | 594 verdict.set_is_phishing(false); |
| 584 | 595 |
| 585 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 596 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| 586 OnPhishingDetectionDone(verdict.SerializeAsString()); | 597 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 587 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 598 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 612 | 623 |
| 613 EXPECT_CALL(*csd_service_, | 624 EXPECT_CALL(*csd_service_, |
| 614 SendClientReportPhishingRequest( | 625 SendClientReportPhishingRequest( |
| 615 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 626 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
| 616 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 627 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
| 617 std::vector<GURL> redirect_chain; | 628 std::vector<GURL> redirect_chain; |
| 618 redirect_chain.push_back(url); | 629 redirect_chain.push_back(url); |
| 619 SetRedirectChain(redirect_chain); | 630 SetRedirectChain(redirect_chain); |
| 620 OnPhishingDetectionDone(verdict.SerializeAsString()); | 631 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 621 base::MessageLoop::current()->Run(); | 632 base::MessageLoop::current()->Run(); |
| 622 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 633 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 623 } | 634 } |
| 624 | 635 |
| 625 #if defined(OS_WIN) | 636 #if defined(OS_WIN) |
| 626 // Crashes on Blink canary bots: http://crbug.com/299149 | 637 // Crashes on Blink canary bots: http://crbug.com/299149 |
| 627 TEST_F(ClientSideDetectionHostTest, DISABLED_UpdateIPUrlMap) { | 638 TEST_F(ClientSideDetectionHostTest, DISABLED_UpdateIPUrlMap) { |
| 628 #else | 639 #else |
| 629 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { | 640 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
| 630 #endif | 641 #endif |
| 631 BrowseInfo* browse_info = GetBrowseInfo(); | 642 BrowseInfo* browse_info = GetBrowseInfo(); |
| 632 | 643 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 TEST_F(ClientSideDetectionHostTest, | 696 TEST_F(ClientSideDetectionHostTest, |
| 686 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { | 697 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { |
| 687 #else | 698 #else |
| 688 TEST_F(ClientSideDetectionHostTest, | 699 TEST_F(ClientSideDetectionHostTest, |
| 689 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { | 700 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { |
| 690 #endif | 701 #endif |
| 691 // Case 7: renderer sends a verdict string that isn't phishing and not matches | 702 // Case 7: renderer sends a verdict string that isn't phishing and not matches |
| 692 // malware bad IP list | 703 // malware bad IP list |
| 693 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 704 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 694 web_contents(), | 705 web_contents(), |
| 695 csd_service_.get()); | 706 csd_host_.get()); |
| 696 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 707 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 697 | 708 |
| 698 ClientPhishingRequest verdict; | 709 ClientPhishingRequest verdict; |
| 699 verdict.set_url("http://not-phishing.com/"); | 710 verdict.set_url("http://not-phishing.com/"); |
| 700 verdict.set_client_score(0.1f); | 711 verdict.set_client_score(0.1f); |
| 701 verdict.set_is_phishing(false); | 712 verdict.set_is_phishing(false); |
| 702 | 713 |
| 703 ClientMalwareRequest malware_verdict; | 714 ClientMalwareRequest malware_verdict; |
| 704 malware_verdict.set_url("http://not-phishing.com/"); | 715 malware_verdict.set_url("http://not-phishing.com/"); |
| 705 | 716 |
| 706 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 717 // That is a special case. If there were no IP matches or if feature |
| 707 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 718 // extraction failed the callback will delete the malware_verdict. |
| 719 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 720 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| 708 EXPECT_CALL(*csd_service_, | 721 EXPECT_CALL(*csd_service_, |
| 709 SendClientReportMalwareRequest(_, _)).Times(0); | 722 SendClientReportMalwareRequest(_, _)).Times(0); |
| 710 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 723 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| 711 | 724 |
| 712 OnPhishingDetectionDone(verdict.SerializeAsString()); | 725 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 713 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 726 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| 714 } | 727 } |
| 715 | 728 |
| 716 #if defined(OS_WIN) | 729 #if defined(OS_WIN) |
| 717 // Crashes on Blink canary bots: http://crbug.com/299149 | 730 // Crashes on Blink canary bots: http://crbug.com/299149 |
| 718 TEST_F(ClientSideDetectionHostTest, | 731 TEST_F(ClientSideDetectionHostTest, |
| 719 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { | 732 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { |
| 720 #else | 733 #else |
| 721 TEST_F(ClientSideDetectionHostTest, | 734 TEST_F(ClientSideDetectionHostTest, |
| 722 OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { | 735 OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { |
| 723 #endif | 736 #endif |
| 724 // Case 8: renderer sends a verdict string that isn't phishing but matches | 737 // Case 8: renderer sends a verdict string that isn't phishing but matches |
| 725 // malware bad IP list | 738 // malware bad IP list |
| 726 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 739 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 727 web_contents(), | 740 web_contents(), |
| 728 csd_service_.get()); | 741 csd_host_.get()); |
| 729 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 742 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 730 | 743 |
| 731 ClientPhishingRequest verdict; | 744 ClientPhishingRequest verdict; |
| 732 verdict.set_url("http://not-phishing.com/"); | 745 verdict.set_url("http://not-phishing.com/"); |
| 733 verdict.set_client_score(0.1f); | 746 verdict.set_client_score(0.1f); |
| 734 verdict.set_is_phishing(false); | 747 verdict.set_is_phishing(false); |
| 735 | 748 |
| 736 ClientMalwareRequest malware_verdict; | 749 ClientMalwareRequest malware_verdict; |
| 737 malware_verdict.set_url("http://not-phishing.com/"); | 750 malware_verdict.set_url("http://not-phishing.com/"); |
| 738 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); | 751 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); |
| 739 feature->set_name("malwareip1.2.3.4"); | 752 feature->set_name("malwareip1.2.3.4"); |
| 740 feature->set_value(1.0); | 753 feature->set_value(1.0); |
| 741 feature->add_metainfo("badip.com"); | 754 feature->add_metainfo("badip.com"); |
| 742 | 755 |
| 743 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 756 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 744 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 757 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| 745 EXPECT_CALL(*csd_service_, | 758 EXPECT_CALL(*csd_service_, |
| 746 SendClientReportMalwareRequest( | 759 SendClientReportMalwareRequest( |
| 747 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | 760 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
| 748 .WillOnce(DeleteArg<0>()); | 761 .WillOnce(DeleteArg<0>()); |
| 749 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 762 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| 750 | 763 |
| 751 OnPhishingDetectionDone(verdict.SerializeAsString()); | 764 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 752 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 765 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| 753 } | 766 } |
| 754 | 767 |
| 755 #if defined(OS_WIN) | 768 #if defined(OS_WIN) |
| 756 // Crashes on Blink canary bots: http://crbug.com/299149 | 769 // Crashes on Blink canary bots: http://crbug.com/299149 |
| 757 TEST_F(ClientSideDetectionHostTest, | 770 TEST_F(ClientSideDetectionHostTest, |
| 758 DISABLED_OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { | 771 DISABLED_OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { |
| 759 #else | 772 #else |
| 760 TEST_F(ClientSideDetectionHostTest, | 773 TEST_F(ClientSideDetectionHostTest, |
| 761 OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { | 774 OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { |
| 762 #endif | 775 #endif |
| 763 // Case 9: renderer sends a verdict string that is phishing and matches | 776 // Case 9: renderer sends a verdict string that is phishing and matches |
| 764 // malware bad IP list | 777 // malware bad IP list |
| 765 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 778 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 766 web_contents(), | 779 web_contents(), |
| 767 csd_service_.get()); | 780 csd_host_.get()); |
| 768 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 781 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 769 | 782 |
| 770 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 783 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
| 771 ClientPhishingRequest verdict; | 784 ClientPhishingRequest verdict; |
| 772 verdict.set_url("http://not-phishing.com/"); | 785 verdict.set_url("http://not-phishing.com/"); |
| 773 verdict.set_client_score(0.1f); | 786 verdict.set_client_score(0.1f); |
| 774 verdict.set_is_phishing(true); | 787 verdict.set_is_phishing(true); |
| 775 | 788 |
| 776 ClientMalwareRequest malware_verdict; | 789 ClientMalwareRequest malware_verdict; |
| 777 malware_verdict.set_url("http://not-phishing.com/"); | 790 malware_verdict.set_url("http://not-phishing.com/"); |
| 778 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); | 791 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); |
| 779 feature->set_name("malwareip1.2.3.4"); | 792 feature->set_name("malwareip1.2.3.4"); |
| 780 feature->set_value(1.0); | 793 feature->set_value(1.0); |
| 781 feature->add_metainfo("badip.com"); | 794 feature->add_metainfo("badip.com"); |
| 782 | 795 |
| 783 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 796 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 784 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 797 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| 785 EXPECT_CALL(*csd_service_, | 798 EXPECT_CALL(*csd_service_, |
| 786 SendClientReportMalwareRequest( | 799 SendClientReportMalwareRequest( |
| 787 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | 800 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
| 788 .WillOnce(DeleteArg<0>()); | 801 .WillOnce(DeleteArg<0>()); |
| 789 | 802 |
| 790 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 803 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| 791 .WillOnce(DoAll(DeleteArg<1>(), | 804 .WillOnce(DoAll(DeleteArg<1>(), |
| 792 InvokeCallbackArgument<2>(true, &verdict))); | 805 InvokeCallbackArgument<2>(true, &verdict))); |
| 793 | 806 |
| 794 EXPECT_CALL(*csd_service_, | 807 EXPECT_CALL(*csd_service_, |
| 795 SendClientReportPhishingRequest( | 808 SendClientReportPhishingRequest( |
| 796 Pointee(PartiallyEqualVerdict(verdict)), _)) | 809 Pointee(PartiallyEqualVerdict(verdict)), _)) |
| 797 .WillOnce(SaveArg<1>(&cb)); | 810 .WillOnce(SaveArg<1>(&cb)); |
| 798 OnPhishingDetectionDone(verdict.SerializeAsString()); | 811 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 799 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 812 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| 813 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 800 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 814 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 801 ASSERT_FALSE(cb.is_null()); | 815 ASSERT_FALSE(cb.is_null()); |
| 802 } | 816 } |
| 803 | 817 |
| 804 #if defined(OS_WIN) | 818 #if defined(OS_WIN) |
| 805 // Crashes on Blink canary bots: http://crbug.com/299149 | 819 // Crashes on Blink canary bots: http://crbug.com/299149 |
| 806 TEST_F(ClientSideDetectionHostTest, | 820 TEST_F(ClientSideDetectionHostTest, |
| 807 DISABLED_OnPhishingDetectionDoneShowMalwareInterstitial) { | 821 DISABLED_OnPhishingDetectionDoneShowMalwareInterstitial) { |
| 808 #else | 822 #else |
| 809 TEST_F(ClientSideDetectionHostTest, | 823 TEST_F(ClientSideDetectionHostTest, |
| 810 OnPhishingDetectionDoneShowMalwareInterstitial) { | 824 OnPhishingDetectionDoneShowMalwareInterstitial) { |
| 811 #endif | 825 #endif |
| 812 // Case 10: client thinks the page match malware IP and so does the server. | 826 // Case 10: client thinks the page match malware IP and so does the server. |
| 813 // We show an sub-resource malware interstitial. | 827 // We show an sub-resource malware interstitial. |
| 814 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 828 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( |
| 815 web_contents(), | 829 web_contents(), |
| 816 csd_service_.get()); | 830 csd_host_.get()); |
| 817 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 831 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| 818 | 832 |
| 819 ClientPhishingRequest verdict; | 833 ClientPhishingRequest verdict; |
| 820 verdict.set_url("http://not-phishing.com/"); | 834 verdict.set_url("http://not-phishing.com/"); |
| 821 verdict.set_client_score(0.1f); | 835 verdict.set_client_score(0.1f); |
| 822 verdict.set_is_phishing(false); | 836 verdict.set_is_phishing(false); |
| 823 | 837 |
| 824 ClientSideDetectionService::ClientReportMalwareRequestCallback cb; | 838 ClientSideDetectionService::ClientReportMalwareRequestCallback cb; |
| 825 GURL malware_landing_url("http://malware.com/"); | 839 GURL malware_landing_url("http://malware.com/"); |
| 826 GURL malware_ip_url("http://badip.com"); | 840 GURL malware_ip_url("http://badip.com"); |
| 827 ClientMalwareRequest malware_verdict; | 841 ClientMalwareRequest malware_verdict; |
| 828 malware_verdict.set_url("http://malware.com/"); | 842 malware_verdict.set_url("http://malware.com/"); |
| 829 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); | 843 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); |
| 830 feature->set_name("malwareip1.2.3.4"); | 844 feature->set_name("malwareip1.2.3.4"); |
| 831 feature->set_value(1.0); | 845 feature->set_value(1.0); |
| 832 feature->add_metainfo("http://badip.com"); | 846 feature->add_metainfo("http://badip.com"); |
| 833 | 847 |
| 834 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 848 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 835 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 849 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| 836 EXPECT_CALL(*csd_service_, | 850 EXPECT_CALL(*csd_service_, |
| 837 SendClientReportMalwareRequest( | 851 SendClientReportMalwareRequest( |
| 838 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | 852 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
| 839 .WillOnce(DoAll(DeleteArg<0>(), | 853 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb))); |
| 840 SaveArg<1>(&cb))); | |
| 841 OnPhishingDetectionDone(verdict.SerializeAsString()); | 854 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 855 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 842 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 856 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| 843 ASSERT_FALSE(cb.is_null()); | 857 ASSERT_FALSE(cb.is_null()); |
| 844 | 858 |
| 845 UnsafeResource resource; | 859 UnsafeResource resource; |
| 846 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 860 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
| 847 .WillOnce(SaveArg<0>(&resource)); | 861 .WillOnce(SaveArg<0>(&resource)); |
| 848 cb.Run(malware_landing_url, malware_ip_url, true); | 862 cb.Run(malware_landing_url, malware_ip_url, true); |
| 849 | 863 |
| 850 base::RunLoop().RunUntilIdle(); | 864 base::RunLoop().RunUntilIdle(); |
| 851 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 865 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 | 1052 |
| 1039 UnsafeResource resource; | 1053 UnsafeResource resource; |
| 1040 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 1054 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
| 1041 .WillOnce(SaveArg<0>(&resource)); | 1055 .WillOnce(SaveArg<0>(&resource)); |
| 1042 | 1056 |
| 1043 NavigateAndCommit(url); | 1057 NavigateAndCommit(url); |
| 1044 // Wait for CheckCsdWhitelist and CheckCache() to be called. | 1058 // Wait for CheckCsdWhitelist and CheckCache() to be called. |
| 1045 base::RunLoop().RunUntilIdle(); | 1059 base::RunLoop().RunUntilIdle(); |
| 1046 // Now we check that all expected functions were indeed called on the two | 1060 // Now we check that all expected functions were indeed called on the two |
| 1047 // service objects. | 1061 // service objects. |
| 1048 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 1062 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| 1049 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 1063 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
| 1050 EXPECT_EQ(url, resource.url); | 1064 EXPECT_EQ(url, resource.url); |
| 1051 EXPECT_EQ(url, resource.original_url); | 1065 EXPECT_EQ(url, resource.original_url); |
| 1052 resource.callback.Reset(); | 1066 resource.callback.Reset(); |
| 1053 msg = process()->sink().GetFirstMessageMatching( | 1067 msg = process()->sink().GetFirstMessageMatching( |
| 1054 SafeBrowsingMsg_StartPhishingDetection::ID); | 1068 SafeBrowsingMsg_StartPhishingDetection::ID); |
| 1055 ASSERT_FALSE(msg); | 1069 ASSERT_FALSE(msg); |
| 1056 } | 1070 } |
| 1057 | |
| 1058 } // namespace safe_browsing | 1071 } // namespace safe_browsing |
| OLD | NEW |