chromium/content/renderer/service_worker/service_worker_subresource_loader_unittest.cc

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

#include "content/renderer/service_worker/service_worker_subresource_loader.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "content/common/features.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_task_environment.h"
#include "content/renderer/service_worker/controller_service_worker_connector.h"
#include "content/test/fake_network_url_loader_factory.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/http/http_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_data_pipe_getter.h"
#include "services/network/test/test_url_loader_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/service_worker/service_worker_router_rule.h"
#include "third_party/blink/public/mojom/blob/blob.mojom.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_response.mojom.h"
#include "third_party/blink/public/mojom/loader/fetch_client_settings_object.mojom.h"
#include "third_party/blink/public/mojom/service_worker/dispatch_fetch_event_params.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_container.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_fetch_handler_bypass_option.mojom-shared.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration_options.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_stream_handle.mojom.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "url/origin.h"

namespace content {
namespace service_worker_subresource_loader_unittest {

// A simple blob implementation for serving data stored in a vector.
class FakeBlob final : public blink::mojom::Blob {};

class FakeControllerServiceWorker
    : public blink::mojom::ControllerServiceWorker {};

class FakeServiceWorkerContainerHost
    : public blink::mojom::ServiceWorkerContainerHost {};

// Returns an expected network::mojom::URLResponseHeadPtr which is used by
// stream response related tests.
network::mojom::URLResponseHeadPtr CreateResponseInfoFromServiceWorker() {}

// ServiceWorkerSubresourceLoader::RecordTimingMetrics() records the metrics
// only when the consistent high-resolution timer is used among processes.
bool LoaderRecordsTimingMetrics() {}

const char kHistogramSubresourceFetchEvent[] =;

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

TEST_F(ServiceWorkerSubresourceLoaderTest, Basic) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, Abort) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, DropController) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, NoController) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, DropController_RestartFetchEvent) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, DropController_TooManyRestart) {}

TEST_F(ServiceWorkerSubresourceLoaderTest,
       DropController_RestartFetchEvent_RaceNetworkRequest) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, StreamResponse) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, StreamResponse_Abort) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, BlobResponse) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, BlobResponseWithoutMetadata) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, BlobResponseNonScript) {}

// Test when the service worker responds with network fallback.
// i.e., does not call respondWith().
TEST_F(ServiceWorkerSubresourceLoaderTest, FallbackResponse) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, ErrorResponse) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, RedirectResponse) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, TooManyRedirects) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, FollowNonexistentRedirect) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, FallbackWithRequestBody_String) {}

TEST_F(ServiceWorkerSubresourceLoaderTest, FallbackWithRequestBody_DataPipe) {}

// Test a range request that the service worker responds to with a 200
// (non-ranged) response. The client should get the entire response as-is from
// the service worker.
TEST_F(ServiceWorkerSubresourceLoaderTest, RangeRequest_200Response) {}

// Test a range request that the service worker responds to with a 206 ranged
// response. The client should get the partial response as-is from the service
// worker.
TEST_F(ServiceWorkerSubresourceLoaderTest, RangeRequest_206Response) {}

// Test a range request that the service worker responds to with a 206 ranged
// response. The requested range has an unbounded end. The client should get the
// partial response as-is from the service worker.
TEST_F(ServiceWorkerSubresourceLoaderTest,
       RangeRequest_UnboundedRight_206Response) {}

}  // namespace service_worker_subresource_loader_unittest
}  // namespace content