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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 331 |
324 #if defined(OS_WIN) | 332 #if defined(OS_WIN) |
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 = |
334 web_contents(), | 342 new StrictMock<MockBrowserFeatureExtractor>( |
335 csd_service_.get()); | 343 web_contents(), |
| 344 csd_host_.get()); |
336 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 345 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
337 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 346 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
338 OnPhishingDetectionDone("Invalid Protocol Buffer"); | 347 OnPhishingDetectionDone("Invalid Protocol Buffer"); |
339 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 348 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
340 } | 349 } |
341 | 350 |
342 #if defined(OS_WIN) | 351 #if defined(OS_WIN) |
343 // Fails on Blink canary bots: http://crbug.com/299149 | 352 // Fails on Blink canary bots: http://crbug.com/299149 |
344 TEST_F(ClientSideDetectionHostTest, | 353 TEST_F(ClientSideDetectionHostTest, |
345 DISABLED_OnPhishingDetectionDoneNotPhishing) { | 354 DISABLED_OnPhishingDetectionDoneNotPhishing) { |
346 #else | 355 #else |
347 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { | 356 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { |
348 #endif | 357 #endif |
349 // Case 1: client thinks the page is phishing. The server does not agree. | 358 // Case 1: client thinks the page is phishing. The server does not agree. |
350 // No interstitial is shown. | 359 // No interstitial is shown. |
351 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 360 MockBrowserFeatureExtractor* mock_extractor = |
352 web_contents(), | 361 new StrictMock<MockBrowserFeatureExtractor>( |
353 csd_service_.get()); | 362 web_contents(), |
| 363 csd_host_.get()); |
354 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 364 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
355 | 365 |
356 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 366 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
357 ClientPhishingRequest verdict; | 367 ClientPhishingRequest verdict; |
358 verdict.set_url("http://phishingurl.com/"); | 368 verdict.set_url("http://phishingurl.com/"); |
359 verdict.set_client_score(1.0f); | 369 verdict.set_client_score(1.0f); |
360 verdict.set_is_phishing(true); | 370 verdict.set_is_phishing(true); |
361 | 371 |
| 372 ClientMalwareRequest malware_verdict; |
| 373 malware_verdict.set_url(verdict.url()); |
362 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 374 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
363 .WillOnce(DoAll(DeleteArg<1>(), | 375 .WillOnce(DoAll(DeleteArg<1>(), |
364 InvokeCallbackArgument<2>(true, &verdict))); | 376 InvokeCallbackArgument<2>(true, &verdict))); |
| 377 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 378 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
365 EXPECT_CALL(*csd_service_, | 379 EXPECT_CALL(*csd_service_, |
366 SendClientReportPhishingRequest( | 380 SendClientReportPhishingRequest( |
367 Pointee(PartiallyEqualVerdict(verdict)), _)) | 381 Pointee(PartiallyEqualVerdict(verdict)), _)) |
368 .WillOnce(SaveArg<1>(&cb)); | 382 .WillOnce(SaveArg<1>(&cb)); |
369 OnPhishingDetectionDone(verdict.SerializeAsString()); | 383 OnPhishingDetectionDone(verdict.SerializeAsString()); |
370 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 384 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
371 ASSERT_FALSE(cb.is_null()); | 385 ASSERT_FALSE(cb.is_null()); |
372 | 386 |
373 // Make sure DoDisplayBlockingPage is not going to be called. | 387 // Make sure DoDisplayBlockingPage is not going to be called. |
374 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); | 388 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); |
375 cb.Run(GURL(verdict.url()), false); | 389 cb.Run(GURL(verdict.url()), false); |
376 base::RunLoop().RunUntilIdle(); | 390 base::RunLoop().RunUntilIdle(); |
377 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 391 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
378 } | 392 } |
379 | 393 |
380 #if defined(OS_WIN) | 394 #if defined(OS_WIN) |
381 // Fails on Blink canary bots: http://crbug.com/299149 | 395 // Fails on Blink canary bots: http://crbug.com/299149 |
382 TEST_F(ClientSideDetectionHostTest, DISABLED_OnPhishingDetectionDoneDisabled) { | 396 TEST_F(ClientSideDetectionHostTest, DISABLED_OnPhishingDetectionDoneDisabled) { |
383 #else | 397 #else |
384 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { | 398 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
385 #endif | 399 #endif |
386 // Case 2: client thinks the page is phishing and so does the server but | 400 // Case 2: client thinks the page is phishing and so does the server but |
387 // showing the interstitial is disabled => no interstitial is shown. | 401 // showing the interstitial is disabled => no interstitial is shown. |
388 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 402 MockBrowserFeatureExtractor* mock_extractor = |
389 web_contents(), | 403 new StrictMock<MockBrowserFeatureExtractor>( |
390 csd_service_.get()); | 404 web_contents(), |
| 405 csd_host_.get()); |
391 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 406 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
392 | 407 |
393 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 408 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
394 ClientPhishingRequest verdict; | 409 ClientPhishingRequest verdict; |
395 verdict.set_url("http://phishingurl.com/"); | 410 verdict.set_url("http://phishingurl.com/"); |
396 verdict.set_client_score(1.0f); | 411 verdict.set_client_score(1.0f); |
397 verdict.set_is_phishing(true); | 412 verdict.set_is_phishing(true); |
398 | 413 |
399 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 414 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
400 .WillOnce(DoAll(DeleteArg<1>(), | 415 .WillOnce(DoAll(DeleteArg<1>(), |
401 InvokeCallbackArgument<2>(true, &verdict))); | 416 InvokeCallbackArgument<2>(true, &verdict))); |
402 EXPECT_CALL(*csd_service_, | 417 EXPECT_CALL(*csd_service_, |
403 SendClientReportPhishingRequest( | 418 SendClientReportPhishingRequest( |
404 Pointee(PartiallyEqualVerdict(verdict)), _)) | 419 Pointee(PartiallyEqualVerdict(verdict)), _)) |
405 .WillOnce(SaveArg<1>(&cb)); | 420 .WillOnce(SaveArg<1>(&cb)); |
| 421 |
| 422 ClientMalwareRequest malware_verdict; |
| 423 malware_verdict.set_url(verdict.url()); |
| 424 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 425 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| 426 EXPECT_CALL(*csd_service_, |
| 427 SendClientReportMalwareRequest(_, _)).Times(0); |
| 428 |
406 OnPhishingDetectionDone(verdict.SerializeAsString()); | 429 OnPhishingDetectionDone(verdict.SerializeAsString()); |
407 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 430 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
408 ASSERT_FALSE(cb.is_null()); | 431 ASSERT_FALSE(cb.is_null()); |
409 | 432 |
410 // Make sure DoDisplayBlockingPage is not going to be called. | 433 // Make sure DoDisplayBlockingPage is not going to be called. |
411 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); | 434 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)).Times(0); |
412 cb.Run(GURL(verdict.url()), false); | 435 cb.Run(GURL(verdict.url()), false); |
413 base::RunLoop().RunUntilIdle(); | 436 base::RunLoop().RunUntilIdle(); |
414 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 437 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
415 } | 438 } |
416 | 439 |
417 #if defined(OS_WIN) | 440 #if defined(OS_WIN) |
418 // Fails on Blink canary bots: http://crbug.com/299149 | 441 // Fails on Blink canary bots: http://crbug.com/299149 |
419 TEST_F(ClientSideDetectionHostTest, | 442 TEST_F(ClientSideDetectionHostTest, |
420 DISABLED_OnPhishingDetectionDoneShowInterstitial) { | 443 DISABLED_OnPhishingDetectionDoneShowInterstitial) { |
421 #else | 444 #else |
422 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { | 445 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
423 #endif | 446 #endif |
424 // Case 3: client thinks the page is phishing and so does the server. | 447 // Case 3: client thinks the page is phishing and so does the server. |
425 // We show an interstitial. | 448 // We show an interstitial. |
426 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 449 MockBrowserFeatureExtractor* mock_extractor = |
427 web_contents(), | 450 new StrictMock<MockBrowserFeatureExtractor>( |
428 csd_service_.get()); | 451 web_contents(), |
| 452 csd_host_.get()); |
429 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 453 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
430 | 454 |
431 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 455 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
432 GURL phishing_url("http://phishingurl.com/"); | 456 GURL phishing_url("http://phishingurl.com/"); |
433 ClientPhishingRequest verdict; | 457 ClientPhishingRequest verdict; |
434 verdict.set_url(phishing_url.spec()); | 458 verdict.set_url(phishing_url.spec()); |
435 verdict.set_client_score(1.0f); | 459 verdict.set_client_score(1.0f); |
436 verdict.set_is_phishing(true); | 460 verdict.set_is_phishing(true); |
437 | 461 |
| 462 ClientMalwareRequest malware_verdict; |
| 463 malware_verdict.set_url(verdict.url()); |
| 464 |
438 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 465 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
439 .WillOnce(DoAll(DeleteArg<1>(), | 466 .WillOnce(DoAll(DeleteArg<1>(), |
440 InvokeCallbackArgument<2>(true, &verdict))); | 467 InvokeCallbackArgument<2>(true, &verdict))); |
| 468 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 469 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
441 EXPECT_CALL(*csd_service_, | 470 EXPECT_CALL(*csd_service_, |
442 SendClientReportPhishingRequest( | 471 SendClientReportPhishingRequest( |
443 Pointee(PartiallyEqualVerdict(verdict)), _)) | 472 Pointee(PartiallyEqualVerdict(verdict)), _)) |
444 .WillOnce(SaveArg<1>(&cb)); | 473 .WillOnce(SaveArg<1>(&cb)); |
445 OnPhishingDetectionDone(verdict.SerializeAsString()); | 474 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 475 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
446 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 476 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
447 ASSERT_FALSE(cb.is_null()); | 477 ASSERT_FALSE(cb.is_null()); |
448 | 478 |
449 UnsafeResource resource; | 479 UnsafeResource resource; |
450 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 480 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
451 .WillOnce(SaveArg<0>(&resource)); | 481 .WillOnce(SaveArg<0>(&resource)); |
452 cb.Run(phishing_url, true); | 482 cb.Run(phishing_url, true); |
453 | 483 |
454 base::RunLoop().RunUntilIdle(); | 484 base::RunLoop().RunUntilIdle(); |
455 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 485 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
(...skipping 19 matching lines...) Expand all Loading... |
475 TEST_F(ClientSideDetectionHostTest, | 505 TEST_F(ClientSideDetectionHostTest, |
476 DISABLED_OnPhishingDetectionDoneMultiplePings) { | 506 DISABLED_OnPhishingDetectionDoneMultiplePings) { |
477 #else | 507 #else |
478 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { | 508 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { |
479 #endif | 509 #endif |
480 // Case 4 & 5: client thinks a page is phishing then navigates to | 510 // Case 4 & 5: client thinks a page is phishing then navigates to |
481 // another page which is also considered phishing by the client | 511 // another page which is also considered phishing by the client |
482 // before the server responds with a verdict. After a while the | 512 // before the server responds with a verdict. After a while the |
483 // server responds for both requests with a phishing verdict. Only | 513 // server responds for both requests with a phishing verdict. Only |
484 // a single interstitial is shown for the second URL. | 514 // a single interstitial is shown for the second URL. |
485 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 515 MockBrowserFeatureExtractor* mock_extractor = |
486 web_contents(), | 516 new StrictMock<MockBrowserFeatureExtractor>( |
487 csd_service_.get()); | 517 web_contents(), |
| 518 csd_host_.get()); |
488 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 519 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
489 | 520 |
490 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 521 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
491 GURL phishing_url("http://phishingurl.com/"); | 522 GURL phishing_url("http://phishingurl.com/"); |
492 ClientPhishingRequest verdict; | 523 ClientPhishingRequest verdict; |
493 verdict.set_url(phishing_url.spec()); | 524 verdict.set_url(phishing_url.spec()); |
494 verdict.set_client_score(1.0f); | 525 verdict.set_client_score(1.0f); |
495 verdict.set_is_phishing(true); | 526 verdict.set_is_phishing(true); |
496 | 527 |
| 528 ClientMalwareRequest malware_verdict; |
| 529 malware_verdict.set_url(verdict.url()); |
| 530 |
497 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 531 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
498 .WillOnce(DoAll(DeleteArg<1>(), | 532 .WillOnce(DoAll(DeleteArg<1>(), |
499 InvokeCallbackArgument<2>(true, &verdict))); | 533 InvokeCallbackArgument<2>(true, &verdict))); |
| 534 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 535 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
500 EXPECT_CALL(*csd_service_, | 536 EXPECT_CALL(*csd_service_, |
501 SendClientReportPhishingRequest( | 537 SendClientReportPhishingRequest( |
502 Pointee(PartiallyEqualVerdict(verdict)), _)) | 538 Pointee(PartiallyEqualVerdict(verdict)), _)) |
503 .WillOnce(SaveArg<1>(&cb)); | 539 .WillOnce(SaveArg<1>(&cb)); |
504 OnPhishingDetectionDone(verdict.SerializeAsString()); | 540 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 541 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
505 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 542 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
506 ASSERT_FALSE(cb.is_null()); | 543 ASSERT_FALSE(cb.is_null()); |
507 | 544 |
508 // Set this back to a normal browser feature extractor since we're using | 545 // 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 | 546 // NavigateAndCommit() and it's easier to use the real thing than setting up |
510 // mock expectations. | 547 // mock expectations. |
511 SetFeatureExtractor(new BrowserFeatureExtractor(web_contents(), | 548 SetFeatureExtractor(new BrowserFeatureExtractor(web_contents(), |
512 csd_service_.get())); | 549 csd_host_.get())); |
513 GURL other_phishing_url("http://other_phishing_url.com/bla"); | 550 GURL other_phishing_url("http://other_phishing_url.com/bla"); |
514 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, | 551 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, |
515 &kFalse, &kFalse, &kFalse); | 552 &kFalse, &kFalse, &kFalse); |
516 // We navigate away. The callback cb should be revoked. | 553 // We navigate away. The callback cb should be revoked. |
517 NavigateAndCommit(other_phishing_url); | 554 NavigateAndCommit(other_phishing_url); |
518 // Wait for the pre-classification checks to finish for other_phishing_url. | 555 // Wait for the pre-classification checks to finish for other_phishing_url. |
519 WaitAndCheckPreClassificationChecks(); | 556 WaitAndCheckPreClassificationChecks(); |
520 | 557 |
521 ClientSideDetectionService::ClientReportPhishingRequestCallback cb_other; | 558 ClientSideDetectionService::ClientReportPhishingRequestCallback cb_other; |
522 verdict.set_url(other_phishing_url.spec()); | 559 verdict.set_url(other_phishing_url.spec()); |
523 verdict.set_client_score(0.8f); | 560 verdict.set_client_score(0.8f); |
524 EXPECT_CALL(*csd_service_, | 561 EXPECT_CALL(*csd_service_, |
525 SendClientReportPhishingRequest( | 562 SendClientReportPhishingRequest( |
526 Pointee(PartiallyEqualVerdict(verdict)), _)) | 563 Pointee(PartiallyEqualVerdict(verdict)), _)) |
527 .WillOnce(DoAll(DeleteArg<0>(), | 564 .WillOnce(DoAll(DeleteArg<0>(), |
528 SaveArg<1>(&cb_other), | 565 SaveArg<1>(&cb_other), |
529 QuitUIMessageLoop())); | 566 QuitUIMessageLoop())); |
530 std::vector<GURL> redirect_chain; | 567 std::vector<GURL> redirect_chain; |
531 redirect_chain.push_back(other_phishing_url); | 568 redirect_chain.push_back(other_phishing_url); |
532 SetRedirectChain(redirect_chain); | 569 SetRedirectChain(redirect_chain); |
533 OnPhishingDetectionDone(verdict.SerializeAsString()); | 570 OnPhishingDetectionDone(verdict.SerializeAsString()); |
534 base::MessageLoop::current()->Run(); | 571 base::MessageLoop::current()->Run(); |
| 572 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
535 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 573 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
536 ASSERT_FALSE(cb_other.is_null()); | 574 ASSERT_FALSE(cb_other.is_null()); |
537 | 575 |
538 // We expect that the interstitial is shown for the second phishing URL and | 576 // We expect that the interstitial is shown for the second phishing URL and |
539 // not for the first phishing URL. | 577 // not for the first phishing URL. |
540 UnsafeResource resource; | 578 UnsafeResource resource; |
541 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 579 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
542 .WillOnce(SaveArg<0>(&resource)); | 580 .WillOnce(SaveArg<0>(&resource)); |
543 | 581 |
544 cb.Run(phishing_url, true); // Should have no effect. | 582 cb.Run(phishing_url, true); // Should have no effect. |
(...skipping 20 matching lines...) Expand all Loading... |
565 | 603 |
566 #if defined(OS_WIN) | 604 #if defined(OS_WIN) |
567 // Fails on Blink canary bots: http://crbug.com/299149 | 605 // Fails on Blink canary bots: http://crbug.com/299149 |
568 TEST_F(ClientSideDetectionHostTest, | 606 TEST_F(ClientSideDetectionHostTest, |
569 DISABLED_OnPhishingDetectionDoneVerdictNotPhishing) { | 607 DISABLED_OnPhishingDetectionDoneVerdictNotPhishing) { |
570 #else | 608 #else |
571 TEST_F(ClientSideDetectionHostTest, | 609 TEST_F(ClientSideDetectionHostTest, |
572 OnPhishingDetectionDoneVerdictNotPhishing) { | 610 OnPhishingDetectionDoneVerdictNotPhishing) { |
573 #endif | 611 #endif |
574 // Case 6: renderer sends a verdict string that isn't phishing. | 612 // Case 6: renderer sends a verdict string that isn't phishing. |
575 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 613 MockBrowserFeatureExtractor* mock_extractor = |
576 web_contents(), | 614 new StrictMock<MockBrowserFeatureExtractor>( |
577 csd_service_.get()); | 615 web_contents(), |
| 616 csd_host_.get()); |
578 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 617 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
579 | 618 |
580 ClientPhishingRequest verdict; | 619 ClientPhishingRequest verdict; |
581 verdict.set_url("http://not-phishing.com/"); | 620 verdict.set_url("http://not-phishing.com/"); |
582 verdict.set_client_score(0.1f); | 621 verdict.set_client_score(0.1f); |
583 verdict.set_is_phishing(false); | 622 verdict.set_is_phishing(false); |
584 | 623 |
| 624 ClientMalwareRequest malware_verdict; |
| 625 malware_verdict.set_url(verdict.url()); |
| 626 |
585 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 627 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| 628 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 629 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
586 OnPhishingDetectionDone(verdict.SerializeAsString()); | 630 OnPhishingDetectionDone(verdict.SerializeAsString()); |
587 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 631 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
588 } | 632 } |
589 | 633 |
590 #if defined(OS_WIN) | 634 #if defined(OS_WIN) |
591 // Fails on Blink canary bots: http://crbug.com/299149 | 635 // Fails on Blink canary bots: http://crbug.com/299149 |
592 TEST_F(ClientSideDetectionHostTest, | 636 TEST_F(ClientSideDetectionHostTest, |
593 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingButSBMatch) { | 637 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingButSBMatch) { |
594 #else | 638 #else |
595 TEST_F(ClientSideDetectionHostTest, | 639 TEST_F(ClientSideDetectionHostTest, |
(...skipping 16 matching lines...) Expand all Loading... |
612 | 656 |
613 EXPECT_CALL(*csd_service_, | 657 EXPECT_CALL(*csd_service_, |
614 SendClientReportPhishingRequest( | 658 SendClientReportPhishingRequest( |
615 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 659 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
616 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 660 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
617 std::vector<GURL> redirect_chain; | 661 std::vector<GURL> redirect_chain; |
618 redirect_chain.push_back(url); | 662 redirect_chain.push_back(url); |
619 SetRedirectChain(redirect_chain); | 663 SetRedirectChain(redirect_chain); |
620 OnPhishingDetectionDone(verdict.SerializeAsString()); | 664 OnPhishingDetectionDone(verdict.SerializeAsString()); |
621 base::MessageLoop::current()->Run(); | 665 base::MessageLoop::current()->Run(); |
622 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 666 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
623 } | 667 } |
624 | 668 |
625 #if defined(OS_WIN) | 669 #if defined(OS_WIN) |
626 // Crashes on Blink canary bots: http://crbug.com/299149 | 670 // Crashes on Blink canary bots: http://crbug.com/299149 |
627 TEST_F(ClientSideDetectionHostTest, DISABLED_UpdateIPUrlMap) { | 671 TEST_F(ClientSideDetectionHostTest, DISABLED_UpdateIPUrlMap) { |
628 #else | 672 #else |
629 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { | 673 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
630 #endif | 674 #endif |
631 BrowseInfo* browse_info = GetBrowseInfo(); | 675 BrowseInfo* browse_info = GetBrowseInfo(); |
632 | 676 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 #if defined(OS_WIN) | 727 #if defined(OS_WIN) |
684 // Crashes on Blink canary bots: http://crbug.com/299149 | 728 // Crashes on Blink canary bots: http://crbug.com/299149 |
685 TEST_F(ClientSideDetectionHostTest, | 729 TEST_F(ClientSideDetectionHostTest, |
686 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { | 730 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { |
687 #else | 731 #else |
688 TEST_F(ClientSideDetectionHostTest, | 732 TEST_F(ClientSideDetectionHostTest, |
689 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { | 733 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { |
690 #endif | 734 #endif |
691 // Case 7: renderer sends a verdict string that isn't phishing and not matches | 735 // Case 7: renderer sends a verdict string that isn't phishing and not matches |
692 // malware bad IP list | 736 // malware bad IP list |
693 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 737 MockBrowserFeatureExtractor* mock_extractor = |
694 web_contents(), | 738 new StrictMock<MockBrowserFeatureExtractor>( |
695 csd_service_.get()); | 739 web_contents(), |
| 740 csd_host_.get()); |
696 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 741 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
697 | 742 |
698 ClientPhishingRequest verdict; | 743 ClientPhishingRequest verdict; |
699 verdict.set_url("http://not-phishing.com/"); | 744 verdict.set_url("http://not-phishing.com/"); |
700 verdict.set_client_score(0.1f); | 745 verdict.set_client_score(0.1f); |
701 verdict.set_is_phishing(false); | 746 verdict.set_is_phishing(false); |
702 | 747 |
703 ClientMalwareRequest malware_verdict; | 748 ClientMalwareRequest malware_verdict; |
704 malware_verdict.set_url("http://not-phishing.com/"); | 749 malware_verdict.set_url(verdict.url()); |
705 | 750 |
706 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 751 // That is a special case. If there were no IP matches or if feature |
707 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 752 // extraction failed the callback will delete the malware_verdict. |
| 753 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| 754 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
708 EXPECT_CALL(*csd_service_, | 755 EXPECT_CALL(*csd_service_, |
709 SendClientReportMalwareRequest(_, _)).Times(0); | 756 SendClientReportMalwareRequest(_, _)).Times(0); |
710 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 757 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
711 | 758 |
712 OnPhishingDetectionDone(verdict.SerializeAsString()); | 759 OnPhishingDetectionDone(verdict.SerializeAsString()); |
713 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 760 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
714 } | 761 } |
715 | 762 |
716 #if defined(OS_WIN) | 763 #if defined(OS_WIN) |
717 // Crashes on Blink canary bots: http://crbug.com/299149 | 764 // Crashes on Blink canary bots: http://crbug.com/299149 |
718 TEST_F(ClientSideDetectionHostTest, | 765 TEST_F(ClientSideDetectionHostTest, |
719 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { | 766 DISABLED_OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { |
720 #else | 767 #else |
721 TEST_F(ClientSideDetectionHostTest, | 768 TEST_F(ClientSideDetectionHostTest, |
722 OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { | 769 OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { |
723 #endif | 770 #endif |
724 // Case 8: renderer sends a verdict string that isn't phishing but matches | 771 // Case 8: renderer sends a verdict string that isn't phishing but matches |
725 // malware bad IP list | 772 // malware bad IP list |
726 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 773 MockBrowserFeatureExtractor* mock_extractor = |
727 web_contents(), | 774 new StrictMock<MockBrowserFeatureExtractor>( |
728 csd_service_.get()); | 775 web_contents(), |
| 776 csd_host_.get()); |
729 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 777 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
730 | 778 |
731 ClientPhishingRequest verdict; | 779 ClientPhishingRequest verdict; |
732 verdict.set_url("http://not-phishing.com/"); | 780 verdict.set_url("http://not-phishing.com/"); |
733 verdict.set_client_score(0.1f); | 781 verdict.set_client_score(0.1f); |
734 verdict.set_is_phishing(false); | 782 verdict.set_is_phishing(false); |
735 | 783 |
736 ClientMalwareRequest malware_verdict; | 784 ClientMalwareRequest malware_verdict; |
737 malware_verdict.set_url("http://not-phishing.com/"); | 785 malware_verdict.set_url(verdict.url()); |
738 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); | 786 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); |
739 feature->set_name("malwareip1.2.3.4"); | 787 feature->set_name("malwareip1.2.3.4"); |
740 feature->set_value(1.0); | 788 feature->set_value(1.0); |
741 feature->add_metainfo("badip.com"); | 789 feature->add_metainfo("badip.com"); |
742 | 790 |
743 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 791 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
744 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 792 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
745 EXPECT_CALL(*csd_service_, | 793 EXPECT_CALL(*csd_service_, |
746 SendClientReportMalwareRequest( | 794 SendClientReportMalwareRequest( |
747 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | 795 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
748 .WillOnce(DeleteArg<0>()); | 796 .WillOnce(DeleteArg<0>()); |
749 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 797 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
750 | 798 |
751 OnPhishingDetectionDone(verdict.SerializeAsString()); | 799 OnPhishingDetectionDone(verdict.SerializeAsString()); |
752 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 800 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
753 } | 801 } |
754 | 802 |
755 #if defined(OS_WIN) | 803 #if defined(OS_WIN) |
756 // Crashes on Blink canary bots: http://crbug.com/299149 | 804 // Crashes on Blink canary bots: http://crbug.com/299149 |
757 TEST_F(ClientSideDetectionHostTest, | 805 TEST_F(ClientSideDetectionHostTest, |
758 DISABLED_OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { | 806 DISABLED_OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { |
759 #else | 807 #else |
760 TEST_F(ClientSideDetectionHostTest, | 808 TEST_F(ClientSideDetectionHostTest, |
761 OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { | 809 OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { |
762 #endif | 810 #endif |
763 // Case 9: renderer sends a verdict string that is phishing and matches | 811 // Case 9: renderer sends a verdict string that is phishing and matches |
764 // malware bad IP list | 812 // malware bad IP list |
765 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 813 MockBrowserFeatureExtractor* mock_extractor = |
766 web_contents(), | 814 new StrictMock<MockBrowserFeatureExtractor>( |
767 csd_service_.get()); | 815 web_contents(), |
| 816 csd_host_.get()); |
768 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 817 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
769 | 818 |
770 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 819 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
771 ClientPhishingRequest verdict; | 820 ClientPhishingRequest verdict; |
772 verdict.set_url("http://not-phishing.com/"); | 821 verdict.set_url("http://not-phishing.com/"); |
773 verdict.set_client_score(0.1f); | 822 verdict.set_client_score(0.1f); |
774 verdict.set_is_phishing(true); | 823 verdict.set_is_phishing(true); |
775 | 824 |
776 ClientMalwareRequest malware_verdict; | 825 ClientMalwareRequest malware_verdict; |
777 malware_verdict.set_url("http://not-phishing.com/"); | 826 malware_verdict.set_url(verdict.url()); |
778 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); | 827 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); |
779 feature->set_name("malwareip1.2.3.4"); | 828 feature->set_name("malwareip1.2.3.4"); |
780 feature->set_value(1.0); | 829 feature->set_value(1.0); |
781 feature->add_metainfo("badip.com"); | 830 feature->add_metainfo("badip.com"); |
782 | 831 |
783 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 832 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
784 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 833 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
785 EXPECT_CALL(*csd_service_, | 834 EXPECT_CALL(*csd_service_, |
786 SendClientReportMalwareRequest( | 835 SendClientReportMalwareRequest( |
787 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | 836 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
788 .WillOnce(DeleteArg<0>()); | 837 .WillOnce(DeleteArg<0>()); |
789 | 838 |
790 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 839 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
791 .WillOnce(DoAll(DeleteArg<1>(), | 840 .WillOnce(DoAll(DeleteArg<1>(), |
792 InvokeCallbackArgument<2>(true, &verdict))); | 841 InvokeCallbackArgument<2>(true, &verdict))); |
793 | 842 |
794 EXPECT_CALL(*csd_service_, | 843 EXPECT_CALL(*csd_service_, |
795 SendClientReportPhishingRequest( | 844 SendClientReportPhishingRequest( |
796 Pointee(PartiallyEqualVerdict(verdict)), _)) | 845 Pointee(PartiallyEqualVerdict(verdict)), _)) |
797 .WillOnce(SaveArg<1>(&cb)); | 846 .WillOnce(SaveArg<1>(&cb)); |
798 OnPhishingDetectionDone(verdict.SerializeAsString()); | 847 OnPhishingDetectionDone(verdict.SerializeAsString()); |
799 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 848 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| 849 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
800 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 850 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
801 ASSERT_FALSE(cb.is_null()); | 851 ASSERT_FALSE(cb.is_null()); |
802 } | 852 } |
803 | 853 |
804 #if defined(OS_WIN) | 854 #if defined(OS_WIN) |
805 // Crashes on Blink canary bots: http://crbug.com/299149 | 855 // Crashes on Blink canary bots: http://crbug.com/299149 |
806 TEST_F(ClientSideDetectionHostTest, | 856 TEST_F(ClientSideDetectionHostTest, |
807 DISABLED_OnPhishingDetectionDoneShowMalwareInterstitial) { | 857 DISABLED_OnPhishingDetectionDoneShowMalwareInterstitial) { |
808 #else | 858 #else |
809 TEST_F(ClientSideDetectionHostTest, | 859 TEST_F(ClientSideDetectionHostTest, |
810 OnPhishingDetectionDoneShowMalwareInterstitial) { | 860 OnPhishingDetectionDoneShowMalwareInterstitial) { |
811 #endif | 861 #endif |
812 // Case 10: client thinks the page match malware IP and so does the server. | 862 // Case 10: client thinks the page match malware IP and so does the server. |
813 // We show an sub-resource malware interstitial. | 863 // We show an sub-resource malware interstitial. |
814 MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor( | 864 MockBrowserFeatureExtractor* mock_extractor = |
815 web_contents(), | 865 new StrictMock<MockBrowserFeatureExtractor>( |
816 csd_service_.get()); | 866 web_contents(), |
| 867 csd_host_.get()); |
817 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 868 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
818 | 869 |
819 ClientPhishingRequest verdict; | 870 ClientPhishingRequest verdict; |
820 verdict.set_url("http://not-phishing.com/"); | 871 verdict.set_url("http://not-phishing.com/"); |
821 verdict.set_client_score(0.1f); | 872 verdict.set_client_score(0.1f); |
822 verdict.set_is_phishing(false); | 873 verdict.set_is_phishing(false); |
823 | 874 |
824 ClientSideDetectionService::ClientReportMalwareRequestCallback cb; | 875 ClientSideDetectionService::ClientReportMalwareRequestCallback cb; |
825 GURL malware_landing_url("http://malware.com/"); | 876 GURL malware_landing_url("http://malware.com/"); |
826 GURL malware_ip_url("http://badip.com"); | 877 GURL malware_ip_url("http://badip.com"); |
827 ClientMalwareRequest malware_verdict; | 878 ClientMalwareRequest malware_verdict; |
828 malware_verdict.set_url("http://malware.com/"); | 879 malware_verdict.set_url("http://malware.com/"); |
829 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); | 880 ClientMalwareRequest::Feature* feature = malware_verdict.add_feature_map(); |
830 feature->set_name("malwareip1.2.3.4"); | 881 feature->set_name("malwareip1.2.3.4"); |
831 feature->set_value(1.0); | 882 feature->set_value(1.0); |
832 feature->add_metainfo("http://badip.com"); | 883 feature->add_metainfo("http://badip.com"); |
833 | 884 |
834 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _)) | 885 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
835 .WillOnce(SetArgumentPointee<1>(malware_verdict)); | 886 .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
836 EXPECT_CALL(*csd_service_, | 887 EXPECT_CALL(*csd_service_, |
837 SendClientReportMalwareRequest( | 888 SendClientReportMalwareRequest( |
838 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | 889 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
839 .WillOnce(DoAll(DeleteArg<0>(), | 890 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb))); |
840 SaveArg<1>(&cb))); | |
841 OnPhishingDetectionDone(verdict.SerializeAsString()); | 891 OnPhishingDetectionDone(verdict.SerializeAsString()); |
| 892 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
842 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 893 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
843 ASSERT_FALSE(cb.is_null()); | 894 ASSERT_FALSE(cb.is_null()); |
844 | 895 |
845 UnsafeResource resource; | 896 UnsafeResource resource; |
846 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 897 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
847 .WillOnce(SaveArg<0>(&resource)); | 898 .WillOnce(SaveArg<0>(&resource)); |
848 cb.Run(malware_landing_url, malware_ip_url, true); | 899 cb.Run(malware_landing_url, malware_ip_url, true); |
849 | 900 |
850 base::RunLoop().RunUntilIdle(); | 901 base::RunLoop().RunUntilIdle(); |
851 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 902 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 | 1089 |
1039 UnsafeResource resource; | 1090 UnsafeResource resource; |
1040 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) | 1091 EXPECT_CALL(*ui_manager_.get(), DoDisplayBlockingPage(_)) |
1041 .WillOnce(SaveArg<0>(&resource)); | 1092 .WillOnce(SaveArg<0>(&resource)); |
1042 | 1093 |
1043 NavigateAndCommit(url); | 1094 NavigateAndCommit(url); |
1044 // Wait for CheckCsdWhitelist and CheckCache() to be called. | 1095 // Wait for CheckCsdWhitelist and CheckCache() to be called. |
1045 base::RunLoop().RunUntilIdle(); | 1096 base::RunLoop().RunUntilIdle(); |
1046 // Now we check that all expected functions were indeed called on the two | 1097 // Now we check that all expected functions were indeed called on the two |
1047 // service objects. | 1098 // service objects. |
1048 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 1099 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
1049 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 1100 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
1050 EXPECT_EQ(url, resource.url); | 1101 EXPECT_EQ(url, resource.url); |
1051 EXPECT_EQ(url, resource.original_url); | 1102 EXPECT_EQ(url, resource.original_url); |
1052 resource.callback.Reset(); | 1103 resource.callback.Reset(); |
1053 msg = process()->sink().GetFirstMessageMatching( | 1104 msg = process()->sink().GetFirstMessageMatching( |
1054 SafeBrowsingMsg_StartPhishingDetection::ID); | 1105 SafeBrowsingMsg_StartPhishingDetection::ID); |
1055 ASSERT_FALSE(msg); | 1106 ASSERT_FALSE(msg); |
1056 } | 1107 } |
1057 | |
1058 } // namespace safe_browsing | 1108 } // namespace safe_browsing |
OLD | NEW |