#include <memory>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "chrome/browser/background_fetch/background_fetch_delegate_impl.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/download/background_download_service_factory.h"
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/offline_items_collection/offline_content_aggregator_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/background_fetch/job_details.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/download/public/background_service/background_download_service.h"
#include "components/download/public/background_service/logger.h"
#include "components/offline_items_collection/core/offline_content_aggregator.h"
#include "components/offline_items_collection/core/offline_content_provider.h"
#include "components/offline_items_collection/core/offline_item.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.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/fenced_frame_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "url/origin.h"
ContentId;
OfflineContentProvider;
GetVisualsOptions;
OfflineItem;
OfflineItemFilter;
OfflineItemProgressUnit;
OfflineItemVisuals;
namespace {
BasicHttpResponse;
HttpRequest;
HttpResponse;
const char kHelperPage[] = …;
const char kBackgroundFetchClient[] = …;
const char kResultAccepted[] = …;
const char kSingleFileDownloadTitle[] = …;
const int kDownloadedResourceSizeInBytes = …;
const int kDownloadTotalBytesTooHigh = …;
const int kDownloadTotalBytesTooLow = …;
const int kNumRequestsInFetch = …;
const int kNumIconsInFetch = …;
const double kUkmEventDataBucketSpacing = …;
class WaitableDownloadLoggerObserver : public download::Logger::Observer { … };
class OfflineContentProviderObserver final
: public OfflineContentProvider::Observer { … };
}
class BackgroundFetchBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest, DownloadService_Acceptance) { … }
#if BUILDFLAG(IS_LINUX)
#define MAYBE_RecordBackgroundFetchUkmEvent …
#else
#define MAYBE_RecordBackgroundFetchUkmEvent …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
MAYBE_RecordBackgroundFetchUkmEvent) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_OfflineItemCollection_SingleFileMetadata …
#else
#define MAYBE_OfflineItemCollection_SingleFileMetadata …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
MAYBE_OfflineItemCollection_SingleFileMetadata) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
DISABLED_OfflineItemCollection_VerifyIconReceived) { … }
IN_PROC_BROWSER_TEST_F(
BackgroundFetchBrowserTest,
DISABLED_OfflineItemCollection_VerifyResourceDownloadedWhenDownloadTotalLargerThanActualSize) { … }
IN_PROC_BROWSER_TEST_F(
BackgroundFetchBrowserTest,
DISABLED_OfflineItemCollection_VerifyResourceDownloadedWhenDownloadTotalSmallerThanActualSize) { … }
IN_PROC_BROWSER_TEST_F(
BackgroundFetchBrowserTest,
DISABLED_OfflineItemCollection_VerifyResourceDownloadedWhenCorrectDownloadTotalSpecified) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
OfflineItemCollection_IncognitoPropagated) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
FetchesRunToCompletionAndUpdateTitle_Fetched) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
FetchesRunToCompletionAndUpdateTitle_Failed) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
FetchesRunToCompletion_Upload) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest, ClickEventIsDispatched) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest, DISABLED_AbortFromUI) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest, FetchCanBePausedAndResumed) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
FetchRejectedWithoutPermission) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest, FetchFromServiceWorker) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
DISABLED_FetchFromServiceWorkerWithAsk) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
DISABLED_FetchFromChildFrameWithPermissions) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
DISABLED_FetchFromChildFrameWithAsk) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchBrowserTest,
FetchFromChildFrameWithMissingPermissions) { … }
class BackgroundFetchFencedFrameBrowserTest
: public BackgroundFetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(BackgroundFetchFencedFrameBrowserTest,
NoRecordBackgroundFetchUkmEvent) { … }
IN_PROC_BROWSER_TEST_F(BackgroundFetchFencedFrameBrowserTest,
NoRecordBackgroundFetchUkmEventNotInSameOrigin) { … }