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.
7 if (document.location.hash === '#part1') {
9 } else if (document.location.hash === '#part2') {
11 } else if (document.location.hash === '#part3') {
14 result('fail - unexpected hash');
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');
32 openreq.onsuccess = function(e) {
33 result('pass - part1 - complete');
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; }());
63 // Validate that Part 2 never committed
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');
77 if (!db.objectStoreNames.contains('store1')) {
78 result('fail - store1 does not exist');
82 if (db.objectStoreNames.contains('store2')) {
83 result('fail - store2 exists');
87 result('pass - part3 - rolled back');