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

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

Issue 10694107: Revert 145523 - Add a policy to disable proceeding through the Safe Browsing interstitials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
13 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/safe_browsing/malware_details.h" 14 #include "chrome/browser/safe_browsing/malware_details.h"
17 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
19 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 18 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents.h"
22 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
24 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/interstitial_page.h" 24 #include "content/public/browser/interstitial_page.h"
27 #include "content/public/browser/navigation_controller.h" 25 #include "content/public/browser/navigation_controller.h"
28 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_contents_view.h" 28 #include "content/public/browser/web_contents_view.h"
32 #include "content/public/test/test_browser_thread.h" 29 #include "content/public/test/test_browser_thread.h"
33 30
34 using content::BrowserThread; 31 using content::BrowserThread;
35 using content::InterstitialPage; 32 using content::InterstitialPage;
36 using content::NavigationController; 33 using content::NavigationController;
37 using content::WebContents; 34 using content::WebContents;
38 35
39 namespace { 36 namespace {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 ui_test_utils::NavigateToURLWithDisposition( 362 ui_test_utils::NavigateToURLWithDisposition(
366 browser(), 363 browser(),
367 GURL("javascript:stopWin()"), 364 GURL("javascript:stopWin()"),
368 CURRENT_TAB, 365 CURRENT_TAB,
369 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 366 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
370 chrome::ActivateTabAt(browser(), 1, true); 367 chrome::ActivateTabAt(browser(), 1, true);
371 // Simulate the user clicking "proceed", there should be no crash. 368 // Simulate the user clicking "proceed", there should be no crash.
372 SendCommand("\"proceed\""); 369 SendCommand("\"proceed\"");
373 } 370 }
374 371
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
396 protected: 372 protected:
397 TestMalwareDetailsFactory details_factory_; 373 TestMalwareDetailsFactory details_factory_;
398 374
399 private: 375 private:
400 TestSafeBrowsingServiceFactory factory_; 376 TestSafeBrowsingServiceFactory factory_;
401 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; 377 TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
402 378
403 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest); 379 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest);
404 }; 380 };
405 381
(...skipping 17 matching lines...) Expand all
423 // already. See crbug.com/76460. 399 // already. See crbug.com/76460.
424 EXPECT_TRUE(YesInterstitial()); 400 EXPECT_TRUE(YesInterstitial());
425 } 401 }
426 402
427 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) { 403 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) {
428 GURL url = test_server()->GetURL(kEmptyPage); 404 GURL url = test_server()->GetURL(kEmptyPage);
429 AddURLResult(url, SafeBrowsingService::URL_MALWARE); 405 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
430 406
431 ui_test_utils::NavigateToURL(browser(), url); 407 ui_test_utils::NavigateToURL(browser(), url);
432 408
433 bool hidden = false;
434 EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
435 EXPECT_FALSE(hidden);
436
437 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back" 409 SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
438 AssertNoInterstitial(false); // Assert the interstitial is gone 410 AssertNoInterstitial(false); // Assert the interstitial is gone
439 EXPECT_EQ( 411 EXPECT_EQ(
440 GURL(chrome::kAboutBlankURL), // Back to "about:blank" 412 GURL(chrome::kAboutBlankURL), // Back to "about:blank"
441 chrome::GetActiveWebContents(browser())->GetURL()); 413 chrome::GetActiveWebContents(browser())->GetURL());
442 } 414 }
443 415
444 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) { 416 IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) {
445 GURL url = test_server()->GetURL(kEmptyPage); 417 GURL url = test_server()->GetURL(kEmptyPage);
446 AddURLResult(url, SafeBrowsingService::URL_MALWARE); 418 AddURLResult(url, SafeBrowsingService::URL_MALWARE);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 SendCommand("\"doReport\""); // Simulate the user checking the checkbox. 555 SendCommand("\"doReport\""); // Simulate the user checking the checkbox.
584 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 556 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
585 prefs::kSafeBrowsingReportingEnabled)); 557 prefs::kSafeBrowsingReportingEnabled));
586 558
587 SendCommand("\"proceed\""); // Simulate the user clicking "back" 559 SendCommand("\"proceed\""); // Simulate the user clicking "back"
588 AssertNoInterstitial(true); // Assert the interstitial is gone 560 AssertNoInterstitial(true); // Assert the interstitial is gone
589 561
590 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL()); 562 EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
591 AssertReportSent(); 563 AssertReportSent();
592 } 564 }
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 }
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