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.clear()."); 14 if (window.layoutTestController) 15 layoutTestController.waitUntilDone(); 16 17 function test() 18 { 19 request = evalAndLog("webkitIndexedDB.open('objectstore-clear')"); 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 = createSecondObjectStoreAndAddValue; 47 request.onerror = unexpectedErrorCallback; 48 } 49 50 function createSecondObjectStoreAndAddValue() 51 { 52 otherStore = evalAndLog("otherStore = db.createObjectStore('otherStoreName', null)"); 53 54 request = evalAndLog("otherStore.add('value', 'key')"); 55 request.onsuccess = clearObjectStore; 56 request.onerror = unexpectedErrorCallback; 57 } 58 59 function clearObjectStore() 60 { 61 request = evalAndLog("store.clear()"); 62 request.onsuccess = clearSuccess; 63 request.onerror = unexpectedErrorCallback; 64 } 65 66 function clearSuccess() 67 { 68 shouldBeUndefined("event.target.result"); 69 70 request = evalAndLog("store.openCursor()"); 71 request.onsuccess = openCursorSuccess; 72 request.onerror = unexpectedErrorCallback; 73 } 74 75 function openCursorSuccess() 76 { 77 shouldBeNull("event.target.result"); 78 79 index = evalAndLog("index = store.index('indexName')"); 80 request = evalAndLog("index.openKeyCursor()"); 81 request.onsuccess = openKeyCursorSuccess; 82 request.onerror = unexpectedErrorCallback; 83 } 84 85 function openKeyCursorSuccess() 86 { 87 debug("openKeyCursorSuccess():"); 88 shouldBeNull("event.target.result"); 89 90 transaction = evalAndLog("db.transaction({mode: webkitIDBTransaction.READ_WRITE})"); 91 transaction.onabort = unexpectedErrorCallback; 92 var otherStore = evalAndLog("otherStore = transaction.objectStore('otherStoreName')"); 93 94 request = evalAndLog("otherStore.get('key')"); 95 request.onsuccess = getSuccess; 96 request.onerror = unexpectedErrorCallback; 97 } 98 99 function getSuccess() 100 { 101 shouldBeEqualToString("event.target.result", "value"); 102 103 done(); 104 } 105 106 test(); 107 108 var successfullyParsed = true; 109 </script> 110 </body> 111 </html> 112