From 0acbbc1c5e81b83b2d0a1d9637ed7da21dad3a9e Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Fri, 13 Jul 2012 12:35:33 -0700 Subject: [PATCH] Bug 773713 - Stop using profile directory for Device Storage testings. r=jmaher --- dom/devicestorage/nsDeviceStorage.cpp | 13 +++++----- .../test/devicestorage_common.js | 11 ++++++++ dom/devicestorage/test/test_basic.html | 8 +++--- dom/devicestorage/test/test_dotdot.html | 12 ++++----- dom/devicestorage/test/test_enumerate.html | 2 +- .../test/test_enumerateMultipleContinue.html | 2 +- .../test/test_enumerateNoParam.html | 2 +- .../test/test_enumerateOptions.html | 2 +- .../test/test_lastModificationFilter.html | 9 ++++--- dom/devicestorage/test/test_overwrite.html | 8 +++--- dom/devicestorage/test/test_sanity.html | 25 +++---------------- 11 files changed, 44 insertions(+), 50 deletions(-) diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index 50c8719d2d5..f78edd0c4f6 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -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); + } } } diff --git a/dom/devicestorage/test/devicestorage_common.js b/dom/devicestorage/test/devicestorage_common.js index 9419f880c6c..02112ab29cb 100644 --- a/dom/devicestorage/test/devicestorage_common.js +++ b/dom/devicestorage/test/devicestorage_common.js @@ -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 { diff --git a/dom/devicestorage/test/test_basic.html b/dom/devicestorage/test/test_basic.html index d9c3a5aecf0..fafb01f0141 100644 --- a/dom/devicestorage/test/test_basic.html +++ b/dom/devicestorage/test/test_basic.html @@ -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"); diff --git a/dom/devicestorage/test/test_dotdot.html b/dom/devicestorage/test/test_dotdot.html index ebdf0d23327..ad2ec61d43e 100644 --- a/dom/devicestorage/test/test_dotdot.html +++ b/dom/devicestorage/test/test_dotdot.html @@ -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"; diff --git a/dom/devicestorage/test/test_enumerate.html b/dom/devicestorage/test/test_enumerate.html index c6ba5c39bbf..73decaa74c9 100644 --- a/dom/devicestorage/test/test_enumerate.html +++ b/dom/devicestorage/test/test_enumerate.html @@ -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) diff --git a/dom/devicestorage/test/test_enumerateMultipleContinue.html b/dom/devicestorage/test/test_enumerateMultipleContinue.html index 0d56d62130d..73fb9686a3c 100644 --- a/dom/devicestorage/test/test_enumerateMultipleContinue.html +++ b/dom/devicestorage/test/test_enumerateMultipleContinue.html @@ -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; diff --git a/dom/devicestorage/test/test_enumerateNoParam.html b/dom/devicestorage/test/test_enumerateNoParam.html index b84f9c15172..59121aea90f 100644 --- a/dom/devicestorage/test/test_enumerateNoParam.html +++ b/dom/devicestorage/test/test_enumerateNoParam.html @@ -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) diff --git a/dom/devicestorage/test/test_enumerateOptions.html b/dom/devicestorage/test/test_enumerateOptions.html index 2a849423504..592b3b5b5a5 100644 --- a/dom/devicestorage/test/test_enumerateOptions.html +++ b/dom/devicestorage/test/test_enumerateOptions.html @@ -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; diff --git a/dom/devicestorage/test/test_lastModificationFilter.html b/dom/devicestorage/test/test_lastModificationFilter.html index 484bafaa426..129e2a74a8f 100644 --- a/dom/devicestorage/test/test_lastModificationFilter.html +++ b/dom/devicestorage/test/test_lastModificationFilter.html @@ -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 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();