summaryrefslogtreecommitdiffstats
path: root/content/test/data/indexeddb/transaction_run_forever.js
blob: 3a793404d9b8dd6eb774417ba659482f1c000c1c (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
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

loopCount = 0;
function endlessLoop()
{
  var request = objectStore.get(0);
  request.onsuccess = endlessLoop;
  request.onerror = unexpectedErrorCallback;

  loopCount += 1;
  if (loopCount == 7) {
    // If we've already looped 7 times, it's pretty safe to assume
    // we'll continue looping for some time...
    debug("Looping infinitely within a transaction.");
    done();
  }
}

function newTransactionComplete()
{
  debug('The transaction completed.');

  var finalTransaction = db.transaction(['employees'],
                                        'readonly');
  finalTransaction.oncomplete = unexpectedCompleteCallback;
  finalTransaction.onabort = unexpectedErrorCallback;

  objectStore = finalTransaction.objectStore('employees');
  endlessLoop();
  endlessLoop(); // Make sure at least one is in flight at any time.
}

function onSetVersionComplete()
{
  debug('Creating new transaction.');
  var newTransaction = db.transaction(['employees'], 'readwrite');
  newTransaction.oncomplete = newTransactionComplete;
  newTransaction.onabort = unexpectedAbortCallback;

  var request = newTransaction.objectStore('employees').put(
      {id: 0, name: 'John Doe', desk: 'LON-BEL-123'});
  request.onerror = unexpectedErrorCallback;
}

function onSetVersion()
{
  // We are now in a set version transaction.
  debug('Creating object store.');
  db = event.target.result;
  deleteAllObjectStores(db);
  var objectStore = db.createObjectStore('employees', {keyPath: 'id'});
}

function test()
{
  if ('webkitIndexedDB' in window) {
    indexedDB = webkitIndexedDB;
    IDBCursor = webkitIDBCursor;
    IDBKeyRange = webkitIDBKeyRange;
    IDBTransaction = webkitIDBTransaction;
  }
  indexedDBTest(onSetVersion, onSetVersionComplete);
}