OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../inspector-test.js"></script> |
| 4 <script src="indexeddb-test.js"></script> |
| 5 <script> |
| 6 function test() |
| 7 { |
| 8 var indexedDBModel = new WebInspector.IndexedDBModel(WebInspector.targetMana
ger.mainTarget()); |
| 9 indexedDBModel.enable(); |
| 10 var mainFrameId = InspectorTest.resourceTreeModel.mainFrame.id; |
| 11 var securityOrigin = "http://127.0.0.1:8000"; |
| 12 var databaseName = "testDatabase - " + self.location; |
| 13 var objectStoreName = "testObjectStore"; |
| 14 var databaseId = new WebInspector.IndexedDBModel.DatabaseId(securityOrigin,
databaseName); |
| 15 |
| 16 function onConsoleError(callback) { |
| 17 var old = console.error; |
| 18 console.error = function(message) { |
| 19 console.error = old; |
| 20 InspectorTest.addResult(message); |
| 21 callback(); |
| 22 }; |
| 23 } |
| 24 |
| 25 function addIDBValues(count, callback) |
| 26 { |
| 27 var i = 0; |
| 28 addValues(); |
| 29 |
| 30 function addValues() |
| 31 { |
| 32 if (i == count) { |
| 33 callback(); |
| 34 return; |
| 35 } |
| 36 ++i; |
| 37 var id = i < 10 ? "0" + i : i; |
| 38 var key = "key_" + id; |
| 39 var value = "value_" + id; |
| 40 InspectorTest.addIDBValue(mainFrameId, databaseName, objectStoreName
, { key: key, value: value }, "", addValues); |
| 41 } |
| 42 } |
| 43 |
| 44 function loadValues(skipCount, pageSize, callback) |
| 45 { |
| 46 indexedDBModel.loadObjectStoreData(databaseId, objectStoreName, null, sk
ipCount, pageSize, innerCallback); |
| 47 |
| 48 function innerCallback(entries, hasMore) |
| 49 { |
| 50 callback(); |
| 51 } |
| 52 } |
| 53 |
| 54 InspectorTest.addSniffer(WebInspector.IndexedDBModel.prototype, "_updateOrig
inDatabaseNames", fillDatabase, false); |
| 55 |
| 56 function fillDatabase() |
| 57 { |
| 58 InspectorTest.addResult('Preparing database'); |
| 59 InspectorTest.deleteDatabase(mainFrameId, databaseName, step2); |
| 60 |
| 61 function step2() |
| 62 { |
| 63 InspectorTest.createDatabase(mainFrameId, databaseName, step3); |
| 64 } |
| 65 |
| 66 function step3() |
| 67 { |
| 68 InspectorTest.createObjectStore(mainFrameId, databaseName, objectSto
reName, "key", true, step4); |
| 69 } |
| 70 |
| 71 function step4() |
| 72 { |
| 73 addIDBValues(6, step5); |
| 74 } |
| 75 |
| 76 function step5() |
| 77 { |
| 78 InspectorTest.addResult('Verifying that database was created'); |
| 79 checkDatabaseDoesExist(loadValuesAndDeleteDatabase); |
| 80 } |
| 81 } |
| 82 |
| 83 function loadValuesAndDeleteDatabase() |
| 84 { |
| 85 InspectorTest.addResult('Loading values'); |
| 86 loadValues(0, 2, step2); |
| 87 |
| 88 function step2() |
| 89 { |
| 90 InspectorTest.addResult('Deleting database'); |
| 91 InspectorTest.deleteDatabase(mainFrameId, databaseName, step3); |
| 92 } |
| 93 |
| 94 function step3() |
| 95 { |
| 96 // ... but access the database again. This will implicitly attempt t
o recreate it, |
| 97 // which should be aborted during the "upgradeneeded" event. |
| 98 InspectorTest.addResult('Loading values again (which should fail)'); |
| 99 loadValues(0, 2, function() { InspectorTest.addResult("Unexpected ca
llback"); }); |
| 100 onConsoleError(step4); |
| 101 } |
| 102 |
| 103 function step4() |
| 104 { |
| 105 InspectorTest.addResult('Verifying that database was not recreated')
; |
| 106 checkDatabaseDoesNotExist(step5); |
| 107 } |
| 108 |
| 109 function step5() |
| 110 { |
| 111 InspectorTest.completeTest(); |
| 112 } |
| 113 } |
| 114 |
| 115 function checkDatabaseDoesExist(callback) |
| 116 { |
| 117 InspectorTest.addSniffer(WebInspector.IndexedDBModel.prototype, "_update
OriginDatabaseNames", step2, false); |
| 118 indexedDBModel.refreshDatabaseNames(); |
| 119 |
| 120 function step2() |
| 121 { |
| 122 var names = indexedDBModel._databaseNamesBySecurityOrigin[securityOr
igin]; |
| 123 InspectorTest.assertGreaterOrEqual(0, names.indexOf(databaseName), "
Database should exist"); |
| 124 callback(); |
| 125 } |
| 126 } |
| 127 |
| 128 function checkDatabaseDoesNotExist(callback) |
| 129 { |
| 130 InspectorTest.addSniffer(WebInspector.IndexedDBModel.prototype, "_update
OriginDatabaseNames", step2, false); |
| 131 indexedDBModel.refreshDatabaseNames(); |
| 132 |
| 133 function step2() |
| 134 { |
| 135 var names = indexedDBModel._databaseNamesBySecurityOrigin[securityOr
igin]; |
| 136 InspectorTest.assertEquals(-1, names.indexOf(databaseName), "Databas
e should not exist"); |
| 137 callback(); |
| 138 } |
| 139 } |
| 140 } |
| 141 </script> |
| 142 </head> |
| 143 <body onload="runTest()"> |
| 144 <p>Tests that deleted databases do not get recreated.</p> |
| 145 </body> |
| 146 </html> |
OLD | NEW |