Commit 8357d9e1 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Convert app launch overlays to use Alert[Request/Config]

This CL updates the app launch confirmation overlays to use the new
AlertRequest and AlertConfig objects.  This allows for the removal of
the app launcher overlay mediator, allowing the app launch confirmation
dialog to use the shared AlertOverlayMediator implementation.

Bug: 1071543
Change-Id: Ic0548bbdeb728a9465fe013e1201e434413386f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2155475
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Auto-Submit: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762056}
parent 0472f8c1
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#import "ios/chrome/browser/overlays/public/overlay_request.h" #import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h" #import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
#import "ios/chrome/browser/overlays/public/overlay_response.h" #import "ios/chrome/browser/overlays/public/overlay_response.h"
#import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h" #import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_overlay.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_opener.h" #import "ios/chrome/browser/web_state_list/web_state_opener.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
BROWSER_USER_DATA_KEY_IMPL(AppLauncherBrowserAgent) BROWSER_USER_DATA_KEY_IMPL(AppLauncherBrowserAgent)
using app_launcher_overlays::AppLaunchConfirmationRequest;
using app_launcher_overlays::AllowAppLaunchResponse;
namespace { namespace {
// Records histogram metric on the user's response when prompted to open another // Records histogram metric on the user's response when prompted to open another
// application. |user_accepted| should be YES if the user accepted the prompt to // application. |user_accepted| should be YES if the user accepted the prompt to
...@@ -43,13 +46,8 @@ void RecordUserAcceptedAppLaunchMetric(BOOL user_accepted) { ...@@ -43,13 +46,8 @@ void RecordUserAcceptedAppLaunchMetric(BOOL user_accepted) {
void AppLauncherOverlayCallback(base::OnceCallback<void(bool)> completion, void AppLauncherOverlayCallback(base::OnceCallback<void(bool)> completion,
bool repeated_request, bool repeated_request,
OverlayResponse* response) { OverlayResponse* response) {
// Extract the user decision from |response|. // Check whether the user has allowed the navigation.
bool user_accepted = false; bool user_accepted = response && response->GetInfo<AllowAppLaunchResponse>();
if (response) {
AppLauncherAlertOverlayResponseInfo* info =
response->GetInfo<AppLauncherAlertOverlayResponseInfo>();
user_accepted = info && info->allow_navigation();
}
// Record the UMA for repeated requests. // Record the UMA for repeated requests.
if (repeated_request) if (repeated_request)
...@@ -113,7 +111,7 @@ void AppLauncherBrowserAgent::TabHelperDelegate::LaunchAppForTabHelper( ...@@ -113,7 +111,7 @@ void AppLauncherBrowserAgent::TabHelperDelegate::LaunchAppForTabHelper(
bool show_dialog = UrlHasAppStoreScheme(url) || !link_transition; bool show_dialog = UrlHasAppStoreScheme(url) || !link_transition;
if (show_dialog) { if (show_dialog) {
std::unique_ptr<OverlayRequest> request = std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<AppLauncherAlertOverlayRequestConfig>( OverlayRequest::CreateWithConfig<AppLaunchConfirmationRequest>(
/*is_repeated_request=*/false); /*is_repeated_request=*/false);
request->GetCallbackManager()->AddCompletionCallback(base::BindOnce( request->GetCallbackManager()->AddCompletionCallback(base::BindOnce(
&AppLauncherOverlayCallback, base::BindOnce(&LaunchExternalApp, url), &AppLauncherOverlayCallback, base::BindOnce(&LaunchExternalApp, url),
...@@ -129,7 +127,7 @@ void AppLauncherBrowserAgent::TabHelperDelegate::ShowRepeatedAppLaunchAlert( ...@@ -129,7 +127,7 @@ void AppLauncherBrowserAgent::TabHelperDelegate::ShowRepeatedAppLaunchAlert(
AppLauncherTabHelper* tab_helper, AppLauncherTabHelper* tab_helper,
base::OnceCallback<void(bool)> completion) { base::OnceCallback<void(bool)> completion) {
std::unique_ptr<OverlayRequest> request = std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<AppLauncherAlertOverlayRequestConfig>( OverlayRequest::CreateWithConfig<AppLaunchConfirmationRequest>(
/*is_repeated_request=*/true); /*is_repeated_request=*/true);
request->GetCallbackManager()->AddCompletionCallback( request->GetCallbackManager()->AddCompletionCallback(
base::BindOnce(&AppLauncherOverlayCallback, std::move(completion), base::BindOnce(&AppLauncherOverlayCallback, std::move(completion),
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "ios/chrome/browser/overlays/public/overlay_request.h" #include "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h" #import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
#include "ios/chrome/browser/overlays/public/overlay_response.h" #include "ios/chrome/browser/overlays/public/overlay_response.h"
#import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h" #import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_overlay.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_opener.h" #import "ios/chrome/browser/web_state_list/web_state_opener.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h" #import "ios/web/public/test/fakes/test_navigation_manager.h"
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using app_launcher_overlays::AppLaunchConfirmationRequest;
using app_launcher_overlays::AllowAppLaunchResponse;
// Test fixture for AppLauncherBrowserAgent. // Test fixture for AppLauncherBrowserAgent.
class AppLauncherBrowserAgentTest : public PlatformTest { class AppLauncherBrowserAgentTest : public PlatformTest {
protected: protected:
...@@ -79,7 +82,7 @@ class AppLauncherBrowserAgentTest : public PlatformTest { ...@@ -79,7 +82,7 @@ class AppLauncherBrowserAgentTest : public PlatformTest {
} }
// Returns whether the front OverlayRequest for |web_state|'s queue is // Returns whether the front OverlayRequest for |web_state|'s queue is
// configured with an AppLauncherAlertOverlayRequestConfig with // configured with an AppLaunchConfirmationRequest with
// |is_repeated_request|. // |is_repeated_request|.
bool IsShowingDialog(web::WebState* web_state, bool is_repeated_request) { bool IsShowingDialog(web::WebState* web_state, bool is_repeated_request) {
OverlayRequest* request = OverlayRequestQueue::FromWebState( OverlayRequest* request = OverlayRequestQueue::FromWebState(
...@@ -88,8 +91,8 @@ class AppLauncherBrowserAgentTest : public PlatformTest { ...@@ -88,8 +91,8 @@ class AppLauncherBrowserAgentTest : public PlatformTest {
if (!request) if (!request)
return false; return false;
AppLauncherAlertOverlayRequestConfig* config = AppLaunchConfirmationRequest* config =
request->GetConfig<AppLauncherAlertOverlayRequestConfig>(); request->GetConfig<AppLaunchConfirmationRequest>();
return config && config->is_repeated_request() == is_repeated_request; return config && config->is_repeated_request() == is_repeated_request;
} }
...@@ -117,8 +120,7 @@ TEST_F(AppLauncherBrowserAgentTest, AppStoreUrlShowsAlert) { ...@@ -117,8 +120,7 @@ TEST_F(AppLauncherBrowserAgentTest, AppStoreUrlShowsAlert) {
OverlayRequestQueue* queue = OverlayRequestQueue::FromWebState( OverlayRequestQueue* queue = OverlayRequestQueue::FromWebState(
web_state, OverlayModality::kWebContentArea); web_state, OverlayModality::kWebContentArea);
queue->front_request()->GetCallbackManager()->SetCompletionResponse( queue->front_request()->GetCallbackManager()->SetCompletionResponse(
OverlayResponse::CreateWithInfo<AppLauncherAlertOverlayResponseInfo>( OverlayResponse::CreateWithInfo<AllowAppLaunchResponse>());
/*allow_navigation=*/true));
// Cancel requests in the queue so that the completion callback is executed, // Cancel requests in the queue so that the completion callback is executed,
// expecting that the application will open the URL. // expecting that the application will open the URL.
...@@ -193,8 +195,7 @@ TEST_F(AppLauncherBrowserAgentTest, RepeatedRequestShowsAlert) { ...@@ -193,8 +195,7 @@ TEST_F(AppLauncherBrowserAgentTest, RepeatedRequestShowsAlert) {
OverlayRequestQueue* queue = OverlayRequestQueue::FromWebState( OverlayRequestQueue* queue = OverlayRequestQueue::FromWebState(
web_state, OverlayModality::kWebContentArea); web_state, OverlayModality::kWebContentArea);
queue->front_request()->GetCallbackManager()->SetCompletionResponse( queue->front_request()->GetCallbackManager()->SetCompletionResponse(
OverlayResponse::CreateWithInfo<AppLauncherAlertOverlayResponseInfo>( OverlayResponse::CreateWithInfo<AllowAppLaunchResponse>());
/*allow_navigation=*/true));
// Cancel requests in the queue so that the completion callback is executed, // Cancel requests in the queue so that the completion callback is executed,
// expecting that the application will open the URL. // expecting that the application will open the URL.
...@@ -226,8 +227,7 @@ TEST_F(AppLauncherBrowserAgentTest, AppUrlWithoutLinkShowsAlert) { ...@@ -226,8 +227,7 @@ TEST_F(AppLauncherBrowserAgentTest, AppUrlWithoutLinkShowsAlert) {
OverlayRequestQueue* queue = OverlayRequestQueue::FromWebState( OverlayRequestQueue* queue = OverlayRequestQueue::FromWebState(
web_state, OverlayModality::kWebContentArea); web_state, OverlayModality::kWebContentArea);
queue->front_request()->GetCallbackManager()->SetCompletionResponse( queue->front_request()->GetCallbackManager()->SetCompletionResponse(
OverlayResponse::CreateWithInfo<AppLauncherAlertOverlayResponseInfo>( OverlayResponse::CreateWithInfo<AllowAppLaunchResponse>());
/*allow_navigation=*/true));
// Cancel requests in the queue so that the completion callback is executed, // Cancel requests in the queue so that the completion callback is executed,
// expecting that the application will open the URL. // expecting that the application will open the URL.
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
source_set("web_content_area") { source_set("web_content_area") {
sources = [ sources = [
"app_launcher_alert_overlay.h", "app_launcher_overlay.h",
"app_launcher_alert_overlay.mm", "app_launcher_overlay.mm",
"http_auth_overlay.h", "http_auth_overlay.h",
"http_auth_overlay.mm", "http_auth_overlay.mm",
"java_script_alert_overlay.h", "java_script_alert_overlay.h",
...@@ -35,7 +35,10 @@ source_set("web_content_area") { ...@@ -35,7 +35,10 @@ source_set("web_content_area") {
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ "http_auth_overlay_unittest.mm" ] sources = [
"app_launcher_overlay_unittest.mm",
"http_auth_overlay_unittest.mm",
]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
// 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/overlays/public/web_content_area/app_launcher_alert_overlay.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
OVERLAY_USER_DATA_SETUP_IMPL(AppLauncherAlertOverlayRequestConfig);
AppLauncherAlertOverlayRequestConfig::AppLauncherAlertOverlayRequestConfig(
bool is_repeated_request)
: is_repeated_request_(is_repeated_request) {}
AppLauncherAlertOverlayRequestConfig::~AppLauncherAlertOverlayRequestConfig() =
default;
OVERLAY_USER_DATA_SETUP_IMPL(AppLauncherAlertOverlayResponseInfo);
AppLauncherAlertOverlayResponseInfo::AppLauncherAlertOverlayResponseInfo(
bool allow_navigation)
: allow_navigation_(allow_navigation) {}
AppLauncherAlertOverlayResponseInfo::~AppLauncherAlertOverlayResponseInfo() =
default;
...@@ -2,43 +2,37 @@ ...@@ -2,43 +2,37 @@
// 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_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_APP_LAUNCHER_ALERT_OVERLAY_H_ #ifndef IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_APP_LAUNCHER_OVERLAY_H_
#define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_APP_LAUNCHER_ALERT_OVERLAY_H_ #define IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_APP_LAUNCHER_OVERLAY_H_
#include "ios/chrome/browser/overlays/public/overlay_request_config.h" #include "ios/chrome/browser/overlays/public/overlay_request_config.h"
#include "ios/chrome/browser/overlays/public/overlay_response_info.h" #include "ios/chrome/browser/overlays/public/overlay_response_info.h"
namespace app_launcher_overlays {
// Configuration object for OverlayRequests for alerts notifying the user that // Configuration object for OverlayRequests for alerts notifying the user that
// a navigation will open another app. // a navigation will open another app.
class AppLauncherAlertOverlayRequestConfig class AppLaunchConfirmationRequest
: public OverlayRequestConfig<AppLauncherAlertOverlayRequestConfig> { : public OverlayRequestConfig<AppLaunchConfirmationRequest> {
public: public:
~AppLauncherAlertOverlayRequestConfig() override; ~AppLaunchConfirmationRequest() override;
// Whether the current page has previously attempted to open another app. // Whether the current page has previously attempted to open another app.
bool is_repeated_request() const { return is_repeated_request_; } bool is_repeated_request() const { return is_repeated_request_; }
private: private:
OVERLAY_USER_DATA_SETUP(AppLauncherAlertOverlayRequestConfig); OVERLAY_USER_DATA_SETUP(AppLaunchConfirmationRequest);
AppLauncherAlertOverlayRequestConfig(bool is_repeated_request); AppLaunchConfirmationRequest(bool is_repeated_request);
// OverlayUserData:
void CreateAuxiliaryData(base::SupportsUserData* user_data) override;
const bool is_repeated_request_; const bool is_repeated_request_;
}; };
// User interaction info for OverlayResponses for app launcher alerts. // Completion response used when the user allows the app launcher navigation.
class AppLauncherAlertOverlayResponseInfo DEFINE_STATELESS_OVERLAY_RESPONSE_INFO(AllowAppLaunchResponse);
: public OverlayResponseInfo<AppLauncherAlertOverlayResponseInfo> {
public:
~AppLauncherAlertOverlayResponseInfo() override;
// Whether the user has chosen to allow navigation to another app.
bool allow_navigation() const { return allow_navigation_; }
private: } // namespace app_launcher_overlays
OVERLAY_USER_DATA_SETUP(AppLauncherAlertOverlayResponseInfo);
AppLauncherAlertOverlayResponseInfo(bool allow_navigation);
const bool allow_navigation_;
};
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_APP_LAUNCHER_ALERT_OVERLAY_H_ #endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_WEB_CONTENT_AREA_APP_LAUNCHER_OVERLAY_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/overlays/public/web_content_area/app_launcher_overlay.h"
#include "base/bind.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/overlays/public/common/alerts/alert_overlay.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using alert_overlays::AlertRequest;
using alert_overlays::AlertResponse;
using alert_overlays::ButtonConfig;
namespace app_launcher_overlays {
namespace {
// The index of the alert for the OK button.
const size_t kButtonIndexOk = 0;
// Creates an OverlayRequest with AllowAppLaunchResponse from one created
// with an AlertResponse.
std::unique_ptr<OverlayResponse> CreateAllowAppLaunchResponse(
std::unique_ptr<OverlayResponse> alert_response) {
AlertResponse* alert_info = alert_response->GetInfo<AlertResponse>();
if (!alert_info || alert_info->tapped_button_index() != kButtonIndexOk)
return nullptr;
return OverlayResponse::CreateWithInfo<AllowAppLaunchResponse>();
}
} // namespace
#pragma mark - AppLaunchConfirmationRequest
OVERLAY_USER_DATA_SETUP_IMPL(AppLaunchConfirmationRequest);
AppLaunchConfirmationRequest::AppLaunchConfirmationRequest(
bool is_repeated_request)
: is_repeated_request_(is_repeated_request) {}
AppLaunchConfirmationRequest::~AppLaunchConfirmationRequest() = default;
void AppLaunchConfirmationRequest::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
NSString* alert_message =
is_repeated_request()
? l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP)
: l10n_util::GetNSString(IDS_IOS_OPEN_IN_ANOTHER_APP);
NSString* reject_button_title = l10n_util::GetNSString(IDS_CANCEL);
NSString* allow_button_title =
is_repeated_request()
? l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP_ALLOW)
: l10n_util::GetNSString(IDS_IOS_APP_LAUNCHER_OPEN_APP_BUTTON_LABEL);
const std::vector<ButtonConfig> alert_button_configs{
ButtonConfig(allow_button_title),
ButtonConfig(reject_button_title, UIAlertActionStyleCancel)};
AlertRequest::CreateForUserData(
user_data, /*title=*/nil, alert_message, /*accessibility_identifier=*/nil,
/*text_field_configs=*/nil, alert_button_configs,
base::BindRepeating(&CreateAllowAppLaunchResponse));
}
#pragma mark - AllowAppLaunchResponse
OVERLAY_USER_DATA_SETUP_IMPL(AllowAppLaunchResponse);
} // app_launcher_overlays
// 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/overlays/public/web_content_area/app_launcher_overlay.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/overlays/public/common/alerts/alert_overlay.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_response.h"
#import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_overlay.h"
#include "ios/chrome/grit/ios_strings.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using alert_overlays::AlertRequest;
using alert_overlays::AlertResponse;
using alert_overlays::ButtonConfig;
using app_launcher_overlays::AppLaunchConfirmationRequest;
using app_launcher_overlays::AllowAppLaunchResponse;
// Test fixture for app launcher overlays.
using AppLauncherOverlayTest = PlatformTest;
// Tests that the alert overlay request is set correctly for the first app
// launch request.
TEST_F(AppLauncherOverlayTest, FirstRequestAlertSetup) {
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<AppLaunchConfirmationRequest>(
/*is_repeated_request=*/false);
AlertRequest* config = request->GetConfig<AlertRequest>();
ASSERT_TRUE(config);
// The app launch alert has no title, and uses IDS_IOS_OPEN_IN_ANOTHER_APP as
// its message.
EXPECT_NSEQ(l10n_util::GetNSString(IDS_IOS_OPEN_IN_ANOTHER_APP),
config->message());
// There is an OK button and a Cancel button in app launch alerts.
ASSERT_EQ(2U, config->button_configs().size());
const ButtonConfig& ok_button_config = config->button_configs()[0];
const ButtonConfig& cancel_button_config = config->button_configs()[1];
EXPECT_EQ(UIAlertActionStyleDefault, ok_button_config.style);
EXPECT_NSEQ(
l10n_util::GetNSString(IDS_IOS_APP_LAUNCHER_OPEN_APP_BUTTON_LABEL),
ok_button_config.title);
EXPECT_EQ(UIAlertActionStyleCancel, cancel_button_config.style);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_CANCEL), cancel_button_config.title);
}
// Tests that the alert overlay request is set correctly for a repeated app
// launch request.
TEST_F(AppLauncherOverlayTest, RepeatedRequestAlertSetup) {
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<AppLaunchConfirmationRequest>(
/*is_repeated_request=*/true);
AlertRequest* config = request->GetConfig<AlertRequest>();
ASSERT_TRUE(config);
// The app launch alert has no title, and uses
// IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP as its message.
EXPECT_NSEQ(l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP),
config->message());
// There is an OK button and a Cancel button in app launch alerts.
ASSERT_EQ(2U, config->button_configs().size());
const ButtonConfig& ok_button_config = config->button_configs()[0];
const ButtonConfig& cancel_button_config = config->button_configs()[1];
EXPECT_EQ(UIAlertActionStyleDefault, ok_button_config.style);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP_ALLOW),
ok_button_config.title);
EXPECT_EQ(UIAlertActionStyleCancel, cancel_button_config.style);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_CANCEL), cancel_button_config.title);
}
// Tests that an alert response after tapping the OK button successfully creates
// an AllowAppLaunchResponse.
TEST_F(AppLauncherOverlayTest, ResponseConversionOk) {
// Simulate a response where the OK button is tapped.
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<AppLaunchConfirmationRequest>(
/*is_repeated_request=*/false);
AlertRequest* config = request->GetConfig<AlertRequest>();
std::unique_ptr<OverlayResponse> alert_response =
OverlayResponse::CreateWithInfo<AlertResponse>(
/*tapped_button_index=*/0, /*text_field_values=*/nil);
// Convert the response to the AllowAppLaunchResponse.
std::unique_ptr<OverlayResponse> response =
config->response_converter().Run(std::move(alert_response));
ASSERT_TRUE(response);
EXPECT_TRUE(response->GetInfo<AllowAppLaunchResponse>());
}
// Tests that an alert response after tapping the Cancel button is converted to
// a null response.
TEST_F(AppLauncherOverlayTest, ResponseConversionCancel) {
// Simulate a response where the Cancel button is tapped.
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<AppLaunchConfirmationRequest>(
/*is_repeated_request=*/false);
AlertRequest* config = request->GetConfig<AlertRequest>();
std::unique_ptr<OverlayResponse> alert_response =
OverlayResponse::CreateWithInfo<AlertResponse>(
/*tapped_button_index=*/1, /*text_field_values=*/nil);
// Convert the response and verify that no AllowAppLaunchResponse was created.
std::unique_ptr<OverlayResponse> response =
config->response_converter().Run(std::move(alert_response));
EXPECT_FALSE(response);
}
...@@ -21,7 +21,6 @@ source_set("alerts") { ...@@ -21,7 +21,6 @@ source_set("alerts") {
"//ios/chrome/browser/ui/overlays:coordinators", "//ios/chrome/browser/ui/overlays:coordinators",
"//ios/chrome/browser/ui/overlays:util", "//ios/chrome/browser/ui/overlays:util",
"//ios/chrome/browser/ui/overlays/common/alerts", "//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/java_script_dialogs", "//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs",
"//ui/base", "//ui/base",
] ]
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "ios/chrome/browser/overlays/public/overlay_request_support.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/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/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/java_script_dialogs/java_script_alert_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_confirmation_overlay_mediator.h"
#import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_mediator.h" #import "ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs/java_script_prompt_overlay_mediator.h"
...@@ -33,7 +32,6 @@ ...@@ -33,7 +32,6 @@
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
_supportedMediatorClasses = @[ _supportedMediatorClasses = @[
[AlertOverlayMediator class], [AlertOverlayMediator class],
[AppLauncherAlertOverlayMediator class],
[JavaScriptConfirmationOverlayMediator class], [JavaScriptConfirmationOverlayMediator class],
[JavaScriptAlertOverlayMediator class], [JavaScriptAlertOverlayMediator class],
[JavaScriptPromptOverlayMediator class], [JavaScriptPromptOverlayMediator class],
......
# 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.
source_set("app_launcher") {
sources = [
"app_launcher_alert_overlay_mediator.h",
"app_launcher_alert_overlay_mediator.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/common/alerts",
"//ui/base",
]
}
source_set("unit_tests") {
testonly = true
sources = [ "app_launcher_alert_overlay_mediator_unittest.mm" ]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
":app_launcher",
"//base/test:test_support",
"//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/overlays/test",
"//ios/chrome/browser/ui/alert_view",
"//ios/chrome/browser/ui/alert_view/test",
"//ios/chrome/browser/ui/dialogs",
"//ios/chrome/browser/ui/overlays/common/alerts/test",
"//ios/chrome/browser/ui/overlays/test",
"//testing/gmock",
"//testing/gtest",
"//ui/base",
]
}
// 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_MEDIATOR_H_
#define IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_APP_LAUNCHER_APP_LAUNCHER_ALERT_OVERLAY_MEDIATOR_H_
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_mediator.h"
class OverlayRequest;
// Mediator object that uses a AppLauncherAlertOverlayRequestConfig to set up
// the UI for an alert notifying the user that a navigation will open an
// external app.
@interface AppLauncherAlertOverlayMediator : AlertOverlayMediator
// Designated initializer for a mediator that uses |request|'s configuration to
// set up an AlertConsumer.
- (instancetype)initWithRequest:(OverlayRequest*)request
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_OVERLAYS_WEB_CONTENT_AREA_APP_LAUNCHER_APP_LAUNCHER_ALERT_OVERLAY_MEDIATOR_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_mediator.h"
#include "base/logging.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/overlays/public/overlay_callback_manager.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#include "ios/chrome/browser/overlays/public/overlay_response.h"
#include "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h"
#import "ios/chrome/browser/ui/alert_view/alert_action.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/alert_overlay_mediator+alert_consumer_support.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface AppLauncherAlertOverlayMediator ()
// The config from the request passed on initialization.
@property(nonatomic, readonly) AppLauncherAlertOverlayRequestConfig* config;
// Sets the OverlayResponse. |allowAppLaunch| indicates whether the alert's
// allow button was tapped to allow the navigation to open in another app.
- (void)updateResponseAllowingAppLaunch:(BOOL)allowAppLaunch;
@end
@implementation AppLauncherAlertOverlayMediator
- (instancetype)initWithRequest:(OverlayRequest*)request {
if (self = [super initWithRequest:request]) {
// Verify that the request is configured for app launcher alerts.
DCHECK(request->GetConfig<AppLauncherAlertOverlayRequestConfig>());
}
return self;
}
#pragma mark - Accessors
- (AppLauncherAlertOverlayRequestConfig*)config {
return self.request
? self.request->GetConfig<AppLauncherAlertOverlayRequestConfig>()
: nullptr;
}
#pragma mark - OverlayRequestMediator
+ (const OverlayRequestSupport*)requestSupport {
return AppLauncherAlertOverlayRequestConfig::RequestSupport();
}
#pragma mark - Response helpers
- (void)updateResponseAllowingAppLaunch:(BOOL)allowAppLaunch {
if (!self.request)
return;
self.request->GetCallbackManager()->SetCompletionResponse(
OverlayResponse::CreateWithInfo<AppLauncherAlertOverlayResponseInfo>(
allowAppLaunch));
}
@end
@implementation AppLauncherAlertOverlayMediator (AlertConsumerSupport)
- (NSString*)alertMessage {
return self.config->is_repeated_request()
? l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP)
: l10n_util::GetNSString(IDS_IOS_OPEN_IN_ANOTHER_APP);
}
- (NSArray<AlertAction*>*)alertActions {
NSString* rejectActionTitle = l10n_util::GetNSString(IDS_CANCEL);
NSString* allowActionTitle =
self.config->is_repeated_request()
? l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP_ALLOW)
: l10n_util::GetNSString(IDS_IOS_APP_LAUNCHER_OPEN_APP_BUTTON_LABEL);
__weak __typeof__(self) weakSelf = self;
return @[
[AlertAction actionWithTitle:allowActionTitle
style:UIAlertActionStyleDefault
handler:^(AlertAction* action) {
__typeof__(self) strongSelf = weakSelf;
[strongSelf updateResponseAllowingAppLaunch:YES];
[strongSelf.delegate
stopOverlayForMediator:strongSelf];
}],
[AlertAction actionWithTitle:rejectActionTitle
style:UIAlertActionStyleCancel
handler:^(AlertAction* action) {
__typeof__(self) strongSelf = weakSelf;
[strongSelf updateResponseAllowingAppLaunch:NO];
[strongSelf.delegate
stopOverlayForMediator:strongSelf];
}],
];
}
@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/app_launcher/app_launcher_alert_overlay_mediator.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_response.h"
#import "ios/chrome/browser/overlays/public/web_content_area/app_launcher_alert_overlay.h"
#import "ios/chrome/browser/ui/alert_view/alert_action.h"
#import "ios/chrome/browser/ui/alert_view/test/fake_alert_consumer.h"
#import "ios/chrome/browser/ui/overlays/common/alerts/test/alert_overlay_mediator_test.h"
#include "ios/chrome/grit/ios_strings.h"
#include "testing/gtest_mac.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
class AppLauncherAlertOverlayMediatorTest : public AlertOverlayMediatorTest {
protected:
AppLauncherAlertOverlayMediatorTest() { UpdateMediator(); }
// Setter for whether the test is for a repeated app launch request.
void set_is_repeated_request(bool is_repeated_request) {
if (is_repeated_request_ == is_repeated_request)
return;
is_repeated_request_ = is_repeated_request;
UpdateMediator();
}
private:
// Instantiates |request_| with an OverlayRequest configured with an
// AppLauncherAlertOverlayRequestConfig set up using |is_repeated_request_|.
// Creates a new mediator using using |request_|.
void UpdateMediator() {
request_ =
OverlayRequest::CreateWithConfig<AppLauncherAlertOverlayRequestConfig>(
is_repeated_request_);
SetMediator([[AppLauncherAlertOverlayMediator alloc]
initWithRequest:request_.get()]);
}
bool is_repeated_request_ = false;
std::unique_ptr<OverlayRequest> request_;
};
// Tests that the consumer values are set correctly for the first app launch
// request.
TEST_F(AppLauncherAlertOverlayMediatorTest, FirstRequestAlertSetup) {
EXPECT_NSEQ(l10n_util::GetNSString(IDS_IOS_OPEN_IN_ANOTHER_APP),
consumer().message);
ASSERT_EQ(2U, consumer().actions.count);
EXPECT_EQ(UIAlertActionStyleDefault, consumer().actions[0].style);
EXPECT_NSEQ(
l10n_util::GetNSString(IDS_IOS_APP_LAUNCHER_OPEN_APP_BUTTON_LABEL),
consumer().actions[0].title);
EXPECT_EQ(UIAlertActionStyleCancel, consumer().actions[1].style);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_CANCEL), consumer().actions[1].title);
}
// Tests that the consumer values are set correctly for the repeated app launch
// requests.
TEST_F(AppLauncherAlertOverlayMediatorTest, RepeatedRequestAlertSetup) {
set_is_repeated_request(true);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP),
consumer().message);
ASSERT_EQ(2U, consumer().actions.count);
EXPECT_EQ(UIAlertActionStyleDefault, consumer().actions[0].style);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_IOS_OPEN_REPEATEDLY_ANOTHER_APP_ALLOW),
consumer().actions[0].title);
EXPECT_EQ(UIAlertActionStyleCancel, consumer().actions[1].style);
EXPECT_NSEQ(l10n_util::GetNSString(IDS_CANCEL), consumer().actions[1].title);
}
...@@ -278,7 +278,6 @@ test("ios_chrome_unittests") { ...@@ -278,7 +278,6 @@ test("ios_chrome_unittests") {
"//ios/chrome/browser/ui/overlays/infobar_modal:unit_tests", "//ios/chrome/browser/ui/overlays/infobar_modal:unit_tests",
"//ios/chrome/browser/ui/overlays/infobar_modal/passwords:unit_tests", "//ios/chrome/browser/ui/overlays/infobar_modal/passwords:unit_tests",
"//ios/chrome/browser/ui/overlays/test_modality:unit_tests", "//ios/chrome/browser/ui/overlays/test_modality:unit_tests",
"//ios/chrome/browser/ui/overlays/web_content_area/app_launcher:unit_tests",
"//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs:unit_tests", "//ios/chrome/browser/ui/overlays/web_content_area/java_script_dialogs:unit_tests",
"//ios/chrome/browser/ui/popup_menu:unit_tests", "//ios/chrome/browser/ui/popup_menu:unit_tests",
"//ios/chrome/browser/ui/presenters:unit_tests", "//ios/chrome/browser/ui/presenters:unit_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