1 <html> 2 <head> 3 <script> 4 5 function writeMessageToLog(message) 6 { 7 document.getElementById("console").innerText += message + "\n"; 8 } 9 10 var setupStatements = [ 11 "CREATE TABLE IF NOT EXISTS PrivateTest1 (randomData)", 12 "INSERT INTO PrivateTest1 VALUES ('somedata')" 13 ]; 14 15 var privateBrowsingStatements = [ 16 "CREATE TABLE IF NOT EXISTS PrivateTest2 (randomData)", 17 "DELETE FROM PrivateTest1", 18 "DROP TABLE PrivateTest1", 19 "INSERT INTO PrivateTest1 VALUES ('somedata')" 20 ]; 21 22 var completed = 0; 23 var theTransaction; 24 25 function setupSuccessFunction(tx, result) 26 { 27 ++completed; 28 writeMessageToLog("Setup statement " + completed + " completed successfully"); 29 checkSetupComplete(); 30 } 31 32 function setupErrorFunction(tx, error) 33 { 34 ++completed; 35 writeMessageToLog("Setup statement " + completed + " completed with an error\n" + error.message); 36 checkSetupComplete(); 37 } 38 39 function privateBrowsingSuccessFunction(tx, result) 40 { 41 ++completed; 42 writeMessageToLog("Private browsing statement " + completed + " completed successfully"); 43 } 44 45 function privateBrowsingErrorFunction(tx, error) 46 { 47 ++completed; 48 writeMessageToLog("Private browsing statement " + completed + " completed with an error\n" + error.message); 49 } 50 51 function runSetup(transaction) 52 { 53 theTransaction = transaction; 54 for (i in setupStatements) 55 theTransaction.executeSql(setupStatements[i], [], setupSuccessFunction, setupErrorFunction); 56 } 57 58 function checkSetupComplete() 59 { 60 if (completed == setupStatements.length) 61 runPrivateBrowsingTests(); 62 } 63 64 function runPrivateBrowsingTests() 65 { 66 completed = 0; 67 68 if (window.layoutTestController) 69 layoutTestController.setPrivateBrowsingEnabled(true); 70 71 for (i in privateBrowsingStatements) 72 theTransaction.executeSql(privateBrowsingStatements[i], [], privateBrowsingSuccessFunction, privateBrowsingErrorFunction); 73 } 74 75 function endTest() 76 { 77 writeMessageToLog("Test ended"); 78 79 if (window.layoutTestController) 80 layoutTestController.notifyDone(); 81 } 82 83 function runTest() 84 { 85 if (window.layoutTestController) { 86 layoutTestController.dumpAsText(); 87 layoutTestController.waitUntilDone(); 88 } 89 90 var database = openDatabase("PrivateBrowsingReadOnlyTest", "1.0", "Test private browsing read-only safety", 1); 91 database.transaction(runSetup, endTest, endTest); 92 } 93 94 </script> 95 </head> 96 <body onload="runTest();"> 97 This test makes sure that attempts to change the database during private browsing fail.<br> 98 <div id="console"></div> 99 </body> 100 </html> 101