OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <!-- | 3 <!-- |
4 Copyright 2014 The Chromium Authors. All rights reserved. | 4 Copyright 2014 The Chromium Authors. All rights reserved. |
5 Use of this source code is governed by a BSD-style license that can be | 5 Use of this source code is governed by a BSD-style license that can be |
6 found in the LICENSE file. | 6 found in the LICENSE file. |
7 --> | 7 --> |
8 <head> | 8 <head> |
9 <title>IDB test that db's corrupted while open are properly handled Part 1 / 2</
title> | 9 <title>IDB test that db's corrupted while open are properly handled Part 1 / 2</
title> |
10 <script type="text/javascript" src="common.js"></script> | 10 <script type="text/javascript" src="common.js"></script> |
11 <script> | 11 <script> |
12 | 12 |
| 13 var testType = 'get'; |
| 14 |
13 function test() { | 15 function test() { |
| 16 testType = location.hash.substring(1); |
14 indexedDBTest(upgradeCallback, openCallback); | 17 indexedDBTest(upgradeCallback, openCallback); |
15 } | 18 } |
16 | 19 |
17 var numObjectsWrittenToDb = 500; | 20 var numObjectsWrittenToDb = 500; |
18 var numTransactions = 0; | 21 var numTransactions = 0; |
19 var numTransactionErrors = 0; | 22 var numTransactionErrors = 0; |
20 var numTransactionAborts = 0; | 23 var numTransactionAborts = 0; |
21 var numKeys = 0; | 24 var numKeys = 0; |
22 var transaction; | 25 var transaction; |
23 var request; | 26 var request; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 db.onclose = databaseClosed; | 88 db.onclose = databaseClosed; |
86 transaction.onabort = transactionAbort; | 89 transaction.onabort = transactionAbort; |
87 transaction.onerror = transactionError; | 90 transaction.onerror = transactionError; |
88 request.oncomplete = unexpectedCompleteCallback; | 91 request.oncomplete = unexpectedCompleteCallback; |
89 store = transaction.objectStore('storeName'); | 92 store = transaction.objectStore('storeName'); |
90 request = store.get('key-0'); | 93 request = store.get('key-0'); |
91 request.onsuccess = unexpectedSuccessCallback; | 94 request.onsuccess = unexpectedSuccessCallback; |
92 request.onerror = requestError; | 95 request.onerror = requestError; |
93 } | 96 } |
94 | 97 |
| 98 function iterateData() { |
| 99 transaction = db.transaction('storeName'); |
| 100 db.onclose = databaseClosed; |
| 101 transaction.onabort = transactionAbort; |
| 102 transaction.onerror = transactionError; |
| 103 var store = transaction.objectStore('storeName'); |
| 104 var request = store.openCursor(); |
| 105 request.oncomplete = unexpectedCompleteCallback; |
| 106 request.onerror = requestError; |
| 107 request.onsuccess = function (event){ |
| 108 var cursor = request.result; |
| 109 if (cursor) { |
| 110 // Get an object. Probably shouldn't get this far, but won't call this an
error. |
| 111 cursor.continue(); |
| 112 } else { |
| 113 // Got the last object. We shouldn't get this far. |
| 114 fail("Should *not* have been able to iterate over database."); |
| 115 } |
| 116 }; |
| 117 } |
| 118 |
95 function openCallback() { | 119 function openCallback() { |
96 var xmlhttp = new window.XMLHttpRequest(); | 120 var xmlhttp = new window.XMLHttpRequest(); |
97 xmlhttp.open("GET", "/corrupt/test/corruptdb?storeName", false /*sync*/); | 121 xmlhttp.open("GET", "/corrupt/test/corruptdb?storeName", false /*sync*/); |
98 xmlhttp.onreadystatechange = function() { | 122 xmlhttp.onreadystatechange = function() { |
99 if (xmlhttp.readyState === 4) { | 123 if (xmlhttp.readyState === 4) { |
100 if (xmlhttp.status === 200) { | 124 if (xmlhttp.status === 200) { |
101 // The database is now corrupt. | 125 // The database is now corrupt. |
102 getData(); | 126 if (testType === 'get') { |
| 127 getData(); |
| 128 } else if (testType === 'iterate') { |
| 129 iterateData(); |
| 130 } else { |
| 131 fail('Unknown test: "' + testType + '"'); |
| 132 } |
103 } | 133 } |
104 } | 134 } |
105 }; | 135 }; |
106 xmlhttp.send(); | 136 xmlhttp.send(); |
107 } | 137 } |
108 | 138 |
109 </script> | 139 </script> |
110 </head> | 140 </head> |
111 <body onLoad="test()"> | 141 <body onLoad="test()"> |
112 <div id="status">Starting...</div> | 142 <div id="status">Starting...</div> |
113 </body> | 143 </body> |
114 </html> | 144 </html> |
OLD | NEW |