Commit 739d1c32 authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Convert ScopedBlockPopupsPref to be compatible with EG2.

App calls made by this test class are moved into ChromeEarlGrey and made
to compile with EG2, so that ScopedBlockPopupsPref can continue to work
when moved into test-side code.

ChromeBrowserState was removed from ScopedBlockPopupsPref as I was not
sure if it would be passable over EDO safely, and all callsites of this
class use GetOriginalBrowserState(). Therefore, I moved getting the
ChromeBrowserState using GetOriginalBrowserState() to app-side in
CEGAppInterface.

Bug: 922813
Change-Id: I954d28309360b8b805a9943c7fde77df69f7df95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1668512
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672710}
parent 3ddb7968
...@@ -373,6 +373,7 @@ source_set("eg_tests") { ...@@ -373,6 +373,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:util", "//ios/chrome/browser/ui/util:util",
"//ios/chrome/test:eg_test_support",
"//ios/chrome/test:test_support", "//ios/chrome/test:test_support",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.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_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/chrome/test/scoped_block_popups_pref.h" #include "ios/chrome/test/earl_grey/scoped_block_popups_pref.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h" #include "ios/web/public/test/http_server/http_server_util.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -126,8 +126,7 @@ class ScopedBlockPopupsException { ...@@ -126,8 +126,7 @@ class ScopedBlockPopupsException {
responses[openedWindowURL] = kOpenedWindowResponse; responses[openedWindowURL] = kOpenedWindowResponse;
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
[ChromeEarlGrey loadURL:blockPopupsURL]; [ChromeEarlGrey loadURL:blockPopupsURL];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
...@@ -156,8 +155,7 @@ class ScopedBlockPopupsException { ...@@ -156,8 +155,7 @@ class ScopedBlockPopupsException {
responses[openedWindowURL] = kOpenedWindowResponse; responses[openedWindowURL] = kOpenedWindowResponse;
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK);
GetOriginalBrowserState());
[ChromeEarlGrey loadURL:blockPopupsURL]; [ChromeEarlGrey loadURL:blockPopupsURL];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
...@@ -185,8 +183,7 @@ class ScopedBlockPopupsException { ...@@ -185,8 +183,7 @@ class ScopedBlockPopupsException {
// revealed properly when the preference switch is toggled. // revealed properly when the preference switch is toggled.
- (void)testSettingsPageWithExceptions { - (void)testSettingsPageWithExceptions {
std::string allowedPattern = "[*.]example.com"; std::string allowedPattern = "[*.]example.com";
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_BLOCK);
GetOriginalBrowserState());
ScopedBlockPopupsException exceptionSetter(allowedPattern); ScopedBlockPopupsException exceptionSetter(allowedPattern);
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.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_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/chrome/test/scoped_block_popups_pref.h" #include "ios/chrome/test/earl_grey/scoped_block_popups_pref.h"
#include "ios/net/url_test_util.h" #include "ios/net/url_test_util.h"
#import "ios/web/public/test/earl_grey/web_view_actions.h" #import "ios/web/public/test/earl_grey/web_view_actions.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h" #import "ios/web/public/test/earl_grey/web_view_matchers.h"
...@@ -184,8 +184,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) { ...@@ -184,8 +184,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) {
responses[destinationURL] = "You've arrived!"; responses[destinationURL] = "You've arrived!";
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
[ChromeEarlGrey loadURL:URL]; [ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
...@@ -214,8 +213,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) { ...@@ -214,8 +213,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) {
responses[destinationURL] = "You've arrived!"; responses[destinationURL] = "You've arrived!";
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
[ChromeEarlGrey loadURL:URL]; [ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
...@@ -257,8 +255,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) { ...@@ -257,8 +255,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) {
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
[ChromeEarlGrey loadURL:URL]; [ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
...@@ -296,8 +293,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) { ...@@ -296,8 +293,7 @@ id<GREYMatcher> TabWithTitle(const std::string& tab_title) {
web::test::SetUpSimpleHttpServer(responses); web::test::SetUpSimpleHttpServer(responses);
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
[ChromeEarlGrey loadURL:URL]; [ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForMainTabCount:1]; [ChromeEarlGrey waitForMainTabCount:1];
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#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_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/chrome/test/scoped_block_popups_pref.h" #include "ios/chrome/test/earl_grey/scoped_block_popups_pref.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h" #include "ios/web/public/test/http_server/http_server_util.h"
#include "url/url_constants.h" #include "url/url_constants.h"
...@@ -48,8 +48,7 @@ GURL GetTestUrl() { ...@@ -48,8 +48,7 @@ GURL GetTestUrl() {
- (void)runTestAndVerifyNoNavigationForLinkID:(const std::string&)linkID { - (void)runTestAndVerifyNoNavigationForLinkID:(const std::string&)linkID {
// Disable popup blocking, because that will mask failures that try to open // Disable popup blocking, because that will mask failures that try to open
// new tabs. // new tabs.
ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
web::test::SetUpFileBasedHttpServer(); web::test::SetUpFileBasedHttpServer();
const GURL testURL = GetTestUrl(); const GURL testURL = GetTestUrl();
...@@ -89,8 +88,7 @@ GURL GetTestUrl() { ...@@ -89,8 +88,7 @@ GURL GetTestUrl() {
- (void)testPreventDefaultOverridesWindowOpen { - (void)testPreventDefaultOverridesWindowOpen {
// Disable popup blocking, because that will mask failures that try to open // Disable popup blocking, because that will mask failures that try to open
// new tabs. // new tabs.
ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
web::test::SetUpFileBasedHttpServer(); web::test::SetUpFileBasedHttpServer();
const GURL testURL = GetTestUrl(); const GURL testURL = GetTestUrl();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.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_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/chrome/test/scoped_block_popups_pref.h" #include "ios/chrome/test/earl_grey/scoped_block_popups_pref.h"
#include "ios/web/public/test/http_server/html_response_provider.h" #include "ios/web/public/test/http_server/html_response_provider.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h" #include "ios/web/public/test/http_server/http_server_util.h"
...@@ -174,8 +174,7 @@ class CacheTestResponseProvider : public web::DataResponseProvider { ...@@ -174,8 +174,7 @@ class CacheTestResponseProvider : public web::DataResponseProvider {
// Open the first page in a new tab. Verify that cache was not used. Must // Open the first page in a new tab. Verify that cache was not used. Must
// first allow popups. // first allow popups.
ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW, ScopedBlockPopupsPref prefSetter(CONTENT_SETTING_ALLOW);
GetOriginalBrowserState());
[ChromeEarlGrey [ChromeEarlGrey
tapWebStateElementWithID:[NSString tapWebStateElementWithID:[NSString
stringWithUTF8String:kCacheTestLinkID]]; stringWithUTF8String:kCacheTestLinkID]];
......
...@@ -31,8 +31,6 @@ source_set("test_support") { ...@@ -31,8 +31,6 @@ source_set("test_support") {
"ios_chrome_unit_test_suite.mm", "ios_chrome_unit_test_suite.mm",
"root_view_controller_test.h", "root_view_controller_test.h",
"root_view_controller_test.mm", "root_view_controller_test.mm",
"scoped_block_popups_pref.h",
"scoped_block_popups_pref.mm",
"scoped_key_window.h", "scoped_key_window.h",
"testing_application_context.h", "testing_application_context.h",
"testing_application_context.mm", "testing_application_context.mm",
...@@ -77,7 +75,7 @@ source_set("eg_test_support") { ...@@ -77,7 +75,7 @@ source_set("eg_test_support") {
] ]
deps = [ deps = [
":test_support", ":test_support",
"//base", "//base:base",
"//ios/third_party/earl_grey:earl_grey+link", "//ios/third_party/earl_grey:earl_grey+link",
] ]
} }
......
...@@ -219,6 +219,8 @@ source_set("test_support") { ...@@ -219,6 +219,8 @@ source_set("test_support") {
"chrome_test_case.mm", "chrome_test_case.mm",
"chrome_test_case_app_interface.h", "chrome_test_case_app_interface.h",
"chrome_test_case_app_interface.mm", "chrome_test_case_app_interface.mm",
"scoped_block_popups_pref.h",
"scoped_block_popups_pref.mm",
] ]
deps = [ deps = [
...@@ -232,6 +234,7 @@ source_set("test_support") { ...@@ -232,6 +234,7 @@ source_set("test_support") {
"//components/ukm/ios:features", "//components/ukm/ios:features",
"//components/unified_consent", "//components/unified_consent",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/content_settings:content_settings",
"//ios/chrome/browser/ntp:features", "//ios/chrome/browser/ntp:features",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/authentication:authentication", "//ios/chrome/browser/ui/authentication:authentication",
...@@ -331,6 +334,7 @@ source_set("eg_app_support+eg2") { ...@@ -331,6 +334,7 @@ source_set("eg_app_support+eg2") {
"//components/ukm/ios:features", "//components/ukm/ios:features",
"//components/unified_consent", "//components/unified_consent",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/content_settings:content_settings",
"//ios/chrome/browser/ntp:features", "//ios/chrome/browser/ntp:features",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/authentication/cells", "//ios/chrome/browser/ui/authentication/cells",
...@@ -394,6 +398,8 @@ source_set("eg_test_support+eg2") { ...@@ -394,6 +398,8 @@ source_set("eg_test_support+eg2") {
"chrome_test_case.h", "chrome_test_case.h",
"chrome_test_case.mm", "chrome_test_case.mm",
"chrome_test_case_app_interface.h", "chrome_test_case_app_interface.h",
"scoped_block_popups_pref.h",
"scoped_block_popups_pref.mm",
] ]
deps = [ deps = [
......
...@@ -345,6 +345,16 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -345,6 +345,16 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Returns YES if WebPaymentsModifiers feature is enabled. // Returns YES if WebPaymentsModifiers feature is enabled.
- (BOOL)isWebPaymentsModifiersEnabled WARN_UNUSED_RESULT; - (BOOL)isWebPaymentsModifiersEnabled WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the
// original browser state.
- (ContentSetting)popupPrefValue;
// Sets the popup content setting preference to the given value for the original
// browser state.
- (void)setPopupPrefValue:(ContentSetting)value;
@end @end
// Helpers that only compile under EarlGrey 1 are included in this "EG1" // Helpers that only compile under EarlGrey 1 are included in this "EG1"
......
...@@ -558,6 +558,16 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -558,6 +558,16 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface isWebPaymentsModifiersEnabled]; return [ChromeEarlGreyAppInterface isWebPaymentsModifiersEnabled];
} }
#pragma mark - ScopedBlockPopupsPref
- (ContentSetting)popupPrefValue {
return [ChromeEarlGreyAppInterface popupPrefValue];
}
- (void)setPopupPrefValue:(ContentSetting)value {
return [ChromeEarlGreyAppInterface setPopupPrefValue:value];
}
@end @end
// The helpers below only compile under EarlGrey1. // The helpers below only compile under EarlGrey1.
......
...@@ -283,6 +283,16 @@ ...@@ -283,6 +283,16 @@
// Returns YES if WebPaymentsModifiers feature is enabled. // Returns YES if WebPaymentsModifiers feature is enabled.
+ (BOOL)isWebPaymentsModifiersEnabled WARN_UNUSED_RESULT; + (BOOL)isWebPaymentsModifiersEnabled WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the
// original browser state.
+ (ContentSetting)popupPrefValue;
// Sets the popup content setting preference to the given value for the original
// browser state.
+ (void)setPopupPrefValue:(ContentSetting)value;
@end @end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_APP_INTERFACE_H_ #endif // IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_APP_INTERFACE_H_
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#import "components/payments/core/features.h" #import "components/payments/core/features.h"
#import "components/ukm/ios/features.h" #import "components/ukm/ios/features.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/browser/ntp/features.h" #import "ios/chrome/browser/ntp/features.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h" #import "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/test/app/bookmarks_test_util.h" #import "ios/chrome/test/app/bookmarks_test_util.h"
...@@ -486,4 +488,19 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -486,4 +488,19 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
payments::features::kWebPaymentsModifiers); payments::features::kWebPaymentsModifiers);
} }
#pragma mark - ScopedBlockPopupsPref
+ (ContentSetting)popupPrefValue {
return ios::HostContentSettingsMapFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState())
->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, NULL);
}
+ (void)setPopupPrefValue:(ContentSetting)value {
DCHECK(value == CONTENT_SETTING_BLOCK || value == CONTENT_SETTING_ALLOW);
ios::HostContentSettingsMapFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState())
->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, value);
}
@end @end
...@@ -2,35 +2,21 @@ ...@@ -2,35 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_TEST_SCOPED_BLOCK_POPUPS_PREF_H_ #ifndef IOS_CHROME_TEST_EARL_GREY_SCOPED_BLOCK_POPUPS_PREF_H_
#define IOS_CHROME_TEST_SCOPED_BLOCK_POPUPS_PREF_H_ #define IOS_CHROME_TEST_EARL_GREY_SCOPED_BLOCK_POPUPS_PREF_H_
#include "base/macros.h" #include "base/macros.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
namespace ios { // ScopedBlockPopupsPref modifies the block popups preference for the original
class ChromeBrowserState; // browser state and resets the preference to its original value when this
} // object goes out of scope.
// ScopedBlockPopupsPref modifies the block popups preference
// and resets the preference to its original value when this object goes out of
// scope.
class ScopedBlockPopupsPref { class ScopedBlockPopupsPref {
public: public:
explicit ScopedBlockPopupsPref(ContentSetting setting, explicit ScopedBlockPopupsPref(ContentSetting setting);
ios::ChromeBrowserState* browser_state);
~ScopedBlockPopupsPref(); ~ScopedBlockPopupsPref();
private: private:
// Gets the current value of the preference.
ContentSetting GetPrefValue();
// Sets the preference to the given value.
void SetPrefValue(ContentSetting setting);
// Saves the browser state, which is required when getting and setting prefs.
ios::ChromeBrowserState* browser_state_;
// Saves the original pref setting so that it can be restored when the scoper // Saves the original pref setting so that it can be restored when the scoper
// is destroyed. // is destroyed.
ContentSetting original_setting_; ContentSetting original_setting_;
...@@ -38,4 +24,4 @@ class ScopedBlockPopupsPref { ...@@ -38,4 +24,4 @@ class ScopedBlockPopupsPref {
DISALLOW_COPY_AND_ASSIGN(ScopedBlockPopupsPref); DISALLOW_COPY_AND_ASSIGN(ScopedBlockPopupsPref);
}; };
#endif // IOS_CHROME_TEST_SCOPED_BLOCK_POPUPS_PREF_H_ #endif // IOS_CHROME_TEST_EARL_GREY_SCOPED_BLOCK_POPUPS_PREF_H_
// Copyright 2017 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.
#include "ios/chrome/test/earl_grey/scoped_block_popups_pref.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
ScopedBlockPopupsPref::ScopedBlockPopupsPref(ContentSetting setting)
: original_setting_([ChromeEarlGrey popupPrefValue]) {
[ChromeEarlGrey setPopupPrefValue:setting];
}
ScopedBlockPopupsPref::~ScopedBlockPopupsPref() {
[ChromeEarlGrey setPopupPrefValue:original_setting_];
}
// Copyright 2017 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.
#include "ios/chrome/test/scoped_block_popups_pref.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
ScopedBlockPopupsPref::ScopedBlockPopupsPref(
ContentSetting setting,
ios::ChromeBrowserState* browser_state)
: browser_state_(browser_state), original_setting_(GetPrefValue()) {
SetPrefValue(setting);
}
ScopedBlockPopupsPref::~ScopedBlockPopupsPref() {
SetPrefValue(original_setting_);
}
ContentSetting ScopedBlockPopupsPref::GetPrefValue() {
return ios::HostContentSettingsMapFactory::GetForBrowserState(browser_state_)
->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, NULL);
}
void ScopedBlockPopupsPref::SetPrefValue(ContentSetting setting) {
DCHECK(setting == CONTENT_SETTING_BLOCK || setting == CONTENT_SETTING_ALLOW);
ios::HostContentSettingsMapFactory::GetForBrowserState(browser_state_)
->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, setting);
}
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