Bug 773713 - Stop using profile directory for Device Storage testings. r=jmaher
authorDoug Turner <dougt@dougt.org>
Fri, 13 Jul 2012 12:35:33 -0700
changeset 99277 ebaadef4058056f94dc40ae79c7769d27a371858
parent 99276 75f82fd7b2b0b582d39bb7759690e110194056b5
child 99278 8349edd9f8a1658ce5aed5b77a541c2ed5fc1f0d
push id23116
push userryanvm@gmail.com
push dateSat, 14 Jul 2012 16:58:48 +0000
treeherdermozilla-central@9046ecf4db8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs773713
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 773713 - Stop using profile directory for Device Storage testings. r=jmaher
dom/devicestorage/nsDeviceStorage.cpp
dom/devicestorage/test/devicestorage_common.js
dom/devicestorage/test/test_basic.html
dom/devicestorage/test/test_dotdot.html
dom/devicestorage/test/test_enumerate.html
dom/devicestorage/test/test_enumerateMultipleContinue.html
dom/devicestorage/test/test_enumerateNoParam.html
dom/devicestorage/test/test_enumerateOptions.html
dom/devicestorage/test/test_lastModificationFilter.html
dom/devicestorage/test/test_overwrite.html
dom/devicestorage/test/test_sanity.html
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -209,24 +209,23 @@ nsDOMDeviceStorage::SetRootFileForType(c
       dirService->Get(NS_UNIX_XDG_MUSIC_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
     }
 #endif
   }
 
   // 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);
+      }
     }
   } 
 
   mFile = f;
   return typeResult;
 }
 
 static jsval nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile)
--- a/dom/devicestorage/test/devicestorage_common.js
+++ b/dom/devicestorage/test/devicestorage_common.js
@@ -8,16 +8,27 @@ var oldVal = false;
 // Array Remove - By John Resig (MIT Licensed)
 Array.prototype.remove = function(from, to) {
   var rest = this.slice((to || from) + 1 || this.length);
   this.length = from < 0 ? this.length + from : from;
   return this.push.apply(this, rest);
 };
 
 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 {
       oldVal = SpecialPowers.getBoolPref("device.storage.enabled");
     } catch(e) {}
     SpecialPowers.setBoolPref("device.storage.enabled", true);
     SpecialPowers.setBoolPref("device.storage.testing", true);
     SpecialPowers.setBoolPref("device.storage.prompt.testing", true);
