зеркало из https://github.com/mozilla/gecko-dev.git
Back out dougt (bug 788588 et al.) for burning the tree (and some nostalgia).
This commit is contained in:
Родитель
247ae26919
Коммит
19dc351f35
|
@ -50,9 +50,6 @@ private:
|
||||||
bool aEditable,
|
bool aEditable,
|
||||||
nsIDOMDeviceStorageCursor** aRetval);
|
nsIDOMDeviceStorageCursor** aRetval);
|
||||||
|
|
||||||
static bool IsMimeTypeCorrectForStorageType(nsAString& aType,
|
|
||||||
nsIDOMBlob* aBlob);
|
|
||||||
|
|
||||||
nsString mStorageType;
|
nsString mStorageType;
|
||||||
nsCOMPtr<nsIFile> mRootDirectory;
|
nsCOMPtr<nsIFile> mRootDirectory;
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ DeviceStorageRequestParent::StatFileEvent::CancelableRun()
|
||||||
|
|
||||||
nsCOMPtr<nsIRunnable> r;
|
nsCOMPtr<nsIRunnable> r;
|
||||||
uint64_t diskUsage = 0;
|
uint64_t diskUsage = 0;
|
||||||
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage, mFile->mStorageType);
|
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage);
|
||||||
int64_t freeSpace = 0;
|
int64_t freeSpace = 0;
|
||||||
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
|
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
#include "nsIMIMEService.h"
|
#include "nsIMIMEService.h"
|
||||||
#include "nsCExternalHandlerService.h"
|
#include "nsCExternalHandlerService.h"
|
||||||
|
|
||||||
#include "nsIStringBundle.h"
|
|
||||||
|
|
||||||
// Microsoft's API Name hackery sucks
|
// Microsoft's API Name hackery sucks
|
||||||
#undef CreateEvent
|
#undef CreateEvent
|
||||||
|
|
||||||
|
@ -49,7 +47,11 @@
|
||||||
#include "nsIVolumeService.h"
|
#include "nsIVolumeService.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEVICESTORAGE_PROPERTIES "chrome://global/content/devicestorage.properties"
|
#define DEBUG_ISTYPE 1
|
||||||
|
|
||||||
|
#ifdef DEBUG_ISTYPE
|
||||||
|
#include "nsIConsoleService.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
using namespace mozilla::dom::devicestorage;
|
using namespace mozilla::dom::devicestorage;
|
||||||
|
@ -82,9 +84,7 @@ private:
|
||||||
nsCString mType;
|
nsCString mType;
|
||||||
};
|
};
|
||||||
|
|
||||||
DeviceStorageFile::DeviceStorageFile(const nsAString& aStorageType,
|
DeviceStorageFile::DeviceStorageFile(const nsAString& aStorageType, nsIFile* aFile, const nsAString& aPath)
|
||||||
nsIFile* aFile,
|
|
||||||
const nsAString& aPath)
|
|
||||||
: mPath(aPath)
|
: mPath(aPath)
|
||||||
, mStorageType(aStorageType)
|
, mStorageType(aStorageType)
|
||||||
, mEditable(false)
|
, mEditable(false)
|
||||||
|
@ -151,40 +151,72 @@ DeviceStorageFile::IsSafePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DeviceStorageFile::IsType(nsIFile* aFile, const nsAString& aStorageType)
|
DeviceStorageFile::IsType(nsAString& aType)
|
||||||
{
|
{
|
||||||
// String bundles are cached by the bundle service.
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||||
nsCOMPtr<nsIStringBundleService> stringService = mozilla::services::GetStringBundleService();
|
|
||||||
if (!stringService) {
|
// in testing, we ignore filtering for the testing types
|
||||||
|
if (mozilla::Preferences::GetBool("device.storage.testing", false) &&
|
||||||
|
(aType.Equals(NS_LITERAL_STRING("testing")) ||
|
||||||
|
aType.Equals(NS_LITERAL_STRING("testing-other")))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_ISTYPE
|
||||||
|
nsCOMPtr<nsIConsoleService> svc = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||||
|
char buffer[1024];
|
||||||
|
nsCString path;
|
||||||
|
mFile->GetNativePath(path);
|
||||||
|
|
||||||
|
PRIntervalTime iStart = PR_IntervalNow();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nsAutoCString mimeType;
|
||||||
|
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
||||||
|
if (!mimeService) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIStringBundle> filterBundle;
|
nsresult rv = mimeService->GetTypeFromFile(mFile, mimeType);
|
||||||
if (NS_FAILED(stringService->CreateBundle(DEVICESTORAGE_PROPERTIES,
|
if (NS_FAILED(rv)) {
|
||||||
getter_AddRefs(filterBundle)))) {
|
#ifdef DEBUG_ISTYPE
|
||||||
|
sprintf(buffer, "GetTypeFromFile failed for %s (took: %dms)\n",
|
||||||
|
path.get(),
|
||||||
|
PR_IntervalToMilliseconds(PR_IntervalNow() - iStart));
|
||||||
|
|
||||||
|
nsString data;
|
||||||
|
CopyASCIItoUTF16(buffer, data);
|
||||||
|
svc->LogStringMessage(data.get());
|
||||||
|
printf("%s\n", buffer);
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsString path;
|
#ifdef DEBUG_ISTYPE
|
||||||
aFile->GetPath(path);
|
sprintf(buffer, "IsType of %s is %s (took: %dms)\n",
|
||||||
|
path.get(),
|
||||||
|
mimeType.get(),
|
||||||
|
PR_IntervalToMilliseconds(PR_IntervalNow() - iStart));
|
||||||
|
|
||||||
int32_t dotIdx = path.RFindChar(PRUnichar('.'));
|
nsString data;
|
||||||
if (dotIdx == kNotFound) {
|
CopyASCIItoUTF16(buffer, data);
|
||||||
return false;
|
svc->LogStringMessage(data.get());
|
||||||
|
printf("%s\n", buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (aType.Equals(NS_LITERAL_STRING("pictures"))) {
|
||||||
|
return StringBeginsWith(mimeType, NS_LITERAL_CSTRING("image/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString extensionMatch;
|
if (aType.Equals(NS_LITERAL_STRING("videos"))) {
|
||||||
extensionMatch.AssignASCII("*");
|
return StringBeginsWith(mimeType, NS_LITERAL_CSTRING("video/"));
|
||||||
extensionMatch.Append(Substring(path, dotIdx));
|
|
||||||
extensionMatch.AppendASCII(";");
|
|
||||||
|
|
||||||
nsString extensionListStr;
|
|
||||||
if (NS_FAILED(filterBundle->GetStringFromName(aStorageType.BeginReading(),
|
|
||||||
getter_Copies(extensionListStr)))) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FindInReadable(extensionMatch, extensionListStr);
|
if (aType.Equals(NS_LITERAL_STRING("music"))) {
|
||||||
|
return StringBeginsWith(mimeType, NS_LITERAL_CSTRING("audio/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -318,7 +350,7 @@ DeviceStorageFile::Remove()
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!check) {
|
if (!check) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -403,7 +435,7 @@ DeviceStorageFile::collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const nsAString& aStorageType)
|
DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar)
|
||||||
{
|
{
|
||||||
if (!aFile) {
|
if (!aFile) {
|
||||||
return;
|
return;
|
||||||
|
@ -439,18 +471,12 @@ DeviceStorageFile::DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const ns
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLink) {
|
if (isLink) {
|
||||||
// for now, lets just totally ignore symlinks.
|
// for now, lets just totally ignore symlinks.
|
||||||
NS_WARNING("DirectoryDiskUsage ignores symlinks");
|
NS_WARNING("DirectoryDiskUsage ignores symlinks");
|
||||||
} else if (isDir) {
|
} else if (isDir) {
|
||||||
DirectoryDiskUsage(f, aSoFar, aStorageType);
|
DirectoryDiskUsage(f, aSoFar);
|
||||||
} else if (isFile) {
|
} else if (isFile) {
|
||||||
|
|
||||||
if (!DeviceStorageFile::IsType(f, aStorageType)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t size;
|
int64_t size;
|
||||||
rv = f->GetFileSize(&size);
|
rv = f->GetFileSize(&size);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
@ -521,8 +547,6 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aType)
|
||||||
dirService->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
dirService->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
#elif defined (XP_UNIX)
|
#elif defined (XP_UNIX)
|
||||||
dirService->Get(NS_UNIX_XDG_PICTURES_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
dirService->Get(NS_UNIX_XDG_PICTURES_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
#elif defined (XP_WIN)
|
|
||||||
dirService->Get(NS_WIN_PERSONAL_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,8 +558,6 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aType)
|
||||||
dirService->Get(NS_OSX_MOVIE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
dirService->Get(NS_OSX_MOVIE_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
#elif defined (XP_UNIX)
|
#elif defined (XP_UNIX)
|
||||||
dirService->Get(NS_UNIX_XDG_VIDEOS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
dirService->Get(NS_UNIX_XDG_VIDEOS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
#elif defined (XP_WIN)
|
|
||||||
dirService->Get(NS_WIN_PERSONAL_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,18 +569,21 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aType)
|
||||||
dirService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
dirService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
#elif defined (XP_UNIX)
|
#elif defined (XP_UNIX)
|
||||||
dirService->Get(NS_UNIX_XDG_MUSIC_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
dirService->Get(NS_UNIX_XDG_MUSIC_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
#elif defined (XP_WIN)
|
|
||||||
dirService->Get(NS_WIN_PERSONAL_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// in testing, we default all device storage types to a temp directory
|
// in testing, we have access to a few more directory locations
|
||||||
if (f && mozilla::Preferences::GetBool("device.storage.testing", false)) {
|
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
|
||||||
dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
|
||||||
if (f) {
|
// testing directory
|
||||||
f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing"));
|
if (aType.Equals(NS_LITERAL_STRING("testing")) ||
|
||||||
f->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
aType.Equals(NS_LITERAL_STRING("testing-other"))) {
|
||||||
f->Normalize();
|
dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
|
||||||
|
if (f) {
|
||||||
|
f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing"));
|
||||||
|
f->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
||||||
|
f->Normalize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,7 +808,7 @@ ContinueCursorEvent::Run() {
|
||||||
while (cursor->mFiles.Length() > 0) {
|
while (cursor->mFiles.Length() > 0) {
|
||||||
nsRefPtr<DeviceStorageFile> file = cursor->mFiles[0];
|
nsRefPtr<DeviceStorageFile> file = cursor->mFiles[0];
|
||||||
cursor->mFiles.RemoveElementAt(0);
|
cursor->mFiles.RemoveElementAt(0);
|
||||||
if (!DeviceStorageFile::IsType(file->mFile, cursorStorageType)) {
|
if (!file->IsType(cursorStorageType)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
val = nsIFileToJsval(cursor->GetOwner(), file);
|
val = nsIFileToJsval(cursor->GetOwner(), file);
|
||||||
|
@ -1197,7 +1222,7 @@ public:
|
||||||
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
||||||
nsCOMPtr<nsIRunnable> r;
|
nsCOMPtr<nsIRunnable> r;
|
||||||
uint64_t diskUsage = 0;
|
uint64_t diskUsage = 0;
|
||||||
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage, mFile->mStorageType);
|
DeviceStorageFile::DirectoryDiskUsage(mFile->mFile, &diskUsage);
|
||||||
int64_t freeSpace = 0;
|
int64_t freeSpace = 0;
|
||||||
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
|
nsresult rv = mFile->mFile->GetDiskSpaceAvailable(&freeSpace);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
@ -1552,65 +1577,17 @@ nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
nsDOMDeviceStorage::IsMimeTypeCorrectForStorageType(nsAString& aType, nsIDOMBlob* aBlob)
|
|
||||||
{
|
|
||||||
NS_ASSERTION(aBlob, "Calling IsMimeTypeCorrectForStorageType without a blob");
|
|
||||||
|
|
||||||
nsString mimeType;
|
|
||||||
if (NS_FAILED(aBlob->GetType(mimeType))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aType.Equals(NS_LITERAL_STRING("pictures"))) {
|
|
||||||
return StringBeginsWith(mimeType, NS_LITERAL_STRING("image/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aType.Equals(NS_LITERAL_STRING("videos"))) {
|
|
||||||
return StringBeginsWith(mimeType, NS_LITERAL_STRING("video/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aType.Equals(NS_LITERAL_STRING("music"))) {
|
|
||||||
return StringBeginsWith(mimeType, NS_LITERAL_STRING("audio/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval)
|
nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval)
|
||||||
{
|
{
|
||||||
if (!aBlob) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIMIMEService> mimeSvc = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
|
||||||
if (!mimeSvc) {
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if mimeType isn't set, we will not get a correct
|
|
||||||
// extension, and AddNamed() will fail. This will post an
|
|
||||||
// onerror to the requestee.
|
|
||||||
nsString mimeType;
|
|
||||||
aBlob->GetType(mimeType);
|
|
||||||
|
|
||||||
nsCString extension;
|
|
||||||
mimeSvc->GetPrimaryExtension(NS_LossyConvertUTF16toASCII(mimeType), EmptyCString(), extension);
|
|
||||||
// if extension is null here, we will ignore it for now.
|
|
||||||
// AddNamed() will check the file path and fail. This
|
|
||||||
// will post an onerror to the requestee.
|
|
||||||
|
|
||||||
// possible race here w/ unique filename
|
// possible race here w/ unique filename
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
NS_MakeRandomString(buffer, ArrayLength(buffer));
|
NS_MakeRandomString(buffer, 128);
|
||||||
|
|
||||||
nsAutoCString path;
|
nsString path;
|
||||||
path.Assign(nsDependentCString(buffer));
|
path.AssignWithConversion(nsDependentCString(buffer));
|
||||||
path.Append(".");
|
|
||||||
path.Append(extension);
|
|
||||||
|
|
||||||
return AddNamed(aBlob, NS_ConvertASCIItoUTF16(path), _retval);
|
return AddNamed(aBlob, path, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1633,17 +1610,14 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
|
||||||
nsCOMPtr<nsIRunnable> r;
|
nsCOMPtr<nsIRunnable> r;
|
||||||
|
|
||||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, aPath);
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, aPath);
|
||||||
if (!DeviceStorageFile::IsType(dsf->mFile, mStorageType) || !IsMimeTypeCorrectForStorageType(mStorageType, aBlob)) {
|
|
||||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE, dsf);
|
if (!dsf->IsSafePath()) {
|
||||||
}
|
|
||||||
else if (!dsf->IsSafePath()) {
|
|
||||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_WRITE,
|
r = new DeviceStorageRequest(DeviceStorageRequest::DEVICE_STORAGE_REQUEST_WRITE,
|
||||||
win, mPrincipal, dsf, request, aBlob);
|
win, mPrincipal, dsf, request, aBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_DispatchToMainThread(r);
|
NS_DispatchToMainThread(r);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -1693,6 +1667,7 @@ nsDOMDeviceStorage::GetInternal(const JS::Value & aPath,
|
||||||
|
|
||||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, path);
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType, mRootDirectory, path);
|
||||||
dsf->SetEditable(aEditable);
|
dsf->SetEditable(aEditable);
|
||||||
|
|
||||||
if (!dsf->IsSafePath()) {
|
if (!dsf->IsSafePath()) {
|
||||||
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_FILE_NAME, dsf);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2158,4 +2133,4 @@ nsDOMDeviceStorage::GetJSContextForEventHandlers()
|
||||||
return nsDOMEventTargetHelper::GetJSContextForEventHandlers();
|
return nsDOMEventTargetHelper::GetJSContextForEventHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_EVENT_HANDLER(nsDOMDeviceStorage, change)
|
NS_IMPL_EVENT_HANDLER(nsDOMDeviceStorage, change)
|
|
@ -33,7 +33,6 @@ class nsPIDOMWindow;
|
||||||
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "File location is not enumerable"
|
#define POST_ERROR_EVENT_FILE_NOT_ENUMERABLE "File location is not enumerable"
|
||||||
#define POST_ERROR_EVENT_PERMISSION_DENIED "Permission Denied"
|
#define POST_ERROR_EVENT_PERMISSION_DENIED "Permission Denied"
|
||||||
#define POST_ERROR_EVENT_ILLEGAL_FILE_NAME "Illegal file name"
|
#define POST_ERROR_EVENT_ILLEGAL_FILE_NAME "Illegal file name"
|
||||||
#define POST_ERROR_EVENT_ILLEGAL_TYPE "Illegal content type"
|
|
||||||
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
#define POST_ERROR_EVENT_UNKNOWN "Unknown"
|
||||||
#define POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED "Non-string type unsupported"
|
#define POST_ERROR_EVENT_NON_STRING_TYPE_UNSUPPORTED "Non-string type unsupported"
|
||||||
#define POST_ERROR_EVENT_NOT_IMPLEMENTED "Not implemented"
|
#define POST_ERROR_EVENT_NOT_IMPLEMENTED "Not implemented"
|
||||||
|
@ -58,6 +57,7 @@ public:
|
||||||
// we want to make sure that the names of file can't reach
|
// we want to make sure that the names of file can't reach
|
||||||
// outside of the type of storage the user asked for.
|
// outside of the type of storage the user asked for.
|
||||||
bool IsSafePath();
|
bool IsSafePath();
|
||||||
|
bool IsType(nsAString& aType);
|
||||||
|
|
||||||
nsresult Remove();
|
nsresult Remove();
|
||||||
nsresult Write(nsIInputStream* aInputStream);
|
nsresult Write(nsIInputStream* aInputStream);
|
||||||
|
@ -65,8 +65,7 @@ public:
|
||||||
void CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, uint64_t aSince = 0);
|
void CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, uint64_t aSince = 0);
|
||||||
void collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, uint64_t aSince, nsAString& aRootPath);
|
void collectFilesInternal(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles, uint64_t aSince, nsAString& aRootPath);
|
||||||
|
|
||||||
static bool IsType(nsIFile* aFile, const nsAString& aStorageType);
|
static void DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar);
|
||||||
static void DirectoryDiskUsage(nsIFile* aFile, uint64_t* aSoFar, const nsAString& aStorageType);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void NormalizeFilePath();
|
void NormalizeFilePath();
|
||||||
|
|
|
@ -10,17 +10,12 @@ relativesrcdir = dom/devicestorage/test/
|
||||||
|
|
||||||
include $(DEPTH)/config/autoconf.mk
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
# man, our mime database sucks hard. followup bug # 788273
|
|
||||||
# test_add.html \
|
|
||||||
|
|
||||||
MOCHITEST_FILES = \
|
MOCHITEST_FILES = \
|
||||||
test_sanity.html \
|
test_sanity.html \
|
||||||
test_addCorrectType.html \
|
|
||||||
test_basic.html \
|
test_basic.html \
|
||||||
test_enumerate.html \
|
test_enumerate.html \
|
||||||
test_enumerateMultipleContinue.html \
|
test_enumerateMultipleContinue.html \
|
||||||
test_overwrite.html \
|
test_overwrite.html \
|
||||||
test_diskSpace.html \
|
|
||||||
test_dotdot.html \
|
test_dotdot.html \
|
||||||
test_enumerateOptions.html \
|
test_enumerateOptions.html \
|
||||||
test_lastModificationFilter.html \
|
test_lastModificationFilter.html \
|
||||||
|
|
|
@ -54,8 +54,8 @@ function getRandomBuffer() {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRandomBlob(mime) {
|
function createRandomBlob() {
|
||||||
return blob = new Blob([getRandomBuffer()], {type: mime});
|
return blob = new Blob([getRandomBuffer()], {type: 'binary/random'});
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomFilename(l) {
|
function randomFilename(l) {
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
<!--
|
|
||||||
Any copyright is dedicated to the Public Domain.
|
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/
|
|
||||||
-->
|
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
<!--
|
|
||||||
https://bugzilla.mozilla.org/show_bug.cgi?id=786922
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<title>Test for basic sanity of the device storage API </title>
|
|
||||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
||||||
<script type="text/javascript" src="devicestorage_common.js"></script>
|
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=786922">Mozilla Bug 786922</a>
|
|
||||||
<p id="display"></p>
|
|
||||||
<div id="content" style="display: none">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<pre id="test">
|
|
||||||
<script class="testbody" type="text/javascript">
|
|
||||||
|
|
||||||
|
|
||||||
devicestorage_setup();
|
|
||||||
|
|
||||||
function add(storage, mime) {
|
|
||||||
dump("adding: " + mime + "\n");
|
|
||||||
return navigator.getDeviceStorage(storage).add(createRandomBlob(mime));
|
|
||||||
}
|
|
||||||
|
|
||||||
var tests = [
|
|
||||||
function () { return add("pictures", "image/png")},
|
|
||||||
function () { return add("videos", "video/webm")},
|
|
||||||
function () { return add("music", "audio/wav")},
|
|
||||||
];
|
|
||||||
|
|
||||||
function fail(e) {
|
|
||||||
ok(false, "onerror was called");
|
|
||||||
devicestorage_cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
function next(e) {
|
|
||||||
|
|
||||||
if (e != undefined)
|
|
||||||
ok(true, "addError was called");
|
|
||||||
|
|
||||||
var f = tests.pop();
|
|
||||||
|
|
||||||
if (f == undefined) {
|
|
||||||
devicestorage_cleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
request = f();
|
|
||||||
request.onsuccess = next;
|
|
||||||
request.onerror = fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</pre>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
<!--
|
|
||||||
Any copyright is dedicated to the Public Domain.
|
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/
|
|
||||||
-->
|
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html>
|
|
||||||
<!--
|
|
||||||
https://bugzilla.mozilla.org/show_bug.cgi?id=786922
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<title>Test for basic sanity of the device storage API </title>
|
|
||||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
||||||
<script type="text/javascript" src="devicestorage_common.js"></script>
|
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=786922">Mozilla Bug 786922</a>
|
|
||||||
<p id="display"></p>
|
|
||||||
<div id="content" style="display: none">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<pre id="test">
|
|
||||||
<script class="testbody" type="text/javascript">
|
|
||||||
|
|
||||||
|
|
||||||
devicestorage_setup();
|
|
||||||
|
|
||||||
function addNamed(storage, mime, fileExtension) {
|
|
||||||
dump("adding: " + mime + " " + fileExtension + "\n");
|
|
||||||
return navigator.getDeviceStorage(storage).addNamed(createRandomBlob(mime), randomFilename(40) + "." + fileExtension);
|
|
||||||
}
|
|
||||||
|
|
||||||
// These tests must all fail
|
|
||||||
var tests = [
|
|
||||||
function () { return addNamed("pictures", "kyle/smash", ".png")},
|
|
||||||
function () { return addNamed("pictures", "image/png", ".poo")},
|
|
||||||
function () { return addNamed("music", "kyle/smash", ".mp3")},
|
|
||||||
function () { return addNamed("music", "music/mp3", ".poo")},
|
|
||||||
function () { return addNamed("videos", "kyle/smash", ".ogv")},
|
|
||||||
function () { return addNamed("videos", "video/ogv", ".poo")},
|
|
||||||
];
|
|
||||||
|
|
||||||
function fail(e) {
|
|
||||||
ok(false, "addSuccess was called");
|
|
||||||
devicestorage_cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
function next(e) {
|
|
||||||
|
|
||||||
if (e != undefined)
|
|
||||||
ok(true, "addError was called");
|
|
||||||
|
|
||||||
var f = tests.pop();
|
|
||||||
|
|
||||||
if (f == undefined) {
|
|
||||||
devicestorage_cleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
request = f();
|
|
||||||
request.onsuccess = fail;
|
|
||||||
request.onerror = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</pre>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ function unload() {
|
||||||
|
|
||||||
devicestorage_setup();
|
devicestorage_setup();
|
||||||
|
|
||||||
var gFileName = "devicestorage/hi.png";
|
var gFileName = "devicestorage/hi";
|
||||||
var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies."
|
var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies."
|
||||||
var gDataBlob = new Blob([gData], {type: 'image/png'});
|
var gDataBlob = new Blob([gData], {type: 'text/plain'});
|
||||||
var gFileReader = new FileReader();
|
var gFileReader = new FileReader();
|
||||||
|
|
||||||
function getAfterDeleteSuccess(e) {
|
function getAfterDeleteSuccess(e) {
|
||||||
|
@ -53,7 +53,7 @@ function deleteSuccess(e) {
|
||||||
ok(e.target.result == gFileName, "File name should match");
|
ok(e.target.result == gFileName, "File name should match");
|
||||||
dump(e.target.result + "\n")
|
dump(e.target.result + "\n")
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
request = storage.get(e.target.result);
|
request = storage.get(e.target.result);
|
||||||
request.onsuccess = getAfterDeleteSuccess;
|
request.onsuccess = getAfterDeleteSuccess;
|
||||||
request.onerror = getAfterDeleteError;
|
request.onerror = getAfterDeleteError;
|
||||||
|
@ -66,7 +66,7 @@ function deleteError(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSuccess(e) {
|
function getSuccess(e) {
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
|
|
||||||
ok(e.target.result.name == gFileName, "File name should match");
|
ok(e.target.result.name == gFileName, "File name should match");
|
||||||
|
@ -101,7 +101,7 @@ function addSuccess(e) {
|
||||||
|
|
||||||
ok(e.target.result == gFileName, "File name should match");
|
ok(e.target.result == gFileName, "File name should match");
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
request = storage.get(gFileName);
|
request = storage.get(gFileName);
|
||||||
request.onsuccess = getSuccess;
|
request.onsuccess = getSuccess;
|
||||||
request.onerror = getError;
|
request.onerror = getError;
|
||||||
|
@ -116,10 +116,10 @@ function addError(e) {
|
||||||
|
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(storage, "Should have gotten a storage");
|
ok(storage, "Should have gotten a storage");
|
||||||
|
|
||||||
request = storage.addNamed(gDataBlob, "devicestorage/hi.png");
|
request = storage.addNamed(gDataBlob, "devicestorage/hi");
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
|
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
<!--
|
|
||||||
Any copyright is dedicated to the Public Domain.
|
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/
|
|
||||||
-->
|
|
||||||
<!DOCTYPE HTML>
|
|
||||||
<html> <!--
|
|
||||||
https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
|
||||||
-->
|
|
||||||
<head>
|
|
||||||
<title>Test for the device storage API </title>
|
|
||||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
||||||
<script type="text/javascript" src="devicestorage_common.js"></script>
|
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
|
|
||||||
<p id="display"></p>
|
|
||||||
<div id="content" style="display: none">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<pre id="test">
|
|
||||||
<script class="testbody" type="text/javascript">
|
|
||||||
|
|
||||||
devicestorage_setup();
|
|
||||||
|
|
||||||
|
|
||||||
var freeBytes = -1;
|
|
||||||
var stats = 0;
|
|
||||||
|
|
||||||
function stat(s, file_list_length) {
|
|
||||||
if (freeBytes == -1) {
|
|
||||||
freeBytes = s.target.result.freeBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok(freeBytes == s.target.result.freeBytes, "Free bytes should be the same");
|
|
||||||
ok(file_list_length * 1024 == s.target.result.totalBytes, "space taken up by files should match")
|
|
||||||
|
|
||||||
stats = stats + 1;
|
|
||||||
|
|
||||||
if (stats == 2) {
|
|
||||||
devicestorage_cleanup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addSuccess(e) {
|
|
||||||
added = added - 1;
|
|
||||||
|
|
||||||
if (added == 0) {
|
|
||||||
request = pictures.stat();
|
|
||||||
request.onsuccess = function(s) {stat(s, picture_files.length)};
|
|
||||||
|
|
||||||
request = videos.stat();
|
|
||||||
request.onsuccess = function(s) {stat(s, video_files.length)};
|
|
||||||
|
|
||||||
request = music.stat();
|
|
||||||
request.onsuccess = function(s) {stat(s, music_files.length)};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addError(e) {
|
|
||||||
ok(false, "addError was called : " + e.target.error.name);
|
|
||||||
devicestorage_cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
ok(true, "hi");
|
|
||||||
|
|
||||||
var pictures = navigator.getDeviceStorage("pictures");
|
|
||||||
var picture_files = [ "a.png", "b.png", "c.png", "d.png", "e.png" ];
|
|
||||||
|
|
||||||
var videos = navigator.getDeviceStorage("videos");
|
|
||||||
var video_files = [ "a.ogv", "b.ogv" ];
|
|
||||||
|
|
||||||
var music = navigator.getDeviceStorage("music");
|
|
||||||
var music_files = [ "a.mp3", "b.mp3", "c.mp3" ];
|
|
||||||
|
|
||||||
var added = picture_files.length + video_files.length + music_files.length;
|
|
||||||
|
|
||||||
for (var i=0; i < picture_files.length; i++) {
|
|
||||||
request = pictures.addNamed(createRandomBlob('image/png'), picture_files[i]);
|
|
||||||
request.onsuccess = addSuccess;
|
|
||||||
request.onerror = addError;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i=0; i < video_files.length; i++) {
|
|
||||||
request = videos.addNamed(createRandomBlob('video/ogv'), video_files[i]);
|
|
||||||
request.onsuccess = addSuccess;
|
|
||||||
request.onerror = addError;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i=0; i < music_files.length; i++) {
|
|
||||||
request = music.addNamed(createRandomBlob('audio/mp3'), music_files[i]);
|
|
||||||
request.onsuccess = addSuccess;
|
|
||||||
request.onerror = addError;
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</pre>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -25,17 +25,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||||
devicestorage_setup();
|
devicestorage_setup();
|
||||||
|
|
||||||
function testingStorage() {
|
function testingStorage() {
|
||||||
return navigator.getDeviceStorage("pictures");
|
return navigator.getDeviceStorage("testing");
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
function () { return testingStorage().addNamed(createRandomBlob('image/png'), gFileName); },
|
function () { return testingStorage().addNamed(createRandomBlob(), gFileName); },
|
||||||
function () { return testingStorage().delete(gFileName); },
|
function () { return testingStorage().delete(gFileName); },
|
||||||
function () { return testingStorage().get(gFileName); },
|
function () { return testingStorage().get(gFileName); },
|
||||||
function () { var r = testingStorage().enumerate("../"); return r; }
|
function () { var r = testingStorage().enumerate("../"); return r; }
|
||||||
];
|
];
|
||||||
|
|
||||||
var gFileName = "../owned.png";
|
var gFileName = "../owned";
|
||||||
|
|
||||||
function fail(e) {
|
function fail(e) {
|
||||||
ok(false, "addSuccess was called");
|
ok(false, "addSuccess was called");
|
||||||
|
|
|
@ -67,17 +67,17 @@ function addError(e) {
|
||||||
devicestorage_cleanup();
|
devicestorage_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
var prefix = "devicestorage/" + randomFilename(12) + ".png"
|
var prefix = "devicestorage/" + randomFilename(12)
|
||||||
|
|
||||||
var files = [ "a.png", "b.png", "c.png", "d/a.png", "d/b.png", "d/c.png", "d/d.png", "The/quick/brown/fox/jumps/over/the/lazy/dog.png"]
|
var files = [ "a", "b", "c", "d/a", "d/b", "d/c", "d/d", "The/quick/brown/fox/jumps/over/the/lazy/dog"]
|
||||||
var addedSoFar = 0;
|
var addedSoFar = 0;
|
||||||
|
|
||||||
|
|
||||||
for (var i=0; i<files.length; i++) {
|
for (var i=0; i<files.length; i++) {
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
|
request = storage.addNamed(createRandomBlob(), prefix + '/' + files[i]);
|
||||||
|
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
|
|
|
@ -30,7 +30,7 @@ function enumerateSuccess(e) {
|
||||||
function enumerateFailure(e) {
|
function enumerateFailure(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var cursor = navigator.getDeviceStorage("pictures").enumerate();
|
var cursor = navigator.getDeviceStorage("testing").enumerate();
|
||||||
cursor.onsuccess = enumerateSuccess;
|
cursor.onsuccess = enumerateSuccess;
|
||||||
cursor.onerror = enumerateFailure;
|
cursor.onerror = enumerateFailure;
|
||||||
|
|
||||||
|
|
|
@ -71,17 +71,17 @@ function addError(e) {
|
||||||
devicestorage_cleanup();
|
devicestorage_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
var prefix = "devicestorage/" + randomFilename(12)
|
var prefix = "devicestorage/" + randomFilename(12)
|
||||||
|
|
||||||
var files = [ "a.png", "b.png", "c.png" ]
|
var files = [ "a", "b", "c" ]
|
||||||
var addedSoFar = 0;
|
var addedSoFar = 0;
|
||||||
|
|
||||||
|
|
||||||
for (var i=0; i<files.length; i++) {
|
for (var i=0; i<files.length; i++) {
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
|
request = storage.addNamed(createRandomBlob(), prefix + '/' + files[i]);
|
||||||
|
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
|
|
|
@ -25,7 +25,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||||
|
|
||||||
devicestorage_setup()
|
devicestorage_setup()
|
||||||
|
|
||||||
storage = navigator.getDeviceStorage("pictures");
|
storage = navigator.getDeviceStorage("testing");
|
||||||
|
|
||||||
|
|
||||||
throws = false;
|
throws = false;
|
||||||
|
|
|
@ -44,7 +44,7 @@ function verifyAndDelete(prefix, files, e) {
|
||||||
files.remove(index);
|
files.remove(index);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
var cleanup = storage.delete(prefix + "/" + filename);
|
var cleanup = storage.delete(prefix + "/" + filename);
|
||||||
cleanup.onsuccess = function(e) {}
|
cleanup.onsuccess = function(e) {}
|
||||||
}
|
}
|
||||||
|
@ -76,15 +76,15 @@ devicestorage_setup();
|
||||||
|
|
||||||
var prefix = "devicestorage/" + randomFilename(12)
|
var prefix = "devicestorage/" + randomFilename(12)
|
||||||
|
|
||||||
var oldFiles = ["a.png", "b.png", "c.png"];
|
var oldFiles = ["a", "b", "c"];
|
||||||
var newFiles = ["d.png", "e.png", "f.png"];
|
var newFiles = ["d", "e", "f"];
|
||||||
|
|
||||||
// 157795200 is a long long time ago.
|
// 157795200 is a long long time ago.
|
||||||
addFiles(prefix, oldFiles, 157795200, addNewFiles);
|
addFiles(prefix, oldFiles, 157795200, addNewFiles);
|
||||||
|
|
||||||
function enumerateNew() {
|
function enumerateNew() {
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
|
|
||||||
// 836031600 is a long time ago
|
// 836031600 is a long time ago
|
||||||
|
|
|
@ -23,7 +23,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||||
<pre id="test">
|
<pre id="test">
|
||||||
<script class="testbody" type="text/javascript">
|
<script class="testbody" type="text/javascript">
|
||||||
|
|
||||||
var filename = "devicestorage/aaaa.png"
|
var filename = "devicestorage/aaaa"
|
||||||
|
|
||||||
devicestorage_setup();
|
devicestorage_setup();
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ function addOverwritingSuccess(e) {
|
||||||
function addOverwritingError(e) {
|
function addOverwritingError(e) {
|
||||||
ok(true, "Adding to the same location should fail");
|
ok(true, "Adding to the same location should fail");
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
request = storage.delete(filename)
|
request = storage.delete(filename)
|
||||||
request.onsuccess = deleteSuccess;
|
request.onsuccess = deleteSuccess;
|
||||||
request.onerror = deleteError;
|
request.onerror = deleteError;
|
||||||
|
@ -54,10 +54,10 @@ function addOverwritingError(e) {
|
||||||
function addSuccess(e) {
|
function addSuccess(e) {
|
||||||
ok(true, "addSuccess was called");
|
ok(true, "addSuccess was called");
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), filename);
|
request = storage.addNamed(createRandomBlob(), filename);
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
|
|
||||||
request.onsuccess = addOverwritingSuccess;
|
request.onsuccess = addOverwritingSuccess;
|
||||||
|
@ -66,16 +66,16 @@ function addSuccess(e) {
|
||||||
|
|
||||||
function addError(e) {
|
function addError(e) {
|
||||||
// test file is already exists. clean it up and try again..
|
// test file is already exists. clean it up and try again..
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
request = storage.delete(filename)
|
request = storage.delete(filename)
|
||||||
request.onsuccess = runtest;
|
request.onsuccess = runtest;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runtest() {
|
function runtest() {
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), filename);
|
request = storage.addNamed(createRandomBlob(), filename);
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
|
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
|
|
|
@ -38,14 +38,8 @@ ok(throws, "getDeviceStorage takes one arg");
|
||||||
storage = navigator.getDeviceStorage("kilimanjaro");
|
storage = navigator.getDeviceStorage("kilimanjaro");
|
||||||
ok(!storage, "kilimanjaro - Should not have this type of storage");
|
ok(!storage, "kilimanjaro - Should not have this type of storage");
|
||||||
|
|
||||||
storage = navigator.getDeviceStorage("pictures");
|
storage = navigator.getDeviceStorage("testing");
|
||||||
ok(storage, "pictures - Should have getDeviceStorage");
|
ok(storage, "testing - Should have getDeviceStorage");
|
||||||
|
|
||||||
storage = navigator.getDeviceStorage("music");
|
|
||||||
ok(storage, "music - Should have getDeviceStorage");
|
|
||||||
|
|
||||||
storage = navigator.getDeviceStorage("videos");
|
|
||||||
ok(storage, "videos - Should have getDeviceStorage");
|
|
||||||
|
|
||||||
var cursor = storage.enumerate();
|
var cursor = storage.enumerate();
|
||||||
ok(cursor, "Should have a non-null cursor");
|
ok(cursor, "Should have a non-null cursor");
|
||||||
|
|
|
@ -35,7 +35,7 @@ function statError(e) {
|
||||||
devicestorage_cleanup();
|
devicestorage_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
||||||
|
|
||||||
function addError(e) {
|
function addError(e) {
|
||||||
|
@ -51,7 +51,7 @@ function addSuccess(e) {
|
||||||
request.onerror = statError;
|
request.onerror = statError;
|
||||||
}
|
}
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), "a/b.png");
|
request = storage.addNamed(createRandomBlob(), "a/b");
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
request.onerror = addError;
|
request.onerror = addError;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||||
|
|
||||||
devicestorage_setup();
|
devicestorage_setup();
|
||||||
|
|
||||||
var gFileName = randomFilename(20) + ".png"
|
var gFileName = randomFilename(20);
|
||||||
|
|
||||||
function addSuccess(e) {
|
function addSuccess(e) {
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,11 @@ function onChange(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(storage, "Should have storage");
|
ok(storage, "Should have storage");
|
||||||
storage.addEventListener("change", onChange);
|
storage.addEventListener("change", onChange);
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), gFileName);
|
request = storage.addNamed(createRandomBlob(), gFileName);
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
|
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
|
|
|
@ -24,7 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
|
||||||
|
|
||||||
devicestorage_setup();
|
devicestorage_setup();
|
||||||
|
|
||||||
var gFileName = randomFilename(20) + ".png"
|
var gFileName = randomFilename(20);
|
||||||
|
|
||||||
function addSuccess(e) {
|
function addSuccess(e) {
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,15 @@ function onChangeFail(e) {
|
||||||
ok(false, "We should never see any changes");
|
ok(false, "We should never see any changes");
|
||||||
}
|
}
|
||||||
|
|
||||||
var storage = navigator.getDeviceStorage("pictures");
|
var storage = navigator.getDeviceStorage("testing");
|
||||||
ok(storage, "Should have storage");
|
ok(storage, "Should have storage");
|
||||||
storage.addEventListener("change", onChange);
|
storage.addEventListener("change", onChange);
|
||||||
|
|
||||||
var storageOther = navigator.getDeviceStorage("music");
|
var storageOther = navigator.getDeviceStorage("testing-other");
|
||||||
ok(storageOther, "Should have storage");
|
ok(storageOther, "Should have storage");
|
||||||
storageOther.addEventListener("change", onChangeFail);
|
storageOther.addEventListener("change", onChangeFail);
|
||||||
|
|
||||||
request = storage.addNamed(createRandomBlob('image/png'), gFileName);
|
request = storage.addNamed(createRandomBlob(), gFileName);
|
||||||
ok(request, "Should have a non-null request");
|
ok(request, "Should have a non-null request");
|
||||||
|
|
||||||
request.onsuccess = addSuccess;
|
request.onsuccess = addSuccess;
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
pictures=*.jpe; *.jpg; *.jpeg; *.gif; *.png; *.bmp;
|
|
||||||
music=*.mp3; *.ogg; *.m4a; *.m4b; *.m4p; *.m4v; *.m4r; *.3gp; *.mp4; *.aac;
|
|
||||||
videos=*.avi; *.divx; *.flv; *.m4v; *.mkv; *.mov; *.mp4; *.mpeg; *.mpg; *.ogm; *.ogv; *.ogx; *.rm; *.rmvb; *.smil; *.webm; *.wmv; *.xvid
|
|
|
@ -28,7 +28,6 @@ toolkit.jar:
|
||||||
content/global/customizeToolbar.css (customizeToolbar.css)
|
content/global/customizeToolbar.css (customizeToolbar.css)
|
||||||
* content/global/customizeToolbar.js (customizeToolbar.js)
|
* content/global/customizeToolbar.js (customizeToolbar.js)
|
||||||
content/global/customizeToolbar.xul (customizeToolbar.xul)
|
content/global/customizeToolbar.xul (customizeToolbar.xul)
|
||||||
content/global/devicestorage.properties (devicestorage.properties)
|
|
||||||
content/global/editMenuOverlay.js (editMenuOverlay.js)
|
content/global/editMenuOverlay.js (editMenuOverlay.js)
|
||||||
*+ content/global/editMenuOverlay.xul (editMenuOverlay.xul)
|
*+ content/global/editMenuOverlay.xul (editMenuOverlay.xul)
|
||||||
content/global/finddialog.js (finddialog.js)
|
content/global/finddialog.js (finddialog.js)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче