GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / test / data / indexeddb / corrupted_open_db_detection.html
blob12021fb8e81a35d662677c9880a6869710b70614
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>
13 var testType = 'get';
15 function test() {
16 testType = location.hash.substring(1);
17 if (testType == 'testCommon') {
18 fail('"testCommon" is a reserved test name');
19 return;
21 indexedDBTest(upgradeCallback, openCallback);
24 var numObjectsWrittenToDb = 5;
25 var numTransactions = 0;
26 var numTransactionErrors = 0;
27 var numTransactionAborts = 0;
28 var numKeys = 0;
29 var transaction;
30 var request;
31 var db;
32 var objectStore;
34 function upgradeCallback() {
35 db = event.target.result;
36 deleteAllObjectStores(db);
37 objectStore = db.createObjectStore('storeName', { autoIncrement : true });
39 var i;
40 var len = 80;
41 var data = Array(len);
42 for (i = 0; i < len; ++i) {
43 data[i] = i;
46 for (i = 0; i < numObjectsWrittenToDb; ++i) {
47 var key = 'key-' + i;
48 request = objectStore.add(data, key);
49 request.onerror = unexpectedErrorCallback;
50 request.onsuccess = upgradeTransactionComplete;
54 function upgradeTransactionComplete() {
55 ++numTransactions;
56 if (numTransactions === numObjectsWrittenToDb) {
57 debug("All transactions written");
61 function transactionError(event) {
62 if (event.target.error) {
63 numTransactionErrors += 1;
64 } else {
65 fail("Transaction onerror had no error");
69 function transactionAbort(event) {
70 if (event.target.error) {
71 numTransactionAborts += 1;
72 } else {
73 fail("Transaction onabort had no error");
77 function requestError(event) {
78 if (!event.target.error) {
79 fail("get request had no/invalid error");
83 function databaseClosed(event) {
84 shouldBe("numTransactionErrors", "1");
85 shouldBe("numTransactionAborts", "1");
87 done("Closed as expected");
90 function testXhr(url, onSuccess) {
91 var xmlhttp = new window.XMLHttpRequest();
92 xmlhttp.open("GET", url, /*async=*/false);
93 xmlhttp.onreadystatechange = function() {
94 if (xmlhttp.readyState === 4) {
95 if (xmlhttp.status === 200) {
96 onSuccess()
100 xmlhttp.send();
103 var tests = {
104 // Common setup tasks for the other tests in this object
105 testCommon: function(mode) {
106 transaction = db.transaction('storeName', mode);
107 db.onclose = databaseClosed;
108 transaction.onabort = transactionAbort;
109 transaction.onerror = transactionError;
110 objectStore = transaction.objectStore('storeName');
112 get: function() {
113 testXhr("/corrupt/test/fail?class=LevelDBTransaction&method=Get&instNum=1",
114 function() {
115 tests.testCommon('readonly');
116 request = objectStore.get('key-0');
117 request.onsuccess = unexpectedSuccessCallback;
118 request.onerror = requestError;
121 failTransactionCommit: function() {
122 tests.testCommon('readwrite');
123 db.onclose = function(event) {
124 shouldBe("numTransactionErrors", "0");
125 shouldBe("numTransactionAborts", "1");
127 done("Closed as expected");
129 testXhr("/corrupt/test/fail?class=LevelDBTransaction&method=Commit", function() {
130 request = objectStore.put("Any Value", 'key-0');
131 request.onerror = requestError;
134 failWebkitGetDatabaseNames: function() {
135 tests.testCommon('readonly');
136 gotRequestError = 0;
137 db.onclose = function(event) {
138 shouldBe("numTransactionErrors", "0");
139 shouldBe("numTransactionAborts", "1");
140 shouldBe("gotRequestError", "1");
142 done("Closed as expected");
144 testXhr("/corrupt/test/fail?class=LevelDBIterator&method=Seek", function() {
145 request = window.indexedDB.webkitGetDatabaseNames();
146 request.onsuccess = unexpectedSuccessCallback;
147 request.onerror = function(evt) {
148 gotRequestError += 1;
152 iterate: function() {
153 testXhr("/corrupt/test/corruptdb?storeName", function() {
154 tests.testCommon('readonly');
155 request = objectStore.openCursor();
156 request.onerror = requestError;
157 request.onsuccess = function (event){
158 var cursor = request.result;
159 if (cursor) {
160 // Get an object. Probably shouldn't get this far, but won't call this an error.
161 cursor.continue();
162 } else {
163 // Got the last object. We shouldn't get this far.
164 fail("Should *not* have been able to iterate over database.");
169 failGetBlobJournal: function() {
170 // Get() #1 is the put (GetNewVersionNumber)
171 // Get() #2 is the blob key generator (GetBlobKeyGeneratorCurrentNumber)
172 // Get() #3 is the journal (GetPrimaryBlobJournal)
173 testXhr("/corrupt/test/fail?class=LevelDBTransaction&method=Get&instNum=3", function() {
174 tests.testCommon('readwrite');
175 request = objectStore.put({blob: new Blob(['abc'])}, 'key-0');
176 request.onerror = requestError;
177 db.onclose = function databaseClosed(event) {
178 shouldBe("numTransactionErrors", "0");
179 shouldBe("numTransactionAborts", "1");
181 done("Closed as expected");
185 clearObjectStore: function() {
186 testXhr("/corrupt/test/corruptdb?storeName", function() {
187 tests.testCommon('readwrite');
188 request = objectStore.clear();
189 request.onerror = requestError;
190 request.onsuccess = unexpectedSuccessCallback
195 function openCallback() {
196 if (testType in tests)
197 tests[testType]();
198 else
199 fail('Unknown test: "' + testType + '"');
202 </script>
203 </head>
204 <body onLoad="test()">
205 <div id="status">Starting...</div>
206 </body>
207 </html>