-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple AdsServiceImpl full screen mode business logic
- Loading branch information
Showing
26 changed files
with
221 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
37 changes: 37 additions & 0 deletions
37
.../src/bat/ads/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <string> | ||
|
||
#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_ |
74 changes: 74 additions & 0 deletions
74
...ds/internal/frequency_capping/permission_rules/full_screen_mode_frequency_cap_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.