chromium/content/browser/service_worker/service_worker_single_script_update_checker_unittest.cc

// Copyright 2018 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_single_script_update_checker.h"

#include <vector>

#include "base/containers/queue.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/base/load_flags.h"
#include "net/http/http_util.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/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "third_party/blink/public/common/features.h"

namespace content {
namespace {

constexpr char kScriptURL[] =;
constexpr char kImportedScriptURL[] =;
constexpr char kScope[] =;
constexpr char kSuccessHeader[] =;

class ServiceWorkerSingleScriptUpdateCheckerTest : public testing::Test {};

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, Identical_SingleRead) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, Identical_MultipleRead) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, Identical_Empty) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_SingleRead_NetworkIsLonger) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_SingleRead_StorageIsLonger) {}

// Regression test for https://crbug.com/995146.
// It should detect the update appropriately even when OnComplete() arrives
// after the end of the body.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_SingleRead_EndOfTheBodyFirst) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_SingleRead_DifferentBody) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_MultipleRead_NetworkIsLonger) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_MultipleRead_StorageIsLonger) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       Different_MultipleRead_DifferentBody) {}

TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       PendingReadWithErrorStatusShouldNotLeak) {}

// Tests cache validation behavior when updateViaCache is 'all'.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, UpdateViaCache_All) {}

// Tests cache validation behavior when updateViaCache is 'none'.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, UpdateViaCache_None) {}

// Tests cache validation behavior when updateViaCache is 'imports'.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, UpdateViaCache_Imports) {}

// Tests attributions of the resource request for kClassic script.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, ScriptType_Classic_Main) {}

// Tests attributions of the resource request for kClassic script's
// importScripts().
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       ScriptType_Classic_StaticImport) {}

// Tests attributions of the resource request for kModule script.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, ScriptType_Module_Main) {}

// Tests attributions of the resource request for kModule script's static
// import.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest,
       ScriptType_Module_StaticImport) {}

// Tests cache validation behavior when version's
// |force_bypass_cache_for_scripts_| is true.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, ForceBypassCache) {}

// Tests cache validation behavior when more than 24 hours passed.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, MoreThan24Hours) {}

// Tests MIME type header checking.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, MimeTypeError) {}

// Tests path restriction check error for main script.
// |kOutScope| is not under the default scope ("/in-scope/") and the
// Service-Worker-Allowed header is not specified. The check should fail.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, PathRestrictionError) {}

// Tests path restriction check success for main script.
// |kOutScope| is not under the default scope ("/in-scope/") but the
// Service-Worker-Allowed header allows it. The check should pass.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, PathRestrictionPass) {}

// Tests network error is reported.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, NetworkError) {}

// The main script needs to request a SSL info so that the navigation handled
// by the service worker can use the SSL info served for the main script.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, RequestSSLInfo_Classic) {}

// The module script needs to request a SSL info so that the navigation handled
// by the service worker can use the SSL info served for the module script.
TEST_F(ServiceWorkerSingleScriptUpdateCheckerTest, RequestSSLInfo_Module) {}

class ServiceWorkerSingleScriptUpdateCheckerSha256ChecksumTest
    : public ServiceWorkerSingleScriptUpdateCheckerTest,
      public testing::WithParamInterface<
          ServiceWorkerSingleScriptUpdateChecker::ScriptChecksumUpdateOption> {};

TEST_P(ServiceWorkerSingleScriptUpdateCheckerSha256ChecksumTest, Identical) {}

TEST_P(ServiceWorkerSingleScriptUpdateCheckerSha256ChecksumTest, Different) {}

INSTANTIATE_TEST_SUITE_P();
}  // namespace
}  // namespace content