Bug 861456 - Fix all device storage tests so that they run. r=dclarke

This commit is contained in:
Dave Hylands 2013-07-12 00:18:28 -07:00
parent a8827750da
commit e54b28c472
10 changed files with 80 additions and 62 deletions

View File

@ -24,7 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=823965
devicestorage_setup(); devicestorage_setup();
var gFileName = "devicestorage/hi.png"; var gFileName = "devicestorage/" + randomFilename(12) + "/hi.png";
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: 'image/png'});
@ -63,7 +63,7 @@ function addSuccess(e) {
var filename = e.target.result; var filename = e.target.result;
if (filename[0] == "/") { if (filename[0] == "/") {
// We got /storgaeName/prefix/filename // We got /storageName/prefix/filename
// Remove the storageName (this shows up on FirefoxOS) // Remove the storageName (this shows up on FirefoxOS)
filename = filename.substring(1); // Remove leading slash filename = filename.substring(1); // Remove leading slash
var slashIndex = filename.indexOf("/"); var slashIndex = filename.indexOf("/");
@ -93,7 +93,7 @@ ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var storage = navigator.getDeviceStorage("pictures"); var storage = navigator.getDeviceStorage("pictures");
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, gFileName);
ok(request, "Should have a non-null request"); ok(request, "Should have a non-null request");
request.onsuccess = addSuccess; request.onsuccess = addSuccess;

View File

@ -24,7 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup(); devicestorage_setup();
var gFileName = "devicestorage/hi.png"; var gFileName = "devicestorage/" + randomFilename(12) + "/hi.png";
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: 'image/png'});
var gFileReader = new FileReader(); var gFileReader = new FileReader();
@ -93,7 +93,21 @@ function getError(e) {
function addSuccess(e) { function addSuccess(e) {
ok(e.target.result == gFileName, "File name should match"); 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;
var storage = navigator.getDeviceStorage("pictures"); var storage = navigator.getDeviceStorage("pictures");
request = storage.get(gFileName); request = storage.get(gFileName);
@ -113,7 +127,7 @@ ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var storage = navigator.getDeviceStorage("pictures"); var storage = navigator.getDeviceStorage("pictures");
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, gFileName);
ok(request, "Should have a non-null request"); ok(request, "Should have a non-null request");
request.onsuccess = addSuccess; request.onsuccess = addSuccess;

View File

@ -35,7 +35,7 @@ function enumerateSuccess(e) {
var filename = e.target.result.name; var filename = e.target.result.name;
if (filename[0] == "/") { if (filename[0] == "/") {
// We got /storgaeName/prefix/filename // We got /storageName/prefix/filename
// Remove the storageName (this shows up on FirefoxOS) // Remove the storageName (this shows up on FirefoxOS)
filename = filename.substring(1); // Remove leading slash filename = filename.substring(1); // Remove leading slash
var slashIndex = filename.indexOf("/"); var slashIndex = filename.indexOf("/");

View File

@ -41,7 +41,7 @@ function enumerateSuccess(e) {
var filename = e.target.result.name; var filename = e.target.result.name;
if (filename[0] == "/") { if (filename[0] == "/") {
// We got /storgaeName/prefix/filename // We got /storageName/prefix/filename
// Remove the storageName (this shows up on FirefoxOS) // Remove the storageName (this shows up on FirefoxOS)
filename = filename.substring(1); // Remove leading slash filename = filename.substring(1); // Remove leading slash
var slashIndex = filename.indexOf("/"); var slashIndex = filename.indexOf("/");

View File

@ -49,7 +49,8 @@ function addSuccess(e) {
request.onerror = freeSpaceError; request.onerror = freeSpaceError;
} }
request = storage.addNamed(createRandomBlob('image/png'), "a/b.png"); var prefix = "devicestorage/" + randomFilename(12);
request = storage.addNamed(createRandomBlob('image/png'), prefix + "/a/b.png");
request.onsuccess = addSuccess; request.onsuccess = addSuccess;
request.onerror = addError; request.onerror = addError;

View File

@ -22,10 +22,19 @@ 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">
devicestorage_setup();
var oldFiles = ["a.png", "b.png", "c.png"];
var newFiles = ["d.png", "e.png", "f.png"];
var storage = navigator.getDeviceStorage('pictures');
var prefix = "devicestorage/" + randomFilename(12);
var callback;
var files;
var i;
var timestamp;
function verifyAndDelete(prefix, files, e) { function verifyAndDelete(prefix, files, e) {
if (e.target.result == null) { if (e.target.result == null) {
ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array") 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 + "\n"); dump("We still have length = " + files.length + "\n");
@ -36,7 +45,7 @@ function verifyAndDelete(prefix, files, e) {
var filename = e.target.result.name; var filename = e.target.result.name;
if (filename[0] == "/") { if (filename[0] == "/") {
// We got /storgaeName/prefix/filename // We got /storageName/prefix/filename
// Remove the storageName (this shows up on FirefoxOS) // Remove the storageName (this shows up on FirefoxOS)
filename = filename.substring(1); // Remove leading slash filename = filename.substring(1); // Remove leading slash
var slashIndex = filename.indexOf("/"); var slashIndex = filename.indexOf("/");
@ -56,68 +65,68 @@ function verifyAndDelete(prefix, files, e) {
files.remove(index); files.remove(index);
// clean up // clean up
var storage = navigator.getDeviceStorage("pictures"); var cleanup = storage.delete(e.target.result.name);
var cleanup = storage.delete(prefix + "/" + filename);
cleanup.onsuccess = function(e) {} cleanup.onsuccess = function(e) {}
} }
function addFiles(prefix, files, date, callback) { function addSuccess(e) {
i = i + 1;
const Cc = SpecialPowers.Cc; if (i == files.length) {
const Ci = SpecialPowers.Ci; callback();
return;
var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
for (var i=0; i<files.length; i++) {
var f = directoryService.get("TmpD", Ci.nsIFile);
f.appendRelativePath("device-storage-testing");
var path = prefix + '/' + files[i];
path.split("/").forEach(function(p) {
f.appendRelativePath(p);
});
f.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
f.lastModifiedTime = date;
} }
callback(); addFile(files[i]);
} }
function addError(e) {
ok(false, "addError was called : " + e.target.error.name);
devicestorage_cleanup();
}
devicestorage_setup(); function addFile(filename){
var req = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
req.onsuccess = addSuccess;
req.onerror = addError;
}
var prefix = "devicestorage/" + randomFilename(12) function afterNewFiles() {
var cursor = storage.enumerate(prefix, {"since": timestamp});
var oldFiles = ["a.png", "b.png", "c.png"];
var newFiles = ["d.png", "e.png", "f.png"];
// 157795200 is a long long time ago.
addFiles(prefix, oldFiles, 157795200, addNewFiles);
function enumerateNew() {
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
// 836031600 is a long time ago
var cursor = storage.enumerate(prefix, {"since": new Date(836031600)});
cursor.onsuccess = function(e) { cursor.onsuccess = function(e) {
verifyAndDelete(prefix, newFiles, e); verifyAndDelete(prefix, newFiles, e);
if (e.target.result) { if (e.target.result) {
e.target.continue(); e.target.continue();
} }
} };
cursor.onerror = function (e) { cursor.onerror = function (e) {
ok(false, "handleError was called : " + e.target.error.name); ok(false, "handleError was called : " + e.target.error.name);
devicestorage_cleanup(); devicestorage_cleanup();
} };
} }
function addNewFiles() { function addNewFiles() {
addFiles(prefix, newFiles, Date.now(), enumerateNew); i = 0;
files = newFiles;
callback = afterNewFiles;
addFile(files[0]);
} }
function beforeNewFiles() {
timestamp = new Date();
setTimeout(addNewFiles, 1000);
}
function afterOldFiles() {
setTimeout(beforeNewFiles, 1000);
}
function addOldFiles() {
i = 0;
files = oldFiles;
callback = afterOldFiles;
addFile(files[0]);
}
addOldFiles();
</script> </script>
</pre> </pre>

View File

@ -49,7 +49,8 @@ function addSuccess(e) {
request.onerror = usedSpaceError; request.onerror = usedSpaceError;
} }
request = storage.addNamed(createRandomBlob('image/png'), "a/b.png"); var prefix = "devicestorage/" + randomFilename(12);
request = storage.addNamed(createRandomBlob('image/png'), prefix + "/a/b.png");
request.onsuccess = addSuccess; request.onsuccess = addSuccess;
request.onerror = addError; request.onerror = addError;

View File

@ -40,7 +40,7 @@ function onChange(e) {
var filename = e.path; var filename = e.path;
if (filename[0] == "/") { if (filename[0] == "/") {
// We got /storgaeName/prefix/filename // We got /storageName/prefix/filename
// Remove the storageName (this shows up on FirefoxOS) // Remove the storageName (this shows up on FirefoxOS)
filename = filename.substring(1); // Remove leading slash filename = filename.substring(1); // Remove leading slash
var slashIndex = filename.indexOf("/"); var slashIndex = filename.indexOf("/");

View File

@ -40,7 +40,7 @@ function onChange(e) {
var filename = e.path; var filename = e.path;
if (filename[0] == "/") { if (filename[0] == "/") {
// We got /storgaeName/prefix/filename // We got /storageName/prefix/filename
// Remove the storageName (this shows up on FirefoxOS) // Remove the storageName (this shows up on FirefoxOS)
filename = filename.substring(1); // Remove leading slash filename = filename.substring(1); // Remove leading slash
var slashIndex = filename.indexOf("/"); var slashIndex = filename.indexOf("/");

View File

@ -243,10 +243,6 @@
"dom/browser-element/mochitest/test_browserElement_inproc_CloseFromOpener.html":"", "dom/browser-element/mochitest/test_browserElement_inproc_CloseFromOpener.html":"",
"dom/browser-element/":"", "dom/browser-element/":"",
"dom/devicestorage/test/test_basic.html":"",
"dom/devicestorage/test/test_lastModificationFilter.html":"",
"dom/devicestorage/test/test_overwrite.html":"",
"dom/devicestorage/test/test_stat.html":"",
"dom/file/test/test_append_read_data.html":"", "dom/file/test/test_append_read_data.html":"",
"dom/file/test/test_archivereader.html":"", "dom/file/test/test_archivereader.html":"",
"dom/file/test/test_archivereader_nonUnicode.html":"", "dom/file/test/test_archivereader_nonUnicode.html":"",
@ -364,9 +360,6 @@
"dom/tests/mochitest/sessionstorage/test_sessionStorageReplace.html":"", "dom/tests/mochitest/sessionstorage/test_sessionStorageReplace.html":"",
"dom/tests/mochitest/webapps/test_bug_779982.html":"", "dom/tests/mochitest/webapps/test_bug_779982.html":"",
"dom/tests/mochitest/whatwg/test_postMessage_closed.html":"", "dom/tests/mochitest/whatwg/test_postMessage_closed.html":"",
"dom/devicestorage/test/test_available.html":"",
"dom/devicestorage/test/test_freeSpace.html":"",
"dom/devicestorage/test/test_usedSpace.html":"",
"dom/workers/test/test_suspend.html":"", "dom/workers/test/test_suspend.html":"",
"dom/workers/test/test_csp.html":"", "dom/workers/test/test_csp.html":"",
"dom/workers/test/test_workersDisabled.html":"", "dom/workers/test/test_workersDisabled.html":"",