summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/reading-autoincrement-indexes-cursors.any.js
blob: ff71000683c65e92e19c06a4cc567f1c1a807d93 (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
77
78
79
80
81
82
83
84
85
86
87
88
// META: global=window,dedicatedworker,sharedworker,serviceworker
// META: script=resources/support-promises.js
// META: script=resources/reading-autoincrement-common.js

promise_test(async testCase => {
  const database = await setupAutoincrementDatabase(testCase);

  const transaction = database.transaction(['store'], 'readonly');
  const store = transaction.objectStore('store');
  const index = store.index('by_id');

  const result = await getAllViaCursor(testCase, index);
  assert_equals(result.length, 32);
  for (let i = 1; i <= 32; ++i) {
    assert_equals(result[i - 1].key, i, 'Autoincrement index key');
    assert_equals(result[i - 1].primaryKey, i, 'Autoincrement primary key');
    assert_equals(result[i - 1].value.id, i, 'Autoincrement key in value');
    assert_equals(result[i - 1].value.name, nameForId(i),
                  'String property in value');
  }

  database.close();
}, 'IDBIndex.openCursor() iterates over an index on the autoincrement key');

promise_test(async testCase => {
  const database = await setupAutoincrementDatabase(testCase);

  const transaction = database.transaction(['store'], 'readonly');
  const store = transaction.objectStore('store');
  const index = store.index('by_id');

  const result = await getAllKeysViaCursor(testCase, index);
  assert_equals(result.length, 32);
  for (let i = 1; i <= 32; ++i) {
    assert_equals(result[i - 1].key, i, 'Autoincrement index key');
    assert_equals(result[i - 1].primaryKey, i, 'Autoincrement primary key');
  }

  database.close();
}, 'IDBIndex.openKeyCursor() iterates over an index on the autoincrement key');

promise_test(async testCase => {
  const database = await setupAutoincrementDatabase(testCase);

  const transaction = database.transaction(['store'], 'readonly');
  const store = transaction.objectStore('store');
  const index = store.index('by_name');

  const stringSortedIds = idsSortedByStringCompare();

  const result = await getAllViaCursor(testCase, index);
  assert_equals(result.length, 32);
  for (let i = 1; i <= 32; ++i) {
    assert_equals(result[i - 1].key, nameForId(stringSortedIds[i - 1]),
                  'Index key');
    assert_equals(result[i - 1].primaryKey, stringSortedIds[i - 1],
                  'Autoincrement primary key');
    assert_equals(result[i - 1].value.id, stringSortedIds[i - 1],
                  'Autoincrement key in value');
    assert_equals(result[i - 1].value.name, nameForId(stringSortedIds[i - 1]),
                  'String property in value');
  }

  database.close();
}, 'IDBIndex.openCursor() iterates over an index not covering the ' +
   'autoincrement key');

promise_test(async testCase => {
  const database = await setupAutoincrementDatabase(testCase);

  const transaction = database.transaction(['store'], 'readonly');
  const store = transaction.objectStore('store');
  const index = store.index('by_name');

  const stringSortedIds = idsSortedByStringCompare();

  const result = await getAllKeysViaCursor(testCase, index);
  assert_equals(result.length, 32);
  for (let i = 1; i <= 32; ++i) {
    assert_equals(result[i - 1].key, nameForId(stringSortedIds[i - 1]),
                  'Index key');
    assert_equals(result[i - 1].primaryKey, stringSortedIds[i - 1],
                  'Autoincrement primary key');
  }

  database.close();
}, 'IDBIndex.openKeyCursor() iterates over an index not covering the ' +
   'autoincrement key');