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 webkitIDBObjectStore.deleteObjectStore().");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('objectstore-removeobjectstore')");
     20     request.onsuccess = startSetVersion;
     21     request.onerror = unexpectedErrorCallback;
     22 }
     23 
     24 function startSetVersion()
     25 {
     26     db = evalAndLog("db = event.target.result");
     27 
     28     request = evalAndLog("db.setVersion('new version')");
     29     request.onsuccess = deleteExisting;
     30     request.onerror = unexpectedErrorCallback;
     31 }
     32 
     33 function deleteExisting()
     34 {
     35     window.trans = evalAndLog("trans = event.target.result");
     36     shouldBeTrue("trans !== null");
     37 
     38     deleteAllObjectStores(db);
     39 
     40     store = evalAndLog("store = db.createObjectStore('storeName', null)");
     41 
     42     window.index = evalAndLog("store.createIndex('indexName', '')");
     43     shouldBeTrue("store.indexNames.contains('indexName')");
     44 
     45     request = evalAndLog("store.add('value', 'key')");
     46     request.onsuccess = getValue;
     47     request.onerror = unexpectedErrorCallback;
     48 }
     49 
     50 function getValue()
     51 {
     52     transaction = evalAndLog("db.transaction({mode: webkitIDBTransaction.READ_WRITE})");
     53     transaction.onabort = unexpectedErrorCallback;
     54     var store = evalAndLog("store = transaction.objectStore('storeName')");
     55 
     56     request = evalAndLog("store.get('key')");
     57     request.onsuccess = addIndex;
     58     request.onerror = unexpectedErrorCallback;
     59 }
     60 
     61 function addIndex()
     62 {
     63     shouldBeEqualToString("event.target.result", "value");
     64 
     65     request = evalAndLog("db.setVersion('new version')");
     66     request.onsuccess = deleteObjectStore;
     67     request.onerror = unexpectedErrorCallback;
     68 }
     69 
     70 function deleteObjectStore()
     71 {
     72     window.trans = evalAndLog("trans = event.target.result");
     73     shouldBeTrue("trans !== null");
     74     trans.onabort = unexpectedAbortCallback;
     75 
     76     evalAndLog("db.deleteObjectStore('storeName')");
     77     createObjectStoreAgain();
     78 }
     79 
     80 function createObjectStoreAgain()
     81 {
     82     evalAndLog("db.createObjectStore('storeName', null)");
     83     getValueAgain();
     84 }
     85 
     86 function getValueAgain()
     87 {
     88     transaction = evalAndLog("db.transaction({mode: webkitIDBTransaction.READ_WRITE})");
     89     transaction.onabort = unexpectedErrorCallback;
     90     var store = evalAndLog("store = transaction.objectStore('storeName')");
     91 
     92     request = evalAndLog("store.get('key')");
     93     request.onsuccess = verifyNotFound;
     94     request.onerror = unexpectedErrorCallback;
     95 }
     96 
     97 function verifyNotFound()
     98 {
     99     shouldBe("event.target.result", "undefined");
    100     shouldBeFalse("event.target.source.indexNames.contains('indexName')");
    101 
    102     done();
    103 }
    104 
    105 test();
    106 
    107 var successfullyParsed = true;
    108 </script>
    109 </body>
    110 </html>
    111