Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: content/test/data/indexeddb/corrupted_open_db_detection.html

Issue 197333009: Handling LevelDB errors encountered after open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted two unecessary changes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/data/indexeddb/common.js ('k') | content/test/data/indexeddb/corrupted_open_db_recovery.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « content/test/data/indexeddb/common.js ('k') | content/test/data/indexeddb/corrupted_open_db_recovery.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698