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

Unified Diff: chrome/browser/safe_browsing/client_side_detection_host_unittest.cc

Issue 7408001: If we show a SafeBrowsing warning we always send the client-side detection (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
diff --git a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
index 3ce5f8a5ca7da4fb28a9a6e3ef6ecc2642f2c876..89ea148db28ad7c4f8f516b547150c113f320154 100644
--- a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
+++ b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
@@ -29,6 +29,7 @@ using ::testing::_;
using ::testing::DeleteArg;
using ::testing::DoAll;
using ::testing::Eq;
+using ::testing::IsNull;
using ::testing::Mock;
using ::testing::NiceMock;
using ::testing::NotNull;
@@ -161,11 +162,11 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness {
ui_thread_.reset();
}
- void OnDetectedPhishingSite(const std::string& verdict_str) {
+ void OnPhishingDetectionDone(const std::string& verdict_str) {
// Make sure we have a valid BrowseInfo object set before we call this
// method.
csd_host_->browse_info_.reset(new BrowseInfo);
- csd_host_->OnDetectedPhishingSite(verdict_str);
+ csd_host_->OnPhishingDetectionDone(verdict_str);
}
void FlushIOMessageLoop() {
@@ -225,6 +226,12 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness {
csd_host_->feature_extractor_.reset(extractor);
}
+ void SetUnsafeUniquePageIdToCurrent() {
+ csd_host_->unsafe_unique_page_id_ =
+ contents()->controller().GetActiveEntry()->unique_id();
+ ASSERT_TRUE(csd_host_->DidShowSBInterstitial());
+ }
+
protected:
scoped_ptr<ClientSideDetectionHost> csd_host_;
scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_;
@@ -236,7 +243,7 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness {
scoped_ptr<BrowserThread> io_thread_;
};
-TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteInvalidVerdict) {
+TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneInvalidVerdict) {
// Case 0: renderer sends an invalid verdict string that we're unable to
// parse.
MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
@@ -244,11 +251,11 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteInvalidVerdict) {
csd_service_.get());
SetFeatureExtractor(mock_extractor); // The host class takes ownership.
EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0);
- OnDetectedPhishingSite("Invalid Protocol Buffer");
+ OnPhishingDetectionDone("Invalid Protocol Buffer");
EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor));
}
-TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteNotPhishing) {
+TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) {
// Case 1: client thinks the page is phishing. The server does not agree.
// No interstitial is shown.
ClientSideDetectionService::ClientReportPhishingRequestCallback* cb;
@@ -261,7 +268,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteNotPhishing) {
SendClientReportPhishingRequest(
Pointee(PartiallyEqualVerdict(verdict)), _))
.WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop()));
- OnDetectedPhishingSite(verdict.SerializeAsString());
+ OnPhishingDetectionDone(verdict.SerializeAsString());
MessageLoop::current()->Run();
EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
ASSERT_TRUE(cb);
@@ -274,7 +281,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteNotPhishing) {
EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get()));
}
-TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteDisabled) {
+TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) {
// Case 2: client thinks the page is phishing and so does the server but
// showing the interstitial is disabled => no interstitial is shown.
ClientSideDetectionService::ClientReportPhishingRequestCallback* cb;
@@ -287,7 +294,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteDisabled) {
SendClientReportPhishingRequest(
Pointee(PartiallyEqualVerdict(verdict)), _))
.WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop()));
- OnDetectedPhishingSite(verdict.SerializeAsString());
+ OnPhishingDetectionDone(verdict.SerializeAsString());
MessageLoop::current()->Run();
EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
ASSERT_TRUE(cb);
@@ -300,7 +307,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteDisabled) {
EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get()));
}
-TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteShowInterstitial) {
+TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) {
// Case 3: client thinks the page is phishing and so does the server.
// We show an interstitial.
ClientSideDetectionService::ClientReportPhishingRequestCallback* cb;
@@ -314,7 +321,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteShowInterstitial) {
SendClientReportPhishingRequest(
Pointee(PartiallyEqualVerdict(verdict)), _))
.WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop()));
- OnDetectedPhishingSite(verdict.SerializeAsString());
+ OnPhishingDetectionDone(verdict.SerializeAsString());
MessageLoop::current()->Run();
EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
ASSERT_TRUE(cb);
@@ -351,7 +358,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteShowInterstitial) {
FlushIOMessageLoop();
}
-TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteMultiplePings) {
+TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) {
// Case 4 & 5: client thinks a page is phishing then navigates to
// another page which is also considered phishing by the client
// before the server responds with a verdict. After a while the
@@ -368,7 +375,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteMultiplePings) {
SendClientReportPhishingRequest(
Pointee(PartiallyEqualVerdict(verdict)), _))
.WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb), QuitUIMessageLoop()));
- OnDetectedPhishingSite(verdict.SerializeAsString());
+ OnPhishingDetectionDone(verdict.SerializeAsString());
MessageLoop::current()->Run();
EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
ASSERT_TRUE(cb);
@@ -389,7 +396,7 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteMultiplePings) {
.WillOnce(DoAll(DeleteArg<0>(),
SaveArg<1>(&cb_other),
QuitUIMessageLoop()));
- OnDetectedPhishingSite(verdict.SerializeAsString());
+ OnPhishingDetectionDone(verdict.SerializeAsString());
MessageLoop::current()->Run();
EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
ASSERT_TRUE(cb_other);
@@ -431,6 +438,49 @@ TEST_F(ClientSideDetectionHostTest, OnDetectedPhishingSiteMultiplePings) {
FlushIOMessageLoop();
}
+TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneVerdictNotPhishing) {
+ // Case 6: renderer sends a verdict string that isn't phishing.
+ MockBrowserFeatureExtractor* mock_extractor = new MockBrowserFeatureExtractor(
+ contents(),
+ csd_service_.get());
+ SetFeatureExtractor(mock_extractor); // The host class takes ownership.
+
+ ClientPhishingRequest verdict;
+ verdict.set_url("http://not-phishing.com/");
+ verdict.set_client_score(0.1f);
+ verdict.set_is_phishing(false);
+
+ EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0);
+ OnPhishingDetectionDone(verdict.SerializeAsString());
+ EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor));
+}
+
+TEST_F(ClientSideDetectionHostTest,
+ OnPhishingDetectionDoneVerdictNotPhishingButSBMatch) {
+ // Case 7: renderer sends a verdict string that isn't phishing but the URL
+ // was on the regular phishing or malware lists.
+ GURL url("http://not-phishing.com/");
+ ClientPhishingRequest verdict;
+ verdict.set_url(url.spec());
+ verdict.set_client_score(0.1f);
+ verdict.set_is_phishing(false);
+
+ // First we have to navigate to the URL to set the unique page ID.
+ ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse,
+ &kFalse, &kFalse);
+ NavigateAndCommit(url);
+ WaitAndCheckPreClassificationChecks();
+ SetUnsafeUniquePageIdToCurrent();
+
+ EXPECT_CALL(*csd_service_,
+ SendClientReportPhishingRequest(
+ Pointee(PartiallyEqualVerdict(verdict)), IsNull()))
+ .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop()));
Brian Ryner 2011/07/19 21:27:10 Is there an easy way to check that this situation
noelutz 2011/07/19 22:28:08 Well, I do check that NULL is passed for the callb
Brian Ryner 2011/07/19 22:35:24 Ah, I missed that. Seems reasonable.
+ OnPhishingDetectionDone(verdict.SerializeAsString());
+ MessageLoop::current()->Run();
+ EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
+}
+
TEST_F(ClientSideDetectionHostTest, NavigationCancelsShouldClassifyUrl) {
// Test that canceling pending should classify requests works as expected.

Powered by Google App Engine
This is Rietveld 408576698