test_file_copy_failure.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. */
  5. var testGenerator = testSteps();
  6. function testSteps()
  7. {
  8. const name = "test_file_copy_failure.js";
  9. const objectStoreName = "Blobs";
  10. const blob = getBlob(getView(1024));
  11. info("Opening database");
  12. let request = indexedDB.open(name);
  13. request.onerror = errorHandler;
  14. request.onupgradeneeded = continueToNextStepSync;
  15. request.onsuccess = unexpectedSuccessHandler;
  16. yield undefined;
  17. // upgradeneeded
  18. request.onupgradeneeded = unexpectedSuccessHandler;
  19. request.onsuccess = continueToNextStepSync;
  20. info("Creating objectStore");
  21. request.result.createObjectStore(objectStoreName);
  22. yield undefined;
  23. // success
  24. let db = request.result;
  25. db.onerror = errorHandler;
  26. info("Creating orphaned file");
  27. let filesDir = getChromeFilesDir();
  28. let journalFile = filesDir.clone();
  29. journalFile.append("journals");
  30. journalFile.append("1");
  31. let exists = journalFile.exists();
  32. ok(!exists, "Journal file doesn't exist");
  33. journalFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
  34. let file = filesDir.clone();
  35. file.append("1");
  36. exists = file.exists();
  37. ok(!exists, "File doesn't exist");
  38. file.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0644", 8));
  39. info("Storing blob");
  40. let trans = db.transaction(objectStoreName, "readwrite");
  41. request = trans.objectStore(objectStoreName).add(blob, 1);
  42. request.onsuccess = continueToNextStepSync;
  43. yield undefined;
  44. trans.oncomplete = continueToNextStepSync;
  45. yield undefined;
  46. exists = journalFile.exists();
  47. ok(!exists, "Journal file doesn't exist");
  48. finishTest();
  49. yield undefined;
  50. }