chromium/chrome/updater/net/network_unittest.cc

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

#include "chrome/updater/net/network.h"

#include <cstdint>
#include <memory>
#include <string>

#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/updater/net/network.h"
#include "chrome/updater/policy/service.h"
#include "chrome/updater/test/unit_test_util.h"
#include "components/update_client/network.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 "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

#if BUILDFLAG(IS_WIN)
#include <Urlmon.h>
#endif

namespace updater {
namespace {

RunClosure;
ResponseStartedCallback;
ProgressCallback;
PostRequestCompleteCallback;
DownloadToFileCompleteCallback;

class UpdaterNetworkTest : public ::testing::Test {};

// Sets up a download for "chrome/updater/test/data/signed.exe" using the
// embedded test server running on localhost.
class UpdaterDownloadTest : public ::testing::Test {};

}  // namespace

TEST_F(UpdaterNetworkTest, NetworkFetcherPostRequest) {}

TEST_F(UpdaterNetworkTest, NetworkFetcherDownloadToFile) {}

TEST_F(UpdaterDownloadTest, NetworkFetcher) {}

#if BUILDFLAG(IS_WIN)
// Tests that a direct download through URL moniker from a local HTTP server is
// reasonably fast. This provides a baseline to compare the network throughput
// of various fetchers.
TEST_F(UpdaterDownloadTest, URLMonFetcher) {
  EXPECT_FALSE(base::PathExists(dest_));
  EXPECT_HRESULT_SUCCEEDED(
      ::URLDownloadToFile(nullptr, base::ASCIIToWide(gurl_.spec()).c_str(),
                          dest_.value().c_str(), 0, nullptr));
  EXPECT_TRUE(base::PathExists(dest_));
}
#endif
}  // namespace updater