#include "content/browser/background_fetch/background_fetch_data_manager.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/barrier_closure.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/uuid.h"
#include "content/browser/background_fetch/background_fetch.pb.h"
#include "content/browser/background_fetch/background_fetch_data_manager_observer.h"
#include "content/browser/background_fetch/background_fetch_request_info.h"
#include "content/browser/background_fetch/background_fetch_request_match_params.h"
#include "content/browser/background_fetch/background_fetch_test_base.h"
#include "content/browser/background_fetch/background_fetch_test_data_manager.h"
#include "content/browser/background_fetch/storage/database_helpers.h"
#include "content/browser/background_fetch/storage/image_helpers.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/common/background_fetch/background_fetch_types.h"
#include "content/common/fetch/fetch_api_request_proto.h"
#include "content/public/browser/background_fetch_response.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_impl.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/test/blob_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/background_fetch/background_fetch.mojom.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "url/origin.h"
namespace content {
namespace {
BackgroundFetchInitializationData;
_;
UnorderedElementsAre;
IsEmpty;
const char kUserDataPrefix[] = …;
const char kExampleDeveloperId[] = …;
const char kAlternativeDeveloperId[] = …;
const char kExampleUniqueId[] = …;
const char kAlternativeUniqueId[] = …;
const char kInitialTitle[] = …;
constexpr size_t kResponseSize = …;
void DidGetInitializationData(
base::OnceClosure quit_closure,
std::vector<BackgroundFetchInitializationData>* out_result,
blink::mojom::BackgroundFetchError error,
std::vector<BackgroundFetchInitializationData> result) { … }
void DidCreateRegistration(
base::OnceClosure quit_closure,
blink::mojom::BackgroundFetchError* out_error,
blink::mojom::BackgroundFetchError error,
blink::mojom::BackgroundFetchRegistrationDataPtr registration) { … }
void DidGetError(base::OnceClosure quit_closure,
blink::mojom::BackgroundFetchError* out_error,
blink::mojom::BackgroundFetchError error) { … }
void DidGetRegistrationUserDataByKeyPrefix(
base::OnceClosure quit_closure,
std::vector<std::string>* out_data,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) { … }
void DidStoreUserData(base::OnceClosure quit_closure,
blink::ServiceWorkerStatusCode status) { … }
void GetNumUserData(base::OnceClosure quit_closure,
size_t* out_size,
const std::vector<std::string>& data,
blink::ServiceWorkerStatusCode status) { … }
struct ResponseStateStats { … };
bool operator==(const ResponseStateStats& s1, const ResponseStateStats& s2) { … }
std::vector<blink::mojom::FetchAPIRequestPtr> CreateValidRequests(
const url::Origin& origin,
size_t num_requests = 1u) { … }
blink::mojom::FetchAPIRequestPtr CreateValidRequestWithMethod(
const url::Origin& origin,
const std::string& method) { … }
SkBitmap CreateTestIcon(int size = 42, SkColor color = SK_ColorGREEN) { … }
void ExpectIconProperties(const SkBitmap& icon, int size, SkColor color) { … }
std::vector<blink::mojom::FetchAPIRequestPtr> CloneRequestVector(
const std::vector<blink::mojom::FetchAPIRequestPtr>& requests) { … }
}
class BackgroundFetchDataManagerTest
: public BackgroundFetchTestBase,
public BackgroundFetchDataManagerObserver { … };
TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) { … }
TEST_F(BackgroundFetchDataManagerTest, ExceedingQuotaFailsCreation) { … }
TEST_F(BackgroundFetchDataManagerTest, RegistrationLimitIsEnforced) { … }
TEST_F(BackgroundFetchDataManagerTest, GetDeveloperIds) { … }
TEST_F(BackgroundFetchDataManagerTest, StorageVersionIsPersisted) { … }
TEST_F(BackgroundFetchDataManagerTest, GetRegistration) { … }
TEST_F(BackgroundFetchDataManagerTest, GetMetadata) { … }
TEST_F(BackgroundFetchDataManagerTest, RegistrationUploadInfo) { … }
TEST_F(BackgroundFetchDataManagerTest, LargeIconNotPersisted) { … }
TEST_F(BackgroundFetchDataManagerTest, CreateAndDeleteRegistration) { … }
TEST_F(BackgroundFetchDataManagerTest, MarkRegistrationForDeletion) { … }
TEST_F(BackgroundFetchDataManagerTest,
MarkRegistrationForDeletionFailureReason) { … }
TEST_F(BackgroundFetchDataManagerTest, PopNextRequestAndMarkAsComplete) { … }
TEST_F(BackgroundFetchDataManagerTest, GetUploadBody) { … }
TEST_F(BackgroundFetchDataManagerTest, RegistrationBytesUpdated) { … }
TEST_F(BackgroundFetchDataManagerTest, ExceedingQuotaIsReported) { … }
TEST_F(BackgroundFetchDataManagerTest, WriteToCache) { … }
TEST_F(BackgroundFetchDataManagerTest, CacheDeleted) { … }
TEST_F(BackgroundFetchDataManagerTest, MatchRequests) { … }
TEST_F(BackgroundFetchDataManagerTest, MatchRequestsWithBody) { … }
TEST_F(BackgroundFetchDataManagerTest, MatchRequestsFromCache) { … }
TEST_F(BackgroundFetchDataManagerTest, MatchRequestsForASpecificRequest) { … }
TEST_F(BackgroundFetchDataManagerTest, MatchRequestsForAnIncompleteRequest) { … }
TEST_F(BackgroundFetchDataManagerTest, IgnoreMethodAndMatchAll) { … }
TEST_F(BackgroundFetchDataManagerTest, MatchRequestsWithDuplicates) { … }
TEST_F(BackgroundFetchDataManagerTest, Cleanup) { … }
TEST_F(BackgroundFetchDataManagerTest, GetInitializationData) { … }
TEST_F(BackgroundFetchDataManagerTest, CreateInParallel) { … }
TEST_F(BackgroundFetchDataManagerTest, StorageErrorsReported) { … }
TEST_F(BackgroundFetchDataManagerTest, NotifyObserversOnRequestCompletion) { … }
TEST_F(BackgroundFetchDataManagerTest, IsolationInfo) { … }
}