summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_cursor_cycle.js
blob: 795a9b63d708af5f39b34c7d78a19f700006785b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var testGenerator = testSteps();

function testSteps()
{
  const Bob = { ss: "237-23-7732", name: "Bob" };

  let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
  request.onerror = errorHandler;
  request.onupgradeneeded = grabEventAndContinueHandler;
  let event = yield undefined;

  let db = event.target.result;
  event.target.onsuccess = continueToNextStep;

  let objectStore = db.createObjectStore("foo", { keyPath: "ss" });
  objectStore.createIndex("name", "name", { unique: true });
  objectStore.add(Bob);
  yield undefined;

  db.transaction("foo", "readwrite").objectStore("foo")
    .index("name").openCursor().onsuccess = function(event) {
    event.target.transaction.oncomplete = continueToNextStep;
    let cursor = event.target.result;
    if (cursor) {
      let objectStore = event.target.transaction.objectStore("foo");
      objectStore.delete(Bob.ss)
                 .onsuccess = function(event) { cursor.continue(); };
    }
  };
  yield undefined;
  finishTest();

  objectStore = null; // Bug 943409 workaround.

  yield undefined;
}