Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Sep 22, 2024
1 parent 4d33a3c commit 4802e77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 3 additions & 7 deletions browser/brave_rewards/rewards_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,19 @@ KeyedService* RewardsServiceFactory::BuildServiceInstanceFor(
notification_observer =
std::make_unique<ExtensionRewardsNotificationServiceObserver>(profile);
#endif
auto* brave_wallet_service =
brave_wallet::BraveWalletServiceFactory::GetServiceForContext(context);
auto* storage_partition = profile->GetDefaultStoragePartition();
auto* bitmap_fetcher_service =
BitmapFetcherServiceFactory::GetForBrowserContext(profile);
// Set up the rewards data source
content::URLDataSource::Add(profile,
std::make_unique<BraveRewardsSource>(profile));
std::unique_ptr<RewardsServiceImpl> rewards_service(new RewardsServiceImpl(
profile->GetPrefs(), profile->GetPath(),
FaviconServiceFactory::GetForProfile(profile,
ServiceAccessType::EXPLICIT_ACCESS),
bitmap_fetcher_service, storage_partition,
BitmapFetcherServiceFactory::GetForBrowserContext(profile),
profile->GetDefaultStoragePartition(),
#if BUILDFLAG(ENABLE_GREASELION)
greaselion::GreaselionServiceFactory::GetForBrowserContext(context),
#endif
brave_wallet_service));
brave_wallet::BraveWalletServiceFactory::GetServiceForContext(context)));
rewards_service->Init(std::move(extension_observer),
std::move(notification_observer));
return rewards_service.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <tuple>
#include <vector>

#include "brave/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

// clang-format off
// npm run test -- brave_unit_tests --filter="*RewardsProtocolNavigationThrottleTest*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@
* 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 <map>

#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/components/brave_rewards/browser/rewards_service_impl.h"
#include "brave/components/brave_rewards/browser/rewards_service_observer.h"
#include "brave/components/brave_rewards/browser/test_util.h"
#include "brave/components/brave_rewards/common/features.h"
#include "brave/components/brave_rewards/common/mojom/rewards.mojom.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/brave_rewards/common/rewards_flags.h"
#include "brave/components/brave_rewards/core/global_constants.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/l10n/common/test/scoped_default_locale.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/prefs/pref_service.h"
Expand All @@ -46,12 +41,16 @@ class RewardsServiceJPTest : public testing::Test {
std::make_unique<brave_l10n::test::ScopedDefaultLocale>("ja_JP");
profile_ = CreateBraveRewardsProfile(temp_dir_.GetPath());
ASSERT_TRUE(profile_);
rewards_service_ = std::make_unique<RewardsServiceImpl>(
profile()->GetPrefs(), profile()->GetPath(),
FaviconServiceFactory::GetForProfile(
profile(), ServiceAccessType::EXPLICIT_ACCESS),
BitmapFetcherServiceFactory::GetForBrowserContext(profile()),
profile()->GetDefaultStoragePartition(),
#if BUILDFLAG(ENABLE_GREASELION)
rewards_service_ =
std::make_unique<RewardsServiceImpl>(profile(), nullptr, nullptr);
#else
rewards_service_ = std::make_unique<RewardsServiceImpl>(profile(), nullptr);
nullptr,
#endif
nullptr);
ASSERT_TRUE(rewards_service());

profile()->GetPrefs()->SetString(prefs::kDeclaredGeo, "JP");
Expand Down
21 changes: 13 additions & 8 deletions components/brave_rewards/browser/rewards_service_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
* 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 <map>
#include "brave/components/brave_rewards/browser/rewards_service_impl.h"

#include <memory>

#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/components/brave_rewards/browser/rewards_service_impl.h"
#include "brave/components/brave_rewards/browser/rewards_service_observer.h"
#include "brave/components/brave_rewards/browser/test_util.h"
#include "brave/components/brave_rewards/common/features.h"
Expand All @@ -20,6 +18,8 @@
#include "brave/components/brave_rewards/core/global_constants.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/l10n/common/test/scoped_default_locale.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/prefs/pref_service.h"
Expand Down Expand Up @@ -67,12 +67,17 @@ class RewardsServiceTest : public testing::Test {
std::make_unique<brave_l10n::test::ScopedDefaultLocale>("en_US");
profile_ = CreateBraveRewardsProfile(temp_dir_.GetPath());
ASSERT_TRUE(profile_.get());

rewards_service_ = std::make_unique<RewardsServiceImpl>(
profile()->GetPrefs(), profile()->GetPath(),
FaviconServiceFactory::GetForProfile(
profile(), ServiceAccessType::EXPLICIT_ACCESS),
BitmapFetcherServiceFactory::GetForBrowserContext(profile()),
profile()->GetDefaultStoragePartition(),
#if BUILDFLAG(ENABLE_GREASELION)
rewards_service_ =
std::make_unique<RewardsServiceImpl>(profile(), nullptr, nullptr);
#else
rewards_service_ = std::make_unique<RewardsServiceImpl>(profile(), nullptr);
nullptr,
#endif
nullptr);
ASSERT_TRUE(rewards_service());
observer_ = std::make_unique<MockRewardsServiceObserver>();
rewards_service_->AddObserver(observer_.get());
Expand Down

0 comments on commit 4802e77

Please sign in to comment.