Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrevert unified adblock catalog #21556

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/android_browser_tests.gni
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ android_test_exception_sources = [
"//brave/components/brave_rewards/browser/test/rewards_promotion_browsertest.cc",
"//brave/components/brave_rewards/browser/test/rewards_publisher_browsertest.cc",
"//brave/components/brave_rewards/browser/test/rewards_state_browsertest.cc",
"//brave/components/brave_shields/browser/test_filters_provider.cc",
"//brave/components/content_settings/renderer/brave_content_settings_agent_impl_browsertest.cc",
"//brave/third_party/blink/renderer/modules/brave/navigator_browsertest.cc",
"//chrome/browser/extensions/browsertest_util.cc",
Expand Down Expand Up @@ -116,6 +115,7 @@ android_test_exception_deps = [
"//brave/browser/ui:browser_tests",
"//brave/browser/ui/tabs/test:browser_tests",
"//brave/browser/ui/views/tabs:browser_tests",
"//brave/components/brave_shields/browser:test_support",
"//brave/components/brave_wallet/resources:ethereum_provider_generated_resources",
"//brave/components/de_amp/browser/test:browser_tests",
"//brave/renderer/skus:browser_tests",
Expand Down
1 change: 0 additions & 1 deletion browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_referrals/browser/brave_referrals_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/browser/brave_farbling_service.h"
Expand Down
376 changes: 211 additions & 165 deletions browser/brave_shields/ad_block_service_browsertest.cc

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions browser/brave_shields/ad_block_service_browsertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class AdBlockServiceTest : public extensions::ExtensionBrowserTest {

HostContentSettingsMap* content_settings();
void UpdateAdBlockInstanceWithRules(const std::string& rules,
const std::string& resources = "[]");
const std::string& resources = "[]",
uint8_t permission_mask = 0);
void UpdateAdBlockInstanceWithDAT(const base::FilePath& dat_location,
const std::string& resources = "[]");
void UpdateCustomAdBlockInstanceWithRules(
Expand All @@ -51,9 +52,9 @@ class AdBlockServiceTest : public extensions::ExtensionBrowserTest {
void GetTestDataDir(base::FilePath* test_data_dir);
void SetDefaultComponentIdAndBase64PublicKeyForTest();
void SetRegionalComponentIdAndBase64PublicKeyForTest();
bool InstallDefaultAdBlockExtension(
bool InstallDefaultAdBlockComponent(
const std::string& extension_dir = "adblock-default");
bool InstallRegionalAdBlockExtension(const std::string& uuid,
bool InstallRegionalAdBlockComponent(const std::string& uuid,
bool enable_list = true);
void SetSubscriptionIntervals();
void WaitForAdBlockServiceThreads();
Expand Down
26 changes: 13 additions & 13 deletions browser/brave_shields/domain_block_page_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DomainBlockDisabledTest : public DomainBlockTestBase {
};

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -121,7 +121,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitial) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndProceed) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -145,7 +145,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndProceed) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndReload) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -166,7 +166,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndReload) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedAndReload) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -199,7 +199,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedAndReload) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectNewTabs) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -233,7 +233,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectNewTabs) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, DontWarnAgainAndProceed) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -274,7 +274,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, DontWarnAgainAndProceed) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndGoBack) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
url_a);
Expand All @@ -300,7 +300,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndGoBack) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoFetch) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
ASSERT_EQ(0, request_count_);
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);
Expand All @@ -319,7 +319,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoFetch) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoThirdPartyInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
ASSERT_TRUE(g_brave_browser_process->ad_block_service()
->custom_filters_provider()
->UpdateCustomFilters("||b.com^$third-party"));
Expand Down Expand Up @@ -354,7 +354,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoThirdPartyInterstitial) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoInterstitialUnlessAggressive) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -387,7 +387,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoInterstitialUnlessAggressive) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockDisabledTest, NoInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -409,7 +409,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockDisabledTest, NoInterstitial) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectOtherDomains) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
url_a);
Expand Down Expand Up @@ -450,7 +450,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectOtherDomains) {

IN_PROC_BROWSER_TEST_F(DomainBlockTest,
DontWarnAgainDoesNotAffectOtherDomains) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
url_a);
Expand Down
32 changes: 7 additions & 25 deletions browser/debounce/debounce_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,28 @@