--- a/dom/devicestorage/test/test_basic.html
+++ b/dom/devicestorage/test/test_basic.html
@@ -38,30 +38,30 @@ function getAfterDeleteError(e) {
   devicestorage_cleanup();
 }
 
 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;
 
 }
 
 function deleteError(e) {
   ok(false, "deleteError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
 
 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");
 
   var name = e.target.result.name;
 
   var reader = new FileReader();
   reader.readAsArrayBuffer(gDataBlob);
@@ -87,32 +87,32 @@ function getError(e) {
   ok(false, "getError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
 
 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;
 
   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");
 
-var storage = navigator.getDeviceStorage("profile");
+var storage = navigator.getDeviceStorage("testing");
 ok(storage, "Should have gotten a storage");
 
 request = storage[0].addNamed(gDataBlob, "devicestorage/hi");
 ok(request, "Should have a non-null request");
 
 request.onsuccess = addSuccess;
 request.onerror = addError;
 
--- a/dom/devicestorage/test/test_dotdot.html
+++ b/dom/devicestorage/test/test_dotdot.html
@@ -19,25 +19,25 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 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";
 
 function fail(e) {
   ok(false, "addSuccess was called");
   dump(request);
   devicestorage_cleanup();
--- a/dom/devicestorage/test/test_enumerate.html
+++ b/dom/devicestorage/test/test_enumerate.html
@@ -62,17 +62,17 @@ function addSuccess(e) {
   }
 }
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
 
-var storage = navigator.getDeviceStorage("profile");
+var storage = navigator.getDeviceStorage("testing");
 ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 var prefix = "devicestorage/" + randomFilename(12)
 
 var files = [ "a", "b", "c", "d/a", "d/b", "d/c", "d/d", "The/quick/brown/fox/jumps/over/the/lazy/dog"]
 var addedSoFar = 0;
 
 
 for (var i=0; i<files.length; i++) {
--- a/dom/devicestorage/test/test_enumerateMultipleContinue.html
+++ b/dom/devicestorage/test/test_enumerateMultipleContinue.html
@@ -25,17 +25,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 devicestorage_setup();
 
 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;
 
 try {
  cursor.continue();
 }
 catch (e) {
   ok(true, "Calling continue before enumerateSuccess fires should throw");
--- a/dom/devicestorage/test/test_enumerateNoParam.html
+++ b/dom/devicestorage/test/test_enumerateNoParam.html
@@ -66,17 +66,17 @@ function addSuccess(e) {
   }
 }
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
 
-var storage = navigator.getDeviceStorage("profile");
+var storage = navigator.getDeviceStorage("testing");
 ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 var prefix = "devicestorage/" + randomFilename(12)
 
 var files = [ "a", "b", "c" ]
 var addedSoFar = 0;
 
 
 for (var i=0; i<files.length; i++) {
--- a/dom/devicestorage/test/test_enumerateOptions.html
+++ b/dom/devicestorage/test/test_enumerateOptions.html
@@ -20,17 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 devicestorage_setup()
 
-storage = navigator.getDeviceStorage("profile");
+storage = navigator.getDeviceStorage("testing");
 
 
 throws = false;
 try {
 var cursor = storage[0].enumerate();
 } catch(e) {throws = true}
 ok(!throws, "enumerate no parameter");
 
--- a/dom/devicestorage/test/test_lastModificationFilter.html
+++ b/dom/devicestorage/test/test_lastModificationFilter.html
@@ -39,30 +39,33 @@ function verifyAndDelete(prefix, files, 
   var index = files.indexOf(filename);
   ok(index > -1, "filename should be in the enumeration : " + e.target.result.name);
   if (index == -1)
     return;
 
   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) {}
 }
 
 function addFiles(prefix, files, date, callback) {
 
   const Cc = SpecialPowers.wrap(Components).classes;
   const Ci = Components.interfaces;
 
   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);
     });
     f.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
     f.lastModifiedTime = date;
   }
   callback();
@@ -76,17 +79,17 @@ var prefix = "devicestorage/" + randomFi
 var oldFiles = ["a", "b", "c"];
 var newFiles = ["d", "e", "f"];
 
 // 157795200 is a long long time ago.
 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
   var cursor = storage[0].enumerate(prefix, {"since": new Date(836031600)});
   cursor.onsuccess = function(e) {
     verifyAndDelete(prefix, newFiles, e);
     if (e.target.result) {
       e.target.continue();
--- a/dom/devicestorage/test/test_overwrite.html
+++ b/dom/devicestorage/test/test_overwrite.html
@@ -39,44 +39,44 @@ function deleteError(e) {
 
 function addOverwritingSuccess(e) {
   ok(false, "addOverwritingSuccess was called.");
 }
 
 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;
 }
 
 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);
   ok(request, "Should have a non-null request");
 
   request.onsuccess = addOverwritingSuccess;
   request.onerror = addOverwritingError;
 }
 
 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);
   ok(request, "Should have a non-null request");
 
   request.onsuccess = addSuccess;
   request.onerror = addError;
 }
--- a/dom/devicestorage/test/test_sanity.html
+++ b/dom/devicestorage/test/test_sanity.html
@@ -33,40 +33,21 @@ var throws = false;
 try {
  storage = navigator.getDeviceStorage();
 } catch(e) {throws = true}
 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>
 </body>
 </html>