| 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 fake safebrowsing service, where we can inject | 5 // This test creates a fake safebrowsing service, where we can inject |
| 6 // malware and phishing urls. It then uses a real browser to go to | 6 // malware and phishing urls. It then uses a real browser to go to |
| 7 // these urls, and sends "goback" or "proceed" commands and verifies | 7 // these urls, and sends "goback" or "proceed" commands and verifies |
| 8 // they work. | 8 // they work. |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/safe_browsing/database_manager.h" | 16 #include "chrome/browser/safe_browsing/database_manager.h" |
| 17 #include "chrome/browser/safe_browsing/malware_details.h" | 17 #include "chrome/browser/safe_browsing/malware_details.h" |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 20 #include "chrome/browser/safe_browsing/ui_manager.h" | 21 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "content/public/browser/interstitial_page.h" | 29 #include "content/public/browser/interstitial_page.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 return true; | 62 return true; |
| 62 | 63 |
| 63 BrowserThread::PostTask( | 64 BrowserThread::PostTask( |
| 64 BrowserThread::IO, FROM_HERE, | 65 BrowserThread::IO, FROM_HERE, |
| 65 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone, | 66 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone, |
| 66 this, gurl, client)); | 67 this, gurl, client)); |
| 67 return false; | 68 return false; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void OnCheckBrowseURLDone(const GURL& gurl, Client* client) { | 71 void OnCheckBrowseURLDone(const GURL& gurl, Client* client) { |
| 71 SafeBrowsingDatabaseManager::SafeBrowsingCheck check; | 72 SafeBrowsingDatabaseManager::SafeBrowsingCheck sb_check( |
| 72 check.urls.push_back(gurl); | 73 std::vector<GURL>(1, gurl), |
| 73 check.client = client; | 74 std::vector<SBFullHash>(), |
| 74 check.threat_type = badurls[gurl.spec()]; | 75 client, |
| 75 client->OnSafeBrowsingResult(check); | 76 safe_browsing_util::MALWARE); |
| 77 sb_check.url_results[0] = badurls[gurl.spec()]; |
| 78 client->OnSafeBrowsingResult(sb_check); |
| 76 } | 79 } |
| 77 | 80 |
| 78 void SetURLThreatType(const GURL& url, SBThreatType threat_type) { | 81 void SetURLThreatType(const GURL& url, SBThreatType threat_type) { |
| 79 badurls[url.spec()] = threat_type; | 82 badurls[url.spec()] = threat_type; |
| 80 } | 83 } |
| 81 | 84 |
| 82 private: | 85 private: |
| 83 virtual ~FakeSafeBrowsingDatabaseManager() {} | 86 virtual ~FakeSafeBrowsingDatabaseManager() {} |
| 84 | 87 |
| 85 base::hash_map<std::string, SBThreatType> badurls; | 88 base::hash_map<std::string, SBThreatType> badurls; |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); | 781 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); |
| 779 | 782 |
| 780 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); | 783 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); |
| 781 AssertNoInterstitial(false); // Assert the interstitial is gone | 784 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 782 | 785 |
| 783 // We are in the help page. | 786 // We are in the help page. |
| 784 EXPECT_EQ( | 787 EXPECT_EQ( |
| 785 "/goodtoknow/online-safety/phishing/", | 788 "/goodtoknow/online-safety/phishing/", |
| 786 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 789 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
| 787 } | 790 } |
| OLD | NEW |