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 @@ ...@@ -45,27 +45,27 @@
- (void)bannerInfobarButtonWasPressed:(UIButton*)sender { - (void)bannerInfobarButtonWasPressed:(UIButton*)sender {
// Notify the model layer to perform the infobar's main action before // Notify the model layer to perform the infobar's main action before
// dismissing the banner. // dismissing the banner.
[self dispatchResponseAndStopOverlay:OverlayResponse::CreateWithInfo< [self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarBannerMainActionResponse>()]; InfobarBannerMainActionResponse>()];
[self dismissOverlay];
} }
- (void)dismissInfobarBannerForUserInteraction:(BOOL)userInitiated { - (void)dismissInfobarBannerForUserInteraction:(BOOL)userInitiated {
if (userInitiated) { if (userInitiated) {
// Notify the model layer of user-initiated banner dismissal before // Notify the model layer of user-initiated banner dismissal before
// dismissing the banner. // dismissing the banner.
[self dispatchResponseAndStopOverlay: [self dispatchResponse:OverlayResponse::CreateWithInfo<
OverlayResponse::CreateWithInfo<
InfobarBannerUserInitiatedDismissalResponse>()]; InfobarBannerUserInitiatedDismissalResponse>()];
} else {
[self.delegate stopOverlayForMediator:self];
} }
[self dismissOverlay];
} }
- (void)presentInfobarModalFromBanner { - (void)presentInfobarModalFromBanner {
// Notify the model layer to show the infobar modal before dismissing the // Notify the model layer to show the infobar modal before dismissing the
// banner. // banner.
[self dispatchResponseAndStopOverlay:OverlayResponse::CreateWithInfo< [self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarBannerShowModalResponse>()]; InfobarBannerShowModalResponse>()];
[self dismissOverlay];
} }
- (void)infobarBannerWasDismissed { - (void)infobarBannerWasDismissed {
......
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
} }
- (void)modalInfobarButtonWasAccepted:(id)infobarModal { - (void)modalInfobarButtonWasAccepted:(id)infobarModal {
[self dispatchResponseAndStopOverlay:OverlayResponse::CreateWithInfo< [self dispatchResponse:OverlayResponse::CreateWithInfo<
InfobarModalMainActionResponse>()]; InfobarModalMainActionResponse>()];
[self dismissOverlay];
} }
- (void)modalInfobarWasDismissed:(id)infobarModal { - (void)modalInfobarWasDismissed:(id)infobarModal {
......
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
// Exposes shared functionality for OverlayRequestMediator subclasses. // Exposes shared functionality for OverlayRequestMediator subclasses.
@interface OverlayRequestMediator (Subclassing) @interface OverlayRequestMediator (Subclassing)
// Dispatches |response| through the mediator's request callback manager, then // Dispatches |response| through the mediator's request callback manager. Does
// instructs the delegate to stop the overlay. // nothing if the request has been cancelled.
- (void)dispatchResponseAndStopOverlay: - (void)dispatchResponse:(std::unique_ptr<OverlayResponse>)response;
(std::unique_ptr<OverlayResponse>)response;
// Instructs the delegate to stop the overlay.
- (void)dismissOverlay;
@end @end
......
...@@ -55,10 +55,12 @@ ...@@ -55,10 +55,12 @@
@implementation OverlayRequestMediator (Subclassing) @implementation OverlayRequestMediator (Subclassing)
- (void)dispatchResponseAndStopOverlay: - (void)dispatchResponse:(std::unique_ptr<OverlayResponse>)response {
(std::unique_ptr<OverlayResponse>)response {
if (self.request) if (self.request)
self.request->GetCallbackManager()->DispatchResponse(std::move(response)); self.request->GetCallbackManager()->DispatchResponse(std::move(response));
}
- (void)dismissOverlay {
[self.delegate stopOverlayForMediator:self]; [self.delegate stopOverlayForMediator:self];
} }
......
...@@ -39,9 +39,8 @@ TEST_F(OverlayRequestMediatorTest, ResetRequestAfterDestruction) { ...@@ -39,9 +39,8 @@ TEST_F(OverlayRequestMediatorTest, ResetRequestAfterDestruction) {
EXPECT_EQ(nullptr, mediator.request); EXPECT_EQ(nullptr, mediator.request);
} }
// Tests that the |-dispatchResponseAndStopOverlay:| correctly dispatches the // Tests that |-dispatchResponse:| correctly dispatches the response.
// response and stops the overlay. TEST_F(OverlayRequestMediatorTest, DispatchResponse) {
TEST_F(OverlayRequestMediatorTest, DispatchResponseAndStopOverlay) {
std::unique_ptr<OverlayRequest> request = std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<FakeOverlayUserData>(); OverlayRequest::CreateWithConfig<FakeOverlayUserData>();
// Add a dispatch callback that sets |dispatch_callback_executed| to true // Add a dispatch callback that sets |dispatch_callback_executed| to true
...@@ -58,13 +57,24 @@ TEST_F(OverlayRequestMediatorTest, DispatchResponseAndStopOverlay) { ...@@ -58,13 +57,24 @@ TEST_F(OverlayRequestMediatorTest, DispatchResponseAndStopOverlay) {
DispatchInfo::ResponseSupport())); DispatchInfo::ResponseSupport()));
OverlayRequestMediator* mediator = OverlayRequestMediator* mediator =
[[OverlayRequestMediator alloc] initWithRequest:request.get()]; [[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 = id<OverlayRequestMediatorDelegate> delegate =
OCMStrictProtocolMock(@protocol(OverlayRequestMediatorDelegate)); OCMStrictProtocolMock(@protocol(OverlayRequestMediatorDelegate));
mediator.delegate = delegate; mediator.delegate = delegate;
OCMExpect([delegate stopOverlayForMediator:mediator]); OCMExpect([delegate stopOverlayForMediator:mediator]);
[mediator dispatchResponseAndStopOverlay:std::move(dispatched_response)]; [mediator dismissOverlay];
EXPECT_TRUE(dispatch_callback_executed);
EXPECT_OCMOCK_VERIFY(delegate); 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