| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { | 51 class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { |
| 52 public: | 52 public: |
| 53 explicit FakeSafeBrowsingDatabaseManager(SafeBrowsingService* service) | 53 explicit FakeSafeBrowsingDatabaseManager(SafeBrowsingService* service) |
| 54 : SafeBrowsingDatabaseManager(service) { } | 54 : SafeBrowsingDatabaseManager(service) { } |
| 55 | 55 |
| 56 // Called on the IO thread to check if the given url is safe or not. If we | 56 // Called on the IO thread to check if the given url is safe or not. If we |
| 57 // can synchronously determine that the url is safe, CheckUrl returns true. | 57 // can synchronously determine that the url is safe, CheckUrl returns true. |
| 58 // Otherwise it returns false, and "client" is called asynchronously with the | 58 // Otherwise it returns false, and "client" is called asynchronously with the |
| 59 // result when it is ready. | 59 // result when it is ready. |
| 60 // Overrides SafeBrowsingDatabaseManager::CheckBrowseUrl. | 60 // Overrides SafeBrowsingDatabaseManager::CheckBrowseUrl. |
| 61 virtual bool CheckBrowseUrl(const GURL& gurl, Client* client) { | 61 virtual bool CheckBrowseUrl(const GURL& gurl, Client* client) OVERRIDE { |
| 62 if (badurls[gurl.spec()] == SB_THREAT_TYPE_SAFE) | 62 if (badurls[gurl.spec()] == SB_THREAT_TYPE_SAFE) |
| 63 return true; | 63 return true; |
| 64 | 64 |
| 65 BrowserThread::PostTask( | 65 BrowserThread::PostTask( |
| 66 BrowserThread::IO, FROM_HERE, | 66 BrowserThread::IO, FROM_HERE, |
| 67 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone, | 67 base::Bind(&FakeSafeBrowsingDatabaseManager::OnCheckBrowseURLDone, |
| 68 this, gurl, client)); | 68 this, gurl, client)); |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager); | 90 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // A SafeBrowingUIManager class that allows intercepting malware details. | 93 // A SafeBrowingUIManager class that allows intercepting malware details. |
| 94 class FakeSafeBrowsingUIManager : public SafeBrowsingUIManager { | 94 class FakeSafeBrowsingUIManager : public SafeBrowsingUIManager { |
| 95 public: | 95 public: |
| 96 explicit FakeSafeBrowsingUIManager(SafeBrowsingService* service) : | 96 explicit FakeSafeBrowsingUIManager(SafeBrowsingService* service) : |
| 97 SafeBrowsingUIManager(service) { } | 97 SafeBrowsingUIManager(service) { } |
| 98 | 98 |
| 99 // Overrides SafeBrowsingUIManager | 99 // Overrides SafeBrowsingUIManager |
| 100 virtual void SendSerializedMalwareDetails(const std::string& serialized) { | 100 virtual void SendSerializedMalwareDetails( |
| 101 const std::string& serialized) OVERRIDE { |
| 101 reports_.push_back(serialized); | 102 reports_.push_back(serialized); |
| 102 // Notify the UI thread that we got a report. | 103 // Notify the UI thread that we got a report. |
| 103 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| 104 BrowserThread::UI, FROM_HERE, | 105 BrowserThread::UI, FROM_HERE, |
| 105 base::Bind(&FakeSafeBrowsingUIManager::OnMalwareDetailsDone, this)); | 106 base::Bind(&FakeSafeBrowsingUIManager::OnMalwareDetailsDone, this)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void OnMalwareDetailsDone() { | 109 void OnMalwareDetailsDone() { |
| 109 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 110 MessageLoopForUI::current()->Quit(); | 111 MessageLoopForUI::current()->Quit(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 public: | 259 public: |
| 259 TestSafeBrowsingBlockingPage(SafeBrowsingUIManager* manager, | 260 TestSafeBrowsingBlockingPage(SafeBrowsingUIManager* manager, |
| 260 WebContents* web_contents, | 261 WebContents* web_contents, |
| 261 const UnsafeResourceList& unsafe_resources) | 262 const UnsafeResourceList& unsafe_resources) |
| 262 : SafeBrowsingBlockingPageV2(manager, web_contents, unsafe_resources), | 263 : SafeBrowsingBlockingPageV2(manager, web_contents, unsafe_resources), |
| 263 wait_for_delete_(false) { | 264 wait_for_delete_(false) { |
| 264 // Don't wait the whole 3 seconds for the browser test. | 265 // Don't wait the whole 3 seconds for the browser test. |
| 265 malware_details_proceed_delay_ms_ = 100; | 266 malware_details_proceed_delay_ms_ = 100; |
| 266 } | 267 } |
| 267 | 268 |
| 268 ~TestSafeBrowsingBlockingPage() { | 269 virtual ~TestSafeBrowsingBlockingPage() { |
| 269 if (!wait_for_delete_) | 270 if (!wait_for_delete_) |
| 270 return; | 271 return; |
| 271 | 272 |
| 272 // Notify that we are gone | 273 // Notify that we are gone |
| 273 MessageLoopForUI::current()->Quit(); | 274 MessageLoopForUI::current()->Quit(); |
| 274 wait_for_delete_ = false; | 275 wait_for_delete_ = false; |
| 275 } | 276 } |
| 276 | 277 |
| 277 void WaitForDelete() { | 278 void WaitForDelete() { |
| 278 wait_for_delete_ = true; | 279 wait_for_delete_ = true; |
| 279 content::RunMessageLoop(); | 280 content::RunMessageLoop(); |
| 280 } | 281 } |
| 281 | 282 |
| 282 private: | 283 private: |
| 283 bool wait_for_delete_; | 284 bool wait_for_delete_; |
| 284 }; | 285 }; |
| 285 | 286 |
| 286 class TestSafeBrowsingBlockingPageFactory | 287 class TestSafeBrowsingBlockingPageFactory |
| 287 : public SafeBrowsingBlockingPageFactory { | 288 : public SafeBrowsingBlockingPageFactory { |
| 288 public: | 289 public: |
| 289 TestSafeBrowsingBlockingPageFactory() { } | 290 TestSafeBrowsingBlockingPageFactory() { } |
| 290 ~TestSafeBrowsingBlockingPageFactory() { } | 291 virtual ~TestSafeBrowsingBlockingPageFactory() { } |
| 291 | 292 |
| 292 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 293 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 293 SafeBrowsingUIManager* delegate, | 294 SafeBrowsingUIManager* delegate, |
| 294 WebContents* web_contents, | 295 WebContents* web_contents, |
| 295 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 296 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
| 296 OVERRIDE { | 297 OVERRIDE { |
| 297 return new TestSafeBrowsingBlockingPage(delegate, web_contents, | 298 return new TestSafeBrowsingBlockingPage(delegate, web_contents, |
| 298 unsafe_resources); | 299 unsafe_resources); |
| 299 } | 300 } |
| 300 }; | 301 }; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); | 781 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); |
| 781 | 782 |
| 782 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); | 783 EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link")); |
| 783 AssertNoInterstitial(false); // Assert the interstitial is gone | 784 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 784 | 785 |
| 785 // We are in the help page. | 786 // We are in the help page. |
| 786 EXPECT_EQ( | 787 EXPECT_EQ( |
| 787 "/goodtoknow/online-safety/phishing/", | 788 "/goodtoknow/online-safety/phishing/", |
| 788 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 789 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
| 789 } | 790 } |
| OLD | NEW |