1 <html> 2 <head> 3 <script> 4 var database; 5 6 function log(message) 7 { 8 document.getElementById("console").innerHTML += message + "<br>"; 9 } 10 11 function finishTest() 12 { 13 log("Test part 1 Complete"); 14 if (window.layoutTestController) 15 layoutTestController.notifyDone(); 16 } 17 18 function errorFunction(tx, error) 19 { 20 log("Test failed - " + error.message); 21 finishTest(); 22 } 23 24 function addData(db) 25 { 26 db.transaction(function(tx) { 27 log("Inserting some data"); 28 // Insert a large amount of data that will take a little while to run. Schedule a timout to run that will load a new page 29 // whilst the transaction is still in progress, interrupting the transaction. This should not leave the database locked and on 30 // the next page we should be able to insert some more data. 31 tx.executeSql("INSERT INTO DataTest (testData) VALUES (randomBlob(524200 ))", [], function(tx, result) { }, errorFunction); 32 location.href = "./resources/database-lock-after-reload-2.html"; 33 }, errorFunction, function() { 34 finishTest(); 35 }); 36 } 37 38 function runTest() 39 { 40 if (window.layoutTestController) { 41 layoutTestController.clearAllDatabases(); 42 layoutTestController.dumpAsText(); 43 layoutTestController.waitUntilDone(); 44 } 45 46 try { 47 database = openDatabase("DatabaseLockTest", "1.0", "Test for database locking", 5242880); 48 } catch (e) { 49 log("Error - could not open database"); 50 finishTest(); 51 } 52 53 database.transaction(function(tx) { 54 log("Adding a table"); 55 tx.executeSql("CREATE TABLE DataTest (testData)", [], function(tx, result) { }, errorFunction); 56 }, errorFunction, function() { 57 addData(database); 58 }); 59 } 60 61 </script> 62 </head> 63 64 <body onload="runTest()"> 65 <pre id="console"> 66 </pre> 67 </body> 68 69 </html> 70