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

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

Issue 586793003: Safebrowsing: Honor the metadata from malware fullhash results in SB API 3.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes for sky Created 6 years, 2 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 // This test creates a safebrowsing service using test safebrowsing database 5 // This test creates a safebrowsing service using test safebrowsing database
6 // and a test protocol manager. It is used to test logics in safebrowsing 6 // and a test protocol manager. It is used to test logics in safebrowsing
7 // service. 7 // service.
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h" 23 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/prerender/prerender_manager.h" 24 #include "chrome/browser/prerender/prerender_manager.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/profiles/startup_task_runner_service.h" 27 #include "chrome/browser/profiles/startup_task_runner_service.h"
28 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" 28 #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
29 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 29 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
30 #include "chrome/browser/safe_browsing/database_manager.h" 30 #include "chrome/browser/safe_browsing/database_manager.h"
31 #include "chrome/browser/safe_browsing/metadata.pb.h"
31 #include "chrome/browser/safe_browsing/protocol_manager.h" 32 #include "chrome/browser/safe_browsing/protocol_manager.h"
32 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 33 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
34 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 35 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
35 #include "chrome/browser/safe_browsing/ui_manager.h" 36 #include "chrome/browser/safe_browsing/ui_manager.h"
36 #include "chrome/browser/ui/browser.h" 37 #include "chrome/browser/ui/browser.h"
37 #include "chrome/browser/ui/tabs/tab_strip_model.h" 38 #include "chrome/browser/ui/tabs/tab_strip_model.h"
38 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
39 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 } 495 }
495 496
496 private: 497 private:
497 scoped_ptr<TestSafeBrowsingServiceFactory> sb_factory_; 498 scoped_ptr<TestSafeBrowsingServiceFactory> sb_factory_;
498 TestSafeBrowsingDatabaseFactory db_factory_; 499 TestSafeBrowsingDatabaseFactory db_factory_;
499 TestSBProtocolManagerFactory pm_factory_; 500 TestSBProtocolManagerFactory pm_factory_;
500 501
501 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTest); 502 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceTest);
502 }; 503 };
503 504
505 enum MalwareMetadataTestType {
506 METADATA_NONE,
507 METADATA_LANDING,
508 METADATA_DISTRIBUTION,
509 };
510
511 class SafeBrowsingServiceMetadataTest
512 : public SafeBrowsingServiceTest,
513 public ::testing::WithParamInterface<MalwareMetadataTestType> {
514 public:
515 SafeBrowsingServiceMetadataTest() {}
516
517 virtual void SetUpOnMainThread() OVERRIDE {
518 SafeBrowsingServiceTest::SetUpOnMainThread();
519 g_browser_process->safe_browsing_service()->ui_manager()->AddObserver(
520 &observer_);
521 }
522
523 virtual void TearDownOnMainThread() OVERRIDE {
524 g_browser_process->safe_browsing_service()->ui_manager()->RemoveObserver(
525 &observer_);
526 SafeBrowsingServiceTest::TearDownOnMainThread();
527 }
528
529 void GenUrlFullhashResultWithMetadata(const GURL& url,
530 SBFullHashResult* full_hash) {
531 GenUrlFullhashResult(url, safe_browsing_util::MALWARE, full_hash);
532
533 safe_browsing::MalwarePatternType proto;
534 switch (GetParam()) {
535 case METADATA_NONE:
536 full_hash->metadata = std::string();
537 break;
538 case METADATA_LANDING:
539 proto.set_pattern_type(safe_browsing::MalwarePatternType::LANDING);
540 full_hash->metadata = proto.SerializeAsString();
541 break;
542 case METADATA_DISTRIBUTION:
543 proto.set_pattern_type(safe_browsing::MalwarePatternType::DISTRIBUTION);
544 full_hash->metadata = proto.SerializeAsString();
545 break;
546 }
547 }
548
549 private:
550 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest);
551 };
552
504 namespace { 553 namespace {
505 554
506 const char kEmptyPage[] = "files/empty.html"; 555 const char kEmptyPage[] = "files/empty.html";
507 const char kMalwareFile[] = "files/downloads/dangerous/dangerous.exe"; 556 const char kMalwareFile[] = "files/downloads/dangerous/dangerous.exe";
508 const char kMalwarePage[] = "files/safe_browsing/malware.html"; 557 const char kMalwarePage[] = "files/safe_browsing/malware.html";
558 const char kMalwareIFrame[] = "files/safe_browsing/malware_iframe.html";
559 const char kMalwareImg[] = "files/safe_browsing/malware_image.png";
509 560
510 // This test goes through DownloadResourceHandler. 561 // This test goes through DownloadResourceHandler.
511 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, Malware) { 562 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareMainFrame) {
512 GURL url = test_server()->GetURL(kEmptyPage); 563 GURL url = test_server()->GetURL(kEmptyPage);
513 g_browser_process->safe_browsing_service()->
514 ui_manager()->AddObserver(&observer_);
515 564
516 // After adding the url to safebrowsing database and getfullhash result, 565 // After adding the url to safebrowsing database and getfullhash result,
517 // we should see the interstitial page. 566 // we should see the interstitial page.
518 SBFullHashResult malware_full_hash; 567 SBFullHashResult malware_full_hash;
519 GenUrlFullhashResult(url, safe_browsing_util::MALWARE, &malware_full_hash); 568 GenUrlFullhashResultWithMetadata(url, &malware_full_hash);
520 EXPECT_CALL(observer_, 569 EXPECT_CALL(observer_,
521 OnSafeBrowsingMatch(IsUnsafeResourceFor(url))).Times(1); 570 OnSafeBrowsingMatch(IsUnsafeResourceFor(url))).Times(1);
522 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); 571 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1);
523 SetupResponseForUrl(url, malware_full_hash); 572 SetupResponseForUrl(url, malware_full_hash);
524 ui_test_utils::NavigateToURL(browser(), url); 573 ui_test_utils::NavigateToURL(browser(), url);
574 // All types should show the interstitial.
525 EXPECT_TRUE(ShowingInterstitialPage()); 575 EXPECT_TRUE(ShowingInterstitialPage());
526 g_browser_process->safe_browsing_service()->
527 ui_manager()->RemoveObserver(&observer_);
528 } 576 }
529 577
578 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) {
579 GURL main_url = test_server()->GetURL(kMalwarePage);
580 GURL iframe_url = test_server()->GetURL(kMalwareIFrame);
581
582 // Add the iframe url as malware and then load the parent page.
583 SBFullHashResult malware_full_hash;
584 GenUrlFullhashResultWithMetadata(iframe_url, &malware_full_hash);
585 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(iframe_url)))
586 .Times(1);
587 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url)))
588 .Times(1);
589 SetupResponseForUrl(iframe_url, malware_full_hash);
590 ui_test_utils::NavigateToURL(browser(), main_url);
591 // All types should show the interstitial.
592 EXPECT_TRUE(ShowingInterstitialPage());
593 }
594
595 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareImg) {
596 GURL main_url = test_server()->GetURL(kMalwarePage);
597 GURL img_url = test_server()->GetURL(kMalwareImg);
598
599 // Add the img url as malware and then load the parent page.
600 SBFullHashResult malware_full_hash;
601 GenUrlFullhashResultWithMetadata(img_url, &malware_full_hash);
602 switch (GetParam()) {
603 case METADATA_NONE:
604 case METADATA_DISTRIBUTION:
605 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(img_url)))
606 .Times(1);
607 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(img_url)))
608 .Times(1);
609 break;
610 case METADATA_LANDING:
611 // No interstitial shown, so no notifications expected.
612 break;
613 }
614 SetupResponseForUrl(img_url, malware_full_hash);
615 ui_test_utils::NavigateToURL(browser(), main_url);
616 // Subresource which is tagged as a landing page should not show an
617 // interstitial, the other types should.
618 switch (GetParam()) {
619 case METADATA_NONE:
620 case METADATA_DISTRIBUTION:
621 EXPECT_TRUE(ShowingInterstitialPage());
622 break;
623 case METADATA_LANDING:
624 EXPECT_FALSE(ShowingInterstitialPage());
625 break;
626 }
627 }
628
629 INSTANTIATE_TEST_CASE_P(MaybeSetMetadata,
630 SafeBrowsingServiceMetadataTest,
631 testing::Values(METADATA_NONE,
632 METADATA_LANDING,
633 METADATA_DISTRIBUTION));
634
530 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, DISABLED_MalwareWithWhitelist) { 635 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, DISABLED_MalwareWithWhitelist) {
531 GURL url = test_server()->GetURL(kEmptyPage); 636 GURL url = test_server()->GetURL(kEmptyPage);
532 g_browser_process->safe_browsing_service()-> 637 g_browser_process->safe_browsing_service()->
533 ui_manager()->AddObserver(&observer_); 638 ui_manager()->AddObserver(&observer_);
534 639
535 // After adding the url to safebrowsing database and getfullhash result, 640 // After adding the url to safebrowsing database and getfullhash result,
536 // we should see the interstitial page. 641 // we should see the interstitial page.
537 SBFullHashResult malware_full_hash; 642 SBFullHashResult malware_full_hash;
538 GenUrlFullhashResult(url, safe_browsing_util::MALWARE, &malware_full_hash); 643 GenUrlFullhashResult(url, safe_browsing_util::MALWARE, &malware_full_hash);
539 EXPECT_CALL(observer_, 644 EXPECT_CALL(observer_,
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 content::WindowedNotificationObserver observer( 1109 content::WindowedNotificationObserver observer(
1005 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 1110 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
1006 content::Source<SafeBrowsingDatabaseManager>( 1111 content::Source<SafeBrowsingDatabaseManager>(
1007 sb_service_->database_manager().get())); 1112 sb_service_->database_manager().get()));
1008 BrowserThread::PostTask( 1113 BrowserThread::PostTask(
1009 BrowserThread::IO, 1114 BrowserThread::IO,
1010 FROM_HERE, 1115 FROM_HERE,
1011 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); 1116 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this));
1012 observer.Wait(); 1117 observer.Wait();
1013 } 1118 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_parser_unittest.cc ('k') | chrome/browser/safe_browsing/safe_browsing_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698