Commit 901f759f authored by Ali Juma's avatar Ali Juma Committed by Commit Bot

[iOS] Add more integration tests for real-time Safe Browsing

This add additional EG test coverage for real-time Safe Browsing,
for scenarios identified by the test team when they were manually
testing this feature.

Bug: 1122997
Change-Id: I984babf81e251381965454679fa293426fc4c958
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392977
Commit-Queue: Ali Juma <ajuma@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805042}
parent 982b79cc
...@@ -122,6 +122,7 @@ source_set("eg2_tests") { ...@@ -122,6 +122,7 @@ source_set("eg2_tests") {
"//components/safe_browsing/core:features", "//components/safe_browsing/core:features",
"//components/safe_browsing/core/common:safe_browsing_prefs", "//components/safe_browsing/core/common:safe_browsing_prefs",
"//components/strings:components_strings_grit", "//components/strings:components_strings_grit",
"//ios/chrome/browser/ui/bookmarks:eg_test_support+eg2",
"//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",
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "components/safe_browsing/core/common/safe_browsing_prefs.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"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_earl_grey_ui.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_earl_grey_app_interface.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
...@@ -28,6 +30,7 @@ ...@@ -28,6 +30,7 @@
using chrome_test_util::BackButton; using chrome_test_util::BackButton;
using chrome_test_util::ForwardButton; using chrome_test_util::ForwardButton;
using chrome_test_util::TappableBookmarkNodeWithLabel;
namespace { namespace {
...@@ -156,7 +159,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -156,7 +159,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
// Ensure that the real-time Safe Browsing opt-in starts in the default // Ensure that the real-time Safe Browsing opt-in starts in the default
// (opted-out) state. // (opted-out) state.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:false]; [ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:NO];
} }
- (void)tearDown { - (void)tearDown {
...@@ -170,7 +173,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -170,7 +173,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
// Ensure that the real-time Safe Browsing opt-in is reset to its original // Ensure that the real-time Safe Browsing opt-in is reset to its original
// value. // value.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:false]; [ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:NO];
[super tearDown]; [super tearDown];
} }
...@@ -651,11 +654,29 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -651,11 +654,29 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
[ChromeEarlGrey waitForWebStateContainingText:_realTimePhishingContent]; [ChromeEarlGrey waitForWebStateContainingText:_realTimePhishingContent];
} }
// Tests that real-time lookups are not performed when opted-out of Safe
// Browsing, regardless of the state of the real-time opt-in.
- (void)testRealTimeLookupsWhileOptedOutOfSafeBrowsing {
// Opt out of Safe Browsing.
[ChromeEarlGrey setBoolValue:NO forUserPref:prefs::kSafeBrowsingEnabled];
// Load the real-time phishing page and verify that no warning is shown.
[ChromeEarlGrey loadURL:_realTimePhishingURL];
[ChromeEarlGrey waitForWebStateContainingText:_realTimePhishingContent];
// Opt-in to real-time checks and verify that it's still the case that no
// warning is shown.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:YES];
[ChromeEarlGrey openNewTab];
[ChromeEarlGrey loadURL:_realTimePhishingURL];
[ChromeEarlGrey waitForWebStateContainingText:_realTimePhishingContent];
}
// Tests that a page identified as unsafe by real-time Safe Browsing is blocked // Tests that a page identified as unsafe by real-time Safe Browsing is blocked
// when opted-in to real-time lookups. // when opted-in to real-time lookups.
- (void)testRealTimeLookupsWhileOptedIn { - (void)testRealTimeLookupsWhileOptedIn {
// Opt-in to real-time checks. // Opt-in to real-time checks.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:true]; [ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:YES];
// Load the real-time phishing page and verify that a warning page is shown. // Load the real-time phishing page and verify that a warning page is shown.
[ChromeEarlGrey loadURL:_realTimePhishingURL]; [ChromeEarlGrey loadURL:_realTimePhishingURL];
...@@ -666,7 +687,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -666,7 +687,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
// Tests that real-time lookups are not performed in incognito mode. // Tests that real-time lookups are not performed in incognito mode.
- (void)testRealTimeLookupsInIncognito { - (void)testRealTimeLookupsInIncognito {
// Opt-in to real-time checks. // Opt-in to real-time checks.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:true]; [ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:YES];
// Load the real-time phishing page and verify that no warning is shown. // Load the real-time phishing page and verify that no warning is shown.
[ChromeEarlGrey openNewIncognitoTab]; [ChromeEarlGrey openNewIncognitoTab];
...@@ -674,4 +695,48 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -674,4 +695,48 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
[ChromeEarlGrey waitForWebStateContainingText:_realTimePhishingContent]; [ChromeEarlGrey waitForWebStateContainingText:_realTimePhishingContent];
} }
// Tests that a page identified as unsafe by real-time Safe Browsing is blocked
// when loaded as part of session restoration.
- (void)testRestoreRealTimeWarning {
// Opt-in to real-time checks.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:YES];
// Visit two safe pages, followed by an unsafe page.
[ChromeEarlGrey loadURL:_safeURL1];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent1];
[ChromeEarlGrey loadURL:_safeURL2];
[ChromeEarlGrey waitForWebStateContainingText:_safeContent2];
[ChromeEarlGrey loadURL:_realTimePhishingURL];
// Verify that a warning is shown for the unsafe page.
[ChromeEarlGrey waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_PHISHING_V4_HEADING)];
// Perform session restoration, and verify that a warning is still shown.
[ChromeEarlGrey triggerRestoreViaTabGridRemoveAllUndo];
[ChromeEarlGrey waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_PHISHING_V4_HEADING)];
}
// Tests that when a page identified as unsafe by real-time Safe Browsing is
// loaded using a bookmark, a warning is shown.
- (void)testRealTimeWarningForBookmark {
NSString* phishingTitle = @"Real-time phishing";
[BookmarkEarlGrey addBookmarkWithTitle:phishingTitle
URL:base::SysUTF8ToNSString(
_realTimePhishingURL.spec())];
// Opt-in to real-time checks.
[ChromeEarlGrey setURLKeyedAnonymizedDataCollectionEnabled:YES];
// Load the real-time phishing page using its bookmark, and verify that a
// warning is shown.
[BookmarkEarlGreyUI openBookmarks];
[BookmarkEarlGreyUI openMobileBookmarks];
[[EarlGrey
selectElementWithMatcher:TappableBookmarkNodeWithLabel(phishingTitle)]
performAction:grey_tap()];
[ChromeEarlGrey waitForWebStateContainingText:l10n_util::GetStringUTF8(
IDS_PHISHING_V4_HEADING)];
}
@end @end
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