• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
4<script src="../../fast/js/resources/js-test-pre.js"></script>
5<script src="../../fast/js/resources/js-test-post-function.js"></script>
6<script src="resources/shared.js"></script>
7</head>
8<body>
9<p id="description"></p>
10<div id="console"></div>
11<script>
12
13description("Verify that a transaction with an error aborts unless preventDefault() is called.");
14if (window.layoutTestController)
15    layoutTestController.waitUntilDone();
16
17function test()
18{
19    request = evalAndLog("webkitIndexedDB.open('error-causes-abort-by-default')");
20    request.onsuccess = setVersion;
21    request.onerror = unexpectedErrorCallback;
22}
23
24function setVersion()
25{
26    db = evalAndLog("db = event.target.result");
27
28    request = evalAndLog("db.setVersion('new version')");
29    request.onsuccess = deleteExisting;
30    request.onerror = unexpectedErrorCallback;
31}
32
33function deleteExisting()
34{
35    debug("setVersionSuccess():");
36    window.trans = evalAndLog("trans = event.target.result");
37    shouldBeTrue("trans !== null");
38    trans.onabort = unexpectedAbortCallback;
39    evalAndLog("trans.oncomplete = addData");
40
41    deleteAllObjectStores(db);
42
43    evalAndLog("db.createObjectStore('storeName', null)");
44}
45
46function addData()
47{
48    trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
49    evalAndLog("trans.onabort = unexpectedAbortCallback");
50    evalAndLog("trans.oncomplete = transactionCompleted");
51    store = evalAndLog("store = trans.objectStore('storeName')");
52    request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
53    request.onsuccess = addMore;
54    request.onerror = unexpectedErrorCallback;
55}
56
57function addMore()
58{
59
60    request = evalAndLog("event.target.source.add({x: 'value', y: 'zzz'}, 'key')");
61    request.onsuccess = unexpectedSuccessCallback;
62    request.addEventListener("error", preventTheDefault);
63}
64
65function preventTheDefault()
66{
67    evalAndLog("event.preventDefault()");
68}
69
70function transactionCompleted()
71{
72    testPassed("Transaction completed");
73    debug("");
74    debug("");
75    trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
76    evalAndLog("trans.onabort = transactionAborted1");
77    evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
78    store = evalAndLog("store = trans.objectStore('storeName')");
79    request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
80    request.onsuccess = unexpectedSuccessCallback;
81    request.onerror = allowDefault;
82}
83
84function allowDefault()
85{
86    debug("Doing nothing to prevent the default action...");
87}
88
89function transactionAborted1()
90{
91    testPassed("Transaction aborted");
92    debug("");
93    debug("");
94    trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
95    evalAndLog("trans.onabort = transactionAborted2");
96    evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
97    store = evalAndLog("store = trans.objectStore('storeName')");
98    request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
99    request.onsuccess = unexpectedSuccessCallback;
100    debug("Omitting an onerror handler");
101}
102
103function transactionAborted2()
104{
105    testPassed("Transaction aborted");
106    done();
107}
108
109test();
110
111var successfullyParsed = true;
112
113</script>
114</body>
115</html>
116