From d6ecdf833934023d24dbc2aa164d8d17b5377a83 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Tue, 16 Mar 2021 15:25:31 +0000 Subject: [PATCH] Decouple AdsServiceImpl full screen mode business logic --- components/brave_ads/browser/DEPS | 2 +- .../brave_ads/browser/ads_service_impl.cc | 5 ++ .../brave_ads/browser/ads_service_impl.h | 2 + .../browser/notification_helper_linux.cc | 6 -- .../browser/notification_helper_mac.mm | 9 +-- .../browser/notification_helper_win.cc | 10 +-- components/brave_ads/test/BUILD.gn | 1 + .../bat_ads/bat_ads_client_mojo_bridge.cc | 10 +++ .../bat_ads/bat_ads_client_mojo_bridge.h | 2 + .../public/cpp/ads_client_mojo_bridge.cc | 10 +++ .../public/cpp/ads_client_mojo_bridge.h | 2 + .../bat_ads/public/interfaces/bat_ads.mojom | 2 + vendor/bat-native-ads/BUILD.gn | 2 + .../include/bat/ads/ads_client.h | 3 + .../src/bat/ads/internal/ads_client_mock.h | 2 + .../ad_notifications_frequency_capping.cc | 6 ++ .../full_screen_mode_frequency_cap.cc | 39 ++++++++++ .../full_screen_mode_frequency_cap.h | 37 ++++++++++ ...full_screen_mode_frequency_cap_unittest.cc | 74 +++++++++++++++++++ .../src/bat/ads/internal/unittest_base.cc | 2 + .../src/bat/ads/internal/unittest_util.cc | 5 ++ .../src/bat/ads/internal/unittest_util.h | 3 + vendor/brave-ios/Ads/BATBraveAds.mm | 4 + .../brave-ios/Ads/Generated/NativeAdsClient.h | 1 + .../Ads/Generated/NativeAdsClient.mm | 4 + .../Ads/Generated/NativeAdsClientBridge.h | 1 + 26 files changed, 221 insertions(+), 23 deletions(-) create mode 100644 vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.cc create mode 100644 vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h create mode 100644 vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap_unittest.cc diff --git a/components/brave_ads/browser/DEPS b/components/brave_ads/browser/DEPS index 79a00179fb52..5a06266b0e63 100644 --- a/components/brave_ads/browser/DEPS +++ b/components/brave_ads/browser/DEPS @@ -31,6 +31,7 @@ specific_include_rules = { "+brave/browser/notifications/brave_notification_platform_bridge_helper_android.h", "+chrome/common/chrome_paths.h", "+chrome/browser/browser_process.h", + "+chrome/browser/fullscreen.h", "+chrome/browser/notifications/notification_display_service.h", "+chrome/browser/profiles/profile_manager.h", "+chrome/browser/profiles/profile.h", @@ -77,7 +78,6 @@ specific_include_rules = { "+brave/common/brave_channel_info.h", "+chrome/android/chrome_jni_headers/NotificationSystemStatusUtil_jni.h", "+chrome/browser/notifications/notification_channels_provider_android.h", - "+chrome/browser/fullscreen.h", "+chrome/common/chrome_features.h", "+chrome/install_static/install_util.h", "+chrome/installer/util/install_util.h", diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index a2f8c474493c..27104b7a0b49 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -60,6 +60,7 @@ #include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/fullscreen.h" #include "chrome/browser/notifications/notification_display_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" @@ -1720,6 +1721,10 @@ bool AdsServiceImpl::IsForeground() const { return BackgroundHelper::GetInstance()->IsForeground(); } +bool AdsServiceImpl::IsFullScreen() const { + return IsFullScreenMode(); +} + std::string AdsServiceImpl::GetLocale() const { return brave_l10n::LocaleHelper::GetInstance()->GetLocale(); } diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index 96a9f831b381..10831434bfce 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -315,6 +315,8 @@ class AdsServiceImpl : public AdsService, bool IsForeground() const override; + bool IsFullScreen() const override; + bool ShouldShowNotifications() override; bool CanShowBackgroundNotifications() const override; diff --git a/components/brave_ads/browser/notification_helper_linux.cc b/components/brave_ads/browser/notification_helper_linux.cc index cde70ae8e0b8..b4c5431bb7d7 100644 --- a/components/brave_ads/browser/notification_helper_linux.cc +++ b/components/brave_ads/browser/notification_helper_linux.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "brave/common/brave_channel_info.h" -#include "chrome/browser/fullscreen.h" namespace brave_ads { @@ -16,11 +15,6 @@ NotificationHelperLinux::NotificationHelperLinux() = default; NotificationHelperLinux::~NotificationHelperLinux() = default; bool NotificationHelperLinux::ShouldShowNotifications() { - if (IsFullScreenMode()) { - LOG(WARNING) << "Notification not made: Full screen mode"; - return false; - } - if (brave::IsNightlyOrDeveloperBuild()) { return true; } diff --git a/components/brave_ads/browser/notification_helper_mac.mm b/components/brave_ads/browser/notification_helper_mac.mm index f7d72949c2a8..2b25105e0aa4 100644 --- a/components/brave_ads/browser/notification_helper_mac.mm +++ b/components/brave_ads/browser/notification_helper_mac.mm @@ -14,10 +14,8 @@ #include "base/logging.h" #include "base/mac/mac_util.h" #include "brave/common/brave_channel_info.h" -#include "chrome/common/chrome_features.h" - #include "brave/components/brave_ads/browser/notification_helper_mac.h" -#include "chrome/browser/fullscreen.h" +#include "chrome/common/chrome_features.h" namespace brave_ads { @@ -26,11 +24,6 @@ NotificationHelperMac::~NotificationHelperMac() = default; bool NotificationHelperMac::ShouldShowNotifications() { - if (IsFullScreenMode()) { - LOG(WARNING) << "Notification not made: Full screen mode"; - return false; - } - if (brave::IsNightlyOrDeveloperBuild()) { return true; } diff --git a/components/brave_ads/browser/notification_helper_win.cc b/components/brave_ads/browser/notification_helper_win.cc index aeca5fabd5db..b1bd39536677 100644 --- a/components/brave_ads/browser/notification_helper_win.cc +++ b/components/brave_ads/browser/notification_helper_win.cc @@ -3,17 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include - #include "brave/components/brave_ads/browser/notification_helper_win.h" +#include + #include "base/feature_list.h" #include "base/logging.h" #include "base/win/core_winrt_util.h" #include "base/win/scoped_hstring.h" #include "base/win/windows_version.h" #include "brave/common/brave_channel_info.h" -#include "chrome/browser/fullscreen.h" #include "chrome/common/chrome_features.h" #include "chrome/install_static/install_util.h" #include "chrome/installer/util/install_util.h" @@ -66,11 +65,6 @@ NotificationHelperWin::NotificationHelperWin() = default; NotificationHelperWin::~NotificationHelperWin() = default; bool NotificationHelperWin::ShouldShowNotifications() { - if (IsFullScreenMode()) { - LOG(WARNING) << "Notification not made: Full screen mode"; - return false; - } - if (brave::IsNightlyOrDeveloperBuild()) { return true; } diff --git a/components/brave_ads/test/BUILD.gn b/components/brave_ads/test/BUILD.gn index 7ac9bc29444c..61f1dbf7693f 100644 --- a/components/brave_ads/test/BUILD.gn +++ b/components/brave_ads/test/BUILD.gn @@ -88,6 +88,7 @@ source_set("brave_ads_unit_tests") { "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/browser_is_active_frequency_cap_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/catalog_frequency_cap_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/do_not_disturb_frequency_cap_unittest.cc", + "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/media_frequency_cap_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/minimum_wait_time_frequency_cap_unittest.cc", "//brave/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/network_connection_frequency_cap_unittest.cc", diff --git a/components/services/bat_ads/bat_ads_client_mojo_bridge.cc b/components/services/bat_ads/bat_ads_client_mojo_bridge.cc index 7f1951b29f99..3a8eb37daeb4 100644 --- a/components/services/bat_ads/bat_ads_client_mojo_bridge.cc +++ b/components/services/bat_ads/bat_ads_client_mojo_bridge.cc @@ -62,6 +62,16 @@ bool BatAdsClientMojoBridge::IsForeground() const { return is_foreground; } +bool BatAdsClientMojoBridge::IsFullScreen() const { + if (!connected()) { + return false; + } + + bool is_full_screen; + bat_ads_client_->IsFullScreen(&is_full_screen); + return is_full_screen; +} + void BatAdsClientMojoBridge::ShowNotification( const ads::AdNotificationInfo& ad_notification) { if (!connected()) { diff --git a/components/services/bat_ads/bat_ads_client_mojo_bridge.h b/components/services/bat_ads/bat_ads_client_mojo_bridge.h index 02510799400a..9fbbf37d5c47 100644 --- a/components/services/bat_ads/bat_ads_client_mojo_bridge.h +++ b/components/services/bat_ads/bat_ads_client_mojo_bridge.h @@ -35,6 +35,8 @@ class BatAdsClientMojoBridge bool IsForeground() const override; + bool IsFullScreen() const override; + void ShowNotification( const ads::AdNotificationInfo& ad_notification) override; bool ShouldShowNotifications() override; diff --git a/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.cc b/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.cc index c64feffc959b..835737a0f3ed 100644 --- a/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.cc +++ b/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.cc @@ -41,6 +41,16 @@ void AdsClientMojoBridge::IsForeground( std::move(callback).Run(ads_client_->IsForeground()); } +bool AdsClientMojoBridge::IsFullScreen(bool* out_is_full_screen) { + DCHECK(out_is_full_screen); + *out_is_full_screen = ads_client_->IsFullScreen(); + return true; +} + +void AdsClientMojoBridge::IsFullScreen(IsFullScreenCallback callback) { + std::move(callback).Run(ads_client_->IsFullScreen()); +} + bool AdsClientMojoBridge::CanShowBackgroundNotifications( bool* out_can_show) { DCHECK(out_can_show); diff --git a/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.h b/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.h index 59bedaa8e4a0..2bfc1828fa0d 100644 --- a/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.h +++ b/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.h @@ -35,6 +35,8 @@ class AdsClientMojoBridge bool* out_is_foreground) override; void IsForeground( IsForegroundCallback callback) override; + bool IsFullScreen(bool* out_is_full_screen) override; + void IsFullScreen(IsFullScreenCallback callback) override; bool IsNetworkConnectionAvailable( bool* out_available) override; void IsNetworkConnectionAvailable( diff --git a/components/services/bat_ads/public/interfaces/bat_ads.mojom b/components/services/bat_ads/public/interfaces/bat_ads.mojom index ac2bc25b605b..addc7c7d35b2 100644 --- a/components/services/bat_ads/public/interfaces/bat_ads.mojom +++ b/components/services/bat_ads/public/interfaces/bat_ads.mojom @@ -23,6 +23,8 @@ interface BatAdsClient { [Sync] IsForeground() => (bool is_foreground); [Sync] + IsFullScreen() => (bool is_full_screen); + [Sync] ShouldShowNotifications() => (bool should_show); [Sync] CanShowBackgroundNotifications() => (bool can_show); diff --git a/vendor/bat-native-ads/BUILD.gn b/vendor/bat-native-ads/BUILD.gn index 58971246aede..3bb0cea7c113 100644 --- a/vendor/bat-native-ads/BUILD.gn +++ b/vendor/bat-native-ads/BUILD.gn @@ -454,6 +454,8 @@ source_set("ads") { "src/bat/ads/internal/frequency_capping/permission_rules/catalog_frequency_cap.h", "src/bat/ads/internal/frequency_capping/permission_rules/do_not_disturb_frequency_cap.cc", "src/bat/ads/internal/frequency_capping/permission_rules/do_not_disturb_frequency_cap.h", + "src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.cc", + "src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h", "src/bat/ads/internal/frequency_capping/permission_rules/media_frequency_cap.cc", "src/bat/ads/internal/frequency_capping/permission_rules/media_frequency_cap.h", "src/bat/ads/internal/frequency_capping/permission_rules/minimum_wait_time_frequency_cap.cc", diff --git a/vendor/bat-native-ads/include/bat/ads/ads_client.h b/vendor/bat-native-ads/include/bat/ads/ads_client.h index fbcb240a9c58..0297a9510cb9 100644 --- a/vendor/bat-native-ads/include/bat/ads/ads_client.h +++ b/vendor/bat-native-ads/include/bat/ads/ads_client.h @@ -37,6 +37,9 @@ class ADS_EXPORT AdsClient { // false virtual bool IsForeground() const = 0; + // Return true if the browser is full screen otherwise return false + virtual bool IsFullScreen() const = 0; + // Return true if notifications should be displayed otherwise return false virtual bool ShouldShowNotifications() = 0; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h b/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h index baa012680be0..1e6321f485c1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_client_mock.h @@ -25,6 +25,8 @@ class AdsClientMock : public AdsClient { MOCK_CONST_METHOD0(IsForeground, bool()); + MOCK_CONST_METHOD0(IsFullScreen, bool()); + MOCK_METHOD0(ShouldShowNotifications, bool()); MOCK_CONST_METHOD0(CanShowBackgroundNotifications, bool()); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/ad_notifications/ad_notifications_frequency_capping.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/ad_notifications/ad_notifications_frequency_capping.cc index fd7529d148ea..2a2f869adba1 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/ad_notifications/ad_notifications_frequency_capping.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/ad_notifications/ad_notifications_frequency_capping.cc @@ -27,6 +27,7 @@ #include "bat/ads/internal/frequency_capping/permission_rules/browser_is_active_frequency_cap.h" #include "bat/ads/internal/frequency_capping/permission_rules/catalog_frequency_cap.h" #include "bat/ads/internal/frequency_capping/permission_rules/do_not_disturb_frequency_cap.h" +#include "bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h" #include "bat/ads/internal/frequency_capping/permission_rules/media_frequency_cap.h" #include "bat/ads/internal/frequency_capping/permission_rules/minimum_wait_time_frequency_cap.h" #include "bat/ads/internal/frequency_capping/permission_rules/network_connection_frequency_cap.h" @@ -58,6 +59,11 @@ bool FrequencyCapping::IsAdAllowed() { return false; } + FullScreenModeFrequencyCap full_screen_mode_frequency_cap; + if (!ShouldAllow(&full_screen_mode_frequency_cap)) { + return false; + } + BrowserIsActiveFrequencyCap browser_is_active_frequency_cap; if (!ShouldAllow(&browser_is_active_frequency_cap)) { return false; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.cc new file mode 100644 index 000000000000..0bc150b150e7 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.cc @@ -0,0 +1,39 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h" + +#include "bat/ads/internal/ads_client_helper.h" +#include "bat/ads/internal/frequency_capping/frequency_capping_util.h" +#include "bat/ads/internal/platform/platform_helper.h" + +namespace ads { + +FullScreenModeFrequencyCap::FullScreenModeFrequencyCap() = default; + +FullScreenModeFrequencyCap::~FullScreenModeFrequencyCap() = default; + +bool FullScreenModeFrequencyCap::ShouldAllow() { + if (!DoesRespectCap()) { + last_message_ = "Full screen mode"; + return false; + } + + return true; +} + +std::string FullScreenModeFrequencyCap::get_last_message() const { + return last_message_; +} + +bool FullScreenModeFrequencyCap::DoesRespectCap() { + if (PlatformHelper::GetInstance()->IsMobile()) { + return true; + } + + return !AdsClientHelper::Get()->IsFullScreen(); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h new file mode 100644 index 000000000000..cb06d92588df --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_FREQUENCY_CAPPING_PERMISSION_RULES_FULL_SCREEN_MODE_FREQUENCY_CAP_H_ +#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_FREQUENCY_CAPPING_PERMISSION_RULES_FULL_SCREEN_MODE_FREQUENCY_CAP_H_ + +#include + +#include "bat/ads/internal/frequency_capping/permission_rules/permission_rule.h" + +namespace ads { + +class FullScreenModeFrequencyCap : public PermissionRule { + public: + FullScreenModeFrequencyCap(); + + ~FullScreenModeFrequencyCap() override; + + FullScreenModeFrequencyCap(const FullScreenModeFrequencyCap&) = delete; + FullScreenModeFrequencyCap& operator=(const FullScreenModeFrequencyCap&) = + delete; + + bool ShouldAllow() override; + + std::string get_last_message() const override; + + private: + std::string last_message_; + + bool DoesRespectCap(); +}; + +} // namespace ads + +#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_FREQUENCY_CAPPING_PERMISSION_RULES_FULL_SCREEN_MODE_FREQUENCY_CAP_H_ diff --git a/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap_unittest.cc b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap_unittest.cc new file mode 100644 index 000000000000..5f65d8da7919 --- /dev/null +++ b/vendor/bat-native-ads/src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap_unittest.cc @@ -0,0 +1,74 @@ +/* Copyright (c) 2020 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h" + +#include "bat/ads/internal/unittest_base.h" +#include "bat/ads/internal/unittest_util.h" + +// npm run test -- brave_unit_tests --filter=BatAds* + +namespace ads { + +class BatAdsFullScreenModeFrequencyCapTest : public UnitTestBase { + protected: + BatAdsFullScreenModeFrequencyCapTest() = default; + + ~BatAdsFullScreenModeFrequencyCapTest() override = default; +}; + +TEST_F(BatAdsFullScreenModeFrequencyCapTest, AllowAd) { + // Arrange + MockIsFullScreen(ads_client_mock_, false); + + // Act + FullScreenModeFrequencyCap frequency_cap; + const bool is_allowed = frequency_cap.ShouldAllow(); + + // Assert + EXPECT_TRUE(is_allowed); +} + +TEST_F(BatAdsFullScreenModeFrequencyCapTest, AlwaysAllowAdForAndroid) { + // Arrange + MockPlatformHelper(platform_helper_mock_, PlatformType::kAndroid); + + MockIsFullScreen(ads_client_mock_, true); + + // Act + FullScreenModeFrequencyCap frequency_cap; + const bool is_allowed = frequency_cap.ShouldAllow(); + + // Assert + EXPECT_TRUE(is_allowed); +} + +TEST_F(BatAdsFullScreenModeFrequencyCapTest, AlwaysAllowAdForIOS) { + // Arrange + MockPlatformHelper(platform_helper_mock_, PlatformType::kIOS); + + MockIsFullScreen(ads_client_mock_, true); + + // Act + FullScreenModeFrequencyCap frequency_cap; + const bool is_allowed = frequency_cap.ShouldAllow(); + + // Assert + EXPECT_TRUE(is_allowed); +} + +TEST_F(BatAdsFullScreenModeFrequencyCapTest, DoNotAllowAd) { + // Arrange + MockIsFullScreen(ads_client_mock_, true); + + // Act + FullScreenModeFrequencyCap frequency_cap; + const bool is_allowed = frequency_cap.ShouldAllow(); + + // Assert + EXPECT_FALSE(is_allowed); +} + +} // namespace ads diff --git a/vendor/bat-native-ads/src/bat/ads/internal/unittest_base.cc b/vendor/bat-native-ads/src/bat/ads/internal/unittest_base.cc index 68f54488bcb5..7f5f12afe11a 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/unittest_base.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/unittest_base.cc @@ -120,6 +120,8 @@ void UnitTestBase::Initialize() { MockIsForeground(ads_client_mock_, true); + MockIsFullScreen(ads_client_mock_, false); + MockShouldShowNotifications(ads_client_mock_, true); MockShowNotification(ads_client_mock_); MockCloseNotification(ads_client_mock_); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.cc b/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.cc index 07c631aa1533..fb9bdd8723bc 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.cc @@ -532,6 +532,11 @@ void MockIsForeground(const std::unique_ptr& mock, ON_CALL(*mock, IsForeground()).WillByDefault(Return(is_foreground)); } +void MockIsFullScreen(const std::unique_ptr& mock, + const bool is_full_screen) { + ON_CALL(*mock, IsFullScreen()).WillByDefault(Return(is_full_screen)); +} + void MockShouldShowNotifications(const std::unique_ptr& mock, const bool should_show) { ON_CALL(*mock, ShouldShowNotifications()).WillByDefault(Return(should_show)); diff --git a/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.h b/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.h index 4c5560dd0d2c..d45820af181c 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/unittest_util.h @@ -105,6 +105,9 @@ void MockIsNetworkConnectionAvailable( void MockIsForeground(const std::unique_ptr& mock, const bool is_foreground); +void MockIsFullScreen(const std::unique_ptr& mock, + const bool is_full_screen); + void MockShouldShowNotifications(const std::unique_ptr& mock, const bool should_show); diff --git a/vendor/brave-ios/Ads/BATBraveAds.mm b/vendor/brave-ios/Ads/BATBraveAds.mm index 9262fa90fac0..00bc32c288e4 100644 --- a/vendor/brave-ios/Ads/BATBraveAds.mm +++ b/vendor/brave-ios/Ads/BATBraveAds.mm @@ -612,6 +612,10 @@ - (bool)isForeground return UIApplication.sharedApplication.applicationState == UIApplicationStateActive; } +- (bool)isFullScreen { + return true; +} + - (bool)canShowBackgroundNotifications { return false; diff --git a/vendor/brave-ios/Ads/Generated/NativeAdsClient.h b/vendor/brave-ios/Ads/Generated/NativeAdsClient.h index 8a0e8218182b..3509115f350d 100644 --- a/vendor/brave-ios/Ads/Generated/NativeAdsClient.h +++ b/vendor/brave-ios/Ads/Generated/NativeAdsClient.h @@ -19,6 +19,7 @@ class NativeAdsClient : public ads::AdsClient { bool IsNetworkConnectionAvailable() const override; bool IsForeground() const override; + bool IsFullScreen() const override; bool CanShowBackgroundNotifications() const override; void ShowNotification(const ads::AdNotificationInfo& info) override; bool ShouldShowNotifications() override; diff --git a/vendor/brave-ios/Ads/Generated/NativeAdsClient.mm b/vendor/brave-ios/Ads/Generated/NativeAdsClient.mm index d0418e3a89c3..88f423e89091 100644 --- a/vendor/brave-ios/Ads/Generated/NativeAdsClient.mm +++ b/vendor/brave-ios/Ads/Generated/NativeAdsClient.mm @@ -23,6 +23,10 @@ return [bridge_ isForeground]; } +bool NativeAdsClient::IsFullScreen() const { + return [bridge_ isFullScreen]; +} + bool NativeAdsClient::CanShowBackgroundNotifications() const { return [bridge_ canShowBackgroundNotifications]; } diff --git a/vendor/brave-ios/Ads/Generated/NativeAdsClientBridge.h b/vendor/brave-ios/Ads/Generated/NativeAdsClientBridge.h index c6d95144ae0e..6fb756d3262a 100644 --- a/vendor/brave-ios/Ads/Generated/NativeAdsClientBridge.h +++ b/vendor/brave-ios/Ads/Generated/NativeAdsClientBridge.h @@ -14,6 +14,7 @@ - (bool)isAdsEnabled; - (bool)shouldAllowAdConversionTracking; - (bool)isForeground; +- (bool)isFullScreen; - (bool)canShowBackgroundNotifications; - (bool)isNetworkConnectionAvailable; - (bool)shouldShowNotifications;