Bug 788268 - Device Storage - Convert tests to use public types. r=bent
authorDoug Turner <dougt@dougt.org>
Wed, 05 Sep 2012 14:30:36 -0700
changeset 104336 14ea11f7a22af84111cccc65b4d9b4239a715004
parent 104335 1948141f2eb09003a7c481810d1566bb9b5a97b6
child 104337 2543cd470978b12b8f44b454c0d1e7ce076a59f2
push id14464
push userryanvm@gmail.com
push dateWed, 05 Sep 2012 21:52:38 +0000
treeherdermozilla-inbound@013743bb609e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs788268
milestone18.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 788268 - Device Storage - Convert tests to use public types. r=bent
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
dom/devicestorage/test/test_stat.html
dom/devicestorage/test/test_watch.html
dom/devicestorage/test/test_watchOther.html
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -150,23 +150,16 @@ DeviceStorageFile::IsSafePath()
   return true;
 }
 
 bool
 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<nsIConsoleService> svc = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
   char buffer[1024];
   nsCString path;
   mFile->GetNativePath(path);
 
   PRIntervalTime iStart = PR_IntervalNow();
 #endif
@@ -567,28 +560,23 @@ nsDOMDeviceStorage::SetRootDirectoryForT
     NS_NewLocalFile(NS_LITERAL_STRING("/sdcard"), false, getter_AddRefs(f));
 #elif defined (MOZ_WIDGET_COCOA)
     dirService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
 #elif defined (XP_UNIX)
     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)) {
-
-    // 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();
     }
   }
 
 #ifdef MOZ_WIDGET_GONK
   RegisterForSDCardChanges(this);
 #endif
 
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
@@ -2128,9 +2116,9 @@ nsDOMDeviceStorage::GetContextForEventHa
 }
 
 JSContext *
 nsDOMDeviceStorage::GetJSContextForEventHandlers()
 {
   return nsDOMEventTargetHelper::GetJSContextForEventHandlers();
 }
 
