-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
129 changed files
with
1,989 additions
and
1,973 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
37 changes: 37 additions & 0 deletions
37
...nents/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.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,37 @@ | ||
/* Copyright (c) 2025 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.h" | ||
|
||
#include "base/containers/fixed_flat_map.h" | ||
#include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" | ||
|
||
namespace brave_ads { | ||
|
||
namespace { | ||
|
||
constexpr auto kNewTabPageAdEventTypeMap = | ||
base::MakeFixedFlatMap<std::string, mojom::NewTabPageAdEventType>({ | ||
{"served", mojom::NewTabPageAdEventType::kServedImpression}, | ||
{"view", mojom::NewTabPageAdEventType::kViewedImpression}, | ||
{"click", mojom::NewTabPageAdEventType::kClicked}, | ||
{"media_play", mojom::NewTabPageAdEventType::kMediaPlay}, | ||
{"media_25", mojom::NewTabPageAdEventType::kMedia25}, | ||
{"media_100", brave_ads::mojom::NewTabPageAdEventType::kMedia100}, | ||
}); | ||
|
||
} // namespace | ||
|
||
std::optional<brave_ads::mojom::NewTabPageAdEventType> | ||
ToMojomNewTabPageAdEventType(const std::string& event_type) { | ||
const auto iter = kNewTabPageAdEventTypeMap.find(event_type); | ||
if (iter == kNewTabPageAdEventTypeMap.cend()) { | ||
return std::nullopt; | ||
} | ||
|
||
return iter->second; | ||
} | ||
|
||
} // namespace brave_ads |
40 changes: 40 additions & 0 deletions
40
...ve_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util_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,40 @@ | ||
/* Copyright (c) 2025 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_event_type_util.h" | ||
|
||
#include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
// npm run test -- brave_unit_tests --filter=BraveAds* | ||
|
||
namespace brave_ads { | ||
|
||
TEST(BraveAdsNewTabPageAdEventTypeUtilTest, ToMojomNewTabPageAdEventType) { | ||
// Act & Assert | ||
EXPECT_EQ(ToMojomNewTabPageAdEventType("served"), | ||
mojom::NewTabPageAdEventType::kServedImpression); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType("view"), | ||
mojom::NewTabPageAdEventType::kViewedImpression); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType("click"), | ||
mojom::NewTabPageAdEventType::kClicked); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType("media_play"), | ||
mojom::NewTabPageAdEventType::kMediaPlay); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType("media_25"), | ||
mojom::NewTabPageAdEventType::kMedia25); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType("media_100"), | ||
mojom::NewTabPageAdEventType::kMedia100); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType(""), std::nullopt); | ||
|
||
EXPECT_EQ(ToMojomNewTabPageAdEventType("foobar"), std::nullopt); | ||
} | ||
|
||
} // namespace brave_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
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.