Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 10690102: Relanding https://chromiumcodereview.appspot.com/10694037 after a revert. The original CL failed on… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added TODO Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // TODO(joaodasilva): it would be better to make sure all the
388 // <script> tags have executed before injecting more javascript.
389 "var root = document.getElementById('template_root');\n"
390 "jstProcess(new JsEvalContext(templateData), root);\n"
391 // Now inspect the "proceed anyway" <div>.
392 "var list = document.querySelectorAll("
393 " 'div[jsdisplay=\"!proceedDisabled\"]');\n"
394 "if (list.length == 1)\n"
395 " list[0].style.display === 'none';\n"
396 "else\n"
397 " 'Fail with non-boolean result value';\n")));
398 if (!value.get())
399 return false;
400 return value->GetAsBoolean(result);
401 }
402
372 protected: 403 protected:
373 TestMalwareDetailsFactory details_factory_; 404 TestMalwareDetailsFactory details_factory_;
374 405
375 private: 406 private:
376 TestSafeBrowsingServiceFactory factory_; 407 TestSafeBrowsingServiceFactory factory_;
377 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; 408 TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
378 409
379 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); 410 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest);
380 }; 411 };
381 412
(...skipping 17 matching lines...) Expand all
399 // already. See crbug.com/76460. 430 // already. See crbug.com/76460.
400 EXPECT_TRUE(YesInterstitial()); 431 EXPECT_TRUE(YesInterstitial());
401 } 432 }
402 433
403 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { 434 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) {
404 GURL url = test_server()->GetURL(kEmptyPage); 435 GURL url = test_server()->GetURL(kEmptyPage);
405 AddURLResult(url, SafeBrowsingService::URL_MALWARE); 436 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
406 437
407 ui_test_utils::NavigateToURL(browser(), url); 438 ui_test_utils::NavigateToURL(browser(), url);
408 439
440 bool hidden = false;
441 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
442 EXPECT_FALSE(hidden);
443
409 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" 444 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
410 AssertNoInterstitial(false); // Assert the interstitial is gone 445 AssertNoInterstitial(false); // Assert the interstitial is gone
411 EXPECT_EQ( 446 EXPECT_EQ(
412 GURL(chrome::kAboutBlankURL), // Back to "about:blank" 447 GURL(chrome::kAboutBlankURL), // Back to "about:blank"
413 chrome::GetActiveWebContents(browser())->GetURL()); 448 chrome::GetActiveWebContents(browser())->GetURL());
414 } 449 }
415 450
416 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { 451 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) {
417 GURL url = test_server()->GetURL(kEmptyPage); 452 GURL url = test_server()->GetURL(kEmptyPage);
418 AddURLResult(url, SafeBrowsingService::URL_MALWARE); 453 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. 590 SendCommand("\"doReport\""); // Simulate the user checking the checkbox.
556 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 591 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
557 prefs::kSafeBrowsingReportingEnabled)); 592 prefs::kSafeBrowsingReportingEnabled));
558 593
559 SendCommand("\"proceed\""); // Simulate the user clicking "back" 594 SendCommand("\"proceed\""); // Simulate the user clicking "back"
560 AssertNoInterstitial(true); // Assert the interstitial is gone 595 AssertNoInterstitial(true); // Assert the interstitial is gone
561 596
562 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); 597 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
563 AssertReportSent(); 598 AssertReportSent();
564 } 599 }
600
601 // Verifies that the "proceed anyway" link isn't available when it is disabled
602 // by the corresponding policy. Also verifies that sending the "proceed"
603 // command anyway doesn't advance to the malware site.
604 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) {
605 // Simulate a policy disabling the "proceed anyway" link.
606 browser()->profile()->GetPrefs()->SetBoolean(
607 prefs::kSafeBrowsingProceedAnywayDisabled, true);
608
609 GURL url = test_server()->GetURL(kEmptyPage);
610 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
611 ui_test_utils::NavigateToURL(browser(), url);
612
613 // The "proceed anyway" link should be hidden.
614 bool hidden = false;
615 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
616 EXPECT_TRUE(hidden);
617
618 // The "proceed" command should go back instead, if proceeding is disabled.
619 SendCommand("\"proceed\"");
620 AssertNoInterstitial(true);
621 EXPECT_EQ(
622 GURL(chrome::kAboutBlankURL), // Back to "about:blank"
623 chrome::GetActiveWebContents(browser())->GetURL());
624 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698