chromium/extensions/browser/updater/extension_downloader_test_helper.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_TEST_HELPER_H_
#define EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_TEST_HELPER_H_

#include <memory>
#include <set>
#include <string>

#include "extensions/browser/updater/extension_cache.h"
#include "extensions/browser/updater/extension_downloader.h"
#include "extensions/browser/updater/extension_downloader_delegate.h"
#include "extensions/browser/updater/extension_downloader_types.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace extensions {

// Backoff policy to enforce zero initial delay.
const extern net::BackoffEntry::Policy kZeroBackoffPolicy;

class MockExtensionDownloaderDelegate
    : public ::testing::NiceMock<ExtensionDownloaderDelegate> {};

class MockExtensionCache : public ExtensionCache {};

// Creates ExtensionDownloader for tests, with mocked delegate and
// TestURLLoaderFactory as a URL factory.
class ExtensionDownloaderTestHelper {};

// Creates a downloader task with most arguments set to default values.
// Note that as ExtensionDownloaderTask is just a simple struct, callers can
// configure additional properties if needed.
ExtensionDownloaderTask CreateDownloaderTask(const ExtensionId& id,
                                             const GURL& update_url = {};

// Creates extension info and associated task, adds both to `fetch_data`.
void AddExtensionToFetchDataForTesting(ManifestFetchData* fetch_data,
                                       const ExtensionId& id,
                                       const std::string& version,
                                       const GURL& update_url,
                                       DownloadPingData ping_data);

// Simplified version with fewer arguments.
void AddExtensionToFetchDataForTesting(ManifestFetchData* fetch_data,
                                       const ExtensionId& id,
                                       const std::string& version,
                                       const GURL& update_url);

// Struct for creating app entries in the update manifest XML.
struct UpdateManifestItem {};

// A generic method to create an XML update manifest. For each extension an
// extension ID should be provided along with parameters of the updatecheck
// tag.
std::string CreateUpdateManifest(
    const std::vector<UpdateManifestItem>& extensions);

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_TEST_HELPER_H_