Commit d1ffd14a authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Create WebContentAreaAlertOverlayCoordinator.

This is an AlertOverlayCoordinator subclass that aggregates all the
mediator types used for the supported OverlayRequests for alerts shown
in OverlayModality::kWebContentArea, allowing for the removal of the
boilerplate coordinator code for these overlays.  After this CL, new
alerts shown over the web content area simply need a new mediator that
is added to the coordinator's |supportedMediatorClasses| array.

This CL also creates a new util function to instantiate an appropriate
mediator for other OverlayRequestCoordinators that support multiple
mediator types.  InfobarBannerOverlayCoordinator was updated to use
this function as well, since it also supports multiple banner mediator
classes.

Bug: none
Change-Id: I360b0f94bb2eb76709074f826854a262fc82ce80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2149687
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Auto-Submit: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759767}
parent 361aae84
...@@ -25,12 +25,16 @@ source_set("alerts") { ...@@ -25,12 +25,16 @@ source_set("alerts") {
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ "alert_overlay_mediator_unittest.mm" ] sources = [
"alert_overlay_coordinator_unittest.mm",
"alert_overlay_mediator_unittest.mm",
]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
deps = [ deps = [
":alerts", ":alerts",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/overlays", "//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/test", "//ios/chrome/browser/overlays/test",
"//ios/chrome/browser/ui/alert_view", "//ios/chrome/browser/ui/alert_view",
...@@ -38,6 +42,8 @@ source_set("unit_tests") { ...@@ -38,6 +42,8 @@ source_set("unit_tests") {
"//ios/chrome/browser/ui/elements", "//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/overlays/common/alerts/test", "//ios/chrome/browser/ui/overlays/common/alerts/test",
"//ios/chrome/browser/ui/overlays/test", "//ios/chrome/browser/ui/overlays/test",
"//ios/chrome/test:test_support",
"//ios/web/public/test:test",
"//testing/gtest", "//testing/gtest",
"//ui/base", "//ui/base",
] ]
......
// Copyright 2020 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/overlays/common/alerts/alert_overlay_coordinator.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/main/test_browser.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/test/overlay_test_macros.h"
#import "ios/chrome/browser/ui/alert_view/alert_action.h"
#import "ios/chrome/browser/ui/alert_view/alert_view_controller.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/test/fake_alert_overlay_mediator.h"
#include "ios/chrome/browser/ui/overlays/test/fake_overlay_request_coordinator_delegate.h"
#include "ios/chrome/test/scoped_key_window.h"
#include "ios/web/public/test/web_task_environment.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Fake request config type for use in tests.
DEFINE_TEST_OVERLAY_REQUEST_CONFIG(FakeAlert);
}
#pragma mark - FakeAlertOverlayCoordinator
@interface FakeAlertOverlayCoordinator : AlertOverlayCoordinator
@property(nonatomic, strong) FakeAlertOverlayMediator* fakeMediator;
@end
@implementation FakeAlertOverlayCoordinator
+ (const OverlayRequestSupport*)requestSupport {
return FakeAlert::RequestSupport();
}
@end
@implementation FakeAlertOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
return self.fakeMediator;
}
@end
#pragma mark - AlertOverlayCoordinatorTest
// Test fixture for AlertOverlayCoordinator.
class AlertOverlayCoordinatorTest : public PlatformTest {
public:
AlertOverlayCoordinatorTest()
: root_view_controller_([[UIViewController alloc] init]),
request_(OverlayRequest::CreateWithConfig<FakeAlert>()),
mediator_(
[[FakeAlertOverlayMediator alloc] initWithRequest:request_.get()]),
coordinator_([[FakeAlertOverlayCoordinator alloc]
initWithBaseViewController:root_view_controller_
browser:&browser_
request:request_.get()
delegate:&delegate_]) {
scoped_window_.Get().rootViewController = root_view_controller_;
// Set up the fake mediator and provide it to the coordinator.
mediator_.alertTitle = @"title";
mediator_.alertMessage = @"message";
mediator_.alertActions =
@[ [AlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:nil] ];
coordinator_.fakeMediator = mediator_;
}
protected:
web::WebTaskEnvironment task_environment_;
TestBrowser browser_;
ScopedKeyWindow scoped_window_;
UIViewController* root_view_controller_ = nil;
std::unique_ptr<OverlayRequest> request_;
FakeOverlayRequestCoordinatorDelegate delegate_;
FakeAlertOverlayMediator* mediator_ = nil;
FakeAlertOverlayCoordinator* coordinator_ = nil;
};
// Tests that the coordinator creates an alert view, presents it within the
// base UIViewController's hierarchy, and sets it up using its mediator.
TEST_F(AlertOverlayCoordinatorTest, ViewSetup) {
[coordinator_ startAnimated:NO];
AlertViewController* view_controller =
base::mac::ObjCCast<AlertViewController>(coordinator_.viewController);
EXPECT_TRUE(view_controller);
EXPECT_EQ(view_controller.parentViewController, root_view_controller_);
EXPECT_TRUE(
[view_controller.view isDescendantOfView:root_view_controller_.view]);
EXPECT_TRUE(delegate_.HasUIBeenPresented(request_.get()));
EXPECT_EQ(mediator_.consumer, view_controller);
[coordinator_ stopAnimated:NO];
EXPECT_TRUE(delegate_.HasUIBeenDismissed(request_.get()));
}
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/elements/text_field_configuration.h" #import "ios/chrome/browser/ui/elements/text_field_configuration.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_mediator+alert_consumer_support.h" #import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_mediator+alert_consumer_support.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/test/alert_overlay_mediator_test.h" #import "ios/chrome/browser/ui/overlays/common/alerts/test/alert_overlay_mediator_test.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/test/fake_alert_overlay_mediator.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
...@@ -18,20 +19,6 @@ ...@@ -18,20 +19,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
// Fake subclass of AlertOverlayMediator for tests.
@interface FakeAlertOverlayMediator : AlertOverlayMediator
// Define readwrite versions of subclassing properties.
@property(nonatomic, readwrite) NSString* alertTitle;
@property(nonatomic, readwrite) NSString* alertMessage;
@property(nonatomic, readwrite)
NSArray<TextFieldConfiguration*>* alertTextFieldConfigurations;
@property(nonatomic, readwrite) NSArray<AlertAction*>* alertActions;
@property(nonatomic, readwrite) NSString* alertAccessibilityIdentifier;
@end
@implementation FakeAlertOverlayMediator
@end
// Tests that the AlertOverlayMediator's subclassing properties are correctly // Tests that the AlertOverlayMediator's subclassing properties are correctly
// applied to the consumer. // applied to the consumer.
TEST_F(AlertOverlayMediatorTest, SetUpConsumer) { TEST_F(AlertOverlayMediatorTest, SetUpConsumer) {
......
...@@ -7,6 +7,8 @@ source_set("test") { ...@@ -7,6 +7,8 @@ source_set("test") {
sources = [ sources = [
"alert_overlay_mediator_test.h", "alert_overlay_mediator_test.h",
"alert_overlay_mediator_test.mm", "alert_overlay_mediator_test.mm",
"fake_alert_overlay_mediator.h",
"fake_alert_overlay_mediator.mm",
] ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
// Copyright 2020 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_OVERLAYS_COMMON_ALERTS_TEST_FAKE_ALERT_OVERLAY_MEDIATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_COMMON_ALERTS_TEST_FAKE_ALERT_OVERLAY_MEDIATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_mediator.h"
@class AlertAction;
@class TextFieldConfiguration;
// Fake subclass of AlertOverlayMediator for tests.
@interface FakeAlertOverlayMediator : AlertOverlayMediator
// Define readwrite versions of subclassing properties.
@property(nonatomic, readwrite) NSString* alertTitle;
@property(nonatomic, readwrite) NSString* alertMessage;
@property(nonatomic, readwrite)
NSArray<TextFieldConfiguration*>* alertTextFieldConfigurations;
@property(nonatomic, readwrite) NSArray<AlertAction*>* alertActions;
@property(nonatomic, readwrite) NSString* alertAccessibilityIdentifier;
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_COMMON_ALERTS_TEST_FAKE_ALERT_OVERLAY_MEDIATOR_H_
// Copyright 2020 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/overlays/common/alerts/test/fake_alert_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation FakeAlertOverlayMediator
@end
...@@ -140,12 +140,11 @@ ...@@ -140,12 +140,11 @@
// Creates a mediator instance from the supported mediator class list that // Creates a mediator instance from the supported mediator class list that
// supports the coordinator's request. // supports the coordinator's request.
- (InfobarBannerOverlayMediator*)newMediator { - (InfobarBannerOverlayMediator*)newMediator {
for (Class mediatorClass in [self class].supportedMediatorClasses) { InfobarBannerOverlayMediator* mediator =
if (mediatorClass.requestSupport->IsRequestSupported(self.request)) base::mac::ObjCCast<InfobarBannerOverlayMediator>(GetMediatorForRequest(
return [[mediatorClass alloc] initWithRequest:self.request]; [self class].supportedMediatorClasses, self.request));
} DCHECK(mediator) << "None of the supported mediator classes support request.";
NOTREACHED() << "None of the supported mediator classes support request."; return mediator;
return nil;
} }
@end @end
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <memory> #include <memory>
@class OverlayRequestMediator;
class OverlayRequest;
class OverlayRequestSupport; class OverlayRequestSupport;
// Returns an OverlayRequestSupport aggregating the support from all // Returns an OverlayRequestSupport aggregating the support from all
...@@ -18,4 +20,10 @@ class OverlayRequestSupport; ...@@ -18,4 +20,10 @@ class OverlayRequestSupport;
std::unique_ptr<OverlayRequestSupport> CreateAggregateSupportForMediators( std::unique_ptr<OverlayRequestSupport> CreateAggregateSupportForMediators(
NSArray<Class>* mediator_classes); NSArray<Class>* mediator_classes);
// Iterates through the OverlayRequestMediator classes in |mediator_classes|,
// searching for one that supports |request|. If one is found, returns a new
// instance of the mediator for that request. Otherwise, returns nil.
OverlayRequestMediator* GetMediatorForRequest(NSArray<Class>* mediator_classes,
OverlayRequest* request);
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_OVERLAY_REQUEST_MEDIATOR_UTIL_H_ #endif // IOS_CHROME_BROWSER_UI_OVERLAYS_OVERLAY_REQUEST_MEDIATOR_UTIL_H_
...@@ -22,3 +22,13 @@ std::unique_ptr<OverlayRequestSupport> CreateAggregateSupportForMediators( ...@@ -22,3 +22,13 @@ std::unique_ptr<OverlayRequestSupport> CreateAggregateSupportForMediators(
} }
return std::make_unique<OverlayRequestSupport>(supports); return std::make_unique<OverlayRequestSupport>(supports);
} }
OverlayRequestMediator* GetMediatorForRequest(NSArray<Class>* mediator_classes,
OverlayRequest* request) {
for (Class mediator_class in mediator_classes) {
DCHECK([mediator_class isSubclassOfClass:[OverlayRequestMediator class]]);
if ([mediator_class requestSupport]->IsRequestSupported(request))
return [[mediator_class alloc] initWithRequest:request];
}
return nil;
}
...@@ -11,10 +11,6 @@ source_set("web_content_area") { ...@@ -11,10 +11,6 @@ source_set("web_content_area") {
deps = [ deps = [
"//base", "//base",
"//ios/chrome/browser/ui/overlays:coordinators", "//ios/chrome/browser/ui/overlays:coordinators",
"//ios/chrome/browser/ui/overlays/web_content_area/app_launcher", "//ios/chrome/browser/ui/overlays/web_content_area/alerts",
"//ios/chrome/browser/ui/overlays/web_content_area/http_auth_dialogs",
"//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs:alerts",
"//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs:confirmations",
"//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs:prompts",
] ]
} }
# Copyright 2020 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.
source_set("alerts") {
sources = [
"web_content_area_alert_overlay_coordinator.h",
"web_content_area_alert_overlay_coordinator.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
"//base",
"//components/strings:components_strings_grit",
"//components/url_formatter",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/alert_view",
"//ios/chrome/browser/ui/overlays:coordinators",
"//ios/chrome/browser/ui/overlays:util",
"//ios/chrome/browser/ui/overlays/common/alerts",
"//ios/chrome/browser/ui/overlays/web_content_area/app_launcher",
"//ios/chrome/browser/ui/overlays/web_content_area/http_auth_dialogs",
"//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs",
"//ui/base",
]
}
// Copyright 2020 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_OVERLAYS_WEB_CONTENT_AREA_ALERTS_WEB_CONTENT_AREA_ALERT_OVERLAY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_ALERTS_WEB_CONTENT_AREA_ALERT_OVERLAY_COORDINATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator.h"
// A coordinator that is used to display all overlay UI using alerts for
// OverlayModality::kWebContentArea.
@interface WebContentAreaOverlayCoordinator : AlertOverlayCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_ALERTS_WEB_CONTENT_AREA_ALERT_OVERLAY_COORDINATOR_H_
// Copyright 2020 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/overlays/web_content_area/alerts/web_content_area_alert_overlay_coordinator.h"
#include "base/mac/foundation_util.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/public/overlay_request_support.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#import "ios/chrome/browser/ui/overlays/overlay_request_mediator_util.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/app_launcher/app_launcher_alert_overlay_mediator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/http_auth_dialogs/http_auth_dialog_overlay_mediator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_alert_overlay_mediator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_confirmation_overlay_mediator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface WebContentAreaOverlayCoordinator ()
// Returns an array of all the mediator classes supported for this coordinator.
@property(class, nonatomic, readonly) NSArray<Class>* supportedMediatorClasses;
@end
@implementation WebContentAreaOverlayCoordinator
#pragma mark - Accessors
+ (NSArray<Class>*)supportedMediatorClasses {
static NSArray<Class>* _supportedMediatorClasses = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_supportedMediatorClasses = @[
[AppLauncherAlertOverlayMediator class],
[HTTPAuthDialogOverlayMediator class],
[JavaScriptConfirmationOverlayMediator class],
[JavaScriptAlertOverlayMediator class],
[JavaScriptPromptOverlayMediator class]
];
});
return _supportedMediatorClasses;
}
#pragma mark - OverlayRequestCoordinator
+ (const OverlayRequestSupport*)requestSupport {
static std::unique_ptr<const OverlayRequestSupport> _requestSupport;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_requestSupport =
CreateAggregateSupportForMediators(self.supportedMediatorClasses);
});
return _requestSupport.get();
}
@end
@implementation WebContentAreaOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
AlertOverlayMediator* mediator =
base::mac::ObjCCast<AlertOverlayMediator>(GetMediatorForRequest(
[self class].supportedMediatorClasses, self.request));
DCHECK(mediator) << "None of the supported mediator classes support request.";
return mediator;
}
@end
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
source_set("app_launcher") { source_set("app_launcher") {
sources = [ sources = [
"app_launcher_alert_overlay_coordinator.h",
"app_launcher_alert_overlay_coordinator.mm",
"app_launcher_alert_overlay_mediator.h", "app_launcher_alert_overlay_mediator.h",
"app_launcher_alert_overlay_mediator.mm", "app_launcher_alert_overlay_mediator.mm",
] ]
......
// 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_OVERLAYS_WEB_CONTENT_AREA_APP_LAUNCHER_APP_LAUNCHER_ALERT_OVERLAY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_APP_LAUNCHER_APP_LAUNCHER_ALERT_OVERLAY_COORDINATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator.h"
// A coordinator that is used to display UI for HTTP authentication dialogs via
// OverlayPresenter.
@interface AppLauncherAlertOverlayCoordinator : AlertOverlayCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_APP_LAUNCHER_APP_LAUNCHER_ALERT_OVERLAY_COORDINATOR_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/overlays/web_content_area/app_launcher/app_launcher_alert_overlay_coordinator.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/app_launcher/app_launcher_alert_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation AppLauncherAlertOverlayCoordinator
#pragma mark - OverlayRequestCoordinator
+ (const OverlayRequestSupport*)requestSupport {
return AppLauncherAlertOverlayRequestConfig::RequestSupport();
}
@end
@implementation AppLauncherAlertOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
return [[AppLauncherAlertOverlayMediator alloc] initWithRequest:self.request];
}
@end
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
source_set("http_auth_dialogs") { source_set("http_auth_dialogs") {
sources = [ sources = [
"http_auth_dialog_overlay_coordinator.h",
"http_auth_dialog_overlay_coordinator.mm",
"http_auth_dialog_overlay_mediator.h", "http_auth_dialog_overlay_mediator.h",
"http_auth_dialog_overlay_mediator.mm", "http_auth_dialog_overlay_mediator.mm",
] ]
......
// 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_OVERLAYS_WEB_CONTENT_AREA_HTTP_AUTH_DIALOGS_HTTP_AUTH_DIALOG_OVERLAY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_HTTP_AUTH_DIALOGS_HTTP_AUTH_DIALOG_OVERLAY_COORDINATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator.h"
// A coordinator that is used to display UI for HTTP authentication dialogs via
// OverlayPresenter.
@interface HTTPAuthDialogOverlayCoordinator : AlertOverlayCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_HTTP_AUTH_DIALOGS_HTTP_AUTH_DIALOG_OVERLAY_COORDINATOR_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/overlays/web_content_area/http_auth_dialogs/http_auth_dialog_overlay_coordinator.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/public/web_content_area/http_auth_overlay.h"
#import "ios/chrome/browser/ui/alert_view/alert_view_controller.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/http_auth_dialogs/http_auth_dialog_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface HTTPAuthDialogOverlayCoordinator ()
@end
@implementation HTTPAuthDialogOverlayCoordinator
#pragma mark - OverlayRequestCoordinator
+ (const OverlayRequestSupport*)requestSupport {
return HTTPAuthOverlayRequestConfig::RequestSupport();
}
@end
@implementation HTTPAuthDialogOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
return [[HTTPAuthDialogOverlayMediator alloc] initWithRequest:self.request];
}
@end
...@@ -2,16 +2,26 @@ ...@@ -2,16 +2,26 @@
# 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.
source_set("common") { source_set("java_script_dialogs") {
public = [
"java_script_alert_overlay_mediator.h",
"java_script_confirmation_overlay_mediator.h",
"java_script_prompt_overlay_mediator.h",
]
sources = [ sources = [
"java_script_alert_overlay_mediator.mm",
"java_script_confirmation_overlay_mediator.mm",
"java_script_dialog_blocking_action.h", "java_script_dialog_blocking_action.h",
"java_script_dialog_blocking_action.mm", "java_script_dialog_blocking_action.mm",
"java_script_overlay_mediator_util.h", "java_script_overlay_mediator_util.h",
"java_script_overlay_mediator_util.mm", "java_script_overlay_mediator_util.mm",
"java_script_prompt_overlay_mediator.mm",
] ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
friend = [ ":unit_tests" ]
deps = [ deps = [
"//base", "//base",
"//components/strings:components_strings_grit", "//components/strings:components_strings_grit",
...@@ -21,83 +31,6 @@ source_set("common") { ...@@ -21,83 +31,6 @@ source_set("common") {
"//ios/chrome/browser/overlays/public/web_content_area", "//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/alert_view", "//ios/chrome/browser/ui/alert_view",
"//ios/chrome/browser/ui/dialogs", "//ios/chrome/browser/ui/dialogs",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/overlays:coordinators",
"//ios/chrome/browser/ui/overlays/common/alerts",
"//ui/base",
]
}
source_set("alerts") {
sources = [
"java_script_alert_overlay_coordinator.h",
"java_script_alert_overlay_coordinator.mm",
"java_script_alert_overlay_mediator.h",
"java_script_alert_overlay_mediator.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
":common",
"//base",
"//components/strings:components_strings_grit",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/alert_view",
"//ios/chrome/browser/ui/dialogs:constants",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/overlays:coordinators",
"//ios/chrome/browser/ui/overlays/common/alerts",
"//ui/base",
]
}
source_set("confirmations") {
sources = [
"java_script_confirmation_overlay_coordinator.h",
"java_script_confirmation_overlay_coordinator.mm",
"java_script_confirmation_overlay_mediator.h",
"java_script_confirmation_overlay_mediator.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
":common",
"//base",
"//components/strings:components_strings_grit",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/alert_view",
"//ios/chrome/browser/ui/dialogs:constants",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/overlays:coordinators",
"//ios/chrome/browser/ui/overlays/common/alerts",
"//ui/base",
]
}
source_set("prompts") {
sources = [
"java_script_prompt_overlay_coordinator.h",
"java_script_prompt_overlay_coordinator.mm",
"java_script_prompt_overlay_mediator.h",
"java_script_prompt_overlay_mediator.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
":common",
"//base",
"//components/strings:components_strings_grit",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/ui/alert_view",
"//ios/chrome/browser/ui/dialogs:constants", "//ios/chrome/browser/ui/dialogs:constants",
"//ios/chrome/browser/ui/elements", "//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/overlays:coordinators", "//ios/chrome/browser/ui/overlays:coordinators",
...@@ -117,10 +50,7 @@ source_set("unit_tests") { ...@@ -117,10 +50,7 @@ source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
deps = [ deps = [
":alerts", ":java_script_dialogs",
":common",
":confirmations",
":prompts",
"//base/test:test_support", "//base/test:test_support",
"//components/strings:components_strings_grit", "//components/strings:components_strings_grit",
"//components/url_formatter", "//components/url_formatter",
......
// 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_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_ALERT_OVERLAY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_ALERT_OVERLAY_COORDINATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator.h"
// An OverlayCoordinator that displays the UI for JavaScript alerts.
@interface JavaScriptAlertOverlayCoordinator : AlertOverlayCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_ALERT_OVERLAY_COORDINATOR_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/overlays/web_content_area/java_script_dialogs/java_script_alert_overlay_coordinator.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/public/overlay_request_support.h"
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_alert_overlay.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_alert_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation JavaScriptAlertOverlayCoordinator
#pragma mark - OverlayRequestCoordinator
+ (const OverlayRequestSupport*)requestSupport {
return JavaScriptAlertOverlayRequestConfig::RequestSupport();
}
@end
@implementation JavaScriptAlertOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
return [[JavaScriptAlertOverlayMediator alloc] initWithRequest:self.request];
}
@end
// 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/overlays/web_content_area/java_script_dialogs/java_script_alert_overlay_coordinator.h"
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_alert_overlay.h"
#import "ios/chrome/browser/ui/alert_view/alert_view_controller.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/test/java_script_dialog_overlay_coordinator_test.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
// Test fixture for JavaScriptAlertOverlayCoordinator.
using JavaScriptAlertOverlayCoordinatorTest =
JavaScriptDialogOverlayCoordinatorTest;
// Tests that JavaScriptAlertOverlayCoordinator creates an alert and presents it
// non-modally.
TEST_F(JavaScriptAlertOverlayCoordinatorTest, StartAndStop) {
web::TestWebState web_state;
std::unique_ptr<OverlayRequest> passed_request =
OverlayRequest::CreateWithConfig<JavaScriptAlertOverlayRequestConfig>(
JavaScriptDialogSource(&web_state, GURL("https://chromium.test"),
/*is_main_frame=*/true),
"Message Text");
OverlayRequest* request = passed_request.get();
SetRequest(std::move(passed_request));
// Start the coordinator and verify that the alert is shown.
StartDialogCoordinator();
__weak UIViewController* alert = GetAlertViewController();
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^bool {
return !!alert.presentingViewController && !alert.beingPresented;
}));
// Stop the coordinator and verify that the alert is dismissed and that the
// dismissal delegate is notified.
StopDialogCoordinator();
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^bool {
return !alert.presentingViewController;
}));
EXPECT_TRUE(delegate().HasUIBeenDismissed(request));
}
// 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_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_CONFIRMATION_OVERLAY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_CONFIRMATION_OVERLAY_COORDINATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator.h"
// An OverlayCoordinator that displays the UI for JavaScript confirmations.
@interface JavaScriptConfirmationOverlayCoordinator : AlertOverlayCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_CONFIRMATION_OVERLAY_COORDINATOR_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/overlays/web_content_area/java_script_dialogs/java_script_confirmation_overlay_coordinator.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_confirmation_overlay.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_confirmation_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation JavaScriptConfirmationOverlayCoordinator
#pragma mark - OverlayRequestCoordinator
+ (const OverlayRequestSupport*)requestSupport {
return JavaScriptConfirmationOverlayRequestConfig::RequestSupport();
}
@end
@implementation JavaScriptConfirmationOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
return [[JavaScriptConfirmationOverlayMediator alloc]
initWithRequest:self.request];
}
@end
// 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_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_PROMPT_OVERLAY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_PROMPT_OVERLAY_COORDINATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator.h"
// An OverlayCoordinator that displays the UI for JavaScript prompts.
@interface JavaScriptPromptOverlayCoordinator : AlertOverlayCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_JAVA_SCRIPT_DIALOGS_JAVA_SCRIPT_PROMPT_OVERLAY_COORDINATOR_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/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_coordinator.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_prompt_overlay.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_coordinator+alert_mediator_creation.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_mediator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation JavaScriptPromptOverlayCoordinator
#pragma mark - OverlayRequestCoordinator
+ (const OverlayRequestSupport*)requestSupport {
return JavaScriptPromptOverlayRequestConfig::RequestSupport();
}
@end
@implementation JavaScriptPromptOverlayCoordinator (AlertMediatorCreation)
- (AlertOverlayMediator*)newMediator {
return [[JavaScriptPromptOverlayMediator alloc] initWithRequest:self.request];
}
@end
// 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/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_coordinator.h"
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/web_content_area/java_script_prompt_overlay.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/test/java_script_dialog_overlay_coordinator_test.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using base::test::ios::kWaitForUIElementTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
// Test fixture for JavaScriptPromptOverlayCoordinator.
using JavaScriptPromptOverlayCoordinatorTest =
JavaScriptDialogOverlayCoordinatorTest;
// Tests that JavaScriptPromptOverlayCoordinator creates an alert and
// presents it non-modally.
TEST_F(JavaScriptPromptOverlayCoordinatorTest, StartAndStop) {
web::TestWebState web_state;
std::unique_ptr<OverlayRequest> passed_request =
OverlayRequest::CreateWithConfig<JavaScriptPromptOverlayRequestConfig>(
JavaScriptDialogSource(&web_state, GURL("https://chromium.test"),
/*is_main_frame=*/true),
"Message Text", "Default Prompt Value");
OverlayRequest* request = passed_request.get();
SetRequest(std::move(passed_request));
// Start the coordinator and verify that the alert is shown.
StartDialogCoordinator();
__weak UIViewController* prompt = GetAlertViewController();
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^bool {
return !!prompt.presentingViewController && !prompt.isBeingPresented;
}));
// Stop the coordinator and verify that the alert is dismissed and that the
// dismissal delegate is notified.
StopDialogCoordinator();
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^bool {
return !prompt.presentingViewController;
}));
EXPECT_TRUE(delegate().HasUIBeenDismissed(request));
}
...@@ -4,11 +4,7 @@ ...@@ -4,11 +4,7 @@
#import "ios/chrome/browser/ui/overlays/web_content_area/web_content_area_supported_overlay_coordinator_classes.h" #import "ios/chrome/browser/ui/overlays/web_content_area/web_content_area_supported_overlay_coordinator_classes.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/app_launcher/app_launcher_alert_overlay_coordinator.h" #import "ios/chrome/browser/ui/overlays/web_content_area/alerts/web_content_area_alert_overlay_coordinator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/http_auth_dialogs/http_auth_dialog_overlay_coordinator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_alert_overlay_coordinator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_confirmation_overlay_coordinator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_coordinator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -17,11 +13,7 @@ ...@@ -17,11 +13,7 @@
namespace web_content_area { namespace web_content_area {
NSArray<Class>* GetSupportedOverlayCoordinatorClasses() { NSArray<Class>* GetSupportedOverlayCoordinatorClasses() {
return @ [[AppLauncherAlertOverlayCoordinator class], return @[ [WebContentAreaOverlayCoordinator class] ];
[HTTPAuthDialogOverlayCoordinator class],
[JavaScriptAlertOverlayCoordinator class],
[JavaScriptConfirmationOverlayCoordinator class],
[JavaScriptPromptOverlayCoordinator class]];
} }
} // web_content_area } // web_content_area
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