chromium/content/browser/service_worker/service_worker_cache_writer_unittest.cc

// Copyright 2015 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_cache_writer.h"

#include <stddef.h>

#include <list>
#include <string>
#include <vector>

#include "base/containers/queue.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/test/task_environment.h"
#include "content/browser/service_worker/service_worker_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {
namespace {

// A test implementation of ServiceWorkerCacheWriter::WriteObserver.
// This observer captures the response head or data sent to the observer
// for further checking.
class MockServiceWorkerCacheWriterObserver
    : public ServiceWorkerCacheWriter::WriteObserver {};

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

// Passthrough tests:
// In these tests, the ServiceWorkerCacheWriter under test has no existing
// reader, since no calls to ExpectReader() have been made; this means that
// there is no existing cached response and the incoming data is written back to
// the cache directly.

TEST_F(ServiceWorkerCacheWriterTest, PassthroughHeadersAsync) {}

TEST_F(ServiceWorkerCacheWriterTest, PassthroughDataAsync) {}

TEST_F(ServiceWorkerCacheWriterTest, PassthroughHeadersFailAsync) {}

TEST_F(ServiceWorkerCacheWriterTest, PassthroughDataFailAsync) {}

// Comparison tests:
// For the Compare* tests below, the ServiceWorkerCacheWriter under test has a
// reader for an existing cached response, so it will compare the response being
// written to it against the existing cached response.
TEST_F(ServiceWorkerCacheWriterTest, CompareDataOkAsync) {}

TEST_F(ServiceWorkerCacheWriterTest, CompareDataManyOkAsync) {}

// This test writes headers and three data blocks data1, data2, data3; data2
// differs in the cached version. The writer should be asked to rewrite the
// headers and body with the new value, and the copy reader should be asked to
// read the header and data1.
TEST_F(ServiceWorkerCacheWriterTest, CompareFailedCopy) {}

// Tests behavior when the cached data is shorter than the network data.
TEST_F(ServiceWorkerCacheWriterTest, CompareFailedCopyShort) {}

// Tests behavior when the cached data is longer than the network data.
TEST_F(ServiceWorkerCacheWriterTest, CompareFailedCopyLong) {}

// Tests behavior when the compare reader does not complete in single try and
// needs to issue another read.
TEST_F(ServiceWorkerCacheWriterTest, MultipleComparisonInSingleWrite) {}

// Tests behavior when |pause_when_not_identical| is enabled and cache writer
// finishes asynchronously.
TEST_F(ServiceWorkerCacheWriterTest, PauseWhenNotIdentical_AsyncWriteData) {}

// Tests behavior of a cache writer used to copy script which finishes
// asynchronously.
TEST_F(ServiceWorkerCacheWriterTest, CopyScript_Async) {}

// Tests behavior of a cache writer used to copy script that read multiple
// times and finishes asynchronously.
TEST_F(ServiceWorkerCacheWriterTest, CopyScript_AsyncMultipleRead) {}

// The observer runs synchronously and the response writer runs asynchronously.
TEST_F(ServiceWorkerCacheWriterTest, ObserverSyncResponseWriterAsync) {}

// The observer and response writer all run asynchronously.
TEST_F(ServiceWorkerCacheWriterTest, ObserverAsyncResponseWriterAsync) {}

// Observer's OnWillWriteData() runs synchronously but fails.
TEST_F(ServiceWorkerCacheWriterTest, ObserverSyncFail) {}

// Observer's OnWillWriteData() runs asynchronously but fails.
TEST_F(ServiceWorkerCacheWriterTest, ObserverAsyncFail) {}

class ServiceWorkerCacheWriterSha256ChecksumTest
    : public ServiceWorkerCacheWriterTest,
      public testing::WithParamInterface<
          ServiceWorkerCacheWriter::ChecksumUpdateTiming> {};

TEST_P(ServiceWorkerCacheWriterSha256ChecksumTest, CompareDataOk) {}

TEST_P(ServiceWorkerCacheWriterSha256ChecksumTest, CompareFailed) {}

INSTANTIATE_TEST_SUITE_P();

class ServiceWorkerCacheWriterDisconnectionTest
    : public ServiceWorkerCacheWriterTest {};

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, WriteBackBeforeHeader) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, WriteBackBeforeData) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, WriteBackDuringData) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, CopyBeforeStart) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, CopyBeforeHeaderRead) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, CopyBeforeDataRead) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, CopyDuringDataRead) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, ComparisonBeforeHeaderRead) {}

TEST_F(ServiceWorkerCacheWriterDisconnectionTest, ComparisonBeforeDataWrite) {}

// Tests that a comparison fails gracefully when remotes are disconnected during
// copy. See also the comment of ServiceWorkerCacheWriterTest.CompareFailedCopy.
TEST_F(ServiceWorkerCacheWriterDisconnectionTest, ComparisonDuringCopy) {}

// Tests that a comparison fails gracefully when remotes are disconnected before
// resuming.
TEST_F(ServiceWorkerCacheWriterDisconnectionTest, ComparisonBeforeResume) {}

}  // namespace
}  // namespace content