Chromium Code Reviews| 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" |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "base/values.h" | |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/safe_browsing/malware_details.h" | 16 #include "chrome/browser/safe_browsing/malware_details.h" |
| 15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/interstitial_page.h" | 26 #include "content/public/browser/interstitial_page.h" |
| 25 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
| 26 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/render_view_host.h" | |
| 27 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_view.h" | 31 #include "content/public/browser/web_contents_view.h" |
| 29 #include "content/public/test/test_browser_thread.h" | 32 #include "content/public/test/test_browser_thread.h" |
| 30 | 33 |
| 31 using content::BrowserThread; | 34 using content::BrowserThread; |
| 32 using content::InterstitialPage; | 35 using content::InterstitialPage; |
| 33 using content::NavigationController; | 36 using content::NavigationController; |
| 34 using content::WebContents; | 37 using content::WebContents; |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 ui_test_utils::NavigateToURLWithDisposition( | 365 ui_test_utils::NavigateToURLWithDisposition( |
| 363 browser(), | 366 browser(), |
| 364 GURL("javascript:stopWin()"), | 367 GURL("javascript:stopWin()"), |
| 365 CURRENT_TAB, | 368 CURRENT_TAB, |
| 366 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 369 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 367 chrome::ActivateTabAt(browser(), 1, true); | 370 chrome::ActivateTabAt(browser(), 1, true); |
| 368 // Simulate the user clicking "proceed", there should be no crash. | 371 // Simulate the user clicking "proceed", there should be no crash. |
| 369 SendCommand("\"proceed\""); | 372 SendCommand("\"proceed\""); |
| 370 } | 373 } |
| 371 | 374 |
| 375 bool GetProceedLinkIsHidden(bool* result) { | |
| 376 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( | |
| 377 chrome::GetActiveWebContents(browser())); | |
| 378 if (!interstitial) | |
| 379 return false; | |
| 380 content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting(); | |
| 381 if (!rvh) | |
| 382 return false; | |
| 383 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( | |
| 384 string16(), | |
| 385 ASCIIToUTF16( | |
| 386 // Make sure jstemplate has processed the page. | |
| 387 "var root = document.getElementById('template_root');\n" | |
| 388 "jstProcess(new JsEvalContext(templateData), root);\n" | |
|
Mattias Nissler (ping if slow)
2012/07/10 11:28:45
If I were in your shoes, I'd just wait a day or tw
Joao da Silva
2012/07/12 14:27:21
Haven't found a better way to do this. John's sugg
| |
| 389 // Now inspect the "proceed anyway" <div>. | |
| 390 "var list = document.querySelectorAll(" | |
| 391 " 'div[jsdisplay=\"!proceedDisabled\"]');\n" | |
| 392 "if (list.length == 1)\n" | |
| 393 " list[0].style.display === 'none';\n" | |
| 394 "else\n" | |
| 395 " 'Fail with non-boolean result value';\n"))); | |
| 396 if (!value.get()) | |
| 397 return false; | |
| 398 return value->GetAsBoolean(result); | |
| 399 } | |
| 400 | |
| 372 protected: | 401 protected: |
| 373 TestMalwareDetailsFactory details_factory_; | 402 TestMalwareDetailsFactory details_factory_; |
| 374 | 403 |
| 375 private: | 404 private: |
| 376 TestSafeBrowsingServiceFactory factory_; | 405 TestSafeBrowsingServiceFactory factory_; |
| 377 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; | 406 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; |
| 378 | 407 |
| 379 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); | 408 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); |
| 380 }; | 409 }; |
| 381 | 410 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 399 // already. See crbug.com/76460. | 428 // already. See crbug.com/76460. |
| 400 EXPECT_TRUE(YesInterstitial()); | 429 EXPECT_TRUE(YesInterstitial()); |
| 401 } | 430 } |
| 402 | 431 |
| 403 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { | 432 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { |
| 404 GURL url = test_server()->GetURL(kEmptyPage); | 433 GURL url = test_server()->GetURL(kEmptyPage); |
| 405 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 434 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
| 406 | 435 |
| 407 ui_test_utils::NavigateToURL(browser(), url); | 436 ui_test_utils::NavigateToURL(browser(), url); |
| 408 | 437 |
| 438 bool hidden = false; | |
| 439 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); | |
| 440 EXPECT_FALSE(hidden); | |
| 441 | |
| 409 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" | 442 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" |
| 410 AssertNoInterstitial(false); // Assert the interstitial is gone | 443 AssertNoInterstitial(false); // Assert the interstitial is gone |
| 411 EXPECT_EQ( | 444 EXPECT_EQ( |
| 412 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 445 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
| 413 chrome::GetActiveWebContents(browser())->GetURL()); | 446 chrome::GetActiveWebContents(browser())->GetURL()); |
| 414 } | 447 } |
| 415 | 448 |
| 416 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { | 449 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { |
| 417 GURL url = test_server()->GetURL(kEmptyPage); | 450 GURL url = test_server()->GetURL(kEmptyPage); |
| 418 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 451 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. | 588 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. |
| 556 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 589 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
| 557 prefs::kSafeBrowsingReportingEnabled)); | 590 prefs::kSafeBrowsingReportingEnabled)); |
| 558 | 591 |
| 559 SendCommand("\"proceed\""); // Simulate the user clicking "back" | 592 SendCommand("\"proceed\""); // Simulate the user clicking "back" |
| 560 AssertNoInterstitial(true); // Assert the interstitial is gone | 593 AssertNoInterstitial(true); // Assert the interstitial is gone |
| 561 | 594 |
| 562 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); | 595 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); |
| 563 AssertReportSent(); | 596 AssertReportSent(); |
| 564 } | 597 } |
| 598 | |
| 599 // Verifies that the "proceed anyway" link isn't available when it is disabled | |
| 600 // by the corresponding policy. Also verifies that sending the "proceed" | |
| 601 // command anyway doesn't advance to the malware site. | |
| 602 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) { | |
| 603 // Simulate a policy disabling the "proceed anyway" link. | |
| 604 browser()->profile()->GetPrefs()->SetBoolean( | |
| 605 prefs::kSafeBrowsingProceedAnywayDisabled, true); | |
| 606 | |
| 607 GURL url = test_server()->GetURL(kEmptyPage); | |
| 608 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | |
| 609 ui_test_utils::NavigateToURL(browser(), url); | |
| 610 | |
| 611 // The "proceed anyway" link should be hidden. | |
| 612 bool hidden = false; | |
| 613 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); | |
| 614 EXPECT_TRUE(hidden); | |
| 615 | |
| 616 // The "proceed" command should go back instead, if proceeding is disabled. | |
| 617 SendCommand("\"proceed\""); | |
| 618 AssertNoInterstitial(true); | |
| 619 EXPECT_EQ( | |
| 620 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | |
| 621 chrome::GetActiveWebContents(browser())->GetURL()); | |
| 622 } | |
| OLD | NEW |