Bug 1284987 - Entries API - part 2 - FileSystemEntry.getParent, r=smaug

This commit is contained in:
Andrea Marchesini 2016-11-03 07:55:30 +01:00
Родитель 6db54bcb2f
Коммит 3a9551a834
17 изменённых файлов: 147 добавлений и 60 удалений

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

@ -326,9 +326,9 @@ DataTransferItem::GetAsEntry(nsIPrincipal& aSubjectPrincipal,
}
RefPtr<Directory> directory = Directory::Create(global, directoryFile);
entry = new FileSystemDirectoryEntry(global, directory, fs);
entry = new FileSystemDirectoryEntry(global, directory, nullptr, fs);
} else {
entry = new FileSystemFileEntry(global, file, fs);
entry = new FileSystemFileEntry(global, file, nullptr, fs);
}
Sequence<RefPtr<FileSystemEntry>> entries;

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

@ -74,18 +74,18 @@ EmptyEntriesCallbackRunnable::Run()
return NS_OK;
}
GetEntryHelper::GetEntryHelper(nsIGlobalObject* aGlobalObject,
GetEntryHelper::GetEntryHelper(FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem,
FileSystemEntryCallback* aSuccessCallback,
ErrorCallback* aErrorCallback,
FileSystemDirectoryEntry::GetInternalType aType)
: mGlobal(aGlobalObject)
: mParentEntry(aParentEntry)
, mFileSystem(aFileSystem)
, mSuccessCallback(aSuccessCallback)
, mErrorCallback(aErrorCallback)
, mType(aType)
{
MOZ_ASSERT(aGlobalObject);
MOZ_ASSERT(aParentEntry);
MOZ_ASSERT(aFileSystem);
MOZ_ASSERT(aSuccessCallback || aErrorCallback);
}
@ -110,7 +110,8 @@ GetEntryHelper::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
}
RefPtr<FileSystemFileEntry> entry =
new FileSystemFileEntry(mGlobal, file, mFileSystem);
new FileSystemFileEntry(mParentEntry->GetParentObject(), file,
mParentEntry, mFileSystem);
mSuccessCallback->HandleEvent(*entry);
return;
}
@ -124,7 +125,8 @@ GetEntryHelper::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
}
RefPtr<FileSystemDirectoryEntry> entry =
new FileSystemDirectoryEntry(mGlobal, directory, mFileSystem);
new FileSystemDirectoryEntry(mParentEntry->GetParentObject(), directory,
mParentEntry, mFileSystem);
mSuccessCallback->HandleEvent(*entry);
}
@ -141,7 +143,8 @@ GetEntryHelper::Error(nsresult aError)
if (mErrorCallback) {
RefPtr<ErrorCallbackRunnable> runnable =
new ErrorCallbackRunnable(mGlobal, mErrorCallback, aError);
new ErrorCallbackRunnable(mParentEntry->GetParentObject(),
mErrorCallback, aError);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
}
@ -149,6 +152,21 @@ GetEntryHelper::Error(nsresult aError)
NS_IMPL_ISUPPORTS0(GetEntryHelper);
/* static */ void
FileSystemEntryCallbackHelper::Call(const Optional<OwningNonNull<FileSystemEntryCallback>>& aEntryCallback,
FileSystemEntry* aEntry)
{
MOZ_ASSERT(aEntry);
if (aEntryCallback.WasPassed()) {
RefPtr<EntryCallbackRunnable> runnable =
new EntryCallbackRunnable(&aEntryCallback.Value(), aEntry);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
}
}
/* static */ void
ErrorCallbackHelper::Call(nsIGlobalObject* aGlobal,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,

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

@ -65,7 +65,7 @@ class GetEntryHelper final : public PromiseNativeHandler
public:
NS_DECL_ISUPPORTS
GetEntryHelper(nsIGlobalObject* aGlobalObject,
GetEntryHelper(FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem,
FileSystemEntryCallback* aSuccessCallback,
ErrorCallback* aErrorCallback,
@ -83,13 +83,21 @@ private:
void
Error(nsresult aError);
nsCOMPtr<nsIGlobalObject> mGlobal;
RefPtr<FileSystemDirectoryEntry> mParentEntry;
RefPtr<FileSystem> mFileSystem;
RefPtr<FileSystemEntryCallback> mSuccessCallback;
RefPtr<ErrorCallback> mErrorCallback;
FileSystemDirectoryEntry::GetInternalType mType;
};
class FileSystemEntryCallbackHelper
{
public:
static void
Call(const Optional<OwningNonNull<FileSystemEntryCallback>>& aEntryCallback,
FileSystemEntry* aEntry);
};
class ErrorCallbackHelper
{
public:

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

@ -25,8 +25,9 @@ NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry)
FileSystemDirectoryEntry::FileSystemDirectoryEntry(nsIGlobalObject* aGlobal,
Directory* aDirectory,
FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem)
: FileSystemEntry(aGlobal, aFileSystem)
: FileSystemEntry(aGlobal, aParentEntry, aFileSystem)
, mDirectory(aDirectory)
{
MOZ_ASSERT(aGlobal);
@ -57,12 +58,12 @@ FileSystemDirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const
}
already_AddRefed<FileSystemDirectoryReader>
FileSystemDirectoryEntry::CreateReader() const
FileSystemDirectoryEntry::CreateReader()
{
MOZ_ASSERT(mDirectory);
RefPtr<FileSystemDirectoryReader> reader =
new FileSystemDirectoryReader(GetParentObject(), Filesystem(), mDirectory);
new FileSystemDirectoryReader(this, Filesystem(), mDirectory);
return reader.forget();
}
@ -71,7 +72,7 @@ FileSystemDirectoryEntry::GetInternal(const nsAString& aPath,
const FileSystemFlags& aFlag,
const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
GetInternalType aType) const
GetInternalType aType)
{
MOZ_ASSERT(mDirectory);
@ -101,7 +102,7 @@ FileSystemDirectoryEntry::GetInternal(const nsAString& aPath,
}
RefPtr<GetEntryHelper> handler =
new GetEntryHelper(GetParentObject(), Filesystem(),
new GetEntryHelper(this, Filesystem(),
aSuccessCallback.WasPassed()
? &aSuccessCallback.Value() : nullptr,
aErrorCallback.WasPassed()

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

@ -7,7 +7,6 @@
#ifndef mozilla_dom_FileSystemDirectoryEntry_h
#define mozilla_dom_FileSystemDirectoryEntry_h
#include "mozilla/dom/FileSystemBinding.h"
#include "mozilla/dom/FileSystemEntry.h"
namespace mozilla {
@ -25,6 +24,7 @@ public:
FileSystemDirectoryEntry(nsIGlobalObject* aGlobalObject,
Directory* aDirectory,
FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem);
virtual JSObject*
@ -43,12 +43,12 @@ public:
GetFullPath(nsAString& aFullPath, ErrorResult& aRv) const override;
virtual already_AddRefed<FileSystemDirectoryReader>
CreateReader() const;
CreateReader();
void
GetFile(const Optional<nsAString>& aPath, const FileSystemFlags& aFlag,
const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback)
{
GetInternal(aPath.WasPassed() ? aPath.Value() : EmptyString(),
aFlag, aSuccessCallback, aErrorCallback, eGetFile);
@ -57,7 +57,7 @@ public:
void
GetDirectory(const Optional<nsAString>& aPath, const FileSystemFlags& aFlag,
const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback)
{
GetInternal(aPath.WasPassed() ? aPath.Value() : EmptyString(),
aFlag, aSuccessCallback, aErrorCallback, eGetDirectory);
@ -73,7 +73,7 @@ public:
GetInternal(const nsAString& aPath, const FileSystemFlags& aFlag,
const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
GetInternalType aType) const;
GetInternalType aType);
protected:
virtual ~FileSystemDirectoryEntry();

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

@ -12,7 +12,6 @@
#include "mozilla/dom/DirectoryBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseNativeHandler.h"
#include "nsIGlobalObject.h"
namespace mozilla {
namespace dom {
@ -24,16 +23,16 @@ class PromiseHandler final : public PromiseNativeHandler
public:
NS_DECL_ISUPPORTS
PromiseHandler(nsIGlobalObject* aGlobalObject,
PromiseHandler(FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem,
FileSystemEntriesCallback* aSuccessCallback,
ErrorCallback* aErrorCallback)
: mGlobal(aGlobalObject)
: mParentEntry(aParentEntry)
, mFileSystem(aFileSystem)
, mSuccessCallback(aSuccessCallback)
, mErrorCallback(aErrorCallback)
{
MOZ_ASSERT(aGlobalObject);
MOZ_ASSERT(aParentEntry);
MOZ_ASSERT(aFileSystem);
MOZ_ASSERT(aSuccessCallback);
}
@ -72,7 +71,8 @@ public:
RefPtr<File> file;
if (NS_SUCCEEDED(UNWRAP_OBJECT(File, valueObj, file))) {
RefPtr<FileSystemFileEntry> entry =
new FileSystemFileEntry(mGlobal, file, mFileSystem);
new FileSystemFileEntry(mParentEntry->GetParentObject(), file,
mParentEntry, mFileSystem);
sequence[i] = entry;
continue;
}
@ -84,7 +84,8 @@ public:
}
RefPtr<FileSystemDirectoryEntry> entry =
new FileSystemDirectoryEntry(mGlobal, directory, mFileSystem);
new FileSystemDirectoryEntry(mParentEntry->GetParentObject(), directory,
mParentEntry, mFileSystem);
sequence[i] = entry;
}
@ -96,7 +97,8 @@ public:
{
if (mErrorCallback) {
RefPtr<ErrorCallbackRunnable> runnable =
new ErrorCallbackRunnable(mGlobal, mErrorCallback,
new ErrorCallbackRunnable(mParentEntry->GetParentObject(),
mErrorCallback,
NS_ERROR_DOM_INVALID_STATE_ERR);
DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
@ -106,7 +108,7 @@ public:
private:
~PromiseHandler() {}
nsCOMPtr<nsIGlobalObject> mGlobal;
RefPtr<FileSystemDirectoryEntry> mParentEntry;
RefPtr<FileSystem> mFileSystem;
RefPtr<FileSystemEntriesCallback> mSuccessCallback;
RefPtr<ErrorCallback> mErrorCallback;
@ -116,7 +118,7 @@ NS_IMPL_ISUPPORTS0(PromiseHandler);
} // anonymous namespace
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemDirectoryReader, mParent,
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemDirectoryReader, mParentEntry,
mDirectory, mFileSystem)
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemDirectoryReader)
@ -127,15 +129,15 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemDirectoryReader)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
FileSystemDirectoryReader::FileSystemDirectoryReader(nsIGlobalObject* aGlobal,
FileSystemDirectoryReader::FileSystemDirectoryReader(FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem,
Directory* aDirectory)
: mParent(aGlobal)
: mParentEntry(aParentEntry)
, mFileSystem(aFileSystem)
, mDirectory(aDirectory)
, mAlreadyRead(false)
{
MOZ_ASSERT(aGlobal);
MOZ_ASSERT(aParentEntry);
MOZ_ASSERT(aFileSystem);
}
@ -176,7 +178,7 @@ FileSystemDirectoryReader::ReadEntries(FileSystemEntriesCallback& aSuccessCallba
}
RefPtr<PromiseHandler> handler =
new PromiseHandler(GetParentObject(), mFileSystem, &aSuccessCallback,
new PromiseHandler(mParentEntry, mFileSystem, &aSuccessCallback,
aErrorCallback.WasPassed()
? &aErrorCallback.Value() : nullptr);
promise->AppendNativeHandler(handler);

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

@ -13,8 +13,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
class nsIGlobalObject;
namespace mozilla {
namespace dom {
@ -30,14 +28,14 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileSystemDirectoryReader)
explicit FileSystemDirectoryReader(nsIGlobalObject* aGlobalObject,
explicit FileSystemDirectoryReader(FileSystemDirectoryEntry* aDirectoryEntry,
FileSystem* aFileSystem,
Directory* aDirectory);
nsIGlobalObject*
GetParentObject() const
{
return mParent;
return mParentEntry->GetParentObject();
}
virtual JSObject*
@ -52,7 +50,7 @@ protected:
virtual ~FileSystemDirectoryReader();
private:
nsCOMPtr<nsIGlobalObject> mParent;
RefPtr<FileSystemDirectoryEntry> mParentEntry;
RefPtr<FileSystem> mFileSystem;
RefPtr<Directory> mDirectory;

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

@ -13,7 +13,8 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemEntry, mParent, mFileSystem)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemEntry, mParent, mParentEntry,
mFileSystem)
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemEntry)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FileSystemEntry)
@ -35,11 +36,13 @@ FileSystemEntry::Create(nsIGlobalObject* aGlobalObject,
if (aFileOrDirectory.IsFile()) {
entry = new FileSystemFileEntry(aGlobalObject,
aFileOrDirectory.GetAsFile(),
nullptr,
aFileSystem);
} else {
MOZ_ASSERT(aFileOrDirectory.IsDirectory());
entry = new FileSystemDirectoryEntry(aGlobalObject,
aFileOrDirectory.GetAsDirectory(),
nullptr,
aFileSystem);
}
@ -47,8 +50,10 @@ FileSystemEntry::Create(nsIGlobalObject* aGlobalObject,
}
FileSystemEntry::FileSystemEntry(nsIGlobalObject* aGlobal,
FileSystemEntry* aParentEntry,
FileSystem* aFileSystem)
: mParent(aGlobal)
, mParentEntry(aParentEntry)
, mFileSystem(aFileSystem)
{
MOZ_ASSERT(aGlobal);
@ -64,5 +69,21 @@ FileSystemEntry::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return FileSystemEntryBinding::Wrap(aCx, this, aGivenProto);
}
void
FileSystemEntry::GetParent(const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback)
{
if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) {
return;
}
if (mParentEntry) {
FileSystemEntryCallbackHelper::Call(aSuccessCallback, mParentEntry);
return;
}
FileSystemEntryCallbackHelper::Call(aSuccessCallback, this);
}
} // dom namespace
} // mozilla namespace

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

@ -10,6 +10,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/FileSystemBinding.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIGlobalObject.h"
#include "nsWrapperCache.h"
@ -60,6 +61,10 @@ public:
virtual void
GetFullPath(nsAString& aFullPath, ErrorResult& aRv) const = 0;
void
GetParent(const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback);
FileSystem*
Filesystem() const
{
@ -68,11 +73,13 @@ public:
protected:
FileSystemEntry(nsIGlobalObject* aGlobalObject,
FileSystemEntry* aParentEntry,
FileSystem* aFileSystem);
virtual ~FileSystemEntry();
private:
nsCOMPtr<nsIGlobalObject> mParent;
RefPtr<FileSystemEntry> mParentEntry;
RefPtr<FileSystem> mFileSystem;
};

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

@ -49,8 +49,9 @@ NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry)
FileSystemFileEntry::FileSystemFileEntry(nsIGlobalObject* aGlobal,
File* aFile,
FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem)
: FileSystemEntry(aGlobal, aFileSystem)
: FileSystemEntry(aGlobal, aParentEntry, aFileSystem)
, mFile(aFile)
{
MOZ_ASSERT(aGlobal);

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

@ -12,8 +12,9 @@
namespace mozilla {
namespace dom {
class File;
class BlobCallback;
class File;
class FileSystemDirectoryEntry;
class FileSystemFileEntry final : public FileSystemEntry
{
@ -22,6 +23,7 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemFileEntry, FileSystemEntry)
FileSystemFileEntry(nsIGlobalObject* aGlobalObject, File* aFile,
FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem);
virtual JSObject*

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

@ -23,7 +23,7 @@ NS_INTERFACE_MAP_END_INHERITING(FileSystemDirectoryEntry)
FileSystemRootDirectoryEntry::FileSystemRootDirectoryEntry(nsIGlobalObject* aGlobal,
const Sequence<RefPtr<FileSystemEntry>>& aEntries,
FileSystem* aFileSystem)
: FileSystemDirectoryEntry(aGlobal, nullptr, aFileSystem)
: FileSystemDirectoryEntry(aGlobal, nullptr, nullptr, aFileSystem)
, mEntries(aEntries)
{
MOZ_ASSERT(aGlobal);
@ -45,11 +45,10 @@ FileSystemRootDirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) co
}
already_AddRefed<FileSystemDirectoryReader>
FileSystemRootDirectoryEntry::CreateReader() const
FileSystemRootDirectoryEntry::CreateReader()
{
RefPtr<FileSystemDirectoryReader> reader =
new FileSystemRootDirectoryReader(GetParentObject(), Filesystem(),
mEntries);
new FileSystemRootDirectoryReader(this, Filesystem(), mEntries);
return reader.forget();
}
@ -58,7 +57,7 @@ FileSystemRootDirectoryEntry::GetInternal(const nsAString& aPath,
const FileSystemFlags& aFlag,
const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
GetInternalType aType) const
GetInternalType aType)
{
if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) {
return;

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

@ -29,7 +29,7 @@ public:
GetFullPath(nsAString& aFullPath, ErrorResult& aRv) const override;
virtual already_AddRefed<FileSystemDirectoryReader>
CreateReader() const override;
CreateReader() override;
private:
~FileSystemRootDirectoryEntry();
@ -38,7 +38,7 @@ private:
GetInternal(const nsAString& aPath, const FileSystemFlags& aFlag,
const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback,
const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
GetInternalType aType) const override;
GetInternalType aType) override;
void
Error(const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,

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

@ -56,14 +56,14 @@ NS_IMPL_RELEASE_INHERITED(FileSystemRootDirectoryReader,
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileSystemRootDirectoryReader)
NS_INTERFACE_MAP_END_INHERITING(FileSystemDirectoryReader)
FileSystemRootDirectoryReader::FileSystemRootDirectoryReader(nsIGlobalObject* aGlobal,
FileSystemRootDirectoryReader::FileSystemRootDirectoryReader(FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem,
const Sequence<RefPtr<FileSystemEntry>>& aEntries)
: FileSystemDirectoryReader(aGlobal, aFileSystem, nullptr)
: FileSystemDirectoryReader(aParentEntry, aFileSystem, nullptr)
, mEntries(aEntries)
, mAlreadyRead(false)
{
MOZ_ASSERT(aGlobal);
MOZ_ASSERT(aParentEntry);
MOZ_ASSERT(aFileSystem);
}

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

@ -19,7 +19,7 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemRootDirectoryReader,
FileSystemDirectoryReader)
explicit FileSystemRootDirectoryReader(nsIGlobalObject* aGlobalObject,
explicit FileSystemRootDirectoryReader(FileSystemDirectoryEntry* aParentEntry,
FileSystem* aFileSystem,
const Sequence<RefPtr<FileSystemEntry>>& aEntries);

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

@ -80,6 +80,15 @@ function test_fileEntry_createWriter() {
});
}
function test_fileEntry_getParent() {
fileEntry.getParent(function(entry) {
is(fileEntry.fullPath, entry.fullPath, "Top level FileEntry should return itself as parent.");
next();
}, function() {
ok(false, "This is wrong.");
});
}
function test_directoryEntry() {
ok("name" in directoryEntry, "We have a name.");
ok("fullPath" in directoryEntry, "We have a fullPath.");
@ -115,6 +124,15 @@ function test_directoryEntry_createReader() {
});
}
function test_directoryEntry_getParent() {
directoryEntry.getParent(function(entry) {
is(directoryEntry.fullPath, entry.fullPath, "Top level FileEntry should return itself as parent.");
next();
}, function() {
ok(false, "This is wrong.");
});
}
function test_directoryEntry_getFile_securityError() {
directoryEntry.getFile("foo", { create: true },
function() {
@ -159,7 +177,7 @@ function test_directoryEntry_getFile_simple() {
directoryEntry.getFile("foo.txt", {},
function(e) {
is(e.name, "foo.txt", "We have the right FileEntry.");
next();
test_getParent(e, directoryEntry);
}, function(e) {
ok(false, "This should not happen.");
});
@ -169,7 +187,7 @@ function test_directoryEntry_getFile_deep() {
directoryEntry.getFile("subdir/bar.txt", {},
function(e) {
is(e.name, "bar.txt", "We have the right FileEntry.");
next();
test_getParent(e, null);
}, function(e) {
ok(false, "This should not happen.");
});
@ -219,7 +237,7 @@ function test_directoryEntry_getDirectory_simple() {
directoryEntry.getDirectory("subdir", {},
function(e) {
is(e.name, "subdir", "We have the right DirectoryEntry.");
next();
test_getParent(e, directoryEntry);
}, function(e) {
ok(false, "This should not happen.");
});
@ -229,7 +247,7 @@ function test_directoryEntry_getDirectory_deep() {
directoryEntry.getDirectory("subdir/subsubdir", {},
function(e) {
is(e.name, "subsubdir", "We have the right DirectoryEntry.");
next();
test_getParent(e, directoryEntry);
}, function(e) {
ok(false, "This should not happen.");
});
@ -385,6 +403,18 @@ function cleanUpTestingFiles() {
script.sendAsyncMessage("entries.delete");
}
function test_getParent(entry, parentEntry) {
entry.getParent(function(e) {
ok(e, "We have a parent Entry.");
if (parentEntry) {
is (e, parentEntry, "Parent entry matches");
}
next();
}, function(e) {
ok(false, "This should not happen.");
});
}
var tests = [
setup_tests,
populate_entries,
@ -394,9 +424,11 @@ var tests = [
test_fileEntry,
test_fileEntry_file,
test_fileEntry_createWriter,
test_fileEntry_getParent,
test_directoryEntry,
test_directoryEntry_createReader,
test_directoryEntry_getParent,
test_directoryEntry_getFile_securityError,
test_directoryEntry_getFile_typeMismatchError,

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

@ -16,8 +16,6 @@ interface FileSystemEntry {
readonly attribute FileSystem filesystem;
/** Not implemented:
* void getParent(optional FileSystemEntryCallback successCallback,
* optional ErrorCallback errorCallback);
*/
void getParent(optional FileSystemEntryCallback successCallback,
optional ErrorCallback errorCallback);
};