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

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

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Remove '// namespace safe_browsing' for a small fwd decl block. Created 5 years, 1 month 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
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/pickle.h" 8 #include "base/pickle.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 15 matching lines...) Expand all
26 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
27 #include "net/base/test_completion_callback.h" 27 #include "net/base/test_completion_callback.h"
28 #include "net/disk_cache/disk_cache.h" 28 #include "net/disk_cache/disk_cache.h"
29 #include "net/http/http_cache.h" 29 #include "net/http/http_cache.h"
30 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
31 #include "net/http/http_response_info.h" 31 #include "net/http/http_response_info.h"
32 #include "net/http/http_util.h" 32 #include "net/http/http_util.h"
33 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
34 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
35 35
36 using content::BrowserThread;
37 using content::WebContents;
38
39 namespace safe_browsing {
40
41 namespace {
42
36 // Mixture of HTTP and HTTPS. No special treatment for HTTPS. 43 // Mixture of HTTP and HTTPS. No special treatment for HTTPS.
37 static const char* kOriginalLandingURL = 44 static const char* kOriginalLandingURL =
38 "http://www.originallandingpage.com/with/path"; 45 "http://www.originallandingpage.com/with/path";
39 static const char* kDOMChildURL = "https://www.domparent.com/with/path"; 46 static const char* kDOMChildURL = "https://www.domparent.com/with/path";
40 static const char* kDOMParentURL = "https://www.domchild.com/with/path"; 47 static const char* kDOMParentURL = "https://www.domchild.com/with/path";
41 static const char* kFirstRedirectURL = "http://redirectone.com/with/path"; 48 static const char* kFirstRedirectURL = "http://redirectone.com/with/path";
42 static const char* kSecondRedirectURL = "https://redirecttwo.com/with/path"; 49 static const char* kSecondRedirectURL = "https://redirecttwo.com/with/path";
43 static const char* kReferrerURL = "http://www.referrer.com/with/path"; 50 static const char* kReferrerURL = "http://www.referrer.com/with/path";
44 51
45 static const char* kThreatURL = "http://www.threat.com/with/path"; 52 static const char* kThreatURL = "http://www.threat.com/with/path";
46 static const char* kThreatHeaders = 53 static const char* kThreatHeaders =
47 "HTTP/1.1 200 OK\n" 54 "HTTP/1.1 200 OK\n"
48 "Content-Type: image/jpeg\n"; 55 "Content-Type: image/jpeg\n";
49 static const char* kThreatData = "exploit();"; 56 static const char* kThreatData = "exploit();";
50 57
51 static const char* kLandingURL = "http://www.landingpage.com/with/path"; 58 static const char* kLandingURL = "http://www.landingpage.com/with/path";
52 static const char* kLandingHeaders = 59 static const char* kLandingHeaders =
53 "HTTP/1.1 200 OK\n" 60 "HTTP/1.1 200 OK\n"
54 "Content-Type: text/html\n" 61 "Content-Type: text/html\n"
55 "Content-Length: 1024\n" 62 "Content-Length: 1024\n"
56 "Set-Cookie: tastycookie\n"; // This header is stripped. 63 "Set-Cookie: tastycookie\n"; // This header is stripped.
57 static const char* kLandingData = 64 static const char* kLandingData =
58 "<iframe src='http://www.threat.com/with/path'>"; 65 "<iframe src='http://www.threat.com/with/path'>";
59 66
60 using content::BrowserThread; 67 using content::BrowserThread;
61 using content::WebContents; 68 using content::WebContents;
62 using safe_browsing::ClientSafeBrowsingReportRequest;
63
64 namespace {
65 69
66 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) { 70 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) {
67 net::HttpResponseInfo responseinfo; 71 net::HttpResponseInfo responseinfo;
68 std::string raw_headers = 72 std::string raw_headers =
69 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size()); 73 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size());
70 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); 74 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80);
71 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); 75 responseinfo.headers = new net::HttpResponseHeaders(raw_headers);
72 76
73 base::Pickle pickle; 77 base::Pickle pickle;
74 responseinfo.Persist(&pickle, false, false); 78 responseinfo.Persist(&pickle, false, false);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 172
169 const std::string& GetSerialized() { return serialized_; } 173 const std::string& GetSerialized() { return serialized_; }
170 174
171 private: 175 private:
172 ~MockSafeBrowsingUIManager() override {} 176 ~MockSafeBrowsingUIManager() override {}
173 177
174 std::string serialized_; 178 std::string serialized_;
175 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); 179 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager);
176 }; 180 };
177 181
178 } // namespace. 182 } // namespace
179 183
180 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { 184 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness {
181 public: 185 public:
182 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; 186 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
183 187
184 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} 188 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {}
185 189
186 void SetUp() override { 190 void SetUp() override {
187 ChromeRenderViewHostTestHarness::SetUp(); 191 ChromeRenderViewHostTestHarness::SetUp();
188 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, 192 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */,
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_PHISHING_URL); 572 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_PHISHING_URL);
569 expected.set_url(kThreatURL); 573 expected.set_url(kThreatURL);
570 expected.set_page_url(kLandingURL); 574 expected.set_page_url(kLandingURL);
571 expected.set_referrer_url(""); 575 expected.set_referrer_url("");
572 expected.set_did_proceed(true); 576 expected.set_did_proceed(true);
573 577
574 ClientSafeBrowsingReportRequest::Resource* pb_resource = 578 ClientSafeBrowsingReportRequest::Resource* pb_resource =
575 expected.add_resources(); 579 expected.add_resources();
576 pb_resource->set_id(0); 580 pb_resource->set_id(0);
577 pb_resource->set_url(kLandingURL); 581 pb_resource->set_url(kLandingURL);
578 safe_browsing::ClientSafeBrowsingReportRequest::HTTPResponse* pb_response = 582 ClientSafeBrowsingReportRequest::HTTPResponse* pb_response =
579 pb_resource->mutable_response(); 583 pb_resource->mutable_response();
580 pb_response->mutable_firstline()->set_code(200); 584 pb_response->mutable_firstline()->set_code(200);
581 safe_browsing::ClientSafeBrowsingReportRequest::HTTPHeader* pb_header = 585 ClientSafeBrowsingReportRequest::HTTPHeader* pb_header =
582 pb_response->add_headers(); 586 pb_response->add_headers();
583 pb_header->set_name("Content-Type"); 587 pb_header->set_name("Content-Type");
584 pb_header->set_value("text/html"); 588 pb_header->set_value("text/html");
585 pb_header = pb_response->add_headers(); 589 pb_header = pb_response->add_headers();
586 pb_header->set_name("Content-Length"); 590 pb_header->set_name("Content-Length");
587 pb_header->set_value("1024"); 591 pb_header->set_value("1024");
588 pb_header = pb_response->add_headers(); 592 pb_header = pb_response->add_headers();
589 pb_header->set_name("Set-Cookie"); 593 pb_header->set_name("Set-Cookie");
590 pb_header->set_value(""); // The cookie is dropped. 594 pb_header->set_value(""); // The cookie is dropped.
591 pb_response->set_body(kLandingData); 595 pb_response->set_body(kLandingData);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 pb_resource = expected.add_resources(); 715 pb_resource = expected.add_resources();
712 pb_resource->set_id(2); 716 pb_resource->set_id(2);
713 pb_resource->set_parent_id(3); 717 pb_resource->set_parent_id(3);
714 pb_resource->set_url(kSecondRedirectURL); 718 pb_resource->set_url(kSecondRedirectURL);
715 pb_resource = expected.add_resources(); 719 pb_resource = expected.add_resources();
716 pb_resource->set_id(3); 720 pb_resource->set_id(3);
717 pb_resource->set_url(kFirstRedirectURL); 721 pb_resource->set_url(kFirstRedirectURL);
718 722
719 VerifyResults(actual, expected); 723 VerifyResults(actual, expected);
720 } 724 }
725
726 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/threat_details_history.cc ('k') | chrome/browser/safe_browsing/two_phase_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698