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

AppCache: Update IfModifiedSinceUpgrade test to use cache helper

This change updates the IfModifiedSinceUpgradeParserVersion1 test to
use the new cache helper.  There's no expected change in functionality
for this test.

A later CL will add another test to verify the 304 behavior for
multiple cached resources (not just the manifest) based on this test's
new structure.

Bug: 989611
Change-Id: I6984632694efa2fd17d100281416890800e93990
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1990252
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@{#729870}
parent d63380b8
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/browser/appcache/appcache_cache_test_helper.h"
#include "content/browser/appcache/appcache_group.h" #include "content/browser/appcache/appcache_group.h"
#include "content/browser/appcache/appcache_host.h" #include "content/browser/appcache/appcache_host.h"
#include "content/browser/appcache/appcache_response.h" #include "content/browser/appcache/appcache_response.h"
...@@ -3439,20 +3440,13 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3439,20 +3440,13 @@ class AppCacheUpdateJobTest : public testing::Test,
group_ = base::MakeRefCounted<AppCacheGroup>( group_ = base::MakeRefCounted<AppCacheGroup>(
service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"), service_->storage(), MockHttpServer::GetMockUrl("files/manifest1"),
111); 111);
http_headers_request_test_jobs_.emplace(
group_->manifest_url(),
std::make_unique<HttpHeadersRequestTestJob>(
"Sat, 29 Oct 1994 19:43:31 GMT", std::string()));
AppCacheUpdateJob* update = AppCacheUpdateJob* update =
new AppCacheUpdateJob(service_.get(), group_.get()); new AppCacheUpdateJob(service_.get(), group_.get());
group_->update_job_ = update; group_->update_job_ = update;
// Give the newest cache a manifest entry that is in storage. // Create a cache without a manifest entry. The manifest entry will be
response_writer_ = // added later.
service_->storage()->CreateResponseWriter(group_->manifest_url()); AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), -1);
AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(),
response_writer_->response_id());
MockFrontend* frontend = MakeMockFrontend(); MockFrontend* frontend = MakeMockFrontend();
AppCacheHost* host = MakeHost(frontend); AppCacheHost* host = MakeHost(frontend);
host->AssociateCompleteCache(cache); host->AssociateCompleteCache(cache);
...@@ -3476,26 +3470,41 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3476,26 +3470,41 @@ class AppCacheUpdateJobTest : public testing::Test,
frontend->AddExpectedEvent( frontend->AddExpectedEvent(
blink::mojom::AppCacheEventID::APPCACHE_UPDATE_READY_EVENT); blink::mojom::AppCacheEventID::APPCACHE_UPDATE_READY_EVENT);
AppCacheCacheTestHelper::CacheEntries cache_entries;
// Add cache entry for manifest.
// Seed storage with expected manifest response info that will cause // Seed storage with expected manifest response info that will cause
// an If-Modified-Since header to be put in the manifest fetch request. // an If-Modified-Since header to be put in the manifest fetch request.
const char data[] = const char data[] =
"HTTP/1.1 200 OK\0" "HTTP/1.1 200 OK\0"
"Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0";
"\0";
scoped_refptr<net::HttpResponseHeaders> headers = scoped_refptr<net::HttpResponseHeaders> headers =
base::MakeRefCounted<net::HttpResponseHeaders>( base::MakeRefCounted<net::HttpResponseHeaders>(
std::string(data, base::size(data))); std::string(data, base::size(data)));
std::unique_ptr<net::HttpResponseInfo> response_info = std::unique_ptr<net::HttpResponseInfo> response_info =
std::make_unique<net::HttpResponseInfo>(); std::make_unique<net::HttpResponseInfo>();
response_info->headers = std::move(headers); response_info->headers = std::move(headers);
scoped_refptr<HttpResponseInfoIOBuffer> io_buffer = AppCacheCacheTestHelper::AddCacheEntry(
base::MakeRefCounted<HttpResponseInfoIOBuffer>( &cache_entries, group_->manifest_url(), AppCacheEntry::EXPLICIT,
std::move(response_info)); /*expect_if_modified_since=*/"Sat, 29 Oct 1994 19:43:31 GMT",
response_writer_->WriteInfo( /*expect_if_none_match=*/std::string(), /*headers_allowed=*/true,
io_buffer.get(), std::move(response_info), kManifest1Contents);
// Add all header checks from |cache_entries|.
for (auto it = cache_entries.begin(); it != cache_entries.end(); ++it) {
http_headers_request_test_jobs_.emplace(
it->first,
std::make_unique<HttpHeadersRequestTestJob>(
it->second->expect_if_modified_since,
it->second->expect_if_none_match, it->second->headers_allowed));
}
cache_helper_ = std::make_unique<AppCacheCacheTestHelper>(
service_.get(), group_->manifest_url(), cache, std::move(cache_entries),
base::BindOnce( base::BindOnce(
&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData, &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
base::Unretained(this))); base::Unretained(this)));
cache_helper_->Write();
// Start update after data write completes asynchronously. // Start update after data write completes asynchronously.
} }
...@@ -3800,6 +3809,7 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3800,6 +3809,7 @@ class AppCacheUpdateJobTest : public testing::Test,
VerifyExpectations(); VerifyExpectations();
// Clean up everything that was created on the IO thread. // Clean up everything that was created on the IO thread.
cache_helper_.reset();
protect_newest_cache_ = nullptr; protect_newest_cache_ = nullptr;
group_ = nullptr; group_ = nullptr;
hosts_.clear(); hosts_.clear();
...@@ -3832,8 +3842,10 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3832,8 +3842,10 @@ class AppCacheUpdateJobTest : public testing::Test,
group_->set_last_full_update_check_time(cache->update_time()); group_->set_last_full_update_check_time(cache->update_time());
// Add manifest entry to cache. // Add manifest entry to cache.
cache->AddEntry(manifest_entry_url, AppCacheEntry(AppCacheEntry::MANIFEST, if (manifest_response_id >= 0) {
manifest_response_id)); cache->AddEntry(manifest_entry_url, AppCacheEntry(AppCacheEntry::MANIFEST,
manifest_response_id));
}
// Specific tests that expect a newer time should set // Specific tests that expect a newer time should set
// expect_full_update_time_newer_than_ which causes this // expect_full_update_time_newer_than_ which causes this
...@@ -4564,6 +4576,7 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -4564,6 +4576,7 @@ class AppCacheUpdateJobTest : public testing::Test,
base::OnceClosure test_completed_cb_; base::OnceClosure test_completed_cb_;
std::unique_ptr<AppCacheResponseWriter> response_writer_; std::unique_ptr<AppCacheResponseWriter> response_writer_;
std::unique_ptr<AppCacheCacheTestHelper> cache_helper_;
// Hosts used by an async test that need to live until update job finishes. // Hosts used by an async test that need to live until update job finishes.
// Otherwise, test can put host on the stack instead of here. // Otherwise, test can put host on the stack instead of here.
......
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