summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_odd_result_order.js
blob: fb3d992c92c32d46d6a152f9c55edcd20ab64f90 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var testGenerator = testSteps();

function testSteps()
{
  const data = { key: 5, index: 10 };

  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;

  ok(db instanceof IDBDatabase, "Got a real database");

  db.onerror = errorHandler;

  let objectStore = db.createObjectStore("foo", { keyPath: "key",
                                                  autoIncrement: true });
  let index = objectStore.createIndex("foo", "index");

  event.target.onsuccess = continueToNextStep;
  yield undefined;

  objectStore = db.transaction("foo", "readwrite")
                  .objectStore("foo");
  request = objectStore.add(data);
  request.onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  let key;
  executeSoon(function() {
    key = request.result;
    continueToNextStep();
  });
  yield undefined;

  is(key, data.key, "Got the right key");

  objectStore = db.transaction("foo").objectStore("foo");
  objectStore.get(data.key).onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  let obj;
  executeSoon(function() {
    obj = event.target.result;
    continueToNextStep();
  });
  yield undefined;

  is(obj.key, data.key, "Got the right key");
  is(obj.index, data.index, "Got the right property value");

  objectStore = db.transaction("foo", "readwrite")
                  .objectStore("foo");
  request = objectStore.delete(data.key);
  request.onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  key = undefined;
  executeSoon(function() {
    key = request.result;
    continueToNextStep();
  }, 0);
  yield undefined;

  ok(key === undefined, "Got the right value");

  finishTest();
  yield undefined;
}