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 IDBTransaction.");
     14 if (window.layoutTestController) 
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     request = evalAndLog("webkitIndexedDB.open('transaction-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     window.trans = evalAndLog("trans = event.target.result");
     36     shouldBeTrue("trans !== null");
     37     trans.onabort = unexpectedAbortCallback;
     38     evalAndLog("trans.oncomplete = startTest");
     39 
     40     deleteAllObjectStores(db);
     41 
     42     store = evalAndLog("store = db.createObjectStore('storeName', null)");
     43     request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     44     request.onerror = unexpectedErrorCallback;
     45 }
     46 
     47 function startTest()
     48 {
     49     debug("Verifing abort");
     50     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     51     evalAndLog("trans.onabort = abortFiredCallback");
     52     evalAndLog("trans.oncomplete = unexpectedAbortCallback");
     53     evalAndLog("db.addEventListener('abort', dbAbortCaptureCallback, true)");
     54     evalAndLog("db.addEventListener('abort', dbAbortBubbleCallback, false)");
     55     evalAndLog("db.addEventListener('complete', unexpectedCompleteCallback, true)");
     56     evalAndLog("db.addEventListener('complete', unexpectedCompleteCallback, false)");
     57     store = evalAndLog("store = trans.objectStore('storeName')");
     58     evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
     59     dbCaptureFired = false;
     60     abortFired = false;
     61     dbBubbleFired1 = false;
     62 }
     63 
     64 function dbAbortCaptureCallback()
     65 {
     66     debug("");
     67     debug("In IDBDatabase abort capture");
     68     shouldBeFalse("dbCaptureFired");
     69     shouldBeFalse("abortFired");
     70     shouldBeFalse("dbBubbleFired1");
     71     shouldBe("event.target", "trans");
     72     shouldBe("event.currentTarget", "db");
     73     dbCaptureFired = true;
     74 }
     75 
     76 function abortFiredCallback()
     77 {
     78     debug("");
     79     debug("In abort handler");
     80     shouldBeTrue("dbCaptureFired");
     81     shouldBeFalse("abortFired");
     82     shouldBeFalse("dbBubbleFired1");
     83     shouldBe("event.target", "trans");
     84     shouldBe("event.currentTarget", "trans");
     85     abortFired = true;
     86 }
     87 
     88 function dbAbortBubbleCallback()
     89 {
     90     debug("");
     91     debug("In IDBDatabase error bubble");
     92     shouldBeTrue("dbCaptureFired");
     93     shouldBeTrue("abortFired");
     94     shouldBeFalse("dbBubbleFired1");
     95     shouldBe("event.target", "trans");
     96     shouldBe("event.currentTarget", "db");
     97     dbBubbleFired1 = true;
     98     debug("");
     99     debug("Verifing success.");
    100     trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
    101     evalAndLog("trans.oncomplete = completeFiredCallback");
    102     evalAndLog("trans.onabort = unexpectedAbortCallback");
    103     evalAndLog("db.removeEventListener('abort', dbAbortCaptureCallback, true)");
    104     evalAndLog("db.removeEventListener('abort', dbAbortBubbleCallback, false)");
    105     evalAndLog("db.removeEventListener('complete', unexpectedCompleteCallback, true)");
    106     evalAndLog("db.removeEventListener('complete', unexpectedCompleteCallback, false)");
    107     evalAndLog("db.addEventListener('complete', dbCompleteCaptureCallback, true)");
    108     evalAndLog("db.addEventListener('complete', dbCompleteBubbleCallback, false)");
    109     evalAndLog("db.addEventListener('abort', unexpectedAbortCallback, true)");
    110     evalAndLog("db.addEventListener('abort', unexpectedAbortCallback, false)");
    111     store = evalAndLog("store = trans.objectStore('storeName')");
    112     evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key2')");
    113     dbCaptureFired = false;
    114     completeFired = false;
    115     dbBubbleFired2 = false;
    116 }
    117 
    118 function dbCompleteCaptureCallback()
    119 {
    120     debug("");
    121     debug("In IDBDatabase complete capture");
    122     shouldBeFalse("dbCaptureFired");
    123     shouldBeFalse("completeFired");
    124     shouldBeFalse("dbBubbleFired2");
    125     shouldBe("event.target", "trans");
    126     shouldBe("event.currentTarget", "db");
    127     dbCaptureFired = true;
    128 }
    129 
    130 function completeFiredCallback()
    131 {
    132     debug("");
    133     debug("In IDBRequest handler");
    134     shouldBeTrue("dbCaptureFired");
    135     shouldBeFalse("completeFired");
    136     shouldBeFalse("dbBubbleFired2");
    137     shouldBe("event.target", "trans");
    138     shouldBe("event.currentTarget", "trans");
    139     completeFired = true;
    140     debug("");
    141     done();
    142 }
    143 
    144 function dbCompleteBubbleCallback()
    145 {
    146     debug("");
    147     debug("In IDBDatabase complete bubble");
    148     testFailed("Complete bubble callback should NOT fire");
    149     dbBubbleFired2 = true;
    150 }
    151 
    152 test();
    153 
    154 var successfullyParsed = true;
    155 
    156 </script>
    157 </body>
    158 </html>
    159