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

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

Issue 351363002: Revert of Port HistoryService::GetVisibleVisitCountToHost to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Test that the callback is NULL when the verdict is not phishing. 84 // Test that the callback is NULL when the verdict is not phishing.
85 MATCHER(CallbackIsNull, "") { 85 MATCHER(CallbackIsNull, "") {
86 return arg.is_null(); 86 return arg.is_null();
87 } 87 }
88 88
89 ACTION(QuitUIMessageLoop) { 89 ACTION(QuitUIMessageLoop) {
90 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); 90 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
91 base::MessageLoopForUI::current()->Quit(); 91 base::MessageLoopForUI::current()->Quit();
92 } 92 }
93 93
94 ACTION_P(InvokeDoneCallback, verdict) { 94 // It's kind of insane that InvokeArgument doesn't work with callbacks, but it
95 scoped_ptr<ClientPhishingRequest> request(::std::tr1::get<1>(args)); 95 // doesn't seem like it.
96 request->CopyFrom(*verdict); 96 ACTION_TEMPLATE(InvokeCallbackArgument,
97 ::std::tr1::get<2>(args).Run(true, request.Pass()); 97 HAS_1_TEMPLATE_PARAMS(int, k),
98 AND_2_VALUE_PARAMS(p0, p1)) {
99 ::std::tr1::get<k>(args).Run(p0, p1);
98 } 100 }
99 101
100 ACTION_P(InvokeMalwareCallback, verdict) { 102 ACTION_P(InvokeMalwareCallback, verdict) {
101 scoped_ptr<ClientMalwareRequest> request(::std::tr1::get<1>(args)); 103 scoped_ptr<ClientMalwareRequest> request(::std::tr1::get<1>(args));
102 request->CopyFrom(*verdict); 104 request->CopyFrom(*verdict);
103 ::std::tr1::get<2>(args).Run(true, request.Pass()); 105 ::std::tr1::get<2>(args).Run(true, request.Pass());
104 } 106 }
105 107
106 void EmptyUrlCheckCallback(bool processed) { 108 void EmptyUrlCheckCallback(bool processed) {
107 } 109 }
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 csd_host_.get()); 475 csd_host_.get());
474 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 476 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
475 477
476 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; 478 ClientSideDetectionService::ClientReportPhishingRequestCallback cb;
477 ClientPhishingRequest verdict; 479 ClientPhishingRequest verdict;
478 verdict.set_url("http://phishingurl.com/"); 480 verdict.set_url("http://phishingurl.com/");
479 verdict.set_client_score(1.0f); 481 verdict.set_client_score(1.0f);
480 verdict.set_is_phishing(true); 482 verdict.set_is_phishing(true);
481 483
482 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) 484 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _))
483 .WillOnce(InvokeDoneCallback(&verdict)); 485 .WillOnce(DoAll(DeleteArg<1>(),
486 InvokeCallbackArgument<2>(true, &verdict)));
484 EXPECT_CALL(*csd_service_, 487 EXPECT_CALL(*csd_service_,
485 SendClientReportPhishingRequest( 488 SendClientReportPhishingRequest(
486 Pointee(PartiallyEqualVerdict(verdict)), _)) 489 Pointee(PartiallyEqualVerdict(verdict)), _))
487 .WillOnce(SaveArg<1>(&cb)); 490 .WillOnce(SaveArg<1>(&cb));
488 OnPhishingDetectionDone(verdict.SerializeAsString()); 491 OnPhishingDetectionDone(verdict.SerializeAsString());
489 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); 492 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get()));
490 ASSERT_FALSE(cb.is_null()); 493 ASSERT_FALSE(cb.is_null());
491 494
492 // Make sure DisplayBlockingPage is not going to be called. 495 // Make sure DisplayBlockingPage is not going to be called.
493 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0); 496 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0);
(...skipping 11 matching lines...) Expand all
505 csd_host_.get()); 508 csd_host_.get());
506 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 509 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
507 510
508 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; 511 ClientSideDetectionService::ClientReportPhishingRequestCallback cb;
509 ClientPhishingRequest verdict; 512 ClientPhishingRequest verdict;
510 verdict.set_url("http://phishingurl.com/"); 513 verdict.set_url("http://phishingurl.com/");
511 verdict.set_client_score(1.0f); 514 verdict.set_client_score(1.0f);
512 verdict.set_is_phishing(true); 515 verdict.set_is_phishing(true);
513 516
514 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) 517 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _))
515 .WillOnce(InvokeDoneCallback(&verdict)); 518 .WillOnce(DoAll(DeleteArg<1>(),
519 InvokeCallbackArgument<2>(true, &verdict)));
516 EXPECT_CALL(*csd_service_, 520 EXPECT_CALL(*csd_service_,
517 SendClientReportPhishingRequest( 521 SendClientReportPhishingRequest(
518 Pointee(PartiallyEqualVerdict(verdict)), _)) 522 Pointee(PartiallyEqualVerdict(verdict)), _))
519 .WillOnce(SaveArg<1>(&cb)); 523 .WillOnce(SaveArg<1>(&cb));
520 OnPhishingDetectionDone(verdict.SerializeAsString()); 524 OnPhishingDetectionDone(verdict.SerializeAsString());
521 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); 525 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get()));
522 ASSERT_FALSE(cb.is_null()); 526 ASSERT_FALSE(cb.is_null());
523 527
524 // Make sure DisplayBlockingPage is not going to be called. 528 // Make sure DisplayBlockingPage is not going to be called.
525 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0); 529 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0);
(...skipping 12 matching lines...) Expand all
538 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 542 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
539 543
540 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; 544 ClientSideDetectionService::ClientReportPhishingRequestCallback cb;
541 GURL phishing_url("http://phishingurl.com/"); 545 GURL phishing_url("http://phishingurl.com/");
542 ClientPhishingRequest verdict; 546 ClientPhishingRequest verdict;
543 verdict.set_url(phishing_url.spec()); 547 verdict.set_url(phishing_url.spec());
544 verdict.set_client_score(1.0f); 548 verdict.set_client_score(1.0f);
545 verdict.set_is_phishing(true); 549 verdict.set_is_phishing(true);
546 550
547 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) 551 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _))
548 .WillOnce(InvokeDoneCallback(&verdict)); 552 .WillOnce(DoAll(DeleteArg<1>(),
553 InvokeCallbackArgument<2>(true, &verdict)));
549 EXPECT_CALL(*csd_service_, 554 EXPECT_CALL(*csd_service_,
550 SendClientReportPhishingRequest( 555 SendClientReportPhishingRequest(
551 Pointee(PartiallyEqualVerdict(verdict)), _)) 556 Pointee(PartiallyEqualVerdict(verdict)), _))
552 .WillOnce(SaveArg<1>(&cb)); 557 .WillOnce(SaveArg<1>(&cb));
553 OnPhishingDetectionDone(verdict.SerializeAsString()); 558 OnPhishingDetectionDone(verdict.SerializeAsString());
554 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); 559 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get()));
555 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 560 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
556 ASSERT_FALSE(cb.is_null()); 561 ASSERT_FALSE(cb.is_null());
557 562
558 UnsafeResource resource; 563 UnsafeResource resource;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 SetFeatureExtractor(mock_extractor); // The host class takes ownership. 597 SetFeatureExtractor(mock_extractor); // The host class takes ownership.
593 598
594 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; 599 ClientSideDetectionService::ClientReportPhishingRequestCallback cb;
595 GURL phishing_url("http://phishingurl.com/"); 600 GURL phishing_url("http://phishingurl.com/");
596 ClientPhishingRequest verdict; 601 ClientPhishingRequest verdict;
597 verdict.set_url(phishing_url.spec()); 602 verdict.set_url(phishing_url.spec());
598 verdict.set_client_score(1.0f); 603 verdict.set_client_score(1.0f);
599 verdict.set_is_phishing(true); 604 verdict.set_is_phishing(true);
600 605
601 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) 606 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _))
602 .WillOnce(InvokeDoneCallback(&verdict)); 607 .WillOnce(DoAll(DeleteArg<1>(),
608 InvokeCallbackArgument<2>(true, &verdict)));
603 EXPECT_CALL(*csd_service_, 609 EXPECT_CALL(*csd_service_,
604 SendClientReportPhishingRequest( 610 SendClientReportPhishingRequest(
605 Pointee(PartiallyEqualVerdict(verdict)), _)) 611 Pointee(PartiallyEqualVerdict(verdict)), _))
606 .WillOnce(SaveArg<1>(&cb)); 612 .WillOnce(SaveArg<1>(&cb));
607 OnPhishingDetectionDone(verdict.SerializeAsString()); 613 OnPhishingDetectionDone(verdict.SerializeAsString());
608 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); 614 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get()));
609 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 615 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
610 ASSERT_FALSE(cb.is_null()); 616 ASSERT_FALSE(cb.is_null());
611 617
612 // Set this back to a normal browser feature extractor since we're using 618 // Set this back to a normal browser feature extractor since we're using
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 EXPECT_EQ(url, resource.url); 1143 EXPECT_EQ(url, resource.url);
1138 EXPECT_EQ(url, resource.original_url); 1144 EXPECT_EQ(url, resource.original_url);
1139 1145
1140 ExpectStartPhishingDetection(NULL); 1146 ExpectStartPhishingDetection(NULL);
1141 1147
1142 // Showing a phishing warning will invalidate all the weak pointers which 1148 // Showing a phishing warning will invalidate all the weak pointers which
1143 // means we will not extract malware features. 1149 // means we will not extract malware features.
1144 ExpectShouldClassifyForMalwareResult(false); 1150 ExpectShouldClassifyForMalwareResult(false);
1145 } 1151 }
1146 } // namespace safe_browsing 1152 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_host.cc ('k') | chrome/browser/safe_browsing/safe_browsing_blocking_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698