Commit 45fda9fa authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Separate dispatch and dismiss OverlayRequestMediator selectors

This allows OverlayRequestMediator subclasses to dispatch multiple
responses before dismissal for a single UI interaction event.

Bug: none
Change-Id: I6248d6d5a369dc9b25c3a5f88a1f8962241505b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1996160
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731813}
parent c79ae4c2
......@@ -45,27 +45,27 @@
- (void)bannerInfobarButtonWasPressed:(UIButton*)sender {
// Notify the model layer to perform the infobar's main action before
// dismissing the banner.
[self dispatchResponseAndStopOverlay:OverlayResponse::CreateWithInfo<
InfobarBannerMainActionResponse>()];
[self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarBannerMainActionResponse>()];
[self dismissOverlay];
}
- (void)dismissInfobarBannerForUserInteraction:(BOOL)userInitiated {
if (userInitiated) {
// Notify the model layer of user-initiated banner dismissal before
// dismissing the banner.
[self dispatchResponseAndStopOverlay:
OverlayResponse::CreateWithInfo<
InfobarBannerUserInitiatedDismissalResponse>()];
} else {
[self.delegate stopOverlayForMediator:self];
[self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarBannerUserInitiatedDismissalResponse>()];
}
[self dismissOverlay];
}
- (void)presentInfobarModalFromBanner {
// Notify the model layer to show the infobar modal before dismissing the
// banner.
[self dispatchResponseAndStopOverlay:OverlayResponse::CreateWithInfo<
InfobarBannerShowModalResponse>()];
[self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarBannerShowModalResponse>()];
[self dismissOverlay];
}
- (void)infobarBannerWasDismissed {
......
......@@ -23,8 +23,9 @@
}
- (void)modalInfobarButtonWasAccepted:(id)infobarModal {
[self dispatchResponseAndStopOverlay:OverlayResponse::CreateWithInfo<
InfobarModalMainActionResponse>()];
[self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarModalMainActionResponse>()];
[self dismissOverlay];
}
- (void)modalInfobarWasDismissed:(id)infobarModal {
......
......@@ -14,10 +14,12 @@
// Exposes shared functionality for OverlayRequestMediator subclasses.
@interface OverlayRequestMediator (Subclassing)
// Dispatches |response| through the mediator's request callback manager, then
// instructs the delegate to stop the overlay.
- (void)dispatchResponseAndStopOverlay:
(std::unique_ptr<OverlayResponse>)response;
// Dispatches |response| through the mediator's request callback manager. Does
// nothing if the request has been cancelled.
- (void)dispatchResponse:(std::unique_ptr<OverlayResponse>)response;
// Instructs the delegate to stop the overlay.
- (void)dismissOverlay;
@end
......
......@@ -55,10 +55,12 @@
@implementation OverlayRequestMediator (Subclassing)
- (void)dispatchResponseAndStopOverlay:
(std::unique_ptr<OverlayResponse>)response {
- (void)dispatchResponse:(std::unique_ptr<OverlayResponse>)response {
if (self.request)
self.request->GetCallbackManager()->DispatchResponse(std::move(response));
}
- (void)dismissOverlay {
[self.delegate stopOverlayForMediator:self];
}
......
......@@ -39,9 +39,8 @@ TEST_F(OverlayRequestMediatorTest, ResetRequestAfterDestruction) {
EXPECT_EQ(nullptr, mediator.request);
}
// Tests that the |-dispatchResponseAndStopOverlay:| correctly dispatches the
// response and stops the overlay.
TEST_F(OverlayRequestMediatorTest, DispatchResponseAndStopOverlay) {
// Tests that |-dispatchResponse:| correctly dispatches the response.
TEST_F(OverlayRequestMediatorTest, DispatchResponse) {
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<FakeOverlayUserData>();
// Add a dispatch callback that sets |dispatch_callback_executed| to true
......@@ -58,13 +57,24 @@ TEST_F(OverlayRequestMediatorTest, DispatchResponseAndStopOverlay) {
DispatchInfo::ResponseSupport()));
OverlayRequestMediator* mediator =
[[OverlayRequestMediator alloc] initWithRequest:request.get()];
// Dispatch the response and verify |dipatch_callback_executed|.
[mediator dispatchResponse:std::move(dispatched_response)];
EXPECT_TRUE(dispatch_callback_executed);
}
// Tests that |-dismissOverlay| stops the overlay.
TEST_F(OverlayRequestMediatorTest, DismissOverlay) {
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<FakeOverlayUserData>();
OverlayRequestMediator* mediator =
[[OverlayRequestMediator alloc] initWithRequest:request.get()];
id<OverlayRequestMediatorDelegate> delegate =
OCMStrictProtocolMock(@protocol(OverlayRequestMediatorDelegate));
mediator.delegate = delegate;
OCMExpect([delegate stopOverlayForMediator:mediator]);
[mediator dispatchResponseAndStopOverlay:std::move(dispatched_response)];
[mediator dismissOverlay];
EXPECT_TRUE(dispatch_callback_executed);
EXPECT_OCMOCK_VERIFY(delegate);
}
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