Bug 773713 - Stop using profile directory for Device Storage testings. r=jmaher

This commit is contained in:
Doug Turner 2012-07-13 12:35:33 -07:00
parent 6b6c7e2b75
commit 0acbbc1c5e
11 changed files with 44 additions and 50 deletions

View File

@ -214,14 +214,13 @@ nsDOMDeviceStorage::SetRootFileForType(const nsAString& aType, const PRInt32 aIn
// in testing, we have access to a few more directory locations
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
// Temp directory
if (aType.Equals(NS_LITERAL_STRING("temp")) && aIndex == 0) {
// testing directory
if (aType.Equals(NS_LITERAL_STRING("testing")) && aIndex == 0) {
dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
}
// Profile directory
else if (aType.Equals(NS_LITERAL_STRING("profile")) && aIndex == 0) {
dirService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
if (f) {
f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing"));
f->Create(nsIFile::DIRECTORY_TYPE, 0777);
}
}
}

View File

@ -13,6 +13,17 @@ Array.prototype.remove = function(from, to) {
};
function devicestorage_setup() {
// ensure that the directory we are writing into is empty
try {
const Cc = SpecialPowers.wrap(Components).classes;
const Ci = Components.interfaces;
var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var f = directoryService.get("TmpD", Ci.nsIFile);
f.appendRelativePath("device-storage-testing");
f.remove(true);
} catch(e) {}
SimpleTest.waitForExplicitFinish();
if (SpecialPowers.isMainProcess()) {
try {

View File

@ -43,7 +43,7 @@ function deleteSuccess(e) {
ok(e.target.result == gFileName, "File name should match");
dump(e.target.result + "\n")
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
request = storage[0].get(e.target.result);
request.onsuccess = getAfterDeleteSuccess;
request.onerror = getAfterDeleteError;
@ -56,7 +56,7 @@ function deleteError(e) {
}
function getSuccess(e) {
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
ok(e.target.result.name == gFileName, "File name should match");
@ -92,7 +92,7 @@ function addSuccess(e) {
ok(e.target.result == gFileName, "File name should match");
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
request = storage[0].get(gFileName);
request.onsuccess = getSuccess;
request.onerror = getError;
@ -107,7 +107,7 @@ function addError(e) {
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(storage, "Should have gotten a storage");
request = storage[0].addNamed(gDataBlob, "devicestorage/hi");

View File

@ -24,15 +24,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup();
function profileStorage() {
return navigator.getDeviceStorage("profile")[0];
function testingStorage() {
return navigator.getDeviceStorage("testing")[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; }
function () { return testingStorage().addNamed(createRandomBlob(), gFileName); },
function () { return testingStorage().delete(gFileName); },
function () { return testingStorage().get(gFileName); },
function () { var r = testingStorage().enumerate("../"); return r; }
];
var gFileName = "../owned";

View File

@ -67,7 +67,7 @@ function addError(e) {
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var prefix = "devicestorage/" + randomFilename(12)

View File

@ -30,7 +30,7 @@ function enumerateSuccess(e) {
function enumerateFailure(e) {
}
var cursor = navigator.getDeviceStorage("profile")[0].enumerate();
var cursor = navigator.getDeviceStorage("testing")[0].enumerate();
cursor.onsuccess = enumerateSuccess;
cursor.onerror = enumerateFailure;

View File

@ -71,7 +71,7 @@ function addError(e) {
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var prefix = "devicestorage/" + randomFilename(12)

View File

@ -25,7 +25,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup()
storage = navigator.getDeviceStorage("profile");
storage = navigator.getDeviceStorage("testing");
throws = false;

View File

@ -44,7 +44,7 @@ function verifyAndDelete(prefix, files, e) {
files.remove(index);
// clean up
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
var cleanup = storage[0].delete(prefix + "/" + filename);
cleanup.onsuccess = function(e) {}
}
@ -57,7 +57,10 @@ function addFiles(prefix, files, date, callback) {
var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
for (var i=0; i<files.length; i++) {
var f = directoryService.get("ProfD", Components.interfaces.nsIFile);
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);
@ -81,7 +84,7 @@ addFiles(prefix, oldFiles, 157795200, addNewFiles);
function enumerateNew() {
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
// 836031600 is a long time ago

View File

@ -44,7 +44,7 @@ function addOverwritingSuccess(e) {
function addOverwritingError(e) {
ok(true, "Adding to the same location should fail");
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
request = storage[0].delete(filename)
request.onsuccess = deleteSuccess;
request.onerror = deleteError;
@ -53,7 +53,7 @@ function addOverwritingError(e) {
function addSuccess(e) {
ok(true, "addSuccess was called");
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage[0].addNamed(createRandomBlob(), filename);
@ -65,13 +65,13 @@ function addSuccess(e) {
function addError(e) {
// test file is already exists. clean it up and try again..
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
request = storage[0].delete(filename)
request.onsuccess = runtest;
}
function runtest() {
var storage = navigator.getDeviceStorage("profile");
var storage = navigator.getDeviceStorage("testing");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage[0].addNamed(createRandomBlob(), filename);

View File

@ -38,32 +38,13 @@ 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");
storage = navigator.getDeviceStorage("testing");
ok(storage, "testing - 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();
}
devicestorage_cleanup();
</script>
</pre>