#include "base/base64url.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/thread_test_helper.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/browser/extensions/brave_base_local_data_files_browsertest.h"
#include "brave/components/brave_shields/browser/ad_block_component_filters_provider.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/engine_test_observer.h"
#include "brave/components/brave_shields/browser/test_filters_provider.h"
#include "brave/components/constants/brave_paths.h"
#include "brave/components/debounce/browser/debounce_component_installer.h"
#include "brave/components/debounce/common/features.h"
#include "brave/components/debounce/common/pref_names.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/content_client.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "net/base/url_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h"

namespace {
Expand Down Expand Up @@ -181,27 +174,16 @@ class DebounceBrowserTest : public BaseLocalDataFilesBrowserTest {
EXPECT_EQ(web_contents()->GetLastCommittedURL(), landing_url);
}

bool InstallAdBlockForDebounce() {
base::FilePath test_data_dir;
GetTestDataDir(&test_data_dir);
const extensions::Extension* ad_block_extension =
InstallExtension(test_data_dir.AppendASCII("adblock-data")
.AppendASCII("adblock-default"),
1);
if (!ad_block_extension) {
return false;
}
g_brave_browser_process->ad_block_service()
->default_filters_provider()
->OnComponentReady(ad_block_extension->path());
void InitAdBlockForDebounce() {
auto source_provider = std::make_unique<brave_shields::TestFiltersProvider>(
"||blocked.com^", "[]");
g_brave_browser_process->ad_block_service()->UseSourceProvidersForTest(
source_provider.get(), source_provider.get());
source_providers_.push_back(std::move(source_provider));
scoped_refptr<base::ThreadTestHelper> tr_helper(new base::ThreadTestHelper(
g_brave_browser_process->ad_block_service()->GetTaskRunner()));
return tr_helper->Run();
auto* engine =
g_brave_browser_process->ad_block_service()->default_engine_.get();
EngineTestObserver engine_observer(engine);
engine_observer.Wait();
}

private:
Expand Down Expand Up @@ -439,7 +421,7 @@ IN_PROC_BROWSER_TEST_F(DebounceBrowserTest, DebounceBeforeDomainBlock) {
// Install adblock, turn on aggressive blocking for this URL, then attempt to
// navigate to it. This should be interrupted by the domain block
// interstitial.
ASSERT_TRUE(InstallAdBlockForDebounce());
InitAdBlockForDebounce();
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
original_url);
NavigateTo(original_url);
Expand Down
1 change: 1 addition & 0 deletions browser/ephemeral_storage/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ source_set("browser_tests") {
"//brave/browser",
"//brave/components/brave_component_updater/browser",
"//brave/components/brave_shields/browser",
"//brave/components/brave_shields/browser:test_support",
"//brave/components/brave_shields/common",
"//brave/components/ephemeral_storage",
"//chrome/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/engine_test_observer.h"
#include "brave/components/brave_shields/browser/test_filters_provider.h"
#include "brave/components/brave_shields/common/features.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
Expand Down Expand Up @@ -48,7 +49,11 @@ class EphemeralStorage1pDomainBlockBrowserTest
g_brave_browser_process->ad_block_service();
ad_block_service->UseSourceProvidersForTest(source_provider_.get(),
source_provider_.get());
WaitForAdBlockServiceThreads();

auto* engine =
g_brave_browser_process->ad_block_service()->default_engine_.get();
EngineTestObserver engine_observer(engine);
engine_observer.Wait();
}

void WaitForAdBlockServiceThreads() {
Expand Down
1 change: 1 addition & 0 deletions browser/net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ source_set("unit_tests") {
"//brave/components/brave_rewards/common",
"//brave/components/brave_rewards/common:features",
"//brave/components/brave_shields/browser",
"//brave/components/brave_shields/browser:test_support",
"//brave/components/l10n/common:test_support",
"//chrome/test:test_support",
"//content/test:test_support",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class BraveAdBlockTPNetworkDelegateHelperTest : public testing::Test {
filters_provider_ = std::make_unique<TestFiltersProvider>(rules, resources);
g_brave_browser_process->ad_block_service()->UseSourceProvidersForTest(
filters_provider_.get(), filters_provider_.get());
task_environment_.RunUntilIdle();
}

// Returns true if the request handler deferred control back to the calling
Expand Down
14 changes: 7 additions & 7 deletions browser/perf/brave_perf_features_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "brave/components/brave_ads/core/public/prefs/pref_names.h"
#include "brave/components/brave_news/common/pref_names.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -33,19 +33,19 @@ void EnableAdblockCookieList(base::WeakPtr<Profile> profile) {
}

// Obtrusive cookie notices list in cosmetic filters.
auto* regional_service_manager =
g_brave_browser_process->ad_block_service()->regional_service_manager();
if (!regional_service_manager ||
!regional_service_manager->IsFilterListAvailable(
auto* component_service_manager =
g_brave_browser_process->ad_block_service()->component_service_manager();
if (!component_service_manager ||
!component_service_manager->IsFilterListAvailable(
brave_shields::kCookieListUuid)) {
base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, base::BindOnce(&EnableAdblockCookieList, profile),
base::Seconds(1));
return;
}

regional_service_manager->EnableFilterList(brave_shields::kCookieListUuid,
true);
component_service_manager->EnableFilterList(brave_shields::kCookieListUuid,
true);
}

} // namespace
Expand Down
1 change: 1 addition & 0 deletions browser/permissions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (!is_android) {
"//brave/browser/brave_wallet",
"//brave/components/brave_component_updater/browser:browser",
"//brave/components/brave_shields/browser:browser",
"//brave/components/brave_shields/browser:test_support",
"//brave/components/brave_shields/common",
"//brave/components/brave_wallet/browser",
"//brave/components/brave_wallet/browser:permission_utils",
Expand Down
18 changes: 9 additions & 9 deletions browser/ui/views/brave_shields/cookie_list_opt_in_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/perf/brave_perf_switches.h"
#include "brave/browser/ui/views/brave_shields/cookie_list_opt_in_bubble_host.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/filter_list_catalog_entry.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
Expand All @@ -38,13 +38,13 @@ namespace brave_shields {

namespace {

auto* GetRegionalServiceManager() {
auto* GetComponentServiceManager() {
return g_brave_browser_process->ad_block_service()
->regional_service_manager();
->component_service_manager();
}

bool IsCookieListFilterEnabled() {
return GetRegionalServiceManager()->IsFilterListEnabled(kCookieListUuid);
return GetComponentServiceManager()->IsFilterListEnabled(kCookieListUuid);
}

class CookieListFilterEnabledObserver {
Expand Down Expand Up @@ -127,10 +127,10 @@ class CookieListOptInBrowserTest : public InProcessBrowserTest {
kCookieListUuid,
"https://secure.fanboy.co.nz/fanboy-cookiemonster_ubo.txt",
"Easylist-Cookie List - Filter Obtrusive Cookie Notices", {},
"https://forums.lanik.us/", kRegionalAdBlockComponentTestId,
kRegionalAdBlockComponentTest64PublicKey,
"Removes obtrusive cookie law notices")};
GetRegionalServiceManager()->SetFilterListCatalog(filter_list_catalog);
"https://forums.lanik.us/", "Removes obtrusive cookie law notices",
false, false, false, 0, {}, kRegionalAdBlockComponentTestId,
kRegionalAdBlockComponentTest64PublicKey)};
GetComponentServiceManager()->SetFilterListCatalog(filter_list_catalog);
}

base::test::ScopedFeatureList scoped_feature_list_;
Expand Down Expand Up @@ -248,7 +248,7 @@ class CookieListOptInPreEnabledBrowserTest : public CookieListOptInBrowserTest {
void SetUpLocalState() override {
CookieListOptInBrowserTest::SetUpLocalState();

GetRegionalServiceManager()->EnableFilterList(kCookieListUuid, true);
GetComponentServiceManager()->EnableFilterList(kCookieListUuid, true);

// Since `AdBlockRegionalServiceManager::EnableFilterList` modifies local
// state asynchronously in a posted task, waiting for the update to complete
Expand Down
Loading
Loading