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

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

Issue 7538009: Send back the URL that matched the SafeBrowsing list with the CSD ping. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Matt's comments. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Bogus client class. We just need this class to check that the client
251 // field of the UnsafeResource gets cleared before we stored it in the
252 // host object.
253 class BogusClient : public SafeBrowsingService::Client {
254 public:
255 BogusClient() {}
256 virtual ~BogusClient() {}
257 };
258 resource.client = new BogusClient();
259 resource.render_process_host_id = contents()->GetRenderProcessHost()->id();
260 resource.render_view_id = contents()->render_view_host()->routing_id();
261 csd_host_->OnSafeBrowsingHit(resource);
262 delete resource.client;
247 ASSERT_TRUE(csd_host_->DidShowSBInterstitial()); 263 ASSERT_TRUE(csd_host_->DidShowSBInterstitial());
264 ASSERT_TRUE(csd_host_->unsafe_resource_.get());
265 // Test that the resource above was copied.
266 EXPECT_EQ(resource.url, csd_host_->unsafe_resource_->url);
267 EXPECT_EQ(resource.original_url, csd_host_->unsafe_resource_->original_url);
268 EXPECT_EQ(resource.is_subresource,
269 csd_host_->unsafe_resource_->is_subresource);
270 EXPECT_EQ(resource.threat_type, csd_host_->unsafe_resource_->threat_type);
271 EXPECT_EQ(NULL, csd_host_->unsafe_resource_->client);
272 EXPECT_EQ(resource.render_process_host_id,
273 csd_host_->unsafe_resource_->render_process_host_id);
274 EXPECT_EQ(resource.render_view_id,
275 csd_host_->unsafe_resource_->render_view_id);
248 } 276 }
249 277
250 protected: 278 protected:
251 scoped_ptr<ClientSideDetectionHost> csd_host_; 279 scoped_ptr<ClientSideDetectionHost> csd_host_;
252 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_; 280 scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_;
253 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_; 281 scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_;
254 MockTestingProfile* mock_profile_; // We don't own this object 282 MockTestingProfile* mock_profile_; // We don't own this object
255 283
256 private: 284 private:
257 scoped_ptr<BrowserThread> ui_thread_; 285 scoped_ptr<BrowserThread> ui_thread_;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 ClientPhishingRequest verdict; 540 ClientPhishingRequest verdict;
513 verdict.set_url(url.spec()); 541 verdict.set_url(url.spec());
514 verdict.set_client_score(0.1f); 542 verdict.set_client_score(0.1f);
515 verdict.set_is_phishing(false); 543 verdict.set_is_phishing(false);
516 544
517 // First we have to navigate to the URL to set the unique page ID. 545 // First we have to navigate to the URL to set the unique page ID.
518 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse, 546 ExpectPreClassificationChecks(url, &kFalse, &kFalse, &kFalse, &kFalse,
519 &kFalse, &kFalse); 547 &kFalse, &kFalse);
520 NavigateAndCommit(url); 548 NavigateAndCommit(url);
521 WaitAndCheckPreClassificationChecks(); 549 WaitAndCheckPreClassificationChecks();
522 SetUnsafeUniquePageIdToCurrent(); 550 SetUnsafeResourceToCurrent();
523 551
524 EXPECT_CALL(*csd_service_, 552 EXPECT_CALL(*csd_service_,
525 SendClientReportPhishingRequest( 553 SendClientReportPhishingRequest(
526 Pointee(PartiallyEqualVerdict(verdict)), IsNull())) 554 Pointee(PartiallyEqualVerdict(verdict)), IsNull()))
527 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop())); 555 .WillOnce(DoAll(DeleteArg<0>(), QuitUIMessageLoop()));
528 OnPhishingDetectionDone(verdict.SerializeAsString()); 556 OnPhishingDetectionDone(verdict.SerializeAsString());
529 MessageLoop::current()->Run(); 557 MessageLoop::current()->Run();
530 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get())); 558 EXPECT_TRUE(Mock::VerifyAndClear(csd_service_.get()));
531 } 559 }
532 560
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get())); 739 EXPECT_TRUE(Mock::VerifyAndClear(sb_service_.get()));
712 EXPECT_EQ(url, resource.url); 740 EXPECT_EQ(url, resource.url);
713 EXPECT_EQ(url, resource.original_url); 741 EXPECT_EQ(url, resource.original_url);
714 delete resource.client; 742 delete resource.client;
715 msg = process()->sink().GetFirstMessageMatching( 743 msg = process()->sink().GetFirstMessageMatching(
716 SafeBrowsingMsg_StartPhishingDetection::ID); 744 SafeBrowsingMsg_StartPhishingDetection::ID);
717 ASSERT_FALSE(msg); 745 ASSERT_FALSE(msg);
718 } 746 }
719 747
720 } // namespace safe_browsing 748 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698