Bug 1798459 - Add a shutdown check to FileSystemRequestHandler::GetWritable; r=dom-storage-reviewers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D161171
This commit is contained in:
Jan Varga 2022-11-09 17:15:34 +00:00
Родитель 9bb3260919
Коммит 975c16dc24
4 изменённых файлов: 35 добавлений и 3 удалений

Просмотреть файл

@ -69,7 +69,10 @@ already_AddRefed<Promise> FileSystemFileHandle::CreateWritable(
}
mRequestHandler->GetWritable(mManager, mMetadata, aOptions.mKeepExistingData,
promise);
promise, aError);
if (aError.Failed()) {
return nullptr;
}
return promise.forget();
}

Просмотреть файл

@ -457,12 +457,18 @@ void FileSystemRequestHandler::GetAccessHandle(
void FileSystemRequestHandler::GetWritable(RefPtr<FileSystemManager>& aManager,
const FileSystemEntryMetadata& aFile,
bool aKeepData,
const RefPtr<Promise>& aPromise) {
const RefPtr<Promise>& aPromise,
ErrorResult& aError) {
MOZ_ASSERT(aManager);
MOZ_ASSERT(aPromise);
LOG(("GetWritable %s keep %d", NS_ConvertUTF16toUTF8(aFile.entryName()).get(),
aKeepData));
if (aManager->IsShutdown()) {
aError.Throw(NS_ERROR_ILLEGAL_DURING_SHUTDOWN);
return;
}
aManager->BeginRequest(
[request = FileSystemGetWritableRequest(aFile.entryId(), aKeepData),
onResolve =

Просмотреть файл

@ -54,7 +54,8 @@ class FileSystemRequestHandler {
virtual void GetWritable(RefPtr<FileSystemManager>& aManager,
const FileSystemEntryMetadata& aFile, bool aKeepData,
const RefPtr<Promise>& aPromise);
const RefPtr<Promise>& aPromise,
ErrorResult& aError);
virtual void GetEntries(RefPtr<FileSystemManager>& aManager,
const EntryId& aDirectory, PageNumber aPage,

Просмотреть файл

@ -245,6 +245,28 @@ TEST_F(TestFileSystemRequestHandler, isGetFileBlockedAfterShutdown) {
ASSERT_TRUE(error.ErrorCodeIs(NS_ERROR_ILLEGAL_DURING_SHUTDOWN));
}
TEST_F(TestFileSystemRequestHandler, isGetAccessHandleBlockedAfterShutdown) {
mManager->Shutdown();
IgnoredErrorResult error;
GetFileSystemRequestHandler()->GetAccessHandle(mManager, mEntry,
GetSimplePromise(), error);
ASSERT_TRUE(error.Failed());
ASSERT_TRUE(error.ErrorCodeIs(NS_ERROR_ILLEGAL_DURING_SHUTDOWN));
}
TEST_F(TestFileSystemRequestHandler, isGetWritableBlockedAfterShutdown) {
mManager->Shutdown();
IgnoredErrorResult error;
GetFileSystemRequestHandler()->GetWritable(
mManager, mEntry, /* aKeepData */ false, GetSimplePromise(), error);
ASSERT_TRUE(error.Failed());
ASSERT_TRUE(error.ErrorCodeIs(NS_ERROR_ILLEGAL_DURING_SHUTDOWN));
}
TEST_F(TestFileSystemRequestHandler, isGetEntriesSuccessful) {
auto fakeResponse = [](const auto& /* aRequest */, auto&& aResolve,
auto&& /* aReject */) {