Bug 740485 - Implement Device Storage. r=sicking

This commit is contained in:
Doug Turner 2012-05-21 09:18:30 -07:00
parent 5d63586521
commit a1636519c8
31 changed files with 2077 additions and 7 deletions

View File

@ -164,6 +164,7 @@
@BINPATH@/components/dom_contacts.xpt
@BINPATH@/components/dom_core.xpt
@BINPATH@/components/dom_css.xpt
@BINPATH@/components/dom_devicestorage.xpt
@BINPATH@/components/dom_events.xpt
@BINPATH@/components/dom_geolocation.xpt
@BINPATH@/components/dom_network.xpt

View File

@ -168,6 +168,7 @@
@BINPATH@/components/dom_contacts.xpt
@BINPATH@/components/dom_core.xpt
@BINPATH@/components/dom_css.xpt
@BINPATH@/components/dom_devicestorage.xpt
@BINPATH@/components/dom_events.xpt
@BINPATH@/components/dom_geolocation.xpt
@BINPATH@/components/dom_network.xpt

View File

@ -1179,6 +1179,7 @@ xpicleanup@BIN_SUFFIX@
components/dom_css.xpt
components/dom_events.xpt
components/dom_geolocation.xpt
components/dom_devicestorage.xpt
components/dom_html.xpt
components/dom_json.xpt
components/dom_loadsave.xpt

View File

@ -132,7 +132,7 @@ public:
// Create as a blob
nsDOMFileFile(nsIFile *aFile, const nsAString& aContentType,
nsISupports *aCacheToken = nsnull)
nsISupports *aCacheToken)
: nsDOMFileBase(aContentType, UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(false),
mCacheToken(aCacheToken)
@ -140,6 +140,17 @@ public:
NS_ASSERTION(mFile, "must have file");
}
// Create as a file with custom name
nsDOMFileFile(nsIFile *aFile, const nsAString& aName)
: nsDOMFileBase(EmptyString(), EmptyString(), UINT64_MAX),
mFile(aFile), mWholeFile(true), mStoredFile(false)
{
NS_ASSERTION(mFile, "must have file");
// Lazily get the content type and size
mContentType.SetIsVoid(true);
mName.Assign(aName);
}
// Create as a stored file
nsDOMFileFile(const nsAString& aName, const nsAString& aContentType,
PRUint64 aLength, nsIFile* aFile,

View File

@ -16,6 +16,7 @@ DIRS = \
interfaces/base \
interfaces/canvas \
interfaces/core \
interfaces/devicestorage \
interfaces/html \
interfaces/events \
interfaces/contacts \
@ -48,6 +49,7 @@ DIRS += \
bindings \
battery \
contacts \
devicestorage \
power \
settings \
sms \

View File

@ -20,11 +20,6 @@ namespace dom {
class DOMRequest : public nsDOMEventTargetHelper,
public nsIDOMDOMRequest
{
bool mDone;
jsval mResult;
nsCOMPtr<nsIDOMDOMError> mError;
bool mRooted;
NS_DECL_EVENT_HANDLER(success)
NS_DECL_EVENT_HANDLER(error)
@ -46,6 +41,11 @@ public:
UnrootResultVal();
}
bool mDone;
jsval mResult;
nsCOMPtr<nsIDOMDOMError> mError;
bool mRooted;
private:
void FireEvent(const nsAString& aType);

View File

@ -13,6 +13,7 @@
#include "nsMimeTypeArray.h"
#include "nsDesktopNotification.h"
#include "nsGeolocation.h"
#include "nsDeviceStorage.h"
#include "nsIHttpProtocolHandler.h"
#include "nsICachingChannel.h"
#include "nsIDocShell.h"
@ -89,6 +90,7 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNavigator)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigator)
NS_INTERFACE_MAP_ENTRY(nsIDOMClientInformation)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDeviceStorage)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorGeolocation)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorBattery)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDesktopNotification)
@ -839,6 +841,26 @@ Navigator::MozIsLocallyAvailable(const nsAString &aURI,
return httpChannel->GetRequestSucceeded(aIsAvailable);
}
//*****************************************************************************
// Navigator::nsIDOMNavigatorDeviceStorage
//*****************************************************************************
NS_IMETHODIMP Navigator::GetDeviceStorage(const nsAString &aType, nsIVariant** _retval)
{
if (!Preferences::GetBool("device.storage.enabled", false)) {
return NS_OK;
}
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
if (!win || !win->GetOuterWindow() || !win->GetDocShell()) {
return NS_ERROR_FAILURE;
}
nsDOMDeviceStorage::CreateDeviceStoragesFor(win, aType, _retval);
return NS_OK;
}
//*****************************************************************************
// Navigator::nsIDOMNavigatorGeolocation
//*****************************************************************************

View File

@ -9,6 +9,7 @@
#include "nsIDOMNavigator.h"
#include "nsIDOMNavigatorGeolocation.h"
#include "nsIDOMNavigatorDeviceStorage.h"
#include "nsIDOMNavigatorDesktopNotification.h"
#include "nsIDOMClientInformation.h"
#include "nsIDOMNavigatorBattery.h"
@ -60,6 +61,7 @@ class PowerManager;
class Navigator : public nsIDOMNavigator
, public nsIDOMClientInformation
, public nsIDOMNavigatorDeviceStorage
, public nsIDOMNavigatorGeolocation
, public nsIDOMNavigatorDesktopNotification
, public nsIDOMMozNavigatorBattery
@ -79,6 +81,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMNAVIGATOR
NS_DECL_NSIDOMCLIENTINFORMATION
NS_DECL_NSIDOMNAVIGATORDEVICESTORAGE
NS_DECL_NSIDOMNAVIGATORGEOLOCATION
NS_DECL_NSIDOMNAVIGATORDESKTOPNOTIFICATION
NS_DECL_NSIDOMMOZNAVIGATORBATTERY

View File

@ -414,6 +414,10 @@
// Storage includes
#include "nsDOMStorage.h"
// Device Storage
#include "nsIDOMDeviceStorage.h"
#include "nsIDOMDeviceStorageCursor.h"
// Drag and drop
#include "nsIDOMDataTransfer.h"
@ -434,6 +438,7 @@
#include "nsIDOMDesktopNotification.h"
#include "nsIDOMNavigatorDesktopNotification.h"
#include "nsIDOMNavigatorDeviceStorage.h"
#include "nsIDOMNavigatorGeolocation.h"
#include "Navigator.h"
@ -1394,6 +1399,12 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(MessageEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DeviceStorage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DeviceStorageCursor, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(GeoGeolocation, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -2431,6 +2442,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(Navigator, nsIDOMNavigator)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigator)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorDeviceStorage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorGeolocation)
DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(nsIDOMNavigatorDesktopNotification,
Navigator::HasDesktopNotificationSupport())
@ -4034,6 +4046,16 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DeviceStorage, nsIDOMDeviceStorage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceStorage)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DeviceStorageCursor, nsIDOMDeviceStorageCursor)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceStorageCursor)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMRequest)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(GeoGeolocation, nsIDOMGeoGeolocation)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMGeoGeolocation)
DOM_CLASSINFO_MAP_END

View File

@ -387,6 +387,9 @@ DOMCI_CLASS(DataContainerEvent)
// HTML5
DOMCI_CLASS(MessageEvent)
DOMCI_CLASS(DeviceStorage)
DOMCI_CLASS(DeviceStorageCursor)
// Geolocation
DOMCI_CLASS(GeoGeolocation)
DOMCI_CLASS(GeoPosition)

View File

@ -0,0 +1,40 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
LIBRARY_NAME = domdevicestorage_s
XPIDL_MODULE = dom_devicestorage
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
include $(topsrcdir)/dom/dom-config.mk
CPPSRCS = \
nsDeviceStorage.cpp \
$(NULL)
EXPORTS = \
nsDeviceStorage.h \
$(NULL)
LOCAL_INCLUDES = \
-I$(topsrcdir)/dom/base \
-I$(topsrcdir)/dom/ipc \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/events/src \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_LAYOUT

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsDeviceStorage_h
#define nsDeviceStorage_h
class nsPIDOMWindow;
#include "nsIClassInfo.h"
#include "nsIDOMDeviceStorage.h"
#include "nsIDOMDeviceStorageCursor.h"
#include "nsIDOMWindow.h"
#include "nsIURI.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDOMClassInfoID.h"
#include "nsString.h"
#include "nsWeakPtr.h"
#include "nsInterfaceHashtable.h"
class nsDOMDeviceStorage : public nsIDOMDeviceStorage
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMDEVICESTORAGE
nsDOMDeviceStorage();
nsresult Init(nsPIDOMWindow* aWindow, const nsAString &aType, const PRInt32 aIndex);
PRInt32 SetRootFileForType(const nsAString& aType, const PRInt32 aIndex);
static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin, const nsAString &aType, nsIVariant** _retval);
private:
~nsDOMDeviceStorage();
nsresult GetInternal(const JS::Value & aName, JSContext* aCx, nsIDOMDOMRequest * *_retval NS_OUTPARAM, bool aEditable);
nsresult EnumerateInternal(const nsAString & aName, nsIDOMDeviceStorageCursor * *_retval NS_OUTPARAM, bool aEditable);
PRInt32 mStorageType;
nsCOMPtr<nsIFile> mFile;
nsWeakPtr mOwner;
nsCOMPtr<nsIURI> mURI;
// nsIDOMDeviceStorage.type
enum {
DEVICE_STORAGE_TYPE_DEFAULT = 0,
DEVICE_STORAGE_TYPE_SHARED,
DEVICE_STORAGE_TYPE_EXTERNAL,
};
};
#endif

View File

@ -0,0 +1,26 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = dom
LIBRARY_NAME = domdevicestorage_s
XPIDL_MODULE = dom_devicestorage
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
include $(topsrcdir)/dom/dom-config.mk
XPIDLSRCS = \
nsIDOMDeviceStorage.idl \
nsIDOMDeviceStorageCursor.idl \
nsIDOMNavigatorDeviceStorage.idl
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,35 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "domstubs.idl"
interface nsIDOMBlob;
interface nsIDOMDOMRequest;
interface nsIDOMDeviceStorageCursor;
[scriptable, uuid(05C0D0C8-D698-4CCD-899C-7198A33BD7EC)]
interface nsIDOMDeviceStorage : nsISupports
{
/*
* Hint as to what kind of storage this object is.
* May be "external", "shared", or "default".
*/
readonly attribute DOMString type;
nsIDOMDOMRequest add(in nsIDOMBlob aBlob);
nsIDOMDOMRequest addNamed(in nsIDOMBlob aBlob, in DOMString aName);
[implicit_jscontext]
nsIDOMDOMRequest get(in jsval aName);
[implicit_jscontext]
nsIDOMDOMRequest getEditable(in jsval aName);
[implicit_jscontext]
nsIDOMDOMRequest delete(in jsval aName);
nsIDOMDeviceStorageCursor enumerate([optional] in DOMString directory);
nsIDOMDeviceStorageCursor enumerateEditable([optional] in DOMString directory);
};

View File

@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "domstubs.idl"
[scriptable, uuid(995DFF99-ED70-4780-AC9A-4B58CD491186)]
interface nsIDOMDeviceStorageCursor : nsISupports
{
void continue();
};

View File

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "domstubs.idl"
interface nsIVariant;
/**
* Property that extends the navigator object.
*/
[scriptable, uuid(A4B2831D-6065-472F-8A6D-2C9085C74C15)]
interface nsIDOMNavigatorDeviceStorage : nsISupports
{
// returns an array of nsIDOMDeviceStorage
nsIVariant getDeviceStorage(in DOMString type);
};

View File

@ -18,6 +18,7 @@ DIRS += \
ajax \
bugs \
chrome \
devicestorage \
general \
whatwg \
geolocation \

View File

@ -0,0 +1,27 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = dom/tests/mochitest/devicestorage
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_sanity.html \
test_basic.html \
test_enumerate.html \
test_enumerateMultipleContinue.html \
test_overwrite.html \
test_dotdot.html \
devicestorage_common.js \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

View File

@ -0,0 +1,48 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var oldVal = false;
function devicestorage_setup() {
SimpleTest.waitForExplicitFinish();
try {
oldVal = SpecialPowers.getBoolPref("device.storage.enabled");
} catch(e) {}
SpecialPowers.setBoolPref("device.storage.enabled", true);
SpecialPowers.setBoolPref("device.storage.testing", true);
SpecialPowers.setBoolPref("device.storage.prompt.testing", true);
}
function devicestorage_cleanup() {
SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
SpecialPowers.setBoolPref("device.storage.testing", false);
SpecialPowers.setBoolPref("device.storage.prompt.testing", false);
SimpleTest.finish();
}
function getRandomBuffer() {
var size = 1024;
var buffer = new ArrayBuffer(size);
var view = new Uint8Array(buffer);
for (var i = 0; i < size; i++) {
view[i] = parseInt(Math.random() * 255);
}
return buffer;
}
function createRandomBlob() {
return blob = new Blob([getRandomBuffer()], {type: 'binary/random'});
}
function randomFilename(l) {
var set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
var result = "";
for (var i=0; i<l; i++) {
var r = Math.floor(set.length * Math.random());
result += set.substring(r, r + 1);
}
return result;
}

View File

@ -0,0 +1,102 @@
<!--
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 gFileName = "devicestorage/hi";
function getAfterDeleteSuccess(e) {
ok(false, "file was deleted not successfully");
devicestorage_cleanup();
}
function getAfterDeleteError(e) {
ok(true, "file was deleted successfully");
devicestorage_cleanup();
}
function deleteSuccess(e) {
ok(e.target.result == gFileName, "File name should match");
var storage = navigator.getDeviceStorage("profile");
request = storage[0].get(e.target.result);
request.onsuccess = getAfterDeleteSuccess;
request.onerror = getAfterDeleteError;
}
function deleteError(e) {
ok(false, "deleteError was called : " + e.target.error.name);
devicestorage_cleanup();
}
function getSuccess(e) {
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
ok(e.target.result.name == gFileName, "File name should match");
request = storage[0].delete(e.target.result.name)
request.onsuccess = deleteSuccess;
request.onerror = deleteError;
}
function getError(e) {
ok(false, "getError was called : " + e.target.error.name);
SpecialPowers.setBoolPref("device.storage.enabled", oldVal);
SimpleTest.finish();
}
function addSuccess(e) {
ok(e.target.result == gFileName, "File name should match");
var storage = navigator.getDeviceStorage("profile");
request = storage[0].get(gFileName);
request.onsuccess = getSuccess;
request.onerror = getError;
ok(true, "addSuccess was called");
}
function addError(e) {
ok(false, "addError was called : " + e.target.error.name);
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage[0].addNamed(createRandomBlob(), "devicestorage/hi");
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;
request.onerror = addError;
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,72 @@
<!--
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();
function profileStorage() {
return navigator.getDeviceStorage("profile")[0];
}
var tests = [
function () { return profileStorage().addNamed(createRandomBlob(), gFileName); },
function () { return profileStorage().delete(gFileName); },
function () { return profileStorage().get(gFileName); },
function () { var r = profileStorage().enumerate("../"); return r; }
];
var gFileName = "../owned";
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;
}
var request = f();
request.onsuccess = fail;
request.onerror = next;
}
next();
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,101 @@
<!--
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">
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
devicestorage_setup();
function enumerateSuccess(e) {
if (e.target.result == null) {
ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array")
dump("We still have length = " + files.length);
devicestorage_cleanup();
return;
}
dump("asdfasdf"+ e.target.result + "\n");
dump("asdfasdf"+ e.target.result.name + "\n");
var filename = e.target.result.name;
var index = files.indexOf(filename);
files.remove(index);
ok(index > -1, "filename should be in the enumeration : " + e.target.result.name);
// clean up
var cleanup = storage[0].delete(prefix + "/" + filename);
cleanup.onsuccess = function(e) {} // todo - can i remove this?
e.target.continue();
}
function handleError(e) {
ok(false, "handleError was called : " + e.target.error.name);
devicestorage_cleanup();
}
function addSuccess(e) {
addedSoFar = addedSoFar + 1;
if (addedSoFar == files.length) {
var cursor = storage[0].enumerate(prefix);
cursor.onsuccess = enumerateSuccess;
cursor.onerror = handleError;
}
}
function addError(e) {
ok(false, "addError was called : " + e.target.error.name);
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var prefix = "devicestorage/" + randomFilename(12)
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;
for (var i=0; i<files.length; i++) {
request = storage[0].addNamed(createRandomBlob(), prefix + '/' + files[i]);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;
request.onerror = addError;
}
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,50 @@
<!--
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();
function enumerateSuccess(e) {
}
function enumerateFailure(e) {
}
var cursor = navigator.getDeviceStorage("profile")[0].enumerate();
cursor.onsuccess = enumerateSuccess;
cursor.onerror = enumerateFailure;
try {
cursor.continue();
}
catch (e) {
ok(true, "Calling continue before enumerateSuccess fires should throw");
devicestorage_cleanup();
}
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,95 @@
<!--
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">
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
devicestorage_setup();
function enumerateSuccess(e) {
if (e.target.result == null) {
ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array")
devicestorage_cleanup();
}
var filename = e.target.result.name;
var index = files.indexOf(filename);
files.remove(index);
ok(index > -1, "filename should be in the enumeration : " + e.target.result.name);
// clean up
var cleanup = storage[0].delete(prefix + "/" + filename);
cleanup.onsuccess = function(e) {} // todo - can i remove this?
e.target.continue();
}
function handleError(e) {
ok(false, "handleError was called : " + e.target.error.name);
devicestorage_cleanup();
}
function addSuccess(e) {
addedSoFar = addedSoFar + 1;
if (addedSoFar == files.length) {
var cursor = storage[0].enumerate();
cursor.onsuccess = enumerateSuccess;
cursor.onerror = handleError;
}
}
function addError(e) {
ok(false, "addError was called : " + e.target.error.name);
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var prefix = "devicestorage/" + randomFilename(12)
var files = [ "a", "b", "c" ]
var addedSoFar = 0;
for (var i=0; i<files.length; i++) {
request = storage[0].addNamed(createRandomBlob(), prefix + '/' + files[i]);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;
request.onerror = addError;
}
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,90 @@
<!--
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 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=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">
var filename = "devicestorage/aaaa"
devicestorage_setup();
function deleteSuccess(e) {
devicestorage_cleanup();
}
function deleteError(e) {
ok(false, "deleteError was called : " + e.target.error.name);
devicestorage_cleanup();
}
function addOverwritingSuccess(e) {
ok(false, "addOverwritingSuccess was called.");
}
function addOverwritingError(e) {
ok(true, "Adding to the same location should fail");
var storage = navigator.getDeviceStorage("profile");
request = storage[0].delete(filename)
request.onsuccess = deleteSuccess;
request.onerror = deleteError;
}
function addSuccess(e) {
ok(true, "addSuccess was called");
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage[0].addNamed(createRandomBlob(), filename);
ok(request, "Should have a non-null request");
request.onsuccess = addOverwritingSuccess;
request.onerror = addOverwritingError;
}
function addError(e) {
// test file is already exists. clean it up and try again..
var storage = navigator.getDeviceStorage("profile");
request = storage[0].delete(filename)
request.onsuccess = runtest;
}
function runtest() {
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage[0].addNamed(createRandomBlob(), filename);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;
request.onerror = addError;
}
runtest();
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,72 @@
<!--
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 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=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()
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var storage;
var throws = false;
try {
storage = navigator.getDeviceStorage();
} catch(e) {throws = true}
ok(throws, "getDeviceStorage takes one arg");
storage = navigator.getDeviceStorage("kilimanjaro");
ok(!storage, "kilimanjaro - Should not have this type of storage");
storage = navigator.getDeviceStorage("temp");
ok(storage, "temp - Should have getDeviceStorage");
storage = navigator.getDeviceStorage("profile");
ok(storage, "profile - Should have getDeviceStorage");
var cursor = storage[0].enumerate();
ok(cursor, "Should have a non-null cursor");
var i = 4;
cursor.onsuccess = function(e) {
i = i - 1;
if (i > 0) {
ok(true, "onsuccess was called");
e.target.continue();
}
else {
ok(true, "onsuccess was called 4 times");
devicestorage_cleanup();
}
}
cursor.onerror = function(e) {
ok(false, "onerror was called : " + e.target.error.name);
devicestorage_cleanup();
}
</script>
</pre>
</body>
</html>

View File

@ -62,6 +62,7 @@ SHARED_LIBRARY_LIBS = \
$(DEPTH)/dom/base/$(LIB_PREFIX)jsdombase_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/battery/$(LIB_PREFIX)dom_battery_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/contacts/$(LIB_PREFIX)jsdomcontacts_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/devicestorage/$(LIB_PREFIX)domdevicestorage_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/power/$(LIB_PREFIX)dom_power_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/settings/$(LIB_PREFIX)jsdomsettings_s.$(LIB_SUFFIX) \
$(DEPTH)/dom/network/src/$(LIB_PREFIX)dom_network_s.$(LIB_SUFFIX) \
@ -214,7 +215,7 @@ LOCAL_INCLUDES += -I$(srcdir)/../base \
-I$(srcdir)/../xul/base/src \
-I$(srcdir)/../mathml \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/content/canvas/src \
-I$(topsrcdir)/content/canvas/src \
-I$(topsrcdir)/content/html/content/src \
-I$(topsrcdir)/content/html/document/src \
-I$(topsrcdir)/content/xslt/src/base \

View File

@ -168,6 +168,7 @@
@BINPATH@/components/dom_canvas.xpt
@BINPATH@/components/dom_core.xpt
@BINPATH@/components/dom_css.xpt
@BINPATH@/components/dom_devicestorage.xpt
@BINPATH@/components/dom_events.xpt
@BINPATH@/components/dom_geolocation.xpt
@BINPATH@/components/dom_network.xpt

View File

@ -3463,6 +3463,9 @@ pref("geo.enabled", true);
// Enable/Disable the orientation API for content
pref("device.motion.enabled", true);
// Enable/Disable the device storage API for content
pref("device.storage.enabled", false);
// Toggle which thread the HTML5 parser uses for stream parsing
pref("html5.offmainthread", true);
// Time in milliseconds between the time a network buffer is seen and the

View File

@ -18,6 +18,7 @@ MAKEFILES_dom="
dom/interfaces/canvas/Makefile
dom/interfaces/core/Makefile
dom/interfaces/css/Makefile
dom/interfaces/devicestorage/Makefile
dom/interfaces/events/Makefile
dom/interfaces/geolocation/Makefile
dom/interfaces/html/Makefile