| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 bool YesInterstitial() { | 314 bool YesInterstitial() { |
| 315 WebContents* contents = chrome::GetActiveWebContents(browser()); | 315 WebContents* contents = chrome::GetActiveWebContents(browser()); |
| 316 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( | 316 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( |
| 317 contents); | 317 contents); |
| 318 return interstitial_page != NULL; | 318 return interstitial_page != NULL; |
| 319 } | 319 } |
| 320 | 320 |
| 321 void WaitForInterstitial() { | 321 void WaitForInterstitial() { |
| 322 WebContents* contents = chrome::GetActiveWebContents(browser()); | 322 WebContents* contents = chrome::GetActiveWebContents(browser()); |
| 323 ui_test_utils::WindowedNotificationObserver interstitial_observer( | 323 content::WindowedNotificationObserver interstitial_observer( |
| 324 content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 324 content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 325 content::Source<WebContents>(contents)); | 325 content::Source<WebContents>(contents)); |
| 326 if (!InterstitialPage::GetInterstitialPage(contents)) | 326 if (!InterstitialPage::GetInterstitialPage(contents)) |
| 327 interstitial_observer.Wait(); | 327 interstitial_observer.Wait(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void AssertReportSent() { | 330 void AssertReportSent() { |
| 331 // When a report is scheduled in the IO thread we should get notified. | 331 // When a report is scheduled in the IO thread we should get notified. |
| 332 ui_test_utils::RunMessageLoop(); | 332 ui_test_utils::RunMessageLoop(); |
| 333 | 333 |
| 334 FakeSafeBrowsingService* service = | 334 FakeSafeBrowsingService* service = |
| 335 static_cast<FakeSafeBrowsingService*>( | 335 static_cast<FakeSafeBrowsingService*>( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 chrome::GetActiveWebContents(browser())->GetURL()); | 448 chrome::GetActiveWebContents(browser())->GetURL()); |
| 449 } | 449 } |
| 450 | 450 |
| 451 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { | 451 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { |
| 452 GURL url = test_server()->GetURL(kEmptyPage); | 452 GURL url = test_server()->GetURL(kEmptyPage); |
| 453 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 453 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
| 454 | 454 |
| 455 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate | 455 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate |
| 456 // event that clears the interstitial. We wait for DidNavigate instead. | 456 // event that clears the interstitial. We wait for DidNavigate instead. |
| 457 ui_test_utils::NavigateToURL(browser(), url); | 457 ui_test_utils::NavigateToURL(browser(), url); |
| 458 ui_test_utils::WindowedNotificationObserver observer( | 458 content::WindowedNotificationObserver observer( |
| 459 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 459 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 460 content::Source<NavigationController>( | 460 content::Source<NavigationController>( |
| 461 &chrome::GetActiveWebContents(browser())->GetController())); | 461 &chrome::GetActiveWebContents(browser())->GetController())); |
| 462 SendCommand("\"proceed\""); // Simulate the user clicking "proceed" | 462 SendCommand("\"proceed\""); // Simulate the user clicking "proceed" |
| 463 observer.Wait(); | 463 observer.Wait(); |
| 464 AssertNoInterstitial(true); // Assert the interstitial is gone. | 464 AssertNoInterstitial(true); // Assert the interstitial is gone. |
| 465 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); | 465 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); |
| 466 } | 466 } |
| 467 | 467 |
| 468 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingDontProceed) { | 468 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingDontProceed) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 479 } | 479 } |
| 480 | 480 |
| 481 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingProceed) { | 481 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingProceed) { |
| 482 GURL url = test_server()->GetURL(kEmptyPage); | 482 GURL url = test_server()->GetURL(kEmptyPage); |
| 483 AddURLResult(url, SafeBrowsingService::URL_PHISHING); | 483 AddURLResult(url, SafeBrowsingService::URL_PHISHING); |
| 484 | 484 |
| 485 ui_test_utils::NavigateToURL(browser(), url); | 485 ui_test_utils::NavigateToURL(browser(), url); |
| 486 | 486 |
| 487 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate | 487 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate |
| 488 // event that clears the interstitial. We wait for DidNavigate instead. | 488 // event that clears the interstitial. We wait for DidNavigate instead. |
| 489 ui_test_utils::WindowedNotificationObserver observer( | 489 content::WindowedNotificationObserver observer( |
| 490 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 490 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 491 content::Source<NavigationController>( | 491 content::Source<NavigationController>( |
| 492 &chrome::GetActiveWebContents(browser())->GetController())); | 492 &chrome::GetActiveWebContents(browser())->GetController())); |
| 493 SendCommand("\"proceed\""); // Simulate the user clicking "proceed". | 493 SendCommand("\"proceed\""); // Simulate the user clicking "proceed". |
| 494 observer.Wait(); | 494 observer.Wait(); |
| 495 AssertNoInterstitial(true); // Assert the interstitial is gone | 495 AssertNoInterstitial(true); // Assert the interstitial is gone |
| 496 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); | 496 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); |
| 497 } | 497 } |
| 498 | 498 |
| 499 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingReportError) { | 499 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingReportError) { |
| 500 GURL url = test_server()->GetURL(kEmptyPage); | 500 GURL url = test_server()->GetURL(kEmptyPage); |
| 501 AddURLResult(url, SafeBrowsingService::URL_PHISHING); | 501 AddURLResult(url, SafeBrowsingService::URL_PHISHING); |
| 502 | 502 |
| 503 ui_test_utils::NavigateToURL(browser(), url); | 503 ui_test_utils::NavigateToURL(browser(), url); |
| 504 | 504 |
| 505 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate | 505 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate |
| 506 // event that clears the interstitial. We wait for DidNavigate instead. | 506 // event that clears the interstitial. We wait for DidNavigate instead. |
| 507 ui_test_utils::WindowedNotificationObserver observer( | 507 content::WindowedNotificationObserver observer( |
| 508 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 508 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 509 content::Source<NavigationController>( | 509 content::Source<NavigationController>( |
| 510 &chrome::GetActiveWebContents(browser())->GetController())); | 510 &chrome::GetActiveWebContents(browser())->GetController())); |
| 511 SendCommand("\"reportError\""); // Simulate the user clicking "report error" | 511 SendCommand("\"reportError\""); // Simulate the user clicking "report error" |
| 512 observer.Wait(); | 512 observer.Wait(); |
| 513 AssertNoInterstitial(false); // Assert the interstitial is gone | 513 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 514 | 514 |
| 515 // We are in the error reporting page. | 515 // We are in the error reporting page. |
| 516 EXPECT_EQ( | 516 EXPECT_EQ( |
| 517 "/safebrowsing/report_error/", | 517 "/safebrowsing/report_error/", |
| 518 chrome::GetActiveWebContents(browser())->GetURL().path()); | 518 chrome::GetActiveWebContents(browser())->GetURL().path()); |
| 519 } | 519 } |
| 520 | 520 |
| 521 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, | 521 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, |
| 522 PhishingLearnMore) { | 522 PhishingLearnMore) { |
| 523 GURL url = test_server()->GetURL(kEmptyPage); | 523 GURL url = test_server()->GetURL(kEmptyPage); |
| 524 AddURLResult(url, SafeBrowsingService::URL_PHISHING); | 524 AddURLResult(url, SafeBrowsingService::URL_PHISHING); |
| 525 | 525 |
| 526 ui_test_utils::NavigateToURL(browser(), url); | 526 ui_test_utils::NavigateToURL(browser(), url); |
| 527 | 527 |
| 528 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate | 528 // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate |
| 529 // event that clears the interstitial. We wait for DidNavigate instead. | 529 // event that clears the interstitial. We wait for DidNavigate instead. |
| 530 ui_test_utils::WindowedNotificationObserver observer( | 530 content::WindowedNotificationObserver observer( |
| 531 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 531 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 532 content::Source<NavigationController>( | 532 content::Source<NavigationController>( |
| 533 &chrome::GetActiveWebContents(browser())->GetController())); | 533 &chrome::GetActiveWebContents(browser())->GetController())); |
| 534 SendCommand("\"learnMore\""); // Simulate the user clicking "learn more" | 534 SendCommand("\"learnMore\""); // Simulate the user clicking "learn more" |
| 535 observer.Wait(); | 535 observer.Wait(); |
| 536 AssertNoInterstitial(false); // Assert the interstitial is gone | 536 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 537 | 537 |
| 538 // We are in the help page. | 538 // We are in the help page. |
| 539 EXPECT_EQ( | 539 EXPECT_EQ( |
| 540 "/support/bin/answer.py", | 540 "/support/bin/answer.py", |
| 541 chrome::GetActiveWebContents(browser())->GetURL().path()); | 541 chrome::GetActiveWebContents(browser())->GetURL().path()); |
| 542 } | 542 } |
| 543 | 543 |
| 544 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareIframeDontProceed) { | 544 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareIframeDontProceed) { |
| 545 GURL url = test_server()->GetURL(kMalwarePage); | 545 GURL url = test_server()->GetURL(kMalwarePage); |
| 546 GURL iframe_url = test_server()->GetURL(kMalwareIframe); | 546 GURL iframe_url = test_server()->GetURL(kMalwareIframe); |
| 547 AddURLResult(iframe_url, SafeBrowsingService::URL_MALWARE); | 547 AddURLResult(iframe_url, SafeBrowsingService::URL_MALWARE); |
| 548 | 548 |
| 549 ui_test_utils::NavigateToURL(browser(), url); | 549 ui_test_utils::NavigateToURL(browser(), url); |
| 550 | 550 |
| 551 ui_test_utils::WindowedNotificationObserver observer( | 551 content::WindowedNotificationObserver observer( |
| 552 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 552 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 553 content::Source<NavigationController>( | 553 content::Source<NavigationController>( |
| 554 &chrome::GetActiveWebContents(browser())->GetController())); | 554 &chrome::GetActiveWebContents(browser())->GetController())); |
| 555 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" | 555 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" |
| 556 observer.Wait(); | 556 observer.Wait(); |
| 557 AssertNoInterstitial(false); // Assert the interstitial is gone | 557 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 558 | 558 |
| 559 EXPECT_EQ( | 559 EXPECT_EQ( |
| 560 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 560 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
| 561 chrome::GetActiveWebContents(browser())->GetURL()); | 561 chrome::GetActiveWebContents(browser())->GetURL()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); | 615 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); |
| 616 EXPECT_TRUE(hidden); | 616 EXPECT_TRUE(hidden); |
| 617 | 617 |
| 618 // The "proceed" command should go back instead, if proceeding is disabled. | 618 // The "proceed" command should go back instead, if proceeding is disabled. |
| 619 SendCommand("\"proceed\""); | 619 SendCommand("\"proceed\""); |
| 620 AssertNoInterstitial(true); | 620 AssertNoInterstitial(true); |
| 621 EXPECT_EQ( | 621 EXPECT_EQ( |
| 622 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 622 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
| 623 chrome::GetActiveWebContents(browser())->GetURL()); | 623 chrome::GetActiveWebContents(browser())->GetURL()); |
| 624 } | 624 } |
| OLD | NEW |