GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / test / data / indexeddb / version_change_crash.js
blob7fa1465408c7d408cce05f76df2a611f0fe7a3e7
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function test()
7   if (document.location.hash === '#part1') {
8     testPart1();
9   } else if (document.location.hash === '#part2') {
10     testPart2();
11   } else if (document.location.hash === '#part3') {
12     testPart3();
13   } else {
14     result('fail - unexpected hash');
15   }
18 function testPart1()
20   // Prepare the database, then exit normally
22   // Set version 1, create store1
23   var delreq = window.indexedDB.deleteDatabase('version-change-crash');
24   delreq.onerror = unexpectedErrorCallback;
25   delreq.onsuccess = function() {
26     var openreq = window.indexedDB.open('version-change-crash', 1);
27     openreq.onerror = unexpectedErrorCallback;
28     openreq.onblocked = unexpectedBlockedCallback;
29     openreq.onupgradeneeded = function(e) {
30       openreq.result.createObjectStore('store1');
31     };
32     openreq.onsuccess = function(e) {
33       result('pass - part1 - complete');
34     };
35   };
38 function testPart2()
40   // Start a VERSION_CHANGE then crash
42   // Set version 2, twiddle stores and crash
43   var openreq = window.indexedDB.open('version-change-crash', 2);
44   openreq.onerror = unexpectedErrorCallback;
45   openreq.onblocked = unexpectedBlockedCallback;
46   openreq.onsuccess = unexpectedSuccessCallback;
47   openreq.onupgradeneeded = function(e) {
48     var db = openreq.result;
49     var transaction = openreq.transaction;
50     transaction.onabort = unexpectedAbortCallback;
51     transaction.oncomplete = unexpectedCompleteCallback;
53     var store = db.createObjectStore('store2');
54     result('pass - part2 - crash me');
56     // Keep adding to the transaction so it can't commit
57     (function loop() { store.put(0, 0).onsuccess = loop; }());
58   };
61 function testPart3()
63   // Validate that Part 2 never committed
65   // Check version
66   var openreq = window.indexedDB.open('version-change-crash');
67   openreq.onerror = unexpectedErrorCallback;
68   openreq.onblocked = unexpectedBlockedCallback;
69   openreq.onupgradeneeded = unexpectedUpgradeNeededCallback;
70   openreq.onsuccess = function(e) {
71     var db = openreq.result;
72     if (db.version !== 1) {
73       result('fail - version incorrect');
74       return;
75     }
77     if (!db.objectStoreNames.contains('store1')) {
78       result('fail - store1 does not exist');
79       return;
80     }
82     if (db.objectStoreNames.contains('store2')) {
83       result('fail - store2 exists');
84       return;
85     }
87     result('pass - part3 - rolled back');
88   };