OLD | NEW |
1 if (this.importScripts) { | 1 if (this.importScripts) { |
2 importScripts('../../../resources/js-test.js'); | 2 importScripts('../../../resources/js-test.js'); |
3 importScripts('shared.js'); | 3 importScripts('shared.js'); |
4 } | 4 } |
5 | 5 |
6 description("Ensure that aborted VERSION_CHANGE transactions are completely roll
ed back"); | 6 description("Ensure that aborted VERSION_CHANGE transactions are completely roll
ed back"); |
7 | 7 |
8 indexedDBTest(prepareDatabase, setVersion1Complete); | 8 self.isOnErrorTest = true; |
| 9 |
| 10 indexedDBTest(prepareDatabase, openRequest1Complete); |
9 function prepareDatabase() | 11 function prepareDatabase() |
10 { | 12 { |
11 db = event.target.result; | 13 db = event.target.result; |
12 trans = event.target.transaction; | 14 trans = event.target.transaction; |
13 shouldBeTrue("trans instanceof IDBTransaction"); | 15 shouldBeTrue("trans instanceof IDBTransaction"); |
14 trans.onabort = unexpectedAbortCallback; | 16 trans.onabort = unexpectedAbortCallback; |
15 trans.onerror = unexpectedErrorCallback; | 17 trans.onerror = unexpectedErrorCallback; |
16 | 18 |
17 evalAndLog("store = db.createObjectStore('store1')"); | 19 evalAndLog("db.createObjectStore('store1')"); |
18 } | 20 } |
19 | 21 |
20 function setVersion1Complete() | 22 function openRequest1Complete() |
21 { | 23 { |
22 debug("setVersion1 complete"); | 24 debug("openRequest1 complete"); |
23 shouldBe("db.version", "1"); | 25 shouldBe("db.version", "1"); |
24 debug(""); | 26 debug(""); |
25 db.close(); | 27 db.close(); |
26 | 28 |
27 evalAndLog("vcreq = indexedDB.open(dbname, 2)"); | 29 evalAndLog("vcreq = indexedDB.open(dbname, 2)"); |
28 vcreq.onupgradeneeded = inSetVersion2; | 30 vcreq.onupgradeneeded = inSetVersion2; |
29 vcreq.onerror = setVersion2Abort; | 31 vcreq.onerror = openRequest2Error; |
30 vcreq.onblocked = unexpectedBlockedCallback; | 32 vcreq.onblocked = unexpectedBlockedCallback; |
31 vcreq.onsuccess = unexpectedSuccessCallback; | 33 vcreq.onsuccess = unexpectedSuccessCallback; |
32 } | 34 } |
33 | 35 |
34 function inSetVersion2() | 36 function inSetVersion2() |
35 { | 37 { |
36 db = event.target.result; | 38 db = event.target.result; |
37 debug("setVersion2() callback"); | 39 debug("openRequest2() callback"); |
38 shouldBe("db.version", "2"); | 40 shouldBe("db.version", "2"); |
39 shouldBeTrue("vcreq.transaction instanceof IDBTransaction"); | 41 shouldBeTrue("vcreq.transaction instanceof IDBTransaction"); |
40 trans = vcreq.result; | 42 trans = vcreq.result; |
41 trans.onerror = unexpectedErrorCallback; | 43 trans.onerror = unexpectedErrorCallback; |
42 trans.oncomplete = unexpectedCompleteCallback; | 44 trans.oncomplete = unexpectedCompleteCallback; |
| 45 trans.onabort = onTransactionAbort; |
43 | 46 |
44 evalAndLog("store = db.deleteObjectStore('store1')"); | 47 evalAndLog("db.deleteObjectStore('store1')"); |
45 evalAndLog("store = db.createObjectStore('store2')"); | 48 evalAndLog("db.createObjectStore('store2')"); |
46 | 49 |
47 // Ensure the test harness error handler is not invoked. | 50 // Throwing an exception during the callback should: |
48 self.originalWindowOnError = self.onerror; | 51 // * fire window.onerror (uncaught within event dispatch) |
49 self.onerror = null; | 52 // * Cause the transaction to abort - fires 'abort' at transaction |
| 53 // * fires 'error' at the open request |
| 54 // * fires window.onerror (with request error) |
50 | 55 |
51 debug("raising exception"); | 56 debug("raising exception"); |
52 throw new Error("This should *NOT* be caught!"); | 57 waitForError(/This should not be caught/, onGlobalErrorUncaughtException); |
| 58 throw new Error("This should not be caught"); |
53 } | 59 } |
54 | 60 |
55 function setVersion2Abort() | 61 function onGlobalErrorUncaughtException() |
| 62 { |
| 63 sawGlobalErrorUncaughtException = true; |
| 64 } |
| 65 |
| 66 function onTransactionAbort() |
| 67 { |
| 68 shouldBeTrue("sawGlobalErrorUncaughtException"); |
| 69 sawTransactionAbort = true; |
| 70 } |
| 71 |
| 72 function openRequest2Error(evt) |
56 { | 73 { |
57 debug(""); | 74 debug(""); |
58 debug("setVersion2Abort() callback"); | 75 debug("openRequest2Error() callback"); |
| 76 shouldBeTrue("sawGlobalErrorUncaughtException"); |
| 77 shouldBeTrue("sawTransactionAbort"); |
| 78 waitForError(/AbortError/, onGlobalErrorAbortError); |
| 79 } |
59 | 80 |
60 // Restore test harness error handler. | 81 function onGlobalErrorAbortError() |
61 self.onerror = self.originalWindowOnError; | 82 { |
62 db.close(); | 83 debug(""); |
| 84 debug("Verify rollback:"); |
63 evalAndLog("request = indexedDB.open(dbname)"); | 85 evalAndLog("request = indexedDB.open(dbname)"); |
64 request.onblocked = unexpectedBlockedCallback; | 86 request.onblocked = unexpectedBlockedCallback; |
65 request.onupgradeneeded = unexpectedUpgradeNeededCallback; | 87 request.onupgradeneeded = unexpectedUpgradeNeededCallback; |
66 request.onerror = unexpectedErrorCallback; | 88 request.onerror = unexpectedErrorCallback; |
67 request.onsuccess = function (e) { | 89 request.onsuccess = function (e) { |
68 db = event.target.result; | 90 db = event.target.result; |
69 shouldBe("db.version", "1"); | 91 shouldBe("db.version", "1"); |
70 shouldBeTrue("db.objectStoreNames.contains('store1')"); | 92 shouldBeTrue("db.objectStoreNames.contains('store1')"); |
71 shouldBeFalse("db.objectStoreNames.contains('store2')"); | 93 shouldBeFalse("db.objectStoreNames.contains('store2')"); |
72 | 94 |
73 finishJSTest(); | 95 finishJSTest(); |
74 } | 96 }; |
75 } | 97 } |
OLD | NEW |