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("4 open connections try to setVersion at the same time.  3 connections eventually close, allowing 1 setVersion call to proceed.");
     14 if (window.layoutTestController)
     15     layoutTestController.waitUntilDone();
     16 
     17 connections = []
     18 function test()
     19 {
     20     if ('webkitIndexedDB' in window)
     21         IndexedDB = webkitIndexedDB;
     22     else if ('mozIndexedDB' in window)
     23         IndexedDB = mozIndexedDB;
     24     shouldBeFalse("IndexedDB == null");
     25     openDBConnection();
     26 }
     27 
     28 function openDBConnection()
     29 {
     30     result = evalAndLog("IndexedDB.open('set-version-queue')");
     31     result.onsuccess = openSuccess;
     32     result.onerror = unexpectedErrorCallback;
     33 }
     34 
     35 function openSuccess()
     36 {
     37     connection = event.target.result;
     38     connection.onversionchange = generateVersionChangeHandler();
     39     connections.push(connection);
     40     if (connections.length < 4)
     41         openDBConnection();
     42     else {
     43         request = evalAndLog("connections[0].setVersion('version 0')");
     44         request.onerror = function(event){ connectionError(event, 0) };
     45         request.onsuccess = unexpectedSuccessCallback;
     46         request.onblocked = blocked0;
     47         request1 = evalAndLog("connections[1].setVersion('version 1')");
     48         request1.onerror = unexpectedErrorCallback;
     49         request1.onsuccess = inSetVersion1;
     50         request1.onblocked = blocked1;
     51         request2 = evalAndLog("connections[2].setVersion('version 2')");
     52         request2.onerror = function(event){ connectionError(event, 2) };
     53         request2.onsuccess = unexpectedSuccessCallback;
     54         request2.onblocked = blocked2;
     55         request3 = evalAndLog("connections[3].setVersion('version 3')");
     56         request3.onerror = function(event){ connectionError(event, 3) };
     57         request3.onsuccess = unexpectedSuccessCallback;
     58         request3.onblocked = blocked3;
     59         debug("");
     60     }
     61 }
     62 
     63 function generateVersionChangeHandler()
     64 {
     65     var connectionNum = connections.length;
     66     return function(event)
     67     {
     68         shouldBeTrue("event.version.length > 0");
     69         debug("connection[" + connectionNum + "] received versionChangeEvent: " + event.version);
     70     }
     71 }
     72 
     73 blocked0fired = false;
     74 blocked2fired = false;
     75 function blocked0(event)
     76 {
     77     debug("");
     78     testPassed("connection[0] got blocked event");
     79     shouldBeEqualToString("event.version", "version 0");
     80     debug("Close the connection that received the block event:");
     81     evalAndLog("connections[0].close()");
     82     debug("Close another connection as well, to test 4.7.4-note:");
     83     evalAndLog("connections[3].close()");
     84     evalAndLog("blocked0fired = true");
     85     debug("");
     86 }
     87 
     88 function blocked1(event)
     89 {
     90     debug("")
     91     testPassed("connection[1] got blocked event");
     92     debug("Ensure that this blocked event is in order:");
     93     shouldBeTrue("blocked0fired");
     94     shouldBeFalse("blocked2fired");
     95     debug("")
     96 }
     97 
     98 function blocked2(event)
     99 {
    100     debug("")
    101     testPassed("connection[2] got blocked event");
    102     shouldBeEqualToString("event.version", "version 2");
    103     evalAndLog("connections[2].close()");
    104     evalAndLog("blocked2fired = true");
    105     debug("")
    106 }
    107 
    108 function blocked3(event)
    109 {
    110     debug("")
    111     testPassed("connection[3] got blocked event");
    112     debug("Note: This means that a connection can receive a blocked event after its close() method has been called.  Spec is silent on the issue and this is easiest to implement.");
    113     shouldBeEqualToString("event.version", "version 3");
    114 }
    115 
    116 function connectionError(event, connectionId)
    117 {
    118     debug("")
    119     testPassed("connection[" + connectionId + "] got error event");
    120     shouldBe("event.target.errorCode", "13")
    121     if ('webkitIndexedDB' in window) {
    122         shouldBe("event.target.webkitErrorMessage.length > 0", "true");
    123         debug(event.target.webkitErrorMessage);
    124     }
    125 }
    126 
    127 function inSetVersion1(event)
    128 {
    129     debug("")
    130     testPassed("connection[1] got into SetVersion");
    131     done();
    132 }
    133 
    134 var successfullyParsed = true;
    135 
    136 test();
    137 
    138 </script>
    139 </body>
    140 </html>
    141