Home | History | Annotate | Download | only in indexeddb
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 function finalTransactionCompleted()
      6 {
      7   debug('The final transaction completed.');
      8   done();
      9 }
     10 
     11 function finalTransactionAborted()
     12 {
     13   fail('The final transaction should not abort.');
     14 }
     15 
     16 function employeeNotFound()
     17 {
     18   debug('Employee not found.');
     19   shouldBe("event.target.result", "undefined");
     20 }
     21 
     22 function newTransactionAborted()
     23 {
     24   debug('The transaction was aborted.');
     25 
     26   var finalTransaction = db.transaction(['employees'],
     27                                         'readonly');
     28   finalTransaction.oncomplete = finalTransactionCompleted;
     29   finalTransaction.onabort = finalTransactionAborted;
     30 
     31   var request = finalTransaction.objectStore('employees').get(0);
     32   request.onsuccess = employeeNotFound;
     33   request.onerror = unexpectedErrorCallback;
     34 }
     35 
     36 function newTransactionCompleted()
     37 {
     38   fail('The new transaction should not complete.');
     39 }
     40 
     41 function employeeAdded()
     42 {
     43   debug('Added an employee inside the transaction.');
     44   newTransaction.abort();
     45 }
     46 
     47 function onSetVersionComplete()
     48 {
     49   debug('Creating new transaction.');
     50   window.newTransaction = db.transaction(['employees'],
     51                                          'readwrite');
     52   newTransaction.oncomplete = newTransactionCompleted;
     53   newTransaction.onabort = newTransactionAborted;
     54 
     55   var request = newTransaction.objectStore('employees').put(
     56       {id: 0, name: 'John Doe', desk: 'LON-BEL-123'});
     57   request.onsuccess = employeeAdded;
     58   request.onerror = unexpectedErrorCallback;
     59 }
     60 
     61 function onSetVersion()
     62 {
     63   // We are now in a set version transaction.
     64   window.db = event.target.result;
     65   debug('Creating object store.');
     66   deleteAllObjectStores(db);
     67   db.createObjectStore('employees', {keyPath: 'id'});
     68 }
     69 
     70 function test()
     71 {
     72   if ('webkitIndexedDB' in window) {
     73     indexedDB = webkitIndexedDB;
     74     IDBCursor = webkitIDBCursor;
     75     IDBKeyRange = webkitIDBKeyRange;
     76     IDBTransaction = webkitIDBTransaction;
     77   }
     78   indexedDBTest(onSetVersion, onSetVersionComplete);
     79 }
     80