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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // We use InterstitialPage::GetInterstitialPage(tab) instead of | 430 // We use InterstitialPage::GetInterstitialPage(tab) instead of |
431 // tab->GetInterstitialPage() because the tab doesn't have a pointer | 431 // tab->GetInterstitialPage() because the tab doesn't have a pointer |
432 // to its interstital page until it gets a command from the renderer | 432 // to its interstital page until it gets a command from the renderer |
433 // that it has indeed displayed it -- and this sometimes happens after | 433 // that it has indeed displayed it -- and this sometimes happens after |
434 // NavigateToURL returns. | 434 // NavigateToURL returns. |
435 SafeBrowsingBlockingPage* interstitial_page = | 435 SafeBrowsingBlockingPage* interstitial_page = |
436 static_cast<SafeBrowsingBlockingPage*>( | 436 static_cast<SafeBrowsingBlockingPage*>( |
437 InterstitialPage::GetInterstitialPage(contents)-> | 437 InterstitialPage::GetInterstitialPage(contents)-> |
438 GetDelegateForTesting()); | 438 GetDelegateForTesting()); |
439 ASSERT_TRUE(interstitial_page); | 439 ASSERT_TRUE(interstitial_page); |
| 440 ASSERT_EQ(SecurityInterstitialPage::SAFEBROWSING, |
| 441 interstitial_page->GetTypeForTesting()); |
440 interstitial_page->CommandReceived(command); | 442 interstitial_page->CommandReceived(command); |
441 } | 443 } |
442 | 444 |
443 void DontProceedThroughInterstitial() { | 445 void DontProceedThroughInterstitial() { |
444 WebContents* contents = | 446 WebContents* contents = |
445 browser()->tab_strip_model()->GetActiveWebContents(); | 447 browser()->tab_strip_model()->GetActiveWebContents(); |
446 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( | 448 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( |
447 contents); | 449 contents); |
448 ASSERT_TRUE(interstitial_page); | 450 ASSERT_TRUE(interstitial_page); |
449 interstitial_page->DontProceed(); | 451 interstitial_page->DontProceed(); |
(...skipping 10 matching lines...) Expand all Loading... |
460 | 462 |
461 void AssertNoInterstitial(bool wait_for_delete) { | 463 void AssertNoInterstitial(bool wait_for_delete) { |
462 WebContents* contents = | 464 WebContents* contents = |
463 browser()->tab_strip_model()->GetActiveWebContents(); | 465 browser()->tab_strip_model()->GetActiveWebContents(); |
464 | 466 |
465 if (contents->ShowingInterstitialPage() && wait_for_delete) { | 467 if (contents->ShowingInterstitialPage() && wait_for_delete) { |
466 // We'll get notified when the interstitial is deleted. | 468 // We'll get notified when the interstitial is deleted. |
467 TestSafeBrowsingBlockingPage* page = | 469 TestSafeBrowsingBlockingPage* page = |
468 static_cast<TestSafeBrowsingBlockingPage*>( | 470 static_cast<TestSafeBrowsingBlockingPage*>( |
469 contents->GetInterstitialPage()->GetDelegateForTesting()); | 471 contents->GetInterstitialPage()->GetDelegateForTesting()); |
| 472 ASSERT_EQ(SecurityInterstitialPage::SAFEBROWSING, |
| 473 page->GetTypeForTesting()); |
470 page->WaitForDelete(); | 474 page->WaitForDelete(); |
471 } | 475 } |
472 | 476 |
473 // Can't use InterstitialPage::GetInterstitialPage() because that | 477 // Can't use InterstitialPage::GetInterstitialPage() because that |
474 // gets updated after the TestSafeBrowsingBlockingPage destructor | 478 // gets updated after the TestSafeBrowsingBlockingPage destructor |
475 ASSERT_FALSE(contents->ShowingInterstitialPage()); | 479 ASSERT_FALSE(contents->ShowingInterstitialPage()); |
476 } | 480 } |
477 | 481 |
478 bool YesInterstitial() { | 482 bool YesInterstitial() { |
479 WebContents* contents = | 483 WebContents* contents = |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageBrowserTest, PhishingLearnMore) { | 885 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageBrowserTest, PhishingLearnMore) { |
882 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); | 886 SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING); |
883 EXPECT_TRUE(ClickAndWaitForDetach("help-link")); | 887 EXPECT_TRUE(ClickAndWaitForDetach("help-link")); |
884 AssertNoInterstitial(false); // Assert the interstitial is gone | 888 AssertNoInterstitial(false); // Assert the interstitial is gone |
885 | 889 |
886 // We are in the help page. | 890 // We are in the help page. |
887 EXPECT_EQ( | 891 EXPECT_EQ( |
888 "/transparencyreport/safebrowsing/", | 892 "/transparencyreport/safebrowsing/", |
889 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); | 893 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); |
890 } | 894 } |
OLD | NEW |