-NS_IMPL_EVENT_HANDLER(nsDOMDeviceStorage, change)
\ No newline at end of file
+NS_IMPL_EVENT_HANDLER(nsDOMDeviceStorage, change)
--- a/dom/devicestorage/test/devicestorage_common.js
+++ b/dom/devicestorage/test/devicestorage_common.js
@@ -49,18 +49,18 @@ function getRandomBuffer() {
   var buffer = new ArrayBuffer(size);
   var view = new Uint8Array(buffer);
   for (var i = 0; i < size; i++) {
     view[i] = parseInt(Math.random() * 255);
   }
   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) {
   var set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
   var result = "";
   for (var i=0; i<l; i++) {
     var r = Math.floor(set.length * Math.random());
     result += set.substring(r, r + 1);
--- a/dom/devicestorage/test/test_basic.html
+++ b/dom/devicestorage/test/test_basic.html
@@ -28,19 +28,19 @@ function unload() {
 
   delete gFileReader;
   gFileReader = null;
 }
 
 
 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) {
   ok(false, "file was deleted not successfully");
   devicestorage_cleanup();
 }
 
 function getAfterDeleteError(e) {
@@ -48,30 +48,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("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   request = storage.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("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 
   ok(e.target.result.name == gFileName, "File name should match");
 
   var name = e.target.result.name;
 
   gFileReader.readAsArrayBuffer(gDataBlob);
   gFileReader.onload = function(e) {
@@ -96,35 +96,35 @@ 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("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   request = storage.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("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;
 request.onerror = addError;
 
 </script>
 </pre>
 </body>
--- a/dom/devicestorage/test/test_dotdot.html
+++ b/dom/devicestorage/test/test_dotdot.html
@@ -20,27 +20,27 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 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");
   dump(request);
   devicestorage_cleanup();
 }
 
 function next(e) {
--- a/dom/devicestorage/test/test_enumerate.html
+++ b/dom/devicestorage/test/test_enumerate.html
@@ -62,27 +62,27 @@ function addSuccess(e) {
   }
 }
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   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<files.length; i++) {
 
- request = storage.addNamed(createRandomBlob(), prefix + '/' + files[i]);
+ request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
 
  ok(request, "Should have a non-null request");
  request.onsuccess = addSuccess;
  request.onerror = addError;
 }
 
 </script>
 </pre>
--- 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("testing").enumerate();
+var cursor = navigator.getDeviceStorage("pictures").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,27 +66,27 @@ function addSuccess(e) {
   }
 }
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
 
-var storage = navigator.getDeviceStorage("testing");
+var storage = navigator.getDeviceStorage("pictures");
 ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 var prefix = "devicestorage/" + randomFilename(12)
 
-var files = [ "a", "b", "c" ]
+var files = [ "a.png", "b.png", "c.png" ]
 var addedSoFar = 0;
 
 
 for (var i=0; i<files.length; i++) {
 
- request = storage.addNamed(createRandomBlob(), prefix + '/' + files[i]);
+ request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
 
  ok(request, "Should have a non-null request");
  request.onsuccess = addSuccess;
  request.onerror = addError;
 }
 
 </script>
 </pre>
--- 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("testing");
+storage = navigator.getDeviceStorage("pictures");
 
 
 throws = false;
 try {
 var cursor = storage.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,17 +39,17 @@ 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("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   var cleanup = storage.delete(prefix + "/" + filename);
   cleanup.onsuccess = function(e) {}
 }
 
 function addFiles(prefix, files, date, callback) {
 
   const Cc = SpecialPowers.wrap(Components).classes;
   const Ci = Components.interfaces;
@@ -71,25 +71,25 @@ function addFiles(prefix, files, date, c
   callback();
 }
 
 
 devicestorage_setup();
 
 var prefix = "devicestorage/" + randomFilename(12)
 
-var oldFiles = ["a", "b", "c"];
-var newFiles = ["d", "e", "f"];
+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("testing");
+  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) {
     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
@@ -18,17 +18,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
-var filename = "devicestorage/aaaa"
+var filename = "devicestorage/aaaa.png"
 
 devicestorage_setup();
 
 
 function deleteSuccess(e) {
   devicestorage_cleanup();
 }
 
@@ -40,47 +40,47 @@ function deleteError(e) {
 function addOverwritingSuccess(e) {
   ok(false, "addOverwritingSuccess was called.");
   devicestorage_cleanup();
 }
 
 function addOverwritingError(e) {
   ok(true, "Adding to the same location should fail");
 
-  var storage = navigator.getDeviceStorage("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   request = storage.delete(filename)
   request.onsuccess = deleteSuccess;
   request.onerror = deleteError;
 }
 
 function addSuccess(e) {
   ok(true, "addSuccess was called");
 
-  var storage = navigator.getDeviceStorage("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 
-  request = storage.addNamed(createRandomBlob(), filename);
+  request = storage.addNamed(createRandomBlob('image/png'), 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("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   request = storage.delete(filename)
   request.onsuccess = runtest;
 }
 
 function runtest() {
-  var storage = navigator.getDeviceStorage("testing");
+  var storage = navigator.getDeviceStorage("pictures");
   ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 
-  request = storage.addNamed(createRandomBlob(), filename);
+  request = storage.addNamed(createRandomBlob('image/png'), filename);
   ok(request, "Should have a non-null request");
 
   request.onsuccess = addSuccess;
   request.onerror = addError;
 }
 
 runtest();
 
--- a/dom/devicestorage/test/test_sanity.html
+++ b/dom/devicestorage/test/test_sanity.html
@@ -33,18 +33,24 @@ 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("testing");
-ok(storage, "testing - Should have getDeviceStorage");
+storage = navigator.getDeviceStorage("pictures");
+ok(storage, "pictures - Should have getDeviceStorage");
+
+storage = navigator.getDeviceStorage("music");
+ok(storage, "music - Should have getDeviceStorage");
+
+storage = navigator.getDeviceStorage("videos");
+ok(storage, "videos - Should have getDeviceStorage");
 
 var cursor = storage.enumerate();
 ok(cursor, "Should have a non-null cursor");
 
 devicestorage_cleanup();
 
 </script>
 </pre>
--- a/dom/devicestorage/test/test_stat.html
+++ b/dom/devicestorage/test/test_stat.html
@@ -30,33 +30,33 @@ function statSuccess(e) {
   devicestorage_cleanup();
 }
 
 function statError(e) {
   ok(false, "statError was called");
   devicestorage_cleanup();
 }
 
-var storage = navigator.getDeviceStorage("testing");
+var storage = navigator.getDeviceStorage("pictures");
 ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
 
 function addSuccess(e) {
   request = storage.stat();
   ok(request, "Should have a non-null request");
 
   request.onsuccess = statSuccess;
   request.onerror = statError;
 }
 
-request = storage.addNamed(createRandomBlob(), "a/b");
+request = storage.addNamed(createRandomBlob('image/png'), "a/b.png");
 request.onsuccess = addSuccess;
 request.onerror = addError;
 
 </script>
 </pre>
 </body>
 </html>
 
--- a/dom/devicestorage/test/test_watch.html
+++ b/dom/devicestorage/test/test_watch.html
@@ -19,17 +19,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();
 
-var gFileName = randomFilename(20);
+var gFileName = randomFilename(20) + ".png"
 
 function addSuccess(e) {
 }
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
@@ -44,21 +44,21 @@ function onChange(e) {
     devicestorage_cleanup();
   }
   else {
     // we may see other file changes during the test, and
     // that is completely ok
   }
 }
 
-var storage = navigator.getDeviceStorage("testing");
+var storage = navigator.getDeviceStorage("pictures");
 ok(storage, "Should have storage");
 storage.addEventListener("change", onChange);
 
-request = storage.addNamed(createRandomBlob(), gFileName);
+request = storage.addNamed(createRandomBlob('image/png'), gFileName);
 ok(request, "Should have a non-null request");
 
 request.onsuccess = addSuccess;
 request.onerror = addError;
 
 </script>
 </pre>
 </body>
--- a/dom/devicestorage/test/test_watchOther.html
+++ b/dom/devicestorage/test/test_watchOther.html
@@ -19,17 +19,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();
 
-var gFileName = randomFilename(20);
+var gFileName = randomFilename(20) + ".png"
 
 function addSuccess(e) {
 }
 
 function addError(e) {
   ok(false, "addError was called : " + e.target.error.name);
   devicestorage_cleanup();
 }
@@ -49,25 +49,25 @@ function onChange(e) {
   }
 }
 
 function onChangeFail(e) {
   dump("onChangeFail: " + e.path + " " + e.reason + "\n");
   ok(false, "We should never see any changes");
 }
 
-var storage = navigator.getDeviceStorage("testing");
+var storage = navigator.getDeviceStorage("pictures");
 ok(storage, "Should have storage");
 storage.addEventListener("change", onChange);
 
-var storageOther = navigator.getDeviceStorage("testing-other");
+var storageOther = navigator.getDeviceStorage("music");
 ok(storageOther, "Should have storage");
 storageOther.addEventListener("change", onChangeFail);
 
-request = storage.addNamed(createRandomBlob(), gFileName);
+request = storage.addNamed(createRandomBlob('image/png'), gFileName);
 ok(request, "Should have a non-null request");
 
 request.onsuccess = addSuccess;
 request.onerror = addError;
 
 </script>
 </pre>
 </body>