Commit d3517f13 authored by Chase Phillips's avatar Chase Phillips Committed by Commit Bot

AppCache: Allow AppCacheUpdateJobTest to monitor multiple requests

Originally, the AppCacheUpdateJobTest was only concerned with testing
that manifest fetches and the headers that were returned matched
expectations.  That was because the update job tests weren't verifying
anything about the fetch process for cached resources.

Unfortunately, the 304 response handling for cached resources isn't
correct which led to a series of bugs where any cached resource that
gets a 304 response can go stale when it could instead have had its
lifetime extended by the server.  This, coupled with a bug where
the request and response times weren't saved at all led to a bunch
of corrupt resources in AppCaches.

This CL extends the interceptor in AppCacheUpdateJobTest so it can
handle monitoring multiple resources, not just a single manifest
resource.  A later CL will add a test which captures a full cache
request and response cycle and monitors multiple resource fetches.

Bug: 989611
Change-Id: I486d11f5be187f76e2ab2bf2c0f931c3efa9d7f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989002
Commit-Queue: Chase Phillips <cmp@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729861}
parent 40021c4d
...@@ -59,6 +59,7 @@ AppCacheCacheTestHelper::AppCacheCacheTestHelper( ...@@ -59,6 +59,7 @@ AppCacheCacheTestHelper::AppCacheCacheTestHelper(
manifest_url_(manifest_url), manifest_url_(manifest_url),
cache_(cache), cache_(cache),
cache_entries_(std::move(cache_entries)), cache_entries_(std::move(cache_entries)),
state_(State::kIdle),
post_write_callback_(std::move(post_write_callback)) {} post_write_callback_(std::move(post_write_callback)) {}
AppCacheCacheTestHelper::~AppCacheCacheTestHelper() = default; AppCacheCacheTestHelper::~AppCacheCacheTestHelper() = default;
...@@ -71,6 +72,7 @@ void AppCacheCacheTestHelper::PrepareForRead( ...@@ -71,6 +72,7 @@ void AppCacheCacheTestHelper::PrepareForRead(
} }
void AppCacheCacheTestHelper::Read() { void AppCacheCacheTestHelper::Read() {
DCHECK_EQ(state_, State::kIdle);
state_ = State::kReadInfo; state_ = State::kReadInfo;
read_it_ = read_cache_->entries().begin(); read_it_ = read_cache_->entries().begin();
read_cache_entries_.clear(); read_cache_entries_.clear();
...@@ -78,6 +80,7 @@ void AppCacheCacheTestHelper::Read() { ...@@ -78,6 +80,7 @@ void AppCacheCacheTestHelper::Read() {
} }
void AppCacheCacheTestHelper::Write() { void AppCacheCacheTestHelper::Write() {
DCHECK_EQ(state_, State::kIdle);
state_ = State::kWriteInfo; state_ = State::kWriteInfo;
write_it_ = cache_entries_.begin(); write_it_ = cache_entries_.begin();
AsyncWrite(0); AsyncWrite(0);
...@@ -98,6 +101,7 @@ void AppCacheCacheTestHelper::AsyncRead(int result) { ...@@ -98,6 +101,7 @@ void AppCacheCacheTestHelper::AsyncRead(int result) {
DCHECK(state_ == State::kReadInfo || state_ == State::kReadData); DCHECK(state_ == State::kReadInfo || state_ == State::kReadData);
DCHECK_GE(result, 0); DCHECK_GE(result, 0);
if (read_it_ == read_cache_->entries().end()) { if (read_it_ == read_cache_->entries().end()) {
state_ = State::kIdle;
std::move(post_read_callback_).Run(); std::move(post_read_callback_).Run();
return; return;
} }
...@@ -149,7 +153,7 @@ void AppCacheCacheTestHelper::AsyncRead(int result) { ...@@ -149,7 +153,7 @@ void AppCacheCacheTestHelper::AsyncRead(int result) {
// Reset after read. // Reset after read.
read_info_response_info_.reset(); read_info_response_info_.reset();
read_entry_response_id_ = 0; read_entry_response_id_ = 0;
read_data_buffer_ = nullptr; read_data_buffer_.reset();
read_data_loaded_data_ = ""; read_data_loaded_data_ = "";
read_data_response_reader_.reset(); read_data_response_reader_.reset();
...@@ -171,6 +175,7 @@ void AppCacheCacheTestHelper::AsyncWrite(int result) { ...@@ -171,6 +175,7 @@ void AppCacheCacheTestHelper::AsyncWrite(int result) {
DCHECK(state_ == State::kWriteInfo || state_ == State::kWriteData); DCHECK(state_ == State::kWriteInfo || state_ == State::kWriteData);
DCHECK_GE(result, 0); DCHECK_GE(result, 0);
if (write_it_ == cache_entries_.end()) { if (write_it_ == cache_entries_.end()) {
state_ = State::kIdle;
std::move(post_write_callback_).Run(1); std::move(post_write_callback_).Run(1);
return; return;
} }
......
...@@ -61,6 +61,7 @@ class AppCacheCacheTestHelper : public AppCacheStorage::Delegate { ...@@ -61,6 +61,7 @@ class AppCacheCacheTestHelper : public AppCacheStorage::Delegate {
private: private:
enum class State { enum class State {
kIdle,
kReadInfo, kReadInfo,
kReadData, kReadData,
kWriteInfo, kWriteInfo,
...@@ -74,12 +75,12 @@ class AppCacheCacheTestHelper : public AppCacheStorage::Delegate { ...@@ -74,12 +75,12 @@ class AppCacheCacheTestHelper : public AppCacheStorage::Delegate {
const GURL manifest_url_; const GURL manifest_url_;
AppCache* const cache_; AppCache* const cache_;
CacheEntries cache_entries_; CacheEntries cache_entries_;
base::OnceCallback<void(int)> post_write_callback_;
State state_; State state_;
// Used for writing cache info and data. // Used for writing cache info and data.
CacheEntries::const_iterator write_it_; CacheEntries::const_iterator write_it_;
std::unique_ptr<AppCacheResponseWriter> response_writer_; std::unique_ptr<AppCacheResponseWriter> response_writer_;
base::OnceCallback<void(int)> post_write_callback_;
// Used for reading cache info and data. // Used for reading cache info and data.
AppCache* read_cache_; AppCache* read_cache_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment