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/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/browser/interstitial_page.h" | 25 #include "content/public/browser/interstitial_page.h" |
24 #include "content/public/browser/navigation_controller.h" | 26 #include "content/public/browser/navigation_controller.h" |
25 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
28 #include "content/public/browser/render_view_host.h" | |
26 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_view.h" | 30 #include "content/public/browser/web_contents_view.h" |
28 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
29 | 32 |
30 using content::BrowserThread; | 33 using content::BrowserThread; |
31 using content::InterstitialPage; | 34 using content::InterstitialPage; |
32 using content::NavigationController; | 35 using content::NavigationController; |
33 using content::WebContents; | 36 using content::WebContents; |
34 | 37 |
35 namespace { | 38 namespace { |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 ui_test_utils::NavigateToURLWithDisposition( | 364 ui_test_utils::NavigateToURLWithDisposition( |
362 browser(), | 365 browser(), |
363 GURL("javascript:stopWin()"), | 366 GURL("javascript:stopWin()"), |
364 CURRENT_TAB, | 367 CURRENT_TAB, |
365 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 368 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
366 browser()->ActivateTabAt(1, true); | 369 browser()->ActivateTabAt(1, true); |
367 // Simulate the user clicking "proceed", there should be no crash. | 370 // Simulate the user clicking "proceed", there should be no crash. |
368 SendCommand("\"proceed\""); | 371 SendCommand("\"proceed\""); |
369 } | 372 } |
370 | 373 |
374 bool GetProceedLinkIsHidden(bool* result) { | |
375 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( | |
376 browser()->GetActiveWebContents()); | |
377 if (!interstitial) | |
378 return false; | |
379 content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting(); | |
380 if (!rvh) | |
381 return false; | |
382 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( | |
383 ASCIIToUTF16(""), | |
James Hawkins
2012/06/29 17:31:51
string16().
Joao da Silva
2012/07/02 10:08:40
Done.
| |
384 ASCIIToUTF16("var isHidden = false;\n" | |
385 "var list = document.querySelectorAll(" | |
386 "'div[jsdisplay=\"!proceed_disabled\"]');" | |
387 "if (list.length == 1)\n" | |
388 " isHidden = list[0].style.display === 'none';\n" | |
389 "isHidden;\n"))); | |
390 if (!value.get()) | |
391 return false; | |
392 return value->GetAsBoolean(result); | |
393 } | |
394 | |
371 protected: | 395 protected: |
372 TestMalwareDetailsFactory details_factory_; | 396 TestMalwareDetailsFactory details_factory_; |
373 | 397 |
374 private: | 398 private: |
375 TestSafeBrowsingServiceFactory factory_; | 399 TestSafeBrowsingServiceFactory factory_; |
376 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; | 400 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; |
377 | 401 |
378 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); | 402 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); |
379 }; | 403 }; |
380 | 404 |
(...skipping 17 matching lines...) Expand all Loading... | |
398 // already. See crbug.com/76460. | 422 // already. See crbug.com/76460. |
399 EXPECT_TRUE(YesInterstitial()); | 423 EXPECT_TRUE(YesInterstitial()); |
400 } | 424 } |
401 | 425 |
402 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { | 426 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { |
403 GURL url = test_server()->GetURL(kEmptyPage); | 427 GURL url = test_server()->GetURL(kEmptyPage); |
404 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 428 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
405 | 429 |
406 ui_test_utils::NavigateToURL(browser(), url); | 430 ui_test_utils::NavigateToURL(browser(), url); |
407 | 431 |
432 bool hidden = false; | |
433 ASSERT_TRUE(GetProceedLinkIsHidden(&hidden)); | |
James Hawkins
2012/06/29 17:31:51
s/ASSERT/EXPECT/
Joao da Silva
2012/07/02 10:08:40
Done.
| |
434 EXPECT_FALSE(hidden); | |
435 | |
408 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" | 436 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" |
409 AssertNoInterstitial(false); // Assert the interstitial is gone | 437 AssertNoInterstitial(false); // Assert the interstitial is gone |
410 EXPECT_EQ( | 438 EXPECT_EQ( |
411 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | 439 GURL(chrome::kAboutBlankURL), // Back to "about:blank" |
412 browser()->GetActiveWebContents()->GetURL()); | 440 browser()->GetActiveWebContents()->GetURL()); |
413 } | 441 } |
414 | 442 |
415 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { | 443 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { |
416 GURL url = test_server()->GetURL(kEmptyPage); | 444 GURL url = test_server()->GetURL(kEmptyPage); |
417 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | 445 AddURLResult(url, SafeBrowsingService::URL_MALWARE); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. | 582 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. |
555 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 583 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
556 prefs::kSafeBrowsingReportingEnabled)); | 584 prefs::kSafeBrowsingReportingEnabled)); |
557 | 585 |
558 SendCommand("\"proceed\""); // Simulate the user clicking "back" | 586 SendCommand("\"proceed\""); // Simulate the user clicking "back" |
559 AssertNoInterstitial(true); // Assert the interstitial is gone | 587 AssertNoInterstitial(true); // Assert the interstitial is gone |
560 | 588 |
561 EXPECT_EQ(url, browser()->GetActiveWebContents()->GetURL()); | 589 EXPECT_EQ(url, browser()->GetActiveWebContents()->GetURL()); |
562 AssertReportSent(); | 590 AssertReportSent(); |
563 } | 591 } |
592 | |
593 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) { | |
James Hawkins
2012/06/29 17:31:51
nit: Document what this test is testing.
Joao da Silva
2012/07/02 10:08:40
Done.
| |
594 // Simulate a policy disabling the "proceed anyway" link. | |
595 browser()->profile()->GetPrefs()->SetBoolean( | |
596 prefs::kSafeBrowsingProceedAnywayDisabled, true); | |
597 | |
598 GURL url = test_server()->GetURL(kEmptyPage); | |
599 AddURLResult(url, SafeBrowsingService::URL_MALWARE); | |
600 ui_test_utils::NavigateToURL(browser(), url); | |
601 | |
602 // The "proceed anyway" link should be hidden. | |
603 bool hidden = false; | |
604 ASSERT_TRUE(GetProceedLinkIsHidden(&hidden)); | |
605 EXPECT_TRUE(hidden); | |
606 | |
607 // The "proceed" command should go back instead, if proceeding is disabled. | |
608 SendCommand("\"proceed\""); | |
609 AssertNoInterstitial(true); | |
610 EXPECT_EQ( | |
611 GURL(chrome::kAboutBlankURL), // Back to "about:blank" | |
612 browser()->GetActiveWebContents()->GetURL()); | |
613 } | |
OLD | NEW |