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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 MOCK_METHOD2(SendClientReportPhishingRequest, | 116 MOCK_METHOD2(SendClientReportPhishingRequest, |
117 void(ClientPhishingRequest*, | 117 void(ClientPhishingRequest*, |
118 const ClientReportPhishingRequestCallback&)); | 118 const ClientReportPhishingRequestCallback&)); |
119 MOCK_METHOD2(SendClientReportMalwareRequest, | 119 MOCK_METHOD2(SendClientReportMalwareRequest, |
120 void(ClientMalwareRequest*, | 120 void(ClientMalwareRequest*, |
121 const ClientReportMalwareRequestCallback&)); | 121 const ClientReportMalwareRequestCallback&)); |
122 MOCK_CONST_METHOD1(IsPrivateIPAddress, bool(const std::string&)); | 122 MOCK_CONST_METHOD1(IsPrivateIPAddress, bool(const std::string&)); |
123 MOCK_METHOD2(GetValidCachedResult, bool(const GURL&, bool*)); | 123 MOCK_METHOD2(GetValidCachedResult, bool(const GURL&, bool*)); |
124 MOCK_METHOD1(IsInCache, bool(const GURL&)); | 124 MOCK_METHOD1(IsInCache, bool(const GURL&)); |
125 MOCK_METHOD0(OverPhishingReportLimit, bool()); | 125 MOCK_METHOD0(OverPhishingReportLimit, bool()); |
126 MOCK_METHOD0(OverMalwareReportLimit, bool()); | |
126 | 127 |
127 private: | 128 private: |
128 DISALLOW_COPY_AND_ASSIGN(MockClientSideDetectionService); | 129 DISALLOW_COPY_AND_ASSIGN(MockClientSideDetectionService); |
129 }; | 130 }; |
130 | 131 |
131 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { | 132 class MockSafeBrowsingUIManager : public SafeBrowsingUIManager { |
132 public: | 133 public: |
133 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service) | 134 explicit MockSafeBrowsingUIManager(SafeBrowsingService* service) |
134 : SafeBrowsingUIManager(service) { } | 135 : SafeBrowsingUIManager(service) { } |
135 | 136 |
(...skipping 16 matching lines...) Expand all Loading... | |
152 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); | 153 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); |
153 }; | 154 }; |
154 | 155 |
155 class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { | 156 class MockSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { |
156 public: | 157 public: |
157 explicit MockSafeBrowsingDatabaseManager(SafeBrowsingService* service) | 158 explicit MockSafeBrowsingDatabaseManager(SafeBrowsingService* service) |
158 : SafeBrowsingDatabaseManager(service) { } | 159 : SafeBrowsingDatabaseManager(service) { } |
159 | 160 |
160 MOCK_METHOD1(MatchCsdWhitelistUrl, bool(const GURL&)); | 161 MOCK_METHOD1(MatchCsdWhitelistUrl, bool(const GURL&)); |
161 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); | 162 MOCK_METHOD1(MatchMalwareIP, bool(const std::string& ip_address)); |
163 MOCK_METHOD0(IsMalwareKillSwitchOn, bool()); | |
162 | 164 |
163 protected: | 165 protected: |
164 virtual ~MockSafeBrowsingDatabaseManager() {} | 166 virtual ~MockSafeBrowsingDatabaseManager() {} |
165 | 167 |
166 private: | 168 private: |
167 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); | 169 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); |
168 }; | 170 }; |
169 | 171 |
170 class MockTestingProfile : public TestingProfile { | 172 class MockTestingProfile : public TestingProfile { |
171 public: | 173 public: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 new StrictMock<MockSafeBrowsingDatabaseManager>(sb_service); | 214 new StrictMock<MockSafeBrowsingDatabaseManager>(sb_service); |
213 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>(sb_service); | 215 ui_manager_ = new StrictMock<MockSafeBrowsingUIManager>(sb_service); |
214 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( | 216 csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create( |
215 web_contents())); | 217 web_contents())); |
216 csd_host_->set_client_side_detection_service(csd_service_.get()); | 218 csd_host_->set_client_side_detection_service(csd_service_.get()); |
217 csd_host_->set_safe_browsing_managers(ui_manager_.get(), | 219 csd_host_->set_safe_browsing_managers(ui_manager_.get(), |
218 database_manager_.get()); | 220 database_manager_.get()); |
219 // We need to create this here since we don't call | 221 // We need to create this here since we don't call |
220 // DidNavigateMainFramePostCommit in this test. | 222 // DidNavigateMainFramePostCommit in this test. |
221 csd_host_->browse_info_.reset(new BrowseInfo); | 223 csd_host_->browse_info_.reset(new BrowseInfo); |
222 | |
223 // By default this is set to false. Turn it on as if we are in canary or | |
224 // dev channel | |
225 csd_host_->malware_report_enabled_ = true; | |
226 } | 224 } |
227 | 225 |
228 virtual void TearDown() { | 226 virtual void TearDown() { |
229 // Delete the host object on the UI thread and release the | 227 // Delete the host object on the UI thread and release the |
230 // SafeBrowsingService. | 228 // SafeBrowsingService. |
231 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, | 229 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, |
232 csd_host_.release()); | 230 csd_host_.release()); |
233 database_manager_ = NULL; | 231 database_manager_ = NULL; |
234 ui_manager_ = NULL; | 232 ui_manager_ = NULL; |
235 base::RunLoop().RunUntilIdle(); | 233 base::RunLoop().RunUntilIdle(); |
236 ChromeRenderViewHostTestHarness::TearDown(); | 234 ChromeRenderViewHostTestHarness::TearDown(); |
237 } | 235 } |
238 | 236 |
239 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE { | 237 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE { |
240 // Set custom profile object so that we can mock calls to IsOffTheRecord. | 238 // Set custom profile object so that we can mock calls to IsOffTheRecord. |
241 // This needs to happen before we call the parent SetUp() function. We use | 239 // This needs to happen before we call the parent SetUp() function. We use |
242 // a nice mock because other parts of the code are calling IsOffTheRecord. | 240 // a nice mock because other parts of the code are calling IsOffTheRecord. |
243 mock_profile_ = new NiceMock<MockTestingProfile>(); | 241 mock_profile_ = new NiceMock<MockTestingProfile>(); |
244 return mock_profile_; | 242 return mock_profile_; |
245 } | 243 } |
246 | 244 |
247 void OnPhishingDetectionDone(const std::string& verdict_str) { | 245 void OnPhishingDetectionDone(const std::string& verdict_str) { |
248 csd_host_->OnPhishingDetectionDone(verdict_str); | 246 csd_host_->OnPhishingDetectionDone(verdict_str); |
249 } | 247 } |
250 | 248 |
249 void DocumentOnLoadCompletedInMainFrame(int32 page_id) { | |
250 csd_host_->DocumentOnLoadCompletedInMainFrame(page_id); | |
251 } | |
252 | |
251 void UpdateIPUrlMap(const std::string& ip, const std::string& host) { | 253 void UpdateIPUrlMap(const std::string& ip, const std::string& host) { |
252 csd_host_->UpdateIPUrlMap(ip, host, "", "", ResourceType::OBJECT); | 254 csd_host_->UpdateIPUrlMap(ip, host, "", "", ResourceType::OBJECT); |
253 } | 255 } |
254 | 256 |
255 BrowseInfo* GetBrowseInfo() { | 257 BrowseInfo* GetBrowseInfo() { |
256 return csd_host_->browse_info_.get(); | 258 return csd_host_->browse_info_.get(); |
257 } | 259 } |
258 | 260 |
259 void ExpectPreClassificationChecks(const GURL& url, | 261 void ExpectPreClassificationChecks(const GURL& url, |
260 const bool* is_private, | 262 const bool* is_private, |
261 const bool* is_incognito, | 263 const bool* is_incognito, |
262 const bool* match_csd_whitelist, | 264 const bool* match_csd_whitelist, |
265 const bool* malware_killswitch, | |
263 const bool* get_valid_cached_result, | 266 const bool* get_valid_cached_result, |
264 const bool* is_in_cache, | 267 const bool* is_in_cache, |
265 const bool* over_report_limit) { | 268 const bool* over_phishing_report_limit, |
269 const bool* over_malware_report_limit) { | |
266 if (is_private) { | 270 if (is_private) { |
267 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) | 271 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) |
268 .WillOnce(Return(*is_private)); | 272 .WillOnce(Return(*is_private)); |
269 } | 273 } |
270 if (is_incognito) { | 274 if (is_incognito) { |
271 EXPECT_CALL(*mock_profile_, IsOffTheRecord()) | 275 EXPECT_CALL(*mock_profile_, IsOffTheRecord()) |
272 .WillRepeatedly(Return(*is_incognito)); | 276 .WillRepeatedly(Return(*is_incognito)); |
273 } | 277 } |
274 if (match_csd_whitelist) { | 278 if (match_csd_whitelist) { |
275 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(url)) | 279 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(url)) |
276 .WillOnce(Return(*match_csd_whitelist)); | 280 .WillOnce(Return(*match_csd_whitelist)); |
277 } | 281 } |
282 if (malware_killswitch) { | |
283 EXPECT_CALL(*database_manager_.get(), IsMalwareKillSwitchOn()) | |
284 .WillRepeatedly(Return(*malware_killswitch)); | |
285 } | |
278 if (get_valid_cached_result) { | 286 if (get_valid_cached_result) { |
279 EXPECT_CALL(*csd_service_, GetValidCachedResult(url, NotNull())) | 287 EXPECT_CALL(*csd_service_, GetValidCachedResult(url, NotNull())) |
280 .WillOnce(DoAll(SetArgumentPointee<1>(true), | 288 .WillOnce(DoAll(SetArgumentPointee<1>(true), |
281 Return(*get_valid_cached_result))); | 289 Return(*get_valid_cached_result))); |
282 } | 290 } |
283 if (is_in_cache) { | 291 if (is_in_cache) { |
284 EXPECT_CALL(*csd_service_, IsInCache(url)).WillOnce(Return(*is_in_cache)); | 292 EXPECT_CALL(*csd_service_, IsInCache(url)).WillOnce(Return(*is_in_cache)); |
285 } | 293 } |
286 if (over_report_limit) { | 294 if (over_phishing_report_limit) { |
287 EXPECT_CALL(*csd_service_, OverPhishingReportLimit()) | 295 EXPECT_CALL(*csd_service_, OverPhishingReportLimit()) |
288 .WillOnce(Return(*over_report_limit)); | 296 .WillOnce(Return(*over_phishing_report_limit)); |
297 } | |
298 if (over_malware_report_limit) { | |
299 EXPECT_CALL(*csd_service_, OverMalwareReportLimit()) | |
300 .WillOnce(Return(*over_malware_report_limit)); | |
289 } | 301 } |
290 } | 302 } |
291 | 303 |
292 void WaitAndCheckPreClassificationChecks() { | 304 void WaitAndCheckPreClassificationChecks() { |
293 // Wait for CheckCsdWhitelist and CheckCache() to be called if at all. | 305 // Wait for CheckCsdWhitelist and CheckCache() to be called if at all. |
294 base::RunLoop().RunUntilIdle(); | 306 base::RunLoop().RunUntilIdle(); |
295 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 307 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
296 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 308 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
297 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); | 309 EXPECT_TRUE(Mock::VerifyAndClear(database_manager_.get())); |
298 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); | 310 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); |
299 } | 311 } |
300 | 312 |
301 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { | 313 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { |
302 csd_host_->feature_extractor_.reset(extractor); | 314 csd_host_->feature_extractor_.reset(extractor); |
303 } | 315 } |
304 | 316 |
305 void SetRedirectChain(const std::vector<GURL>& redirect_chain) { | 317 void SetRedirectChain(const std::vector<GURL>& redirect_chain) { |
306 csd_host_->browse_info_->url_redirects = redirect_chain; | 318 csd_host_->browse_info_->url_redirects = redirect_chain; |
307 } | 319 } |
308 | 320 |
309 void SetReferrer(const GURL& referrer) { | 321 void SetReferrer(const GURL& referrer) { |
310 csd_host_->browse_info_->referrer = referrer; | 322 csd_host_->browse_info_->referrer = referrer; |
311 } | 323 } |
312 | 324 |
325 void ExpectShouldClassifyForMalwareResult(bool should_classify) { | |
326 EXPECT_EQ(should_classify, csd_host_->should_classify_for_malware_); | |
327 } | |
328 | |
329 void ExpectStartPhishingDetection(const GURL* url) { | |
330 const IPC::Message* msg = process()->sink().GetFirstMessageMatching( | |
331 SafeBrowsingMsg_StartPhishingDetection::ID); | |
332 if (url) { | |
333 ASSERT_TRUE(msg); | |
334 Tuple1<GURL> actual_url; | |
335 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | |
336 EXPECT_EQ(*url, actual_url.a); | |
337 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | |
338 process()->sink().ClearMessages(); | |
339 } else { | |
340 ASSERT_FALSE(msg); | |
341 } | |
342 } | |
343 | |
313 void TestUnsafeResourceCopied(const UnsafeResource& resource) { | 344 void TestUnsafeResourceCopied(const UnsafeResource& resource) { |
314 ASSERT_TRUE(csd_host_->unsafe_resource_.get()); | 345 ASSERT_TRUE(csd_host_->unsafe_resource_.get()); |
315 // Test that the resource from OnSafeBrowsingHit notification was copied | 346 // Test that the resource from OnSafeBrowsingHit notification was copied |
316 // into the CSDH. | 347 // into the CSDH. |
317 EXPECT_EQ(resource.url, csd_host_->unsafe_resource_->url); | 348 EXPECT_EQ(resource.url, csd_host_->unsafe_resource_->url); |
318 EXPECT_EQ(resource.original_url, csd_host_->unsafe_resource_->original_url); | 349 EXPECT_EQ(resource.original_url, csd_host_->unsafe_resource_->original_url); |
319 EXPECT_EQ(resource.is_subresource, | 350 EXPECT_EQ(resource.is_subresource, |
320 csd_host_->unsafe_resource_->is_subresource); | 351 csd_host_->unsafe_resource_->is_subresource); |
321 EXPECT_EQ(resource.threat_type, csd_host_->unsafe_resource_->threat_type); | 352 EXPECT_EQ(resource.threat_type, csd_host_->unsafe_resource_->threat_type); |
322 EXPECT_TRUE(csd_host_->unsafe_resource_->callback.is_null()); | 353 EXPECT_TRUE(csd_host_->unsafe_resource_->callback.is_null()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 web_contents(), | 474 web_contents(), |
444 csd_host_.get()); | 475 csd_host_.get()); |
445 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 476 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
446 | 477 |
447 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 478 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
448 ClientPhishingRequest verdict; | 479 ClientPhishingRequest verdict; |
449 verdict.set_url("http://phishingurl.com/"); | 480 verdict.set_url("http://phishingurl.com/"); |
450 verdict.set_client_score(1.0f); | 481 verdict.set_client_score(1.0f); |
451 verdict.set_is_phishing(true); | 482 verdict.set_is_phishing(true); |
452 | 483 |
453 ClientMalwareRequest malware_verdict; | |
454 malware_verdict.set_url(verdict.url()); | |
455 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 484 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
456 .WillOnce(DoAll(DeleteArg<1>(), | 485 .WillOnce(DoAll(DeleteArg<1>(), |
457 InvokeCallbackArgument<2>(true, &verdict))); | 486 InvokeCallbackArgument<2>(true, &verdict))); |
458 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
459 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
460 EXPECT_CALL(*csd_service_, | 487 EXPECT_CALL(*csd_service_, |
461 SendClientReportPhishingRequest( | 488 SendClientReportPhishingRequest( |
462 Pointee(PartiallyEqualVerdict(verdict)), _)) | 489 Pointee(PartiallyEqualVerdict(verdict)), _)) |
463 .WillOnce(SaveArg<1>(&cb)); | 490 .WillOnce(SaveArg<1>(&cb)); |
464 OnPhishingDetectionDone(verdict.SerializeAsString()); | 491 OnPhishingDetectionDone(verdict.SerializeAsString()); |
465 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 492 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
466 ASSERT_FALSE(cb.is_null()); | 493 ASSERT_FALSE(cb.is_null()); |
467 | 494 |
468 // Make sure DisplayBlockingPage is not going to be called. | 495 // Make sure DisplayBlockingPage is not going to be called. |
469 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0); | 496 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0); |
(...skipping 17 matching lines...) Expand all Loading... | |
487 verdict.set_client_score(1.0f); | 514 verdict.set_client_score(1.0f); |
488 verdict.set_is_phishing(true); | 515 verdict.set_is_phishing(true); |
489 | 516 |
490 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 517 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
491 .WillOnce(DoAll(DeleteArg<1>(), | 518 .WillOnce(DoAll(DeleteArg<1>(), |
492 InvokeCallbackArgument<2>(true, &verdict))); | 519 InvokeCallbackArgument<2>(true, &verdict))); |
493 EXPECT_CALL(*csd_service_, | 520 EXPECT_CALL(*csd_service_, |
494 SendClientReportPhishingRequest( | 521 SendClientReportPhishingRequest( |
495 Pointee(PartiallyEqualVerdict(verdict)), _)) | 522 Pointee(PartiallyEqualVerdict(verdict)), _)) |
496 .WillOnce(SaveArg<1>(&cb)); | 523 .WillOnce(SaveArg<1>(&cb)); |
497 | |
498 ClientMalwareRequest malware_verdict; | |
499 malware_verdict.set_url(verdict.url()); | |
500 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
501 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
502 EXPECT_CALL(*csd_service_, | |
503 SendClientReportMalwareRequest(_, _)).Times(0); | |
504 | |
505 OnPhishingDetectionDone(verdict.SerializeAsString()); | 524 OnPhishingDetectionDone(verdict.SerializeAsString()); |
506 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 525 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
507 ASSERT_FALSE(cb.is_null()); | 526 ASSERT_FALSE(cb.is_null()); |
508 | 527 |
509 // Make sure DisplayBlockingPage is not going to be called. | 528 // Make sure DisplayBlockingPage is not going to be called. |
510 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0); | 529 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)).Times(0); |
511 cb.Run(GURL(verdict.url()), false); | 530 cb.Run(GURL(verdict.url()), false); |
512 base::RunLoop().RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
513 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 532 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
514 } | 533 } |
515 | 534 |
516 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { | 535 TEST_F(ClientSideDetectionHostTest, OnPhishingDetectionDoneShowInterstitial) { |
517 // Case 3: client thinks the page is phishing and so does the server. | 536 // Case 3: client thinks the page is phishing and so does the server. |
518 // We show an interstitial. | 537 // We show an interstitial. |
519 MockBrowserFeatureExtractor* mock_extractor = | 538 MockBrowserFeatureExtractor* mock_extractor = |
520 new StrictMock<MockBrowserFeatureExtractor>( | 539 new StrictMock<MockBrowserFeatureExtractor>( |
521 web_contents(), | 540 web_contents(), |
522 csd_host_.get()); | 541 csd_host_.get()); |
523 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 542 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
524 | 543 |
525 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 544 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
526 GURL phishing_url("http://phishingurl.com/"); | 545 GURL phishing_url("http://phishingurl.com/"); |
527 ClientPhishingRequest verdict; | 546 ClientPhishingRequest verdict; |
528 verdict.set_url(phishing_url.spec()); | 547 verdict.set_url(phishing_url.spec()); |
529 verdict.set_client_score(1.0f); | 548 verdict.set_client_score(1.0f); |
530 verdict.set_is_phishing(true); | 549 verdict.set_is_phishing(true); |
531 | 550 |
532 ClientMalwareRequest malware_verdict; | |
533 malware_verdict.set_url(verdict.url()); | |
534 | |
535 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 551 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
536 .WillOnce(DoAll(DeleteArg<1>(), | 552 .WillOnce(DoAll(DeleteArg<1>(), |
537 InvokeCallbackArgument<2>(true, &verdict))); | 553 InvokeCallbackArgument<2>(true, &verdict))); |
538 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
539 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
540 EXPECT_CALL(*csd_service_, | 554 EXPECT_CALL(*csd_service_, |
541 SendClientReportPhishingRequest( | 555 SendClientReportPhishingRequest( |
542 Pointee(PartiallyEqualVerdict(verdict)), _)) | 556 Pointee(PartiallyEqualVerdict(verdict)), _)) |
543 .WillOnce(SaveArg<1>(&cb)); | 557 .WillOnce(SaveArg<1>(&cb)); |
544 OnPhishingDetectionDone(verdict.SerializeAsString()); | 558 OnPhishingDetectionDone(verdict.SerializeAsString()); |
545 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 559 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
546 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 560 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
547 ASSERT_FALSE(cb.is_null()); | 561 ASSERT_FALSE(cb.is_null()); |
548 | 562 |
549 UnsafeResource resource; | 563 UnsafeResource resource; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 csd_host_.get()); | 596 csd_host_.get()); |
583 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 597 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
584 | 598 |
585 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | 599 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; |
586 GURL phishing_url("http://phishingurl.com/"); | 600 GURL phishing_url("http://phishingurl.com/"); |
587 ClientPhishingRequest verdict; | 601 ClientPhishingRequest verdict; |
588 verdict.set_url(phishing_url.spec()); | 602 verdict.set_url(phishing_url.spec()); |
589 verdict.set_client_score(1.0f); | 603 verdict.set_client_score(1.0f); |
590 verdict.set_is_phishing(true); | 604 verdict.set_is_phishing(true); |
591 | 605 |
592 ClientMalwareRequest malware_verdict; | |
593 malware_verdict.set_url(verdict.url()); | |
594 | |
595 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | 606 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) |
596 .WillOnce(DoAll(DeleteArg<1>(), | 607 .WillOnce(DoAll(DeleteArg<1>(), |
597 InvokeCallbackArgument<2>(true, &verdict))); | 608 InvokeCallbackArgument<2>(true, &verdict))); |
598 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
599 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
600 EXPECT_CALL(*csd_service_, | 609 EXPECT_CALL(*csd_service_, |
601 SendClientReportPhishingRequest( | 610 SendClientReportPhishingRequest( |
602 Pointee(PartiallyEqualVerdict(verdict)), _)) | 611 Pointee(PartiallyEqualVerdict(verdict)), _)) |
603 .WillOnce(SaveArg<1>(&cb)); | 612 .WillOnce(SaveArg<1>(&cb)); |
604 OnPhishingDetectionDone(verdict.SerializeAsString()); | 613 OnPhishingDetectionDone(verdict.SerializeAsString()); |
605 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 614 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
606 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 615 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
607 ASSERT_FALSE(cb.is_null()); | 616 ASSERT_FALSE(cb.is_null()); |
608 | 617 |
609 // 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 |
610 // NavigateAndCommit() and it's easier to use the real thing than setting up | 619 // NavigateAndCommit() and it's easier to use the real thing than setting up |
611 // mock expectations. | 620 // mock expectations. |
612 SetFeatureExtractor(new BrowserFeatureExtractor(web_contents(), | 621 SetFeatureExtractor(new BrowserFeatureExtractor(web_contents(), |
613 csd_host_.get())); | 622 csd_host_.get())); |
614 GURL other_phishing_url("http://other_phishing_url.com/bla"); | 623 GURL other_phishing_url("http://other_phishing_url.com/bla"); |
615 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, | 624 ExpectPreClassificationChecks(other_phishing_url, &kFalse, &kFalse, &kFalse, |
616 &kFalse, &kFalse, &kFalse); | 625 &kFalse, &kFalse, &kFalse, &kFalse, &kFalse); |
617 // We navigate away. The callback cb should be revoked. | 626 // We navigate away. The callback cb should be revoked. |
618 NavigateAndCommit(other_phishing_url); | 627 NavigateAndCommit(other_phishing_url); |
619 // Wait for the pre-classification checks to finish for other_phishing_url. | 628 // Wait for the pre-classification checks to finish for other_phishing_url. |
620 WaitAndCheckPreClassificationChecks(); | 629 WaitAndCheckPreClassificationChecks(); |
621 | 630 |
622 ClientSideDetectionService::ClientReportPhishingRequestCallback cb_other; | 631 ClientSideDetectionService::ClientReportPhishingRequestCallback cb_other; |
623 verdict.set_url(other_phishing_url.spec()); | 632 verdict.set_url(other_phishing_url.spec()); |
624 verdict.set_client_score(0.8f); | 633 verdict.set_client_score(0.8f); |
625 EXPECT_CALL(*csd_service_, | 634 EXPECT_CALL(*csd_service_, |
626 SendClientReportPhishingRequest( | 635 SendClientReportPhishingRequest( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 new StrictMock<MockBrowserFeatureExtractor>( | 681 new StrictMock<MockBrowserFeatureExtractor>( |
673 web_contents(), | 682 web_contents(), |
674 csd_host_.get()); | 683 csd_host_.get()); |
675 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | 684 SetFeatureExtractor(mock_extractor); // The host class takes ownership. |
676 | 685 |
677 ClientPhishingRequest verdict; | 686 ClientPhishingRequest verdict; |
678 verdict.set_url("http://not-phishing.com/"); | 687 verdict.set_url("http://not-phishing.com/"); |
679 verdict.set_client_score(0.1f); | 688 verdict.set_client_score(0.1f); |
680 verdict.set_is_phishing(false); | 689 verdict.set_is_phishing(false); |
681 | 690 |
682 ClientMalwareRequest malware_verdict; | |
683 malware_verdict.set_url(verdict.url()); | |
684 | |
685 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | 691 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); |
686 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
687 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
688 OnPhishingDetectionDone(verdict.SerializeAsString()); | 692 OnPhishingDetectionDone(verdict.SerializeAsString()); |
689 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | 693 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); |
690 } | 694 } |
691 | 695 |
692 TEST_F(ClientSideDetectionHostTest, | 696 TEST_F(ClientSideDetectionHostTest, |
693 OnPhishingDetectionDoneVerdictNotPhishingButSBMatchSubResource) { | 697 OnPhishingDetectionDoneVerdictNotPhishingButSBMatchSubResource) { |
694 // Case 7: renderer sends a verdict string that isn't phishing but the URL | 698 // Case 7: renderer sends a verdict string that isn't phishing but the URL |
695 // of a subresource was on the regular phishing or malware lists. | 699 // of a subresource was on the regular phishing or malware lists. |
696 GURL url("http://not-phishing.com/"); | 700 GURL url("http://not-phishing.com/"); |
697 ClientPhishingRequest verdict; | 701 ClientPhishingRequest verdict; |
698 verdict.set_url(url.spec()); | 702 verdict.set_url(url.spec()); |
699 verdict.set_client_score(0.1f); | 703 verdict.set_client_score(0.1f); |
700 verdict.set_is_phishing(false); | 704 verdict.set_is_phishing(false); |
701 | 705 |
702 // First we have to navigate to the URL to set the unique page ID. | 706 // First we have to navigate to the URL to set the unique page ID. |
703 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 707 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
704 &kFalse, &kFalse); | 708 &kFalse, &kFalse, &kFalse, &kFalse); |
705 NavigateAndCommit(url); | 709 NavigateAndCommit(url); |
706 WaitAndCheckPreClassificationChecks(); | 710 WaitAndCheckPreClassificationChecks(); |
707 SetUnsafeSubResourceForCurrent(); | 711 SetUnsafeSubResourceForCurrent(); |
708 | 712 |
709 EXPECT_CALL(*csd_service_, | 713 EXPECT_CALL(*csd_service_, |
710 SendClientReportPhishingRequest( | 714 SendClientReportPhishingRequest( |
711 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 715 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
712 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 716 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
713 std::vector<GURL> redirect_chain; | 717 std::vector<GURL> redirect_chain; |
714 redirect_chain.push_back(url); | 718 redirect_chain.push_back(url); |
715 SetRedirectChain(redirect_chain); | 719 SetRedirectChain(redirect_chain); |
716 OnPhishingDetectionDone(verdict.SerializeAsString()); | 720 OnPhishingDetectionDone(verdict.SerializeAsString()); |
717 base::MessageLoop::current()->Run(); | 721 base::MessageLoop::current()->Run(); |
718 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 722 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
719 } | 723 } |
720 | 724 |
721 TEST_F(ClientSideDetectionHostTest, | 725 TEST_F(ClientSideDetectionHostTest, |
722 OnPhishingDetectionDoneVerdictNotPhishingButSBMatchOnNewRVH) { | 726 OnPhishingDetectionDoneVerdictNotPhishingButSBMatchOnNewRVH) { |
723 // When navigating to a different host (thus creating a pending RVH) which | 727 // When navigating to a different host (thus creating a pending RVH) which |
724 // matches regular malware list, and after navigation the renderer sends a | 728 // matches regular malware list, and after navigation the renderer sends a |
725 // verdict string that isn't phishing, we should still send the report. | 729 // verdict string that isn't phishing, we should still send the report. |
726 | 730 |
727 // Do an initial navigation to a safe host. | 731 // Do an initial navigation to a safe host. |
728 GURL start_url("http://safe.example.com/"); | 732 GURL start_url("http://safe.example.com/"); |
729 ExpectPreClassificationChecks( | 733 ExpectPreClassificationChecks( |
730 start_url, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse); | 734 start_url, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, |
735 &kFalse); | |
731 NavigateAndCommit(start_url); | 736 NavigateAndCommit(start_url); |
732 WaitAndCheckPreClassificationChecks(); | 737 WaitAndCheckPreClassificationChecks(); |
733 | 738 |
734 // Now navigate to a different host which will have a malware hit before the | 739 // Now navigate to a different host which will have a malware hit before the |
735 // navigation commits. | 740 // navigation commits. |
736 GURL url("http://malware-but-not-phishing.com/"); | 741 GURL url("http://malware-but-not-phishing.com/"); |
737 ClientPhishingRequest verdict; | 742 ClientPhishingRequest verdict; |
738 verdict.set_url(url.spec()); | 743 verdict.set_url(url.spec()); |
739 verdict.set_client_score(0.1f); | 744 verdict.set_client_score(0.1f); |
740 verdict.set_is_phishing(false); | 745 verdict.set_is_phishing(false); |
741 | 746 |
742 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 747 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
743 &kFalse, &kFalse); | 748 &kFalse, &kFalse, &kFalse, &kFalse); |
744 NavigateWithSBHitAndCommit(url); | 749 NavigateWithSBHitAndCommit(url); |
745 WaitAndCheckPreClassificationChecks(); | 750 WaitAndCheckPreClassificationChecks(); |
746 | 751 |
747 EXPECT_CALL(*csd_service_, | 752 EXPECT_CALL(*csd_service_, |
748 SendClientReportPhishingRequest( | 753 SendClientReportPhishingRequest( |
749 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) | 754 Pointee(PartiallyEqualVerdict(verdict)), CallbackIsNull())) |
750 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 755 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
751 std::vector<GURL> redirect_chain; | 756 std::vector<GURL> redirect_chain; |
752 redirect_chain.push_back(url); | 757 redirect_chain.push_back(url); |
753 SetRedirectChain(redirect_chain); | 758 SetRedirectChain(redirect_chain); |
754 OnPhishingDetectionDone(verdict.SerializeAsString()); | 759 OnPhishingDetectionDone(verdict.SerializeAsString()); |
755 base::MessageLoop::current()->Run(); | 760 base::MessageLoop::current()->Run(); |
756 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 761 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
757 | 762 |
758 ExpectPreClassificationChecks(start_url, &kFalse, &kFalse, &kFalse, &kFalse, | 763 ExpectPreClassificationChecks(start_url, &kFalse, &kFalse, &kFalse, &kFalse, |
759 &kFalse, &kFalse); | 764 &kFalse, &kFalse, &kFalse, &kFalse); |
760 NavigateWithoutSBHitAndCommit(start_url); | 765 NavigateWithoutSBHitAndCommit(start_url); |
761 WaitAndCheckPreClassificationChecks(); | 766 WaitAndCheckPreClassificationChecks(); |
762 } | 767 } |
763 | 768 |
769 TEST_F(ClientSideDetectionHostTest, | |
770 DocumentOnLoadCompletedInMainFrameShowMalwareInterstitial) { | |
771 // Case 9: client thinks the page match malware IP and so does the server. | |
772 // We show an sub-resource malware interstitial. | |
773 MockBrowserFeatureExtractor* mock_extractor = | |
774 new StrictMock<MockBrowserFeatureExtractor>( | |
775 web_contents(), | |
776 csd_host_.get()); | |
777 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | |
778 | |
779 GURL malware_landing_url("http://malware.com/"); | |
780 GURL malware_ip_url("http://badip.com"); | |
781 ClientMalwareRequest malware_verdict; | |
782 malware_verdict.set_url("http://malware.com/"); | |
783 ClientMalwareRequest::UrlInfo* badipurl = | |
784 malware_verdict.add_bad_ip_url_info(); | |
785 badipurl->set_ip("1.2.3.4"); | |
786 badipurl->set_url("http://badip.com"); | |
787 | |
788 ExpectPreClassificationChecks(GURL(malware_verdict.url()), &kFalse, &kFalse, | |
789 &kFalse, &kFalse, &kFalse, &kFalse, &kFalse, | |
790 &kFalse); | |
791 NavigateAndCommit(GURL(malware_verdict.url())); | |
792 WaitAndCheckPreClassificationChecks(); | |
793 | |
794 ClientSideDetectionService::ClientReportMalwareRequestCallback cb; | |
795 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
796 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
797 EXPECT_CALL(*csd_service_, | |
798 SendClientReportMalwareRequest( | |
799 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | |
800 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb))); | |
801 DocumentOnLoadCompletedInMainFrame(GetBrowseInfo()->page_id); | |
802 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | |
803 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | |
804 ASSERT_FALSE(cb.is_null()); | |
805 | |
806 UnsafeResource resource; | |
807 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)) | |
808 .WillOnce(SaveArg<0>(&resource)); | |
809 cb.Run(malware_landing_url, malware_ip_url, true); | |
810 | |
811 base::RunLoop().RunUntilIdle(); | |
812 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | |
813 EXPECT_EQ(malware_ip_url, resource.url); | |
814 EXPECT_EQ(malware_landing_url, resource.original_url); | |
815 EXPECT_TRUE(resource.is_subresource); | |
816 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, resource.threat_type); | |
817 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), | |
818 resource.render_process_host_id); | |
819 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), | |
820 resource.render_view_id); | |
821 | |
822 // Make sure the client object will be deleted. | |
823 BrowserThread::PostTask( | |
824 BrowserThread::IO, | |
825 FROM_HERE, | |
826 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | |
827 ui_manager_, resource.callback)); | |
828 } | |
829 | |
764 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { | 830 TEST_F(ClientSideDetectionHostTest, UpdateIPUrlMap) { |
765 BrowseInfo* browse_info = GetBrowseInfo(); | 831 BrowseInfo* browse_info = GetBrowseInfo(); |
766 | 832 |
767 // Empty IP or host are skipped | 833 // Empty IP or host are skipped |
768 UpdateIPUrlMap("250.10.10.10", std::string()); | 834 UpdateIPUrlMap("250.10.10.10", std::string()); |
769 ASSERT_EQ(0U, browse_info->ips.size()); | 835 ASSERT_EQ(0U, browse_info->ips.size()); |
770 UpdateIPUrlMap(std::string(), "http://google.com/a"); | 836 UpdateIPUrlMap(std::string(), "http://google.com/a"); |
771 ASSERT_EQ(0U, browse_info->ips.size()); | 837 ASSERT_EQ(0U, browse_info->ips.size()); |
772 UpdateIPUrlMap(std::string(), std::string()); | 838 UpdateIPUrlMap(std::string(), std::string()); |
773 ASSERT_EQ(0U, browse_info->ips.size()); | 839 ASSERT_EQ(0U, browse_info->ips.size()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 // Add url to existing IPs succeed | 878 // Add url to existing IPs succeed |
813 UpdateIPUrlMap("100.100.100.256", "more.com/"); | 879 UpdateIPUrlMap("100.100.100.256", "more.com/"); |
814 ASSERT_EQ(2U, browse_info->ips["100.100.100.256"].size()); | 880 ASSERT_EQ(2U, browse_info->ips["100.100.100.256"].size()); |
815 expected_urls.clear(); | 881 expected_urls.clear(); |
816 expected_urls.push_back(IPUrlInfo("test.com/", "", "", ResourceType::OBJECT)); | 882 expected_urls.push_back(IPUrlInfo("test.com/", "", "", ResourceType::OBJECT)); |
817 expected_urls.push_back(IPUrlInfo("more.com/", "", "", ResourceType::OBJECT)); | 883 expected_urls.push_back(IPUrlInfo("more.com/", "", "", ResourceType::OBJECT)); |
818 CheckIPUrlEqual(expected_urls, | 884 CheckIPUrlEqual(expected_urls, |
819 browse_info->ips["100.100.100.256"]); | 885 browse_info->ips["100.100.100.256"]); |
820 } | 886 } |
821 | 887 |
822 TEST_F(ClientSideDetectionHostTest, | |
823 OnPhishingDetectionDoneVerdictNotPhishingNotMalwareIP) { | |
824 // Case 7: renderer sends a verdict string that isn't phishing and not matches | |
825 // malware bad IP list | |
826 MockBrowserFeatureExtractor* mock_extractor = | |
827 new StrictMock<MockBrowserFeatureExtractor>( | |
828 web_contents(), | |
829 csd_host_.get()); | |
830 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | |
831 | |
832 ClientPhishingRequest verdict; | |
833 verdict.set_url("http://not-phishing.com/"); | |
834 verdict.set_client_score(0.1f); | |
835 verdict.set_is_phishing(false); | |
836 | |
837 ClientMalwareRequest malware_verdict; | |
838 malware_verdict.set_url(verdict.url()); | |
839 | |
840 // That is a special case. If there were no IP matches or if feature | |
841 // extraction failed the callback will delete the malware_verdict. | |
842 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
843 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
844 EXPECT_CALL(*csd_service_, | |
845 SendClientReportMalwareRequest(_, _)).Times(0); | |
846 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | |
847 | |
848 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
849 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | |
850 } | |
851 | |
852 TEST_F(ClientSideDetectionHostTest, | |
853 OnPhishingDetectionDoneVerdictNotPhishingButMalwareIP) { | |
854 // Case 8: renderer sends a verdict string that isn't phishing but matches | |
855 // malware bad IP list | |
856 MockBrowserFeatureExtractor* mock_extractor = | |
857 new StrictMock<MockBrowserFeatureExtractor>( | |
858 web_contents(), | |
859 csd_host_.get()); | |
860 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | |
861 | |
862 ClientPhishingRequest verdict; | |
863 verdict.set_url("http://not-phishing.com/"); | |
864 verdict.set_client_score(0.1f); | |
865 verdict.set_is_phishing(false); | |
866 | |
867 ClientMalwareRequest malware_verdict; | |
868 malware_verdict.set_url(verdict.url()); | |
869 malware_verdict.set_referrer_url("http://referrer.com/"); | |
870 ClientMalwareRequest::UrlInfo* badipurl = | |
871 malware_verdict.add_bad_ip_url_info(); | |
872 badipurl->set_ip("1.2.3.4"); | |
873 badipurl->set_url("badip.com"); | |
874 | |
875 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
876 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
877 EXPECT_CALL(*csd_service_, | |
878 SendClientReportMalwareRequest( | |
879 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | |
880 .WillOnce(DeleteArg<0>()); | |
881 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)).Times(0); | |
882 | |
883 SetReferrer(GURL("http://referrer.com/")); | |
884 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
885 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | |
886 } | |
887 | |
888 TEST_F(ClientSideDetectionHostTest, | |
889 OnPhishingDetectionDoneVerdictPhishingAndMalwareIP) { | |
890 // Case 9: renderer sends a verdict string that is phishing and matches | |
891 // malware bad IP list | |
892 MockBrowserFeatureExtractor* mock_extractor = | |
893 new StrictMock<MockBrowserFeatureExtractor>( | |
894 web_contents(), | |
895 csd_host_.get()); | |
896 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | |
897 | |
898 ClientSideDetectionService::ClientReportPhishingRequestCallback cb; | |
899 ClientPhishingRequest verdict; | |
900 verdict.set_url("http://not-phishing.com/"); | |
901 verdict.set_client_score(0.1f); | |
902 verdict.set_is_phishing(true); | |
903 | |
904 ClientMalwareRequest malware_verdict; | |
905 malware_verdict.set_url(verdict.url()); | |
906 ClientMalwareRequest::UrlInfo* badipurl = | |
907 malware_verdict.add_bad_ip_url_info(); | |
908 badipurl->set_ip("1.2.3.4"); | |
909 badipurl->set_url("badip.com"); | |
910 | |
911 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
912 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
913 EXPECT_CALL(*csd_service_, | |
914 SendClientReportMalwareRequest( | |
915 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | |
916 .WillOnce(DeleteArg<0>()); | |
917 | |
918 EXPECT_CALL(*mock_extractor, ExtractFeatures(_, _, _)) | |
919 .WillOnce(DoAll(DeleteArg<1>(), | |
920 InvokeCallbackArgument<2>(true, &verdict))); | |
921 | |
922 EXPECT_CALL(*csd_service_, | |
923 SendClientReportPhishingRequest( | |
924 Pointee(PartiallyEqualVerdict(verdict)), _)) | |
925 .WillOnce(SaveArg<1>(&cb)); | |
926 | |
927 // Referrer url using https won't be set and sent out. | |
928 SetReferrer(GURL("https://referrer.com/")); | |
929 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
930 EXPECT_TRUE(Mock::VerifyAndClear(mock_extractor)); | |
931 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | |
932 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | |
933 ASSERT_FALSE(cb.is_null()); | |
934 } | |
935 | |
936 TEST_F(ClientSideDetectionHostTest, | |
937 OnPhishingDetectionDoneShowMalwareInterstitial) { | |
938 // Case 10: client thinks the page match malware IP and so does the server. | |
939 // We show an sub-resource malware interstitial. | |
940 MockBrowserFeatureExtractor* mock_extractor = | |
941 new StrictMock<MockBrowserFeatureExtractor>( | |
942 web_contents(), | |
943 csd_host_.get()); | |
944 SetFeatureExtractor(mock_extractor); // The host class takes ownership. | |
945 | |
946 ClientPhishingRequest verdict; | |
947 verdict.set_url("http://not-phishing.com/"); | |
948 verdict.set_client_score(0.1f); | |
949 verdict.set_is_phishing(false); | |
950 | |
951 ClientSideDetectionService::ClientReportMalwareRequestCallback cb; | |
952 GURL malware_landing_url("http://malware.com/"); | |
953 GURL malware_ip_url("http://badip.com"); | |
954 ClientMalwareRequest malware_verdict; | |
955 malware_verdict.set_url("http://malware.com/"); | |
956 ClientMalwareRequest::UrlInfo* badipurl = | |
957 malware_verdict.add_bad_ip_url_info(); | |
958 badipurl->set_ip("1.2.3.4"); | |
959 badipurl->set_url("http://badip.com"); | |
960 | |
961 EXPECT_CALL(*mock_extractor, ExtractMalwareFeatures(_, _, _)) | |
962 .WillOnce(InvokeMalwareCallback(&malware_verdict)); | |
963 EXPECT_CALL(*csd_service_, | |
964 SendClientReportMalwareRequest( | |
965 Pointee(PartiallyEqualMalwareVerdict(malware_verdict)), _)) | |
966 .WillOnce(DoAll(DeleteArg<0>(), SaveArg<1>(&cb))); | |
967 OnPhishingDetectionDone(verdict.SerializeAsString()); | |
968 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | |
969 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | |
970 ASSERT_FALSE(cb.is_null()); | |
971 | |
972 UnsafeResource resource; | |
973 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)) | |
974 .WillOnce(SaveArg<0>(&resource)); | |
975 cb.Run(malware_landing_url, malware_ip_url, true); | |
976 | |
977 base::RunLoop().RunUntilIdle(); | |
978 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | |
979 EXPECT_EQ(malware_ip_url, resource.url); | |
980 EXPECT_EQ(malware_landing_url, resource.original_url); | |
981 EXPECT_TRUE(resource.is_subresource); | |
982 EXPECT_EQ(SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, resource.threat_type); | |
983 EXPECT_EQ(web_contents()->GetRenderProcessHost()->GetID(), | |
984 resource.render_process_host_id); | |
985 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), | |
986 resource.render_view_id); | |
987 | |
988 // Make sure the client object will be deleted. | |
989 BrowserThread::PostTask( | |
990 BrowserThread::IO, | |
991 FROM_HERE, | |
992 base::Bind(&MockSafeBrowsingUIManager::InvokeOnBlockingPageComplete, | |
993 ui_manager_, resource.callback)); | |
994 } | |
995 | |
996 TEST_F(ClientSideDetectionHostTest, NavigationCancelsShouldClassifyUrl) { | 888 TEST_F(ClientSideDetectionHostTest, NavigationCancelsShouldClassifyUrl) { |
997 // Test that canceling pending should classify requests works as expected. | 889 // Test that canceling pending should classify requests works as expected. |
998 | 890 |
999 GURL first_url("http://first.phishy.url.com"); | 891 GURL first_url("http://first.phishy.url.com"); |
1000 GURL second_url("http://second.url.com/"); | 892 GURL second_url("http://second.url.com/"); |
1001 // The first few checks are done synchronously so check that they have been | 893 // The first few checks are done synchronously so check that they have been |
1002 // done for the first URL, while the second URL has all the checks done. We | 894 // done for the first URL, while the second URL has all the checks done. We |
1003 // need to manually set up the IsPrivateIPAddress mock since if the same mock | 895 // need to manually set up the IsPrivateIPAddress mock since if the same mock |
1004 // expectation is specified twice, gmock will only use the last instance of | 896 // expectation is specified twice, gmock will only use the last instance of |
1005 // it, meaning the first will never be matched. | 897 // it, meaning the first will never be matched. |
1006 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) | 898 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)) |
1007 .WillOnce(Return(false)) | 899 .WillOnce(Return(false)) |
1008 .WillOnce(Return(false)); | 900 .WillOnce(Return(false)); |
1009 ExpectPreClassificationChecks(first_url, NULL, &kFalse, &kFalse, NULL, | 901 ExpectPreClassificationChecks(first_url, NULL, &kFalse, &kFalse, &kFalse, |
1010 NULL, NULL); | 902 NULL, NULL, NULL, NULL); |
1011 ExpectPreClassificationChecks(second_url, NULL, &kFalse, &kFalse, &kFalse, | 903 ExpectPreClassificationChecks(second_url, NULL, &kFalse, &kFalse, &kFalse, |
1012 &kFalse, &kFalse); | 904 &kFalse, &kFalse, &kFalse, &kFalse); |
1013 | 905 |
1014 NavigateAndCommit(first_url); | 906 NavigateAndCommit(first_url); |
1015 // Don't flush the message loop, as we want to navigate to a different | 907 // Don't flush the message loop, as we want to navigate to a different |
1016 // url before the final pre-classification checks are run. | 908 // url before the final pre-classification checks are run. |
1017 NavigateAndCommit(second_url); | 909 NavigateAndCommit(second_url); |
1018 WaitAndCheckPreClassificationChecks(); | 910 WaitAndCheckPreClassificationChecks(); |
1019 } | 911 } |
1020 | 912 |
1021 TEST_F(ClientSideDetectionHostTest, ShouldClassifyUrl) { | 913 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckPass) { |
1022 // Navigate the tab to a page. We should see a StartPhishingDetection IPC. | 914 // Navigate the tab to a page. We should see a StartPhishingDetection IPC. |
1023 GURL url("http://host.com/"); | 915 GURL url("http://host.com/"); |
1024 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 916 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
1025 &kFalse, &kFalse); | 917 &kFalse, &kFalse, &kFalse, &kFalse); |
1026 NavigateAndCommit(url); | 918 NavigateAndCommit(url); |
1027 WaitAndCheckPreClassificationChecks(); | 919 WaitAndCheckPreClassificationChecks(); |
1028 | 920 |
1029 const IPC::Message* msg = process()->sink().GetFirstMessageMatching( | 921 ExpectStartPhishingDetection(&url); |
1030 SafeBrowsingMsg_StartPhishingDetection::ID); | 922 ExpectShouldClassifyForMalwareResult(true); |
1031 ASSERT_TRUE(msg); | 923 } |
1032 Tuple1<GURL> actual_url; | 924 |
1033 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 925 TEST_F(ClientSideDetectionHostTest, |
1034 EXPECT_EQ(url, actual_url.a); | 926 TestPreClassificationCheckInPageNavigation) { |
1035 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | 927 GURL url("http://host.com/"); |
1036 process()->sink().ClearMessages(); | 928 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
929 &kFalse, &kFalse, &kFalse, &kFalse); | |
930 NavigateAndCommit(url); | |
931 WaitAndCheckPreClassificationChecks(); | |
932 | |
933 ExpectStartPhishingDetection(&url); | |
934 ExpectShouldClassifyForMalwareResult(true); | |
1037 | 935 |
1038 // Now try an in-page navigation. This should not trigger an IPC. | 936 // Now try an in-page navigation. This should not trigger an IPC. |
1039 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0); | 937 EXPECT_CALL(*csd_service_, IsPrivateIPAddress(_)).Times(0); |
1040 url = GURL("http://host.com/#foo"); | 938 GURL inpage("http://host.com/#foo"); |
1041 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); | 939 ExpectPreClassificationChecks(inpage, NULL, NULL, NULL, NULL, NULL, NULL, |
1042 NavigateAndCommit(url); | 940 NULL, NULL); |
1043 WaitAndCheckPreClassificationChecks(); | 941 NavigateAndCommit(inpage); |
1044 | 942 WaitAndCheckPreClassificationChecks(); |
1045 msg = process()->sink().GetFirstMessageMatching( | 943 |
1046 SafeBrowsingMsg_StartPhishingDetection::ID); | 944 ExpectStartPhishingDetection(NULL); |
1047 ASSERT_FALSE(msg); | 945 ExpectShouldClassifyForMalwareResult(true); |
1048 | 946 } |
947 | |
948 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckXHTML) { | |
1049 // Check that XHTML is supported, in addition to the default HTML type. | 949 // Check that XHTML is supported, in addition to the default HTML type. |
950 GURL url("http://host.com/xhtml"); | |
951 rvh_tester()->SetContentsMimeType("application/xhtml+xml"); | |
952 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
953 &kFalse, &kFalse, &kFalse, &kFalse); | |
954 NavigateAndCommit(url); | |
955 WaitAndCheckPreClassificationChecks(); | |
956 | |
957 ExpectStartPhishingDetection(&url); | |
958 ExpectShouldClassifyForMalwareResult(true); | |
959 } | |
960 | |
961 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckTwoNavigations) { | |
962 // Navigate to two hosts, which should cause two IPCs. | |
963 GURL url1("http://host1.com/"); | |
964 ExpectPreClassificationChecks(url1, &kFalse, &kFalse, &kFalse, &kFalse, | |
965 &kFalse, &kFalse, &kFalse, &kFalse); | |
966 NavigateAndCommit(url1); | |
967 WaitAndCheckPreClassificationChecks(); | |
968 | |
969 ExpectStartPhishingDetection(&url1); | |
970 ExpectShouldClassifyForMalwareResult(true); | |
971 | |
972 GURL url2("http://host2.com/"); | |
973 ExpectPreClassificationChecks(url2, &kFalse, &kFalse, &kFalse, &kFalse, | |
974 &kFalse, &kFalse, &kFalse, &kFalse); | |
975 NavigateAndCommit(url2); | |
976 WaitAndCheckPreClassificationChecks(); | |
977 | |
978 ExpectStartPhishingDetection(&url2); | |
979 ExpectShouldClassifyForMalwareResult(true); | |
980 } | |
981 | |
982 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckMimeType) { | |
983 // If the mime type is not one that we support, no IPC should be triggered | |
984 // but all pre-classification checks should run because we might classify | |
985 // other mime types for malware. | |
1050 // Note: for this test to work correctly, the new URL must be on the | 986 // Note: for this test to work correctly, the new URL must be on the |
1051 // same domain as the previous URL, otherwise it will create a new | 987 // same domain as the previous URL, otherwise it will create a new |
1052 // RenderViewHost that won't have the mime type set. | 988 // RenderViewHost that won't have the mime type set. |
1053 url = GURL("http://host.com/xhtml"); | 989 GURL url("http://host2.com/image.jpg"); |
1054 rvh_tester()->SetContentsMimeType("application/xhtml+xml"); | |
1055 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
1056 &kFalse, &kFalse); | |
1057 NavigateAndCommit(url); | |
1058 WaitAndCheckPreClassificationChecks(); | |
1059 msg = process()->sink().GetFirstMessageMatching( | |
1060 SafeBrowsingMsg_StartPhishingDetection::ID); | |
1061 ASSERT_TRUE(msg); | |
1062 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | |
1063 EXPECT_EQ(url, actual_url.a); | |
1064 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | |
1065 process()->sink().ClearMessages(); | |
1066 | |
1067 // Navigate to a new host, which should cause another IPC. | |
1068 url = GURL("http://host2.com/"); | |
1069 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
1070 &kFalse, &kFalse); | |
1071 NavigateAndCommit(url); | |
1072 WaitAndCheckPreClassificationChecks(); | |
1073 msg = process()->sink().GetFirstMessageMatching( | |
1074 SafeBrowsingMsg_StartPhishingDetection::ID); | |
1075 ASSERT_TRUE(msg); | |
1076 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | |
1077 EXPECT_EQ(url, actual_url.a); | |
1078 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | |
1079 process()->sink().ClearMessages(); | |
1080 | |
1081 // If the mime type is not one that we support, no IPC should be triggered. | |
1082 // Note: for this test to work correctly, the new URL must be on the | |
1083 // same domain as the previous URL, otherwise it will create a new | |
1084 // RenderViewHost that won't have the mime type set. | |
1085 url = GURL("http://host2.com/image.jpg"); | |
1086 rvh_tester()->SetContentsMimeType("image/jpeg"); | 990 rvh_tester()->SetContentsMimeType("image/jpeg"); |
1087 ExpectPreClassificationChecks(url, NULL, NULL, NULL, NULL, NULL, NULL); | 991 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
1088 NavigateAndCommit(url); | 992 &kFalse, &kFalse,&kFalse, &kFalse); |
1089 WaitAndCheckPreClassificationChecks(); | 993 NavigateAndCommit(url); |
1090 msg = process()->sink().GetFirstMessageMatching( | 994 WaitAndCheckPreClassificationChecks(); |
995 | |
996 ExpectStartPhishingDetection(NULL); | |
997 ExpectShouldClassifyForMalwareResult(true); | |
998 } | |
999 | |
1000 TEST_F(ClientSideDetectionHostTest, | |
1001 TestPreClassificationCheckPrivateIpAddress) { | |
1002 // If IsPrivateIPAddress returns true, no IPC should be triggered. | |
1003 GURL url("http://host3.com/"); | |
1004 ExpectPreClassificationChecks(url, &kTrue, &kFalse, NULL, NULL, NULL, NULL, | |
1005 NULL, NULL); | |
1006 NavigateAndCommit(url); | |
1007 WaitAndCheckPreClassificationChecks(); | |
1008 const IPC::Message* msg = process()->sink().GetFirstMessageMatching( | |
1091 SafeBrowsingMsg_StartPhishingDetection::ID); | 1009 SafeBrowsingMsg_StartPhishingDetection::ID); |
1092 ASSERT_FALSE(msg); | 1010 ASSERT_FALSE(msg); |
1093 | 1011 ExpectShouldClassifyForMalwareResult(false); |
1094 // If IsPrivateIPAddress returns true, no IPC should be triggered. | 1012 } |
1095 url = GURL("http://host3.com/"); | 1013 |
1096 ExpectPreClassificationChecks(url, &kTrue, NULL, NULL, NULL, NULL, NULL); | 1014 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckIncognito) { |
1097 NavigateAndCommit(url); | |
1098 WaitAndCheckPreClassificationChecks(); | |
1099 msg = process()->sink().GetFirstMessageMatching( | |
1100 SafeBrowsingMsg_StartPhishingDetection::ID); | |
1101 ASSERT_FALSE(msg); | |
1102 | |
1103 // If the tab is incognito there should be no IPC. Also, we shouldn't | 1015 // If the tab is incognito there should be no IPC. Also, we shouldn't |
1104 // even check the csd-whitelist. | 1016 // even check the csd-whitelist. |
1105 url = GURL("http://host4.com/"); | 1017 GURL url("http://host4.com/"); |
1106 ExpectPreClassificationChecks(url, &kFalse, &kTrue, NULL, NULL, NULL, NULL); | 1018 ExpectPreClassificationChecks(url, &kFalse, &kTrue, NULL, NULL, NULL, NULL, |
1107 NavigateAndCommit(url); | 1019 NULL, NULL); |
1108 WaitAndCheckPreClassificationChecks(); | 1020 NavigateAndCommit(url); |
1109 msg = process()->sink().GetFirstMessageMatching( | 1021 WaitAndCheckPreClassificationChecks(); |
1110 SafeBrowsingMsg_StartPhishingDetection::ID); | 1022 |
1111 ASSERT_FALSE(msg); | 1023 ExpectStartPhishingDetection(NULL); |
1112 | 1024 ExpectShouldClassifyForMalwareResult(false); |
1113 // If the URL is on the csd whitelist, no IPC should be triggered. | 1025 } |
1114 url = GURL("http://host5.com/"); | 1026 |
1115 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kTrue, NULL, NULL, | 1027 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckCsdWhitelist) { |
1116 NULL); | 1028 // If the URL is on the csd whitelist no phishing IPC should be sent |
1117 NavigateAndCommit(url); | 1029 // but we should classify the URL for malware. |
1118 WaitAndCheckPreClassificationChecks(); | 1030 GURL url("http://host5.com/"); |
1119 msg = process()->sink().GetFirstMessageMatching( | 1031 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kTrue, &kFalse, &kFalse, |
1120 SafeBrowsingMsg_StartPhishingDetection::ID); | 1032 &kFalse, &kFalse, &kFalse); |
1121 ASSERT_FALSE(msg); | 1033 NavigateAndCommit(url); |
1122 | 1034 WaitAndCheckPreClassificationChecks(); |
1035 | |
1036 ExpectStartPhishingDetection(NULL); | |
1037 ExpectShouldClassifyForMalwareResult(true); | |
1038 } | |
1039 | |
1040 TEST_F(ClientSideDetectionHostTest, | |
1041 TestPreClassificationCheckMalwareKillSwitch) { | |
1042 // If the malware killswitch is on we shouldn't classify the page for malware. | |
1043 GURL url("http://host5.com/kill-switch"); | |
1044 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, &kFalse, | |
1045 &kFalse, &kFalse, &kFalse); | |
1046 NavigateAndCommit(url); | |
1047 WaitAndCheckPreClassificationChecks(); | |
1048 | |
1049 ExpectStartPhishingDetection(&url); | |
1050 ExpectShouldClassifyForMalwareResult(false); | |
1051 } | |
1052 | |
1053 TEST_F(ClientSideDetectionHostTest, | |
1054 TestPreClassificationCheckKillswitchAndCsdWhitelist) { | |
1055 // If both the malware kill-swtich is on and the URL is on the csd whitelist, | |
1056 // we will leave pre-classification checks early. | |
1057 GURL url("http://host5.com/kill-switch-and-whitelisted"); | |
1058 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kTrue, &kTrue, NULL, | |
1059 NULL, NULL, NULL); | |
1060 NavigateAndCommit(url); | |
1061 WaitAndCheckPreClassificationChecks(); | |
1062 | |
1063 ExpectStartPhishingDetection(NULL); | |
1064 ExpectShouldClassifyForMalwareResult(false); | |
1065 } | |
1066 | |
1067 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckInvalidCache) { | |
1123 // If item is in the cache but it isn't valid, we will classify regardless | 1068 // If item is in the cache but it isn't valid, we will classify regardless |
1124 // of whether we are over the reporting limit. | 1069 // of whether we are over the reporting limit. |
1125 url = GURL("http://host6.com/"); | 1070 GURL url("http://host6.com/"); |
1126 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, &kTrue, | 1071 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
1127 NULL); | 1072 &kFalse, &kTrue, NULL, &kFalse); |
1128 NavigateAndCommit(url); | 1073 |
1129 WaitAndCheckPreClassificationChecks(); | 1074 NavigateAndCommit(url); |
1130 msg = process()->sink().GetFirstMessageMatching( | 1075 WaitAndCheckPreClassificationChecks(); |
1131 SafeBrowsingMsg_StartPhishingDetection::ID); | 1076 |
1132 ASSERT_TRUE(msg); | 1077 ExpectStartPhishingDetection(&url); |
1133 SafeBrowsingMsg_StartPhishingDetection::Read(msg, &actual_url); | 1078 ExpectShouldClassifyForMalwareResult(true); |
1134 EXPECT_EQ(url, actual_url.a); | 1079 } |
1135 EXPECT_EQ(rvh()->GetRoutingID(), msg->routing_id()); | 1080 |
1136 process()->sink().ClearMessages(); | 1081 TEST_F(ClientSideDetectionHostTest, |
1137 | 1082 TestPreClassificationCheckOverPhishingReportingLimit) { |
1138 // If the url isn't in the cache and we are over the reporting limit, we | 1083 // If the url isn't in the cache and we are over the reporting limit, we |
1139 // don't do classification. | 1084 // don't do classification. |
1140 url = GURL("http://host7.com/"); | 1085 GURL url("http://host7.com/"); |
1141 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 1086 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
1142 &kFalse, &kTrue); | 1087 &kFalse, &kFalse, &kTrue, &kFalse); |
1143 NavigateAndCommit(url); | 1088 NavigateAndCommit(url); |
1144 WaitAndCheckPreClassificationChecks(); | 1089 WaitAndCheckPreClassificationChecks(); |
1145 msg = process()->sink().GetFirstMessageMatching( | 1090 |
1146 SafeBrowsingMsg_StartPhishingDetection::ID); | 1091 ExpectStartPhishingDetection(NULL); |
1147 ASSERT_FALSE(msg); | 1092 ExpectShouldClassifyForMalwareResult(true); |
1148 | 1093 } |
1094 | |
1095 TEST_F(ClientSideDetectionHostTest, | |
1096 TestPreClassificationCheckOverMalwareReportingLimit) { | |
1097 GURL url("http://host.com/"); | |
1098 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
1099 &kFalse, &kFalse, &kFalse, &kTrue); | |
1100 NavigateAndCommit(url); | |
1101 WaitAndCheckPreClassificationChecks(); | |
1102 | |
1103 ExpectStartPhishingDetection(&url); | |
1104 ExpectShouldClassifyForMalwareResult(false); | |
1105 } | |
1106 | |
1107 TEST_F(ClientSideDetectionHostTest, | |
1108 TestPreClassificationCheckOverBothReportingLimits) { | |
1109 GURL url("http://host.com/"); | |
1110 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
1111 &kFalse, &kFalse, &kTrue, &kTrue); | |
1112 NavigateAndCommit(url); | |
1113 WaitAndCheckPreClassificationChecks(); | |
1114 | |
1115 ExpectStartPhishingDetection(NULL); | |
1116 ExpectShouldClassifyForMalwareResult(false); | |
1117 } | |
1118 | |
1119 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckHttpsUrl) { | |
1120 GURL url("https://host.com/"); | |
1121 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | |
1122 &kFalse, &kFalse, &kFalse, &kFalse); | |
1123 NavigateAndCommit(url); | |
1124 WaitAndCheckPreClassificationChecks(); | |
1125 | |
1126 ExpectStartPhishingDetection(NULL); | |
1127 ExpectShouldClassifyForMalwareResult(true); | |
1128 } | |
1129 | |
1130 TEST_F(ClientSideDetectionHostTest, TestPreClassificationCheckValidCached) { | |
1149 // If result is cached, we will try and display the blocking page directly | 1131 // If result is cached, we will try and display the blocking page directly |
1150 // with no start classification message. | 1132 // with no start classification message. |
1151 url = GURL("http://host8.com/"); | 1133 GURL url("http://host8.com/"); |
1152 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kTrue, NULL, | 1134 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, &kTrue, |
1153 NULL); | 1135 &kFalse, &kFalse, &kFalse); |
1154 | 1136 |
1155 UnsafeResource resource; | 1137 UnsafeResource resource; |
1156 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)) | 1138 EXPECT_CALL(*ui_manager_.get(), DisplayBlockingPage(_)) |
1157 .WillOnce(SaveArg<0>(&resource)); | 1139 .WillOnce(SaveArg<0>(&resource)); |
1158 | 1140 |
1159 NavigateAndCommit(url); | 1141 NavigateAndCommit(url); |
1160 // Wait for CheckCsdWhitelist and CheckCache() to be called. | 1142 WaitAndCheckPreClassificationChecks(); |
1161 base::RunLoop().RunUntilIdle(); | |
1162 // Now we check that all expected functions were indeed called on the two | 1143 // Now we check that all expected functions were indeed called on the two |
1163 // service objects. | 1144 // service objects. |
1164 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); | 1145 EXPECT_TRUE(Mock::VerifyAndClear(csd_host_.get())); |
1165 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); | 1146 EXPECT_TRUE(Mock::VerifyAndClear(ui_manager_.get())); |
mattm
2014/03/21 01:15:22
WaitAndCheckPreClassificationChecks already does V
noé
2014/03/21 04:32:36
Done.
| |
1166 EXPECT_EQ(url, resource.url); | 1147 EXPECT_EQ(url, resource.url); |
1167 EXPECT_EQ(url, resource.original_url); | 1148 EXPECT_EQ(url, resource.original_url); |
1168 resource.callback.Reset(); | 1149 |
1169 msg = process()->sink().GetFirstMessageMatching( | 1150 ExpectStartPhishingDetection(NULL); |
1170 SafeBrowsingMsg_StartPhishingDetection::ID); | 1151 |
1171 ASSERT_FALSE(msg); | 1152 // Showing a phishing warning will invalidate all the weak pointers which |
1153 // means we will not extract malware features. | |
1154 ExpectShouldClassifyForMalwareResult(false); | |
1172 } | 1155 } |
1173 } // namespace safe_browsing | 1156 } // namespace safe_browsing |
OLD | NEW |