Commit 237e4fad authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Create InfobarOverlayType enum.

InfobarOverlayType is used to describe the types of OverlayRequest
configurations that will be supported for a single InfoBar.  These are
used to show overlays for the banner UI (kBanner), the action sheet
displayed in Messages 2.0 showing detailed options (kDetailSheet), and
the modal UI used to update settings for that infobar (kModal).

InfobarOverlayRequestFactory was updated to take an InfobarOverlayType
in its factory method to allow the creation of OverlayRequests
configured for each of these overlay types for a given InfoBar.
InfobarOverlayRequestFactoryImpl was updated to use templated helpers
to create requests instead of relying on switch statements and boolean
logic to decide which configuration to use for each InfobarType
and InfobarOverlayType pair.

Bug: 1030357
Change-Id: Iaba54c95dfece2381164ccf8a615b8fda28c42d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959936
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724796}
parent 8d044ed2
......@@ -5,41 +5,69 @@
source_set("overlays") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"infobar_banner_overlay_request_factory.h",
"infobar_banner_overlay_request_factory_impl.h",
"infobar_banner_overlay_request_factory_impl.mm",
"infobar_overlay_request_cancel_handler.h",
"infobar_overlay_request_cancel_handler.mm",
"infobar_overlay_request_factory.h",
"infobar_overlay_request_factory_impl.h",
"infobar_overlay_request_factory_impl.mm",
"infobar_overlay_tab_helper.h",
"infobar_overlay_tab_helper.mm",
"infobar_overlay_type.h",
]
deps = [
"//base",
"//components/infobars/core",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/infobars:public",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/common/infobars",
"//ios/chrome/browser/overlays/public/infobar_banner",
"//ios/chrome/browser/passwords:infobar_delegates",
"//ios/chrome/browser/ui/infobars:infobars_ui",
"//ios/web/public",
]
}
source_set("test_support") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"fake_infobar_overlay_request_factory.h",
"fake_infobar_overlay_request_factory.mm",
]
deps = [
":overlays",
"//base",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/common/infobars",
]
}
source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"infobar_overlay_request_cancel_handler_unittest.mm",
"infobar_overlay_request_factory_impl_unittest.mm",
"infobar_overlay_tab_helper_unittest.mm",
]
deps = [
":overlays",
":test_support",
"//base/test:test_support",
"//base/test:test_support",
"//components/password_manager/core/browser:test_support",
"//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/infobars:public",
"//ios/chrome/browser/infobars/test",
"//ios/chrome/browser/overlays",
"//ios/chrome/browser/overlays/public/common/infobars",
"//ios/chrome/browser/overlays/public/infobar_banner",
"//ios/chrome/browser/overlays/test",
"//ios/chrome/browser/passwords:infobar_delegates",
"//ios/chrome/browser/ui/infobars:feature_flags",
"//ios/chrome/browser/ui/infobars/test",
"//ios/chrome/test:test_support",
"//ios/web/public/test/fakes",
"//testing/gtest",
......
// 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_INFOBARS_OVERLAYS_FAKE_INFOBAR_OVERLAY_REQUEST_FACTORY_H_
#define IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_FAKE_INFOBAR_OVERLAY_REQUEST_FACTORY_H_
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_factory.h"
class OverlayRequest;
// Fake version of InfobarOverlayRequestFactory. Creates OverlayRequests that
// are only configured with an InfobarOverlayData.
class FakeInfobarOverlayRequestFactory : public InfobarOverlayRequestFactory {
public:
FakeInfobarOverlayRequestFactory();
~FakeInfobarOverlayRequestFactory() override;
// InfobarOverlayRequestFactory:
std::unique_ptr<OverlayRequest> CreateInfobarRequest(
infobars::InfoBar* infobar,
InfobarOverlayType type) override;
};
#endif // IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_FAKE_INFOBAR_OVERLAY_REQUEST_FACTORY_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/infobars/overlays/fake_infobar_overlay_request_factory.h"
#import "ios/chrome/browser/overlays/public/common/infobars/infobar_overlay.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
FakeInfobarOverlayRequestFactory::FakeInfobarOverlayRequestFactory() = default;
FakeInfobarOverlayRequestFactory::~FakeInfobarOverlayRequestFactory() = default;
std::unique_ptr<OverlayRequest>
FakeInfobarOverlayRequestFactory::CreateInfobarRequest(
infobars::InfoBar* infobar,
InfobarOverlayType type) {
return OverlayRequest::CreateWithConfig<InfobarOverlayData>(infobar);
}
// 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_INFOBARS_OVERLAYS_INFOBAR_BANNER_OVERLAY_REQUEST_FACTORY_H_
#define IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_BANNER_OVERLAY_REQUEST_FACTORY_H_
#include <memory>
namespace infobars {
class InfoBar;
}
class OverlayRequest;
// Factory object that converts InfoBars into OverlayRequests for banner UI.
class InfobarBannerOverlayRequestFactory {
public:
virtual ~InfobarBannerOverlayRequestFactory() = default;
// Creates an OverlayRequest for an InfoBar banner configured using |infobar|,
// or returns nullptr if a banner request cannot be created.
virtual std::unique_ptr<OverlayRequest> CreateBannerRequest(
infobars::InfoBar* infobar) = 0;
};
#endif // IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_BANNER_OVERLAY_REQUEST_FACTORY_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.
#ifndef IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_BANNER_OVERLAY_REQUEST_FACTORY_IMPL_H_
#define IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_BANNER_OVERLAY_REQUEST_FACTORY_IMPL_H_
#import "ios/chrome/browser/infobars/overlays/infobar_banner_overlay_request_factory.h"
// Implementation of InfobarBannerOverlayRequestFactory.
class InfobarBannerOverlayRequestFactoryImpl
: public InfobarBannerOverlayRequestFactory {
public:
explicit InfobarBannerOverlayRequestFactoryImpl();
~InfobarBannerOverlayRequestFactoryImpl() override;
private:
// InfobarBannerOverlayRequestFactory:
std::unique_ptr<OverlayRequest> CreateBannerRequest(
infobars::InfoBar* infobar) override;
};
#endif // IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_BANNER_OVERLAY_REQUEST_FACTORY_IMPL_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/infobars/overlays/infobar_banner_overlay_request_factory_impl.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#import "ios/chrome/browser/overlays/public/infobar_banner/save_password_infobar_banner_overlay.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using infobars::InfoBar;
using infobars::InfoBarDelegate;
InfobarBannerOverlayRequestFactoryImpl::
InfobarBannerOverlayRequestFactoryImpl() = default;
InfobarBannerOverlayRequestFactoryImpl::
~InfobarBannerOverlayRequestFactoryImpl() = default;
std::unique_ptr<OverlayRequest>
InfobarBannerOverlayRequestFactoryImpl::CreateBannerRequest(InfoBar* infobar) {
switch (infobar->delegate()->GetIdentifier()) {
case InfoBarDelegate::SAVE_PASSWORD_INFOBAR_DELEGATE_MOBILE:
return OverlayRequest::CreateWithConfig<
SavePasswordInfobarBannerOverlayRequestConfig>(infobar);
default:
return nullptr;
}
}
// 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_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_REQUEST_FACTORY_H_
#define IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_REQUEST_FACTORY_H_
#include <memory>
#include "ios/chrome/browser/infobars/overlays/infobar_overlay_type.h"
namespace infobars {
class InfoBar;
}
class OverlayRequest;
// Factory object that converts InfoBars into OverlayRequests.
class InfobarOverlayRequestFactory {
public:
virtual ~InfobarOverlayRequestFactory() = default;
// Creates an OverlayRequest configured to show the overlay of |type| for
// |infobar|.
virtual std::unique_ptr<OverlayRequest> CreateInfobarRequest(
infobars::InfoBar* infobar,
InfobarOverlayType type) = 0;
};
#endif // IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_REQUEST_FACTORY_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.
#ifndef IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_REQUEST_FACTORY_IMPL_H_
#define IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_REQUEST_FACTORY_IMPL_H_
#include <map>
#include <vector>
#include "components/infobars/core/infobar_delegate.h"
#import "ios/chrome/browser/infobars/infobar_type.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_factory.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
// Implementation of InfobarOverlayRequestFactory.
class InfobarOverlayRequestFactoryImpl : public InfobarOverlayRequestFactory {
public:
explicit InfobarOverlayRequestFactoryImpl();
~InfobarOverlayRequestFactoryImpl() override;
private:
// InfobarOverlayRequestFactory:
std::unique_ptr<OverlayRequest> CreateInfobarRequest(
infobars::InfoBar* infobar,
InfobarOverlayType type) override;
// Helper object used to create OverlayRequests. Subclasses should be created
// for each InfobarType and InfobarOverlayType.
class FactoryHelper {
public:
FactoryHelper() = default;
virtual ~FactoryHelper() = default;
virtual std::unique_ptr<OverlayRequest> CreateInfobarRequest(
infobars::InfoBar* infobar) const = 0;
};
// Template for a helper objects used to create OverlayRequests.
// Specializations of this template should be created for each
// InfobarType and InfobarOverlayType.
template <class RequestConfigType>
class FactoryHelperImpl : public FactoryHelper {
public:
FactoryHelperImpl() = default;
virtual ~FactoryHelperImpl() override = default;
// CreationHelperBase:
std::unique_ptr<OverlayRequest> CreateInfobarRequest(
infobars::InfoBar* infobar) const override {
return OverlayRequest::CreateWithConfig<RequestConfigType>(infobar);
}
};
// Storage object that holds the factory helpers for each InfobarOverlayType
// for a given InfobarType.
class FactoryHelperStorage {
public:
FactoryHelperStorage();
FactoryHelperStorage(std::unique_ptr<FactoryHelper> banner_factory,
std::unique_ptr<FactoryHelper> detail_sheet_factory,
std::unique_ptr<FactoryHelper> modal_factory);
FactoryHelperStorage(FactoryHelperStorage&& storage);
~FactoryHelperStorage();
// Returns the factory for |type|.
FactoryHelper* operator[](InfobarOverlayType type);
private:
// The factory helper for each InfobarOverlayType.
std::map<InfobarOverlayType, std::unique_ptr<FactoryHelper>> factories_;
};
// Creates a FactoryHelper that creates OverlayRequests using ConfigType.
template <class ConfigType>
std::unique_ptr<FactoryHelper> CreateFactory() {
return std::make_unique<FactoryHelperImpl<ConfigType>>();
}
// Creates a FactoryHelperStorage with the passed factory helpers, then adds
// it to |factory_storages_|.
void SetUpFactories(InfobarType type,
std::unique_ptr<FactoryHelper> banner_factory,
std::unique_ptr<FactoryHelper> detail_sheet_factory,
std::unique_ptr<FactoryHelper> modal_factory);
// Map containing the factory storages for each of InfobarType.
std::map<InfobarType, FactoryHelperStorage> factory_storages_;
};
#endif // IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_REQUEST_FACTORY_IMPL_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/infobars/overlays/infobar_overlay_request_factory_impl.h"
#include "components/infobars/core/infobar.h"
#import "ios/chrome/browser/infobars/infobar_ios.h"
#import "ios/chrome/browser/overlays/public/infobar_banner/save_password_infobar_banner_overlay.h"
#import "ios/chrome/browser/ui/infobars/infobar_ui_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using infobars::InfoBar;
using infobars::InfoBarDelegate;
InfobarOverlayRequestFactoryImpl::InfobarOverlayRequestFactoryImpl() {
// Create the factory helpers for the supported infobar types.
// TODO(crbug.com/1030357): Add factory helpers for other infobar and overlay
// types.
SetUpFactories(InfobarType::kInfobarTypePasswordSave,
CreateFactory<SavePasswordInfobarBannerOverlayRequestConfig>(),
/*detail_sheet_factory=*/nullptr, /*modal_factory=*/nullptr);
}
InfobarOverlayRequestFactoryImpl::~InfobarOverlayRequestFactoryImpl() = default;
std::unique_ptr<OverlayRequest>
InfobarOverlayRequestFactoryImpl::CreateInfobarRequest(
InfoBar* infobar,
InfobarOverlayType type) {
DCHECK(infobar);
InfoBarIOS* infobar_ios = static_cast<InfoBarIOS*>(infobar);
// It is an error to call this for an InfobarType/InfobarOverlayType combo
// that has not been added to the factory storages.
return factory_storages_[infobar_ios->InfobarUIDelegate().infobarType][type]
->CreateInfobarRequest(infobar);
}
void InfobarOverlayRequestFactoryImpl::SetUpFactories(
InfobarType type,
std::unique_ptr<FactoryHelper> banner_factory,
std::unique_ptr<FactoryHelper> detail_sheet_factory,
std::unique_ptr<FactoryHelper> modal_factory) {
factory_storages_.emplace(
type, FactoryHelperStorage(std::move(banner_factory),
std::move(detail_sheet_factory),
std::move(modal_factory)));
}
#pragma mark - FactoryHelperStorage
InfobarOverlayRequestFactoryImpl::FactoryHelperStorage::FactoryHelperStorage() =
default;
InfobarOverlayRequestFactoryImpl::FactoryHelperStorage::FactoryHelperStorage(
std::unique_ptr<FactoryHelper> banner_factory,
std::unique_ptr<FactoryHelper> detail_sheet_factory,
std::unique_ptr<FactoryHelper> modal_factory) {
factories_[InfobarOverlayType::kBanner] = std::move(banner_factory);
factories_[InfobarOverlayType::kDetailSheet] =
std::move(detail_sheet_factory);
factories_[InfobarOverlayType::kModal] = std::move(modal_factory);
}
InfobarOverlayRequestFactoryImpl::FactoryHelperStorage::FactoryHelperStorage(
InfobarOverlayRequestFactoryImpl::FactoryHelperStorage&& storage) {
factories_[InfobarOverlayType::kBanner] =
std::move(storage.factories_[InfobarOverlayType::kBanner]);
factories_[InfobarOverlayType::kDetailSheet] =
std::move(storage.factories_[InfobarOverlayType::kDetailSheet]);
factories_[InfobarOverlayType::kModal] =
std::move(storage.factories_[InfobarOverlayType::kModal]);
}
InfobarOverlayRequestFactoryImpl::FactoryHelperStorage::
~FactoryHelperStorage() = default;
InfobarOverlayRequestFactoryImpl::FactoryHelper*
InfobarOverlayRequestFactoryImpl::FactoryHelperStorage::operator[](
InfobarOverlayType type) {
return factories_[type].get();
}
// 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/infobars/overlays/infobar_overlay_request_factory_impl.h"
#include "base/feature_list.h"
#include "base/test/scoped_feature_list.h"
#include "components/infobars/core/infobar.h"
#include "components/password_manager/core/browser/mock_password_form_manager_for_ui.h"
#include "ios/chrome/browser/infobars/infobar_ios.h"
#import "ios/chrome/browser/overlays/public/infobar_banner/save_password_infobar_banner_overlay.h"
#import "ios/chrome/browser/passwords/ios_chrome_save_password_infobar_delegate.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/infobars/test/fake_infobar_ui_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using infobars::InfoBar;
using infobars::InfoBarDelegate;
// Test fixture for InfobarOverlayRequestFactoryImpl.
class InfobarOverlayRequestFactoryImplTest : public PlatformTest {
public:
InfobarOverlayRequestFactoryImplTest() {
feature_list_.InitWithFeatures({kInfobarUIReboot}, {});
}
InfobarOverlayRequestFactory* factory() { return &factory_; }
private:
base::test::ScopedFeatureList feature_list_;
InfobarOverlayRequestFactoryImpl factory_;
};
// Tests that the factory creates a save passwords infobar request.
TEST_F(InfobarOverlayRequestFactoryImplTest, SavePasswords) {
FakeInfobarUIDelegate* ui_delegate = [[FakeInfobarUIDelegate alloc] init];
ui_delegate.infobarType = InfobarType::kInfobarTypePasswordSave;
std::unique_ptr<password_manager::PasswordFormManagerForUI> form =
std::make_unique<password_manager::MockPasswordFormManagerForUI>();
std::unique_ptr<InfoBarDelegate> delegate =
std::make_unique<IOSChromeSavePasswordInfoBarDelegate>(false, false,
std::move(form));
InfoBarIOS infobar(ui_delegate, std::move(delegate));
std::unique_ptr<OverlayRequest> request =
factory()->CreateInfobarRequest(&infobar, InfobarOverlayType::kBanner);
EXPECT_TRUE(
request->GetConfig<SavePasswordInfobarBannerOverlayRequestConfig>());
// TODO(crbug.com/1033154): Add additional tests for other
// InfobarOverlayTypes.
}
......@@ -11,7 +11,7 @@
#include "components/infobars/core/infobar_manager.h"
#import "ios/web/public/web_state_user_data.h"
class InfobarBannerOverlayRequestFactory;
class InfobarOverlayRequestFactory;
class OverlayRequestQueue;
// Helper class that creates OverlayRequests for the banner UI for InfoBars
......@@ -26,12 +26,12 @@ class InfobarOverlayTabHelper
// using |request_factory|.
static void CreateForWebState(
web::WebState* web_state,
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory);
std::unique_ptr<InfobarOverlayRequestFactory> request_factory);
private:
InfobarOverlayTabHelper(
web::WebState* web_state,
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory);
std::unique_ptr<InfobarOverlayRequestFactory> request_factory);
friend class web::WebStateUserData<InfobarOverlayTabHelper>;
WEB_STATE_USER_DATA_KEY_DECL();
......@@ -41,7 +41,7 @@ class InfobarOverlayTabHelper
public:
OverlayRequestScheduler(
web::WebState* web_state,
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory);
std::unique_ptr<InfobarOverlayRequestFactory> request_factory);
~OverlayRequestScheduler() override;
private:
......@@ -54,7 +54,7 @@ class InfobarOverlayTabHelper
OverlayRequestQueue* queue_ = nullptr;
// The request factory passed on initialization. Used to create
// OverlayRequests for InfoBars added to the InfoBarManager.
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory_;
std::unique_ptr<InfobarOverlayRequestFactory> request_factory_;
ScopedObserver<infobars::InfoBarManager, infobars::InfoBarManager::Observer>
scoped_observer_;
......
......@@ -6,8 +6,8 @@
#include "base/logging.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/infobars/overlays/infobar_banner_overlay_request_factory.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_cancel_handler.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_factory.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
......@@ -25,7 +25,7 @@ WEB_STATE_USER_DATA_KEY_IMPL(InfobarOverlayTabHelper)
// static
void InfobarOverlayTabHelper::CreateForWebState(
web::WebState* web_state,
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory) {
std::unique_ptr<InfobarOverlayRequestFactory> request_factory) {
DCHECK(web_state);
if (!FromWebState(web_state)) {
web_state->SetUserData(UserDataKey(),
......@@ -36,7 +36,7 @@ void InfobarOverlayTabHelper::CreateForWebState(
InfobarOverlayTabHelper::InfobarOverlayTabHelper(
web::WebState* web_state,
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory)
std::unique_ptr<InfobarOverlayRequestFactory> request_factory)
: overlay_request_scheduler_(web_state, std::move(request_factory)) {}
InfobarOverlayTabHelper::~InfobarOverlayTabHelper() = default;
......@@ -45,7 +45,7 @@ InfobarOverlayTabHelper::~InfobarOverlayTabHelper() = default;
InfobarOverlayTabHelper::OverlayRequestScheduler::OverlayRequestScheduler(
web::WebState* web_state,
std::unique_ptr<InfobarBannerOverlayRequestFactory> request_factory)
std::unique_ptr<InfobarOverlayRequestFactory> request_factory)
: queue_(
OverlayRequestQueue::FromWebState(web_state,
OverlayModality::kInfobarBanner)),
......@@ -64,7 +64,8 @@ InfobarOverlayTabHelper::OverlayRequestScheduler::~OverlayRequestScheduler() =
void InfobarOverlayTabHelper::OverlayRequestScheduler::OnInfoBarAdded(
InfoBar* infobar) {
std::unique_ptr<OverlayRequest> request =
request_factory_->CreateBannerRequest(infobar);
request_factory_->CreateInfobarRequest(infobar,
InfobarOverlayType::kBanner);
DCHECK(request);
std::unique_ptr<OverlayRequestCancelHandler> cancel_handler =
std::make_unique<InfobarOverlayRequestCancelHandler>(request.get(),
......
......@@ -6,11 +6,12 @@
#import <Foundation/Foundation.h>
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/infobars/overlays/infobar_banner_overlay_request_factory.h"
#import "ios/chrome/browser/infobars/overlays/fake_infobar_overlay_request_factory.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_factory.h"
#include "ios/chrome/browser/infobars/test/fake_infobar_delegate.h"
#import "ios/chrome/browser/infobars/test/fake_infobar_ios.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
#include "ios/chrome/browser/overlays/test/fake_overlay_user_data.h"
......@@ -27,29 +28,6 @@ using infobars::InfoBar;
using infobars::InfoBarDelegate;
using infobars::InfoBarManager;
namespace {
// The pointer value stored in FakeOverlayRequestUserData used to configure
// banner OverlayRequests created for InfoBars using a fake InfoBarDelegate with
// kFakeInfoBarMessage.
void* kOverlayRequestConfigValue = &kOverlayRequestConfigValue;
// Test version of InfobarBannerOverlayRequestFactory.
class FakeInfobarBannerOverlayRequestFactory
: public InfobarBannerOverlayRequestFactory {
public:
FakeInfobarBannerOverlayRequestFactory() = default;
~FakeInfobarBannerOverlayRequestFactory() override = default;
// InfobarBannerOverlayRequestFactory:
std::unique_ptr<OverlayRequest> CreateBannerRequest(
InfoBar* infobar) override {
return OverlayRequest::CreateWithConfig<FakeOverlayUserData>(
kOverlayRequestConfigValue);
}
};
} // namespace
// Test fixture for InfobarOverlayTabHelper.
class InfobarOverlayTabHelperTest : public PlatformTest {
public:
......@@ -58,8 +36,7 @@ class InfobarOverlayTabHelperTest : public PlatformTest {
std::make_unique<web::TestNavigationManager>());
InfoBarManagerImpl::CreateForWebState(&web_state_);
InfobarOverlayTabHelper::CreateForWebState(
&web_state_,
std::make_unique<FakeInfobarBannerOverlayRequestFactory>());
&web_state_, std::make_unique<FakeInfobarOverlayRequestFactory>());
}
// Returns the front request of |web_state_|'s OverlayRequestQueue.
......@@ -79,8 +56,6 @@ class InfobarOverlayTabHelperTest : public PlatformTest {
// Tests that adding an InfoBar to the manager creates a fake banner request.
TEST_F(InfobarOverlayTabHelperTest, AddInfoBar) {
ASSERT_FALSE(front_request());
std::unique_ptr<InfoBar> infobar =
std::make_unique<InfoBar>(std::make_unique<FakeInfobarDelegate>());
manager()->AddInfoBar(std::move(infobar));
manager()->AddInfoBar(std::make_unique<FakeInfobarIOS>());
ASSERT_TRUE(front_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_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_TYPE_H_
#define IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_TYPE_H_
// Enum describing the types of overlays displayed for a single infobar.
enum class InfobarOverlayType : short {
// Used to create banner overlays that are displayed in
// OverlayModality::kInfobarBanner.
kBanner,
// Used to create detail action sheet overlays that are displayed in
// OverlayModality::kInfobarModal.
kDetailSheet,
// Used to create modal overlays that are displayed in
// OverlayModality::kInfobarModal.
kModal,
};
#endif // IOS_CHROME_BROWSER_INFOBARS_OVERLAYS_INFOBAR_OVERLAY_TYPE_H_
......@@ -28,7 +28,7 @@
#include "ios/chrome/browser/history/top_sites_factory.h"
#include "ios/chrome/browser/infobars/infobar_badge_tab_helper.h"
#import "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/infobars/overlays/infobar_banner_overlay_request_factory_impl.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_factory_impl.h"
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_tab_helper.h"
#import "ios/chrome/browser/itunes_urls/itunes_urls_handler_tab_helper.h"
#import "ios/chrome/browser/network_activity/network_activity_indicator_tab_helper.h"
......@@ -94,7 +94,7 @@ void AttachTabHelpers(web::WebState* web_state, bool for_prerender) {
if (base::FeatureList::IsEnabled(kInfobarOverlayUI)) {
InfobarOverlayTabHelper::CreateForWebState(
web_state, std::make_unique<InfobarBannerOverlayRequestFactoryImpl>());
web_state, std::make_unique<InfobarOverlayRequestFactoryImpl>());
}
if (base::FeatureList::IsEnabled(kCaptivePortalMetrics)) {
......
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