1 //description("This test verifies that the javascript values returned by database queries are of same type as the values put into the database.");
3 function writeMessageToLog(message)
5 document.getElementById("console").innerText += message + "\n";
8 function notifyDone(str) {
9 writeMessageToLog(str);
10 if (window.layoutTestController)
11 layoutTestController.notifyDone();
15 timestamp: new Date("Wed Feb 06 2008 12:16:52 GMT+0200 (EET)").valueOf(),
18 text: "WebKit db TEXT",
19 blob: "supercalifragilistic"
22 function shouldBeSameTypeAndValue(propName, testValue, result) {
23 if (testValue == result && typeof testValue == typeof result) {
24 writeMessageToLog("PASS: property '" + propName + "' ok, type was " + typeof result);
27 writeMessageToLog("FAIL: property '" + propName + "' failed."
28 + " expected: " + typeof testValue + ":'" + testValue + "' "
29 + " got: " + typeof result + ":'" + result +"'");
33 function testDBValues(tx, result) {
34 var rs = result.rows.item(0);
35 // Avoid for .. in because (theretically) the order can change
36 i = "timestamp"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
37 i = "id"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
38 i = "real"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
39 i = "text"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
40 i = "blob"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
42 tx.executeSql("DROP TABLE DataTypeTestTable", [],
43 function(tx, result) {
44 notifyDone("PASS: database clean up ok.");
46 function(tx, result) {
47 notifyDone("FAIL: Database clean up failed.");
51 function fetchDBValuesStmt(tx, result) {
52 tx.executeSql("SELECT * FROM DataTypeTestTable", [],
55 notifyDone("FAIL: Error fetching values from the db.")
59 function insertTestValuesStmt(tx, result) {
60 tx.executeSql("INSERT INTO DataTypeTestTable (id, real, timestamp, text, blob) VALUES (?,?,?,?,?)",
61 [testValues.id, testValues.real, testValues.timestamp, testValues.text, testValues.blob],
64 notifyDone("FAIL: Error inserting values to the db.");
68 function createTestDBStmt(tx)
70 tx.executeSql("CREATE TABLE IF NOT EXISTS DataTypeTestTable (id INTEGER UNIQUE, real REAL, timestamp INTEGER, text TEXT, blob BLOB)", [],
73 notifyDone("FAIL: Error creating the db.");
78 if (window.layoutTestController) {
79 layoutTestController.dumpAsText();
80 layoutTestController.waitUntilDone();
82 var db = openDatabase("DataTypeTest", "1.0", "Database for sql data type test", 1);
84 db.transaction(createTestDBStmt);
86 notifyDone("FAIL: Error opening the db");