Chromium Code Reviews| 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 3a66f8a653f4a5cedab6304e09301855b8b22aaa..edc12e11631f6b55091e790b00b12f054e2d11f2 100644 |
| --- a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc |
| +++ b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc |
| @@ -159,6 +159,7 @@ class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { |
| MOCK_METHOD1(MatchCsdWhitelistUrl, bool(const GURL&)); |
| MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); |
| + MOCK_METHOD0(IsMalwareKillSwitchOn, bool()); |
| protected: |
| virtual ~MockSafeBrowsingDatabaseManager() {} |
| @@ -219,10 +220,6 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { |
| // We need to create this here since we don't call |
| // DidNavigateMainFramePostCommit in this test. |
| csd_host_->browse_info_.reset(new BrowseInfo); |
| - |
| - // By default this is set to false. Turn it on as if we are in canary or |
| - // dev channel |
| - csd_host_->malware_report_enabled_ = true; |
| } |
| virtual void TearDown() { |
| @@ -248,6 +245,10 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { |
| csd_host_->OnPhishingDetectionDone(verdict_str); |
| } |
| + void DocumentOnLoadCompletedInMainFrame(int32 page_id) { |
| + csd_host_->DocumentOnLoadCompletedInMainFrame(page_id); |
| + } |
| + |
| void UpdateIPUrlMap(const std::string& ip, const std::string& host) { |
| csd_host_->UpdateIPUrlMap(ip, host, "", "", ResourceType::OBJECT); |
| } |
| @@ -274,6 +275,8 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { |
| if (match_csd_whitelist) { |
|
mattm
2014/03/18 02:19:06
hm, does it make sense to make these dependent on
noé
2014/03/20 17:01:45
Separated them.
|
| EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(url)) |
| .WillOnce(Return(*match_csd_whitelist)); |
| + EXPECT_CALL(*database_manager_.get(), IsMalwareKillSwitchOn()) |
| + .WillRepeatedly(Return(*match_csd_whitelist)); |
|
mattm
2014/03/18 02:19:06
reason this is Repeatedly instead of Once?
noé
2014/03/20 17:01:45
That's because some tests call the Expect method m
|
| } |
| if (get_valid_cached_result) { |
| EXPECT_CALL(*csd_service_, GetValidCachedResult(url, NotNull())) |
| @@ -310,6 +313,17 @@ class ClientSideDetectionHostTest : public ChromeRenderViewHostTestHarness { |
| csd_host_->browse_info_->referrer = referrer; |
| } |
| + void ExpectShouldClassifyForMalwareResult(const bool* should_classify) { |
| + if (should_classify == NULL) { |
| + EXPECT_EQ(NULL, csd_host_->should_classify_for_malware_.get()); |
| + } else { |
| + EXPECT_TRUE(csd_host_->should_classify_for_malware_.get()); |
| + if (csd_host_->should_classify_for_malware_.get()) { |
| + EXPECT_EQ(*should_classify, *(csd_host_->should_classify_for_malware_)); |
| + } |
| + } |
| + } |
| + |
| void TestUnsafeResourceCopied(const UnsafeResource& resource) { |
| ASSERT_TRUE(csd_host_->unsafe_resource_.get()); |
| // Test that the resource from OnSafeBrowsingHit notification was copied |
| @@ -450,13 +464,9 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneNotPhishing) { |
| verdict.set_client_score(1.0f); |
| verdict.set_is_phishing(true); |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| .WillOnce(DoAll(DeleteArg<1>(), |
| InvokeCallbackArgument<2>(true, &verdict))); |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| EXPECT_CALL(*csd_service_, |
| SendClientReportPhishingRequest( |
| Pointee(PartiallyEqualVerdict(verdict)), _)) |
| @@ -494,14 +504,6 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneDisabled) { |
| SendClientReportPhishingRequest( |
| Pointee(PartiallyEqualVerdict(verdict)), _)) |
| .WillOnce(SaveArg<1>(&cb)); |
| - |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| - EXPECT_CALL(*csd_service_, |
| - SendClientReportMalwareRequest(_, _)).Times(0); |
| - |
| OnPhishingDetectionDone(verdict.SerializeAsString()); |
| EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| ASSERT_FALSE(cb.is_null()); |
| @@ -529,14 +531,9 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
| verdict.set_client_score(1.0f); |
| verdict.set_is_phishing(true); |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| - |
| EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| .WillOnce(DoAll(DeleteArg<1>(), |
| InvokeCallbackArgument<2>(true, &verdict))); |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| EXPECT_CALL(*csd_service_, |
| SendClientReportPhishingRequest( |
| Pointee(PartiallyEqualVerdict(verdict)), _)) |
| @@ -589,14 +586,9 @@ TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneMultiplePings) { |
| verdict.set_client_score(1.0f); |
| verdict.set_is_phishing(true); |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| - |
| EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| .WillOnce(DoAll(DeleteArg<1>(), |
| InvokeCallbackArgument<2>(true, &verdict))); |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| EXPECT_CALL(*csd_service_, |
| SendClientReportPhishingRequest( |
| Pointee(PartiallyEqualVerdict(verdict)), _)) |
| @@ -679,12 +671,7 @@ TEST_F(ClientSideDetectionHostTest, |
| verdict.set_client_score(0.1f); |
| verdict.set_is_phishing(false); |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| - |
| EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| OnPhishingDetectionDone(verdict.SerializeAsString()); |
| EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| } |
| @@ -761,152 +748,29 @@ TEST_F(ClientSideDetectionHostTest, |
| WaitAndCheckPreClassificationChecks(); |
| } |
| -TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
| - BrowseInfo* browse_info = GetBrowseInfo(); |
| - |
| - // Empty IP or host are skipped |
| - UpdateIPUrlMap("250.10.10.10", std::string()); |
| - ASSERT_EQ(0U, browse_info->ips.size()); |
| - UpdateIPUrlMap(std::string(), "http://google.com/a"); |
| - ASSERT_EQ(0U, browse_info->ips.size()); |
| - UpdateIPUrlMap(std::string(), std::string()); |
| - ASSERT_EQ(0U, browse_info->ips.size()); |
| - |
| - std::vector<IPUrlInfo> expected_urls; |
| - for (int i = 0; i < 20; i++) { |
| - std::string url = base::StringPrintf("http://%d.com/", i); |
| - expected_urls.push_back(IPUrlInfo(url, "", "", ResourceType::OBJECT)); |
| - UpdateIPUrlMap("250.10.10.10", url); |
| - } |
| - ASSERT_EQ(1U, browse_info->ips.size()); |
| - ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size()); |
| - CheckIPUrlEqual(expected_urls, |
| - browse_info->ips["250.10.10.10"]); |
| - |
| - // Add more urls for this ip, it exceeds max limit and won't be added |
| - UpdateIPUrlMap("250.10.10.10", "http://21.com/"); |
| - ASSERT_EQ(1U, browse_info->ips.size()); |
| - ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size()); |
| - CheckIPUrlEqual(expected_urls, |
| - browse_info->ips["250.10.10.10"]); |
| - |
| - // Add 199 more IPs |
| - for (int i = 0; i < 199; i++) { |
| - std::string ip = base::StringPrintf("%d.%d.%d.256", i, i, i); |
| - expected_urls.clear(); |
| - expected_urls.push_back(IPUrlInfo("test.com/", "", "", |
| - ResourceType::OBJECT)); |
| - UpdateIPUrlMap(ip, "test.com/"); |
| - ASSERT_EQ(1U, browse_info->ips[ip].size()); |
| - CheckIPUrlEqual(expected_urls, |
| - browse_info->ips[ip]); |
| - } |
| - ASSERT_EQ(200U, browse_info->ips.size()); |
| - |
| - // Exceeding max ip limit 200, these won't be added |
| - UpdateIPUrlMap("250.250.250.250", "goo.com/"); |
| - UpdateIPUrlMap("250.250.250.250", "bar.com/"); |
| - UpdateIPUrlMap("250.250.0.250", "foo.com/"); |
| - ASSERT_EQ(200U, browse_info->ips.size()); |
| - |
| - // Add url to existing IPs succeed |
| - UpdateIPUrlMap("100.100.100.256", "more.com/"); |
| - ASSERT_EQ(2U, browse_info->ips["100.100.100.256"].size()); |
| - expected_urls.clear(); |
| - expected_urls.push_back(IPUrlInfo("test.com/", "", "", ResourceType::OBJECT)); |
| - expected_urls.push_back(IPUrlInfo("more.com/", "", "", ResourceType::OBJECT)); |
| - CheckIPUrlEqual(expected_urls, |
| - browse_info->ips["100.100.100.256"]); |
| -} |
| - |
| TEST_F(ClientSideDetectionHostTest, |
| - OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { |
| - // Case 7: renderer sends a verdict string that isn't phishing and not matches |
| - // malware bad IP list |
| + DocumentOnLoadCompletedInMainFrameMalwareIP) { |
|
mattm
2014/03/18 02:19:06
what is this case testing / how is it different th
noé
2014/03/20 17:01:45
Good point. The other test is more complete. Rem
|
| + // Renderer is done loading the main frame and there is a bad IP match. |
| MockBrowserFeatureExtractor* mock_extractor = |
| new StrictMock<MockBrowserFeatureExtractor>( |
| web_contents(), |
| csd_host_.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); |
| - |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| - |
| - // That is a special case. If there were no IP matches or if feature |
| - // extraction failed the callback will delete the malware_verdict. |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| - EXPECT_CALL(*csd_service_, |
| - SendClientReportMalwareRequest(_, _)).Times(0); |
| - EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| - |
| - OnPhishingDetectionDone(verdict.SerializeAsString()); |
| - EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| -} |
| - |
| -TEST_F(ClientSideDetectionHostTest, |
| - OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { |
| - // Case 8: renderer sends a verdict string that isn't phishing but matches |
| - // malware bad IP list |
| - MockBrowserFeatureExtractor* mock_extractor = |
| - new StrictMock<MockBrowserFeatureExtractor>( |
| - web_contents(), |
| - csd_host_.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); |
| - |
| ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| + malware_verdict.set_url("http://not-phishing.com/"); |
| malware_verdict.set_referrer_url("http://referrer.com/"); |
| ClientMalwareRequest::UrlInfo* badipurl = |
| malware_verdict.add_bad_ip_url_info(); |
| badipurl->set_ip("1.2.3.4"); |
| badipurl->set_url("badip.com"); |
| - EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| - .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| - EXPECT_CALL(*csd_service_, |
| - SendClientReportMalwareRequest( |
| - Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
| - .WillOnce(DeleteArg<0>()); |
| - EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
| - |
| SetReferrer(GURL("http://referrer.com/")); |
| - OnPhishingDetectionDone(verdict.SerializeAsString()); |
| - EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| -} |
| -TEST_F(ClientSideDetectionHostTest, |
| - OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { |
| - // Case 9: renderer sends a verdict string that is phishing and matches |
| - // malware bad IP list |
| - MockBrowserFeatureExtractor* mock_extractor = |
| - new StrictMock<MockBrowserFeatureExtractor>( |
| - web_contents(), |
| - csd_host_.get()); |
| - SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
| - |
| - ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
| - ClientPhishingRequest verdict; |
| - verdict.set_url("http://not-phishing.com/"); |
| - verdict.set_client_score(0.1f); |
| - verdict.set_is_phishing(true); |
| - |
| - ClientMalwareRequest malware_verdict; |
| - malware_verdict.set_url(verdict.url()); |
| - ClientMalwareRequest::UrlInfo* badipurl = |
| - malware_verdict.add_bad_ip_url_info(); |
| - badipurl->set_ip("1.2.3.4"); |
| - badipurl->set_url("badip.com"); |
| + ExpectPreClassificationChecks(GURL(malware_verdict.url()), &kFalse, &kFalse, |
| + &kFalse, &kFalse, &kFalse, &kFalse); |
| + NavigateAndCommit(GURL(malware_verdict.url())); |
| + WaitAndCheckPreClassificationChecks(); |
| EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| @@ -915,27 +779,13 @@ TEST_F(ClientSideDetectionHostTest, |
| Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
| .WillOnce(DeleteArg<0>()); |
| - EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
| - .WillOnce(DoAll(DeleteArg<1>(), |
| - InvokeCallbackArgument<2>(true, &verdict))); |
| - |
| - EXPECT_CALL(*csd_service_, |
| - SendClientReportPhishingRequest( |
| - Pointee(PartiallyEqualVerdict(verdict)), _)) |
| - .WillOnce(SaveArg<1>(&cb)); |
| - |
| - // Referrer url using https won't be set and sent out. |
| - SetReferrer(GURL("https://referrer.com/")); |
| - OnPhishingDetectionDone(verdict.SerializeAsString()); |
| + DocumentOnLoadCompletedInMainFrame(GetBrowseInfo()->page_id); |
| EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
| - EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| - EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| - ASSERT_FALSE(cb.is_null()); |
| } |
| TEST_F(ClientSideDetectionHostTest, |
| - OnPhishingDetectionDoneShowMalwareInterstitial) { |
| - // Case 10: client thinks the page match malware IP and so does the server. |
| + DocumentOnLoadCompletedInMainFrameShowMalwareInterstitial) { |
| + // Case 9: client thinks the page match malware IP and so does the server. |
| // We show an sub-resource malware interstitial. |
| MockBrowserFeatureExtractor* mock_extractor = |
| new StrictMock<MockBrowserFeatureExtractor>( |
| @@ -943,12 +793,6 @@ TEST_F(ClientSideDetectionHostTest, |
| csd_host_.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); |
| - |
| - ClientSideDetectionService::ClientReportMalwareRequestCallback cb; |
| GURL malware_landing_url("http://malware.com/"); |
| GURL malware_ip_url("http://badip.com"); |
| ClientMalwareRequest malware_verdict; |
| @@ -958,13 +802,19 @@ TEST_F(ClientSideDetectionHostTest, |
| badipurl->set_ip("1.2.3.4"); |
| badipurl->set_url("http://badip.com"); |
| + ExpectPreClassificationChecks(GURL(malware_verdict.url()), &kFalse, &kFalse, |
| + &kFalse, &kFalse, &kFalse, &kFalse); |
| + NavigateAndCommit(GURL(malware_verdict.url())); |
| + WaitAndCheckPreClassificationChecks(); |
| + |
| + ClientSideDetectionService::ClientReportMalwareRequestCallback cb; |
| EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) |
| .WillOnce(InvokeMalwareCallback(&malware_verdict)); |
| EXPECT_CALL(*csd_service_, |
| SendClientReportMalwareRequest( |
| Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) |
| .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb))); |
| - OnPhishingDetectionDone(verdict.SerializeAsString()); |
| + DocumentOnLoadCompletedInMainFrame(GetBrowseInfo()->page_id); |
| EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
| EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
| ASSERT_FALSE(cb.is_null()); |
| @@ -993,6 +843,64 @@ TEST_F(ClientSideDetectionHostTest, |
| ui_manager_, resource.callback)); |
| } |
| +TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
| + BrowseInfo* browse_info = GetBrowseInfo(); |
| + |
| + // Empty IP or host are skipped |
| + UpdateIPUrlMap("250.10.10.10", std::string()); |
| + ASSERT_EQ(0U, browse_info->ips.size()); |
| + UpdateIPUrlMap(std::string(), "http://google.com/a"); |
| + ASSERT_EQ(0U, browse_info->ips.size()); |
| + UpdateIPUrlMap(std::string(), std::string()); |
| + ASSERT_EQ(0U, browse_info->ips.size()); |
| + |
| + std::vector<IPUrlInfo> expected_urls; |
| + for (int i = 0; i < 20; i++) { |
| + std::string url = base::StringPrintf("http://%d.com/", i); |
| + expected_urls.push_back(IPUrlInfo(url, "", "", ResourceType::OBJECT)); |
| + UpdateIPUrlMap("250.10.10.10", url); |
| + } |
| + ASSERT_EQ(1U, browse_info->ips.size()); |
| + ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size()); |
| + CheckIPUrlEqual(expected_urls, |
| + browse_info->ips["250.10.10.10"]); |
| + |
| + // Add more urls for this ip, it exceeds max limit and won't be added |
| + UpdateIPUrlMap("250.10.10.10", "http://21.com/"); |
| + ASSERT_EQ(1U, browse_info->ips.size()); |
| + ASSERT_EQ(20U, browse_info->ips["250.10.10.10"].size()); |
| + CheckIPUrlEqual(expected_urls, |
| + browse_info->ips["250.10.10.10"]); |
| + |
| + // Add 199 more IPs |
| + for (int i = 0; i < 199; i++) { |
| + std::string ip = base::StringPrintf("%d.%d.%d.256", i, i, i); |
| + expected_urls.clear(); |
| + expected_urls.push_back(IPUrlInfo("test.com/", "", "", |
| + ResourceType::OBJECT)); |
| + UpdateIPUrlMap(ip, "test.com/"); |
| + ASSERT_EQ(1U, browse_info->ips[ip].size()); |
| + CheckIPUrlEqual(expected_urls, |
| + browse_info->ips[ip]); |
| + } |
| + ASSERT_EQ(200U, browse_info->ips.size()); |
| + |
| + // Exceeding max ip limit 200, these won't be added |
| + UpdateIPUrlMap("250.250.250.250", "goo.com/"); |
| + UpdateIPUrlMap("250.250.250.250", "bar.com/"); |
| + UpdateIPUrlMap("250.250.0.250", "foo.com/"); |
| + ASSERT_EQ(200U, browse_info->ips.size()); |
| + |
| + // Add url to existing IPs succeed |
| + UpdateIPUrlMap("100.100.100.256", "more.com/"); |
| + ASSERT_EQ(2U, browse_info->ips["100.100.100.256"].size()); |
| + expected_urls.clear(); |
| + expected_urls.push_back(IPUrlInfo("test.com/", "", "", ResourceType::OBJECT)); |
| + expected_urls.push_back(IPUrlInfo("more.com/", "", "", ResourceType::OBJECT)); |
| + CheckIPUrlEqual(expected_urls, |
| + browse_info->ips["100.100.100.256"]); |
| +} |
| + |
| TEST_F(ClientSideDetectionHostTest, NavigationCancelsShouldClassifyUrl) { |
| // Test that canceling pending should classify requests works as expected. |
| @@ -1034,6 +942,7 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| EXPECT_EQ(url, actual_url.a); |
| EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| process()->sink().ClearMessages(); |
| + ExpectShouldClassifyForMalwareResult(&kTrue); |
| // Now try an in-page navigation. This should not trigger an IPC. |
| EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0); |
| @@ -1063,6 +972,7 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| EXPECT_EQ(url, actual_url.a); |
| EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| process()->sink().ClearMessages(); |
| + ExpectShouldClassifyForMalwareResult(&kTrue); |
| // Navigate to a new host, which should cause another IPC. |
| url = GURL("http://host2.com/"); |
| @@ -1077,28 +987,34 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| EXPECT_EQ(url, actual_url.a); |
| EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| process()->sink().ClearMessages(); |
| + ExpectShouldClassifyForMalwareResult(&kTrue); |
| - // If the mime type is not one that we support, no IPC should be triggered. |
| + // If the mime type is not one that we support, no IPC should be triggered |
| + // but all pre-classification checks should run because we might classify |
| + // other mime types for malware. |
| // Note: for this test to work correctly, the new URL must be on the |
| // same domain as the previous URL, otherwise it will create a new |
| // RenderViewHost that won't have the mime type set. |
| url = GURL("http://host2.com/image.jpg"); |
| rvh_tester()->SetContentsMimeType("image/jpeg"); |
| - ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); |
| + ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
| + &kFalse,&kFalse); |
| NavigateAndCommit(url); |
| WaitAndCheckPreClassificationChecks(); |
| msg = process()->sink().GetFirstMessageMatching( |
| SafeBrowsingMsg_StartPhishingDetection::ID); |
| ASSERT_FALSE(msg); |
| + ExpectShouldClassifyForMalwareResult(&kTrue); |
| // If IsPrivateIPAddress returns true, no IPC should be triggered. |
| url = GURL("http://host3.com/"); |
| - ExpectPreClassificationChecks(url, &kTrue, NULL, NULL, NULL, NULL, NULL); |
| + ExpectPreClassificationChecks(url, &kTrue, &kFalse, NULL, NULL, NULL, NULL); |
| NavigateAndCommit(url); |
| WaitAndCheckPreClassificationChecks(); |
| msg = process()->sink().GetFirstMessageMatching( |
| SafeBrowsingMsg_StartPhishingDetection::ID); |
| ASSERT_FALSE(msg); |
| + ExpectShouldClassifyForMalwareResult(&kFalse); |
| // If the tab is incognito there should be no IPC. Also, we shouldn't |
| // even check the csd-whitelist. |
| @@ -1109,6 +1025,7 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| msg = process()->sink().GetFirstMessageMatching( |
| SafeBrowsingMsg_StartPhishingDetection::ID); |
| ASSERT_FALSE(msg); |
| + ExpectShouldClassifyForMalwareResult(&kFalse); |
| // If the URL is on the csd whitelist, no IPC should be triggered. |
| url = GURL("http://host5.com/"); |
| @@ -1119,6 +1036,7 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| msg = process()->sink().GetFirstMessageMatching( |
| SafeBrowsingMsg_StartPhishingDetection::ID); |
| ASSERT_FALSE(msg); |
| + ExpectShouldClassifyForMalwareResult(&kFalse); |
| // If item is in the cache but it isn't valid, we will classify regardless |
| // of whether we are over the reporting limit. |
| @@ -1134,6 +1052,7 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| EXPECT_EQ(url, actual_url.a); |
| EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); |
| process()->sink().ClearMessages(); |
| + ExpectShouldClassifyForMalwareResult(&kTrue); |
| // If the url isn't in the cache and we are over the reporting limit, we |
| // don't do classification. |
| @@ -1145,12 +1064,13 @@ TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { |
| msg = process()->sink().GetFirstMessageMatching( |
| SafeBrowsingMsg_StartPhishingDetection::ID); |
| ASSERT_FALSE(msg); |
| + ExpectShouldClassifyForMalwareResult(&kTrue); |
| // If result is cached, we will try and display the blocking page directly |
| // with no start classification message. |
| url = GURL("http://host8.com/"); |
| - ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL, |
| - NULL); |
| + ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, &kFalse, |
| + &kFalse); |
| UnsafeResource resource; |
| EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)) |