Commit 180511f5 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

service worker: Expose SetPurgingCompleteCallbackForTest()

This function is used by unittests which depend on in-memory
representations like ServiceWorkerVersion. Expose it as a
mojo test helper function so that these tests can be moved
out service_worker_storage_unittest.cc.

This CL doesn't move any tests. Subsequent CLs will move
these tests.

Bug: 1016064
Change-Id: Icc33be2dc0ddc186237cdd8ff731a11b678bfdc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462942
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816038}
parent 85b2daf9
......@@ -267,4 +267,9 @@ interface ServiceWorkerStorageControl {
// Applies changes to data retention policy which are relevant at shutdown.
// This is analogous to LocalStorageControl::ApplyPolicyUpdates.
ApplyPolicyUpdates(array<LocalStoragePolicyUpdate> policy_updates);
// Sets a callback which is executed when purging resources completes.
// Only a single callback can be set at a time. Overlapped calls are not
// allowed.
SetPurgingCompleteCallbackForTest() => ();
};
......@@ -1126,6 +1126,7 @@ void ServiceWorkerStorage::LazyInitializeForTest() {
void ServiceWorkerStorage::SetPurgingCompleteCallbackForTest(
base::OnceClosure callback) {
DCHECK(!purging_complete_callback_for_test_);
purging_complete_callback_for_test_ = std::move(callback);
}
......
......@@ -368,6 +368,11 @@ void ServiceWorkerStorageControlImpl::ApplyPolicyUpdates(
storage_->ApplyPolicyUpdates(std::move(policy_updates));
}
void ServiceWorkerStorageControlImpl::SetPurgingCompleteCallbackForTest(
SetPurgingCompleteCallbackForTestCallback callback) {
storage_->SetPurgingCompleteCallbackForTest(std::move(callback)); // IN-TEST
}
void ServiceWorkerStorageControlImpl::DidFindRegistration(
base::OnceCallback<
void(storage::mojom::ServiceWorkerDatabaseStatus status,
......
......@@ -150,6 +150,8 @@ class CONTENT_EXPORT ServiceWorkerStorageControlImpl
void ApplyPolicyUpdates(
const std::vector<storage::mojom::LocalStoragePolicyUpdatePtr>
policy_updates) override;
void SetPurgingCompleteCallbackForTest(
SetPurgingCompleteCallbackForTestCallback callback) override;
using ResourceList =
std::vector<storage::mojom::ServiceWorkerResourceRecordPtr>;
......
......@@ -1460,7 +1460,7 @@ TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_NoLiveVersion) {
// purgeable list and then doomed in the disk cache and removed from that
// list.
base::RunLoop loop;
storage()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
storage_control()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
EXPECT_EQ(blink::ServiceWorkerStatusCode::kOk,
DeleteRegistration(registration_, scope_.GetOrigin()));
// At this point registration_->waiting_version() has a remote reference, so
......@@ -1490,7 +1490,7 @@ TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) {
// Doom the version. The resources should be purged.
base::RunLoop loop;
storage()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
storage_control()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
registration_->waiting_version()->Doom();
loop.Run();
EXPECT_TRUE(GetPurgeableResourceIdsFromDB().empty());
......@@ -1524,7 +1524,7 @@ TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) {
// Dooming the version should cause the resources to be deleted.
base::RunLoop loop;
storage()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
storage_control()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
registration_->active_version()->RemoveControllee(
container_host->client_uuid());
registration_->active_version()->Doom();
......@@ -1579,7 +1579,7 @@ TEST_F(ServiceWorkerResourceStorageDiskTest, CleanupOnRestart) {
// Store a new uncommitted resource. This triggers stale resource cleanup.
base::RunLoop loop;
storage()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
storage_control()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
int64_t kNewResourceId = GetNewResourceIdSync(storage_control());
WriteBasicResponse(storage_control(), kNewResourceId);
registry()->StoreUncommittedResourceId(kNewResourceId,
......@@ -1716,7 +1716,7 @@ TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) {
// Remove the controllee to allow the new version to become active, making the
// old version redundant.
base::RunLoop loop;
storage()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
storage_control()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
scoped_refptr<ServiceWorkerVersion> old_version(
registration_->active_version());
old_version->RemoveControllee(container_host->client_uuid());
......@@ -1752,7 +1752,7 @@ TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration_NoLiveVersion) {
// Writing the registration should purge the old version's resources,
// since it's not live.
base::RunLoop loop;
storage()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
storage_control()->SetPurgingCompleteCallbackForTest(loop.QuitClosure());
EXPECT_EQ(
blink::ServiceWorkerStatusCode::kOk,
StoreRegistration(registration_.get(), registration_->waiting_version()));
......
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