1 <html> 2 <head> 3 <script> 4 var database1; 5 var database2; 6 var database3; 7 8 function log(message) 9 { 10 document.getElementById("console").innerHTML += message + "<br>"; 11 } 12 13 function finishTest() 14 { 15 log("Test Complete"); 16 if (window.layoutTestController) 17 layoutTestController.notifyDone(); 18 } 19 20 function statementErrorFunction(tx, error) 21 { 22 log("Unexpected exception - " + error.message); 23 finishTest(); 24 } 25 26 function transactionErrorFunction(db, error) 27 { 28 // We only expect an error message for database2 29 if (db == database2) { 30 log("Expected quota exception - " + error.message); 31 checkCompletion(db); 32 } else { 33 log("Unexpected exception - " + error.message); 34 finishTest(); 35 } 36 } 37 38 function checkCompletion(db) 39 { 40 log("Done adding data"); 41 42 db.complete = true; 43 if (database1.complete && database2.complete && database3.complete) 44 finishTest(); 45 else if (database2.complete) 46 testDatabase(database3); 47 else 48 testDatabase(database2); 49 } 50 51 function addData(db) 52 { 53 db.transaction(function(tx) { 54 log("Inserting some data"); 55 tx.executeSql("INSERT INTO DataTest (randomData) VALUES (ZEROBLOB(17408))", [], 56 function(tx, result) { }, statementErrorFunction); 57 if (db == database2) { 58 // Try to run this statement on 'database2' only. 59 // It should not be run, because the previous statement should've 60 // resulted in a failure that made sqlite roll back the entire transaction. 61 tx.executeSql("INSERT INTO DataTest (randomData) VALUES (ZEROBLOB(10))", [], 62 function(tx, result) { 63 log("This statement should not have been run."); 64 finishTest(); 65 }, statementErrorFunction); 66 } 67 }, function(error) { 68 transactionErrorFunction(db, error); 69 }, function() { 70 checkCompletion(db); 71 }); 72 } 73 74 function testDatabase(db) 75 { 76 db.transaction(function(tx) { 77 log("Adding a table"); 78 tx.executeSql("CREATE TABLE DataTest (randomData)", [], 79 function(tx, result) { }, statementErrorFunction); 80 }, function(error) { 81 transactionErrorFunction(db, error); 82 }, function() { 83 addData(db); 84 }); 85 } 86 87 function runTest() 88 { 89 if (window.layoutTestController) { 90 layoutTestController.clearAllDatabases(); 91 layoutTestController.dumpDatabaseCallbacks(); 92 layoutTestController.setDatabaseQuota(32768); 93 layoutTestController.dumpAsText(); 94 layoutTestController.waitUntilDone(); 95 } 96 97 database1 = openDatabase("QuotaManagementDatabase1", "1.0", "Test for quota management <rdar://5628468>", 1); 98 database2 = openDatabase("QuotaManagementDatabase2", "1.0", "Test for quota management <rdar://5628468>", 1); 99 database3 = openDatabase("QuotaManagementDatabase3", "1.0", "Test for quota management <rdar://5628468>", 1); 100 database1.complete = false; 101 database2.complete = false; 102 database3.complete = false; 103 104 testDatabase(database1); 105 } 106 107 </script> 108 </head> 109 110 <body onload="runTest()"> 111 This test checks to make sure that quotas are enforced per-origin instead of per-database, as they were prior to http://trac.webkit.org/projects/webkit/changeset/29983.<br> 112 The test clears all databases, sets the quota for the origin to 32k, then tries to insert 17k of data into two databases. If things go as planned, the UI Delegate will be informed of the exceeded quota and should increase the quota for this origin. Inserting 17k of data the third time should succeed again. 113 <pre id="console"> 114 </pre> 115 </body> 116 117 </html> 118