| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/safe_browsing/malware_details.h" | 14 #include "chrome/browser/safe_browsing/malware_details.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 23 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 24 #include "content/browser/tab_contents/tab_contents_view.h" | 24 #include "content/browser/tab_contents/tab_contents_view.h" |
| 25 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/test/test_browser_thread.h" | 27 #include "content/test/test_browser_thread.h" |
| 28 | 28 |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 using content::NavigationController; |
| 30 using content::WebContents; | 31 using content::WebContents; |
| 31 | 32 |
| 32 // A SafeBrowingService class that allows us to inject the malicious URLs. | 33 // A SafeBrowingService class that allows us to inject the malicious URLs. |
| 33 class FakeSafeBrowsingService : public SafeBrowsingService { | 34 class FakeSafeBrowsingService : public SafeBrowsingService { |
| 34 public: | 35 public: |
| 35 FakeSafeBrowsingService() {} | 36 FakeSafeBrowsingService() {} |
| 36 | 37 |
| 37 virtual ~FakeSafeBrowsingService() {} | 38 virtual ~FakeSafeBrowsingService() {} |
| 38 | 39 |
| 39 // Called on the IO thread to check if the given url is safe or not. If we | 40 // Called on the IO thread to check if the given url is safe or not. If we |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); | 424 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); |
| 424 } | 425 } |
| 425 | 426 |
| 426 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { | 427 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { |
| 427 GURL url = test_server()->GetURL(kEmptyPage); | 428 GURL url = test_server()->GetURL(kEmptyPage); |
| 428 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 429 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
| 429 | 430 |
| 430 ui_test_utils::NavigateToURL(browser(), url); | 431 ui_test_utils::NavigateToURL(browser(), url); |
| 431 ui_test_utils::WindowedNotificationObserver observer( | 432 ui_test_utils::WindowedNotificationObserver observer( |
| 432 content::NOTIFICATION_LOAD_STOP, | 433 content::NOTIFICATION_LOAD_STOP, |
| 433 content::Source<content::NavigationController>( | 434 content::Source<NavigationController>( |
| 434 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 435 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
| 435 GetController())); | 436 GetController())); |
| 436 SendCommand("\"proceed\""); // Simulate the user clicking "proceed" | 437 SendCommand("\"proceed\""); // Simulate the user clicking "proceed" |
| 437 observer.Wait(); | 438 observer.Wait(); |
| 438 AssertNoInterstitial(true); // Assert the interstitial is gone. | 439 AssertNoInterstitial(true); // Assert the interstitial is gone. |
| 439 EXPECT_EQ( | 440 EXPECT_EQ( |
| 440 url, | 441 url, |
| 441 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); | 442 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); |
| 442 } | 443 } |
| 443 | 444 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 455 } | 456 } |
| 456 | 457 |
| 457 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingProceed) { | 458 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingProceed) { |
| 458 GURL url = test_server()->GetURL(kEmptyPage); | 459 GURL url = test_server()->GetURL(kEmptyPage); |
| 459 AddURLResult(url, SafeBrowsingService::URL_PHISHING); | 460 AddURLResult(url, SafeBrowsingService::URL_PHISHING); |
| 460 | 461 |
| 461 ui_test_utils::NavigateToURL(browser(), url); | 462 ui_test_utils::NavigateToURL(browser(), url); |
| 462 | 463 |
| 463 ui_test_utils::WindowedNotificationObserver observer( | 464 ui_test_utils::WindowedNotificationObserver observer( |
| 464 content::NOTIFICATION_LOAD_STOP, | 465 content::NOTIFICATION_LOAD_STOP, |
| 465 content::Source<content::NavigationController>( | 466 content::Source<NavigationController>( |
| 466 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 467 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
| 467 GetController())); | 468 GetController())); |
| 468 SendCommand("\"proceed\""); // Simulate the user clicking "proceed". | 469 SendCommand("\"proceed\""); // Simulate the user clicking "proceed". |
| 469 observer.Wait(); | 470 observer.Wait(); |
| 470 AssertNoInterstitial(true); // Assert the interstitial is gone | 471 AssertNoInterstitial(true); // Assert the interstitial is gone |
| 471 EXPECT_EQ( | 472 EXPECT_EQ( |
| 472 url, | 473 url, |
| 473 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); | 474 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); |
| 474 } | 475 } |
| 475 | 476 |
| 476 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingReportError) { | 477 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingReportError) { |
| 477 GURL url = test_server()->GetURL(kEmptyPage); | 478 GURL url = test_server()->GetURL(kEmptyPage); |
| 478 AddURLResult(url, SafeBrowsingService::URL_PHISHING); | 479 AddURLResult(url, SafeBrowsingService::URL_PHISHING); |
| 479 | 480 |
| 480 ui_test_utils::NavigateToURL(browser(), url); | 481 ui_test_utils::NavigateToURL(browser(), url); |
| 481 | 482 |
| 482 ui_test_utils::WindowedNotificationObserver observer( | 483 ui_test_utils::WindowedNotificationObserver observer( |
| 483 content::NOTIFICATION_LOAD_STOP, | 484 content::NOTIFICATION_LOAD_STOP, |
| 484 content::Source<content::NavigationController>( | 485 content::Source<NavigationController>( |
| 485 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 486 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
| 486 GetController())); | 487 GetController())); |
| 487 SendCommand("\"reportError\""); // Simulate the user clicking "report error" | 488 SendCommand("\"reportError\""); // Simulate the user clicking "report error" |
| 488 observer.Wait(); | 489 observer.Wait(); |
| 489 AssertNoInterstitial(false); // Assert the interstitial is gone | 490 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 490 | 491 |
| 491 // We are in the error reporting page. | 492 // We are in the error reporting page. |
| 492 EXPECT_EQ( | 493 EXPECT_EQ( |
| 493 "/safebrowsing/report_error/", | 494 "/safebrowsing/report_error/", |
| 494 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL(). | 495 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL(). |
| 495 path()); | 496 path()); |
| 496 } | 497 } |
| 497 | 498 |
| 498 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, | 499 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, |
| 499 PhishingLearnMore) { | 500 PhishingLearnMore) { |
| 500 GURL url = test_server()->GetURL(kEmptyPage); | 501 GURL url = test_server()->GetURL(kEmptyPage); |
| 501 AddURLResult(url, SafeBrowsingService::URL_PHISHING); | 502 AddURLResult(url, SafeBrowsingService::URL_PHISHING); |
| 502 | 503 |
| 503 ui_test_utils::NavigateToURL(browser(), url); | 504 ui_test_utils::NavigateToURL(browser(), url); |
| 504 | 505 |
| 505 ui_test_utils::WindowedNotificationObserver observer( | 506 ui_test_utils::WindowedNotificationObserver observer( |
| 506 content::NOTIFICATION_LOAD_STOP, | 507 content::NOTIFICATION_LOAD_STOP, |
| 507 content::Source<content::NavigationController>( | 508 content::Source<NavigationController>( |
| 508 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 509 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
| 509 GetController())); | 510 GetController())); |
| 510 SendCommand("\"learnMore\""); // Simulate the user clicking "learn more" | 511 SendCommand("\"learnMore\""); // Simulate the user clicking "learn more" |
| 511 observer.Wait(); | 512 observer.Wait(); |
| 512 AssertNoInterstitial(false); // Assert the interstitial is gone | 513 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 513 | 514 |
| 514 // We are in the help page. | 515 // We are in the help page. |
| 515 EXPECT_EQ( | 516 EXPECT_EQ( |
| 516 "/support/bin/answer.py", | 517 "/support/bin/answer.py", |
| 517 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL(). | 518 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL(). |
| 518 path()); | 519 path()); |
| 519 } | 520 } |
| 520 | 521 |
| 521 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareIframeDontProceed) { | 522 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareIframeDontProceed) { |
| 522 GURL url = test_server()->GetURL(kMalwarePage); | 523 GURL url = test_server()->GetURL(kMalwarePage); |
| 523 GURL iframe_url = test_server()->GetURL(kMalwareIframe); | 524 GURL iframe_url = test_server()->GetURL(kMalwareIframe); |
| 524 AddURLResult(iframe_url, SafeBrowsingService::URL_MALWARE); | 525 AddURLResult(iframe_url, SafeBrowsingService::URL_MALWARE); |
| 525 | 526 |
| 526 ui_test_utils::NavigateToURL(browser(), url); | 527 ui_test_utils::NavigateToURL(browser(), url); |
| 527 | 528 |
| 528 ui_test_utils::WindowedNotificationObserver observer( | 529 ui_test_utils::WindowedNotificationObserver observer( |
| 529 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 530 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 530 content::Source<content::NavigationController>( | 531 content::Source<NavigationController>( |
| 531 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 532 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
| 532 GetController())); | 533 GetController())); |
| 533 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" | 534 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" |
| 534 observer.Wait(); | 535 observer.Wait(); |
| 535 AssertNoInterstitial(false); // Assert the interstitial is gone | 536 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 536 | 537 |
| 537 EXPECT_EQ( | 538 EXPECT_EQ( |
| 538 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 539 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
| 539 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); | 540 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); |
| 540 } | 541 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 SendCommand("\"proceed\""); // Simulate the user clicking "back" | 583 SendCommand("\"proceed\""); // Simulate the user clicking "back" |
| 583 AssertNoInterstitial(true); // Assert the interstitial is gone | 584 AssertNoInterstitial(true); // Assert the interstitial is gone |
| 584 | 585 |
| 585 EXPECT_EQ( | 586 EXPECT_EQ( |
| 586 url, | 587 url, |
| 587 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); | 588 browser()->GetSelectedTabContentsWrapper()->web_contents()->GetURL()); |
| 588 AssertReportSent(); | 589 AssertReportSent(); |
| 589 } | 590 } |
| 590 | 591 |
| 591 } // namespace | 592 } // namespace |
| OLD | NEW |