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

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

Issue 981243003: Make commands consistent across security interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: if -> switch in SafeBrowsingBlockingPage Created 5 years, 9 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
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 known- 5 // This test creates a fake safebrowsing service, where we can inject known-
6 // threat urls. It then uses a real browser to go to these urls, and sends 6 // threat urls. It then uses a real browser to go to these urls, and sends
7 // "goback" or "proceed" commands and verifies they work. 7 // "goback" or "proceed" commands and verifies they work.
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/safe_browsing/database_manager.h" 17 #include "chrome/browser/safe_browsing/database_manager.h"
17 #include "chrome/browser/safe_browsing/malware_details.h" 18 #include "chrome/browser/safe_browsing/malware_details.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 19 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 21 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
21 #include "chrome/browser/safe_browsing/ui_manager.h" 22 #include "chrome/browser/safe_browsing/ui_manager.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 GURL SetupThreatIframeWarningAndNavigate() { 394 GURL SetupThreatIframeWarningAndNavigate() {
394 GURL url = test_server()->GetURL(kMalwarePage); 395 GURL url = test_server()->GetURL(kMalwarePage);
395 GURL iframe_url = test_server()->GetURL(kMalwareIframe); 396 GURL iframe_url = test_server()->GetURL(kMalwareIframe);
396 SetURLThreatType(iframe_url, GetParam()); 397 SetURLThreatType(iframe_url, GetParam());
397 398
398 ui_test_utils::NavigateToURL(browser(), url); 399 ui_test_utils::NavigateToURL(browser(), url);
399 EXPECT_TRUE(WaitForReady()); 400 EXPECT_TRUE(WaitForReady());
400 return url; 401 return url;
401 } 402 }
402 403
403 void SendCommand(const std::string& command) { 404 void SendCommand(
405 SecurityInterstitialPage::SecurityInterstitialCommands command) {
404 WebContents* contents = 406 WebContents* contents =
405 browser()->tab_strip_model()->GetActiveWebContents(); 407 browser()->tab_strip_model()->GetActiveWebContents();
406 // We use InterstitialPage::GetInterstitialPage(tab) instead of 408 // We use InterstitialPage::GetInterstitialPage(tab) instead of
407 // tab->GetInterstitialPage() because the tab doesn't have a pointer 409 // tab->GetInterstitialPage() because the tab doesn't have a pointer
408 // to its interstital page until it gets a command from the renderer 410 // to its interstital page until it gets a command from the renderer
409 // that it has indeed displayed it -- and this sometimes happens after 411 // that it has indeed displayed it -- and this sometimes happens after
410 // NavigateToURL returns. 412 // NavigateToURL returns.
411 SafeBrowsingBlockingPage* interstitial_page = 413 SafeBrowsingBlockingPage* interstitial_page =
412 static_cast<SafeBrowsingBlockingPage*>( 414 static_cast<SafeBrowsingBlockingPage*>(
413 InterstitialPage::GetInterstitialPage(contents)-> 415 InterstitialPage::GetInterstitialPage(contents)->
414 GetDelegateForTesting()); 416 GetDelegateForTesting());
415 ASSERT_TRUE(interstitial_page); 417 ASSERT_TRUE(interstitial_page);
416 ASSERT_EQ(SafeBrowsingBlockingPage::kTypeForTesting, 418 ASSERT_EQ(SafeBrowsingBlockingPage::kTypeForTesting,
417 interstitial_page->GetTypeForTesting()); 419 interstitial_page->GetTypeForTesting());
418 interstitial_page->CommandReceived(command); 420 interstitial_page->CommandReceived(base::IntToString(command));
419 } 421 }
420 422
421 void DontProceedThroughInterstitial() { 423 void DontProceedThroughInterstitial() {
422 WebContents* contents = 424 WebContents* contents =
423 browser()->tab_strip_model()->GetActiveWebContents(); 425 browser()->tab_strip_model()->GetActiveWebContents();
424 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage( 426 InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
425 contents); 427 contents);
426 ASSERT_TRUE(interstitial_page); 428 ASSERT_TRUE(interstitial_page);
427 interstitial_page->DontProceed(); 429 interstitial_page->DontProceed();
428 } 430 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 content::WaitForInterstitialAttach(contents); 495 content::WaitForInterstitialAttach(contents);
494 // Cancel the redirect request while interstitial page is open. 496 // Cancel the redirect request while interstitial page is open.
495 browser()->tab_strip_model()->ActivateTabAt(0, true); 497 browser()->tab_strip_model()->ActivateTabAt(0, true);
496 ui_test_utils::NavigateToURL(browser(), GURL("javascript:stopWin()")); 498 ui_test_utils::NavigateToURL(browser(), GURL("javascript:stopWin()"));
497 browser()->tab_strip_model()->ActivateTabAt(1, true); 499 browser()->tab_strip_model()->ActivateTabAt(1, true);
498 // Simulate the user clicking "proceed", there should be no crash. Since 500 // Simulate the user clicking "proceed", there should be no crash. Since
499 // clicking proceed may do nothing (see comment in RedirectCanceled 501 // clicking proceed may do nothing (see comment in RedirectCanceled
500 // below, and crbug.com/76460), we use SendCommand to trigger the callback 502 // below, and crbug.com/76460), we use SendCommand to trigger the callback
501 // directly rather than using ClickAndWaitForDetach since there might not 503 // directly rather than using ClickAndWaitForDetach since there might not
502 // be a notification to wait for. 504 // be a notification to wait for.
503 SendCommand("\"proceed\""); 505 SendCommand(SecurityInterstitialPage::CMD_PROCEED);
504 } 506 }
505 507
506 content::RenderViewHost* GetRenderViewHost() { 508 content::RenderViewHost* GetRenderViewHost() {
507 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage( 509 InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
508 browser()->tab_strip_model()->GetActiveWebContents()); 510 browser()->tab_strip_model()->GetActiveWebContents());
509 if (!interstitial) 511 if (!interstitial)
510 return NULL; 512 return NULL;
511 return interstitial->GetMainFrame()->GetRenderViewHost(); 513 return interstitial->GetMainFrame()->GetRenderViewHost();
512 } 514 }
513 515
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 727
726 SetupWarningAndNavigate(); 728 SetupWarningAndNavigate();
727 729
728 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); 730 EXPECT_EQ(VISIBLE, GetVisibility("primary-button"));
729 EXPECT_EQ(HIDDEN, GetVisibility("details")); 731 EXPECT_EQ(HIDDEN, GetVisibility("details"));
730 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 732 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
731 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); 733 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph"));
732 EXPECT_TRUE(Click("details-button")); 734 EXPECT_TRUE(Click("details-button"));
733 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); 735 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link"));
734 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph")); 736 EXPECT_EQ(HIDDEN, GetVisibility("final-paragraph"));
735 SendCommand("proceed"); 737 SendCommand(SecurityInterstitialPage::CMD_PROCEED);
736 738
737 // The "proceed" command should go back instead, if proceeding is disabled. 739 // The "proceed" command should go back instead, if proceeding is disabled.
738 AssertNoInterstitial(true); 740 AssertNoInterstitial(true);
739 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank" 741 EXPECT_EQ(GURL(url::kAboutBlankURL), // Back to "about:blank"
740 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); 742 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
741 } 743 }
742 744
743 // Verifies that the reporting checkbox is hidden on non-HTTP pages. 745 // Verifies that the reporting checkbox is hidden on non-HTTP pages.
744 // TODO(mattm): Should also verify that no report is sent, but there isn't a 746 // TODO(mattm): Should also verify that no report is sent, but there isn't a
745 // good way to do that in the current design. 747 // good way to do that in the current design.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 ? "/transparencyreport/safebrowsing/" 789 ? "/transparencyreport/safebrowsing/"
788 : "/safebrowsing/diagnostic", 790 : "/safebrowsing/diagnostic",
789 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path()); 791 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().path());
790 } 792 }
791 793
792 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType, 794 INSTANTIATE_TEST_CASE_P(SafeBrowsingBlockingPageBrowserTestWithThreatType,
793 SafeBrowsingBlockingPageBrowserTest, 795 SafeBrowsingBlockingPageBrowserTest,
794 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 796 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
795 SB_THREAT_TYPE_URL_PHISHING, 797 SB_THREAT_TYPE_URL_PHISHING,
796 SB_THREAT_TYPE_URL_UNWANTED)); 798 SB_THREAT_TYPE_URL_UNWANTED));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698