Commit 543cd8bb authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

service worker: Reduce old response writers use in tests

This CL replaces old response writers with new mojo-based writers in the
following test helper functions:
* WriteToDiskCacheWithIdSync()
* WriteToDiskCacheSync()
* WriteToDiskCacheAsync()

Bug: 1055677
Change-Id: Ic897b36d770a57efc88b53dde6a0e4776f626785
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2301710
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789834}
parent 55db96a8
...@@ -184,7 +184,7 @@ void EmbeddedWorkerTestHelper::PopulateScriptCacheMap( ...@@ -184,7 +184,7 @@ void EmbeddedWorkerTestHelper::PopulateScriptCacheMap(
// Add a dummy ResourceRecord for the main script to the script cache map of // Add a dummy ResourceRecord for the main script to the script cache map of
// the ServiceWorkerVersion. // the ServiceWorkerVersion.
WriteToDiskCacheAsync( WriteToDiskCacheAsync(
context()->storage(), version->script_url(), {} /* headers */, context()->GetStorageControl(), version->script_url(), {} /* headers */,
"I'm a body", "I'm a meta data", "I'm a body", "I'm a meta data",
base::BindOnce( base::BindOnce(
[](scoped_refptr<ServiceWorkerVersion> version, [](scoped_refptr<ServiceWorkerVersion> version,
......
...@@ -109,8 +109,8 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test { ...@@ -109,8 +109,8 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
records.push_back(WriteToDiskCacheSync( records.push_back(WriteToDiskCacheSync(
context()->storage(), version_->script_url(), {} /* headers */, context()->GetStorageControl(), version_->script_url(),
"I'm a body", "I'm a meta data")); {} /* headers */, "I'm a body", "I'm a meta data"));
version_->script_cache_map()->SetResources(records); version_->script_cache_map()->SetResources(records);
version_->SetMainScriptResponse( version_->SetMainScriptResponse(
EmbeddedWorkerTestHelper::CreateMainScriptResponse()); EmbeddedWorkerTestHelper::CreateMainScriptResponse());
......
...@@ -43,7 +43,8 @@ class ExpectedScriptInfo { ...@@ -43,7 +43,8 @@ class ExpectedScriptInfo {
meta_data_(meta_data) {} meta_data_(meta_data) {}
storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCache( storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCache(
ServiceWorkerStorage* storage) const { mojo::Remote<storage::mojom::ServiceWorkerStorageControl>& storage)
const {
return ::content::WriteToDiskCacheWithIdSync( return ::content::WriteToDiskCacheWithIdSync(
storage, script_url_, resource_id_, headers_, body_, meta_data_); storage, script_url_, resource_id_, headers_, body_, meta_data_);
} }
...@@ -202,7 +203,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, SendScripts) { ...@@ -202,7 +203,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, SendScripts) {
{ {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
} }
...@@ -260,7 +262,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, FailedToSendBody) { ...@@ -260,7 +262,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, FailedToSendBody) {
{ {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
} }
...@@ -319,7 +322,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, FailedToSendMetaData) { ...@@ -319,7 +322,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, FailedToSendMetaData) {
{ {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
} }
...@@ -390,7 +394,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, Histograms) { ...@@ -390,7 +394,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, Histograms) {
{ {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
} }
...@@ -472,7 +477,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, RequestScriptBeforeStreaming) { ...@@ -472,7 +477,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, RequestScriptBeforeStreaming) {
{ {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
} }
...@@ -562,7 +568,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, RequestScriptAfterStreaming) { ...@@ -562,7 +568,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, RequestScriptAfterStreaming) {
{ {
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
} }
...@@ -633,7 +640,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, NoContext) { ...@@ -633,7 +640,8 @@ TEST_F(ServiceWorkerInstalledScriptsSenderTest, NoContext) {
"I'm meta data for the main script"}}}; "I'm meta data for the main script"}}};
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
for (const auto& info : kExpectedScriptInfoMap) for (const auto& info : kExpectedScriptInfoMap)
records.push_back(info.second.WriteToDiskCache(context()->storage())); records.push_back(
info.second.WriteToDiskCache(context()->GetStorageControl()));
version()->script_cache_map()->SetResources(records); version()->script_cache_map()->SetResources(records);
auto sender = auto sender =
std::make_unique<ServiceWorkerInstalledScriptsSender>(version()); std::make_unique<ServiceWorkerInstalledScriptsSender>(version());
......
...@@ -408,9 +408,9 @@ class ServiceWorkerMainResourceLoaderTest : public testing::Test { ...@@ -408,9 +408,9 @@ class ServiceWorkerMainResourceLoaderTest : public testing::Test {
GURL("https://example.com/service_worker.js"), GURL("https://example.com/service_worker.js"),
blink::mojom::ScriptType::kClassic); blink::mojom::ScriptType::kClassic);
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
records.push_back(WriteToDiskCacheSync(storage(), version_->script_url(), records.push_back(WriteToDiskCacheSync(
{} /* headers */, "I'm the body", GetStorageControl(), version_->script_url(), {} /* headers */,
"I'm the meta data")); "I'm the body", "I'm the meta data"));
version_->script_cache_map()->SetResources(records); version_->script_cache_map()->SetResources(records);
version_->set_fetch_handler_existence( version_->set_fetch_handler_existence(
ServiceWorkerVersion::FetchHandlerExistence::EXISTS); ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
...@@ -454,6 +454,10 @@ class ServiceWorkerMainResourceLoaderTest : public testing::Test { ...@@ -454,6 +454,10 @@ class ServiceWorkerMainResourceLoaderTest : public testing::Test {
ServiceWorkerRegistry* registry() { return helper_->context()->registry(); } ServiceWorkerRegistry* registry() { return helper_->context()->registry(); }
ServiceWorkerStorage* storage() { return helper_->context()->storage(); } ServiceWorkerStorage* storage() { return helper_->context()->storage(); }
mojo::Remote<storage::mojom::ServiceWorkerStorageControl>&
GetStorageControl() {
return helper_->context()->GetStorageControl();
}
// Starts a request. After calling this, the request is ongoing and the // Starts a request. After calling this, the request is ongoing and the
// caller can use functions like client_.RunUntilComplete() to wait for // caller can use functions like client_.RunUntilComplete() to wait for
......
...@@ -404,7 +404,7 @@ class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTest, ...@@ -404,7 +404,7 @@ class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTest,
// Store the registration. // Store the registration.
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records_1; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records_1;
records_1.push_back(WriteToDiskCacheSync( records_1.push_back(WriteToDiskCacheSync(
helper_->context()->storage(), version_1->script_url(), helper_->context()->GetStorageControl(), version_1->script_url(),
{} /* headers */, "I'm the body", "I'm the meta data")); {} /* headers */, "I'm the body", "I'm the meta data"));
version_1->script_cache_map()->SetResources(records_1); version_1->script_cache_map()->SetResources(records_1);
version_1->SetMainScriptResponse( version_1->SetMainScriptResponse(
...@@ -446,7 +446,7 @@ class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTest, ...@@ -446,7 +446,7 @@ class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTest,
blink::mojom::ScriptType::kClassic); blink::mojom::ScriptType::kClassic);
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records_2; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records_2;
records_2.push_back(WriteToDiskCacheSync( records_2.push_back(WriteToDiskCacheSync(
helper_->context()->storage(), version_2->script_url(), helper_->context()->GetStorageControl(), version_2->script_url(),
{} /* headers */, "I'm the body", "I'm the meta data")); {} /* headers */, "I'm the body", "I'm the meta data"));
version_2->script_cache_map()->SetResources(records_2); version_2->script_cache_map()->SetResources(records_2);
version_2->SetMainScriptResponse( version_2->SetMainScriptResponse(
...@@ -890,9 +890,9 @@ class ServiceWorkerRegistrationObjectHostTest ...@@ -890,9 +890,9 @@ class ServiceWorkerRegistrationObjectHostTest
context()->registry(), registration, script_url, context()->registry(), registration, script_url,
blink::mojom::ScriptType::kClassic); blink::mojom::ScriptType::kClassic);
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
records.push_back(WriteToDiskCacheSync(storage(), version->script_url(), records.push_back(WriteToDiskCacheSync(
{} /* headers */, "I'm the body", helper_->context()->GetStorageControl(), version->script_url(),
"I'm the meta data")); {} /* headers */, "I'm the body", "I'm the meta data"));
version->script_cache_map()->SetResources(records); version->script_cache_map()->SetResources(records);
version->SetMainScriptResponse( version->SetMainScriptResponse(
EmbeddedWorkerTestHelper::CreateMainScriptResponse()); EmbeddedWorkerTestHelper::CreateMainScriptResponse());
......
...@@ -133,9 +133,9 @@ class ServiceWorkerScriptLoaderFactoryCopyResumeTest ...@@ -133,9 +133,9 @@ class ServiceWorkerScriptLoaderFactoryCopyResumeTest
void SetUp() override { void SetUp() override {
ServiceWorkerScriptLoaderFactoryTest::SetUp(); ServiceWorkerScriptLoaderFactoryTest::SetUp();
WriteToDiskCacheWithIdSync(helper_->context()->storage(), script_url_, WriteToDiskCacheWithIdSync(helper_->context()->GetStorageControl(),
kOldResourceId, kOldHeaders, kOldData, script_url_, kOldResourceId, kOldHeaders,
std::string()); kOldData, std::string());
} }
void CheckResponse(const std::string& expected_body) { void CheckResponse(const std::string& expected_body) {
......
...@@ -169,7 +169,7 @@ CreateServiceWorkerRegistrationAndVersion(ServiceWorkerContextCore* context, ...@@ -169,7 +169,7 @@ CreateServiceWorkerRegistrationAndVersion(ServiceWorkerContextCore* context,
// all of tasks. If it's in another base::RunLoop, consider to use // all of tasks. If it's in another base::RunLoop, consider to use
// WriteToDiskCacheAsync(). // WriteToDiskCacheAsync().
storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCacheWithIdSync( storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCacheWithIdSync(
ServiceWorkerStorage* storage, mojo::Remote<storage::mojom::ServiceWorkerStorageControl>& storage,
const GURL& script_url, const GURL& script_url,
int64_t resource_id, int64_t resource_id,
const std::vector<std::pair<std::string, std::string>>& headers, const std::vector<std::pair<std::string, std::string>>& headers,
...@@ -179,7 +179,7 @@ storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCacheWithIdSync( ...@@ -179,7 +179,7 @@ storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCacheWithIdSync(
// Similar to WriteToDiskCacheWithIdSync() but instead of taking a resource id, // Similar to WriteToDiskCacheWithIdSync() but instead of taking a resource id,
// this assigns a new resource ID internally. // this assigns a new resource ID internally.
storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCacheSync( storage::mojom::ServiceWorkerResourceRecordPtr WriteToDiskCacheSync(
ServiceWorkerStorage* storage, mojo::Remote<storage::mojom::ServiceWorkerStorageControl>& storage,
const GURL& script_url, const GURL& script_url,
const std::vector<std::pair<std::string, std::string>>& headers, const std::vector<std::pair<std::string, std::string>>& headers,
const std::string& body, const std::string& body,
...@@ -193,7 +193,7 @@ using WriteToDiskCacheCallback = base::OnceCallback<void( ...@@ -193,7 +193,7 @@ using WriteToDiskCacheCallback = base::OnceCallback<void(
// base::RunUntilIdle because wiriting to the storage might happen on another // base::RunUntilIdle because wiriting to the storage might happen on another
// thread and base::RunLoop could get idle before writes has not finished yet. // thread and base::RunLoop could get idle before writes has not finished yet.
void WriteToDiskCacheAsync( void WriteToDiskCacheAsync(
ServiceWorkerStorage* storage, mojo::Remote<storage::mojom::ServiceWorkerStorageControl>& storage,
const GURL& script_url, const GURL& script_url,
const std::vector<std::pair<std::string, std::string>>& headers, const std::vector<std::pair<std::string, std::string>>& headers,
const std::string& body, const std::string& body,
......
...@@ -83,8 +83,9 @@ class ServiceWorkerUpdatedScriptLoaderTest : public testing::Test { ...@@ -83,8 +83,9 @@ class ServiceWorkerUpdatedScriptLoaderTest : public testing::Test {
SetUpRegistration(kScriptURL); SetUpRegistration(kScriptURL);
// Create the old script resource in storage. // Create the old script resource in storage.
WriteToDiskCacheWithIdSync(context()->storage(), kScriptURL, kOldResourceId, WriteToDiskCacheWithIdSync(context()->GetStorageControl(), kScriptURL,
kOldHeaders, kOldData, std::string()); kOldResourceId, kOldHeaders, kOldData,
std::string());
} }
// Sets up ServiceWorkerRegistration and ServiceWorkerVersion. This should be // Sets up ServiceWorkerRegistration and ServiceWorkerVersion. This should be
......
...@@ -102,7 +102,7 @@ class ServiceWorkerVersionTest : public testing::Test { ...@@ -102,7 +102,7 @@ class ServiceWorkerVersionTest : public testing::Test {
EXPECT_EQ(url::Origin::Create(scope_), version_->script_origin()); EXPECT_EQ(url::Origin::Create(scope_), version_->script_origin());
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records; std::vector<storage::mojom::ServiceWorkerResourceRecordPtr> records;
records.push_back(WriteToDiskCacheWithIdSync( records.push_back(WriteToDiskCacheWithIdSync(
helper_->context()->storage(), version_->script_url(), 10, helper_->context()->GetStorageControl(), version_->script_url(), 10,
{} /* headers */, "I'm a body", "I'm a meta data")); {} /* headers */, "I'm a body", "I'm a meta data"));
version_->script_cache_map()->SetResources(records); version_->script_cache_map()->SetResources(records);
version_->SetMainScriptResponse( version_->SetMainScriptResponse(
......
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