tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_file_copy_failure.js (1746B)


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