From 0f32a80188868542d85e1aa63eaddae3798d0c1f Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Sat, 10 Sep 2022 17:18:38 +0000 Subject: [PATCH] Bug 1772540: Implement OPFS isSameEntry() r=jari,dom-storage-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D148267 --- dom/fs/api/FileSystemHandle.cpp | 6 +++++- dom/fs/test/gtest/api/TestFileSystemHandle.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dom/fs/api/FileSystemHandle.cpp b/dom/fs/api/FileSystemHandle.cpp index 65680d59c7b0..c752bdc61452 100644 --- a/dom/fs/api/FileSystemHandle.cpp +++ b/dom/fs/api/FileSystemHandle.cpp @@ -103,7 +103,11 @@ already_AddRefed FileSystemHandle::IsSameEntry( return nullptr; } - promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED); + // Handles the case of "dir = createdir foo; removeEntry(foo); file = + // createfile foo; issameentry(dir, file)" + const bool result = mMetadata.entryId().Equals(aOther.mMetadata.entryId()) && + Kind() == aOther.Kind(); + promise->MaybeResolve(result); return promise.forget(); } diff --git a/dom/fs/test/gtest/api/TestFileSystemHandle.cpp b/dom/fs/test/gtest/api/TestFileSystemHandle.cpp index adb653c317e5..a176bfc7982b 100644 --- a/dom/fs/test/gtest/api/TestFileSystemHandle.cpp +++ b/dom/fs/test/gtest/api/TestFileSystemHandle.cpp @@ -96,11 +96,11 @@ TEST_F(TestFileSystemHandle, isDifferentEntry) { RefPtr promise = dirHandle->IsSameEntry(*fileHandle, rv); ASSERT_TRUE(rv.ErrorCodeIs(NS_OK)); ASSERT_TRUE(promise); - ASSERT_EQ(Promise::PromiseState::Rejected, promise->State()); + ASSERT_EQ(Promise::PromiseState::Resolved, promise->State()); nsString result; ASSERT_NSEQ(NS_OK, GetAsString(promise, result)); - ASSERT_STREQ(u"NS_ERROR_NOT_IMPLEMENTED"_ns, result); + ASSERT_STREQ(u"false"_ns, result); } TEST_F(TestFileSystemHandle, isSameEntry) { @@ -111,11 +111,11 @@ TEST_F(TestFileSystemHandle, isSameEntry) { RefPtr promise = fileHandle->IsSameEntry(*fileHandle, rv); ASSERT_TRUE(rv.ErrorCodeIs(NS_OK)); ASSERT_TRUE(promise); - ASSERT_EQ(Promise::PromiseState::Rejected, promise->State()); + ASSERT_EQ(Promise::PromiseState::Resolved, promise->State()); nsString result; ASSERT_NSEQ(NS_OK, GetAsString(promise, result)); - ASSERT_STREQ(u"NS_ERROR_NOT_IMPLEMENTED"_ns, result); + ASSERT_STREQ(u"true"_ns, result); } } // namespace mozilla::dom::fs::test