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 event propogation on IDBRequest.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('request-event-propagation')");
     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("Verify that handler fires and that not preventing default will result in an abort");
     51     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     52     evalAndLog("trans.onabort = transactionAborted");
     53     evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
     54     evalAndLog("trans.onerror = allowDefault");
     55     store = evalAndLog("store = trans.objectStore('storeName')");
     56     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     57     request.onsuccess = unexpectedSuccessCallback;
     58     handlerFired = false;
     59 }
     60 
     61 function allowDefault()
     62 {
     63     testPassed("Event handler fired");
     64     debug("Doing nothing to prevent the default action...");
     65     handlerFired = true;
     66 }
     67 
     68 function transactionAborted()
     69 {
     70     shouldBeTrue("handlerFired");
     71     debug("");
     72     debug("Verifing error");
     73     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     74     evalAndLog("trans.onabort = transactionAborted2");
     75     evalAndLog("trans.oncomplete = unexpectedAbortCallback");
     76     evalAndLog("trans.addEventListener('error', errorCaptureCallback, true)");
     77     evalAndLog("trans.addEventListener('error', errorBubbleCallback, false)");
     78     evalAndLog("trans.addEventListener('success', unexpectedSuccessCallback, true)");
     79     evalAndLog("trans.addEventListener('success', unexpectedSuccessCallback, false)");
     80     evalAndLog("db.addEventListener('error', dbErrorCaptureCallback, true)");
     81     evalAndLog("db.addEventListener('error', dbErrorBubbleCallback, false)");
     82     evalAndLog("db.addEventListener('success', unexpectedSuccessCallback, true)");
     83     evalAndLog("db.addEventListener('success', unexpectedSuccessCallback, false)");
     84     store = evalAndLog("store = trans.objectStore('storeName')");
     85     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     86     request.onsuccess = unexpectedSuccessCallback;
     87     request.onerror = errorFiredCallback;
     88     dbCaptureFired = false;
     89     captureFired = false;
     90     requestFired = false;
     91     bubbleFired = false;
     92     dbBubbleFired = false;
     93 }
     94 
     95 function dbErrorCaptureCallback()
     96 {
     97     debug("");
     98     debug("In IDBDatabase error capture");
     99     shouldBeFalse("dbCaptureFired");
    100     shouldBeFalse("captureFired");
    101     shouldBeFalse("requestFired");
    102     shouldBeFalse("bubbleFired");
    103     shouldBeFalse("dbBubbleFired");
    104     shouldBe("event.target", "request");
    105     shouldBe("event.currentTarget", "db");
    106     dbCaptureFired = true;
    107 }
    108 
    109 function errorCaptureCallback()
    110 {
    111     debug("");
    112     debug("In IDBTransaction error capture");
    113     shouldBeTrue("dbCaptureFired");
    114     shouldBeFalse("captureFired");
    115     shouldBeFalse("requestFired");
    116     shouldBeFalse("bubbleFired");
    117     shouldBeFalse("dbBubbleFired");
    118     shouldBe("event.target", "request");
    119     shouldBe("event.currentTarget", "trans");
    120     captureFired = true;
    121 }
    122 
    123 function errorFiredCallback()
    124 {
    125     debug("");
    126     debug("In IDBRequest handler");
    127     shouldBeTrue("dbCaptureFired");
    128     shouldBeTrue("captureFired");
    129     shouldBeFalse("requestFired");
    130     shouldBeFalse("bubbleFired");
    131     shouldBeFalse("dbBubbleFired");
    132     shouldBe("event.target", "request");
    133     shouldBe("event.currentTarget", "request");
    134     requestFired = true;
    135 }
    136 
    137 function errorBubbleCallback()
    138 {
    139     debug("");
    140     debug("In IDBTransaction error bubble");
    141     shouldBeTrue("dbCaptureFired");
    142     shouldBeTrue("captureFired");
    143     shouldBeTrue("requestFired");
    144     shouldBeFalse("bubbleFired");
    145     shouldBeFalse("dbBubbleFired");
    146     shouldBe("event.target", "request");
    147     shouldBe("event.currentTarget", "trans");
    148     bubbleFired = true;
    149 }
    150 
    151 function dbErrorBubbleCallback()
    152 {
    153     debug("");
    154     debug("In IDBDatabase error bubble");
    155     shouldBeTrue("dbCaptureFired");
    156     shouldBeTrue("captureFired");
    157     shouldBeTrue("requestFired");
    158     shouldBeTrue("bubbleFired");
    159     shouldBeFalse("dbBubbleFired");
    160     shouldBe("event.target", "request");
    161     shouldBe("event.currentTarget", "db");
    162     dbBubbleFired = true;
    163 }
    164 
    165 function transactionAborted2()
    166 {
    167     debug("");
    168     debug("Transaction aborted");
    169     shouldBeTrue("dbCaptureFired");
    170     shouldBeTrue("captureFired");
    171     shouldBeTrue("requestFired");
    172     shouldBeTrue("bubbleFired");
    173     shouldBeTrue("dbBubbleFired");
    174     debug("");
    175     debug("Verifing success.");
    176     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
    177     evalAndLog("trans.oncomplete = transactionComplete");
    178     evalAndLog("trans.onabort = unexpectedAbortCallback");
    179     evalAndLog("trans.addEventListener('success', successCaptureCallback, true)");
    180     evalAndLog("trans.addEventListener('success', successBubbleCallback, false)");
    181     evalAndLog("trans.addEventListener('error', unexpectedErrorCallback, true)");
    182     evalAndLog("trans.addEventListener('error', unexpectedErrorCallback, false)");
    183     evalAndLog("db.removeEventListener('error', dbErrorCaptureCallback, true)");
    184     evalAndLog("db.removeEventListener('error', dbErrorBubbleCallback, false)");
    185     evalAndLog("db.removeEventListener('success', unexpectedSuccessCallback, true)");
    186     evalAndLog("db.removeEventListener('success', unexpectedSuccessCallback, false)");
    187     evalAndLog("db.addEventListener('success', dbSuccessCaptureCallback, true)");
    188     evalAndLog("db.addEventListener('success', dbSuccessBubbleCallback, false)");
    189     evalAndLog("db.addEventListener('error', unexpectedErrorCallback, true)");
    190     evalAndLog("db.addEventListener('error', unexpectedErrorCallback, false)");
    191     store = evalAndLog("store = trans.objectStore('storeName')");
    192     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key2')");
    193     request.onerror = unexpectedErrorCallback;
    194     request.onsuccess = successFiredCallback;
    195     dbCaptureFired = false;
    196     captureFired = false;
    197     requestFired = false;
    198     bubbleFired = false;
    199     dbBubbleFired = false;
    200 }
    201 
    202 function dbSuccessCaptureCallback()
    203 {
    204     debug("");
    205     debug("In IDBDatabase success capture");
    206     shouldBeFalse("dbCaptureFired");
    207     shouldBeFalse("captureFired");
    208     shouldBeFalse("requestFired");
    209     shouldBeFalse("bubbleFired");
    210     shouldBeFalse("dbBubbleFired");
    211     shouldBe("event.target", "request");
    212     shouldBe("event.currentTarget", "db");
    213     dbCaptureFired = true;
    214 }
    215 
    216 function successCaptureCallback()
    217 {
    218     debug("");
    219     debug("In IDBTransaction success capture");
    220     shouldBeTrue("dbCaptureFired");
    221     shouldBeFalse("captureFired");
    222     shouldBeFalse("requestFired");
    223     shouldBeFalse("bubbleFired");
    224     shouldBeFalse("dbBubbleFired");
    225     shouldBe("event.target", "request");
    226     shouldBe("event.currentTarget", "trans");
    227     captureFired = true;
    228 }
    229 
    230 function successFiredCallback()
    231 {
    232     debug("");
    233     debug("In IDBRequest handler");
    234     shouldBeTrue("dbCaptureFired");
    235     shouldBeTrue("captureFired");
    236     shouldBeFalse("requestFired");
    237     shouldBeFalse("bubbleFired");
    238     shouldBeFalse("dbBubbleFired");
    239     shouldBe("event.target", "request");
    240     shouldBe("event.currentTarget", "request");
    241     requestFired = true;
    242 }
    243 
    244 function successBubbleCallback()
    245 {
    246     debug("");
    247     debug("In IDBTransaction success bubble");
    248     testFailed("Success bubble callback should NOT fire");
    249     bubbleFired = true;
    250 }
    251 
    252 function dbSuccessBubbleCallback()
    253 {
    254     debug("");
    255     debug("In IDBDatabase success bubble");
    256     testFailed("Success bubble callback should NOT fire");
    257     dbBubbleFired = true;
    258 }
    259 
    260 function transactionComplete()
    261 {
    262     debug("");
    263     debug("Transaction completed");
    264     shouldBeTrue("dbCaptureFired");
    265     shouldBeTrue("captureFired");
    266     shouldBeTrue("requestFired");
    267     shouldBeFalse("bubbleFired");
    268     shouldBeFalse("dbBubbleFired");
    269     debug("");
    270 
    271     done();
    272     return;
    273 }
    274 
    275 test();
    276 
    277 var successfullyParsed = true;
    278 
    279 </script>
    280 </body>
    281 </html>
    282