Landing test that was forgotten in the original patch (r30087).
authorkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Feb 2008 18:06:09 +0000 (18:06 +0000)
committerkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Feb 2008 18:06:09 +0000 (18:06 +0000)
        Test for: http://bugs.webkit.org/show_bug.cgi?id=17191
        HTML5: Client-side database queries should return values of type number

        * storage/sql-data-types-expected.txt: Added.
        * storage/sql-data-types.html: Added.
        * storage/sql-data-types.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30628 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/storage/sql-data-types-expected.txt [new file with mode: 0644]
LayoutTests/storage/sql-data-types.html [new file with mode: 0644]
LayoutTests/storage/sql-data-types.js [new file with mode: 0644]

index 56abab72351465bebd91d03405378e51c4643cbe..5cd8a488808f79eb99712763ac171a7455653c48 100644 (file)
@@ -1,3 +1,14 @@
+2008-02-27  Kevin McCullough  <kmccullough@apple.com>
+
+        Landing test that was forgotten in the original patch (r30087).
+
+        Test for: http://bugs.webkit.org/show_bug.cgi?id=17191
+        HTML5: Client-side database queries should return values of type number
+
+        * storage/sql-data-types-expected.txt: Added.
+        * storage/sql-data-types.html: Added.
+        * storage/sql-data-types.js: Added.
+
 2008-02-27  Julien Chaffraix <julien.chaffraix@gmail.com>
 
         Reviewed by Alexey.
diff --git a/LayoutTests/storage/sql-data-types-expected.txt b/LayoutTests/storage/sql-data-types-expected.txt
new file mode 100644 (file)
index 0000000..f60caf5
--- /dev/null
@@ -0,0 +1,7 @@
+PASS: property 'timestamp' ok, type was number
+PASS: property 'id' ok, type was number
+PASS: property 'real' ok, type was number
+PASS: property 'text' ok, type was string
+PASS: property 'blob' ok, type was string
+PASS: database clean up ok.
+
diff --git a/LayoutTests/storage/sql-data-types.html b/LayoutTests/storage/sql-data-types.html
new file mode 100644 (file)
index 0000000..cd1c98f
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+<head>
+<script type="text/javascript" src="sql-data-types.js"></script>
+</head>
+
+<body onload="runTest()">
+<pre id="console"></pre>
+</body>
+
+</html>
diff --git a/LayoutTests/storage/sql-data-types.js b/LayoutTests/storage/sql-data-types.js
new file mode 100644 (file)
index 0000000..36fcd01
--- /dev/null
@@ -0,0 +1,87 @@
+//description("This test verifies that the javascript values returned by database queries are of same type as the values put into the database.");
+
+function writeMessageToLog(message)
+{
+    document.getElementById("console").innerText += message + "\n";
+}
+
+function notifyDone(str) {
+    writeMessageToLog(str);
+    if (window.layoutTestController)
+        layoutTestController.notifyDone();
+}
+
+var testValues = {
+    timestamp: new Date("Wed Feb 06 2008 12:16:52 GMT+0200 (EET)").valueOf(),
+    id: 1001,
+    real: 101.444,
+    text: "WebKit db TEXT",
+    blob: "supercalifragilistic"
+};
+
+function shouldBeSameTypeAndValue(propName, testValue, result) {
+    if (testValue == result && typeof testValue == typeof result) {
+        writeMessageToLog("PASS: property '" + propName + "' ok, type was " + typeof result);
+        return true;
+    }
+    writeMessageToLog("FAIL: property '" + propName + "' failed."
+        + " expected: " + typeof testValue + ":'" + testValue + "' "
+        + " got: " + typeof result + ":'" + result +"'");
+    return false;
+}
+
+function testDBValues(tx, result) {
+    var rs = result.rows.item(0);
+    // Avoid for .. in because (theretically) the order can change
+    i = "timestamp"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
+    i = "id"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
+    i = "real"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
+    i = "text"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
+    i = "blob"; shouldBeSameTypeAndValue(i, testValues[i], rs[i]);
+    
+    tx.executeSql("DROP TABLE DataTypeTestTable", [],
+        function(tx, result) {
+            notifyDone("PASS: database clean up ok.");
+        },
+        function(tx, result) {
+            notifyDone("FAIL: Database clean up failed.");
+        });
+}
+
+function fetchDBValuesStmt(tx, result) {
+    tx.executeSql("SELECT * FROM DataTypeTestTable", [],
+        testDBValues,
+        function(tx,error) {
+            notifyDone("FAIL: Error fetching values from the db.")
+        });
+}
+
+function insertTestValuesStmt(tx, result) {
+    tx.executeSql("INSERT INTO DataTypeTestTable (id, real, timestamp, text, blob) VALUES (?,?,?,?,?)",
+        [testValues.id, testValues.real, testValues.timestamp, testValues.text, testValues.blob],
+        fetchDBValuesStmt,
+        function(tx, error) {
+            notifyDone("FAIL: Error inserting values to the db.");
+        });
+}
+
+function createTestDBStmt(tx)
+{
+    tx.executeSql("CREATE TABLE IF NOT EXISTS DataTypeTestTable (id INTEGER UNIQUE, real REAL, timestamp INTEGER, text TEXT, blob BLOB)", [],
+        insertTestValuesStmt,
+        function(tx, error) {
+            notifyDone("FAIL: Error creating the db.");
+        });
+}
+
+function runTest() {
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+    var db = openDatabase("DataTypeTest", "1.0", "Database for sql data type test", 1);
+    if (db)
+        db.transaction(createTestDBStmt);
+    else
+        notifyDone("FAIL: Error opening the db");
+}