OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 window.indexedDB = window.indexedDB || window.webkitIndexedDB; | 5 window.indexedDB = window.indexedDB || window.webkitIndexedDB; |
6 window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction; | 6 window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction; |
7 | 7 |
8 window.testResult = ''; | 8 function unexpectedErrorCallback() |
| 9 { |
| 10 document.title = 'fail - unexpected error callback'; |
| 11 } |
| 12 function unexpectedAbortCallback() |
| 13 { |
| 14 document.title = 'fail - unexpected abort callback'; |
| 15 } |
9 | 16 |
10 function test() | 17 function test() |
11 { | 18 { |
12 var req = window.indexedDB.open('bug90635'); | 19 if (document.location.hash === '#part1') { |
13 req.onerror = function(e) { | 20 testPart1(); |
14 window.testResult = 'fail'; | 21 } else if (document.location.hash === '#part2') { |
15 }; | 22 testPart2(); |
16 req.onsuccess = function(e) { | 23 } else { |
17 var db = e.target.result; | 24 document.title = 'fail - no hash'; |
18 var VERSION = '1'; | 25 } |
19 if (db.version !== VERSION) { | 26 } |
20 var ver = db.setVersion(VERSION); | 27 |
21 ver.onerror = function(e) { | 28 function testPart1() |
22 window.testResult = 'fail'; | 29 { |
23 }; | 30 var delreq = window.indexedDB.deleteDatabase('bug90635'); |
24 ver.onsuccess = function(e) { | 31 delreq.onerror = unexpectedErrorCallback; |
| 32 delreq.onsuccess = function() { |
| 33 var openreq = window.indexedDB.open('bug90635'); |
| 34 openreq.onerror = unexpectedErrorCallback; |
| 35 openreq.onsuccess = function(e) { |
| 36 var db = openreq.result; |
| 37 var setverreq = db.setVersion('1'); |
| 38 setverreq.onerror = unexpectedErrorCallback; |
| 39 setverreq.onsuccess = function(e) { |
| 40 var transaction = setverreq.result; |
| 41 |
25 db.createObjectStore('store1'); | 42 db.createObjectStore('store1'); |
26 db.createObjectStore('store2', {keyPath: ''}); | 43 db.createObjectStore('store2', {keyPath: ''}); |
27 db.createObjectStore('store3', {keyPath: 'some_path'}); | 44 db.createObjectStore('store3', {keyPath: 'some_path'}); |
28 test_store(db, 'first run'); | 45 |
| 46 transaction.onabort = unexpectedAbortCallback; |
| 47 transaction.oncomplete = function() { |
| 48 test_store(db, 'first run'); |
| 49 }; |
29 }; | 50 }; |
30 } else { | 51 }; |
31 test_store(db, 'second run'); | |
32 } | |
33 }; | 52 }; |
| 53 } |
34 | 54 |
35 function test_store(db, msg) { | 55 function testPart2() |
36 var transaction = db.transaction(['store1', 'store2', 'store3'], | 56 { |
37 IDBTransaction.READ_ONLY); | 57 var openreq = window.indexedDB.open('bug90635'); |
38 var store1 = transaction.objectStore('store1'); | 58 openreq.onerror = unexpectedErrorCallback; |
39 var store2 = transaction.objectStore('store2'); | 59 openreq.onsuccess = function(e) { |
40 var store3 = transaction.objectStore('store3'); | 60 var db = openreq.result; |
| 61 test_store(db, 'second run'); |
| 62 }; |
| 63 } |
41 | 64 |
42 if (store1.keyPath !== null || | 65 function test_store(db, msg) { |
43 store2.keyPath !== '' || | 66 var transaction = db.transaction(['store1', 'store2', 'store3'], |
44 store3.keyPath !== 'some_path') { | 67 IDBTransaction.READ_ONLY); |
45 window.testResult = 'fail - ' + msg; | 68 var store1 = transaction.objectStore('store1'); |
46 } else { | 69 var store2 = transaction.objectStore('store2'); |
47 window.testResult = 'pass - ' + msg; | 70 var store3 = transaction.objectStore('store3'); |
48 } | 71 |
| 72 if (store1.keyPath !== null || |
| 73 store2.keyPath !== '' || |
| 74 store3.keyPath !== 'some_path') { |
| 75 document.title = 'fail - ' + msg; |
| 76 } else { |
| 77 document.title = 'pass - ' + msg; |
49 } | 78 } |
50 } | 79 } |
OLD | NEW |