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

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

Issue 1414343007: Collect threat details for phishing and UwS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit 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"
11 #include "chrome/browser/history/history_service_factory.h" 11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/report.pb.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/browser/safe_browsing/threat_details.h" 14 #include "chrome/browser/safe_browsing/threat_details.h"
16 #include "chrome/browser/safe_browsing/threat_details_history.h" 15 #include "chrome/browser/safe_browsing/threat_details_history.h"
17 #include "chrome/browser/safe_browsing/ui_manager.h" 16 #include "chrome/browser/safe_browsing/ui_manager.h"
17 #include "chrome/common/safe_browsing/csd.pb.h"
18 #include "chrome/common/safe_browsing/safebrowsing_messages.h" 18 #include "chrome/common/safe_browsing/safebrowsing_messages.h"
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "components/history/core/browser/history_backend.h" 21 #include "components/history/core/browser/history_backend.h"
22 #include "components/history/core/browser/history_service.h" 22 #include "components/history/core/browser/history_service.h"
23 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
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 // Mixture of HTTP and HTTPS. No special treatment for HTTPS. 36 // Mixture of HTTP and HTTPS. No special treatment for HTTPS.
37 static const char* kOriginalLandingURL = 37 static const char* kOriginalLandingURL =
38 "http://www.originallandingpage.com/with/path"; 38 "http://www.originallandingpage.com/with/path";
39 static const char* kDOMChildURL = "https://www.domparent.com/with/path"; 39 static const char* kDOMChildURL = "https://www.domparent.com/with/path";
40 static const char* kDOMParentURL = "https://www.domchild.com/with/path"; 40 static const char* kDOMParentURL = "https://www.domchild.com/with/path";
41 static const char* kFirstRedirectURL = "http://redirectone.com/with/path"; 41 static const char* kFirstRedirectURL = "http://redirectone.com/with/path";
42 static const char* kSecondRedirectURL = "https://redirecttwo.com/with/path"; 42 static const char* kSecondRedirectURL = "https://redirecttwo.com/with/path";
43 static const char* kReferrerURL = "http://www.referrer.com/with/path"; 43 static const char* kReferrerURL = "http://www.referrer.com/with/path";
44 44
45 static const char* kMalwareURL = "http://www.malware.com/with/path"; 45 static const char* kThreatURL = "http://www.threat.com/with/path";
46 static const char* kMalwareHeaders = 46 static const char* kThreatHeaders =
47 "HTTP/1.1 200 OK\n" 47 "HTTP/1.1 200 OK\n"
48 "Content-Type: image/jpeg\n"; 48 "Content-Type: image/jpeg\n";
49 static const char* kMalwareData = "exploit();"; 49 static const char* kThreatData = "exploit();";
50 50
51 static const char* kLandingURL = "http://www.landingpage.com/with/path"; 51 static const char* kLandingURL = "http://www.landingpage.com/with/path";
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.threat.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; 62 using safe_browsing::ClientSafeBrowsingReportRequest;
63 63
64 namespace { 64 namespace {
65 65
66 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) { 66 void WriteHeaders(disk_cache::Entry* entry, const std::string& headers) {
67 net::HttpResponseInfo responseinfo; 67 net::HttpResponseInfo responseinfo;
68 std::string raw_headers = 68 std::string raw_headers =
69 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size()); 69 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size());
70 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); 70 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80);
71 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); 71 responseinfo.headers = new net::HttpResponseHeaders(raw_headers);
72 72
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 void FillCache(net::URLRequestContextGetter* context_getter) { 116 void FillCache(net::URLRequestContextGetter* context_getter) {
117 net::TestCompletionCallback cb; 117 net::TestCompletionCallback cb;
118 disk_cache::Backend* cache; 118 disk_cache::Backend* cache;
119 int rv = context_getter->GetURLRequestContext() 119 int rv = context_getter->GetURLRequestContext()
120 ->http_transaction_factory() 120 ->http_transaction_factory()
121 ->GetCache() 121 ->GetCache()
122 ->GetBackend(&cache, cb.callback()); 122 ->GetBackend(&cache, cb.callback());
123 ASSERT_EQ(net::OK, cb.GetResult(rv)); 123 ASSERT_EQ(net::OK, cb.GetResult(rv));
124 124
125 WriteToEntry(cache, kMalwareURL, kMalwareHeaders, kMalwareData); 125 WriteToEntry(cache, kThreatURL, kThreatHeaders, kThreatData);
126 WriteToEntry(cache, kLandingURL, kLandingHeaders, kLandingData); 126 WriteToEntry(cache, kLandingURL, kLandingHeaders, kLandingData);
127 } 127 }
128 128
129 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate. 129 // Lets us provide a MockURLRequestContext with an HTTP Cache we pre-populate.
130 // Also exposes the constructor. 130 // Also exposes the constructor.
131 class ThreatDetailsWrap : public ThreatDetails { 131 class ThreatDetailsWrap : public ThreatDetails {
132 public: 132 public:
133 ThreatDetailsWrap( 133 ThreatDetailsWrap(
134 SafeBrowsingUIManager* ui_manager, 134 SafeBrowsingUIManager* ui_manager,
135 WebContents* web_contents, 135 WebContents* web_contents,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, 188 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */,
189 false /* no_db */)); 189 false /* no_db */));
190 } 190 }
191 191
192 void TearDown() override { 192 void TearDown() override {
193 profile()->DestroyHistoryService(); 193 profile()->DestroyHistoryService();
194 ChromeRenderViewHostTestHarness::TearDown(); 194 ChromeRenderViewHostTestHarness::TearDown();
195 } 195 }
196 196
197 static bool ResourceLessThan( 197 static bool ResourceLessThan(
198 const ClientMalwareReportRequest::Resource* lhs, 198 const ClientSafeBrowsingReportRequest::Resource* lhs,
199 const ClientMalwareReportRequest::Resource* rhs) { 199 const ClientSafeBrowsingReportRequest::Resource* rhs) {
200 return lhs->id() < rhs->id(); 200 return lhs->id() < rhs->id();
201 } 201 }
202 202
203 std::string WaitForSerializedReport(ThreatDetails* report, 203 std::string WaitForSerializedReport(ThreatDetails* report,
204 bool did_proceed, 204 bool did_proceed,
205 int num_visit) { 205 int num_visit) {
206 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 206 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
207 base::Bind(&ThreatDetails::FinishCollection, report, 207 base::Bind(&ThreatDetails::FinishCollection, report,
208 did_proceed, num_visit)); 208 did_proceed, num_visit));
209 // Wait for the callback (SendSerializedThreatDetails). 209 // Wait for the callback (SendSerializedThreatDetails).
210 DVLOG(1) << "Waiting for SendSerializedThreatDetails"; 210 DVLOG(1) << "Waiting for SendSerializedThreatDetails";
211 base::RunLoop run_loop; 211 base::RunLoop run_loop;
212 ui_manager_->SetRunLoopToQuit(&run_loop); 212 ui_manager_->SetRunLoopToQuit(&run_loop);
213 run_loop.Run(); 213 run_loop.Run();
214 return ui_manager_->GetSerialized(); 214 return ui_manager_->GetSerialized();
215 } 215 }
216 216
217 history::HistoryService* history_service() { 217 history::HistoryService* history_service() {
218 return HistoryServiceFactory::GetForProfile( 218 return HistoryServiceFactory::GetForProfile(
219 profile(), ServiceAccessType::EXPLICIT_ACCESS); 219 profile(), ServiceAccessType::EXPLICIT_ACCESS);
220 } 220 }
221 221
222 protected: 222 protected:
223 void InitResource(UnsafeResource* resource, 223 void InitResource(UnsafeResource* resource,
224 SBThreatType threat_type,
224 bool is_subresource, 225 bool is_subresource,
225 const GURL& url) { 226 const GURL& url) {
226 resource->url = url; 227 resource->url = url;
227 resource->is_subresource = is_subresource; 228 resource->is_subresource = is_subresource;
228 resource->threat_type = SB_THREAT_TYPE_URL_MALWARE; 229 resource->threat_type = threat_type;
229 resource->render_process_host_id = 230 resource->render_process_host_id =
230 web_contents()->GetRenderProcessHost()->GetID(); 231 web_contents()->GetRenderProcessHost()->GetID();
231 resource->render_view_id = 232 resource->render_view_id =
232 web_contents()->GetRenderViewHost()->GetRoutingID(); 233 web_contents()->GetRenderViewHost()->GetRoutingID();
233 } 234 }
234 235
235 void VerifyResults(const ClientMalwareReportRequest& report_pb, 236 void VerifyResults(const ClientSafeBrowsingReportRequest& report_pb,
236 const ClientMalwareReportRequest& expected_pb) { 237 const ClientSafeBrowsingReportRequest& expected_pb) {
237 EXPECT_EQ(expected_pb.malware_url(), report_pb.malware_url()); 238 EXPECT_EQ(expected_pb.type(), report_pb.type());
239 EXPECT_EQ(expected_pb.url(), report_pb.url());
238 EXPECT_EQ(expected_pb.page_url(), report_pb.page_url()); 240 EXPECT_EQ(expected_pb.page_url(), report_pb.page_url());
239 EXPECT_EQ(expected_pb.referrer_url(), report_pb.referrer_url()); 241 EXPECT_EQ(expected_pb.referrer_url(), report_pb.referrer_url());
240 EXPECT_EQ(expected_pb.did_proceed(), report_pb.did_proceed()); 242 EXPECT_EQ(expected_pb.did_proceed(), report_pb.did_proceed());
241 EXPECT_EQ(expected_pb.has_repeat_visit(), report_pb.has_repeat_visit()); 243 EXPECT_EQ(expected_pb.has_repeat_visit(), report_pb.has_repeat_visit());
242 if (expected_pb.has_repeat_visit() && report_pb.has_repeat_visit()) { 244 if (expected_pb.has_repeat_visit() && report_pb.has_repeat_visit()) {
243 EXPECT_EQ(expected_pb.repeat_visit(), report_pb.repeat_visit()); 245 EXPECT_EQ(expected_pb.repeat_visit(), report_pb.repeat_visit());
244 } 246 }
245 247
246 ASSERT_EQ(expected_pb.resources_size(), report_pb.resources_size()); 248 ASSERT_EQ(expected_pb.resources_size(), report_pb.resources_size());
247 // Sort the resources, to make the test deterministic 249 // Sort the resources, to make the test deterministic
248 std::vector<const ClientMalwareReportRequest::Resource*> resources; 250 std::vector<const ClientSafeBrowsingReportRequest::Resource*> resources;
249 for (int i = 0; i < report_pb.resources_size(); ++i) { 251 for (int i = 0; i < report_pb.resources_size(); ++i) {
250 const ClientMalwareReportRequest::Resource& resource = 252 const ClientSafeBrowsingReportRequest::Resource& resource =
251 report_pb.resources(i); 253 report_pb.resources(i);
252 resources.push_back(&resource); 254 resources.push_back(&resource);
253 } 255 }
254 std::sort(resources.begin(), resources.end(), 256 std::sort(resources.begin(), resources.end(),
255 &ThreatDetailsTest::ResourceLessThan); 257 &ThreatDetailsTest::ResourceLessThan);
256 258
257 std::vector<const ClientMalwareReportRequest::Resource*> expected; 259 std::vector<const ClientSafeBrowsingReportRequest::Resource*> expected;
258 for (int i = 0; i < report_pb.resources_size(); ++i) { 260 for (int i = 0; i < report_pb.resources_size(); ++i) {
259 const ClientMalwareReportRequest::Resource& resource = 261 const ClientSafeBrowsingReportRequest::Resource& resource =
260 expected_pb.resources(i); 262 expected_pb.resources(i);
261 expected.push_back(&resource); 263 expected.push_back(&resource);
262 } 264 }
263 std::sort(expected.begin(), expected.end(), 265 std::sort(expected.begin(), expected.end(),
264 &ThreatDetailsTest::ResourceLessThan); 266 &ThreatDetailsTest::ResourceLessThan);
265 267
266 for (uint32 i = 0; i < expected.size(); ++i) { 268 for (uint32 i = 0; i < expected.size(); ++i) {
267 VerifyResource(resources[i], expected[i]); 269 VerifyResource(resources[i], expected[i]);
268 } 270 }
269 271
270 EXPECT_EQ(expected_pb.complete(), report_pb.complete()); 272 EXPECT_EQ(expected_pb.complete(), report_pb.complete());
271 } 273 }
272 274
273 void VerifyResource(const ClientMalwareReportRequest::Resource* resource, 275 void VerifyResource(
274 const ClientMalwareReportRequest::Resource* expected) { 276 const ClientSafeBrowsingReportRequest::Resource* resource,
277 const ClientSafeBrowsingReportRequest::Resource* expected) {
275 EXPECT_EQ(expected->id(), resource->id()); 278 EXPECT_EQ(expected->id(), resource->id());
276 EXPECT_EQ(expected->url(), resource->url()); 279 EXPECT_EQ(expected->url(), resource->url());
277 EXPECT_EQ(expected->parent_id(), resource->parent_id()); 280 EXPECT_EQ(expected->parent_id(), resource->parent_id());
278 ASSERT_EQ(expected->child_ids_size(), resource->child_ids_size()); 281 ASSERT_EQ(expected->child_ids_size(), resource->child_ids_size());
279 for (int i = 0; i < expected->child_ids_size(); i++) { 282 for (int i = 0; i < expected->child_ids_size(); i++) {
280 EXPECT_EQ(expected->child_ids(i), resource->child_ids(i)); 283 EXPECT_EQ(expected->child_ids(i), resource->child_ids(i));
281 } 284 }
282 285
283 // Verify HTTP Responses 286 // Verify HTTP Responses
284 if (expected->has_response()) { 287 if (expected->has_response()) {
(...skipping 30 matching lines...) Expand all
315 redirects->push_back(url); 318 redirects->push_back(url);
316 history_service()->AddPage(url, base::Time::Now(), 319 history_service()->AddPage(url, base::Time::Now(),
317 reinterpret_cast<history::ContextID>(1), 0, 320 reinterpret_cast<history::ContextID>(1), 0,
318 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED, 321 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED,
319 history::SOURCE_BROWSED, false); 322 history::SOURCE_BROWSED, false);
320 } 323 }
321 324
322 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; 325 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_;
323 }; 326 };
324 327
325 // Tests creating a simple malware report. 328 // Tests creating a simple threat report of a malware URL.
326 TEST_F(ThreatDetailsTest, MalwareSubResource) { 329 TEST_F(ThreatDetailsTest, ThreatSubResource) {
327 // Start a load. 330 // Start a load.
328 controller().LoadURL( 331 controller().LoadURL(
329 GURL(kLandingURL), 332 GURL(kLandingURL),
330 content::Referrer(GURL(kReferrerURL), blink::WebReferrerPolicyDefault), 333 content::Referrer(GURL(kReferrerURL), blink::WebReferrerPolicyDefault),
331 ui::PAGE_TRANSITION_TYPED, std::string()); 334 ui::PAGE_TRANSITION_TYPED, std::string());
332 335
333 UnsafeResource resource; 336 UnsafeResource resource;
334 InitResource(&resource, true, GURL(kMalwareURL)); 337 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true, GURL(kThreatURL));
335 338
336 scoped_refptr<ThreatDetailsWrap> report = 339 scoped_refptr<ThreatDetailsWrap> report =
337 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); 340 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL);
338 341
339 std::string serialized = WaitForSerializedReport( 342 std::string serialized = WaitForSerializedReport(
340 report.get(), true /* did_proceed*/, 1 /* num_visit */); 343 report.get(), true /* did_proceed*/, 1 /* num_visit */);
341 344
342 ClientMalwareReportRequest actual; 345 ClientSafeBrowsingReportRequest actual;
343 actual.ParseFromString(serialized); 346 actual.ParseFromString(serialized);
344 347
345 ClientMalwareReportRequest expected; 348 ClientSafeBrowsingReportRequest expected;
346 expected.set_malware_url(kMalwareURL); 349 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE);
350 expected.set_url(kThreatURL);
347 expected.set_page_url(kLandingURL); 351 expected.set_page_url(kLandingURL);
348 // Note that the referrer policy is not actually enacted here, since that's 352 // Note that the referrer policy is not actually enacted here, since that's
349 // done in Blink. 353 // done in Blink.
350 expected.set_referrer_url(kReferrerURL); 354 expected.set_referrer_url(kReferrerURL);
351 expected.set_did_proceed(true); 355 expected.set_did_proceed(true);
352 expected.set_repeat_visit(true); 356 expected.set_repeat_visit(true);
353 357
354 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 358 ClientSafeBrowsingReportRequest::Resource* pb_resource =
359 expected.add_resources();
355 pb_resource->set_id(0); 360 pb_resource->set_id(0);
356 pb_resource->set_url(kLandingURL); 361 pb_resource->set_url(kLandingURL);
357 pb_resource = expected.add_resources(); 362 pb_resource = expected.add_resources();
358 pb_resource->set_id(1); 363 pb_resource->set_id(1);
359 pb_resource->set_url(kMalwareURL); 364 pb_resource->set_url(kThreatURL);
360 pb_resource = expected.add_resources(); 365 pb_resource = expected.add_resources();
361 pb_resource->set_id(2); 366 pb_resource->set_id(2);
362 pb_resource->set_url(kReferrerURL); 367 pb_resource->set_url(kReferrerURL);
363 368
364 VerifyResults(actual, expected); 369 VerifyResults(actual, expected);
365 } 370 }
366 371
367 // Tests creating a simple malware report where the subresource has a 372 // Tests creating a simple threat report of a phishing page where the
368 // different original_url. 373 // subresource has a different original_url.
369 TEST_F(ThreatDetailsTest, MalwareSubResourceWithOriginalUrl) { 374 TEST_F(ThreatDetailsTest, ThreatSubResourceWithOriginalUrl) {
370 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 375 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
371 ui::PAGE_TRANSITION_TYPED, std::string()); 376 ui::PAGE_TRANSITION_TYPED, std::string());
372 377
373 UnsafeResource resource; 378 UnsafeResource resource;
374 InitResource(&resource, true, GURL(kMalwareURL)); 379 InitResource(&resource, SB_THREAT_TYPE_URL_PHISHING, true, GURL(kThreatURL));
375 resource.original_url = GURL(kOriginalLandingURL); 380 resource.original_url = GURL(kOriginalLandingURL);
376 381
377 scoped_refptr<ThreatDetailsWrap> report = 382 scoped_refptr<ThreatDetailsWrap> report =
378 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); 383 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL);
379 384
380 std::string serialized = WaitForSerializedReport( 385 std::string serialized = WaitForSerializedReport(
381 report.get(), false /* did_proceed*/, 1 /* num_visit */); 386 report.get(), false /* did_proceed*/, 1 /* num_visit */);
382 387
383 ClientMalwareReportRequest actual; 388 ClientSafeBrowsingReportRequest actual;
384 actual.ParseFromString(serialized); 389 actual.ParseFromString(serialized);
385 390
386 ClientMalwareReportRequest expected; 391 ClientSafeBrowsingReportRequest expected;
387 expected.set_malware_url(kMalwareURL); 392 expected.set_type(ClientSafeBrowsingReportRequest::URL_PHISHING);
393 expected.set_url(kThreatURL);
388 expected.set_page_url(kLandingURL); 394 expected.set_page_url(kLandingURL);
389 expected.set_referrer_url(""); 395 expected.set_referrer_url("");
390 expected.set_did_proceed(false); 396 expected.set_did_proceed(false);
391 expected.set_repeat_visit(true); 397 expected.set_repeat_visit(true);
392 398
393 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 399 ClientSafeBrowsingReportRequest::Resource* pb_resource =
400 expected.add_resources();
394 pb_resource->set_id(0); 401 pb_resource->set_id(0);
395 pb_resource->set_url(kLandingURL); 402 pb_resource->set_url(kLandingURL);
396 403
397 pb_resource = expected.add_resources(); 404 pb_resource = expected.add_resources();
398 pb_resource->set_id(1); 405 pb_resource->set_id(1);
399 pb_resource->set_url(kOriginalLandingURL); 406 pb_resource->set_url(kOriginalLandingURL);
400 407
401 pb_resource = expected.add_resources(); 408 pb_resource = expected.add_resources();
402 pb_resource->set_id(2); 409 pb_resource->set_id(2);
403 pb_resource->set_url(kMalwareURL); 410 pb_resource->set_url(kThreatURL);
404 // The Resource for kMalwareUrl should have the Resource for 411 // The Resource for kThreatURL should have the Resource for
405 // kOriginalLandingURL (with id 1) as parent. 412 // kOriginalLandingURL (with id 1) as parent.
406 pb_resource->set_parent_id(1); 413 pb_resource->set_parent_id(1);
407 414
408 VerifyResults(actual, expected); 415 VerifyResults(actual, expected);
409 } 416 }
410 417
411 // Tests creating a malware report with data from the renderer. 418 // Tests creating a threat report of a UwS page with data from the renderer.
412 TEST_F(ThreatDetailsTest, MalwareDOMDetails) { 419 TEST_F(ThreatDetailsTest, ThreatDOMDetails) {
413 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 420 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
414 ui::PAGE_TRANSITION_TYPED, std::string()); 421 ui::PAGE_TRANSITION_TYPED, std::string());
415 422
416 UnsafeResource resource; 423 UnsafeResource resource;
417 InitResource(&resource, true, GURL(kMalwareURL)); 424 InitResource(&resource, SB_THREAT_TYPE_URL_UNWANTED, true, GURL(kThreatURL));
418 425
419 scoped_refptr<ThreatDetailsWrap> report = 426 scoped_refptr<ThreatDetailsWrap> report =
420 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); 427 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL);
421 428
422 // Send a message from the DOM, with 2 nodes, a parent and a child. 429 // Send a message from the DOM, with 2 nodes, a parent and a child.
423 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 430 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params;
424 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node; 431 SafeBrowsingHostMsg_ThreatDOMDetails_Node child_node;
425 child_node.url = GURL(kDOMChildURL); 432 child_node.url = GURL(kDOMChildURL);
426 child_node.tag_name = "iframe"; 433 child_node.tag_name = "iframe";
427 child_node.parent = GURL(kDOMParentURL); 434 child_node.parent = GURL(kDOMParentURL);
428 params.push_back(child_node); 435 params.push_back(child_node);
429 SafeBrowsingHostMsg_MalwareDOMDetails_Node parent_node; 436 SafeBrowsingHostMsg_ThreatDOMDetails_Node parent_node;
430 parent_node.url = GURL(kDOMParentURL); 437 parent_node.url = GURL(kDOMParentURL);
431 parent_node.children.push_back(GURL(kDOMChildURL)); 438 parent_node.children.push_back(GURL(kDOMChildURL));
432 params.push_back(parent_node); 439 params.push_back(parent_node);
433 report->OnReceivedThreatDOMDetails(params); 440 report->OnReceivedThreatDOMDetails(params);
434 441
435 std::string serialized = WaitForSerializedReport( 442 std::string serialized = WaitForSerializedReport(
436 report.get(), false /* did_proceed*/, 0 /* num_visit */); 443 report.get(), false /* did_proceed*/, 0 /* num_visit */);
437 ClientMalwareReportRequest actual; 444 ClientSafeBrowsingReportRequest actual;
438 actual.ParseFromString(serialized); 445 actual.ParseFromString(serialized);
439 446
440 ClientMalwareReportRequest expected; 447 ClientSafeBrowsingReportRequest expected;
441 expected.set_malware_url(kMalwareURL); 448 expected.set_type(ClientSafeBrowsingReportRequest::URL_UNWANTED);
449 expected.set_url(kThreatURL);
442 expected.set_page_url(kLandingURL); 450 expected.set_page_url(kLandingURL);
443 expected.set_referrer_url(""); 451 expected.set_referrer_url("");
444 expected.set_did_proceed(false); 452 expected.set_did_proceed(false);
445 expected.set_repeat_visit(false); 453 expected.set_repeat_visit(false);
446 454
447 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 455 ClientSafeBrowsingReportRequest::Resource* pb_resource =
456 expected.add_resources();
448 pb_resource->set_id(0); 457 pb_resource->set_id(0);
449 pb_resource->set_url(kLandingURL); 458 pb_resource->set_url(kLandingURL);
450 459
451 pb_resource = expected.add_resources(); 460 pb_resource = expected.add_resources();
452 pb_resource->set_id(1); 461 pb_resource->set_id(1);
453 pb_resource->set_url(kMalwareURL); 462 pb_resource->set_url(kThreatURL);
454 463
455 pb_resource = expected.add_resources(); 464 pb_resource = expected.add_resources();
456 pb_resource->set_id(2); 465 pb_resource->set_id(2);
457 pb_resource->set_url(kDOMChildURL); 466 pb_resource->set_url(kDOMChildURL);
458 pb_resource->set_parent_id(3); 467 pb_resource->set_parent_id(3);
459 468
460 pb_resource = expected.add_resources(); 469 pb_resource = expected.add_resources();
461 pb_resource->set_id(3); 470 pb_resource->set_id(3);
462 pb_resource->set_url(kDOMParentURL); 471 pb_resource->set_url(kDOMParentURL);
463 pb_resource->add_child_ids(2); 472 pb_resource->add_child_ids(2);
464 expected.set_complete(false); // Since the cache was missing. 473 expected.set_complete(false); // Since the cache was missing.
465 474
466 VerifyResults(actual, expected); 475 VerifyResults(actual, expected);
467 } 476 }
468 477
469 // Tests creating a malware report where there are redirect urls to an unsafe 478 // Tests creating a threat report of a malware page where there are redirect
470 // resource url 479 // urls to an unsafe resource url.
471 TEST_F(ThreatDetailsTest, MalwareWithRedirectUrl) { 480 TEST_F(ThreatDetailsTest, ThreatWithRedirectUrl) {
472 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 481 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
473 ui::PAGE_TRANSITION_TYPED, std::string()); 482 ui::PAGE_TRANSITION_TYPED, std::string());
474 483
475 UnsafeResource resource; 484 UnsafeResource resource;
476 InitResource(&resource, true, GURL(kMalwareURL)); 485 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true, GURL(kThreatURL));
477 resource.original_url = GURL(kOriginalLandingURL); 486 resource.original_url = GURL(kOriginalLandingURL);
478 487
479 // add some redirect urls 488 // add some redirect urls
480 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); 489 resource.redirect_urls.push_back(GURL(kFirstRedirectURL));
481 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); 490 resource.redirect_urls.push_back(GURL(kSecondRedirectURL));
482 resource.redirect_urls.push_back(GURL(kMalwareURL)); 491 resource.redirect_urls.push_back(GURL(kThreatURL));
483 492
484 scoped_refptr<ThreatDetailsWrap> report = 493 scoped_refptr<ThreatDetailsWrap> report =
485 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); 494 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL);
486 495
487 std::string serialized = WaitForSerializedReport( 496 std::string serialized = WaitForSerializedReport(
488 report.get(), true /* did_proceed*/, 0 /* num_visit */); 497 report.get(), true /* did_proceed*/, 0 /* num_visit */);
489 ClientMalwareReportRequest actual; 498 ClientSafeBrowsingReportRequest actual;
490 actual.ParseFromString(serialized); 499 actual.ParseFromString(serialized);
491 500
492 ClientMalwareReportRequest expected; 501 ClientSafeBrowsingReportRequest expected;
493 expected.set_malware_url(kMalwareURL); 502 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE);
503 expected.set_url(kThreatURL);
494 expected.set_page_url(kLandingURL); 504 expected.set_page_url(kLandingURL);
495 expected.set_referrer_url(""); 505 expected.set_referrer_url("");
496 expected.set_did_proceed(true); 506 expected.set_did_proceed(true);
497 expected.set_repeat_visit(false); 507 expected.set_repeat_visit(false);
498 508
499 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 509 ClientSafeBrowsingReportRequest::Resource* pb_resource =
510 expected.add_resources();
500 pb_resource->set_id(0); 511 pb_resource->set_id(0);
501 pb_resource->set_url(kLandingURL); 512 pb_resource->set_url(kLandingURL);
502 513
503 pb_resource = expected.add_resources(); 514 pb_resource = expected.add_resources();
504 pb_resource->set_id(1); 515 pb_resource->set_id(1);
505 pb_resource->set_url(kOriginalLandingURL); 516 pb_resource->set_url(kOriginalLandingURL);
506 517
507 pb_resource = expected.add_resources(); 518 pb_resource = expected.add_resources();
508 pb_resource->set_id(2); 519 pb_resource->set_id(2);
509 pb_resource->set_url(kMalwareURL); 520 pb_resource->set_url(kThreatURL);
510 pb_resource->set_parent_id(4); 521 pb_resource->set_parent_id(4);
511 522
512 pb_resource = expected.add_resources(); 523 pb_resource = expected.add_resources();
513 pb_resource->set_id(3); 524 pb_resource->set_id(3);
514 pb_resource->set_url(kFirstRedirectURL); 525 pb_resource->set_url(kFirstRedirectURL);
515 pb_resource->set_parent_id(1); 526 pb_resource->set_parent_id(1);
516 527
517 pb_resource = expected.add_resources(); 528 pb_resource = expected.add_resources();
518 pb_resource->set_id(4); 529 pb_resource->set_id(4);
519 pb_resource->set_url(kSecondRedirectURL); 530 pb_resource->set_url(kSecondRedirectURL);
520 pb_resource->set_parent_id(3); 531 pb_resource->set_parent_id(3);
521 532
522 VerifyResults(actual, expected); 533 VerifyResults(actual, expected);
523 } 534 }
524 535
525 // Tests the interaction with the HTTP cache. 536 // Tests the interaction with the HTTP cache.
526 TEST_F(ThreatDetailsTest, HTTPCache) { 537 TEST_F(ThreatDetailsTest, HTTPCache) {
527 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 538 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
528 ui::PAGE_TRANSITION_TYPED, std::string()); 539 ui::PAGE_TRANSITION_TYPED, std::string());
529 540
530 UnsafeResource resource; 541 UnsafeResource resource;
531 InitResource(&resource, true, GURL(kMalwareURL)); 542 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, true,
543 GURL(kThreatURL));
532 544
533 scoped_refptr<ThreatDetailsWrap> report = 545 scoped_refptr<ThreatDetailsWrap> report =
534 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, 546 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource,
535 profile()->GetRequestContext()); 547 profile()->GetRequestContext());
536 548
537 BrowserThread::PostTask( 549 BrowserThread::PostTask(
538 BrowserThread::IO, FROM_HERE, 550 BrowserThread::IO, FROM_HERE,
539 base::Bind(&FillCache, 551 base::Bind(&FillCache,
540 make_scoped_refptr(profile()->GetRequestContext()))); 552 make_scoped_refptr(profile()->GetRequestContext())));
541 553
542 // The cache collection starts after the IPC from the DOM is fired. 554 // The cache collection starts after the IPC from the DOM is fired.
543 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 555 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params;
544 report->OnReceivedThreatDOMDetails(params); 556 report->OnReceivedThreatDOMDetails(params);
545 557
546 // Let the cache callbacks complete. 558 // Let the cache callbacks complete.
547 base::RunLoop().RunUntilIdle(); 559 base::RunLoop().RunUntilIdle();
548 560
549 DVLOG(1) << "Getting serialized report"; 561 DVLOG(1) << "Getting serialized report";
550 std::string serialized = WaitForSerializedReport( 562 std::string serialized = WaitForSerializedReport(
551 report.get(), true /* did_proceed*/, -1 /* num_visit */); 563 report.get(), true /* did_proceed*/, -1 /* num_visit */);
552 ClientMalwareReportRequest actual; 564 ClientSafeBrowsingReportRequest actual;
553 actual.ParseFromString(serialized); 565 actual.ParseFromString(serialized);
554 566
555 ClientMalwareReportRequest expected; 567 ClientSafeBrowsingReportRequest expected;
556 expected.set_malware_url(kMalwareURL); 568 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_PHISHING_URL);
569 expected.set_url(kThreatURL);
557 expected.set_page_url(kLandingURL); 570 expected.set_page_url(kLandingURL);
558 expected.set_referrer_url(""); 571 expected.set_referrer_url("");
559 expected.set_did_proceed(true); 572 expected.set_did_proceed(true);
560 573
561 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 574 ClientSafeBrowsingReportRequest::Resource* pb_resource =
575 expected.add_resources();
562 pb_resource->set_id(0); 576 pb_resource->set_id(0);
563 pb_resource->set_url(kLandingURL); 577 pb_resource->set_url(kLandingURL);
564 safe_browsing::ClientMalwareReportRequest::HTTPResponse* pb_response = 578 safe_browsing::ClientSafeBrowsingReportRequest::HTTPResponse* pb_response =
565 pb_resource->mutable_response(); 579 pb_resource->mutable_response();
566 pb_response->mutable_firstline()->set_code(200); 580 pb_response->mutable_firstline()->set_code(200);
567 safe_browsing::ClientMalwareReportRequest::HTTPHeader* pb_header = 581 safe_browsing::ClientSafeBrowsingReportRequest::HTTPHeader* pb_header =
568 pb_response->add_headers(); 582 pb_response->add_headers();
569 pb_header->set_name("Content-Type"); 583 pb_header->set_name("Content-Type");
570 pb_header->set_value("text/html"); 584 pb_header->set_value("text/html");
571 pb_header = pb_response->add_headers(); 585 pb_header = pb_response->add_headers();
572 pb_header->set_name("Content-Length"); 586 pb_header->set_name("Content-Length");
573 pb_header->set_value("1024"); 587 pb_header->set_value("1024");
574 pb_header = pb_response->add_headers(); 588 pb_header = pb_response->add_headers();
575 pb_header->set_name("Set-Cookie"); 589 pb_header->set_name("Set-Cookie");
576 pb_header->set_value(""); // The cookie is dropped. 590 pb_header->set_value(""); // The cookie is dropped.
577 pb_response->set_body(kLandingData); 591 pb_response->set_body(kLandingData);
578 pb_response->set_bodylength(47); 592 std::string landing_data(kLandingData);
579 pb_response->set_bodydigest("5abb4e63d806ec2c16a40b2699700554"); 593 pb_response->set_bodylength(landing_data.size());
594 pb_response->set_bodydigest(base::MD5String(landing_data));
580 pb_response->set_remote_ip("1.2.3.4:80"); 595 pb_response->set_remote_ip("1.2.3.4:80");
581 596
582 pb_resource = expected.add_resources(); 597 pb_resource = expected.add_resources();
583 pb_resource->set_id(1); 598 pb_resource->set_id(1);
584 pb_resource->set_url(kMalwareURL); 599 pb_resource->set_url(kThreatURL);
585 pb_response = pb_resource->mutable_response(); 600 pb_response = pb_resource->mutable_response();
586 pb_response->mutable_firstline()->set_code(200); 601 pb_response->mutable_firstline()->set_code(200);
587 pb_header = pb_response->add_headers(); 602 pb_header = pb_response->add_headers();
588 pb_header->set_name("Content-Type"); 603 pb_header->set_name("Content-Type");
589 pb_header->set_value("image/jpeg"); 604 pb_header->set_value("image/jpeg");
590 pb_response->set_body(kMalwareData); 605 pb_response->set_body(kThreatData);
591 pb_response->set_bodylength(10); 606 std::string threat_data(kThreatData);
592 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95"); 607 pb_response->set_bodylength(threat_data.size());
608 pb_response->set_bodydigest(base::MD5String(threat_data));
593 pb_response->set_remote_ip("1.2.3.4:80"); 609 pb_response->set_remote_ip("1.2.3.4:80");
594 expected.set_complete(true); 610 expected.set_complete(true);
595 611
596 VerifyResults(actual, expected); 612 VerifyResults(actual, expected);
597 } 613 }
598 614
599 // Tests the interaction with the HTTP cache (where the cache is empty). 615 // Tests the interaction with the HTTP cache (where the cache is empty).
600 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) { 616 TEST_F(ThreatDetailsTest, HTTPCacheNoEntries) {
601 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 617 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
602 ui::PAGE_TRANSITION_TYPED, std::string()); 618 ui::PAGE_TRANSITION_TYPED, std::string());
603 619
604 UnsafeResource resource; 620 UnsafeResource resource;
605 InitResource(&resource, true, GURL(kMalwareURL)); 621 InitResource(&resource, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, true,
622 GURL(kThreatURL));
606 623
607 scoped_refptr<ThreatDetailsWrap> report = 624 scoped_refptr<ThreatDetailsWrap> report =
608 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, 625 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource,
609 profile()->GetRequestContext()); 626 profile()->GetRequestContext());
610 627
611 // No call to FillCache 628 // No call to FillCache
612 629
613 // The cache collection starts after the IPC from the DOM is fired. 630 // The cache collection starts after the IPC from the DOM is fired.
614 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 631 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params;
615 report->OnReceivedThreatDOMDetails(params); 632 report->OnReceivedThreatDOMDetails(params);
616 633
617 // Let the cache callbacks complete. 634 // Let the cache callbacks complete.
618 base::RunLoop().RunUntilIdle(); 635 base::RunLoop().RunUntilIdle();
619 636
620 DVLOG(1) << "Getting serialized report"; 637 DVLOG(1) << "Getting serialized report";
621 std::string serialized = WaitForSerializedReport( 638 std::string serialized = WaitForSerializedReport(
622 report.get(), false /* did_proceed*/, -1 /* num_visit */); 639 report.get(), false /* did_proceed*/, -1 /* num_visit */);
623 ClientMalwareReportRequest actual; 640 ClientSafeBrowsingReportRequest actual;
624 actual.ParseFromString(serialized); 641 actual.ParseFromString(serialized);
625 642
626 ClientMalwareReportRequest expected; 643 ClientSafeBrowsingReportRequest expected;
627 expected.set_malware_url(kMalwareURL); 644 expected.set_type(ClientSafeBrowsingReportRequest::CLIENT_SIDE_MALWARE_URL);
645 expected.set_url(kThreatURL);
628 expected.set_page_url(kLandingURL); 646 expected.set_page_url(kLandingURL);
629 expected.set_referrer_url(""); 647 expected.set_referrer_url("");
630 expected.set_did_proceed(false); 648 expected.set_did_proceed(false);
631 649
632 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 650 ClientSafeBrowsingReportRequest::Resource* pb_resource =
651 expected.add_resources();
633 pb_resource->set_id(0); 652 pb_resource->set_id(0);
634 pb_resource->set_url(kLandingURL); 653 pb_resource->set_url(kLandingURL);
635 pb_resource = expected.add_resources(); 654 pb_resource = expected.add_resources();
636 pb_resource->set_id(1); 655 pb_resource->set_id(1);
637 pb_resource->set_url(kMalwareURL); 656 pb_resource->set_url(kThreatURL);
638 expected.set_complete(true); 657 expected.set_complete(true);
639 658
640 VerifyResults(actual, expected); 659 VerifyResults(actual, expected);
641 } 660 }
642 661
643 // Test getting redirects from history service. 662 // Test getting redirects from history service.
644 TEST_F(ThreatDetailsTest, HistoryServiceUrls) { 663 TEST_F(ThreatDetailsTest, HistoryServiceUrls) {
645 // Add content to history service. 664 // Add content to history service.
646 // There are two redirect urls before reacing malware url: 665 // There are two redirect urls before reacing malware url:
647 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL 666 // kFirstRedirectURL -> kSecondRedirectURL -> kThreatURL
648 GURL baseurl(kMalwareURL); 667 GURL baseurl(kThreatURL);
649 history::RedirectList redirects; 668 history::RedirectList redirects;
650 redirects.push_back(GURL(kFirstRedirectURL)); 669 redirects.push_back(GURL(kFirstRedirectURL));
651 redirects.push_back(GURL(kSecondRedirectURL)); 670 redirects.push_back(GURL(kSecondRedirectURL));
652 AddPageToHistory(baseurl, &redirects); 671 AddPageToHistory(baseurl, &redirects);
653 // Wait for history service operation finished. 672 // Wait for history service operation finished.
654 profile()->BlockUntilHistoryProcessesPendingRequests(); 673 profile()->BlockUntilHistoryProcessesPendingRequests();
655 674
656 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 675 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
657 ui::PAGE_TRANSITION_TYPED, std::string()); 676 ui::PAGE_TRANSITION_TYPED, std::string());
658 677
659 UnsafeResource resource; 678 UnsafeResource resource;
660 InitResource(&resource, true, GURL(kMalwareURL)); 679 InitResource(&resource, SB_THREAT_TYPE_URL_MALWARE, true, GURL(kThreatURL));
661 scoped_refptr<ThreatDetailsWrap> report = 680 scoped_refptr<ThreatDetailsWrap> report =
662 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); 681 new ThreatDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL);
663 682
664 // The redirects collection starts after the IPC from the DOM is fired. 683 // The redirects collection starts after the IPC from the DOM is fired.
665 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 684 std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node> params;
666 report->OnReceivedThreatDOMDetails(params); 685 report->OnReceivedThreatDOMDetails(params);
667 686
668 // Let the redirects callbacks complete. 687 // Let the redirects callbacks complete.
669 base::RunLoop().RunUntilIdle(); 688 base::RunLoop().RunUntilIdle();
670 689
671 std::string serialized = WaitForSerializedReport( 690 std::string serialized = WaitForSerializedReport(
672 report.get(), true /* did_proceed*/, 1 /* num_visit */); 691 report.get(), true /* did_proceed*/, 1 /* num_visit */);
673 ClientMalwareReportRequest actual; 692 ClientSafeBrowsingReportRequest actual;
674 actual.ParseFromString(serialized); 693 actual.ParseFromString(serialized);
675 694
676 ClientMalwareReportRequest expected; 695 ClientSafeBrowsingReportRequest expected;
677 expected.set_malware_url(kMalwareURL); 696 expected.set_type(ClientSafeBrowsingReportRequest::URL_MALWARE);
697 expected.set_url(kThreatURL);
678 expected.set_page_url(kLandingURL); 698 expected.set_page_url(kLandingURL);
679 expected.set_referrer_url(""); 699 expected.set_referrer_url("");
680 expected.set_did_proceed(true); 700 expected.set_did_proceed(true);
681 expected.set_repeat_visit(true); 701 expected.set_repeat_visit(true);
682 702
683 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 703 ClientSafeBrowsingReportRequest::Resource* pb_resource =
704 expected.add_resources();
684 pb_resource->set_id(0); 705 pb_resource->set_id(0);
685 pb_resource->set_url(kLandingURL); 706 pb_resource->set_url(kLandingURL);
686 pb_resource = expected.add_resources(); 707 pb_resource = expected.add_resources();
687 pb_resource->set_id(1); 708 pb_resource->set_id(1);
688 pb_resource->set_parent_id(2); 709 pb_resource->set_parent_id(2);
689 pb_resource->set_url(kMalwareURL); 710 pb_resource->set_url(kThreatURL);
690 pb_resource = expected.add_resources(); 711 pb_resource = expected.add_resources();
691 pb_resource->set_id(2); 712 pb_resource->set_id(2);
692 pb_resource->set_parent_id(3); 713 pb_resource->set_parent_id(3);
693 pb_resource->set_url(kSecondRedirectURL); 714 pb_resource->set_url(kSecondRedirectURL);
694 pb_resource = expected.add_resources(); 715 pb_resource = expected.add_resources();
695 pb_resource->set_id(3); 716 pb_resource->set_id(3);
696 pb_resource->set_url(kFirstRedirectURL); 717 pb_resource->set_url(kFirstRedirectURL);
697 718
698 VerifyResults(actual, expected); 719 VerifyResults(actual, expected);
699 } 720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698