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

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: Bring back anon namespace. Remove safe_browsing:: wherever not needed. 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* kMalwareURL = "http://www.malware.com/with/path"; 52 static const char* kMalwareURL = "http://www.malware.com/with/path";
46 static const char* kMalwareHeaders = 53 static const char* kMalwareHeaders =
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* kMalwareData = "exploit();"; 56 static const char* kMalwareData = "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.malware.com/with/path'>"; 65 "<iframe src='http://www.malware.com/with/path'>";
59 66
60 using content::BrowserThread;
61 using content::WebContents;
62 using safe_browsing::ClientMalwareReportRequest;
63
64 namespace {
65
66 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) { 67 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) {
67 net::HttpResponseInfo responseinfo; 68 net::HttpResponseInfo responseinfo;
68 std::string raw_headers = 69 std::string raw_headers =
69 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size()); 70 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size());
70 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); 71 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80);
71 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); 72 responseinfo.headers = new net::HttpResponseHeaders(raw_headers);
72 73
73 base::Pickle pickle; 74 base::Pickle pickle;
74 responseinfo.Persist(&pickle, false, false); 75 responseinfo.Persist(&pickle, false, false);
75 76
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 169
169 const std::string& GetSerialized() { return serialized_; } 170 const std::string& GetSerialized() { return serialized_; }
170 171
171 private: 172 private:
172 ~MockSafeBrowsingUIManager() override {} 173 ~MockSafeBrowsingUIManager() override {}
173 174
174 std::string serialized_; 175 std::string serialized_;
175 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); 176 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager);
176 }; 177 };
177 178
178 } // namespace. 179 } // namespace
179 180
180 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { 181 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness {
181 public: 182 public:
182 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; 183 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource;
183 184
184 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} 185 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {}
185 186
186 void SetUp() override { 187 void SetUp() override {
187 ChromeRenderViewHostTestHarness::SetUp(); 188 ChromeRenderViewHostTestHarness::SetUp();
188 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, 189 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 555
555 ClientMalwareReportRequest expected; 556 ClientMalwareReportRequest expected;
556 expected.set_malware_url(kMalwareURL); 557 expected.set_malware_url(kMalwareURL);
557 expected.set_page_url(kLandingURL); 558 expected.set_page_url(kLandingURL);
558 expected.set_referrer_url(""); 559 expected.set_referrer_url("");
559 expected.set_did_proceed(true); 560 expected.set_did_proceed(true);
560 561
561 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 562 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
562 pb_resource->set_id(0); 563 pb_resource->set_id(0);
563 pb_resource->set_url(kLandingURL); 564 pb_resource->set_url(kLandingURL);
564 safe_browsing::ClientMalwareReportRequest::HTTPResponse* pb_response = 565 ClientMalwareReportRequest::HTTPResponse* pb_response =
565 pb_resource->mutable_response(); 566 pb_resource->mutable_response();
566 pb_response->mutable_firstline()->set_code(200); 567 pb_response->mutable_firstline()->set_code(200);
567 safe_browsing::ClientMalwareReportRequest::HTTPHeader* pb_header = 568 ClientMalwareReportRequest::HTTPHeader* pb_header =
568 pb_response->add_headers(); 569 pb_response->add_headers();
569 pb_header->set_name("Content-Type"); 570 pb_header->set_name("Content-Type");
570 pb_header->set_value("text/html"); 571 pb_header->set_value("text/html");
571 pb_header = pb_response->add_headers(); 572 pb_header = pb_response->add_headers();
572 pb_header->set_name("Content-Length"); 573 pb_header->set_name("Content-Length");
573 pb_header->set_value("1024"); 574 pb_header->set_value("1024");
574 pb_header = pb_response->add_headers(); 575 pb_header = pb_response->add_headers();
575 pb_header->set_name("Set-Cookie"); 576 pb_header->set_name("Set-Cookie");
576 pb_header->set_value(""); // The cookie is dropped. 577 pb_header->set_value(""); // The cookie is dropped.
577 pb_response->set_body(kLandingData); 578 pb_response->set_body(kLandingData);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 pb_resource = expected.add_resources(); 691 pb_resource = expected.add_resources();
691 pb_resource->set_id(2); 692 pb_resource->set_id(2);
692 pb_resource->set_parent_id(3); 693 pb_resource->set_parent_id(3);
693 pb_resource->set_url(kSecondRedirectURL); 694 pb_resource->set_url(kSecondRedirectURL);
694 pb_resource = expected.add_resources(); 695 pb_resource = expected.add_resources();
695 pb_resource->set_id(3); 696 pb_resource->set_id(3);
696 pb_resource->set_url(kFirstRedirectURL); 697 pb_resource->set_url(kFirstRedirectURL);
697 698
698 VerifyResults(actual, expected); 699 VerifyResults(actual, expected);
699 } 700 }
701
702 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698