OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_path.h" | 5 #include "base/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/task.h" | 8 #include "base/task.h" |
9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 9 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 10 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 MessageLoop::current()->RunAllPending(); | 234 MessageLoop::current()->RunAllPending(); |
235 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 235 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
236 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 236 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
237 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); | 237 EXPECT_TRUE(Mock::VerifyAndClear(mock_profile_)); |
238 } | 238 } |
239 | 239 |
240 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { | 240 void SetFeatureExtractor(BrowserFeatureExtractor* extractor) { |
241 csd_host_->feature_extractor_.reset(extractor); | 241 csd_host_->feature_extractor_.reset(extractor); |
242 } | 242 } |
243 | 243 |
244 void SetUnsafeUniquePageIdToCurrent() { | 244 void SetUnsafeResourceToCurrent() { |
245 csd_host_->unsafe_unique_page_id_ = | 245 SafeBrowsingService::UnsafeResource resource; |
246 contents()->controller().GetActiveEntry()->unique_id(); | 246 resource.url = GURL("http://www.malware.com/"); |
247 resource.original_url = contents()->GetURL(); | |
248 resource.is_subresource = true; | |
249 resource.threat_type = SafeBrowsingService::URL_MALWARE; | |
250 resource.client = NULL; | |
251 resource.render_process_host_id = contents()->GetRenderProcessHost()->id(); | |
252 resource.render_view_id = contents()->render_view_host()->routing_id(); | |
253 csd_host_->OnSafeBrowsingHit(resource); | |
247 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); | 254 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); |
255 ASSERT_TRUE(csd_host_->unsafe_resource_.get()); | |
256 // Test that the resource above was copied. | |
257 EXPECT_EQ(resource.url, csd_host_->unsafe_resource_->url); | |
258 EXPECT_EQ(resource.original_url, csd_host_->unsafe_resource_->original_url); | |
259 EXPECT_EQ(resource.is_subresource, | |
260 csd_host_->unsafe_resource_->is_subresource); | |
261 EXPECT_EQ(resource.threat_type, csd_host_->unsafe_resource_->threat_type); | |
262 EXPECT_EQ(resource.client, csd_host_->unsafe_resource_->client); | |
mattm
2011/08/01 23:19:35
nit: shouldn't this check it gets NULLed?
noelutz
2011/08/01 23:26:49
good point. done.
| |
263 EXPECT_EQ(resource.render_process_host_id, | |
264 csd_host_->unsafe_resource_->render_process_host_id); | |
265 EXPECT_EQ(resource.render_view_id, | |
266 csd_host_->unsafe_resource_->render_view_id); | |
248 } | 267 } |
249 | 268 |
250 protected: | 269 protected: |
251 scoped_ptr<ClientSideDetectionHost> csd_host_; | 270 scoped_ptr<ClientSideDetectionHost> csd_host_; |
252 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; | 271 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; |
253 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; | 272 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; |
254 MockTestingProfile* mock_profile_; // We don't own this object | 273 MockTestingProfile* mock_profile_; // We don't own this object |
255 | 274 |
256 private: | 275 private: |
257 scoped_ptr<BrowserThread> ui_thread_; | 276 scoped_ptr<BrowserThread> ui_thread_; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 ClientPhishingRequest verdict; | 531 ClientPhishingRequest verdict; |
513 verdict.set_url(url.spec()); | 532 verdict.set_url(url.spec()); |
514 verdict.set_client_score(0.1f); | 533 verdict.set_client_score(0.1f); |
515 verdict.set_is_phishing(false); | 534 verdict.set_is_phishing(false); |
516 | 535 |
517 // First we have to navigate to the URL to set the unique page ID. | 536 // First we have to navigate to the URL to set the unique page ID. |
518 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, | 537 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, |
519 &kFalse, &kFalse); | 538 &kFalse, &kFalse); |
520 NavigateAndCommit(url); | 539 NavigateAndCommit(url); |
521 WaitAndCheckPreClassificationChecks(); | 540 WaitAndCheckPreClassificationChecks(); |
522 SetUnsafeUniquePageIdToCurrent(); | 541 SetUnsafeResourceToCurrent(); |
523 | 542 |
524 EXPECT_CALL(*csd_service_, | 543 EXPECT_CALL(*csd_service_, |
525 SendClientReportPhishingRequest( | 544 SendClientReportPhishingRequest( |
526 Pointee(PartiallyEqualVerdict(verdict)), IsNull())) | 545 Pointee(PartiallyEqualVerdict(verdict)), IsNull())) |
527 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); | 546 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); |
528 OnPhishingDetectionDone(verdict.SerializeAsString()); | 547 OnPhishingDetectionDone(verdict.SerializeAsString()); |
529 MessageLoop::current()->Run(); | 548 MessageLoop::current()->Run(); |
530 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); | 549 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); |
531 } | 550 } |
532 | 551 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); | 730 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); |
712 EXPECT_EQ(url, resource.url); | 731 EXPECT_EQ(url, resource.url); |
713 EXPECT_EQ(url, resource.original_url); | 732 EXPECT_EQ(url, resource.original_url); |
714 delete resource.client; | 733 delete resource.client; |
715 msg = process()->sink().GetFirstMessageMatching( | 734 msg = process()->sink().GetFirstMessageMatching( |
716 SafeBrowsingMsg_StartPhishingDetection::ID); | 735 SafeBrowsingMsg_StartPhishingDetection::ID); |
717 ASSERT_FALSE(msg); | 736 ASSERT_FALSE(msg); |
718 } | 737 } |
719 | 738 |
720 } // namespace safe_browsing | 739 } // namespace safe_browsing |
OLD | NEW |