summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_autoIncrement_indexes.js
blob: 64de7f4efb0d55e4f599aba9f5daa3e1ca8c1c5d (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

/* exported testGenerator */
var testGenerator = testSteps();

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

  let db = request.result;
  db.onerror = errorHandler;

  let objectStore = db.createObjectStore("foo", {
    keyPath: "id",
    autoIncrement: true,
  });
  objectStore.createIndex("first", "first");
  objectStore.createIndex("second", "second");
  objectStore.createIndex("third", "third");

  let data = { first: "foo", second: "foo", third: "foo" };

  objectStore.add(data).onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  is(event.target.result, 1, "Added entry");
  request.onsuccess = grabEventAndContinueHandler;

  event = yield undefined;

  objectStore = db.transaction("foo").objectStore("foo");
  let first = objectStore.index("first");
  let second = objectStore.index("second");
  let third = objectStore.index("third");

  first.get("foo").onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  is(event.target.result.id, 1, "Entry in first");

  second.get("foo").onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  is(event.target.result.id, 1, "Entry in second");

  third.get("foo").onsuccess = grabEventAndContinueHandler;
  event = yield undefined;

  is(event.target.result.id, 1, "Entry in third");

  finishTest();
}