From 803e9134f5295ce34f2025713ebe06d0fea0b31a Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Wed, 5 Sep 2012 14:30:36 -0700 Subject: [PATCH] Bug 788268 - Device Storage - Convert tests to use public types. r=bent --HG-- extra : rebase_source : 208751cfe7b68e67d65686d6606766dd5caebf59 --- dom/devicestorage/nsDeviceStorage.cpp | 28 ++++++------------- .../test/devicestorage_common.js | 4 +-- dom/devicestorage/test/test_basic.html | 14 +++++----- dom/devicestorage/test/test_dotdot.html | 6 ++-- dom/devicestorage/test/test_enumerate.html | 8 +++--- .../test/test_enumerateMultipleContinue.html | 2 +- .../test/test_enumerateNoParam.html | 6 ++-- .../test/test_enumerateOptions.html | 2 +- .../test/test_lastModificationFilter.html | 8 +++--- dom/devicestorage/test/test_overwrite.html | 14 +++++----- dom/devicestorage/test/test_sanity.html | 10 +++++-- dom/devicestorage/test/test_stat.html | 4 +-- dom/devicestorage/test/test_watch.html | 6 ++-- dom/devicestorage/test/test_watchOther.html | 8 +++--- 14 files changed, 57 insertions(+), 63 deletions(-) diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index b5dca82d098f..2db2d135dd25 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -155,13 +155,6 @@ DeviceStorageFile::IsType(nsAString& aType) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); - // in testing, we ignore filtering for the testing types - if (mozilla::Preferences::GetBool("device.storage.testing", false) && - (aType.Equals(NS_LITERAL_STRING("testing")) || - aType.Equals(NS_LITERAL_STRING("testing-other")))) { - return true; - } - #ifdef DEBUG_ISTYPE nsCOMPtr svc = do_GetService(NS_CONSOLESERVICE_CONTRACTID); char buffer[1024]; @@ -572,18 +565,13 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aType) #endif } - // in testing, we have access to a few more directory locations - if (mozilla::Preferences::GetBool("device.storage.testing", false)) { - - // testing directory - if (aType.Equals(NS_LITERAL_STRING("testing")) || - aType.Equals(NS_LITERAL_STRING("testing-other"))) { - dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); - if (f) { - f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing")); - f->Create(nsIFile::DIRECTORY_TYPE, 0777); - f->Normalize(); - } + // in testing, we default all device storage types to a temp directory + if (f && mozilla::Preferences::GetBool("device.storage.testing", false)) { + dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f)); + if (f) { + f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing")); + f->Create(nsIFile::DIRECTORY_TYPE, 0777); + f->Normalize(); } } @@ -2133,4 +2121,4 @@ nsDOMDeviceStorage::GetJSContextForEventHandlers() return nsDOMEventTargetHelper::GetJSContextForEventHandlers(); } -NS_IMPL_EVENT_HANDLER(nsDOMDeviceStorage, change) \ No newline at end of file +NS_IMPL_EVENT_HANDLER(nsDOMDeviceStorage, change) diff --git a/dom/devicestorage/test/devicestorage_common.js b/dom/devicestorage/test/devicestorage_common.js index 82cfc4cc99e4..a2402799215c 100644 --- a/dom/devicestorage/test/devicestorage_common.js +++ b/dom/devicestorage/test/devicestorage_common.js @@ -54,8 +54,8 @@ function getRandomBuffer() { return buffer; } -function createRandomBlob() { - return blob = new Blob([getRandomBuffer()], {type: 'binary/random'}); +function createRandomBlob(mime) { + return blob = new Blob([getRandomBuffer()], {type: mime}); } function randomFilename(l) { diff --git a/dom/devicestorage/test/test_basic.html b/dom/devicestorage/test/test_basic.html index f8f4e4272139..23ce6c142407 100644 --- a/dom/devicestorage/test/test_basic.html +++ b/dom/devicestorage/test/test_basic.html @@ -33,9 +33,9 @@ function unload() { devicestorage_setup(); -var gFileName = "devicestorage/hi"; +var gFileName = "devicestorage/hi.png"; var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies." -var gDataBlob = new Blob([gData], {type: 'text/plain'}); +var gDataBlob = new Blob([gData], {type: 'image/png'}); var gFileReader = new FileReader(); function getAfterDeleteSuccess(e) { @@ -53,7 +53,7 @@ function deleteSuccess(e) { ok(e.target.result == gFileName, "File name should match"); dump(e.target.result + "\n") - var storage = navigator.getDeviceStorage("testing"); + var storage = navigator.getDeviceStorage("pictures"); request = storage.get(e.target.result); request.onsuccess = getAfterDeleteSuccess; request.onerror = getAfterDeleteError; @@ -66,7 +66,7 @@ function deleteError(e) { } function getSuccess(e) { - var storage = navigator.getDeviceStorage("testing"); + var storage = navigator.getDeviceStorage("pictures"); ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); ok(e.target.result.name == gFileName, "File name should match"); @@ -101,7 +101,7 @@ function addSuccess(e) { ok(e.target.result == gFileName, "File name should match"); - var storage = navigator.getDeviceStorage("testing"); + var storage = navigator.getDeviceStorage("pictures"); request = storage.get(gFileName); request.onsuccess = getSuccess; request.onerror = getError; @@ -116,10 +116,10 @@ function addError(e) { ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); -var storage = navigator.getDeviceStorage("testing"); +var storage = navigator.getDeviceStorage("pictures"); ok(storage, "Should have gotten a storage"); -request = storage.addNamed(gDataBlob, "devicestorage/hi"); +request = storage.addNamed(gDataBlob, "devicestorage/hi.png"); ok(request, "Should have a non-null request"); request.onsuccess = addSuccess; diff --git a/dom/devicestorage/test/test_dotdot.html b/dom/devicestorage/test/test_dotdot.html index 8ae4dee0fec6..00eb111197f8 100644 --- a/dom/devicestorage/test/test_dotdot.html +++ b/dom/devicestorage/test/test_dotdot.html @@ -25,17 +25,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103 devicestorage_setup(); function testingStorage() { - return navigator.getDeviceStorage("testing"); + return navigator.getDeviceStorage("pictures"); } var tests = [ - function () { return testingStorage().addNamed(createRandomBlob(), gFileName); }, + function () { return testingStorage().addNamed(createRandomBlob('image/png'), gFileName); }, function () { return testingStorage().delete(gFileName); }, function () { return testingStorage().get(gFileName); }, function () { var r = testingStorage().enumerate("../"); return r; } ]; -var gFileName = "../owned"; +var gFileName = "../owned.png"; function fail(e) { ok(false, "addSuccess was called"); diff --git a/dom/devicestorage/test/test_enumerate.html b/dom/devicestorage/test/test_enumerate.html index c29c7ec156ed..e467fd5b926f 100644 --- a/dom/devicestorage/test/test_enumerate.html +++ b/dom/devicestorage/test/test_enumerate.html @@ -67,17 +67,17 @@ function addError(e) { devicestorage_cleanup(); } -var storage = navigator.getDeviceStorage("testing"); +var storage = navigator.getDeviceStorage("pictures"); ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); -var prefix = "devicestorage/" + randomFilename(12) +var prefix = "devicestorage/" + randomFilename(12) + ".png" -var files = [ "a", "b", "c", "d/a", "d/b", "d/c", "d/d", "The/quick/brown/fox/jumps/over/the/lazy/dog"] +var files = [ "a.png", "b.png", "c.png", "d/a.png", "d/b.png", "d/c.png", "d/d.png", "The/quick/brown/fox/jumps/over/the/lazy/dog.png"] var addedSoFar = 0; for (var i=0; i