Commit 6844dad7 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Converts BlockPopupsTestCase to EG2.

BUG=987646

Change-Id: I2443f70f0981be8c9022e63c540625f88956d40a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869331
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709202}
parent f8098207
......@@ -319,9 +319,31 @@ source_set("unit_tests") {
]
}
source_set("eg_tests") {
source_set("eg_test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"block_popups_app_interface.h",
"block_popups_app_interface.mm",
]
deps = [
"//base",
"//components/content_settings/core/browser",
"//components/content_settings/core/common",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/content_settings",
"//ios/chrome/test/app:test_support",
]
}
source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"block_popups_egtest.mm",
"settings_egtest.mm",
......@@ -330,6 +352,7 @@ source_set("eg_tests") {
]
deps = [
":eg_test_support",
":settings",
"//base",
"//base/test:test_support",
......@@ -375,8 +398,60 @@ source_set("eg_tests") {
"//ui/base",
"//url",
]
libs = [
"UIKit.framework",
"XCTest.framework",
libs = [ "UIKit.framework" ]
}
source_set("eg_app_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"block_popups_app_interface.h",
"block_popups_app_interface.mm",
]
deps = [
"//base",
"//components/content_settings/core/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/content_settings",
"//ios/chrome/test/app:test_support",
]
public_deps = [
"//components/content_settings/core/common",
]
}
source_set("eg_test_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"block_popups_app_interface.h",
]
public_deps = [
"//components/content_settings/core/common",
]
}
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"block_popups_egtest.mm",
]
deps = [
":eg_test_support+eg2",
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test/http_server",
"//ui/base",
"//url",
]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_BLOCK_POPUPS_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_BLOCK_POPUPS_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
#include "components/content_settings/core/common/content_settings.h"
// BlockPopupsAppInterface provides app-side helpers for BlockPopupsTest.
@interface BlockPopupsAppInterface : NSObject
// Sets the popup content setting policy for the given |pattern|.
+ (void)setPopupPolicy:(ContentSetting)policy forPattern:(NSString*)pattern;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_BLOCK_POPUPS_APP_INTERFACE_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/block_popups_app_interface.h"
#include "base/strings/sys_string_conversions.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation BlockPopupsAppInterface
+ (void)setPopupPolicy:(ContentSetting)policy forPattern:(NSString*)pattern {
ios::ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
ContentSettingsPattern exceptionPattern =
ContentSettingsPattern::FromString(base::SysNSStringToUTF8(pattern));
ios::HostContentSettingsMapFactory::GetForBrowserState(browserState)
->SetContentSettingCustomScope(
exceptionPattern, ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_POPUPS, std::string(), policy);
}
@end
......@@ -2,22 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#include "base/strings/sys_string_conversions.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/browser/ui/settings/block_popups_app_interface.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/chrome/test/earl_grey/scoped_block_popups_pref.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -27,8 +24,11 @@
#error "This file requires ARC support."
#endif
#if defined(CHROME_EARL_GREY_2)
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(BlockPopupsAppInterface)
#endif // defined(CHROME_EARL_GREY_2)
using chrome_test_util::ContentSettingsButton;
using chrome_test_util::GetOriginalBrowserState;
using chrome_test_util::SettingsDoneButton;
using chrome_test_util::SettingsMenuBackButton;
......@@ -57,30 +57,19 @@ id<GREYMatcher> BlockPopupsSettingsButton() {
// list for as long as this object is in scope.
class ScopedBlockPopupsException {
public:
ScopedBlockPopupsException(const std::string& pattern) : pattern_(pattern) {
SetException(pattern_, CONTENT_SETTING_ALLOW);
ScopedBlockPopupsException(const std::string& pattern)
: pattern_(base::SysUTF8ToNSString(pattern)) {
[BlockPopupsAppInterface setPopupPolicy:CONTENT_SETTING_ALLOW
forPattern:pattern_];
}
~ScopedBlockPopupsException() {
SetException(pattern_, CONTENT_SETTING_DEFAULT);
[BlockPopupsAppInterface setPopupPolicy:CONTENT_SETTING_DEFAULT
forPattern:pattern_];
}
private:
// Adds an exception for the given |pattern|. If |setting| is
// CONTENT_SETTING_DEFAULT, removes the existing exception instead.
void SetException(const std::string& pattern, ContentSetting setting) {
ios::ChromeBrowserState* browserState =
chrome_test_util::GetOriginalBrowserState();
ContentSettingsPattern exception_pattern =
ContentSettingsPattern::FromString(pattern);
ios::HostContentSettingsMapFactory::GetForBrowserState(browserState)
->SetContentSettingCustomScope(
exception_pattern, ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_POPUPS, std::string(), setting);
}
// The exception pattern that this object is managing.
std::string pattern_;
NSString* pattern_;
DISALLOW_COPY_AND_ASSIGN(ScopedBlockPopupsException);
};
......@@ -164,7 +153,7 @@ class ScopedBlockPopupsException {
// via async JS, so the infobar may not open immediately.
[ChromeEarlGrey executeJavaScript:kOpenPopupScript];
[[GREYCondition
BOOL infobarVisible = [[GREYCondition
conditionWithName:@"Wait for blocked popups infobar to show"
block:^BOOL {
NSError* error = nil;
......@@ -176,6 +165,7 @@ class ScopedBlockPopupsException {
error:&error];
return error == nil;
}] waitWithTimeout:4.0];
GREYAssertTrue(infobarVisible, @"Infobar did not appear");
[ChromeEarlGrey waitForMainTabCount:1];
}
......
......@@ -384,6 +384,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui_constants",
"//ios/chrome/browser/ui/safe_mode",
"//ios/chrome/browser/ui/safe_mode:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings:settings",
"//ios/chrome/browser/ui/settings/autofill",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
......
......@@ -53,6 +53,7 @@ chrome_ios_eg2_test("ios_chrome_settings_eg2tests_module") {
xcode_test_application_name = "ios_chrome_eg2tests"
deps = [
"//ios/chrome/browser/ui/settings:eg2_tests",
"//ios/chrome/browser/ui/settings/autofill:eg2_tests",
]
}
......
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