tor-browser

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

test_transaction_lifetimes.js (2691B)


      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  let request = indexedDB.open(
     11    this.window ? window.location.pathname : "Splendid Test",
     12    1
     13  );
     14  request.onerror = errorHandler;
     15  request.onupgradeneeded = grabEventAndContinueHandler;
     16  request.onsuccess = unexpectedSuccessHandler;
     17  let event = yield undefined;
     18 
     19  let db = event.target.result;
     20  db.onerror = errorHandler;
     21 
     22  event.target.transaction.onerror = errorHandler;
     23  event.target.transaction.oncomplete = grabEventAndContinueHandler;
     24 
     25  let os = db.createObjectStore("foo", { autoIncrement: true });
     26  os.createIndex("bar", "foo.bar");
     27  event = yield undefined;
     28 
     29  is(
     30    request.transaction,
     31    event.target,
     32    "request.transaction should still be set"
     33  );
     34 
     35  request.onsuccess = grabEventAndContinueHandler;
     36  event = yield undefined;
     37 
     38  is(request.transaction, null, "request.transaction should be cleared");
     39 
     40  let transaction = db.transaction("foo", "readwrite");
     41 
     42  os = transaction.objectStore("foo");
     43  // Place a request to keep the transaction alive long enough for our
     44  // executeSoon.
     45  let requestComplete = false;
     46 
     47  let wasAbleToGrabObjectStoreOutsideOfCallback = false;
     48  let wasAbleToGrabIndexOutsideOfCallback = false;
     49  executeSoon(function () {
     50    ok(!requestComplete, "Ordering is correct.");
     51    wasAbleToGrabObjectStoreOutsideOfCallback =
     52      !!transaction.objectStore("foo");
     53    wasAbleToGrabIndexOutsideOfCallback = !!transaction
     54      .objectStore("foo")
     55      .index("bar");
     56  });
     57 
     58  request = os.add({});
     59  request.onerror = errorHandler;
     60  request.onsuccess = grabEventAndContinueHandler;
     61 
     62  event = yield undefined;
     63 
     64  requestComplete = true;
     65 
     66  ok(
     67    wasAbleToGrabObjectStoreOutsideOfCallback,
     68    "Should be able to get objectStore"
     69  );
     70  ok(wasAbleToGrabIndexOutsideOfCallback, "Should be able to get index");
     71 
     72  transaction.oncomplete = grabEventAndContinueHandler;
     73  yield undefined;
     74 
     75  try {
     76    transaction.objectStore("foo");
     77    ok(false, "Should have thrown!");
     78  } catch (e) {
     79    ok(e instanceof DOMException, "Got database exception.");
     80    is(e.name, "InvalidStateError", "Good error.");
     81    is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
     82  }
     83 
     84  continueToNextStep();
     85  yield undefined;
     86 
     87  try {
     88    transaction.objectStore("foo");
     89    ok(false, "Should have thrown!");
     90  } catch (e) {
     91    ok(e instanceof DOMException, "Got database exception.");
     92    is(e.name, "InvalidStateError", "Good error.");
     93    is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
     94  }
     95 
     96  finishTest();
     97 }