| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // We use InterstitialPage::GetInterstitialPage(tab) instead of | 401 // We use InterstitialPage::GetInterstitialPage(tab) instead of |
| 402 // tab->GetInterstitialPage() because the tab doesn't have a pointer | 402 // tab->GetInterstitialPage() because the tab doesn't have a pointer |
| 403 // to its interstital page until it gets a command from the renderer | 403 // to its interstital page until it gets a command from the renderer |
| 404 // that it has indeed displayed it -- and this sometimes happens after | 404 // that it has indeed displayed it -- and this sometimes happens after |
| 405 // NavigateToURL returns. | 405 // NavigateToURL returns. |
| 406 SafeBrowsingBlockingPage* interstitial_page = | 406 SafeBrowsingBlockingPage* interstitial_page = |
| 407 static_cast<SafeBrowsingBlockingPage*>( | 407 static_cast<SafeBrowsingBlockingPage*>( |
| 408 InterstitialPage::GetInterstitialPage(contents)-> | 408 InterstitialPage::GetInterstitialPage(contents)-> |
| 409 GetDelegateForTesting()); | 409 GetDelegateForTesting()); |
| 410 ASSERT_TRUE(interstitial_page); | 410 ASSERT_TRUE(interstitial_page); |
| 411 ASSERT_EQ(SafeBrowsingBlockingPage::kTypeForTesting, |
| 412 interstitial_page->GetTypeForTesting()); |
| 411 interstitial_page->CommandReceived(command); | 413 interstitial_page->CommandReceived(command); |
| 412 } | 414 } |
| 413 | 415 |
| 414 void DontProceedThroughInterstitial() { | 416 void DontProceedThroughInterstitial() { |
| 415 WebContents* contents = | 417 WebContents* contents = |
| 416 browser()->tab_strip_model()->GetActiveWebContents(); | 418 browser()->tab_strip_model()->GetActiveWebContents(); |
| 417 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( | 419 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( |
| 418 contents); | 420 contents); |
| 419 ASSERT_TRUE(interstitial_page); | 421 ASSERT_TRUE(interstitial_page); |
| 420 interstitial_page->DontProceed(); | 422 interstitial_page->DontProceed(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 431 | 433 |
| 432 void AssertNoInterstitial(bool wait_for_delete) { | 434 void AssertNoInterstitial(bool wait_for_delete) { |
| 433 WebContents* contents = | 435 WebContents* contents = |
| 434 browser()->tab_strip_model()->GetActiveWebContents(); | 436 browser()->tab_strip_model()->GetActiveWebContents(); |
| 435 | 437 |
| 436 if (contents->ShowingInterstitialPage() && wait_for_delete) { | 438 if (contents->ShowingInterstitialPage() && wait_for_delete) { |
| 437 // We'll get notified when the interstitial is deleted. | 439 // We'll get notified when the interstitial is deleted. |
| 438 TestSafeBrowsingBlockingPage* page = | 440 TestSafeBrowsingBlockingPage* page = |
| 439 static_cast<TestSafeBrowsingBlockingPage*>( | 441 static_cast<TestSafeBrowsingBlockingPage*>( |
| 440 contents->GetInterstitialPage()->GetDelegateForTesting()); | 442 contents->GetInterstitialPage()->GetDelegateForTesting()); |
| 443 ASSERT_EQ(SafeBrowsingBlockingPage::kTypeForTesting, |
| 444 page->GetTypeForTesting()); |
| 441 page->WaitForDelete(); | 445 page->WaitForDelete(); |
| 442 } | 446 } |
| 443 | 447 |
| 444 // Can't use InterstitialPage::GetInterstitialPage() because that | 448 // Can't use InterstitialPage::GetInterstitialPage() because that |
| 445 // gets updated after the TestSafeBrowsingBlockingPage destructor | 449 // gets updated after the TestSafeBrowsingBlockingPage destructor |
| 446 ASSERT_FALSE(contents->ShowingInterstitialPage()); | 450 ASSERT_FALSE(contents->ShowingInterstitialPage()); |
| 447 } | 451 } |
| 448 | 452 |
| 449 bool YesInterstitial() { | 453 bool YesInterstitial() { |
| 450 WebContents* contents = | 454 WebContents* contents = |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageBrowserTest, PhishingLearnMore) { | 841 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageBrowserTest, PhishingLearnMore) { |
| 838 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); | 842 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); |
| 839 EXPECT_TRUE(ClickAndWaitForDetach("help-link")); | 843 EXPECT_TRUE(ClickAndWaitForDetach("help-link")); |
| 840 AssertNoInterstitial(false); // Assert the interstitial is gone | 844 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 841 | 845 |
| 842 // We are in the help page. | 846 // We are in the help page. |
| 843 EXPECT_EQ( | 847 EXPECT_EQ( |
| 844 "/transparencyreport/safebrowsing/", | 848 "/transparencyreport/safebrowsing/", |
| 845 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 849 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
| 846 } | 850 } |
| OLD | NEW |