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

Side by Side Diff: chrome/test/data/indexeddb/version_change_crash.js

Issue 10828378: Convert the indexed db pyauto tests to content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 function test()
6 {
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 }
16 }
17
18 function testPart1()
19 {
20 // Prepare the database, then exit normally
21
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');
27 openreq.onerror = unexpectedErrorCallback;
28 openreq.onsuccess = function(e) {
29 var db = openreq.result;
30 var setverreq = db.setVersion('1');
31 setverreq.onerror = unexpectedErrorCallback;
32 setverreq.onsuccess = function(e) {
33 var transaction = setverreq.result;
34 db.createObjectStore('store1');
35 transaction.onabort = unexpectedAbortCallback;
36 transaction.oncomplete = function (e) {
37 result('pass - part1 - complete');
38 };
39 };
40 };
41 };
42 }
43
44 function testPart2()
45 {
46 // Start a VERSION_CHANGE then crash
47
48 // Set version 2, twiddle stores and crash
49 var openreq = window.indexedDB.open('version-change-crash');
50 openreq.onerror = unexpectedErrorCallback;
51 openreq.onsuccess = function(e) {
52 var db = openreq.result;
53 var setverreq = db.setVersion('2');
54 setverreq.onerror = unexpectedErrorCallback;
55 setverreq.onsuccess = function(e) {
56 var transaction = setverreq.result;
57 transaction.onabort = unexpectedAbortCallback;
58 transaction.oncomplete = unexpectedCompleteCallback;
59
60 var store = db.createObjectStore('store2');
61 result('pass - part2 - crash me');
62
63 // Keep adding to the transaction so it can't commit
64 (function loop() { store.put(0, 0).onsuccess = loop; }());
65 };
66 };
67 }
68
69 function testPart3()
70 {
71 // Validate that Part 2 never committed
72
73 // Check version
74 var openreq = window.indexedDB.open('version-change-crash');
75 openreq.onerror = unexpectedErrorCallback;
76 openreq.onsuccess = function(e) {
77 var db = openreq.result;
78 if (db.version !== '1') {
79 result('fail - version incorrect');
80 return;
81 }
82
83 if (!db.objectStoreNames.contains('store1')) {
84 result('fail - store1 does not exist');
85 return;
86 }
87
88 if (db.objectStoreNames.contains('store2')) {
89 result('fail - store2 exists');
90 return;
91 }
92
93 result('pass - part3 - rolled back');
94 };
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698