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 { |
65 | 64 |
66 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) { | 65 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) { |
67 net::HttpResponseInfo responseinfo; | 66 net::HttpResponseInfo responseinfo; |
68 std::string raw_headers = | 67 std::string raw_headers = |
69 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size()); | 68 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size()); |
70 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); | 69 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); |
71 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); | 70 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); |
72 | 71 |
73 base::Pickle pickle; | 72 base::Pickle pickle; |
74 responseinfo.Persist(&pickle, false, false); | 73 responseinfo.Persist(&pickle, false, false); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 } | 166 } |
168 | 167 |
169 const std::string& GetSerialized() { return serialized_; } | 168 const std::string& GetSerialized() { return serialized_; } |
170 | 169 |
171 private: | 170 private: |
172 ~MockSafeBrowsingUIManager() override {} | 171 ~MockSafeBrowsingUIManager() override {} |
173 | 172 |
174 std::string serialized_; | 173 std::string serialized_; |
175 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); | 174 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingUIManager); |
176 }; | 175 }; |
177 | 176 |
mattm
2015/11/11 01:10:16
Keep the anon namespace inside the new namespace.
vakh (old account. dont use)
2015/11/11 18:59:53
Done.
| |
178 } // namespace. | |
179 | |
180 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { | 177 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { |
181 public: | 178 public: |
182 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 179 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
183 | 180 |
184 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} | 181 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} |
185 | 182 |
186 void SetUp() override { | 183 void SetUp() override { |
187 ChromeRenderViewHostTestHarness::SetUp(); | 184 ChromeRenderViewHostTestHarness::SetUp(); |
188 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, | 185 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, |
189 false /* no_db */)); | 186 false /* no_db */)); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 | 551 |
555 ClientMalwareReportRequest expected; | 552 ClientMalwareReportRequest expected; |
556 expected.set_malware_url(kMalwareURL); | 553 expected.set_malware_url(kMalwareURL); |
557 expected.set_page_url(kLandingURL); | 554 expected.set_page_url(kLandingURL); |
558 expected.set_referrer_url(""); | 555 expected.set_referrer_url(""); |
559 expected.set_did_proceed(true); | 556 expected.set_did_proceed(true); |
560 | 557 |
561 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); | 558 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); |
562 pb_resource->set_id(0); | 559 pb_resource->set_id(0); |
563 pb_resource->set_url(kLandingURL); | 560 pb_resource->set_url(kLandingURL); |
564 safe_browsing::ClientMalwareReportRequest::HTTPResponse* pb_response = | 561 ClientMalwareReportRequest::HTTPResponse* pb_response = |
565 pb_resource->mutable_response(); | 562 pb_resource->mutable_response(); |
566 pb_response->mutable_firstline()->set_code(200); | 563 pb_response->mutable_firstline()->set_code(200); |
567 safe_browsing::ClientMalwareReportRequest::HTTPHeader* pb_header = | 564 ClientMalwareReportRequest::HTTPHeader* pb_header = |
568 pb_response->add_headers(); | 565 pb_response->add_headers(); |
569 pb_header->set_name("Content-Type"); | 566 pb_header->set_name("Content-Type"); |
570 pb_header->set_value("text/html"); | 567 pb_header->set_value("text/html"); |
571 pb_header = pb_response->add_headers(); | 568 pb_header = pb_response->add_headers(); |
572 pb_header->set_name("Content-Length"); | 569 pb_header->set_name("Content-Length"); |
573 pb_header->set_value("1024"); | 570 pb_header->set_value("1024"); |
574 pb_header = pb_response->add_headers(); | 571 pb_header = pb_response->add_headers(); |
575 pb_header->set_name("Set-Cookie"); | 572 pb_header->set_name("Set-Cookie"); |
576 pb_header->set_value(""); // The cookie is dropped. | 573 pb_header->set_value(""); // The cookie is dropped. |
577 pb_response->set_body(kLandingData); | 574 pb_response->set_body(kLandingData); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 pb_resource = expected.add_resources(); | 687 pb_resource = expected.add_resources(); |
691 pb_resource->set_id(2); | 688 pb_resource->set_id(2); |
692 pb_resource->set_parent_id(3); | 689 pb_resource->set_parent_id(3); |
693 pb_resource->set_url(kSecondRedirectURL); | 690 pb_resource->set_url(kSecondRedirectURL); |
694 pb_resource = expected.add_resources(); | 691 pb_resource = expected.add_resources(); |
695 pb_resource->set_id(3); | 692 pb_resource->set_id(3); |
696 pb_resource->set_url(kFirstRedirectURL); | 693 pb_resource->set_url(kFirstRedirectURL); |
697 | 694 |
698 VerifyResults(actual, expected); | 695 VerifyResults(actual, expected); |
699 } | 696 } |
697 | |
698 } // namespace safe_browsing | |
OLD | NEW |