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("var isHidden = false;\n" |
| 386 "var list = document.querySelectorAll(" |
| 387 "'div[jsdisplay=\"!proceedDisabled\"]');" |
| 388 "if (list.length == 1)\n" |
| 389 " isHidden = list[0].style.display === 'none';\n" |
| 390 "isHidden;\n"))); |
| 391 if (!value.get()) |
| 392 return false; |
| 393 return value->GetAsBoolean(result); |
| 394 } |
| 395 |
372 protected: | 396 protected: |
373 TestMalwareDetailsFactory details_factory_; | 397 TestMalwareDetailsFactory details_factory_; |
374 | 398 |
375 private: | 399 private: |
376 TestSafeBrowsingServiceFactory factory_; | 400 TestSafeBrowsingServiceFactory factory_; |
377 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; | 401 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; |
378 | 402 |
379 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); | 403 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); |
380 }; | 404 }; |
381 | 405 |
(...skipping 17 matching lines...) Expand all Loading... |
399 // already. See crbug.com/76460. | 423 // already. See crbug.com/76460. |
400 EXPECT_TRUE(YesInterstitial()); | 424 EXPECT_TRUE(YesInterstitial()); |
401 } | 425 } |
402 | 426 |
403 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { | 427 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { |
404 GURL url = test_server()->GetURL(kEmptyPage); | 428 GURL url = test_server()->GetURL(kEmptyPage); |
405 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 429 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
406 | 430 |
407 ui_test_utils::NavigateToURL(browser(), url); | 431 ui_test_utils::NavigateToURL(browser(), url); |
408 | 432 |
| 433 bool hidden = false; |
| 434 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); |
| 435 EXPECT_FALSE(hidden); |
| 436 |
409 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" | 437 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" |
410 AssertNoInterstitial(false); // Assert the interstitial is gone | 438 AssertNoInterstitial(false); // Assert the interstitial is gone |
411 EXPECT_EQ( | 439 EXPECT_EQ( |
412 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 440 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
413 chrome::GetActiveWebContents(browser())->GetURL()); | 441 chrome::GetActiveWebContents(browser())->GetURL()); |
414 } | 442 } |
415 | 443 |
416 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { | 444 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { |
417 GURL url = test_server()->GetURL(kEmptyPage); | 445 GURL url = test_server()->GetURL(kEmptyPage); |
418 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 446 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. | 583 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. |
556 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 584 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
557 prefs::kSafeBrowsingReportingEnabled)); | 585 prefs::kSafeBrowsingReportingEnabled)); |
558 | 586 |
559 SendCommand("\"proceed\""); // Simulate the user clicking "back" | 587 SendCommand("\"proceed\""); // Simulate the user clicking "back" |
560 AssertNoInterstitial(true); // Assert the interstitial is gone | 588 AssertNoInterstitial(true); // Assert the interstitial is gone |
561 | 589 |
562 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); | 590 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); |
563 AssertReportSent(); | 591 AssertReportSent(); |
564 } | 592 } |
| 593 |
| 594 // Verifies that the "proceed anyway" link isn't available when it is disabled |
| 595 // by the corresponding policy. Also verifies that sending the "proceed" |
| 596 // command anyway doesn't advance to the malware site. |
| 597 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) { |
| 598 // Simulate a policy disabling the "proceed anyway" link. |
| 599 browser()->profile()->GetPrefs()->SetBoolean( |
| 600 prefs::kSafeBrowsingProceedAnywayDisabled, true); |
| 601 |
| 602 GURL url = test_server()->GetURL(kEmptyPage); |
| 603 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
| 604 ui_test_utils::NavigateToURL(browser(), url); |
| 605 |
| 606 // The "proceed anyway" link should be hidden. |
| 607 bool hidden = false; |
| 608 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden)); |
| 609 EXPECT_TRUE(hidden); |
| 610 |
| 611 // The "proceed" command should go back instead, if proceeding is disabled. |
| 612 SendCommand("\"proceed\""); |
| 613 AssertNoInterstitial(true); |
| 614 EXPECT_EQ( |
| 615 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
| 616 chrome::GetActiveWebContents(browser())->GetURL()); |
| 617 } |
OLD | NEW |