chromium/content/browser/service_worker/service_worker_new_script_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/browser/service_worker/service_worker_new_script_loader.h"

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "base/containers/span.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/service_worker_consts.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/url_loader_interceptor.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/base/features.h"
#include "net/base/load_flags.h"
#include "net/base/test_completion_callback.h"
#include "net/http/http_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/redirect_info.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/parsed_headers.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/network/test/test_url_loader_client.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/storage_key/storage_key.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 "url/origin.h"

namespace content {
namespace service_worker_new_script_loader_unittest {

const char kNormalScriptURL[] =;
const char kNormalImportedScriptURL[] =;
const char kHistogramWriteResponseResult[] =;

// MockHTTPServer is a utility to provide mocked responses for
// ServiceWorkerNewScriptLoader.
class MockHTTPServer {};

// Mocks network activity. Used by URLLoaderInterceptor.
class MockNetwork {};

// ServiceWorkerNewScriptLoaderTest is for testing the handling of requests for
// installing service worker scripts via ServiceWorkerNewScriptLoader.
class ServiceWorkerNewScriptLoaderTest : public testing::Test {};

TEST_F(ServiceWorkerNewScriptLoaderTest, Success) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Success_EmptyBody) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Success_LargeBody) {}

namespace {

// A URLLoaderFactory that provides access to a mojo data pipe for sending a
// response body. Can only handle one URLLoader, i.e, CreateLoaderAndStart()
// can be called only once.
class BodyDataPipeTestURLLoaderFactory final
    : public network::mojom::URLLoaderFactory {};

}  // namespace

// Regression test for https://crbug.com/1312995.
TEST_F(ServiceWorkerNewScriptLoaderTest, Success_ClientConsumeBodyLater) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_404) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_Redirect) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_CertificateError) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_NoMimeType) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_BadMimeType) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Success_PathRestriction) {}

TEST_F(ServiceWorkerNewScriptLoaderTest,
       Fail_ModuleServiceWorker_PathRestriction) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_PathRestriction) {}

TEST_F(ServiceWorkerNewScriptLoaderTest, Error_RedundantWorker) {}

// Tests that EmbeddedWorkerInstance's |network_accessed_for_script_| flag is
// set when the script loader accesses network. This flag is used to enforce the
// 24 hour cache validation.
TEST_F(ServiceWorkerNewScriptLoaderTest, AccessedNetwork) {}

}  // namespace service_worker_new_script_loader_unittest
}  // namespace content