1 <html> 2 <head> 3 <script> 4 5 var TOTAL_STATEMENTS = 8; 6 var statements = 0; 7 var db = null; 8 9 function log(message) 10 { 11 document.body.innerText += message + "\n"; 12 } 13 14 function terminateTest() 15 { 16 if (window.layoutTestController) 17 layoutTestController.notifyDone(); 18 } 19 20 function executeStatement(expectedToPass, statement) 21 { 22 db.transaction(function(tx) { 23 tx.executeSql(statement, [], 24 function(tx, data) { 25 if (!expectedToPass) { 26 log("Statement " + statement + " was expected to fail, but passed."); 27 terminateTest(); 28 } 29 if (++statements == TOTAL_STATEMENTS) { 30 log("Test passed."); 31 terminateTest(); 32 } 33 }, function(tx, error) { 34 if (expectedToPass) { 35 log("Statement " + statement + " was expected to pass, but failed."); 36 terminateTest(); 37 } 38 if (++statements == TOTAL_STATEMENTS) { 39 log("Test passed."); 40 terminateTest(); 41 } 42 }); 43 }); 44 } 45 46 function runTest() 47 { 48 if (window.layoutTestController) { 49 layoutTestController.clearAllDatabases(); 50 layoutTestController.dumpAsText(); 51 layoutTestController.waitUntilDone(); 52 } 53 54 db = openDatabase("ExecuteSQLAcceptsOnlyOneStatementTest", "1.0", "", 1); 55 db.transaction(function(tx) { 56 tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)"); 57 }, function(error) { 58 log("Test failed: " + error.message); 59 terminateTest(); 60 }, function() { 61 executeStatement(true, "INSERT INTO Test VALUES (1)"); 62 executeStatement(true, "INSERT INTO Test VALUES (2);"); 63 executeStatement(true, " INSERT INTO Test VALUES (3) "); 64 executeStatement(true, " INSERT INTO Test VALUES (4); "); 65 executeStatement(true, "INSERT INTO Test VALUES (5) ;"); 66 executeStatement(false, "INSERT INTO Test VALUES (6); garbage"); 67 executeStatement(false, "INSERT INTO Test VALUES (7); INSERT INTO Test VALUES (8)"); 68 executeStatement(false, " INSERT INTO Test VALUES (9); INSERT INTO Test VALUES (10); "); 69 }); 70 } 71 72 </script> 73 </head> 74 <body onload="runTest();"> 75 This test tests that executeSql() fails when called with a string that has more than one valid statement in it.<br> 76 </body> 77 </body> 78 </html> 79