Commit 95b04667 authored by Ali Juma's avatar Ali Juma Committed by Commit Bot

[iOS] Respect kSafeBrowsingProceedAnywayDisabled pref.

Bug: 1062619
Change-Id: If542ea96db20edf083b6ad74cdf0cf3bac7ae4e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2198549
Commit-Queue: Ali Juma <ajuma@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Auto-Submit: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780414}
parent f70c648d
...@@ -32,6 +32,7 @@ source_set("safe_browsing") { ...@@ -32,6 +32,7 @@ source_set("safe_browsing") {
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core/browser", "//components/safe_browsing/core/browser",
"//components/safe_browsing/core/common", "//components/safe_browsing/core/common",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/safe_browsing/core/db", "//components/safe_browsing/core/db",
"//components/safe_browsing/core/db:database_manager", "//components/safe_browsing/core/db:database_manager",
"//components/safe_browsing/core/db:v4_local_database_manager", "//components/safe_browsing/core/db:v4_local_database_manager",
...@@ -104,10 +105,12 @@ source_set("eg2_tests") { ...@@ -104,10 +105,12 @@ source_set("eg2_tests") {
deps = [ deps = [
"//base", "//base",
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core/common:safe_browsing_prefs",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
"//ios/web/common:features", "//ios/web/common:features",
"//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server", "//ios/web/public/test/http_server",
"//net:test_support", "//net:test_support",
] ]
......
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#import "components/safe_browsing/ios/browser/safe_browsing_url_allow_list.h" #import "components/safe_browsing/ios/browser/safe_browsing_url_allow_list.h"
#include "components/security_interstitials/core/base_safe_browsing_error_ui.h" #include "components/security_interstitials/core/base_safe_browsing_error_ui.h"
#include "components/security_interstitials/core/metrics_helper.h" #include "components/security_interstitials/core/metrics_helper.h"
#include "components/security_interstitials/core/safe_browsing_loud_error_ui.h" #include "components/security_interstitials/core/safe_browsing_loud_error_ui.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/safe_browsing/unsafe_resource_util.h" #import "ios/chrome/browser/safe_browsing/unsafe_resource_util.h"
#include "ios/components/security_interstitials/ios_blocking_page_metrics_helper.h" #include "ios/components/security_interstitials/ios_blocking_page_metrics_helper.h"
#import "ios/web/public/web_state.h" #import "ios/web/public/web_state.h"
...@@ -48,6 +51,10 @@ std::unique_ptr<IOSBlockingPageMetricsHelper> CreateMetricsHelper( ...@@ -48,6 +51,10 @@ std::unique_ptr<IOSBlockingPageMetricsHelper> CreateMetricsHelper(
// Returns the default safe browsing error display options. // Returns the default safe browsing error display options.
BaseSafeBrowsingErrorUI::SBErrorDisplayOptions GetDefaultDisplayOptions( BaseSafeBrowsingErrorUI::SBErrorDisplayOptions GetDefaultDisplayOptions(
const UnsafeResource& resource) { const UnsafeResource& resource) {
web::WebState* web_state = resource.web_state_getter.Run();
ChromeBrowserState* browser_state =
ChromeBrowserState::FromBrowserState(web_state->GetBrowserState());
PrefService* prefs = browser_state->GetPrefs();
return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions( return BaseSafeBrowsingErrorUI::SBErrorDisplayOptions(
resource.IsMainPageLoadBlocked(), resource.IsMainPageLoadBlocked(),
/*is_extended_reporting_opt_in_allowed=*/false, /*is_extended_reporting_opt_in_allowed=*/false,
...@@ -55,7 +62,7 @@ BaseSafeBrowsingErrorUI::SBErrorDisplayOptions GetDefaultDisplayOptions( ...@@ -55,7 +62,7 @@ BaseSafeBrowsingErrorUI::SBErrorDisplayOptions GetDefaultDisplayOptions(
/*is_extended_reporting=*/false, /*is_extended_reporting=*/false,
/*is_sber_policy_managed=*/false, /*is_sber_policy_managed=*/false,
/*is_enhanced_protection_enabled=*/false, /*is_enhanced_protection_enabled=*/false,
/*is_proceed_anyway_disabled=*/false, prefs->GetBoolean(prefs::kSafeBrowsingProceedAnywayDisabled),
/*should_open_links_in_new_tab=*/false, /*should_open_links_in_new_tab=*/false,
/*always_show_back_to_safety=*/true, "cpn_safe_browsing"); /*always_show_back_to_safety=*/true, "cpn_safe_browsing");
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/values.h" #include "base/values.h"
#import "components/safe_browsing/ios/browser/safe_browsing_url_allow_list.h" #import "components/safe_browsing/ios/browser/safe_browsing_url_allow_list.h"
#include "components/security_interstitials/core/unsafe_resource.h" #include "components/security_interstitials/core/unsafe_resource.h"
#import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#import "ios/web/public/navigation/navigation_item.h" #import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h" #import "ios/web/public/test/fakes/test_navigation_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h" #import "ios/web/public/test/fakes/test_web_state.h"
...@@ -41,13 +42,16 @@ UnsafeResource CreateResource(web::WebState* web_state, const GURL& url) { ...@@ -41,13 +42,16 @@ UnsafeResource CreateResource(web::WebState* web_state, const GURL& url) {
class SafeBrowsingBlockingPageTest : public PlatformTest { class SafeBrowsingBlockingPageTest : public PlatformTest {
public: public:
SafeBrowsingBlockingPageTest() SafeBrowsingBlockingPageTest()
: url_("http://www.chromium.test"), : browser_state_(TestChromeBrowserState::Builder().Build()),
resource_(CreateResource(&web_state_, url_)), url_("http://www.chromium.test"),
page_(SafeBrowsingBlockingPage::Create(resource_)) { resource_(CreateResource(&web_state_, url_)) {
std::unique_ptr<web::TestNavigationManager> navigation_manager = std::unique_ptr<web::TestNavigationManager> navigation_manager =
std::make_unique<web::TestNavigationManager>(); std::make_unique<web::TestNavigationManager>();
navigation_manager->SetBrowserState(browser_state_.get());
navigation_manager_ = navigation_manager.get(); navigation_manager_ = navigation_manager.get();
web_state_.SetNavigationManager(std::move(navigation_manager)); web_state_.SetNavigationManager(std::move(navigation_manager));
web_state_.SetBrowserState(browser_state_.get());
page_ = SafeBrowsingBlockingPage::Create(resource_);
SafeBrowsingUrlAllowList::CreateForWebState(&web_state_); SafeBrowsingUrlAllowList::CreateForWebState(&web_state_);
SafeBrowsingUrlAllowList::FromWebState(&web_state_) SafeBrowsingUrlAllowList::FromWebState(&web_state_)
->AddPendingUnsafeNavigationDecision(url_, resource_.threat_type); ->AddPendingUnsafeNavigationDecision(url_, resource_.threat_type);
...@@ -64,6 +68,7 @@ class SafeBrowsingBlockingPageTest : public PlatformTest { ...@@ -64,6 +68,7 @@ class SafeBrowsingBlockingPageTest : public PlatformTest {
protected: protected:
web::WebTaskEnvironment task_environment_{ web::WebTaskEnvironment task_environment_{
web::WebTaskEnvironment::IO_MAINLOOP}; web::WebTaskEnvironment::IO_MAINLOOP};
std::unique_ptr<ChromeBrowserState> browser_state_;
web::TestWebState web_state_; web::TestWebState web_state_;
web::TestNavigationManager* navigation_manager_ = nullptr; web::TestNavigationManager* navigation_manager_ = nullptr;
GURL url_; GURL url_;
......
...@@ -5,13 +5,16 @@ ...@@ -5,13 +5,16 @@
#include <string> #include <string>
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/features.h" #include "components/safe_browsing/core/features.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/testing/earl_grey/app_launch_configuration.h" #include "ios/testing/earl_grey/app_launch_configuration.h"
#import "ios/testing/earl_grey/earl_grey_test.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/common/features.h" #import "ios/web/common/features.h"
#include "ios/web/public/test/element_selector.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -159,4 +162,38 @@ ...@@ -159,4 +162,38 @@
[ChromeEarlGrey waitForWebStateContainingText:_phishingContent]; [ChromeEarlGrey waitForWebStateContainingText:_phishingContent];
} }
// Tests that the proceed option is not shown when
// kSafeBrowsingProceedAnywayDisabled is enabled.
- (void)testProceedAlwaysDisabled {
// Enable the pref.
NSString* prefName =
base::SysUTF8ToNSString(prefs::kSafeBrowsingProceedAnywayDisabled);
[ChromeEarlGreyAppInterface setBoolValue:YES forUserPref:prefName];
// Load the a malware safe browsing error page.
[ChromeEarlGrey loadURL:_malwareURL];
[ChromeEarlGrey
waitForWebStateContainingText:"The site ahead contains malware"];
[ChromeEarlGrey tapWebStateElementWithID:@"details-button"];
[ChromeEarlGrey waitForWebStateContainingText:
"Google Safe Browsing recently detected malware"];
// Verify that the proceed-link element is not found. When the proceed link
// is disabled, the entire second paragraph hidden.
NSString* selector =
@"(function() {"
" var element = document.getElementById('final-paragraph');"
" if (element.classList.contains('hidden')) return true;"
" return false;"
"})()";
NSString* description = @"Hidden proceed-anyway link.";
ElementSelector* proceedLink =
[ElementSelector selectorWithScript:selector
selectorDescription:description];
GREYAssert(
[ChromeEarlGreyAppInterface webStateContainsElement:proceedLink],
@"Proceed anyway link shown despite kSafeBrowsingProceedAnywayDisabled");
}
@end @end
...@@ -337,6 +337,7 @@ TEST_F(ChromeWebClientTest, PrepareErrorPageWithSSLInfo) { ...@@ -337,6 +337,7 @@ TEST_F(ChromeWebClientTest, PrepareErrorPageWithSSLInfo) {
TEST_F(ChromeWebClientTest, PrepareErrorPageForSafeBrowsingError) { TEST_F(ChromeWebClientTest, PrepareErrorPageForSafeBrowsingError) {
// Store an unsafe resource in |web_state|'s container. // Store an unsafe resource in |web_state|'s container.
web::TestWebState web_state; web::TestWebState web_state;
web_state.SetBrowserState(browser_state());
SafeBrowsingUrlAllowList::CreateForWebState(&web_state); SafeBrowsingUrlAllowList::CreateForWebState(&web_state);
SafeBrowsingUnsafeResourceContainer::CreateForWebState(&web_state); SafeBrowsingUnsafeResourceContainer::CreateForWebState(&web_state);
security_interstitials::IOSBlockingPageTabHelper::CreateForWebState( security_interstitials::IOSBlockingPageTabHelper::CreateForWebState(
......
...@@ -187,6 +187,9 @@ ...@@ -187,6 +187,9 @@
// failed. // failed.
+ (NSError*)submitWebStateFormWithID:(NSString*)formID; + (NSError*)submitWebStateFormWithID:(NSString*)formID;
// Returns YES if the current WebState contains an element matching |selector|.
+ (BOOL)webStateContainsElement:(ElementSelector*)selector;
// Returns YES if the current WebState contains |text|. // Returns YES if the current WebState contains |text|.
+ (BOOL)webStateContainsText:(NSString*)text; + (BOOL)webStateContainsText:(NSString*)text;
......
...@@ -363,6 +363,11 @@ NSString* SerializedPref(const PrefService::Preference* pref) { ...@@ -363,6 +363,11 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
return nil; return nil;
} }
+ (BOOL)webStateContainsElement:(ElementSelector*)selector {
return web::test::IsWebViewContainingElement(
chrome_test_util::GetCurrentWebState(), selector);
}
+ (BOOL)webStateContainsText:(NSString*)text { + (BOOL)webStateContainsText:(NSString*)text {
return web::test::IsWebViewContainingText( return web::test::IsWebViewContainingText(
chrome_test_util::GetCurrentWebState(), base::SysNSStringToUTF8(text)); chrome_test_util::GetCurrentWebState(), base::SysNSStringToUTF8(text));
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
// Returns an ElementSelector to retrieve an element by a xpath query. // Returns an ElementSelector to retrieve an element by a xpath query.
+ (ElementSelector*)selectorWithXPathQuery:(const std::string&)query; + (ElementSelector*)selectorWithXPathQuery:(const std::string&)query;
// Returns an ElementSelector to retrieve an element described by
// |selectorDescription| using |selectorScript|.
+ (ElementSelector*)selectorWithScript:(NSString*)selectorScript
selectorDescription:(NSString*)selectorDescription;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
@end @end
......
...@@ -64,6 +64,12 @@ ...@@ -64,6 +64,12 @@
selectorDescription:description]; selectorDescription:description];
} }
+ (ElementSelector*)selectorWithScript:(NSString*)selectorScript
selectorDescription:(NSString*)selectorDescription {
return [[ElementSelector alloc] initWithSelectorScript:selectorScript
selectorDescription:selectorDescription];
}
- (instancetype)initWithSelectorScript:(NSString*)selectorScript - (instancetype)initWithSelectorScript:(NSString*)selectorScript
selectorDescription:(NSString*)selectorDescription { selectorDescription:(NSString*)selectorDescription {
if ((self = [super init])) { if ((self = [super init])) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment