2012-05-21 20:18:30 +04:00
|
|
|
<!--
|
|
|
|
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>
|
2012-10-13 19:20:14 +04:00
|
|
|
<body>
|
2012-05-21 20:18:30 +04:00
|
|
|
<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();
|
|
|
|
|
2013-07-12 11:18:28 +04:00
|
|
|
var gFileName = "devicestorage/" + randomFilename(12) + "/hi.png";
|
2012-07-13 20:36:19 +04:00
|
|
|
var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies."
|
2012-09-06 01:30:36 +04:00
|
|
|
var gDataBlob = new Blob([gData], {type: 'image/png'});
|
2012-07-23 20:52:05 +04:00
|
|
|
var gFileReader = new FileReader();
|
2012-05-21 20:18:30 +04:00
|
|
|
|
|
|
|
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");
|
2012-07-13 20:36:19 +04:00
|
|
|
dump(e.target.result + "\n")
|
2012-05-21 20:18:30 +04:00
|
|
|
|
2012-09-06 01:30:36 +04:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-08-02 10:32:11 +04:00
|
|
|
request = storage.get(e.target.result);
|
2012-05-21 20:18:30 +04:00
|
|
|
request.onsuccess = getAfterDeleteSuccess;
|
|
|
|
request.onerror = getAfterDeleteError;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteError(e) {
|
|
|
|
ok(false, "deleteError was called : " + e.target.error.name);
|
|
|
|
devicestorage_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSuccess(e) {
|
2012-09-06 01:30:36 +04:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-05-21 20:18:30 +04:00
|
|
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
|
|
|
|
|
|
|
ok(e.target.result.name == gFileName, "File name should match");
|
2012-10-18 22:29:32 +04:00
|
|
|
ok(e.target.result.size > 0, "File size be greater than zero");
|
|
|
|
ok(e.target.result.type, "File should have a mime type");
|
|
|
|
ok(e.target.result.lastModifiedDate, "File should have a last modified date");
|
2012-05-21 20:18:30 +04:00
|
|
|
|
2012-07-13 20:36:19 +04:00
|
|
|
var name = e.target.result.name;
|
|
|
|
|
2012-07-23 20:52:05 +04:00
|
|
|
gFileReader.readAsArrayBuffer(gDataBlob);
|
|
|
|
gFileReader.onload = function(e) {
|
2012-07-13 20:36:19 +04:00
|
|
|
readerCallback(e);
|
|
|
|
|
2012-08-02 10:32:11 +04:00
|
|
|
request = storage.delete(name)
|
2012-07-13 20:36:19 +04:00
|
|
|
request.onsuccess = deleteSuccess;
|
|
|
|
request.onerror = deleteError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function readerCallback(e) {
|
|
|
|
|
|
|
|
ab = e.target.result;
|
|
|
|
|
|
|
|
is(ab.byteLength, gData.length, "wrong arraybuffer byteLength");
|
|
|
|
var u8v = new Uint8Array(ab);
|
|
|
|
is(String.fromCharCode.apply(String, u8v), gData, "wrong values");
|
2012-05-21 20:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getError(e) {
|
|
|
|
ok(false, "getError was called : " + e.target.error.name);
|
2012-07-13 20:36:19 +04:00
|
|
|
devicestorage_cleanup();
|
2012-05-21 20:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function addSuccess(e) {
|
|
|
|
|
2013-07-12 11:18:28 +04:00
|
|
|
var filename = e.target.result;
|
|
|
|
if (filename[0] == "/") {
|
|
|
|
// We got /storageName/prefix/filename
|
|
|
|
// Remove the storageName (this shows up on FirefoxOS)
|
|
|
|
filename = filename.substring(1); // Remove leading slash
|
|
|
|
var slashIndex = filename.indexOf("/");
|
|
|
|
if (slashIndex >= 0) {
|
|
|
|
filename = filename.substring(slashIndex + 1); // Remove storageName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(filename == gFileName, "File name should match");
|
|
|
|
|
|
|
|
// Update gFileName to be the fully qualified name so that
|
|
|
|
// further checks will pass.
|
|
|
|
gFileName = e.target.result;
|
2012-05-21 20:18:30 +04:00
|
|
|
|
2012-09-06 01:30:36 +04:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-08-02 10:32:11 +04:00
|
|
|
request = storage.get(gFileName);
|
2012-05-21 20:18:30 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
|
|
|
|
2012-09-06 01:30:36 +04:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-07-13 20:36:19 +04:00
|
|
|
ok(storage, "Should have gotten a storage");
|
|
|
|
|
2013-07-12 11:18:28 +04:00
|
|
|
request = storage.addNamed(gDataBlob, gFileName);
|
2012-05-21 20:18:30 +04:00
|
|
|
ok(request, "Should have a non-null request");
|
|
|
|
|
|
|
|
request.onsuccess = addSuccess;
|
|
|
|
request.onerror = addError;
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|