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 the basics of IndexedDB's IDBDatabase.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('database-basics')");
     20     request.onsuccess = openSuccess;
     21     request.onerror = unexpectedErrorCallback;
     22 }
     23 
     24 function openSuccess()
     25 {
     26     window.db = evalAndLog("db = event.target.result");
     27 
     28     request = evalAndLog("db.setVersion('new version')");
     29     request.onsuccess = setVersionSuccess;
     30     request.onerror = unexpectedErrorCallback;
     31 }
     32 
     33 function setVersionSuccess()
     34 {
     35     debug("setVersionSuccess():");
     36     window.trans = evalAndLog("trans = event.target.result");
     37     shouldBeTrue("trans !== null");
     38     trans.onabort = unexpectedAbortCallback;
     39 
     40     deleteAllObjectStores(db);
     41 
     42     debug("Testing setVersion.");
     43     request = evalAndLog('db.setVersion("version a")');
     44     request.onsuccess = setVersionAgain;
     45     request.onerror = unexpectedErrorCallback;
     46 }
     47 
     48 function setVersionAgain()
     49 {
     50     request = evalAndLog('db.setVersion("version b")');
     51     request.onsuccess = createObjectStore;
     52     request.onerror = unexpectedErrorCallback;
     53 }
     54 
     55 function createObjectStore()
     56 {
     57     shouldBeEqualToString("db.version", "version b");
     58     shouldBeEqualToString("db.name", "database-basics");
     59     shouldBe("db.objectStoreNames", "[]");
     60     shouldBe("db.objectStoreNames.length", "0");
     61     shouldBe("db.objectStoreNames.contains('')", "false");
     62     shouldBeNull("db.objectStoreNames[0]");
     63     shouldBeNull("db.objectStoreNames.item(0)");
     64 
     65     objectStore = evalAndLog('db.createObjectStore("test123")');
     66     checkObjectStore();
     67     commitAndContinue();
     68 }
     69 
     70 function checkObjectStore()
     71 {
     72     shouldBe("db.objectStoreNames", "['test123']");
     73     shouldBe("db.objectStoreNames.length", "1");
     74     shouldBe("db.objectStoreNames.contains('')", "false");
     75     shouldBe("db.objectStoreNames.contains('test456')", "false");
     76     shouldBe("db.objectStoreNames.contains('test123')", "true");
     77 }
     78 
     79 function commitAndContinue()
     80 {
     81     window.setTimeout(testSetVersionAbort, 0);
     82 }
     83 
     84 function testSetVersionAbort()
     85 {
     86     request = evalAndLog('db.setVersion("version c")');
     87     request.onsuccess = createAnotherObjectStore;
     88     request.onerror = unexpectedErrorCallback;
     89 }
     90 
     91 function createAnotherObjectStore()
     92 {
     93     shouldBeEqualToString("db.version", "version c");
     94     shouldBeEqualToString("db.name", "database-basics");
     95     checkObjectStore();
     96 
     97     objectStore = evalAndLog('db.createObjectStore("test456")');
     98     var setVersionTrans = evalAndLog("setVersionTrans = event.target.result");
     99     shouldBeTrue("setVersionTrans !== null");
    100     setVersionTrans.oncomplete = unexpectedCompleteCallback;
    101     setVersionTrans.onabort = checkMetadata;
    102     setVersionTrans.abort();
    103 }
    104 
    105 function checkMetadata()
    106 {
    107     shouldBeEqualToString("db.version", "version b");
    108     checkObjectStore();
    109     done();
    110 }
    111 
    112 test();
    113 
    114 var successfullyParsed = true;
    115 
    116 </script>
    117 </body>
    118 </html>
    119