2012-05-21 09:18:30 -07: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 08:20:14 -07:00
|
|
|
<body>
|
2012-05-21 09:18:30 -07: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();
|
|
|
|
|
2012-09-05 14:30:36 -07:00
|
|
|
var gFileName = "devicestorage/hi.png";
|
2012-07-13 09:36:19 -07:00
|
|
|
var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies."
|
2012-09-05 14:30:36 -07:00
|
|
|
var gDataBlob = new Blob([gData], {type: 'image/png'});
|
2012-07-23 09:52:05 -07:00
|
|
|
var gFileReader = new FileReader();
|
2012-05-21 09:18:30 -07: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 09:36:19 -07:00
|
|
|
dump(e.target.result + "\n")
|
2012-05-21 09:18:30 -07:00
|
|
|
|
2012-09-05 14:30:36 -07:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-08-01 23:32:11 -07:00
|
|
|
request = storage.get(e.target.result);
|
2012-05-21 09:18:30 -07: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-05 14:30:36 -07:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-05-21 09:18:30 -07:00
|
|
|
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
|
|
|
|
|
|
|
|
ok(e.target.result.name == gFileName, "File name should match");
|
|
|
|
|
2012-07-13 09:36:19 -07:00
|
|
|
var name = e.target.result.name;
|
|
|
|
|
2012-07-23 09:52:05 -07:00
|
|
|
gFileReader.readAsArrayBuffer(gDataBlob);
|
|
|
|
gFileReader.onload = function(e) {
|
2012-07-13 09:36:19 -07:00
|
|
|
readerCallback(e);
|
|
|
|
|
2012-08-01 23:32:11 -07:00
|
|
|
request = storage.delete(name)
|
2012-07-13 09:36:19 -07: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 09:18:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function getError(e) {
|
|
|
|
ok(false, "getError was called : " + e.target.error.name);
|
2012-07-13 09:36:19 -07:00
|
|
|
devicestorage_cleanup();
|
2012-05-21 09:18:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function addSuccess(e) {
|
|
|
|
|
|
|
|
ok(e.target.result == gFileName, "File name should match");
|
|
|
|
|
2012-09-05 14:30:36 -07:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-08-01 23:32:11 -07:00
|
|
|
request = storage.get(gFileName);
|
2012-05-21 09:18:30 -07: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-05 14:30:36 -07:00
|
|
|
var storage = navigator.getDeviceStorage("pictures");
|
2012-07-13 09:36:19 -07:00
|
|
|
ok(storage, "Should have gotten a storage");
|
|
|
|
|
2012-09-05 14:30:36 -07:00
|
|
|
request = storage.addNamed(gDataBlob, "devicestorage/hi.png");
|
2012-05-21 09:18:30 -07:00
|
|
|
ok(request, "Should have a non-null request");
|
|
|
|
|
|
|
|
request.onsuccess = addSuccess;
|
|
|
|
request.onerror = addError;
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|