Home | History | Annotate | Download | only in indexeddb
      1 <html>
      2 <head>
      3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
      4 <script src="../../fast/js/resources/js-test-pre.js"></script>
      5 <script src="../../fast/js/resources/js-test-post-function.js"></script>
      6 <script src="resources/shared.js"></script>
      7 </head>
      8 <body>
      9 <p id="description"></p>
     10 <div id="console"></div>
     11 <script>
     12 
     13 description("Test IndexedDB's createObjectStore's various options");
     14 if (window.layoutTestController)
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     shouldBeTrue("'webkitIndexedDB' in window");
     20     shouldBeFalse("webkitIndexedDB == null");
     21 
     22     request = evalAndLog("webkitIndexedDB.open('create-object-store-options', 'description')");
     23     request.onsuccess = openSuccess;
     24     request.onerror = unexpectedErrorCallback;
     25 }
     26 
     27 function openSuccess()
     28 {
     29     db = evalAndLog("db = event.target.result");
     30 
     31     request = evalAndLog("request = db.setVersion('version 1')");
     32     request.onsuccess = cleanDatabase;
     33     request.onerror = unexpectedErrorCallback;
     34 }
     35 
     36 function cleanDatabase()
     37 {
     38     deleteAllObjectStores(db);
     39 
     40     evalAndLog("db.createObjectStore('a', {keyPath: 'a'})");
     41     evalAndLog("db.createObjectStore('b')");
     42 
     43     debug("db.createObjectStore('c', {autoIncrement: true});");
     44     db.createObjectStore('c', {autoIncrement: true});
     45 
     46     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     47     shouldBe("trans.mode", "webkitIDBTransaction.READ_WRITE");
     48 
     49     req = evalAndLog("trans.objectStore('a').put({'a': 0})");
     50     req.onsuccess = putB;
     51     req.onerror = unexpectedErrorCallback;
     52 }
     53 
     54 function putB()
     55 {
     56     req = evalAndLog("trans.objectStore('b').put({'a': 0}, 0)");  // OOPS
     57     req.onsuccess = getA;
     58     req.onerror = unexpectedErrorCallback;
     59 }
     60 
     61 function getA()
     62 {
     63     req = evalAndLog("trans.objectStore('a').get(0)");
     64     req.onsuccess = getB;
     65     req.onerror = unexpectedErrorCallback;
     66 }
     67 
     68 function getB()
     69 {
     70     shouldBe("event.target.result.a", "{a: 0}");
     71 
     72     req = evalAndLog("trans.objectStore('b').get(0)");
     73     req.onsuccess = checkB;
     74     req.onerror = unexpectedErrorCallback;
     75 }
     76 
     77 function checkB()
     78 {
     79     shouldBe("event.target.result.a", "{a: 0}");
     80 
     81     done();
     82 }
     83 
     84 var successfullyParsed = true;
     85 
     86 test();
     87 
     88 </script>
     89 </body>
     90 </html>
     91