| 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 // 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/test/thread_test_helper.h" | 22 #include "base/test/thread_test_helper.h" |
| 22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 23 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" | 24 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" |
| 24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 26 #include "chrome/browser/prerender/prerender_manager.h" | 28 #include "chrome/browser/prerender/prerender_manager.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
| 29 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 31 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 30 #include "chrome/browser/safe_browsing/database_manager.h" | 32 #include "chrome/browser/safe_browsing/database_manager.h" |
| 31 #include "chrome/browser/safe_browsing/local_database_manager.h" | 33 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 32 #include "chrome/browser/safe_browsing/metadata.pb.h" | 34 #include "chrome/browser/safe_browsing/metadata.pb.h" |
| 33 #include "chrome/browser/safe_browsing/protocol_manager.h" | 35 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 34 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 36 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 36 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 38 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 37 #include "chrome/browser/safe_browsing/ui_manager.h" | 39 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 38 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
| 41 #include "chrome/browser/ui/browser_navigator_params.h" |
| 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 42 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 40 #include "chrome/common/chrome_paths.h" | 43 #include "chrome/common/chrome_paths.h" |
| 41 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/test/base/in_process_browser_test.h" | 46 #include "chrome/test/base/in_process_browser_test.h" |
| 44 #include "chrome/test/base/ui_test_utils.h" | 47 #include "chrome/test/base/ui_test_utils.h" |
| 45 #include "components/bookmarks/browser/startup_task_runner_service.h" | 48 #include "components/bookmarks/browser/startup_task_runner_service.h" |
| 49 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 46 #include "content/public/browser/interstitial_page.h" | 50 #include "content/public/browser/interstitial_page.h" |
| 51 #include "content/public/browser/navigation_entry.h" |
| 52 #include "content/public/browser/render_frame_host.h" |
| 47 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 54 #include "content/public/test/browser_test_utils.h" |
| 48 #include "net/cookies/cookie_store.h" | 55 #include "net/cookies/cookie_store.h" |
| 49 #include "net/cookies/cookie_util.h" | 56 #include "net/cookies/cookie_util.h" |
| 50 #include "net/test/embedded_test_server/embedded_test_server.h" | 57 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 51 #include "net/test/embedded_test_server/http_request.h" | 58 #include "net/test/embedded_test_server/http_request.h" |
| 52 #include "net/test/embedded_test_server/http_response.h" | 59 #include "net/test/embedded_test_server/http_response.h" |
| 53 #include "sql/connection.h" | 60 #include "sql/connection.h" |
| 54 #include "sql/statement.h" | 61 #include "sql/statement.h" |
| 55 #include "testing/gmock/include/gmock/gmock.h" | 62 #include "testing/gmock/include/gmock/gmock.h" |
| 56 #include "url/gurl.h" | 63 #include "url/gurl.h" |
| 57 | 64 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 using content::InterstitialPage; | 75 using content::InterstitialPage; |
| 69 using content::WebContents; | 76 using content::WebContents; |
| 70 using ::testing::_; | 77 using ::testing::_; |
| 71 using ::testing::Mock; | 78 using ::testing::Mock; |
| 72 using ::testing::StrictMock; | 79 using ::testing::StrictMock; |
| 73 | 80 |
| 74 namespace safe_browsing { | 81 namespace safe_browsing { |
| 75 | 82 |
| 76 namespace { | 83 namespace { |
| 77 | 84 |
| 85 const char kEmptyPage[] = "/empty.html"; |
| 86 const char kMalwareFile[] = "/downloads/dangerous/dangerous.exe"; |
| 87 const char kMalwarePage[] = "/safe_browsing/malware.html"; |
| 88 const char kMalwareDelayedLoadsPage[] = |
| 89 "/safe_browsing/malware_delayed_loads.html"; |
| 90 const char kMalwareIFrame[] = "/safe_browsing/malware_iframe.html"; |
| 91 const char kMalwareImg[] = "/safe_browsing/malware_image.png"; |
| 92 const char kNeverCompletesPath[] = "/never_completes"; |
| 93 |
| 94 class NeverCompletingHttpResponse : public net::test_server::HttpResponse { |
| 95 public: |
| 96 ~NeverCompletingHttpResponse() override {} |
| 97 |
| 98 void SendResponse( |
| 99 const net::test_server::SendBytesCallback& send, |
| 100 const net::test_server::SendCompleteCallback& done) override { |
| 101 // Do nothing. |done| is never called. |
| 102 } |
| 103 }; |
| 104 |
| 105 scoped_ptr<net::test_server::HttpResponse> HandleNeverCompletingRequests( |
| 106 const net::test_server::HttpRequest& request) { |
| 107 if (!base::StartsWith(request.relative_url, kNeverCompletesPath, |
| 108 base::CompareCase::SENSITIVE)) |
| 109 return nullptr; |
| 110 return make_scoped_ptr(new NeverCompletingHttpResponse()); |
| 111 } |
| 112 |
| 78 void InvokeFullHashCallback( | 113 void InvokeFullHashCallback( |
| 79 SafeBrowsingProtocolManager::FullHashCallback callback, | 114 SafeBrowsingProtocolManager::FullHashCallback callback, |
| 80 const std::vector<SBFullHashResult>& result) { | 115 const std::vector<SBFullHashResult>& result) { |
| 81 callback.Run(result, base::TimeDelta::FromMinutes(45)); | 116 callback.Run(result, base::TimeDelta::FromMinutes(45)); |
| 82 } | 117 } |
| 83 | 118 |
| 119 class FakeSafeBrowsingUIManager : public SafeBrowsingUIManager { |
| 120 public: |
| 121 explicit FakeSafeBrowsingUIManager(SafeBrowsingService* service) |
| 122 : SafeBrowsingUIManager(service) {} |
| 123 |
| 124 void MaybeReportSafeBrowsingHit( |
| 125 const safe_browsing::HitReport& hit_report) override { |
| 126 EXPECT_FALSE(got_hit_report_); |
| 127 got_hit_report_ = true; |
| 128 hit_report_ = hit_report; |
| 129 SafeBrowsingUIManager::MaybeReportSafeBrowsingHit(hit_report); |
| 130 } |
| 131 |
| 132 bool got_hit_report_ = false; |
| 133 safe_browsing::HitReport hit_report_; |
| 134 |
| 135 private: |
| 136 ~FakeSafeBrowsingUIManager() override {} |
| 137 }; |
| 138 |
| 84 class FakeSafeBrowsingService : public SafeBrowsingService { | 139 class FakeSafeBrowsingService : public SafeBrowsingService { |
| 85 public: | 140 public: |
| 86 explicit FakeSafeBrowsingService(const std::string& url_prefix) | 141 explicit FakeSafeBrowsingService(const std::string& url_prefix) |
| 87 : url_prefix_(url_prefix) {} | 142 : url_prefix_(url_prefix) {} |
| 88 | 143 |
| 89 SafeBrowsingProtocolConfig GetProtocolConfig() const override { | 144 SafeBrowsingProtocolConfig GetProtocolConfig() const override { |
| 90 SafeBrowsingProtocolConfig config; | 145 SafeBrowsingProtocolConfig config; |
| 91 config.url_prefix = url_prefix_; | 146 config.url_prefix = url_prefix_; |
| 92 // Makes sure the auto update is not triggered. The tests will force the | 147 // Makes sure the auto update is not triggered. The tests will force the |
| 93 // update when needed. | 148 // update when needed. |
| 94 config.disable_auto_update = true; | 149 config.disable_auto_update = true; |
| 95 config.client_name = "browser_tests"; | 150 config.client_name = "browser_tests"; |
| 96 return config; | 151 return config; |
| 97 } | 152 } |
| 98 | 153 |
| 154 protected: |
| 155 SafeBrowsingUIManager* CreateUIManager() override { |
| 156 return new FakeSafeBrowsingUIManager(this); |
| 157 } |
| 158 |
| 99 private: | 159 private: |
| 100 ~FakeSafeBrowsingService() override {} | 160 ~FakeSafeBrowsingService() override {} |
| 101 | 161 |
| 102 std::string url_prefix_; | 162 std::string url_prefix_; |
| 103 | 163 |
| 104 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); | 164 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); |
| 105 }; | 165 }; |
| 106 | 166 |
| 107 // Factory that creates FakeSafeBrowsingService instances. | 167 // Factory that creates FakeSafeBrowsingService instances. |
| 108 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { | 168 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 512 |
| 453 void TearDownOnMainThread() override { | 513 void TearDownOnMainThread() override { |
| 454 g_browser_process->safe_browsing_service()->ui_manager()->RemoveObserver( | 514 g_browser_process->safe_browsing_service()->ui_manager()->RemoveObserver( |
| 455 &observer_); | 515 &observer_); |
| 456 InProcessBrowserTest::TearDownOnMainThread(); | 516 InProcessBrowserTest::TearDownOnMainThread(); |
| 457 } | 517 } |
| 458 | 518 |
| 459 void SetUpInProcessBrowserTestFixture() override { | 519 void SetUpInProcessBrowserTestFixture() override { |
| 460 base::FilePath test_data_dir; | 520 base::FilePath test_data_dir; |
| 461 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 521 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 522 embedded_test_server()->RegisterRequestHandler( |
| 523 base::Bind(&HandleNeverCompletingRequests)); |
| 462 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 524 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 463 ASSERT_TRUE(embedded_test_server()->Start()); | 525 ASSERT_TRUE(embedded_test_server()->Start()); |
| 464 } | 526 } |
| 465 | 527 |
| 466 // This will setup the "url" prefix in database and prepare protocol manager | 528 // This will setup the "url" prefix in database and prepare protocol manager |
| 467 // to respond with |full_hash|, as well as other |full_hash|es previously set | 529 // to respond with |full_hash|, as well as other |full_hash|es previously set |
| 468 // via this call, on GetFullHash requests. | 530 // via this call, on GetFullHash requests. |
| 469 void SetupResponseForUrl(const GURL& url, const SBFullHashResult& full_hash) { | 531 void SetupResponseForUrl(const GURL& url, const SBFullHashResult& full_hash) { |
| 470 std::vector<SBPrefix> prefix_hits; | 532 std::vector<SBPrefix> prefix_hits; |
| 471 prefix_hits.push_back(full_hash.hash.prefix); | 533 prefix_hits.push_back(full_hash.hash.prefix); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 g_browser_process->safe_browsing_service(); | 578 g_browser_process->safe_browsing_service(); |
| 517 | 579 |
| 518 // A CSD service should already exist. | 580 // A CSD service should already exist. |
| 519 EXPECT_TRUE(sb_service->csd_service_); | 581 EXPECT_TRUE(sb_service->csd_service_); |
| 520 | 582 |
| 521 sb_service->csd_service_.reset(csd_service); | 583 sb_service->csd_service_.reset(csd_service); |
| 522 sb_service->RefreshState(); | 584 sb_service->RefreshState(); |
| 523 #endif | 585 #endif |
| 524 } | 586 } |
| 525 | 587 |
| 588 FakeSafeBrowsingUIManager* ui_manager() { |
| 589 return static_cast<FakeSafeBrowsingUIManager*>( |
| 590 g_browser_process->safe_browsing_service()->ui_manager().get()); |
| 591 } |
| 592 bool got_hit_report() { return ui_manager()->got_hit_report_; } |
| 593 const safe_browsing::HitReport& hit_report() { |
| 594 return ui_manager()->hit_report_; |
| 595 } |
| 596 |
| 526 protected: | 597 protected: |
| 527 StrictMock<MockObserver> observer_; | 598 StrictMock<MockObserver> observer_; |
| 528 | 599 |
| 529 // Temporary profile dir for test cases that create a second profile. This is | 600 // Temporary profile dir for test cases that create a second profile. This is |
| 530 // owned by the SafeBrowsingServiceTest object so that it will not get | 601 // owned by the SafeBrowsingServiceTest object so that it will not get |
| 531 // destructed until after the test Browser has been torn down, since the | 602 // destructed until after the test Browser has been torn down, since the |
| 532 // ImportantFileWriter may still be modifying it after the Profile object has | 603 // ImportantFileWriter may still be modifying it after the Profile object has |
| 533 // been destroyed. | 604 // been destroyed. |
| 534 base::ScopedTempDir temp_profile_dir_; | 605 base::ScopedTempDir temp_profile_dir_; |
| 535 | 606 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 proto.set_pattern_type(MalwarePatternType::DISTRIBUTION); | 666 proto.set_pattern_type(MalwarePatternType::DISTRIBUTION); |
| 596 full_hash->metadata = proto.SerializeAsString(); | 667 full_hash->metadata = proto.SerializeAsString(); |
| 597 break; | 668 break; |
| 598 } | 669 } |
| 599 } | 670 } |
| 600 | 671 |
| 601 private: | 672 private: |
| 602 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); | 673 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); |
| 603 }; | 674 }; |
| 604 | 675 |
| 605 namespace { | |
| 606 | |
| 607 const char kEmptyPage[] = "/empty.html"; | |
| 608 const char kMalwareFile[] = "/downloads/dangerous/dangerous.exe"; | |
| 609 const char kMalwarePage[] = "/safe_browsing/malware.html"; | |
| 610 const char kMalwareIFrame[] = "/safe_browsing/malware_iframe.html"; | |
| 611 const char kMalwareImg[] = "/safe_browsing/malware_image.png"; | |
| 612 | |
| 613 // This test goes through DownloadResourceHandler. | |
| 614 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareMainFrame) { | 676 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareMainFrame) { |
| 615 GURL url = embedded_test_server()->GetURL(kEmptyPage); | 677 GURL url = embedded_test_server()->GetURL(kEmptyPage); |
| 616 | 678 |
| 617 // After adding the url to safebrowsing database and getfullhash result, | 679 // After adding the url to safebrowsing database and getfullhash result, |
| 618 // we should see the interstitial page. | 680 // we should see the interstitial page. |
| 619 SBFullHashResult malware_full_hash; | 681 SBFullHashResult malware_full_hash; |
| 620 GenUrlFullhashResultWithMetadata(url, &malware_full_hash); | 682 GenUrlFullhashResultWithMetadata(url, &malware_full_hash); |
| 621 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); | 683 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); |
| 622 SetupResponseForUrl(url, malware_full_hash); | 684 SetupResponseForUrl(url, malware_full_hash); |
| 623 ui_test_utils::NavigateToURL(browser(), url); | 685 ui_test_utils::NavigateToURL(browser(), url); |
| 624 // All types should show the interstitial. | 686 // All types should show the interstitial. |
| 625 EXPECT_TRUE(ShowingInterstitialPage()); | 687 EXPECT_TRUE(ShowingInterstitialPage()); |
| 688 |
| 689 EXPECT_TRUE(got_hit_report()); |
| 690 EXPECT_EQ(url, hit_report().malicious_url); |
| 691 EXPECT_EQ(url, hit_report().page_url); |
| 692 EXPECT_EQ(GURL(), hit_report().referrer_url); |
| 693 EXPECT_FALSE(hit_report().is_subresource); |
| 626 } | 694 } |
| 627 | 695 |
| 628 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) { | 696 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareIFrame) { |
| 629 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 697 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
| 630 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); | 698 GURL iframe_url = embedded_test_server()->GetURL(kMalwareIFrame); |
| 631 | 699 |
| 632 // Add the iframe url as malware and then load the parent page. | 700 // Add the iframe url as malware and then load the parent page. |
| 633 SBFullHashResult malware_full_hash; | 701 SBFullHashResult malware_full_hash; |
| 634 GenUrlFullhashResultWithMetadata(iframe_url, &malware_full_hash); | 702 GenUrlFullhashResultWithMetadata(iframe_url, &malware_full_hash); |
| 635 EXPECT_CALL(observer_, | 703 EXPECT_CALL(observer_, |
| 636 OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))).Times(1); | 704 OnSafeBrowsingHit(IsUnsafeResourceFor(iframe_url))).Times(1); |
| 637 SetupResponseForUrl(iframe_url, malware_full_hash); | 705 SetupResponseForUrl(iframe_url, malware_full_hash); |
| 638 ui_test_utils::NavigateToURL(browser(), main_url); | 706 ui_test_utils::NavigateToURL(browser(), main_url); |
| 639 // All types should show the interstitial. | 707 // All types should show the interstitial. |
| 640 EXPECT_TRUE(ShowingInterstitialPage()); | 708 EXPECT_TRUE(ShowingInterstitialPage()); |
| 709 |
| 710 EXPECT_TRUE(got_hit_report()); |
| 711 EXPECT_EQ(iframe_url, hit_report().malicious_url); |
| 712 EXPECT_EQ(main_url, hit_report().page_url); |
| 713 EXPECT_EQ(GURL(), hit_report().referrer_url); |
| 714 EXPECT_TRUE(hit_report().is_subresource); |
| 641 } | 715 } |
| 642 | 716 |
| 643 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareImg) { | 717 IN_PROC_BROWSER_TEST_P(SafeBrowsingServiceMetadataTest, MalwareImg) { |
| 644 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 718 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
| 645 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | 719 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
| 646 | 720 |
| 647 // Add the img url as malware and then load the parent page. | 721 // Add the img url as malware and then load the parent page. |
| 648 SBFullHashResult malware_full_hash; | 722 SBFullHashResult malware_full_hash; |
| 649 GenUrlFullhashResultWithMetadata(img_url, &malware_full_hash); | 723 GenUrlFullhashResultWithMetadata(img_url, &malware_full_hash); |
| 650 switch (GetParam()) { | 724 switch (GetParam()) { |
| 651 case METADATA_NONE: // Falls through. | 725 case METADATA_NONE: // Falls through. |
| 652 case METADATA_DISTRIBUTION: | 726 case METADATA_DISTRIBUTION: |
| 653 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(img_url))) | 727 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(img_url))) |
| 654 .Times(1); | 728 .Times(1); |
| 655 break; | 729 break; |
| 656 case METADATA_LANDING: | 730 case METADATA_LANDING: |
| 657 // No interstitial shown, so no notifications expected. | 731 // No interstitial shown, so no notifications expected. |
| 658 break; | 732 break; |
| 659 } | 733 } |
| 660 SetupResponseForUrl(img_url, malware_full_hash); | 734 SetupResponseForUrl(img_url, malware_full_hash); |
| 661 ui_test_utils::NavigateToURL(browser(), main_url); | 735 ui_test_utils::NavigateToURL(browser(), main_url); |
| 662 // Subresource which is tagged as a landing page should not show an | 736 // Subresource which is tagged as a landing page should not show an |
| 663 // interstitial, the other types should. | 737 // interstitial, the other types should. |
| 664 switch (GetParam()) { | 738 switch (GetParam()) { |
| 665 case METADATA_NONE: | 739 case METADATA_NONE: |
| 666 case METADATA_DISTRIBUTION: | 740 case METADATA_DISTRIBUTION: |
| 667 EXPECT_TRUE(ShowingInterstitialPage()); | 741 EXPECT_TRUE(ShowingInterstitialPage()); |
| 742 EXPECT_TRUE(got_hit_report()); |
| 743 EXPECT_EQ(img_url, hit_report().malicious_url); |
| 744 EXPECT_EQ(main_url, hit_report().page_url); |
| 745 EXPECT_EQ(GURL(), hit_report().referrer_url); |
| 746 EXPECT_TRUE(hit_report().is_subresource); |
| 668 break; | 747 break; |
| 669 case METADATA_LANDING: | 748 case METADATA_LANDING: |
| 670 EXPECT_FALSE(ShowingInterstitialPage()); | 749 EXPECT_FALSE(ShowingInterstitialPage()); |
| 750 EXPECT_FALSE(got_hit_report()); |
| 671 break; | 751 break; |
| 672 } | 752 } |
| 673 } | 753 } |
| 674 | 754 |
| 675 INSTANTIATE_TEST_CASE_P(MaybeSetMetadata, | 755 INSTANTIATE_TEST_CASE_P(MaybeSetMetadata, |
| 676 SafeBrowsingServiceMetadataTest, | 756 SafeBrowsingServiceMetadataTest, |
| 677 testing::Values(METADATA_NONE, | 757 testing::Values(METADATA_NONE, |
| 678 METADATA_LANDING, | 758 METADATA_LANDING, |
| 679 METADATA_DISTRIBUTION)); | 759 METADATA_DISTRIBUTION)); |
| 680 | 760 |
| 681 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnwantedImgIgnored) { | 761 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnwantedImgIgnored) { |
| 682 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 762 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
| 683 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | 763 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
| 684 | 764 |
| 685 // Add the img url as coming from a site serving UwS and then load the parent | 765 // Add the img url as coming from a site serving UwS and then load the parent |
| 686 // page. | 766 // page. |
| 687 SBFullHashResult uws_full_hash; | 767 SBFullHashResult uws_full_hash; |
| 688 GenUrlFullhashResult(img_url, UNWANTEDURL, &uws_full_hash); | 768 GenUrlFullhashResult(img_url, UNWANTEDURL, &uws_full_hash); |
| 689 SetupResponseForUrl(img_url, uws_full_hash); | 769 SetupResponseForUrl(img_url, uws_full_hash); |
| 690 | 770 |
| 691 ui_test_utils::NavigateToURL(browser(), main_url); | 771 ui_test_utils::NavigateToURL(browser(), main_url); |
| 692 | 772 |
| 693 EXPECT_FALSE(ShowingInterstitialPage()); | 773 EXPECT_FALSE(ShowingInterstitialPage()); |
| 774 EXPECT_FALSE(got_hit_report()); |
| 694 } | 775 } |
| 695 | 776 |
| 696 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, MalwareWithWhitelist) { | 777 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, MalwareWithWhitelist) { |
| 697 GURL url = embedded_test_server()->GetURL(kEmptyPage); | 778 GURL url = embedded_test_server()->GetURL(kEmptyPage); |
| 698 | 779 |
| 699 // After adding the url to safebrowsing database and getfullhash result, | 780 // After adding the url to safebrowsing database and getfullhash result, |
| 700 // we should see the interstitial page. | 781 // we should see the interstitial page. |
| 701 SBFullHashResult malware_full_hash; | 782 SBFullHashResult malware_full_hash; |
| 702 GenUrlFullhashResult(url, MALWARE, &malware_full_hash); | 783 GenUrlFullhashResult(url, MALWARE, &malware_full_hash); |
| 703 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); | 784 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 } set_prefetch_for_test(true); | 833 } set_prefetch_for_test(true); |
| 753 | 834 |
| 754 // Even though we have added this uri to the safebrowsing database and | 835 // Even though we have added this uri to the safebrowsing database and |
| 755 // getfullhash result, we should not see the interstitial page since the | 836 // getfullhash result, we should not see the interstitial page since the |
| 756 // only malware was a prefetch target. | 837 // only malware was a prefetch target. |
| 757 SBFullHashResult malware_full_hash; | 838 SBFullHashResult malware_full_hash; |
| 758 GenUrlFullhashResult(malware_url, MALWARE, &malware_full_hash); | 839 GenUrlFullhashResult(malware_url, MALWARE, &malware_full_hash); |
| 759 SetupResponseForUrl(malware_url, malware_full_hash); | 840 SetupResponseForUrl(malware_url, malware_full_hash); |
| 760 ui_test_utils::NavigateToURL(browser(), url); | 841 ui_test_utils::NavigateToURL(browser(), url); |
| 761 EXPECT_FALSE(ShowingInterstitialPage()); | 842 EXPECT_FALSE(ShowingInterstitialPage()); |
| 843 EXPECT_FALSE(got_hit_report()); |
| 762 Mock::VerifyAndClear(&observer_); | 844 Mock::VerifyAndClear(&observer_); |
| 763 | 845 |
| 764 // However, when we navigate to the malware page, we should still get | 846 // However, when we navigate to the malware page, we should still get |
| 765 // the interstitial. | 847 // the interstitial. |
| 766 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) | 848 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) |
| 767 .Times(1); | 849 .Times(1); |
| 768 ui_test_utils::NavigateToURL(browser(), malware_url); | 850 ui_test_utils::NavigateToURL(browser(), malware_url); |
| 769 EXPECT_TRUE(ShowingInterstitialPage()); | 851 EXPECT_TRUE(ShowingInterstitialPage()); |
| 770 Mock::VerifyAndClear(&observer_); | 852 EXPECT_TRUE(got_hit_report()); |
| 771 } | 853 Mock::VerifyAndClear(&observer_); |
| 772 | 854 } |
| 773 } // namespace | 855 |
| 856 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, MainFrameHitWithReferrer) { |
| 857 GURL first_url = embedded_test_server()->GetURL(kEmptyPage); |
| 858 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); |
| 859 |
| 860 SBFullHashResult malware_full_hash; |
| 861 GenUrlFullhashResult(bad_url, MALWARE, &malware_full_hash); |
| 862 SetupResponseForUrl(bad_url, malware_full_hash); |
| 863 |
| 864 // Navigate to first, safe page. |
| 865 ui_test_utils::NavigateToURL(browser(), first_url); |
| 866 EXPECT_FALSE(ShowingInterstitialPage()); |
| 867 EXPECT_FALSE(got_hit_report()); |
| 868 Mock::VerifyAndClear(&observer_); |
| 869 |
| 870 // Navigate to malware page, should show interstitial and have first page in |
| 871 // referrer. |
| 872 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 873 .Times(1); |
| 874 |
| 875 chrome::NavigateParams params(browser(), bad_url, ui::PAGE_TRANSITION_LINK); |
| 876 params.referrer.url = first_url; |
| 877 ui_test_utils::NavigateToURL(¶ms); |
| 878 |
| 879 EXPECT_TRUE(ShowingInterstitialPage()); |
| 880 EXPECT_TRUE(got_hit_report()); |
| 881 EXPECT_EQ(bad_url, hit_report().malicious_url); |
| 882 EXPECT_EQ(bad_url, hit_report().page_url); |
| 883 EXPECT_EQ(first_url, hit_report().referrer_url); |
| 884 EXPECT_FALSE(hit_report().is_subresource); |
| 885 } |
| 886 |
| 887 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
| 888 SubResourceHitWithMainFrameReferrer) { |
| 889 GURL first_url = embedded_test_server()->GetURL(kEmptyPage); |
| 890 GURL second_url = embedded_test_server()->GetURL(kMalwarePage); |
| 891 GURL bad_url = embedded_test_server()->GetURL(kMalwareImg); |
| 892 |
| 893 SBFullHashResult malware_full_hash; |
| 894 GenUrlFullhashResult(bad_url, MALWARE, &malware_full_hash); |
| 895 SetupResponseForUrl(bad_url, malware_full_hash); |
| 896 |
| 897 // Navigate to first, safe page. |
| 898 ui_test_utils::NavigateToURL(browser(), first_url); |
| 899 EXPECT_FALSE(ShowingInterstitialPage()); |
| 900 EXPECT_FALSE(got_hit_report()); |
| 901 Mock::VerifyAndClear(&observer_); |
| 902 |
| 903 // Navigate to page which has malware subresource, should show interstitial |
| 904 // and have first page in referrer. |
| 905 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 906 .Times(1); |
| 907 |
| 908 chrome::NavigateParams params(browser(), second_url, |
| 909 ui::PAGE_TRANSITION_LINK); |
| 910 params.referrer.url = first_url; |
| 911 ui_test_utils::NavigateToURL(¶ms); |
| 912 |
| 913 EXPECT_TRUE(ShowingInterstitialPage()); |
| 914 EXPECT_TRUE(got_hit_report()); |
| 915 EXPECT_EQ(bad_url, hit_report().malicious_url); |
| 916 EXPECT_EQ(second_url, hit_report().page_url); |
| 917 EXPECT_EQ(first_url, hit_report().referrer_url); |
| 918 EXPECT_TRUE(hit_report().is_subresource); |
| 919 } |
| 920 |
| 921 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
| 922 SubResourceHitWithMainFrameRendererInitiatedSlowLoad) { |
| 923 GURL first_url = embedded_test_server()->GetURL(kEmptyPage); |
| 924 GURL second_url = embedded_test_server()->GetURL(kMalwareDelayedLoadsPage); |
| 925 GURL third_url = embedded_test_server()->GetURL(kNeverCompletesPath); |
| 926 GURL bad_url = embedded_test_server()->GetURL(kMalwareImg); |
| 927 |
| 928 SBFullHashResult malware_full_hash; |
| 929 GenUrlFullhashResult(bad_url, MALWARE, &malware_full_hash); |
| 930 SetupResponseForUrl(bad_url, malware_full_hash); |
| 931 |
| 932 // Navigate to first, safe page. |
| 933 ui_test_utils::NavigateToURL(browser(), first_url); |
| 934 EXPECT_FALSE(ShowingInterstitialPage()); |
| 935 EXPECT_FALSE(got_hit_report()); |
| 936 Mock::VerifyAndClear(&observer_); |
| 937 |
| 938 // Navigate to malware page. The malware subresources haven't loaded yet, so |
| 939 // no interstitial should show yet. |
| 940 chrome::NavigateParams params(browser(), second_url, |
| 941 ui::PAGE_TRANSITION_LINK); |
| 942 params.referrer.url = first_url; |
| 943 ui_test_utils::NavigateToURL(¶ms); |
| 944 |
| 945 EXPECT_FALSE(ShowingInterstitialPage()); |
| 946 EXPECT_FALSE(got_hit_report()); |
| 947 Mock::VerifyAndClear(&observer_); |
| 948 |
| 949 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 950 .Times(1); |
| 951 |
| 952 WebContents* contents = |
| 953 browser()->tab_strip_model()->GetActiveWebContents(); |
| 954 content::WindowedNotificationObserver load_stop_observer( |
| 955 content::NOTIFICATION_LOAD_STOP, |
| 956 content::Source<content::NavigationController>( |
| 957 &contents->GetController())); |
| 958 // Run javascript function in the page which starts a timer to load the |
| 959 // malware image, and also starts a renderer-initiated top-level navigation to |
| 960 // a site that does not respond. Should show interstitial and have first page |
| 961 // in referrer. |
| 962 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
| 963 base::ASCIIToUTF16("navigateAndLoadMalwareImage()")); |
| 964 load_stop_observer.Wait(); |
| 965 |
| 966 EXPECT_TRUE(ShowingInterstitialPage()); |
| 967 EXPECT_TRUE(got_hit_report()); |
| 968 // Report URLs should be for the current page, not the pending load. |
| 969 EXPECT_EQ(bad_url, hit_report().malicious_url); |
| 970 EXPECT_EQ(second_url, hit_report().page_url); |
| 971 EXPECT_EQ(first_url, hit_report().referrer_url); |
| 972 EXPECT_TRUE(hit_report().is_subresource); |
| 973 } |
| 974 |
| 975 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
| 976 SubResourceHitWithMainFrameBrowserInitiatedSlowLoad) { |
| 977 GURL first_url = embedded_test_server()->GetURL(kEmptyPage); |
| 978 GURL second_url = embedded_test_server()->GetURL(kMalwareDelayedLoadsPage); |
| 979 GURL third_url = embedded_test_server()->GetURL(kNeverCompletesPath); |
| 980 GURL bad_url = embedded_test_server()->GetURL(kMalwareImg); |
| 981 |
| 982 SBFullHashResult malware_full_hash; |
| 983 GenUrlFullhashResult(bad_url, MALWARE, &malware_full_hash); |
| 984 SetupResponseForUrl(bad_url, malware_full_hash); |
| 985 |
| 986 // Navigate to first, safe page. |
| 987 ui_test_utils::NavigateToURL(browser(), first_url); |
| 988 EXPECT_FALSE(ShowingInterstitialPage()); |
| 989 EXPECT_FALSE(got_hit_report()); |
| 990 Mock::VerifyAndClear(&observer_); |
| 991 |
| 992 // Navigate to malware page. The malware subresources haven't loaded yet, so |
| 993 // no interstitial should show yet. |
| 994 chrome::NavigateParams params(browser(), second_url, |
| 995 ui::PAGE_TRANSITION_LINK); |
| 996 params.referrer.url = first_url; |
| 997 ui_test_utils::NavigateToURL(¶ms); |
| 998 |
| 999 EXPECT_FALSE(ShowingInterstitialPage()); |
| 1000 EXPECT_FALSE(got_hit_report()); |
| 1001 Mock::VerifyAndClear(&observer_); |
| 1002 |
| 1003 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 1004 .Times(1); |
| 1005 |
| 1006 WebContents* contents = |
| 1007 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1008 content::RenderFrameHost* rfh = contents->GetMainFrame(); |
| 1009 content::WindowedNotificationObserver load_stop_observer( |
| 1010 content::NOTIFICATION_LOAD_STOP, |
| 1011 content::Source<content::NavigationController>( |
| 1012 &contents->GetController())); |
| 1013 // Start a browser initiated top-level navigation to a site that does not |
| 1014 // respond. |
| 1015 ui_test_utils::NavigateToURLWithDisposition(browser(), third_url, CURRENT_TAB, |
| 1016 ui_test_utils::BROWSER_TEST_NONE); |
| 1017 |
| 1018 // While the top-level navigation is pending, run javascript |
| 1019 // function in the page which loads the malware image. |
| 1020 rfh->ExecuteJavaScriptForTests(base::ASCIIToUTF16("loadMalwareImage()")); |
| 1021 |
| 1022 // Wait for interstitial to show. |
| 1023 load_stop_observer.Wait(); |
| 1024 |
| 1025 EXPECT_TRUE(ShowingInterstitialPage()); |
| 1026 EXPECT_TRUE(got_hit_report()); |
| 1027 // Report URLs should be for the current page, not the pending load. |
| 1028 EXPECT_EQ(bad_url, hit_report().malicious_url); |
| 1029 EXPECT_EQ(second_url, hit_report().page_url); |
| 1030 EXPECT_EQ(first_url, hit_report().referrer_url); |
| 1031 EXPECT_TRUE(hit_report().is_subresource); |
| 1032 } |
| 1033 |
| 1034 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, SubResourceHitOnFreshTab) { |
| 1035 // Allow popups. |
| 1036 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 1037 ->SetContentSetting(ContentSettingsPattern::Wildcard(), |
| 1038 ContentSettingsPattern::Wildcard(), |
| 1039 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
| 1040 CONTENT_SETTING_ALLOW); |
| 1041 |
| 1042 // Add |kMalwareImg| to fake safebrowsing db. |
| 1043 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
| 1044 SBFullHashResult img_full_hash; |
| 1045 GenUrlFullhashResult(img_url, MALWARE, &img_full_hash); |
| 1046 SetupResponseForUrl(img_url, img_full_hash); |
| 1047 |
| 1048 // Have the current tab open a new tab with window.open(). |
| 1049 WebContents* main_contents = |
| 1050 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1051 content::RenderFrameHost* main_rfh = main_contents->GetMainFrame(); |
| 1052 |
| 1053 content::WebContentsAddedObserver web_contents_added_observer; |
| 1054 main_rfh->ExecuteJavaScriptForTests( |
| 1055 base::ASCIIToUTF16("w=window.open();")); |
| 1056 WebContents* new_tab_contents = web_contents_added_observer.GetWebContents(); |
| 1057 content::RenderFrameHost* new_tab_rfh = new_tab_contents->GetMainFrame(); |
| 1058 // A fresh WebContents should not have any NavigationEntries yet. (See |
| 1059 // https://crbug.com/524208.) |
| 1060 EXPECT_EQ(nullptr, new_tab_contents->GetController().GetLastCommittedEntry()); |
| 1061 EXPECT_EQ(nullptr, new_tab_contents->GetController().GetPendingEntry()); |
| 1062 |
| 1063 // Run javascript in the blank new tab to load the malware image. |
| 1064 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(img_url))) |
| 1065 .Times(1); |
| 1066 new_tab_rfh->ExecuteJavaScriptForTests( |
| 1067 base::ASCIIToUTF16("var img=new Image();" |
| 1068 "img.src=\"" + img_url.spec() + "\";" |
| 1069 "document.body.appendChild(img);")); |
| 1070 |
| 1071 // Wait for interstitial to show. |
| 1072 content::WaitForInterstitialAttach(new_tab_contents); |
| 1073 Mock::VerifyAndClearExpectations(&observer_); |
| 1074 EXPECT_TRUE(ShowingInterstitialPage()); |
| 1075 EXPECT_TRUE(got_hit_report()); |
| 1076 EXPECT_EQ(img_url, hit_report().malicious_url); |
| 1077 EXPECT_TRUE(hit_report().is_subresource); |
| 1078 // Page report URLs should be empty, since there is no URL for this page. |
| 1079 EXPECT_EQ(GURL(), hit_report().page_url); |
| 1080 EXPECT_EQ(GURL(), hit_report().referrer_url); |
| 1081 |
| 1082 // Proceed through it. |
| 1083 InterstitialPage* interstitial_page = new_tab_contents->GetInterstitialPage(); |
| 1084 ASSERT_TRUE(interstitial_page); |
| 1085 interstitial_page->Proceed(); |
| 1086 |
| 1087 content::WaitForInterstitialDetach(new_tab_contents); |
| 1088 EXPECT_FALSE(ShowingInterstitialPage()); |
| 1089 } |
| 1090 |
| 1091 namespace { |
| 774 | 1092 |
| 775 class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>, | 1093 class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>, |
| 776 public SafeBrowsingDatabaseManager::Client { | 1094 public SafeBrowsingDatabaseManager::Client { |
| 777 public: | 1095 public: |
| 778 TestSBClient() | 1096 TestSBClient() |
| 779 : threat_type_(SB_THREAT_TYPE_SAFE), | 1097 : threat_type_(SB_THREAT_TYPE_SAFE), |
| 780 safe_browsing_service_(g_browser_process->safe_browsing_service()) {} | 1098 safe_browsing_service_(g_browser_process->safe_browsing_service()) {} |
| 781 | 1099 |
| 782 SBThreatType GetThreatType() const { return threat_type_; } | 1100 SBThreatType GetThreatType() const { return threat_type_; } |
| 783 | 1101 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 } | 1158 } |
| 841 | 1159 |
| 842 void CheckDone() { base::MessageLoopForUI::current()->QuitWhenIdle(); } | 1160 void CheckDone() { base::MessageLoopForUI::current()->QuitWhenIdle(); } |
| 843 | 1161 |
| 844 SBThreatType threat_type_; | 1162 SBThreatType threat_type_; |
| 845 SafeBrowsingService* safe_browsing_service_; | 1163 SafeBrowsingService* safe_browsing_service_; |
| 846 | 1164 |
| 847 DISALLOW_COPY_AND_ASSIGN(TestSBClient); | 1165 DISALLOW_COPY_AND_ASSIGN(TestSBClient); |
| 848 }; | 1166 }; |
| 849 | 1167 |
| 1168 } // namespace |
| 1169 |
| 850 // These tests use SafeBrowsingService::Client to directly interact with | 1170 // These tests use SafeBrowsingService::Client to directly interact with |
| 851 // SafeBrowsingService. | 1171 // SafeBrowsingService. |
| 852 namespace { | |
| 853 | |
| 854 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrl) { | 1172 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrl) { |
| 855 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 1173 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
| 856 std::vector<GURL> badbin_urls(1, badbin_url); | 1174 std::vector<GURL> badbin_urls(1, badbin_url); |
| 857 | 1175 |
| 858 scoped_refptr<TestSBClient> client(new TestSBClient); | 1176 scoped_refptr<TestSBClient> client(new TestSBClient); |
| 859 client->CheckDownloadUrl(badbin_urls); | 1177 client->CheckDownloadUrl(badbin_urls); |
| 860 | 1178 |
| 861 // Since badbin_url is not in database, it is considered to be safe. | 1179 // Since badbin_url is not in database, it is considered to be safe. |
| 862 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 1180 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
| 863 | 1181 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 EXPECT_TRUE(csd_service->enabled()); | 1395 EXPECT_TRUE(csd_service->enabled()); |
| 1078 | 1396 |
| 1079 // Delete the Profile. SBS stops again. | 1397 // Delete the Profile. SBS stops again. |
| 1080 pref_service2 = NULL; | 1398 pref_service2 = NULL; |
| 1081 profile2.reset(); | 1399 profile2.reset(); |
| 1082 EXPECT_FALSE(sb_service->enabled_by_prefs()); | 1400 EXPECT_FALSE(sb_service->enabled_by_prefs()); |
| 1083 WaitForIOAndCheckEnabled(sb_service, false); | 1401 WaitForIOAndCheckEnabled(sb_service, false); |
| 1084 EXPECT_FALSE(csd_service->enabled()); | 1402 EXPECT_FALSE(csd_service->enabled()); |
| 1085 } | 1403 } |
| 1086 | 1404 |
| 1087 } // namespace | |
| 1088 | |
| 1089 class SafeBrowsingServiceShutdownTest : public SafeBrowsingServiceTest { | 1405 class SafeBrowsingServiceShutdownTest : public SafeBrowsingServiceTest { |
| 1090 public: | 1406 public: |
| 1091 void TearDown() override { | 1407 void TearDown() override { |
| 1092 // Browser should be fully torn down by now, so we can safely check these | 1408 // Browser should be fully torn down by now, so we can safely check these |
| 1093 // counters. | 1409 // counters. |
| 1094 EXPECT_EQ(1, TestProtocolManager::create_count()); | 1410 EXPECT_EQ(1, TestProtocolManager::create_count()); |
| 1095 EXPECT_EQ(1, TestProtocolManager::delete_count()); | 1411 EXPECT_EQ(1, TestProtocolManager::delete_count()); |
| 1096 | 1412 |
| 1097 SafeBrowsingServiceTest::TearDown(); | 1413 SafeBrowsingServiceTest::TearDown(); |
| 1098 } | 1414 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 1629 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 1314 content::Source<SafeBrowsingDatabaseManager>( | 1630 content::Source<SafeBrowsingDatabaseManager>( |
| 1315 sb_service_->database_manager().get())); | 1631 sb_service_->database_manager().get())); |
| 1316 BrowserThread::PostTask( | 1632 BrowserThread::PostTask( |
| 1317 BrowserThread::IO, FROM_HERE, | 1633 BrowserThread::IO, FROM_HERE, |
| 1318 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1634 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
| 1319 observer.Wait(); | 1635 observer.Wait(); |
| 1320 } | 1636 } |
| 1321 | 1637 |
| 1322 } // namespace safe_browsing | 1638 } // namespace safe_browsing |
| OLD | NEW |