Skip to content

Commit

Permalink
Add Web Discovery factory test for OTR profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
DJAndries committed Jul 4, 2024
1 parent af6779c commit 0a15ebe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions browser/web_discovery/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ source_set("unit_tests") {
testonly = true

sources = [ "web_discovery_unittest.cc" ]

deps = [
"//brave/browser/profiles",
"//brave/components/constants",
Expand All @@ -44,6 +45,14 @@ source_set("unit_tests") {
"//content/test:test_support",
"//testing/gtest",
]

if (enable_web_discovery_native) {
sources += [ "wdp_service_factory_unittest.cc" ]
deps += [
":web_discovery",
"//brave/components/web_discovery/common",
]
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions browser/web_discovery/wdp_service_factory_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2024 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/browser/web_discovery/wdp_service_factory.h"

#include "base/test/scoped_feature_list.h"
#include "brave/components/web_discovery/common/features.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace web_discovery {

TEST(WDPServiceFactoryTest, PrivateNotCreated) {
content::BrowserTaskEnvironment task_environment;
base::test::ScopedFeatureList scoped_features(features::kWebDiscoveryNative);
auto* browser_process = TestingBrowserProcess::GetGlobal();
TestingProfileManager profile_manager(browser_process);
ASSERT_TRUE(profile_manager.SetUp());

auto* profile = profile_manager.CreateTestingProfile("test");

EXPECT_TRUE(WDPServiceFactory::GetForBrowserContext(profile));
EXPECT_FALSE(
WDPServiceFactory::GetForBrowserContext(profile->GetOffTheRecordProfile(
Profile::OTRProfileID::CreateUniqueForTesting(), true)));
}

} // namespace web_discovery

0 comments on commit 0a15ebe

Please sign in to comment.