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

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: 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
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..c8721bafee3b571c5a930c45067c198cfe39e406
--- /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;
+
+function upgradeCallback() {
+ window.db = event.target.result;
jsbell 2014/03/26 18:16:58 We should be consistent and either use 'window.XXX
cmumford 2014/03/26 21:40:36 Done.
+ deleteAllObjectStores(window.db);
+ window.objectStore = window.db.createObjectStore('storeName', { autoIncrement : true });
+
+ var i;
+ var len = 80;
+ var data = Array(len);
+ for (i = 0; i < len; i++) {
jsbell 2014/03/26 18:16:58 Nit: pre-increment
cmumford 2014/03/26 21:40:36 Done.
+ data[i] = i;
+ }
+
+ for (i = 0; i < numObjectsWrittenToDb; i++) {
jsbell 2014/03/26 18:16:58 Nit: pre-increment
cmumford 2014/03/26 21:40:36 Done.
+ var key = 'key-' + i;
+ request = window.objectStore.add(data, key);
+ request.onerror = unexpectedErrorCallback;
+ request.onsuccess = upgradeTransactionComplete;
+ }
+}
+
+function upgradeTransactionComplete() {
+ numTransactions++;
jsbell 2014/03/26 18:16:58 Nit: pre-increment
cmumford 2014/03/26 21:40:36 Done, but just curious why?
jsbell 2014/03/26 22:49:00 It's just Chromium/Blink coding convention. Post-i
+ if (numTransactions == numObjectsWrittenToDb) {
jsbell 2014/03/26 18:16:58 Nit: ===
cmumford 2014/03/26 21:40:36 Done, but just curious why?
jsbell 2014/03/26 22:49:00 double-equals is really busted in JS due to type c
+ debug("All transactions written");
+ }
+}
+
+function transactionError(event) {
+ if (event.target.error) {
+ numTransactionErrors += 1;
+ }
+ else {
jsbell 2014/03/26 18:16:58 nit: } and else on same line
cmumford 2014/03/26 21:40:36 Done.
+ fail("Transaction onerror had no error");
+ }
+}
+
+function transactionAbort() {
+ if (event.target.error) {
+ numTransactionAborts += 1;
+ }
+ else {
jsbell 2014/03/26 18:16:58 nit: } and else on same line
cmumford 2014/03/26 21:40:36 Done.
+ 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 = window.db.transaction('storeName');
+ window.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) {
jsbell 2014/03/26 18:16:58 Nit: === (and below)
cmumford 2014/03/26 21:40:36 Done.
+ if (xmlhttp.status == 200) {
+ // The database is now corrupt.
+ getData();
+ }
+ }
+ };
+ xmlhttp.send();
+}
+
+</script>
+</head>
+<body onLoad="test()">
+<div id="status">Starting...</div>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698