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

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

Issue 562603002: Move PageTransition from //content/public/common to //ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 months 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 305
306 // Adds a page to history. 306 // Adds a page to history.
307 // The redirects is the redirect url chain leading to the url. 307 // The redirects is the redirect url chain leading to the url.
308 void AddPageToHistory(const GURL& url, 308 void AddPageToHistory(const GURL& url,
309 history::RedirectList* redirects) { 309 history::RedirectList* redirects) {
310 // The last item of the redirect chain has to be the final url when adding 310 // The last item of the redirect chain has to be the final url when adding
311 // to history backend. 311 // to history backend.
312 redirects->push_back(url); 312 redirects->push_back(url);
313 history_service()->AddPage( 313 history_service()->AddPage(
314 url, base::Time::Now(), reinterpret_cast<history::ContextID>(1), 0, 314 url, base::Time::Now(), reinterpret_cast<history::ContextID>(1), 0,
315 GURL(), *redirects, content::PAGE_TRANSITION_TYPED, 315 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED,
316 history::SOURCE_BROWSED, false); 316 history::SOURCE_BROWSED, false);
317 } 317 }
318 318
319 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; 319 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_;
320 }; 320 };
321 321
322 // Tests creating a simple malware report. 322 // Tests creating a simple malware report.
323 TEST_F(MalwareDetailsTest, MalwareSubResource) { 323 TEST_F(MalwareDetailsTest, MalwareSubResource) {
324 // Start a load. 324 // Start a load.
325 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 325 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
326 content::PAGE_TRANSITION_TYPED, std::string()); 326 ui::PAGE_TRANSITION_TYPED, std::string());
327 327
328 UnsafeResource resource; 328 UnsafeResource resource;
329 InitResource(&resource, true, GURL(kMalwareURL)); 329 InitResource(&resource, true, GURL(kMalwareURL));
330 330
331 scoped_refptr<MalwareDetailsWrap> report = 331 scoped_refptr<MalwareDetailsWrap> report =
332 new MalwareDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL); 332 new MalwareDetailsWrap(ui_manager_.get(), web_contents(), resource, NULL);
333 333
334 std::string serialized = WaitForSerializedReport(report.get()); 334 std::string serialized = WaitForSerializedReport(report.get());
335 335
336 ClientMalwareReportRequest actual; 336 ClientMalwareReportRequest actual;
(...skipping 11 matching lines...) Expand all
348 pb_resource->set_id(1); 348 pb_resource->set_id(1);
349 pb_resource->set_url(kMalwareURL); 349 pb_resource->set_url(kMalwareURL);
350 350
351 VerifyResults(actual, expected); 351 VerifyResults(actual, expected);
352 } 352 }
353 353
354 // Tests creating a simple malware report where the subresource has a 354 // Tests creating a simple malware report where the subresource has a
355 // different original_url. 355 // different original_url.
356 TEST_F(MalwareDetailsTest, MalwareSubResourceWithOriginalUrl) { 356 TEST_F(MalwareDetailsTest, MalwareSubResourceWithOriginalUrl) {
357 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 357 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
358 content::PAGE_TRANSITION_TYPED, std::string()); 358 ui::PAGE_TRANSITION_TYPED, std::string());
359 359
360 UnsafeResource resource; 360 UnsafeResource resource;
361 InitResource(&resource, true, GURL(kMalwareURL)); 361 InitResource(&resource, true, GURL(kMalwareURL));
362 resource.original_url = GURL(kOriginalLandingURL); 362 resource.original_url = GURL(kOriginalLandingURL);
363 363
364 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 364 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
365 ui_manager_.get(), web_contents(), resource, NULL); 365 ui_manager_.get(), web_contents(), resource, NULL);
366 366
367 std::string serialized = WaitForSerializedReport(report.get()); 367 std::string serialized = WaitForSerializedReport(report.get());
368 368
(...skipping 19 matching lines...) Expand all
388 // The Resource for kMmalwareUrl should have the Resource for 388 // The Resource for kMmalwareUrl should have the Resource for
389 // kOriginalLandingURL (with id 1) as parent. 389 // kOriginalLandingURL (with id 1) as parent.
390 pb_resource->set_parent_id(1); 390 pb_resource->set_parent_id(1);
391 391
392 VerifyResults(actual, expected); 392 VerifyResults(actual, expected);
393 } 393 }
394 394
395 // Tests creating a malware report with data from the renderer. 395 // Tests creating a malware report with data from the renderer.
396 TEST_F(MalwareDetailsTest, MalwareDOMDetails) { 396 TEST_F(MalwareDetailsTest, MalwareDOMDetails) {
397 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 397 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
398 content::PAGE_TRANSITION_TYPED, std::string()); 398 ui::PAGE_TRANSITION_TYPED, std::string());
399 399
400 UnsafeResource resource; 400 UnsafeResource resource;
401 InitResource(&resource, true, GURL(kMalwareURL)); 401 InitResource(&resource, true, GURL(kMalwareURL));
402 402
403 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 403 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
404 ui_manager_.get(), web_contents(), resource, NULL); 404 ui_manager_.get(), web_contents(), resource, NULL);
405 405
406 // Send a message from the DOM, with 2 nodes, a parent and a child. 406 // Send a message from the DOM, with 2 nodes, a parent and a child.
407 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 407 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
408 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node; 408 SafeBrowsingHostMsg_MalwareDOMDetails_Node child_node;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 pb_resource->set_url(kDOMParentURL); 443 pb_resource->set_url(kDOMParentURL);
444 pb_resource->add_child_ids(2); 444 pb_resource->add_child_ids(2);
445 expected.set_complete(false); // Since the cache was missing. 445 expected.set_complete(false); // Since the cache was missing.
446 446
447 VerifyResults(actual, expected); 447 VerifyResults(actual, expected);
448 } 448 }
449 449
450 // Verify that https:// urls are dropped. 450 // Verify that https:// urls are dropped.
451 TEST_F(MalwareDetailsTest, NotPublicUrl) { 451 TEST_F(MalwareDetailsTest, NotPublicUrl) {
452 controller().LoadURL(GURL(kHttpsURL), content::Referrer(), 452 controller().LoadURL(GURL(kHttpsURL), content::Referrer(),
453 content::PAGE_TRANSITION_TYPED, std::string()); 453 ui::PAGE_TRANSITION_TYPED, std::string());
454 UnsafeResource resource; 454 UnsafeResource resource;
455 InitResource(&resource, true, GURL(kMalwareURL)); 455 InitResource(&resource, true, GURL(kMalwareURL));
456 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 456 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
457 ui_manager_.get(), web_contents(), resource, NULL); 457 ui_manager_.get(), web_contents(), resource, NULL);
458 458
459 std::string serialized = WaitForSerializedReport(report.get()); 459 std::string serialized = WaitForSerializedReport(report.get());
460 ClientMalwareReportRequest actual; 460 ClientMalwareReportRequest actual;
461 actual.ParseFromString(serialized); 461 actual.ParseFromString(serialized);
462 462
463 ClientMalwareReportRequest expected; 463 ClientMalwareReportRequest expected;
464 expected.set_malware_url(kMalwareURL); // No page_url 464 expected.set_malware_url(kMalwareURL); // No page_url
465 expected.set_referrer_url(""); 465 expected.set_referrer_url("");
466 466
467 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); 467 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources();
468 pb_resource->set_url(kMalwareURL); // Only one resource 468 pb_resource->set_url(kMalwareURL); // Only one resource
469 469
470 VerifyResults(actual, expected); 470 VerifyResults(actual, expected);
471 } 471 }
472 472
473 // Tests creating a malware report where there are redirect urls to an unsafe 473 // Tests creating a malware report where there are redirect urls to an unsafe
474 // resource url 474 // resource url
475 TEST_F(MalwareDetailsTest, MalwareWithRedirectUrl) { 475 TEST_F(MalwareDetailsTest, MalwareWithRedirectUrl) {
476 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 476 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
477 content::PAGE_TRANSITION_TYPED, std::string()); 477 ui::PAGE_TRANSITION_TYPED, std::string());
478 478
479 UnsafeResource resource; 479 UnsafeResource resource;
480 InitResource(&resource, true, GURL(kMalwareURL)); 480 InitResource(&resource, true, GURL(kMalwareURL));
481 resource.original_url = GURL(kOriginalLandingURL); 481 resource.original_url = GURL(kOriginalLandingURL);
482 482
483 // add some redirect urls 483 // add some redirect urls
484 resource.redirect_urls.push_back(GURL(kFirstRedirectURL)); 484 resource.redirect_urls.push_back(GURL(kFirstRedirectURL));
485 resource.redirect_urls.push_back(GURL(kSecondRedirectURL)); 485 resource.redirect_urls.push_back(GURL(kSecondRedirectURL));
486 resource.redirect_urls.push_back(GURL(kMalwareURL)); 486 resource.redirect_urls.push_back(GURL(kMalwareURL));
487 487
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 pb_resource->set_id(4); 519 pb_resource->set_id(4);
520 pb_resource->set_url(kSecondRedirectURL); 520 pb_resource->set_url(kSecondRedirectURL);
521 pb_resource->set_parent_id(3); 521 pb_resource->set_parent_id(3);
522 522
523 VerifyResults(actual, expected); 523 VerifyResults(actual, expected);
524 } 524 }
525 525
526 // Tests the interaction with the HTTP cache. 526 // Tests the interaction with the HTTP cache.
527 TEST_F(MalwareDetailsTest, HTTPCache) { 527 TEST_F(MalwareDetailsTest, HTTPCache) {
528 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 528 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
529 content::PAGE_TRANSITION_TYPED, std::string()); 529 ui::PAGE_TRANSITION_TYPED, std::string());
530 530
531 UnsafeResource resource; 531 UnsafeResource resource;
532 InitResource(&resource, true, GURL(kMalwareURL)); 532 InitResource(&resource, true, GURL(kMalwareURL));
533 533
534 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 534 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
535 ui_manager_.get(), web_contents(), resource, 535 ui_manager_.get(), web_contents(), resource,
536 profile()->GetRequestContext()); 536 profile()->GetRequestContext());
537 537
538 BrowserThread::PostTask( 538 BrowserThread::PostTask(
539 BrowserThread::IO, FROM_HERE, 539 BrowserThread::IO, FROM_HERE,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95"); 591 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95");
592 pb_response->set_remote_ip("1.2.3.4:80"); 592 pb_response->set_remote_ip("1.2.3.4:80");
593 expected.set_complete(true); 593 expected.set_complete(true);
594 594
595 VerifyResults(actual, expected); 595 VerifyResults(actual, expected);
596 } 596 }
597 597
598 // Tests the interaction with the HTTP cache (where the cache is empty). 598 // Tests the interaction with the HTTP cache (where the cache is empty).
599 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { 599 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) {
600 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 600 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
601 content::PAGE_TRANSITION_TYPED, std::string()); 601 ui::PAGE_TRANSITION_TYPED, std::string());
602 602
603 UnsafeResource resource; 603 UnsafeResource resource;
604 InitResource(&resource, true, GURL(kMalwareURL)); 604 InitResource(&resource, true, GURL(kMalwareURL));
605 605
606 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 606 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
607 ui_manager_.get(), web_contents(), resource, 607 ui_manager_.get(), web_contents(), resource,
608 profile()->GetRequestContext()); 608 profile()->GetRequestContext());
609 609
610 // No call to FillCache 610 // No call to FillCache
611 611
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL 644 // kFirstRedirectURL -> kSecondRedirectURL -> kMalwareURL
645 GURL baseurl(kMalwareURL); 645 GURL baseurl(kMalwareURL);
646 history::RedirectList redirects; 646 history::RedirectList redirects;
647 redirects.push_back(GURL(kFirstRedirectURL)); 647 redirects.push_back(GURL(kFirstRedirectURL));
648 redirects.push_back(GURL(kSecondRedirectURL)); 648 redirects.push_back(GURL(kSecondRedirectURL));
649 AddPageToHistory(baseurl, &redirects); 649 AddPageToHistory(baseurl, &redirects);
650 // Wait for history service operation finished. 650 // Wait for history service operation finished.
651 profile()->BlockUntilHistoryProcessesPendingRequests(); 651 profile()->BlockUntilHistoryProcessesPendingRequests();
652 652
653 controller().LoadURL(GURL(kLandingURL), content::Referrer(), 653 controller().LoadURL(GURL(kLandingURL), content::Referrer(),
654 content::PAGE_TRANSITION_TYPED, std::string()); 654 ui::PAGE_TRANSITION_TYPED, std::string());
655 655
656 UnsafeResource resource; 656 UnsafeResource resource;
657 InitResource(&resource, true, GURL(kMalwareURL)); 657 InitResource(&resource, true, GURL(kMalwareURL));
658 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap( 658 scoped_refptr<MalwareDetailsWrap> report = new MalwareDetailsWrap(
659 ui_manager_.get(), web_contents(), resource, NULL); 659 ui_manager_.get(), web_contents(), resource, NULL);
660 660
661 // The redirects collection starts after the IPC from the DOM is fired. 661 // The redirects collection starts after the IPC from the DOM is fired.
662 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params; 662 std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node> params;
663 report->OnReceivedMalwareDOMDetails(params); 663 report->OnReceivedMalwareDOMDetails(params);
664 664
(...skipping 19 matching lines...) Expand all
684 pb_resource = expected.add_resources(); 684 pb_resource = expected.add_resources();
685 pb_resource->set_id(2); 685 pb_resource->set_id(2);
686 pb_resource->set_parent_id(3); 686 pb_resource->set_parent_id(3);
687 pb_resource->set_url(kSecondRedirectURL); 687 pb_resource->set_url(kSecondRedirectURL);
688 pb_resource = expected.add_resources(); 688 pb_resource = expected.add_resources();
689 pb_resource->set_id(3); 689 pb_resource->set_id(3);
690 pb_resource->set_url(kFirstRedirectURL); 690 pb_resource->set_url(kFirstRedirectURL);
691 691
692 VerifyResults(actual, expected); 692 VerifyResults(actual, expected);
693 } 693 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698