#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <stddef.h>
#include <memory>
#include <string>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_samples.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browsing_data/browsing_data_remover_browsertest_base.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/browsing_data/counters/cache_counter.h"
#include "chrome/browser/browsing_data/counters/site_data_counting_helper.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/media/clear_key_cdm_test_helper.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_reconcilor_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/browsing_data/content/browsing_data_model.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/history/core/common/pref_names.h"
#include "components/metrics/content/subprocess_metrics_provider.h"
#include "components/nacl/common/buildflags.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/features/password_manager_features_util.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_reconcilor.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync/test/test_sync_service.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/clear_site_data_utils.h"
#include "content/public/browser/network_service_util.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/storage_usage_info.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "media/base/media_switches.h"
#include "media/mojo/mojom/media_types.mojom.h"
#include "media/mojo/services/video_decode_perf_history.h"
#include "media/mojo/services/webrtc_video_perf_history.h"
#include "net/cookies/cookie_partition_key.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/features_generated.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
#if BUILDFLAG(IS_MAC)
#include "base/threading/platform_thread.h"
#endif
#include "base/memory/scoped_refptr.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/net/system_proxy_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chromeos/ash/components/dbus/system_proxy/system_proxy_client.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/startup/browser_init_params.h"
#include "components/account_manager_core/account.h"
#include "components/account_manager_core/account_manager_util.h"
#endif
BrowserThread;
BrowsingDataFilterBuilder;
UnorderedElementsAre;
UnorderedElementsAreArray;
namespace {
static const char* kExampleHost = …;
static const char* kLocalHost = …;
static const base::Time kStartTime = …;
static const base::Time kLastHourTime = …;
enum TimeEnum { … };
base::Time TimeEnumToTime(TimeEnum time) { … }
std::vector<std::string> GetHistogramSuffixes(
const base::HistogramTester& tester,
const std::string& prefix) { … }
void AppendRange(std::vector<std::string>& target,
const std::vector<std::string_view> append) { … }
}
class BrowsingDataRemoverBrowserTest
: public BrowsingDataRemoverBrowserTestBase { … };
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
class DiceBrowsingDataRemoverBrowserTest
: public BrowsingDataRemoverBrowserTest { … };
#endif
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, MediaDeviceIdSalt) { … }
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncToken) { … }
IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest,
SyncTokenScopedDeletion) { … }
IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, SyncTokenError) { … }
IN_PROC_BROWSER_TEST_F(DiceBrowsingDataRemoverBrowserTest, NoSync) { … }
#endif
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) {
PrefService* prefs = GetBrowser()->profile()->GetPrefs();
prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
DownloadAnItem();
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS);
VerifyDownloadCount(1u);
}
#endif
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, VideoDecodePerfHistory) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, WebrtcVideoPerfHistory) { … }
#if !BUILDFLAG(IS_ANDROID)
#define MAYBE_Database …
#else
#define MAYBE_Database …
#endif
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, MAYBE_Database) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Cache) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
ClearCacheAndNetworkServiceCrashes) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, VerifyNQECacheCleared) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
ExternalProtocolHandlerPerOriginPrefs) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, HistoryDeletion) { … }
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
ClearingCookiesAlsoClearsPasswordAccountStorageOptIn) { … }
IN_PROC_BROWSER_TEST_F(
BrowsingDataRemoverBrowserTest,
ClearingCookiesWithFilterAlsoClearsPasswordAccountStorageOptIn) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, ClearSiteData) { … }
#endif
class BrowsingDataRemoverStorageBucketsBrowserTest
: public BrowsingDataRemoverBrowserTest { … };
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverStorageBucketsBrowserTest,
ClearSiteDataStorageBuckets) { … }
const char kDelegateHistogramPrefix[] = …;
const char kImplHistogramPrefix[] = …;
const std::vector<std::string_view> kSupportsOriginFilteringImpl{ … };
const std::vector<std::string_view> kSupportsOriginFilteringDelegate{ … };
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, FullyFilteredDataTypes) { … }
const std::vector<std::string_view> kDoesNotSupportOriginFilteringImpl{ … };
const std::vector<std::string_view> kDoesNotSupportOriginFilteringDelegate{ … };
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, AllFilterableDataTypes) { … }
class BrowsingDataRemoverBrowserTestP
: public BrowsingDataRemoverBrowserTest,
public testing::WithParamInterface<TimeEnum> { … };
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, CookieDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
CookieIncognitoDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
BrowserContextDestructionVsCookieRemoval) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, SessionCookieDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, LocalStorageDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
LocalStorageIncognitoDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
DISABLED_SessionStorageDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
SessionStorageDeletionWebOnly) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, SessionStorageCounting) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, ServiceWorkerDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
ServiceWorkerIncognitoDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, CacheStorageDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
CacheStorageIncognitoDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, FileSystemDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
FileSystemIncognitoDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
EmptyFileSystemDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
EmptyFileSystemIncognitoDeletion) { … }
#if !BUILDFLAG(IS_ANDROID)
#define MAYBE_WebSqlDeletion …
#else
#define MAYBE_WebSqlDeletion …
#endif
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, MAYBE_WebSqlDeletion) { … }
#if !BUILDFLAG(IS_ANDROID)
#define MAYBE_WebSqlIncognitoDeletion …
#else
#define MAYBE_WebSqlIncognitoDeletion …
#endif
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
MAYBE_WebSqlIncognitoDeletion) { … }
#if !BUILDFLAG(IS_ANDROID)
#define MAYBE_EmptyWebSqlDeletion …
#else
#define MAYBE_EmptyWebSqlDeletion …
#endif
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
MAYBE_EmptyWebSqlDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, IndexedDbDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP,
IndexedDbIncognitoDeletion) { … }
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, EmptyIndexedDb) { … }
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
IN_PROC_BROWSER_TEST_P(BrowsingDataRemoverBrowserTestP, MediaLicenseDeletion) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
PRE_MediaLicenseTimedDeletion) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
MediaLicenseTimedDeletion) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
MediaLicenseDeletionWithFilter) { … }
#endif
const std::vector<std::string> kStorageTypes{ … };
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
PRE_PRE_StorageRemovedFromDisk) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
PRE_StorageRemovedFromDisk) { … }
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, StorageRemovedFromDisk) { … }
const std::vector<std::string> kSessionOnlyStorageTestTypes{ … };
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
PRE_SessionOnlyStorageRemoved) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_SessionOnlyStorageRemoved …
#else
#define MAYBE_SessionOnlyStorageRemoved …
#endif
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
MAYBE_SessionOnlyStorageRemoved) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
SystemProxyClearsUserCredentials) {
ash::SystemProxyManager::Get()->SetSystemProxyEnabledForTest(true);
EXPECT_EQ(0, ash::SystemProxyClient::Get()
->GetTestInterface()
->GetClearUserCredentialsCount());
RemoveAndWait(chrome_browsing_data_remover::DATA_TYPE_PASSWORDS);
EXPECT_EQ(1, ash::SystemProxyClient::Get()
->GetTestInterface()
->GetClearUserCredentialsCount());
}
#endif
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
RelatedWebsiteSetsDeletion) { … }
INSTANTIATE_TEST_SUITE_P(…);