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 <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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 static const char* kLandingHeaders = | 52 static const char* kLandingHeaders = |
53 "HTTP/1.1 200 OK\n" | 53 "HTTP/1.1 200 OK\n" |
54 "Content-Type: text/html\n" | 54 "Content-Type: text/html\n" |
55 "Content-Length: 1024\n" | 55 "Content-Length: 1024\n" |
56 "Set-Cookie: tastycookie\n"; // This header is stripped. | 56 "Set-Cookie: tastycookie\n"; // This header is stripped. |
57 static const char* kLandingData = | 57 static const char* kLandingData = |
58 "<iframe src='http://www.malware.com/with/path'>"; | 58 "<iframe src='http://www.malware.com/with/path'>"; |
59 | 59 |
60 using content::BrowserThread; | 60 using content::BrowserThread; |
61 using content::WebContents; | 61 using content::WebContents; |
62 using safe_browsing::ClientMalwareReportRequest; | |
63 | 62 |
64 namespace { | 63 namespace safe_browsing { |
64 | |
65 class ClientMalwareReportRequest; | |
Nathan Parker
2015/11/05 22:00:53
Shouldn't need this.
vakh (old account. dont use)
2015/11/07 01:22:57
Done.
| |
65 | 66 |
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); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | |
180 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { | 179 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { |
181 public: | 180 public: |
182 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 181 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
183 | 182 |
184 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} | 183 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} |
185 | 184 |
186 void SetUp() override { | 185 void SetUp() override { |
187 ChromeRenderViewHostTestHarness::SetUp(); | 186 ChromeRenderViewHostTestHarness::SetUp(); |
188 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, | 187 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, |
189 false /* no_db */)); | 188 false /* no_db */)); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 | 553 |
555 ClientMalwareReportRequest expected; | 554 ClientMalwareReportRequest expected; |
556 expected.set_malware_url(kMalwareURL); | 555 expected.set_malware_url(kMalwareURL); |
557 expected.set_page_url(kLandingURL); | 556 expected.set_page_url(kLandingURL); |
558 expected.set_referrer_url(""); | 557 expected.set_referrer_url(""); |
559 expected.set_did_proceed(true); | 558 expected.set_did_proceed(true); |
560 | 559 |
561 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); | 560 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); |
562 pb_resource->set_id(0); | 561 pb_resource->set_id(0); |
563 pb_resource->set_url(kLandingURL); | 562 pb_resource->set_url(kLandingURL); |
564 safe_browsing::ClientMalwareReportRequest::HTTPResponse* pb_response = | 563 ClientMalwareReportRequest::HTTPResponse* pb_response = |
565 pb_resource->mutable_response(); | 564 pb_resource->mutable_response(); |
566 pb_response->mutable_firstline()->set_code(200); | 565 pb_response->mutable_firstline()->set_code(200); |
567 safe_browsing::ClientMalwareReportRequest::HTTPHeader* pb_header = | 566 ClientMalwareReportRequest::HTTPHeader* pb_header = |
568 pb_response->add_headers(); | 567 pb_response->add_headers(); |
569 pb_header->set_name("Content-Type"); | 568 pb_header->set_name("Content-Type"); |
570 pb_header->set_value("text/html"); | 569 pb_header->set_value("text/html"); |
571 pb_header = pb_response->add_headers(); | 570 pb_header = pb_response->add_headers(); |
572 pb_header->set_name("Content-Length"); | 571 pb_header->set_name("Content-Length"); |
573 pb_header->set_value("1024"); | 572 pb_header->set_value("1024"); |
574 pb_header = pb_response->add_headers(); | 573 pb_header = pb_response->add_headers(); |
575 pb_header->set_name("Set-Cookie"); | 574 pb_header->set_name("Set-Cookie"); |
576 pb_header->set_value(""); // The cookie is dropped. | 575 pb_header->set_value(""); // The cookie is dropped. |
577 pb_response->set_body(kLandingData); | 576 pb_response->set_body(kLandingData); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 pb_resource = expected.add_resources(); | 689 pb_resource = expected.add_resources(); |
691 pb_resource->set_id(2); | 690 pb_resource->set_id(2); |
692 pb_resource->set_parent_id(3); | 691 pb_resource->set_parent_id(3); |
693 pb_resource->set_url(kSecondRedirectURL); | 692 pb_resource->set_url(kSecondRedirectURL); |
694 pb_resource = expected.add_resources(); | 693 pb_resource = expected.add_resources(); |
695 pb_resource->set_id(3); | 694 pb_resource->set_id(3); |
696 pb_resource->set_url(kFirstRedirectURL); | 695 pb_resource->set_url(kFirstRedirectURL); |
697 | 696 |
698 VerifyResults(actual, expected); | 697 VerifyResults(actual, expected); |
699 } | 698 } |
699 | |
700 } // namespace safe_browsing | |
OLD | NEW |