summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/parallel-cursors-upgrade.html
blob: 99ea65d9d60d2c8d4d6429b3d51693e98f22a5f6 (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
<!doctype html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>IndexedDB: Parallel iteration of cursors in upgradeneeded</title>
<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/support-promises.js"></script>
<script>
'use strict';

for (let cursorCount of [2, 20, 200, 2000]) {
  promise_test(testCase => {
    return createDatabase(testCase, (database, transaction) => {
      const store = database.createObjectStore('cache', { keyPath: 'key' });
      store.put({ key: '42' });

      const promises = [];

      for (let j = 0; j < 2; j += 1) {
        const promise = new Promise((resolve, reject) => {
          let request = null;
          for (let i = 0; i < cursorCount / 2; i += 1) {
            request = store.openCursor();
          }

          let continued = false;
          request.onsuccess = testCase.step_func(() => {
            const cursor = request.result;

            if (!continued) {
              assert_equals(cursor.key, '42');
              assert_equals(cursor.value.key, '42');
              continued = true;
              cursor.continue();
            } else {
              assert_equals(cursor, null);
              resolve();
            }
          });
          request.onerror = () => reject(request.error);
        });
        promises.push(promise);
      }
      return Promise.all(promises);
    }).then(database => {
      database.close();
    });
  }, `${cursorCount} cursors`);
}

</script>