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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <!--
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
6 found in the LICENSE file.
7 -->
8 <head>
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>
11 <script>
12
13 function test() {
14 indexedDBTest(upgradeCallback, openCallback);
15 }
16
17 var numObjectsWrittenToDb = 500;
18 var numTransactions = 0;
19 var numTransactionErrors = 0;
20 var numTransactionAborts = 0;
21 var numKeys = 0;
22 var transaction;
23 var request;
24 var db;
25 var objectStore;
26
27 function upgradeCallback() {
28 db = event.target.result;
29 deleteAllObjectStores(db);
30 objectStore = db.createObjectStore('storeName', { autoIncrement : true });
31
32 var i;
33 var len = 80;
34 var data = Array(len);
35 for (i = 0; i < len; ++i) {
36 data[i] = i;
37 }
38
39 for (i = 0; i < numObjectsWrittenToDb; ++i) {
40 var key = 'key-' + i;
41 request = objectStore.add(data, key);
42 request.onerror = unexpectedErrorCallback;
43 request.onsuccess = upgradeTransactionComplete;
44 }
45 }
46
47 function upgradeTransactionComplete() {
48 ++numTransactions;
49 if (numTransactions === numObjectsWrittenToDb) {
50 debug("All transactions written");
51 }
52 }
53
54 function transactionError(event) {
55 if (event.target.error) {
56 numTransactionErrors += 1;
57 } else {
58 fail("Transaction onerror had no error");
59 }
60 }
61
62 function transactionAbort() {
63 if (event.target.error) {
64 numTransactionAborts += 1;
65 } else {
66 fail("Transaction onabort had no error");
67 }
68 }
69
70 function requestError(event) {
71 if (!event.target.error) {
72 fail("get request had no/invalid error");
73 }
74 }
75
76 function databaseClosed(event) {
77 shouldBe("numTransactionErrors", "1");
78 shouldBe("numTransactionAborts", "1");
79
80 done("Closed as expected");
81 }
82
83 function getData() {
84 transaction = db.transaction('storeName');
85 db.onclose = databaseClosed;
86 transaction.onabort = transactionAbort;
87 transaction.onerror = transactionError;
88 request.oncomplete = unexpectedCompleteCallback;
89 store = transaction.objectStore('storeName');
90 request = store.get('key-0');
91 request.onsuccess = unexpectedSuccessCallback;
92 request.onerror = requestError;
93 }
94
95 function openCallback() {
96 var xmlhttp = new window.XMLHttpRequest();
97 xmlhttp.open("GET", "/corrupt/test/corruptdb?storeName", false /*sync*/);
98 xmlhttp.onreadystatechange = function() {
99 if (xmlhttp.readyState === 4) {
100 if (xmlhttp.status === 200) {
101 // The database is now corrupt.
102 getData();
103 }
104 }
105 };
106 xmlhttp.send();
107 }
108
109 </script>
110 </head>
111 <body onLoad="test()">
112 <div id="status">Starting...</div>
113 </body>
114 </html>
OLDNEW
« 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