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

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: 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
25 function upgradeCallback() {
26 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.
27 deleteAllObjectStores(window.db);
28 window.objectStore = window.db.createObjectStore('storeName', { autoIncrement : true });
29
30 var i;
31 var len = 80;
32 var data = Array(len);
33 for (i = 0; i < len; i++) {
jsbell 2014/03/26 18:16:58 Nit: pre-increment
cmumford 2014/03/26 21:40:36 Done.
34 data[i] = i;
35 }
36
37 for (i = 0; i < numObjectsWrittenToDb; i++) {
jsbell 2014/03/26 18:16:58 Nit: pre-increment
cmumford 2014/03/26 21:40:36 Done.
38 var key = 'key-' + i;
39 request = window.objectStore.add(data, key);
40 request.onerror = unexpectedErrorCallback;
41 request.onsuccess = upgradeTransactionComplete;
42 }
43 }
44
45 function upgradeTransactionComplete() {
46 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
47 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
48 debug("All transactions written");
49 }
50 }
51
52 function transactionError(event) {
53 if (event.target.error) {
54 numTransactionErrors += 1;
55 }
56 else {
jsbell 2014/03/26 18:16:58 nit: } and else on same line
cmumford 2014/03/26 21:40:36 Done.
57 fail("Transaction onerror had no error");
58 }
59 }
60
61 function transactionAbort() {
62 if (event.target.error) {
63 numTransactionAborts += 1;
64 }
65 else {
jsbell 2014/03/26 18:16:58 nit: } and else on same line
cmumford 2014/03/26 21:40:36 Done.
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 = window.db.transaction('storeName');
85 window.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) {
jsbell 2014/03/26 18:16:58 Nit: === (and below)
cmumford 2014/03/26 21:40:36 Done.
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

Powered by Google App Engine
This is Rietveld 408576698