Index: content/test/data/indexeddb/corrupted_open_db_detection.html |
diff --git a/content/test/data/indexeddb/corrupted_open_db_detection.html b/content/test/data/indexeddb/corrupted_open_db_detection.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..198aed551b8562f7204bf4893915ca14f5668b78 |
--- /dev/null |
+++ b/content/test/data/indexeddb/corrupted_open_db_detection.html |
@@ -0,0 +1,114 @@ |
+<!DOCTYPE html> |
+<html> |
+<!-- |
+ Copyright 2014 The Chromium Authors. All rights reserved. |
+ Use of this source code is governed by a BSD-style license that can be |
+ found in the LICENSE file. |
+--> |
+<head> |
+<title>IDB test that db's corrupted while open are properly handled Part 1 / 2</title> |
+<script type="text/javascript" src="common.js"></script> |
+<script> |
+ |
+function test() { |
+ indexedDBTest(upgradeCallback, openCallback); |
+} |
+ |
+var numObjectsWrittenToDb = 500; |
+var numTransactions = 0; |
+var numTransactionErrors = 0; |
+var numTransactionAborts = 0; |
+var numKeys = 0; |
+var transaction; |
+var request; |
+var db; |
+var objectStore; |
+ |
+function upgradeCallback() { |
+ db = event.target.result; |
+ deleteAllObjectStores(db); |
+ objectStore = db.createObjectStore('storeName', { autoIncrement : true }); |
+ |
+ var i; |
+ var len = 80; |
+ var data = Array(len); |
+ for (i = 0; i < len; ++i) { |
+ data[i] = i; |
+ } |
+ |
+ for (i = 0; i < numObjectsWrittenToDb; ++i) { |
+ var key = 'key-' + i; |
+ request = objectStore.add(data, key); |
+ request.onerror = unexpectedErrorCallback; |
+ request.onsuccess = upgradeTransactionComplete; |
+ } |
+} |
+ |
+function upgradeTransactionComplete() { |
+ ++numTransactions; |
+ if (numTransactions === numObjectsWrittenToDb) { |
+ debug("All transactions written"); |
+ } |
+} |
+ |
+function transactionError(event) { |
+ if (event.target.error) { |
+ numTransactionErrors += 1; |
+ } else { |
+ fail("Transaction onerror had no error"); |
+ } |
+} |
+ |
+function transactionAbort() { |
+ if (event.target.error) { |
+ numTransactionAborts += 1; |
+ } else { |
+ fail("Transaction onabort had no error"); |
+ } |
+} |
+ |
+function requestError(event) { |
+ if (!event.target.error) { |
+ fail("get request had no/invalid error"); |
+ } |
+} |
+ |
+function databaseClosed(event) { |
+ shouldBe("numTransactionErrors", "1"); |
+ shouldBe("numTransactionAborts", "1"); |
+ |
+ done("Closed as expected"); |
+} |
+ |
+function getData() { |
+ transaction = db.transaction('storeName'); |
+ db.onclose = databaseClosed; |
+ transaction.onabort = transactionAbort; |
+ transaction.onerror = transactionError; |
+ request.oncomplete = unexpectedCompleteCallback; |
+ store = transaction.objectStore('storeName'); |
+ request = store.get('key-0'); |
+ request.onsuccess = unexpectedSuccessCallback; |
+ request.onerror = requestError; |
+} |
+ |
+function openCallback() { |
+ var xmlhttp = new window.XMLHttpRequest(); |
+ xmlhttp.open("GET", "/corrupt/test/corruptdb?storeName", false /*sync*/); |
+ xmlhttp.onreadystatechange = function() { |
+ if (xmlhttp.readyState === 4) { |
+ if (xmlhttp.status === 200) { |
+ // The database is now corrupt. |
+ getData(); |
+ } |
+ } |
+ }; |
+ xmlhttp.send(); |
+} |
+ |
+</script> |
+</head> |
+<body onLoad="test()"> |
+<div id="status">Starting...</div> |
+</body> |
+</html> |