Home | History | Annotate | Download | only in indexeddb
      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 
     13 description("Test exceptions in IDBRequest handlers cause aborts.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('exception-in-event-aborts')");
     20     request.onsuccess = setVersion;
     21     request.onerror = unexpectedErrorCallback;
     22 }
     23 
     24 function 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 
     33 function 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 = startTest");
     40 
     41     deleteAllObjectStores(db);
     42 
     43     store = evalAndLog("store = db.createObjectStore('storeName', null)");
     44     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     45     request.onerror = unexpectedErrorCallback;
     46 }
     47 
     48 function startTest()
     49 {
     50     debug("");
     51     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     52     evalAndLog("trans.onabort = transactionAborted1");
     53     evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
     54     store = evalAndLog("store = trans.objectStore('storeName')");
     55     request = evalAndLog("store.add({x: 'value2', y: 'zzz2'}, 'key2')");
     56     trans.addEventListener('success', causeException, true);
     57     request.onerror = unexpectedErrorCallback;
     58 }
     59 
     60 function causeException()
     61 {
     62     debug("");
     63     evalAndLog("event.preventDefault()");
     64     debug("Throwing");
     65     throw "this exception is expected";
     66 }
     67 
     68 function transactionAborted1()
     69 {
     70     debug("");
     71     testPassed("The transaction was aborted.");
     72     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     73     evalAndLog("trans.onabort = transactionAborted2");
     74     evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
     75     store = evalAndLog("store = trans.objectStore('storeName')");
     76     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     77     request.onsuccess = unexpectedSuccessCallback;
     78     db.onerror = causeException;
     79 }
     80 
     81 function transactionAborted2()
     82 {
     83     debug("");
     84     testPassed("The transaction was aborted.");
     85     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     86     evalAndLog("trans.onabort = unexpectedAbortCallback");
     87     evalAndLog("trans.oncomplete = transactionCompleted1");
     88     store = evalAndLog("store = trans.objectStore('storeName')");
     89     request = evalAndLog("store.add({x: 'value3', y: 'zzz3'}, 'key3')");
     90     request.onsuccess = throwAndCatch;
     91     request.onerror = unexpectedErrorCallback;
     92     db.onerror = null;
     93 }
     94 
     95 function throwAndCatch()
     96 {
     97     debug("");
     98     evalAndLog("event.preventDefault()");
     99     debug("Throwing within a try block");
    100     try {
    101         throw "AHHH";
    102     } catch (e) {
    103     }
    104 }
    105 
    106 function transactionCompleted1()
    107 {
    108     debug("");
    109     testPassed("The transaction completed.");
    110     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
    111     evalAndLog("trans.onabort = unexpectedAbortCallback");
    112     evalAndLog("trans.oncomplete = transactionCompleted2");
    113     store = evalAndLog("store = trans.objectStore('storeName')");
    114     request = evalAndLog("store.add({x: 'value4', y: 'zzz4'}, 'key4')");
    115     request.onsuccess = unexpectedSuccessCallback;
    116     request.onerror = throwAndCatch;
    117 }
    118 
    119 function transactionCompleted2()
    120 {
    121     debug("");
    122     testPassed("The transaction completed.");
    123     debug("");
    124     done();
    125 }
    126 
    127 test();
    128 
    129 var successfullyParsed = true;
    130 
    131 </script>
    132 </body>
    133 </html>
    134